diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java deleted file mode 100644 index 98a3146bc6..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.config; - -import org.jclouds.compute.config.BindComputeStrategiesByClass; -import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; -import org.jclouds.compute.strategy.DestroyNodeStrategy; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.ListNodesStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.compute.strategy.ResumeNodeStrategy; -import org.jclouds.compute.strategy.SuspendNodeStrategy; -import org.jclouds.cloudservers.compute.strategy.CloudServersCreateNodeWithGroupEncodedIntoName; -import org.jclouds.cloudservers.compute.strategy.CloudServersDestroyNodeStrategy; -import org.jclouds.cloudservers.compute.strategy.CloudServersGetNodeMetadataStrategy; -import org.jclouds.cloudservers.compute.strategy.CloudServersListNodesStrategy; -import org.jclouds.cloudservers.compute.strategy.CloudServersLifeCycleStrategy; - -/** - * - * @author Adrian Cole - * - */ -public class CloudServersBindComputeStrategiesByClass extends BindComputeStrategiesByClass { - - @Override - protected Class defineAddNodeWithTagStrategy() { - return CloudServersCreateNodeWithGroupEncodedIntoName.class; - } - - @Override - protected Class defineDestroyNodeStrategy() { - return CloudServersDestroyNodeStrategy.class; - } - - @Override - protected Class defineGetNodeMetadataStrategy() { - return CloudServersGetNodeMetadataStrategy.class; - } - - @Override - protected Class defineListNodesStrategy() { - return CloudServersListNodesStrategy.class; - } - - @Override - protected Class defineRebootNodeStrategy() { - return CloudServersLifeCycleStrategy.class; - } - - @Override - protected Class defineStartNodeStrategy() { - return CloudServersLifeCycleStrategy.class; - } - - @Override - protected Class defineStopNodeStrategy() { - return CloudServersLifeCycleStrategy.class; - } -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersBindComputeSuppliersByClass.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersBindComputeSuppliersByClass.java deleted file mode 100644 index 47695d1239..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersBindComputeSuppliersByClass.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.config; - -import java.util.Set; - -import org.jclouds.cloudservers.compute.suppliers.CloudServersHardwareSupplier; -import org.jclouds.cloudservers.compute.suppliers.CloudServersImageSupplier; -import org.jclouds.compute.config.BindComputeSuppliersByClass; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.domain.Location; -import org.jclouds.location.suppliers.JustProvider; - -import com.google.common.base.Supplier; - -/** - * - * @author Adrian Cole - * - */ -public class CloudServersBindComputeSuppliersByClass extends BindComputeSuppliersByClass { - @Override - protected Class>> defineHardwareSupplier() { - return CloudServersHardwareSupplier.class; - } - - @Override - protected Class>> defineImageSupplier() { - return CloudServersImageSupplier.class; - } - - @Override - protected Class>> defineLocationSupplier() { - return JustProvider.class; - } -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index ff7a89183c..8400689e79 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -18,8 +18,38 @@ */ package org.jclouds.cloudservers.compute.config; -import org.jclouds.compute.config.BaseComputeServiceContextModule; +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.cloudservers.CloudServersAsyncClient; +import org.jclouds.cloudservers.CloudServersClient; +import org.jclouds.cloudservers.compute.functions.CloudServersImageToImage; +import org.jclouds.cloudservers.compute.functions.CloudServersImageToOperatingSystem; +import org.jclouds.cloudservers.compute.functions.FlavorToHardware; +import org.jclouds.cloudservers.compute.functions.ServerToNodeMetadata; +import org.jclouds.cloudservers.compute.strategy.CloudServersComputeServiceAdapter; +import org.jclouds.cloudservers.domain.Flavor; +import org.jclouds.cloudservers.domain.Server; +import org.jclouds.cloudservers.domain.ServerStatus; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.internal.BaseComputeService; +import org.jclouds.domain.Location; +import org.jclouds.functions.IdentityFunction; +import org.jclouds.location.suppliers.OnlyLocationOrFirstZone; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; /** * Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService} @@ -27,14 +57,72 @@ import org.jclouds.compute.internal.BaseComputeService; * * @author Adrian Cole */ -public class CloudServersComputeServiceContextModule extends BaseComputeServiceContextModule { +public class CloudServersComputeServiceContextModule + extends + ComputeServiceAdapterContextModule { + public CloudServersComputeServiceContextModule() { + super(CloudServersClient.class, CloudServersAsyncClient.class); + } + @SuppressWarnings("unchecked") @Override protected void configure() { - install(new CloudServersComputeServiceDependenciesModule()); - install(new CloudServersBindComputeStrategiesByClass()); - install(new CloudServersBindComputeSuppliersByClass()); super.configure(); + bind(new TypeLiteral>() { + }).to(CloudServersComputeServiceAdapter.class); + + bind(new TypeLiteral>() { + }).to(ServerToNodeMetadata.class); + + bind(new TypeLiteral>() { + }).to(CloudServersImageToImage.class); + bind(new TypeLiteral>() { + }).to(CloudServersImageToOperatingSystem.class); + + bind(new TypeLiteral>() { + }).to(FlavorToHardware.class); + + // we aren't converting location from a provider-specific type + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + + // there are no locations except the provider + bind(new TypeLiteral>() { + }).to(OnlyLocationOrFirstZone.class); + + } + + @VisibleForTesting + public static final Map serverToNodeState = ImmutableMap + . builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)// + .put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)// + .put(ServerStatus.DELETED, NodeState.TERMINATED)// + .put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)// + .put(ServerStatus.PREP_RESIZE, NodeState.PENDING)// + .put(ServerStatus.RESIZE, NodeState.PENDING)// + .put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)// + .put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)// + .put(ServerStatus.PREP_MOVE, NodeState.PENDING)// + .put(ServerStatus.MOVE, NodeState.PENDING)// + .put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)// + .put(ServerStatus.RESCUE, NodeState.PENDING)// + .put(ServerStatus.ERROR, NodeState.ERROR)// + .put(ServerStatus.BUILD, NodeState.PENDING)// + .put(ServerStatus.RESTORING, NodeState.PENDING)// + .put(ServerStatus.PASSWORD, NodeState.PENDING)// + .put(ServerStatus.REBUILD, NodeState.PENDING)// + .put(ServerStatus.DELETE_IP, NodeState.PENDING)// + .put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)// + .put(ServerStatus.SHARE_IP, NodeState.PENDING)// + .put(ServerStatus.REBOOT, NodeState.PENDING)// + .put(ServerStatus.HARD_REBOOT, NodeState.PENDING)// + .put(ServerStatus.UNKNOWN, NodeState.UNRECOGNIZED)// + .put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); + + @Singleton + @Provides + Map provideServerToNodeState() { + return serverToNodeState; } } diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceDependenciesModule.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceDependenciesModule.java deleted file mode 100644 index dd351e0f85..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceDependenciesModule.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.config; - -import java.util.Map; - -import javax.inject.Singleton; - -import org.jclouds.cloudservers.CloudServersAsyncClient; -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.compute.functions.CloudServersImageToImage; -import org.jclouds.cloudservers.compute.functions.CloudServersImageToOperatingSystem; -import org.jclouds.cloudservers.compute.functions.FlavorToHardware; -import org.jclouds.cloudservers.compute.functions.ServerToNodeMetadata; -import org.jclouds.cloudservers.domain.Flavor; -import org.jclouds.cloudservers.domain.Server; -import org.jclouds.cloudservers.domain.ServerStatus; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.internal.BaseComputeService; -import org.jclouds.compute.internal.ComputeServiceContextImpl; -import org.jclouds.rest.RestContext; -import org.jclouds.rest.internal.RestContextImpl; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.Scopes; -import com.google.inject.TypeLiteral; - -/** - * Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService} - * bound. - * - * @author Adrian Cole - */ -public class CloudServersComputeServiceDependenciesModule extends AbstractModule { - - @Override - protected void configure() { - bind(new TypeLiteral>() { - }).to(ServerToNodeMetadata.class); - - bind(new TypeLiteral>() { - }).to(CloudServersImageToImage.class); - - bind(new TypeLiteral>() { - }).to(CloudServersImageToOperatingSystem.class); - - bind(new TypeLiteral>() { - }).to(FlavorToHardware.class); - - bind(new TypeLiteral() { - }).to(new TypeLiteral>() { - }).in(Scopes.SINGLETON); - bind(new TypeLiteral>() { - }).to(new TypeLiteral>() { - }).in(Scopes.SINGLETON); - } - - @VisibleForTesting - public static final Map serverToNodeState = ImmutableMap - . builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)// - .put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)// - .put(ServerStatus.DELETED, NodeState.TERMINATED)// - .put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)// - .put(ServerStatus.PREP_RESIZE, NodeState.PENDING)// - .put(ServerStatus.RESIZE, NodeState.PENDING)// - .put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)// - .put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)// - .put(ServerStatus.PREP_MOVE, NodeState.PENDING)// - .put(ServerStatus.MOVE, NodeState.PENDING)// - .put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)// - .put(ServerStatus.RESCUE, NodeState.PENDING)// - .put(ServerStatus.ERROR, NodeState.ERROR)// - .put(ServerStatus.BUILD, NodeState.PENDING)// - .put(ServerStatus.RESTORING, NodeState.PENDING)// - .put(ServerStatus.PASSWORD, NodeState.PENDING)// - .put(ServerStatus.REBUILD, NodeState.PENDING)// - .put(ServerStatus.DELETE_IP, NodeState.PENDING)// - .put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)// - .put(ServerStatus.SHARE_IP, NodeState.PENDING)// - .put(ServerStatus.REBOOT, NodeState.PENDING)// - .put(ServerStatus.HARD_REBOOT, NodeState.PENDING)// - .put(ServerStatus.UNKNOWN, NodeState.UNRECOGNIZED)// - .put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); - - @Singleton - @Provides - Map provideServerToNodeState() { - return serverToNodeState; - } - -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersComputeServiceAdapter.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersComputeServiceAdapter.java new file mode 100644 index 0000000000..da2bdb96e6 --- /dev/null +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersComputeServiceAdapter.java @@ -0,0 +1,122 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudservers.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.cloudservers.options.CreateServerOptions.Builder.withMetadata; +import static org.jclouds.cloudservers.options.ListOptions.Builder.withDetails; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.cloudservers.CloudServersClient; +import org.jclouds.cloudservers.domain.Flavor; +import org.jclouds.cloudservers.domain.Image; +import org.jclouds.cloudservers.domain.RebootType; +import org.jclouds.cloudservers.domain.Server; +import org.jclouds.cloudservers.options.ListOptions; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.Location; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.location.suppliers.JustProvider; + +/** + * defines the connection between the {@link CloudServersClient} implementation and the jclouds + * {@link ComputeService} + * + */ +@Singleton +public class CloudServersComputeServiceAdapter implements ComputeServiceAdapter { + + protected final CloudServersClient client; + protected final JustProvider locationSupplier; + + @Inject + protected CloudServersComputeServiceAdapter(CloudServersClient client, JustProvider locationSupplier) { + this.client = checkNotNull(client, "client"); + this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); + + } + + @Override + public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName(String group, String name, + Template template) { + Server server = client + .createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template + .getHardware().getProviderId()), withMetadata(template.getOptions().getUserMetadata())); + + return new NodeAndInitialCredentials(server, server.getId() + "", LoginCredentials.builder().password( + server.getAdminPass()).build()); + } + + @Override + public Iterable listHardwareProfiles() { + return client.listFlavors(withDetails()); + + } + + @Override + public Iterable listImages() { + return client.listImages(withDetails()); + } + + @Override + public Iterable listNodes() { + return client.listServers(ListOptions.Builder.withDetails()); + } + + @SuppressWarnings("unchecked") + @Override + public Iterable listLocations() { + return (Iterable) locationSupplier.get(); + } + + @Override + public Server getNode(String id) { + int serverId = Integer.parseInt(id); + return client.getServer(serverId); + } + + @Override + public void destroyNode(String id) { + int serverId = Integer.parseInt(id); + // if false server wasn't around in the first place + client.deleteServer(serverId); + } + + @Override + public void rebootNode(String id) { + int serverId = Integer.parseInt(id); + // if false server wasn't around in the first place + client.rebootServer(serverId, RebootType.HARD); + } + + @Override + public void resumeNode(String id) { + throw new UnsupportedOperationException("suspend not supported"); + } + + @Override + public void suspendNode(String id) { + throw new UnsupportedOperationException("suspend not supported"); + } + +} \ No newline at end of file diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersCreateNodeWithGroupEncodedIntoName.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersCreateNodeWithGroupEncodedIntoName.java deleted file mode 100644 index 5a68faff3a..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersCreateNodeWithGroupEncodedIntoName.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.strategy; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static org.jclouds.cloudservers.options.CreateServerOptions.Builder.withMetadata; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.domain.Server; -import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; -import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; -import org.jclouds.domain.Credentials; -import org.jclouds.domain.LoginCredentials; - -import com.google.common.base.Function; - -/** - * @author Adrian Cole - */ -@Singleton -public class CloudServersCreateNodeWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName { - protected final CloudServersClient client; - protected final Map credentialStore; - protected final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate; - protected final Function serverToNodeMetadata; - - @Inject - protected CloudServersCreateNodeWithGroupEncodedIntoName(CloudServersClient client, - Map credentialStore, - PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate, - Function serverToNodeMetadata) { - this.client = checkNotNull(client, "client"); - this.credentialStore = checkNotNull(credentialStore, "credentialStore"); - this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata"); - this.prioritizeCredentialsFromTemplate = checkNotNull(prioritizeCredentialsFromTemplate, - "prioritizeCredentialsFromTemplate"); - } - - @Override - public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) { - checkState(group != null, "group (that which groups identical nodes together) must be specified"); - checkState(name != null && name.indexOf(group) != -1, "name should have %s encoded into it", group); - checkState(template != null, "template must be specified"); - - Server server = client - .createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template - .getHardware().getProviderId()), withMetadata(template.getOptions().getUserMetadata())); - - NodeAndInitialCredentials from = new NodeAndInitialCredentials(server, server.getId() + "", - LoginCredentials.builder().password(server.getAdminPass()).build()); - - LoginCredentials fromNode = from.getCredentials(); - LoginCredentials creds = prioritizeCredentialsFromTemplate.apply(template, fromNode); - if (creds != null) - credentialStore.put("node#" + from.getNodeId(), creds); - NodeMetadata node = serverToNodeMetadata.apply(from.getNode()); - return node; - } - -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersDestroyNodeStrategy.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersDestroyNodeStrategy.java deleted file mode 100644 index c0c7058882..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersDestroyNodeStrategy.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.DestroyNodeStrategy; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.cloudservers.CloudServersClient; - -/** - * @author Adrian Cole - */ -@Singleton -public class CloudServersDestroyNodeStrategy implements DestroyNodeStrategy { - private final CloudServersClient client; - private final GetNodeMetadataStrategy getNode; - - @Inject - protected CloudServersDestroyNodeStrategy(CloudServersClient client, GetNodeMetadataStrategy getNode) { - this.client = client; - this.getNode = getNode; - } - - @Override - public NodeMetadata destroyNode(String id) { - int serverId = Integer.parseInt(id); - // if false server wasn't around in the first place - client.deleteServer(serverId); - return getNode.getNode(id); - } - -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersGetNodeMetadataStrategy.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersGetNodeMetadataStrategy.java deleted file mode 100644 index 1347285ae4..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersGetNodeMetadataStrategy.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.strategy; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.domain.Server; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.domain.Credentials; -import org.jclouds.domain.LoginCredentials; - -import com.google.common.base.Function; -import com.google.common.base.Functions; - -/** - * @author Adrian Cole - */ -@Singleton -public class CloudServersGetNodeMetadataStrategy implements GetNodeMetadataStrategy { - - private final CloudServersClient client; - private final Map credentialStore; - private final Function nodeMetadataAdapter; - - @Inject - protected CloudServersGetNodeMetadataStrategy(CloudServersClient client, Map credentialStore, - Function nodeMetadataAdapter) { - this.client = client; - this.credentialStore = credentialStore; - this.nodeMetadataAdapter = Functions.compose(addLoginCredentials, checkNotNull(nodeMetadataAdapter, - "nodeMetadataAdapter")); - } - - private final Function addLoginCredentials = new Function() { - - @Override - public NodeMetadata apply(NodeMetadata arg0) { - return credentialStore.containsKey("node#" + arg0.getId()) ? NodeMetadataBuilder.fromNodeMetadata(arg0) - .credentials(LoginCredentials.fromCredentials(credentialStore.get("node#" + arg0.getId()))).build() - : arg0; - } - - @Override - public String toString() { - return "addLoginCredentialsFromCredentialStore()"; - } - }; - - @Override - public NodeMetadata getNode(String id) { - int serverId = Integer.parseInt(id); - Server server = client.getServer(serverId); - return server == null ? null : nodeMetadataAdapter.apply(server); - } -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersLifeCycleStrategy.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersLifeCycleStrategy.java deleted file mode 100644 index 5871b4ca77..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersLifeCycleStrategy.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.compute.strategy.ResumeNodeStrategy; -import org.jclouds.compute.strategy.SuspendNodeStrategy; -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.domain.RebootType; - -/** - * @author Adrian Cole - */ -@Singleton -public class CloudServersLifeCycleStrategy implements RebootNodeStrategy, SuspendNodeStrategy, ResumeNodeStrategy { - private final CloudServersClient client; - private final GetNodeMetadataStrategy getNode; - - @Inject - protected CloudServersLifeCycleStrategy(CloudServersClient client, GetNodeMetadataStrategy getNode) { - this.client = client; - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String id) { - int serverId = Integer.parseInt(id); - // if false server wasn't around in the first place - client.rebootServer(serverId, RebootType.HARD); - return getNode.getNode(id); - } - - @Override - public NodeMetadata suspendNode(String id) { - throw new UnsupportedOperationException("suspend not supported"); - } - - @Override - public NodeMetadata resumeNode(String id) { - throw new UnsupportedOperationException("resume not supported"); - } - -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersListNodesStrategy.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersListNodesStrategy.java deleted file mode 100644 index 72c81d7189..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/strategy/CloudServersListNodesStrategy.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.ComputeMetadata; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.predicates.NodePredicates; -import org.jclouds.compute.strategy.ListNodesStrategy; -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.domain.Server; -import org.jclouds.cloudservers.options.ListOptions; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -/** - * @author Adrian Cole - */ -@Singleton -public class CloudServersListNodesStrategy implements ListNodesStrategy { - private final CloudServersClient client; - private final Function serverToNodeMetadata; - - @Inject - protected CloudServersListNodesStrategy(CloudServersClient client, - Function serverToNodeMetadata) { - this.client = client; - this.serverToNodeMetadata = serverToNodeMetadata; - } - - @Override - public Iterable listNodes() { - return listDetailsOnNodesMatching(NodePredicates.all()); - } - - @Override - public Iterable listDetailsOnNodesMatching(Predicate filter) { - return Iterables.filter(Iterables.transform(client.listServers(ListOptions.Builder.withDetails()), - serverToNodeMetadata), filter); - } -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/suppliers/CloudServersHardwareSupplier.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/suppliers/CloudServersHardwareSupplier.java deleted file mode 100644 index efa57a2f35..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/suppliers/CloudServersHardwareSupplier.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.suppliers; - -import static org.jclouds.cloudservers.options.ListOptions.Builder.withDetails; - -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.domain.Flavor; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class CloudServersHardwareSupplier implements Supplier> { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - private final CloudServersClient sync; - private final Function flavorToHardware; - - @Inject - CloudServersHardwareSupplier(CloudServersClient sync, Function flavorToHardware) { - this.sync = sync; - this.flavorToHardware = flavorToHardware; - } - - @Override - public Set get() { - final Set hardware; - logger.debug(">> providing hardware"); - hardware = Sets.newLinkedHashSet(Iterables.transform(sync.listFlavors(withDetails()), flavorToHardware)); - logger.debug("<< hardware(%d)", hardware.size()); - return hardware; - } -} diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/suppliers/CloudServersImageSupplier.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/suppliers/CloudServersImageSupplier.java deleted file mode 100644 index 220e1ec49f..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/suppliers/CloudServersImageSupplier.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudservers.compute.suppliers; - -import static org.jclouds.cloudservers.options.ListOptions.Builder.withDetails; - -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.compute.config.ComputeServiceAdapterContextModule.AddDefaultCredentialsToImage; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.base.Supplier; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class CloudServersImageSupplier implements Supplier> { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - protected final CloudServersClient sync; - protected final Function cloudServersImageToImage; - protected final AddDefaultCredentialsToImage addDefaultCredentialsToImage; - - @Inject - CloudServersImageSupplier(CloudServersClient sync, - Function cloudServersImageToImage, - AddDefaultCredentialsToImage addDefaultCredentialsToImage) { - this.sync = sync; - this.cloudServersImageToImage = cloudServersImageToImage; - this.addDefaultCredentialsToImage = addDefaultCredentialsToImage; - } - - @Override - public Set get() { - Set images; - logger.debug(">> providing images"); - images = Sets. newLinkedHashSet(Iterables.transform(sync.listImages(withDetails()), Functions.compose( - addDefaultCredentialsToImage, cloudServersImageToImage))); - logger.debug("<< images(%d)", images.size()); - return images; - } -} diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java index 7df973afa5..7835e6beee 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.cloudservers; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.cloudservers.options.CreateServerOptions.Builder.withFile; import static org.jclouds.cloudservers.options.CreateSharedIpGroupOptions.Builder.withServer; import static org.jclouds.cloudservers.options.ListOptions.Builder.withDetails; @@ -34,7 +33,6 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.Constants; import org.jclouds.cloudservers.domain.BackupSchedule; import org.jclouds.cloudservers.domain.DailyBackup; import org.jclouds.cloudservers.domain.Flavor; @@ -47,6 +45,7 @@ import org.jclouds.cloudservers.domain.ServerStatus; import org.jclouds.cloudservers.domain.SharedIpGroup; import org.jclouds.cloudservers.domain.WeeklyBackup; import org.jclouds.cloudservers.options.RebuildServerOptions; +import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; @@ -65,6 +64,7 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -76,39 +76,15 @@ import com.google.inject.Module; * * @author Adrian Cole */ -// disabled [Web Hosting #129069 -@Test(groups = "live", sequential = true) -public class CloudServersClientLiveTest { +@Test(groups = "live", singleThreaded = true, testName = "CloudServersClientLiveTest") +public class CloudServersClientLiveTest extends BaseVersionedServiceLiveTest { + public CloudServersClientLiveTest() { + provider = "cloudservers"; + } protected CloudServersClient client; protected SshClient.Factory sshFactory; - private Predicate socketTester; - protected String provider = "cloudservers"; - protected String identity; - protected String credential; - protected String endpoint; - protected String apiversion; - - protected void setupCredentials() { - identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); - endpoint = System.getProperty("test." + provider + ".endpoint"); - apiversion = System.getProperty("test." + provider + ".apiversion"); - } - - protected Properties setupProperties() { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - if (endpoint != null) - overrides.setProperty(provider + ".endpoint", endpoint); - if (apiversion != null) - overrides.setProperty(provider + ".apiversion", apiversion); - return overrides; - } + protected Predicate socketTester; @BeforeGroups(groups = { "live" }) public void setupClient() { @@ -116,7 +92,8 @@ public class CloudServersClientLiveTest { Properties overrides = setupProperties(); Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides).buildInjector(); + ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides) + .buildInjector(); client = injector.getInstance(CloudServersClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); @@ -178,13 +155,8 @@ public class CloudServersClientLiveTest { long imageCount = response.size(); assertTrue(imageCount >= 0); for (Image image : response) { - try { - Image newDetails = client.getImage(image.getId()); - assertEquals(image, newDetails); - } catch (HttpResponseException e) {// Ticket #9867 - if (e.getResponse().getStatusCode() != 400) - throw e; - } + Image newDetails = client.getImage(image.getId()); + assertEquals(image, newDetails); } } @@ -290,7 +262,7 @@ public class CloudServersClientLiveTest { assert client.getSharedIpGroup(12312987) == null; } - @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testCreateSharedIpGroup() throws Exception { SharedIpGroup sharedIpGroup = null; while (sharedIpGroup == null) { @@ -307,7 +279,7 @@ public class CloudServersClientLiveTest { assertNotNull(sharedIpGroup.getName()); sharedIpGroupId = sharedIpGroup.getId(); // Response doesn't include the server id Web Hosting #119311 - // assertEquals(sharedIpGroup.getServers(), ImmutableList.of(serverId)); + assert !sharedIpGroup.getServers().equals(ImmutableList.of(serverId)); } private int sharedIpGroupId; @@ -321,7 +293,6 @@ public class CloudServersClientLiveTest { private String adminPass2; private int imageId; - @Test(enabled = false) public void testCreateServer() throws Exception { int imageId = 14362; int flavorId = 1; @@ -329,8 +300,8 @@ public class CloudServersClientLiveTest { while (server == null) { String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt(); try { - server = client.createServer(serverName, imageId, flavorId, - withFile("/etc/jclouds.txt", "rackspace".getBytes()).withMetadata(metadata)); + server = client.createServer(serverName, imageId, flavorId, withFile("/etc/jclouds.txt", + "rackspace".getBytes()).withMetadata(metadata)); } catch (UndeclaredThrowableException e) { HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); if (htpe.getResponse().getStatusCode() == 400) @@ -349,7 +320,7 @@ public class CloudServersClientLiveTest { private void blockUntilServerActive(int serverId) throws InterruptedException { Server currentDetails = null; for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client - .getServer(serverId)) { + .getServer(serverId)) { System.out.printf("blocking on status active%n%s%n", currentDetails); Thread.sleep(5 * 1000); } @@ -358,7 +329,7 @@ public class CloudServersClientLiveTest { private void blockUntilServerVerifyResize(int serverId) throws InterruptedException { Server currentDetails = null; for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.VERIFY_RESIZE; currentDetails = client - .getServer(serverId)) { + .getServer(serverId)) { System.out.printf("blocking on status verify resize%n%s%n", currentDetails); Thread.sleep(5 * 1000); } @@ -367,13 +338,13 @@ public class CloudServersClientLiveTest { private void blockUntilImageActive(int imageId) throws InterruptedException { Image currentDetails = null; for (currentDetails = client.getImage(imageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client - .getImage(imageId)) { + .getImage(imageId)) { System.out.printf("blocking on status active%n%s%n", currentDetails); Thread.sleep(5 * 1000); } } - @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testServerDetails() throws Exception { Server server = client.getServer(serverId); @@ -440,7 +411,7 @@ public class CloudServersClientLiveTest { } } - @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testRenameServer() throws Exception { Server server = client.getServer(serverId); String oldName = server.getName(); @@ -449,7 +420,7 @@ public class CloudServersClientLiveTest { assertEquals(oldName + "new", client.getServer(serverId).getName()); } - @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") + @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") public void testChangePassword() throws Exception { client.changeAdminPass(serverId, "elmo"); blockUntilServerActive(serverId); @@ -457,7 +428,7 @@ public class CloudServersClientLiveTest { this.adminPass = "elmo"; } - @Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateSharedIpGroup") + @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateSharedIpGroup") public void testCreateServerIp() throws Exception { int imageId = 14362; int flavorId = 1; @@ -465,12 +436,9 @@ public class CloudServersClientLiveTest { while (server == null) { String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt(); try { - server = client.createServer( - serverName, - imageId, - flavorId, - withFile("/etc/jclouds.txt", "rackspace".getBytes()).withMetadata(metadata) - .withSharedIpGroup(sharedIpGroupId).withSharedIp(ip)); + server = client + .createServer(serverName, imageId, flavorId, withFile("/etc/jclouds.txt", "rackspace".getBytes()) + .withMetadata(metadata).withSharedIpGroup(sharedIpGroupId).withSharedIp(ip)); } catch (UndeclaredThrowableException e) { HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); if (htpe.getResponse().getStatusCode() == 400) @@ -491,7 +459,7 @@ public class CloudServersClientLiveTest { try { ExecResponse response = exec(server, password, "ifconfig -a"); assert response.getOutput().indexOf(ip) > 0 : String.format("server %s didn't get ip %s%n%s", server, ip, - response); + response); } catch (Exception e) { e.printStackTrace(); } catch (AssertionError e) { @@ -499,7 +467,7 @@ public class CloudServersClientLiveTest { } } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp") public void testUnshare() throws Exception { client.unshareIp(ip, serverId2); blockUntilServerActive(serverId2); @@ -512,7 +480,7 @@ public class CloudServersClientLiveTest { try { ExecResponse response = exec(server, password, "ifconfig -a"); assert response.getOutput().indexOf(ip) == -1 : String.format("server %s still has get ip %s%n%s", server, ip, - response); + response); } catch (Exception e) { e.printStackTrace(); } catch (AssertionError e) { @@ -520,7 +488,7 @@ public class CloudServersClientLiveTest { } } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testUnshare") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testUnshare") public void testShareConfig() throws Exception { client.shareIp(ip, serverId2, sharedIpGroupId, true); blockUntilServerActive(serverId2); @@ -530,7 +498,7 @@ public class CloudServersClientLiveTest { testUnshare(); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareConfig") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareConfig") public void testShareNoConfig() throws Exception { client.shareIp(ip, serverId2, sharedIpGroupId, false); blockUntilServerActive(serverId2); @@ -540,7 +508,7 @@ public class CloudServersClientLiveTest { testUnshare(); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig") public void testBackup() throws Exception { assertEquals(new BackupSchedule(), client.getBackupSchedule(serverId)); BackupSchedule dailyWeekly = new BackupSchedule(); @@ -553,7 +521,7 @@ public class CloudServersClientLiveTest { assertEquals(client.getBackupSchedule(serverId).isEnabled(), false); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup") public void testCreateImage() throws Exception { Image image = client.createImageFromServer("hoofie", serverId); assertEquals("hoofie", image.getName()); @@ -562,27 +530,27 @@ public class CloudServersClientLiveTest { blockUntilImageActive(imageId); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage") public void testRebuildServer() throws Exception { client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId)); blockUntilServerActive(serverId); // issue Web Hosting #119580 imageId comes back incorrect after rebuild - // assertEquals(new Integer(imageId), client.getServer(serverId).getImageId()); + assert !new Integer(imageId).equals(client.getServer(serverId).getImageId()); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer") public void testRebootHard() throws Exception { client.rebootServer(serverId, RebootType.HARD); blockUntilServerActive(serverId); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard") public void testRebootSoft() throws Exception { client.rebootServer(serverId, RebootType.SOFT); blockUntilServerActive(serverId); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") public void testRevertResize() throws Exception { client.resizeServer(serverId, 2); blockUntilServerVerifyResize(serverId); @@ -591,7 +559,7 @@ public class CloudServersClientLiveTest { assertEquals(new Integer(1), client.getServer(serverId).getFlavorId()); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") public void testConfirmResize() throws Exception { client.resizeServer(serverId2, 2); blockUntilServerVerifyResize(serverId2); @@ -600,8 +568,7 @@ public class CloudServersClientLiveTest { assertEquals(new Integer(2), client.getServer(serverId2).getFlavorId()); } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", - "testConfirmResize" }) + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", "testConfirmResize" }) void deleteServer2() { if (serverId2 > 0) { client.deleteServer(serverId2); @@ -609,7 +576,7 @@ public class CloudServersClientLiveTest { } } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2") void testDeleteImage() { if (imageId > 0) { client.deleteImage(imageId); @@ -617,7 +584,7 @@ public class CloudServersClientLiveTest { } } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage") + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage") void deleteServer1() { if (serverId > 0) { client.deleteServer(serverId); @@ -625,7 +592,7 @@ public class CloudServersClientLiveTest { } } - @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = { "deleteServer1" }) + @Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "deleteServer1" }) void testDeleteSharedIpGroup() { if (sharedIpGroupId > 0) { client.deleteSharedIpGroup(sharedIpGroupId); diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java index 2b8b8f72be..b39995a26b 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java @@ -24,13 +24,13 @@ import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "CloudServersComputeServiceContextModuleTest") public class CloudServersComputeServiceContextModuleTest { public void testAllStatusCovered() { for (ServerStatus state : ServerStatus.values()) { - assert CloudServersComputeServiceDependenciesModule.serverToNodeState.containsKey(state) : state; + assert CloudServersComputeServiceContextModule.serverToNodeState.containsKey(state) : state; } } diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java index eaa4b574a1..6949e315b5 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java @@ -20,11 +20,10 @@ package org.jclouds.cloudservers.compute.functions; import static org.testng.Assert.assertEquals; -import java.net.UnknownHostException; import java.util.Map; import java.util.Set; -import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceDependenciesModule; +import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceContextModule; import org.jclouds.cloudservers.domain.Server; import org.jclouds.cloudservers.domain.ServerStatus; import org.jclouds.cloudservers.functions.ParseServerFromJsonResponseTest; @@ -57,8 +56,8 @@ public class ServerToNodeMetadataTest { Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build(); @Test - public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException { - Map serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState; + public void testApplyWhereImageAndHardwareNotFound() { + Map serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState; Set images = ImmutableSet.of(); Set hardwares = ImmutableSet.of(); Server server = ParseServerFromJsonResponseTest.parseServer(); @@ -87,8 +86,8 @@ public class ServerToNodeMetadataTest { } @Test - public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException { - Map serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState; + public void testApplyWhereImageFoundAndHardwareNotFound() { + Map serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState; org.jclouds.compute.domain.Image jcImage = CloudServersImageToImageTest.convertImage(); Set images = ImmutableSet.of(jcImage); Set hardwares = ImmutableSet.of(); @@ -121,8 +120,8 @@ public class ServerToNodeMetadataTest { } @Test - public void testApplyWhereImageAndHardwareFound() throws UnknownHostException { - Map serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState; + public void testApplyWhereImageAndHardwareFound() { + Map serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState; Set images = ImmutableSet.of(CloudServersImageToImageTest.convertImage()); Set hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor()); Server server = ParseServerFromJsonResponseTest.parseServer();