diff --git a/apis/openstack-nova/pom.xml b/apis/openstack-nova/pom.xml index 75a8095730..1a3de0e14a 100644 --- a/apis/openstack-nova/pom.xml +++ b/apis/openstack-nova/pom.xml @@ -27,7 +27,7 @@ org.apache.jclouds.api openstack-nova - jclouds openstack-nova api + Apache jclouds :: OpenStack :: Nova API jclouds components to access an implementation of OpenStack Nova bundle diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java index 6586395f35..c2161b9d67 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.jclouds.openstack.nova.v2_0.compute; + import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED; @@ -61,8 +62,8 @@ import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions; import org.jclouds.openstack.nova.v2_0.domain.KeyPair; import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi; import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi; import org.jclouds.openstack.nova.v2_0.predicates.SecurityGroupPredicates; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java index cabca593ef..029c374f54 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java @@ -71,11 +71,11 @@ import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule; import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.FlavorInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ImageInRegion; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion; import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue; import com.google.common.annotations.VisibleForTesting; @@ -108,9 +108,9 @@ public class NovaComputeServiceContextModule extends super.configure(); bind(new TypeLiteral>() { }).to(NovaComputeServiceAdapter.class); - + bind(ComputeService.class).to(NovaComputeService.class); - + bind(new TypeLiteral>() { }).to(ServerInRegionToNodeMetadata.class); @@ -154,7 +154,7 @@ public class NovaComputeServiceContextModule extends bind(new TypeLiteral>() { }).to(CreateUniqueKeyPair.class); - + bind(new TypeLiteral() { }).to(NovaImageExtension.class); @@ -185,7 +185,7 @@ public class NovaComputeServiceContextModule extends CacheLoader in) { return CacheBuilder.newBuilder().build(in); } - + @Override protected Map osFamilyToCredentials(Injector injector) { return ImmutableMap.of(OsFamily.WINDOWS, LoginCredentials.builder().user("Administrator").build(), @@ -264,7 +264,7 @@ public class NovaComputeServiceContextModule extends protected Map toPortableNodeStatus() { return toPortableNodeStatus; } - + @VisibleForTesting public static final Map toPortableImageStatus = ImmutableMap . builder() @@ -280,7 +280,7 @@ public class NovaComputeServiceContextModule extends protected Map toPortableImageStatus() { return toPortableImageStatus; } - + @Override protected Optional provideImageExtension(Injector i) { return Optional.of(i.getInstance(ImageExtension.class)); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java index 1de8fd8365..12b6b9146f 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.jclouds.openstack.nova.v2_0.compute.functions; + import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java index 4c2c8cc476..4e9b11cb1d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java @@ -32,8 +32,8 @@ import org.jclouds.net.domain.IpProtocol; import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.domain.Ingress; import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi; import com.google.common.base.Function; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInRegionToSecurityGroup.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInRegionToSecurityGroup.java index 08b4e2d8ea..33b641e48f 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInRegionToSecurityGroup.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInRegionToSecurityGroup.java @@ -36,7 +36,6 @@ import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.inject.Inject; - /** * A function for transforming a Nova-specific SecurityGroup into a generic * SecurityGroup object. diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroup.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroup.java index 6bd2e64fff..bdb7ba6a63 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroup.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroup.java @@ -32,7 +32,6 @@ import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule; import com.google.common.base.Function; import com.google.inject.Inject; - /** * A function for transforming a Nova-specific SecurityGroup into a generic * SecurityGroup object. @@ -44,7 +43,7 @@ public class NovaSecurityGroupToSecurityGroup implements Function ruleToPermission; - + @Inject public NovaSecurityGroupToSecurityGroup(Function ruleToPermission) { this.ruleToPermission = ruleToPermission; @@ -53,7 +52,7 @@ public class NovaSecurityGroupToSecurityGroup implements Function parts = Splitter.on('/').split(checkNotNull(id, "id")); checkArgument(Iterables.size(parts) == 2, "id must be in format regionId/id"); @@ -50,6 +53,14 @@ public class RegionAndId { this.id = checkNotNull(id, "id"); } + public String getRegion() { + return regionId; + } + + public String getId() { + return id; + } + @Override public int hashCode() { return Objects.hashCode(regionId, id); @@ -67,17 +78,13 @@ public class RegionAndId { return Objects.equal(regionId, other.regionId) && Objects.equal(id, other.id); } - public String getRegion() { - return regionId; - } - - public String getId() { - return id; + protected ToStringHelper string() { + return MoreObjects.toStringHelper(this).add("regionId", regionId).add("id", id); } @Override public String toString() { - return "[regionId=" + regionId + ", id=" + id + "]"; + return string().toString(); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionAndName.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionAndName.java index e91d1fae7c..13a666b090 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionAndName.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionAndName.java @@ -33,21 +33,17 @@ import com.google.common.collect.Iterables; public class RegionAndName { public static final Function NAME_FUNCTION = new Function() { - @Override public String apply(RegionAndName input) { return input.getName(); } - }; public static final Function REGION_FUNCTION = new Function() { - @Override public String apply(RegionAndName input) { return input.getRegion(); } - }; public static RegionAndName fromSlashEncoded(String name) { @@ -99,12 +95,13 @@ public class RegionAndName { return Objects.hashCode(regionId, name); } + protected ToStringHelper string() { + return MoreObjects.toStringHelper(this).add("regionId", regionId).add("name", name); + } + @Override public String toString() { return string().toString(); } - protected ToStringHelper string() { - return MoreObjects.toStringHelper("").add("regionId", regionId).add("name", name); - } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionSecurityGroupNameAndPorts.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionSecurityGroupNameAndPorts.java index f7866e08cf..789b49cf8a 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionSecurityGroupNameAndPorts.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/RegionSecurityGroupNameAndPorts.java @@ -21,8 +21,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Set; -import com.google.common.base.Objects; import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; public class RegionSecurityGroupNameAndPorts extends RegionAndName { @@ -53,7 +53,13 @@ public class RegionSecurityGroupNameAndPorts extends RegionAndName { } @Override - public ToStringHelper string() { + protected ToStringHelper string() { return super.string().add("ports", ports); } + + @Override + public String toString() { + return string().toString(); + } + } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/SecurityGroupInRegion.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/SecurityGroupInRegion.java index a3898afec3..5f33b68382 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/SecurityGroupInRegion.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/SecurityGroupInRegion.java @@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup; +import com.google.common.base.MoreObjects.ToStringHelper; + public class SecurityGroupInRegion extends RegionAndName { protected final SecurityGroup securityGroup; @@ -32,12 +34,17 @@ public class SecurityGroupInRegion extends RegionAndName { return securityGroup; } - // superclass hashCode/equals are good enough, and help us use RegionAndName and ServerInRegion + // superclass hashCode/equals are good enough, and help us use RegionAndName and SecurityGroupInRegion // interchangeably as Map keys + @Override + protected ToStringHelper string() { + return super.string().add("securityGroup", securityGroup); + } + @Override public String toString() { - return "[securityGroup=" + securityGroup + ", regionId=" + regionId + "]"; + return string().toString(); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ServerInRegion.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ServerInRegion.java index a5c1803166..18c30714b3 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ServerInRegion.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ServerInRegion.java @@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.openstack.nova.v2_0.domain.Server; +import com.google.common.base.MoreObjects.ToStringHelper; + public class ServerInRegion extends RegionAndId { protected final Server server; @@ -35,9 +37,14 @@ public class ServerInRegion extends RegionAndId { // superclass hashCode/equals are good enough, and help us use RegionAndId and ServerInRegion // interchangeably as Map keys + @Override + protected ToStringHelper string() { + return super.string().add("server", server); + } + @Override public String toString() { - return "[server=" + server + ", regionId=" + regionId + "]"; + return string().toString(); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/AvailabilityZone.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/AvailabilityZone.java similarity index 97% rename from apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/AvailabilityZone.java rename to apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/AvailabilityZone.java index e59e4dda99..a963dcd9d9 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/AvailabilityZone.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/AvailabilityZone.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jclouds.openstack.nova.v2_0.domain.regionscoped; +package org.jclouds.openstack.nova.v2_0.domain.zonescoped; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/FlavorInRegion.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/FlavorInRegion.java new file mode 100644 index 0000000000..b547f96e82 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/FlavorInRegion.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.openstack.nova.v2_0.domain.Flavor; + +/** + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.FlavorInRegion FlavorInRegion}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class FlavorInRegion extends RegionAndId { + protected final Flavor flavor; + + public FlavorInRegion(Flavor flavor, String regionId) { + super(regionId, checkNotNull(flavor, "image").getId()); + this.flavor = flavor; + } + + public Flavor getFlavor() { + return flavor; + } + + // superclass hashCode/equals are good enough, and help us use RegionAndId and FlavorInRegion + // interchangeably as Map keys + + @Override + public String toString() { + return "[flavor=" + flavor + ", regionId=" + regionId + "]"; + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ImageInRegion.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ImageInRegion.java new file mode 100644 index 0000000000..cf818ffe7c --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ImageInRegion.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.openstack.nova.v2_0.domain.Image; + +/** + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.ImageInRegion ImageInRegion}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class ImageInRegion extends RegionAndId { + protected final Image image; + + public ImageInRegion(Image image, String regionId) { + super(regionId, checkNotNull(image, "image").getId()); + this.image = image; + } + + public Image getImage() { + return image; + } + + // superclass hashCode/equals are good enough, and help us use RegionAndId and ImageInRegion + // interchangeably as Map keys + + @Override + public String toString() { + return "[image=" + image + ", regionId=" + regionId + "]"; + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionAndId.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionAndId.java new file mode 100644 index 0000000000..7d45bff7ae --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionAndId.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; + +/** + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId RegionAndId}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class RegionAndId { + public static RegionAndId fromSlashEncoded(String id) { + Iterable parts = Splitter.on('/').split(checkNotNull(id, "id")); + checkArgument(Iterables.size(parts) == 2, "id must be in format regionId/id"); + return new RegionAndId(Iterables.get(parts, 0), Iterables.get(parts, 1)); + } + + public static RegionAndId fromRegionAndId(String regionId, String id) { + return new RegionAndId(regionId, id); + } + + private static String slashEncodeRegionAndId(String regionId, String id) { + return checkNotNull(regionId, "regionId") + "/" + checkNotNull(id, "id"); + } + + public String slashEncode() { + return slashEncodeRegionAndId(regionId, id); + } + + protected final String regionId; + protected final String id; + + protected RegionAndId(String regionId, String id) { + this.regionId = checkNotNull(regionId, "regionId"); + this.id = checkNotNull(id, "id"); + } + + @Override + public int hashCode() { + return Objects.hashCode(regionId, id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RegionAndId other = (RegionAndId) obj; + return Objects.equal(regionId, other.regionId) && Objects.equal(id, other.id); + } + + public String getRegion() { + return regionId; + } + + public String getId() { + return id; + } + + @Override + public String toString() { + return "[regionId=" + regionId + ", id=" + id + "]"; + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionAndName.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionAndName.java new file mode 100644 index 0000000000..c7d07e2e8a --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionAndName.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Function; +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; + +/** + * Helpful when looking for resources by region and name + * + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName RegionAndName}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class RegionAndName { + + public static final Function NAME_FUNCTION = new Function() { + + @Override + public String apply(RegionAndName input) { + return input.getName(); + } + + }; + + public static final Function REGION_FUNCTION = new Function() { + + @Override + public String apply(RegionAndName input) { + return input.getRegion(); + } + + }; + + public static RegionAndName fromSlashEncoded(String name) { + Iterable parts = Splitter.on('/').split(checkNotNull(name, "name")); + checkArgument(Iterables.size(parts) == 2, "name must be in format regionId/name"); + return new RegionAndName(Iterables.get(parts, 0), Iterables.get(parts, 1)); + } + + public static RegionAndName fromRegionAndName(String regionId, String name) { + return new RegionAndName(regionId, name); + } + + private static String slashEncodeRegionAndName(String regionId, String name) { + return checkNotNull(regionId, "regionId") + "/" + checkNotNull(name, "name"); + } + + public String slashEncode() { + return slashEncodeRegionAndName(regionId, name); + } + + protected final String regionId; + protected final String name; + + protected RegionAndName(String regionId, String name) { + this.regionId = checkNotNull(regionId, "regionId"); + this.name = checkNotNull(name, "name"); + } + + public String getRegion() { + return regionId; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + RegionAndName that = RegionAndName.class.cast(o); + return equal(this.regionId, that.regionId) && equal(this.name, that.name); + } + + @Override + public int hashCode() { + return Objects.hashCode(regionId, name); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return MoreObjects.toStringHelper("").add("regionId", regionId).add("name", name); + } +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionSecurityGroupNameAndPorts.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionSecurityGroupNameAndPorts.java new file mode 100644 index 0000000000..b464925897 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/RegionSecurityGroupNameAndPorts.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.collect.ImmutableSet; + +/** + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts RegionSecurityGroupNameAndPorts}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class RegionSecurityGroupNameAndPorts extends RegionAndName { + protected final Set ports; + + public RegionSecurityGroupNameAndPorts(String regionId, String name, Iterable ports) { + super(regionId, name); + this.ports = ImmutableSet. copyOf(checkNotNull(ports, "ports")); + } + + public Set getPorts() { + return ports; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + RegionSecurityGroupNameAndPorts that = RegionSecurityGroupNameAndPorts.class.cast(o); + return super.equals(that) && equal(this.ports, that.ports); + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), ports); + } + + @Override + public ToStringHelper string() { + return super.string().add("ports", ports); + } +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/SecurityGroupInRegion.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/SecurityGroupInRegion.java new file mode 100644 index 0000000000..fb2793baab --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/SecurityGroupInRegion.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup; + +/** + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion SecurityGroupInRegion}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class SecurityGroupInRegion extends RegionAndName { + protected final SecurityGroup securityGroup; + + public SecurityGroupInRegion(SecurityGroup securityGroup, String regionId) { + super(regionId, checkNotNull(securityGroup, "securityGroup").getName()); + this.securityGroup = securityGroup; + } + + public SecurityGroup getSecurityGroup() { + return securityGroup; + } + + // superclass hashCode/equals are good enough, and help us use RegionAndName and ServerInRegion + // interchangeably as Map keys + + @Override + public String toString() { + return "[securityGroup=" + securityGroup + ", regionId=" + regionId + "]"; + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ServerInRegion.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ServerInRegion.java new file mode 100644 index 0000000000..9e7c405983 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ServerInRegion.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.nova.v2_0.domain.zonescoped; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.openstack.nova.v2_0.domain.Server; + +/** + * @deprecated This package has been replaced with {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped}. + * Please use {@link org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion ServerInRegion}, + * as this class will be removed in jclouds 2.1.0. + */ +@Deprecated +public class ServerInRegion extends RegionAndId { + protected final Server server; + + public ServerInRegion(Server server, String regionId) { + super(regionId, checkNotNull(server, "server").getId()); + this.server = server; + } + + public Server getServer() { + return server; + } + + // superclass hashCode/equals are good enough, and help us use RegionAndId and ServerInRegion + // interchangeably as Map keys + + @Override + public String toString() { + return "[server=" + server + ", regionId=" + regionId + "]"; + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ZoneState.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ZoneState.java similarity index 96% rename from apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ZoneState.java rename to apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ZoneState.java index 814800a954..6beea925f6 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/regionscoped/ZoneState.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/zonescoped/ZoneState.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jclouds.openstack.nova.v2_0.domain.regionscoped; +package org.jclouds.openstack.nova.v2_0.domain.zonescoped; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApi.java index 7624e6955c..7b894fb115 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApi.java @@ -24,7 +24,7 @@ import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.AvailabilityZone; +import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; import org.jclouds.rest.annotations.Fallback; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java index 578a484716..b7b7f0d164 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java @@ -28,8 +28,8 @@ import javax.inject.Singleton; import org.jclouds.logging.Logger; import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi; import org.jclouds.rest.ResourceNotFoundException; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java index 35c5b39078..5cb02a7d83 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java @@ -35,8 +35,8 @@ import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions; import org.jclouds.openstack.nova.v2_0.domain.KeyPair; import org.jclouds.openstack.nova.v2_0.domain.Network; import org.jclouds.openstack.nova.v2_0.domain.Server; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaComputeServiceContextExpectTest; import org.testng.annotations.Test; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByRegionIdTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByRegionIdTest.java index 27b976dead..0398fab1bf 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByRegionIdTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByRegionIdTest.java @@ -29,8 +29,8 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.ServerInRegion; import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest; import org.testng.annotations.Test; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java index 83585bc4aa..9e3182f620 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java @@ -22,9 +22,9 @@ import static org.testng.Assert.fail; import java.util.concurrent.atomic.AtomicReference; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionSecurityGroupNameAndPorts; +import org.jclouds.openstack.nova.v2_0.domain.regionscoped.SecurityGroupInRegion; import org.testng.annotations.Test; import com.google.common.base.Function; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java index fd608111fb..e2e31bd252 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java @@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableSet; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.nova.v2_0.NovaApi; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.AvailabilityZone; +import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; import org.testng.annotations.Test; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java index 1c0a93b830..25ff002af0 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java @@ -16,15 +16,15 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import com.google.common.base.Optional; -import com.google.common.collect.FluentIterable; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; -import org.jclouds.openstack.nova.v2_0.domain.regionscoped.AvailabilityZone; +import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.testng.annotations.Test; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import com.google.common.base.Optional; +import com.google.common.collect.FluentIterable; @Test(groups = "live", testName = "AvailabilityZonesApiLiveTest") public class AvailabilityZonesApiLiveTest extends BaseNovaApiLiveTest {