mirror of https://github.com/apache/jclouds.git
Issue 321 fixed naming scope of rackspace
This commit is contained in:
parent
9ff4f84783
commit
fd6e1cdee7
|
@ -89,8 +89,8 @@ import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.util.Providers;
|
import com.google.inject.util.Providers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService}
|
* Configures the {@link CloudServersComputeServiceContext}; requires
|
||||||
* bound.
|
* {@link BaseComputeService} bound.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -104,10 +104,8 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
}).to(ServerToNodeMetadata.class);
|
}).to(ServerToNodeMetadata.class);
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
})
|
}).to(new TypeLiteral<ComputeServiceContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
||||||
.to(
|
}).in(Scopes.SINGLETON);
|
||||||
new TypeLiteral<ComputeServiceContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(new TypeLiteral<RestContext<CloudServersClient, CloudServersAsyncClient>>() {
|
bind(new TypeLiteral<RestContext<CloudServersClient, CloudServersAsyncClient>>() {
|
||||||
}).to(new TypeLiteral<RestContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
}).to(new TypeLiteral<RestContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
||||||
}).in(Scopes.SINGLETON);
|
}).in(Scopes.SINGLETON);
|
||||||
|
@ -127,8 +125,8 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Named("NAMING_CONVENTION")
|
@Named("NAMING_CONVENTION")
|
||||||
@Singleton
|
@Singleton
|
||||||
String provideNamingConvention(@Named(Constants.PROPERTY_IDENTITY) String identity) {
|
String provideNamingConvention() {
|
||||||
return identity + "-%s-%s";
|
return "%s-%s";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -137,8 +135,7 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
private final GetNodeMetadataStrategy getNode;
|
private final GetNodeMetadataStrategy getNode;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected CloudServersRebootNodeStrategy(CloudServersClient client,
|
protected CloudServersRebootNodeStrategy(CloudServersClient client, GetNodeMetadataStrategy getNode) {
|
||||||
GetNodeMetadataStrategy getNode) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.getNode = getNode;
|
this.getNode = getNode;
|
||||||
}
|
}
|
||||||
|
@ -159,8 +156,7 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
private final GetNodeMetadataStrategy getNode;
|
private final GetNodeMetadataStrategy getNode;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected CloudServersDestroyNodeStrategy(CloudServersClient client,
|
protected CloudServersDestroyNodeStrategy(CloudServersClient client, GetNodeMetadataStrategy getNode) {
|
||||||
GetNodeMetadataStrategy getNode) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.getNode = getNode;
|
this.getNode = getNode;
|
||||||
}
|
}
|
||||||
|
@ -186,15 +182,13 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String tag, String name, Template template) {
|
public NodeMetadata execute(String tag, String name, Template template) {
|
||||||
Server server = client.createServer(name, Integer.parseInt(template.getImage()
|
Server server = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer
|
||||||
.getProviderId()), Integer.parseInt(template.getSize().getProviderId()));
|
.parseInt(template.getSize().getProviderId()));
|
||||||
return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "",
|
return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "", new LocationImpl(
|
||||||
new LocationImpl(LocationScope.HOST, server.getHostId(), server.getHostId(),
|
LocationScope.HOST, server.getHostId(), server.getHostId(), template.getLocation()), null, server
|
||||||
template.getLocation()), null, server.getMetadata(), tag, template
|
.getMetadata(), tag, template.getImage(), NodeState.PENDING, server.getAddresses().getPublicAddresses(),
|
||||||
.getImage(), NodeState.PENDING, server.getAddresses()
|
server.getAddresses().getPrivateAddresses(), ImmutableMap.<String, String> of(), new Credentials("root",
|
||||||
.getPublicAddresses(), server.getAddresses().getPrivateAddresses(),
|
server.getAdminPass()));
|
||||||
ImmutableMap.<String, String> of(),
|
|
||||||
new Credentials("root", server.getAdminPass()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -206,7 +200,7 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected CloudServersListNodesStrategy(CloudServersClient client,
|
protected CloudServersListNodesStrategy(CloudServersClient client,
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||||
}
|
}
|
||||||
|
@ -217,10 +211,9 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||||
Predicate<ComputeMetadata> filter) {
|
return Iterables.filter(Iterables.transform(client.listServers(ListOptions.Builder.withDetails()),
|
||||||
return Iterables.filter(Iterables.transform(client.listServers(ListOptions.Builder
|
serverToNodeMetadata), filter);
|
||||||
.withDetails()), serverToNodeMetadata), filter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +225,7 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected CloudServersGetNodeMetadataStrategy(CloudServersClient client,
|
protected CloudServersGetNodeMetadataStrategy(CloudServersClient client,
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||||
}
|
}
|
||||||
|
@ -248,30 +241,29 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
||||||
return ImmutableMap.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE,
|
return ImmutableMap.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||||
NodeState.RUNNING)//
|
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
||||||
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
||||||
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
.put(ServerStatus.PREP_RESIZE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.PREP_RESIZE, NodeState.PENDING)//
|
.put(ServerStatus.RESIZE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.RESIZE, NodeState.PENDING)//
|
.put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)//
|
.put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)//
|
.put(ServerStatus.PREP_MOVE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.PREP_MOVE, NodeState.PENDING)//
|
.put(ServerStatus.MOVE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.MOVE, NodeState.PENDING)//
|
.put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)//
|
.put(ServerStatus.RESCUE, NodeState.PENDING)//
|
||||||
.put(ServerStatus.RESCUE, NodeState.PENDING)//
|
.put(ServerStatus.ERROR, NodeState.ERROR)//
|
||||||
.put(ServerStatus.ERROR, NodeState.ERROR)//
|
.put(ServerStatus.BUILD, NodeState.PENDING)//
|
||||||
.put(ServerStatus.BUILD, NodeState.PENDING)//
|
.put(ServerStatus.RESTORING, NodeState.PENDING)//
|
||||||
.put(ServerStatus.RESTORING, NodeState.PENDING)//
|
.put(ServerStatus.PASSWORD, NodeState.PENDING)//
|
||||||
.put(ServerStatus.PASSWORD, NodeState.PENDING)//
|
.put(ServerStatus.REBUILD, NodeState.PENDING)//
|
||||||
.put(ServerStatus.REBUILD, NodeState.PENDING)//
|
.put(ServerStatus.DELETE_IP, NodeState.PENDING)//
|
||||||
.put(ServerStatus.DELETE_IP, NodeState.PENDING)//
|
.put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)//
|
||||||
.put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)//
|
.put(ServerStatus.SHARE_IP, NodeState.PENDING)//
|
||||||
.put(ServerStatus.SHARE_IP, NodeState.PENDING)//
|
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
||||||
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
||||||
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
.put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build();
|
||||||
.put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -287,17 +279,14 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Size> provideSizes(CloudServersClient sync, Set<? extends Image> images,
|
protected Set<? extends Size> provideSizes(CloudServersClient sync, Set<? extends Image> images, Location location,
|
||||||
Location location, LogHolder holder,
|
LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
Function<ComputeMetadata, String> indexer) throws InterruptedException, TimeoutException, ExecutionException {
|
||||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
|
||||||
TimeoutException, ExecutionException {
|
|
||||||
final Set<Size> sizes = Sets.newHashSet();
|
final Set<Size> sizes = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing sizes");
|
holder.logger.debug(">> providing sizes");
|
||||||
for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) {
|
for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) {
|
||||||
sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location,
|
sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
||||||
null, ImmutableMap.<String, String> of(), from.getDisk() / 10, from.getRam(),
|
.<String, String> of(), from.getDisk() / 10, from.getRam(), from.getDisk(), ImagePredicates.any()));
|
||||||
from.getDisk(), ImagePredicates.any()));
|
|
||||||
}
|
}
|
||||||
holder.logger.debug("<< sizes(%d)", sizes.size());
|
holder.logger.debug("<< sizes(%d)", sizes.size());
|
||||||
return sizes;
|
return sizes;
|
||||||
|
@ -313,13 +302,12 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Image> provideImages(final CloudServersClient sync, Location location,
|
protected Set<? extends Image> provideImages(final CloudServersClient sync, Location location, LogHolder holder,
|
||||||
LogHolder holder, Function<ComputeMetadata, String> indexer)
|
Function<ComputeMetadata, String> indexer) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
throws InterruptedException, ExecutionException, TimeoutException {
|
|
||||||
final Set<Image> images = Sets.newHashSet();
|
final Set<Image> images = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing images");
|
holder.logger.debug(">> providing images");
|
||||||
for (final org.jclouds.rackspace.cloudservers.domain.Image from : sync
|
for (final org.jclouds.rackspace.cloudservers.domain.Image from : sync.listImages(ListOptions.Builder
|
||||||
.listImages(ListOptions.Builder.withDetails())) {
|
.withDetails())) {
|
||||||
OsFamily os = null;
|
OsFamily os = null;
|
||||||
Architecture arch = Architecture.X86_64;
|
Architecture arch = Architecture.X86_64;
|
||||||
String osDescription = "";
|
String osDescription = "";
|
||||||
|
@ -337,9 +325,10 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
holder.logger.debug("<< didn't match os(%s)", matcher.group(2));
|
holder.logger.debug("<< didn't match os(%s)", matcher.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
images.add(new ImageImpl(from.getId() + "", from.getName(), from.getId() + "", location,
|
images
|
||||||
null, ImmutableMap.<String, String> of(), from.getName(), version, os,
|
.add(new ImageImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
||||||
osDescription, arch, new Credentials("root", null)));
|
.<String, String> of(), from.getName(), version, os, osDescription, arch, new Credentials("root",
|
||||||
|
null)));
|
||||||
}
|
}
|
||||||
holder.logger.debug("<< images(%d)", images.size());
|
holder.logger.debug("<< images(%d)", images.size());
|
||||||
return images;
|
return images;
|
||||||
|
|
|
@ -49,8 +49,7 @@ import com.google.common.collect.Iterables;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
public static final Pattern SECOND_FIELD_DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern
|
public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
|
||||||
.compile("[^-]+-([^-]+)-[0-9a-f]+");
|
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final Map<ServerStatus, NodeState> serverToNodeState;
|
private final Map<ServerStatus, NodeState> serverToNodeState;
|
||||||
private final Set<? extends Image> images;
|
private final Set<? extends Image> images;
|
||||||
|
@ -70,14 +69,13 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId() + "")
|
return input.getProviderId().equals(instance.getImageId() + "")
|
||||||
&& (input.getLocation() == null || input.getLocation().equals(
|
&& (input.getLocation() == null || input.getLocation().equals(location.getParent()));
|
||||||
location.getParent()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState,
|
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Set<? extends Image> images,
|
||||||
Set<? extends Image> images, Location location) {
|
Location location) {
|
||||||
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.location = checkNotNull(location, "location");
|
this.location = checkNotNull(location, "location");
|
||||||
|
@ -85,22 +83,17 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Server from) {
|
public NodeMetadata apply(Server from) {
|
||||||
Matcher matcher = SECOND_FIELD_DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from
|
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from.getName());
|
||||||
.getName());
|
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
final String tag = matcher.find() ? matcher.group(1) : null;
|
||||||
Location host = new LocationImpl(LocationScope.HOST, from.getHostId(), from.getHostId(),
|
Location host = new LocationImpl(LocationScope.HOST, from.getHostId(), from.getHostId(), location);
|
||||||
location);
|
|
||||||
Image image = null;
|
Image image = null;
|
||||||
try {
|
try {
|
||||||
image = Iterables.find(images, new FindImageForServer(host, from));
|
image = Iterables.find(images, new FindImageForServer(host, from));
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
logger
|
logger.warn("could not find a matching image for server %s in location %s", from, location);
|
||||||
.warn("could not find a matching image for server %s in location %s", from,
|
|
||||||
location);
|
|
||||||
}
|
}
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null,
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null, from.getMetadata(),
|
||||||
from.getMetadata(), tag, image, serverToNodeState.get(from.getStatus()), from
|
tag, image, serverToNodeState.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from
|
||||||
.getAddresses().getPublicAddresses(), from.getAddresses()
|
.getAddresses().getPrivateAddresses(), ImmutableMap.<String, String> of(), null);
|
||||||
.getPrivateAddresses(), ImmutableMap.<String, String> of(), null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue