You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/03/18 03:52:11 UTC
[18/20] fixing https://issues.apache.org/jira/browse/STRATOS-520 -
adding Openstack-nova module to dependencies
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java
new file mode 100644
index 0000000..23035c2
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java
@@ -0,0 +1,199 @@
+/*
+ * 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.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Predicates.not;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.find;
+import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Sets.newHashSet;
+import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromCommaDelimitedValue;
+import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
+import static org.jclouds.openstack.nova.v2_0.domain.Address.createV4;
+import static org.jclouds.openstack.nova.v2_0.domain.Address.createV6;
+
+import java.net.Inet4Address;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jclouds.collect.Memoized;
+import org.jclouds.compute.domain.ComputeMetadata;
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.domain.OperatingSystem;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.logging.Logger;
+import org.jclouds.openstack.nova.v2_0.domain.Address;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.jclouds.openstack.nova.v2_0.domain.Server.Status;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
+import org.jclouds.openstack.v2_0.domain.Link;
+import org.jclouds.util.InetAddresses2;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.common.net.InetAddresses;
+
+/**
+ * A function for transforming a nova-specific Server into a generic
+ * NodeMetadata object.
+ *
+ * @author Matt Stephenson, Adam Lowe, Adrian Cole
+ */
+public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMetadata> {
+ @Resource
+ @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+ protected Logger logger = Logger.NULL;
+
+ protected Map<Status, org.jclouds.compute.domain.NodeMetadata.Status> toPortableNodeStatus;
+ protected final Supplier<Map<String, Location>> locationIndex;
+ protected final Supplier<Set<? extends Image>> images;
+ protected final Supplier<Set<? extends Hardware>> hardwares;
+ protected final GroupNamingConvention nodeNamingConvention;
+
+ @Inject
+ public ServerInZoneToNodeMetadata(Map<Server.Status, NodeMetadata.Status> toPortableNodeStatus,
+ Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
+ @Memoized Supplier<Set<? extends Hardware>> hardwares, GroupNamingConvention.Factory namingConvention) {
+ this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus");
+ this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
+ this.locationIndex = checkNotNull(locationIndex, "locationIndex");
+ this.images = checkNotNull(images, "images");
+ this.hardwares = checkNotNull(hardwares, "hardwares");
+ }
+
+ @Override
+ public NodeMetadata apply(ServerInZone serverInZone) {
+ Location zone = locationIndex.get().get(serverInZone.getZone());
+ checkState(zone != null, "location %s not in locationIndex: %s", serverInZone.getZone(), locationIndex.get());
+ Server from = serverInZone.getServer();
+
+ NodeMetadataBuilder builder = new NodeMetadataBuilder();
+ builder.id(serverInZone.slashEncode());
+ builder.providerId(from.getId());
+ builder.name(from.getName());
+ builder.hostname(from.getName());
+ builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId())
+ .description(from.getHostId()).parent(zone).build() : zone);
+ builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention));
+ addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
+ builder.imageId(ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
+ builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
+ builder.hardware(findHardwareForServerOrNull(serverInZone));
+ builder.status(toPortableNodeStatus.get(from.getStatus()));
+
+ Set<Address> addresses = newHashSet(from.getAddresses().values());
+ if (from.getAccessIPv4() != null) {
+ addresses.add(createV4(from.getAccessIPv4()));
+ }
+ if (from.getAccessIPv6() != null) {
+ addresses.add(createV6(from.getAccessIPv6()));
+ }
+
+ builder.publicAddresses(
+ filter(
+ transform(
+ filter(addresses, not(isPrivateAddress)),
+ AddressToStringTransformationFunction.INSTANCE),
+ isInet4Address));
+
+ builder.privateAddresses(
+ filter(
+ transform(
+ filter(addresses, isPrivateAddress),
+ AddressToStringTransformationFunction.INSTANCE),
+ isInet4Address));
+
+ for (Link link: from.getLinks()) {
+ if (link.getRelation().equals(Link.Relation.SELF)) {
+ builder.uri(link.getHref());
+ }
+ }
+
+ return builder.build();
+ }
+
+ private static final Predicate<Address> isPrivateAddress = new Predicate<Address>() {
+ public boolean apply(Address in) {
+ return InetAddresses2.IsPrivateIPAddress.INSTANCE.apply(in.getAddr());
+ }
+ };
+
+ public static final Predicate<String> isInet4Address = new Predicate<String>() {
+ @Override
+ public boolean apply(String input) {
+ try {
+ // Note we can do this, as InetAddress is now on the white list
+ return InetAddresses.forString(input) instanceof Inet4Address;
+ } catch (IllegalArgumentException e) {
+ // could be a hostname
+ return true;
+ }
+ }
+
+ };
+
+ private enum AddressToStringTransformationFunction implements Function<Address, String> {
+ INSTANCE;
+ @Override
+ public String apply(Address address) {
+ return address.getAddr();
+ }
+ }
+
+ protected Hardware findHardwareForServerOrNull(ServerInZone serverInZone) {
+ return findObjectOfTypeForServerOrNull(hardwares.get(), "hardware", serverInZone.getServer().getFlavor().getId(),
+ serverInZone);
+ }
+
+ protected OperatingSystem findOperatingSystemForServerOrNull(ServerInZone serverInZone) {
+ Image image = findObjectOfTypeForServerOrNull(images.get(), "image", serverInZone.getServer().getImage().getId(),
+ serverInZone);
+ return (image != null) ? image.getOperatingSystem() : null;
+ }
+
+ public <T extends ComputeMetadata> T findObjectOfTypeForServerOrNull(Set<? extends T> supply, String type,
+ final String objectId, final ZoneAndId serverInZone) {
+ try {
+ return find(supply, new Predicate<T>() {
+ @Override
+ public boolean apply(T input) {
+ return input.getId().equals(ZoneAndId.fromZoneAndId(serverInZone.getZone(), objectId).slashEncode());
+ }
+ });
+ } catch (NoSuchElementException e) {
+ logger.trace("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone);
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java
new file mode 100644
index 0000000..18096fe
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java
@@ -0,0 +1,79 @@
+/*
+ * 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.compute.loaders;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Resource;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.logging.Logger;
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
+
+import com.google.common.base.Optional;
+import com.google.common.cache.CacheLoader;
+import com.google.inject.Inject;
+
+/**
+ * @author Adam Lowe
+ */
+@Singleton
+public class CreateUniqueKeyPair extends CacheLoader<ZoneAndName, KeyPair> {
+ @Resource
+ @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+ protected Logger logger = Logger.NULL;
+ protected final NovaApi novaApi;
+ protected final GroupNamingConvention.Factory namingConvention;
+
+ @Inject
+ public CreateUniqueKeyPair(NovaApi novaApi, GroupNamingConvention.Factory namingConvention) {
+ this.novaApi = checkNotNull(novaApi, "novaApi");
+ this.namingConvention = checkNotNull(namingConvention, "namingConvention");
+ }
+
+ @Override
+ public KeyPair load(ZoneAndName zoneAndName) {
+ String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone();
+ String prefix = zoneAndName.getName();
+
+ Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
+ checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
+ zoneId);
+
+ logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix);
+
+ KeyPair keyPair = null;
+ while (keyPair == null) {
+ try {
+ keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
+ } catch (IllegalStateException e) {
+
+ }
+ }
+
+ logger.debug("<< created keyPair(%s)", keyPair.getName());
+ return keyPair;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java
new file mode 100644
index 0000000..71951cd
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java
@@ -0,0 +1,86 @@
+/*
+ * 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.compute.loaders;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.cache.CacheLoader;
+import com.google.common.util.concurrent.Atomics;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public class FindSecurityGroupOrCreate extends CacheLoader<ZoneAndName, SecurityGroupInZone> {
+
+ protected final Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone;
+ protected final Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator;
+
+ @Inject
+ public FindSecurityGroupOrCreate(
+ @Named("SECURITYGROUP_PRESENT") Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone,
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator) {
+ this.returnSecurityGroupExistsInZone = checkNotNull(returnSecurityGroupExistsInZone,
+ "returnSecurityGroupExistsInZone");
+ this.groupCreator = checkNotNull(groupCreator, "groupCreator");
+ }
+
+ @Override
+ public SecurityGroupInZone load(ZoneAndName in) {
+ AtomicReference<ZoneAndName> securityGroupInZoneRef = Atomics.newReference(checkNotNull(in,
+ "zoneSecurityGroupNameAndPorts"));
+ if (returnSecurityGroupExistsInZone.apply(securityGroupInZoneRef)) {
+ return returnExistingSecurityGroup(securityGroupInZoneRef);
+ } else {
+ return createNewSecurityGroup(in);
+ }
+ }
+
+ private SecurityGroupInZone returnExistingSecurityGroup(AtomicReference<ZoneAndName> securityGroupInZoneRef) {
+ ZoneAndName securityGroupInZone = securityGroupInZoneRef.get();
+ checkState(securityGroupInZone instanceof SecurityGroupInZone,
+ "programming error: predicate %s should update the atomic reference to the actual security group found",
+ returnSecurityGroupExistsInZone);
+ return SecurityGroupInZone.class.cast(securityGroupInZone);
+ }
+
+ private SecurityGroupInZone createNewSecurityGroup(ZoneAndName in) {
+ checkState(
+ checkNotNull(in, "zoneSecurityGroupNameAndPorts") instanceof ZoneSecurityGroupNameAndPorts,
+ "programming error: when issuing get to this cacheloader, you need to pass an instance of ZoneSecurityGroupNameAndPorts, not %s",
+ in);
+ ZoneSecurityGroupNameAndPorts zoneSecurityGroupNameAndPorts = ZoneSecurityGroupNameAndPorts.class.cast(in);
+ return groupCreator.apply(zoneSecurityGroupNameAndPorts);
+ }
+
+ @Override
+ public String toString() {
+ return "returnExistingSecurityGroupInZoneOrCreateAsNeeded()";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java
new file mode 100644
index 0000000..1c0ae8a
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java
@@ -0,0 +1,63 @@
+/*
+ * 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.compute.loaders;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
+import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.cache.CacheLoader;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Each zone may or may not have the floating ip function present. In order to safely proceed, we
+ * must allow the user to determine if a zone has floating ip services before attempting to use
+ * them.
+ *
+ * @author Adam Lowe
+ */
+@Singleton
+public class LoadFloatingIpsForInstance extends CacheLoader<ZoneAndId, Iterable<? extends FloatingIP>> {
+ private final NovaApi api;
+
+ @Inject
+ public LoadFloatingIpsForInstance(NovaApi api) {
+ this.api = api;
+ }
+
+ @Override
+ public Iterable<? extends FloatingIP> load(final ZoneAndId key) throws Exception {
+ String zone = key.getZone();
+ Optional<? extends FloatingIPApi> ipApiOptional = api.getFloatingIPExtensionForZone(zone);
+ if (ipApiOptional.isPresent()) {
+ return ipApiOptional.get().list().filter(
+ new Predicate<FloatingIP>() {
+ @Override
+ public boolean apply(FloatingIP input) {
+ return key.getId().equals(input.getInstanceId());
+ }
+ });
+ }
+ return ImmutableSet.of();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java
new file mode 100644
index 0000000..e5f5794
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java
@@ -0,0 +1,620 @@
+/*
+ * 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.compute.options;
+
+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 static com.google.common.base.Strings.emptyToNull;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.openstack.nova.v2_0.domain.Network;
+import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
+import org.jclouds.scriptbuilder.domain.Statement;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Contains options supported in the {@code ComputeService#runNode} operation on the
+ * "openstack-nova" provider. <h2>Usage</h2> The recommended way to instantiate a
+ * NovaTemplateOptions object is to statically import NovaTemplateOptions.* and invoke a static
+ * creation method followed by an instance mutator (if needed):
+ * <p/>
+ * <code>
+ * import static org.jclouds.aws.ec2.compute.options.NovaTemplateOptions.Builder.*;
+ * <p/>
+ * ComputeService api = // get connection
+ * templateBuilder.options(inboundPorts(22, 80, 8080, 443));
+ * Set<? extends NodeMetadata> set = api.createNodesInGroup(tag, 2, templateBuilder.build());
+ * <code>
+ *
+ * @author Adam Lowe
+ */
+public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
+ @Override
+ public NovaTemplateOptions clone() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ copyTo(options);
+ return options;
+ }
+
+ @Override
+ public void copyTo(TemplateOptions to) {
+ super.copyTo(to);
+ if (to instanceof NovaTemplateOptions) {
+ NovaTemplateOptions eTo = NovaTemplateOptions.class.cast(to);
+ eTo.autoAssignFloatingIp(shouldAutoAssignFloatingIp());
+ if (getSecurityGroupNames().isPresent())
+ eTo.securityGroupNames(getSecurityGroupNames().get());
+ eTo.generateKeyPair(shouldGenerateKeyPair());
+ eTo.keyPairName(getKeyPairName());
+ if (getUserData() != null) {
+ eTo.userData(getUserData());
+ }
+ if (getDiskConfig() != null) {
+ eTo.diskConfig(getDiskConfig());
+ }
+
+ eTo.configDrive(getConfigDrive());
+ eTo.novaNetworks(getNovaNetworks());
+ }
+ }
+
+ protected boolean autoAssignFloatingIp = false;
+ protected Optional<Set<String>> securityGroupNames = Optional.absent();
+ protected boolean generateKeyPair = false;
+ protected String keyPairName;
+ protected byte[] userData;
+ protected String diskConfig;
+ protected boolean configDrive;
+ protected Set<Network> novaNetworks;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ NovaTemplateOptions that = NovaTemplateOptions.class.cast(o);
+ return super.equals(that) && equal(this.autoAssignFloatingIp, that.autoAssignFloatingIp)
+ && equal(this.securityGroupNames, that.securityGroupNames)
+ && equal(this.generateKeyPair, that.generateKeyPair)
+ && equal(this.keyPairName, that.keyPairName)
+ && Arrays.equals(this.userData, that.userData)
+ && equal(this.diskConfig, that.diskConfig)
+ && equal(this.configDrive, that.configDrive)
+ && equal(this.novaNetworks, that.novaNetworks);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(super.hashCode(), autoAssignFloatingIp, securityGroupNames, generateKeyPair, keyPairName, userData, diskConfig, configDrive, novaNetworks);
+ }
+
+ @Override
+ public ToStringHelper string() {
+ ToStringHelper toString = super.string();
+ if (!autoAssignFloatingIp)
+ toString.add("autoAssignFloatingIp", autoAssignFloatingIp);
+ if (securityGroupNames.isPresent())
+ toString.add("securityGroupNames", securityGroupNames.get());
+ if (generateKeyPair)
+ toString.add("generateKeyPair", generateKeyPair);
+ toString.add("keyPairName", keyPairName);
+ toString.add("userData", userData);
+ toString.add("diskConfig", diskConfig);
+ toString.add("configDrive", configDrive);
+ toString.add("novaNetworks", novaNetworks);
+ return toString;
+ }
+
+ public static final NovaTemplateOptions NONE = new NovaTemplateOptions();
+
+ /**
+ * @see #shouldAutoAssignFloatingIp()
+ */
+ public NovaTemplateOptions autoAssignFloatingIp(boolean enable) {
+ this.autoAssignFloatingIp = enable;
+ return this;
+ }
+
+ /**
+ * @see #shouldGenerateKeyPair()
+ */
+ public NovaTemplateOptions generateKeyPair(boolean enable) {
+ this.generateKeyPair = enable;
+ return this;
+ }
+
+ /**
+ * @see #shouldGenerateKeyPair()
+ */
+ public NovaTemplateOptions keyPairName(String keyPairName) {
+ this.keyPairName = keyPairName;
+ return this;
+ }
+
+ /**
+ *
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
+ */
+ public NovaTemplateOptions securityGroupNames(String... securityGroupNames) {
+ return securityGroupNames(ImmutableSet.copyOf(checkNotNull(securityGroupNames, "securityGroupNames")));
+ }
+
+ /**
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
+ */
+ public NovaTemplateOptions securityGroupNames(Iterable<String> securityGroupNames) {
+ for (String groupName : checkNotNull(securityGroupNames, "securityGroupNames"))
+ checkNotNull(emptyToNull(groupName), "all security groups must be non-empty");
+ this.securityGroupNames = Optional.<Set<String>> of(ImmutableSet.copyOf(securityGroupNames));
+ return this;
+ }
+
+ /**
+ * <h3>Note</h3>
+ *
+ * This requires that {@link NovaApi#getExtensionForZone(String)} to return
+ * {@link Optional#isPresent present}
+ *
+ * @return true if auto assignment of a floating ip to each vm is enabled
+ */
+ public boolean shouldAutoAssignFloatingIp() {
+ return autoAssignFloatingIp;
+ }
+
+ /**
+ * Specifies the keypair used to run instances with
+ * @return the keypair to be used
+ */
+ public String getKeyPairName() {
+ return keyPairName;
+ }
+
+ /**
+ * <h3>Note</h3>
+ *
+ * This requires that {@link NovaApi#getKeyPairExtensionForZone(String)} to return
+ * {@link Optional#isPresent present}
+ *
+ * @return true if auto generation of keypairs is enabled
+ */
+ public boolean shouldGenerateKeyPair() {
+ return generateKeyPair;
+ }
+
+ /**
+ * if unset, generate a default group prefixed with {@link jclouds#} according
+ * to {@link #getInboundPorts()}
+ *
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
+ */
+ public Optional<Set<String>> getSecurityGroupNames() {
+ return securityGroupNames;
+ }
+
+ public byte[] getUserData() {
+ return userData;
+ }
+
+ /**
+ * @see CreateServerOptions#getDiskConfig()
+ */
+ public String getDiskConfig() {
+ return diskConfig;
+ }
+
+ /**
+ * @see CreateServerOptions#getConfigDrive()
+ */
+ public boolean getConfigDrive() {
+ return configDrive;
+ }
+
+ /**
+ * @see CreateServerOptions#getNetworks()
+ */
+ public Set<Network> getNovaNetworks() {
+ return novaNetworks;
+ }
+
+ public static class Builder {
+
+ /**
+ * @see NovaTemplateOptions#shouldAutoAssignFloatingIp()
+ */
+ public static NovaTemplateOptions autoAssignFloatingIp(boolean enable) {
+ return new NovaTemplateOptions().autoAssignFloatingIp(enable);
+ }
+
+ /**
+ * @see NovaTemplateOptions#shouldGenerateKeyPair()
+ */
+ public static NovaTemplateOptions generateKeyPair(boolean enable) {
+ return new NovaTemplateOptions().generateKeyPair(enable);
+ }
+
+ /**
+ * @see NovaTemplateOptions#getKeyPairName()
+ */
+ public static NovaTemplateOptions keyPairName(String keyPairName) {
+ return new NovaTemplateOptions().keyPairName(keyPairName);
+ }
+
+ /**
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
+ */
+ public static NovaTemplateOptions securityGroupNames(String... groupNames) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.securityGroupNames(groupNames));
+ }
+
+ /**
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
+ */
+ public static NovaTemplateOptions securityGroupNames(Iterable<String> groupNames) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.securityGroupNames(groupNames));
+ }
+
+ // methods that only facilitate returning the correct object type
+
+ /**
+ * @see TemplateOptions#inboundPorts
+ */
+ public static NovaTemplateOptions inboundPorts(int... ports) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.inboundPorts(ports));
+ }
+
+ /**
+ * @see TemplateOptions#port
+ */
+ public static NovaTemplateOptions blockOnPort(int port, int seconds) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.blockOnPort(port, seconds));
+ }
+
+ /**
+ * @see TemplateOptions#installPrivateKey
+ */
+ public static NovaTemplateOptions installPrivateKey(String rsaKey) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.installPrivateKey(rsaKey));
+ }
+
+ /**
+ * @see TemplateOptions#authorizePublicKey
+ */
+ public static NovaTemplateOptions authorizePublicKey(String rsaKey) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.authorizePublicKey(rsaKey));
+ }
+
+ /**
+ * @see TemplateOptions#userMetadata
+ */
+ public static NovaTemplateOptions userMetadata(Map<String, String> userMetadata) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.userMetadata(userMetadata));
+ }
+
+ /**
+ * @see TemplateOptions#nodeNames(Iterable)
+ */
+ public static NovaTemplateOptions nodeNames(Iterable<String> nodeNames) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.nodeNames(nodeNames));
+ }
+
+ /**
+ * @see TemplateOptions#networks(Iterable)
+ */
+ public static NovaTemplateOptions networks(Iterable<String> networks) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.networks(networks));
+ }
+
+ /**
+ * @see TemplateOptions#overrideLoginUser
+ */
+ public static NovaTemplateOptions overrideLoginUser(String user) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return options.overrideLoginUser(user);
+ }
+
+ /**
+ * @see TemplateOptions#overrideLoginPassword
+ */
+ public static NovaTemplateOptions overrideLoginPassword(String password) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return options.overrideLoginPassword(password);
+ }
+
+ /**
+ * @see TemplateOptions#overrideLoginPrivateKey
+ */
+ public static NovaTemplateOptions overrideLoginPrivateKey(String privateKey) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return options.overrideLoginPrivateKey(privateKey);
+ }
+
+ /**
+ * @see TemplateOptions#overrideAuthenticateSudo
+ */
+ public static NovaTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return options.overrideAuthenticateSudo(authenticateSudo);
+ }
+
+ /**
+ * @see TemplateOptions#overrideLoginCredentials
+ */
+ public static NovaTemplateOptions overrideLoginCredentials(LoginCredentials credentials) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return options.overrideLoginCredentials(credentials);
+ }
+
+ /**
+ * @see TemplateOptions#blockUntilRunning
+ */
+ public static NovaTemplateOptions blockUntilRunning(boolean blockUntilRunning) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return options.blockUntilRunning(blockUntilRunning);
+ }
+
+ /**
+ * @see NovaTemplateOptions#userData
+ */
+ public static NovaTemplateOptions userData(byte[] userData) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.userData(userData));
+ }
+
+ /**
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getDiskConfig()
+ */
+ public static NovaTemplateOptions diskConfig(String diskConfig) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.diskConfig(diskConfig));
+ }
+
+ /**
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getConfigDrive()
+ */
+ public static NovaTemplateOptions configDrive(boolean configDrive) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.configDrive(configDrive));
+ }
+
+ /**
+ * @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getNetworks()
+ */
+ public static NovaTemplateOptions novaNetworks(Set<Network> novaNetworks) {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ return NovaTemplateOptions.class.cast(options.novaNetworks(novaNetworks));
+ }
+ }
+
+ // methods that only facilitate returning the correct object type
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions blockOnPort(int port, int seconds) {
+ return NovaTemplateOptions.class.cast(super.blockOnPort(port, seconds));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions inboundPorts(int... ports) {
+ return NovaTemplateOptions.class.cast(super.inboundPorts(ports));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions authorizePublicKey(String publicKey) {
+ return NovaTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions installPrivateKey(String privateKey) {
+ return NovaTemplateOptions.class.cast(super.installPrivateKey(privateKey));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions blockUntilRunning(boolean blockUntilRunning) {
+ return NovaTemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions dontAuthorizePublicKey() {
+ return NovaTemplateOptions.class.cast(super.dontAuthorizePublicKey());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions nameTask(String name) {
+ return NovaTemplateOptions.class.cast(super.nameTask(name));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions runAsRoot(boolean runAsRoot) {
+ return NovaTemplateOptions.class.cast(super.runAsRoot(runAsRoot));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions runScript(Statement script) {
+ return NovaTemplateOptions.class.cast(super.runScript(script));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions overrideLoginCredentials(LoginCredentials overridingCredentials) {
+ return NovaTemplateOptions.class.cast(super.overrideLoginCredentials(overridingCredentials));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions overrideLoginPassword(String password) {
+ return NovaTemplateOptions.class.cast(super.overrideLoginPassword(password));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions overrideLoginPrivateKey(String privateKey) {
+ return NovaTemplateOptions.class.cast(super.overrideLoginPrivateKey(privateKey));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions overrideLoginUser(String loginUser) {
+ return NovaTemplateOptions.class.cast(super.overrideLoginUser(loginUser));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) {
+ return NovaTemplateOptions.class.cast(super.overrideAuthenticateSudo(authenticateSudo));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions userMetadata(Map<String, String> userMetadata) {
+ return NovaTemplateOptions.class.cast(super.userMetadata(userMetadata));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions userMetadata(String key, String value) {
+ return NovaTemplateOptions.class.cast(super.userMetadata(key, value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NovaTemplateOptions nodeNames(Iterable<String> nodeNames) {
+ return NovaTemplateOptions.class.cast(super.nodeNames(nodeNames));
+ }
+
+ /**
+ * <br>Ensures NovaTemplateOptions can work with networks specified as Strings.
+ * Also provides for compatibility with the abstraction layer.
+ */
+ @Override
+ public NovaTemplateOptions networks(Iterable<String> networks) {
+ return NovaTemplateOptions.class.cast(super.networks(networks));
+ }
+
+ /**
+ * <br>Ensures NovaTemplateOptions can work with networks specified as Strings.
+ * Also provides for compatibility with the abstraction layer.
+ */
+ @Override
+ public NovaTemplateOptions networks(String... networks) {
+ return NovaTemplateOptions.class.cast(super.networks(networks));
+ }
+
+ /**
+ * User data as bytes (not base64-encoded)
+ */
+ public NovaTemplateOptions userData(byte[] userData) {
+ // This limit may not be needed for nova
+ checkArgument(checkNotNull(userData, "userData").length <= 16 * 1024,
+ "userData cannot be larger than 16kb");
+ this.userData = userData;
+ return this;
+ }
+
+ /**
+ * @see CreateServerOptions#getDiskConfig()
+ */
+ public NovaTemplateOptions diskConfig(String diskConfig) {
+ this.diskConfig = diskConfig;
+ return this;
+ }
+
+ /**
+ * OpenStack can be configured to write metadata to a special configuration drive that will be
+ * attached to the instance when it boots. The instance can retrieve any information that would
+ * normally be available through the metadata service by mounting this disk and reading files from it.
+ * To enable the config drive, set this parameter to "true".
+ * This has to be enabled for user data cases.
+ * @see CreateServerOptions#getConfigDrive()
+ */
+ public NovaTemplateOptions configDrive(boolean configDrive) {
+ this.configDrive = configDrive;
+ return this;
+ }
+
+ /**
+ * @param novaNetworks The list of network declarations.
+ * Nova-specific network declarations allow for specifying network UUIDs, port UUIDs, and fixed IPs.
+ * Unline {@link #networks(Iterable)} this supports setting additional network parameters and not just network UUIDs.
+ * @see CreateServerOptions#getNetworks()
+ */
+ public NovaTemplateOptions novaNetworks(Set<Network> novaNetworks) {
+ this.novaNetworks = novaNetworks;
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/AllNodesInGroupTerminated.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/AllNodesInGroupTerminated.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/AllNodesInGroupTerminated.java
new file mode 100644
index 0000000..680a82c
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/AllNodesInGroupTerminated.java
@@ -0,0 +1,56 @@
+/*
+ * 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.compute.predicates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.and;
+import static com.google.common.collect.Iterables.all;
+import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
+import static org.jclouds.compute.predicates.NodePredicates.inGroup;
+import static org.jclouds.compute.predicates.NodePredicates.locationId;
+import static org.jclouds.compute.predicates.NodePredicates.parentLocationId;
+
+import javax.inject.Inject;
+
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.domain.ComputeMetadata;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+
+/**
+ * @author Adrian Cole
+ */
+public class AllNodesInGroupTerminated implements Predicate<ZoneAndName> {
+ private final ComputeService computeService;
+
+
+ //TODO: TESTME
+ @Inject
+ public AllNodesInGroupTerminated(ComputeService computeService) {
+ this.computeService = checkNotNull(computeService, "computeService");
+ }
+
+ @Override
+ public boolean apply(ZoneAndName input) {
+ // new nodes can have the zone as their location, existing nodes, the parent is the
+ // location
+ return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getZone()),
+ parentLocationId(input.getZone()))), and(inGroup(input.getName()), TERMINATED));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java
new file mode 100644
index 0000000..e3ea4cc
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java
@@ -0,0 +1,165 @@
+/*
+ * 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.compute.strategy;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.ssh.SshKeys.fingerprintPrivateKey;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.Constants;
+import org.jclouds.compute.config.CustomizationResponse;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
+import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
+import org.jclouds.compute.strategy.ListNodesStrategy;
+import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.compute.functions.AllocateAndAddFloatingIpToNode;
+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.zonescoped.SecurityGroupInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
+
+import com.google.common.base.Throwables;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.Multimap;
+import com.google.common.primitives.Ints;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+@Singleton
+public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet extends
+ CreateNodesWithGroupEncodedIntoNameThenAddToSet {
+
+ private final AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode;
+ private final LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache;
+ private final LoadingCache<ZoneAndName, KeyPair> keyPairCache;
+ private final NovaApi novaApi;
+
+ @Inject
+ protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet(
+ CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy,
+ ListNodesStrategy listNodesStrategy,
+ GroupNamingConvention.Factory namingConvention,
+ CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
+ @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
+ AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode,
+ LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache,
+ LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaApi novaApi) {
+ super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
+ customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
+ this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache");
+ this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
+ this.createAndAddFloatingIpToNode = checkNotNull(createAndAddFloatingIpToNode,
+ "createAndAddFloatingIpToNode");
+ this.novaApi = checkNotNull(novaApi, "novaApi");
+ }
+
+ @Override
+ public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
+ Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
+
+ Template mutableTemplate = template.clone();
+
+ NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(mutableTemplate.getOptions());
+
+ assert template.getOptions().equals(templateOptions) : "options didn't clone properly";
+
+ String zone = mutableTemplate.getLocation().getId();
+
+ if (templateOptions.shouldAutoAssignFloatingIp()) {
+ checkArgument(novaApi.getFloatingIPExtensionForZone(zone).isPresent(),
+ "Floating IPs are required by options, but the extension is not available! options: %s",
+ templateOptions);
+ }
+
+ boolean keyPairExtensionPresent = novaApi.getKeyPairExtensionForZone(zone).isPresent();
+ if (templateOptions.shouldGenerateKeyPair()) {
+ checkArgument(keyPairExtensionPresent,
+ "Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
+ KeyPair keyPair = keyPairCache.getUnchecked(ZoneAndName.fromZoneAndName(zone, namingConvention.create()
+ .sharedNameForGroup(group)));
+ keyPairCache.asMap().put(ZoneAndName.fromZoneAndName(zone, keyPair.getName()), keyPair);
+ templateOptions.keyPairName(keyPair.getName());
+ } else if (templateOptions.getKeyPairName() != null) {
+ checkArgument(keyPairExtensionPresent,
+ "Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
+ if (templateOptions.getLoginPrivateKey() != null) {
+ String pem = templateOptions.getLoginPrivateKey();
+ KeyPair keyPair = KeyPair.builder().name(templateOptions.getKeyPairName())
+ .fingerprint(fingerprintPrivateKey(pem)).privateKey(pem).build();
+ keyPairCache.asMap().put(ZoneAndName.fromZoneAndName(zone, keyPair.getName()), keyPair);
+ }
+ }
+
+ boolean securityGroupExtensionPresent = novaApi.getSecurityGroupExtensionForZone(zone).isPresent();
+ List<Integer> inboundPorts = Ints.asList(templateOptions.getInboundPorts());
+ if (templateOptions.getSecurityGroupNames().isPresent()
+ && templateOptions.getSecurityGroupNames().get().size() > 0) {
+ checkArgument(securityGroupExtensionPresent,
+ "Security groups are required by options, but the extension is not available! options: %s",
+ templateOptions);
+ } else if (securityGroupExtensionPresent) {
+ if (!templateOptions.getSecurityGroupNames().isPresent() && inboundPorts.size() > 0) {
+ String securityGroupName = namingConvention.create().sharedNameForGroup(group);
+ try {
+ securityGroupCache.get(new ZoneSecurityGroupNameAndPorts(zone, securityGroupName, inboundPorts));
+ } catch (ExecutionException e) {
+ throw Throwables.propagate(e.getCause());
+ }
+ templateOptions.securityGroupNames(securityGroupName);
+ }
+ }
+ templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
+
+ return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
+ }
+
+ @Override
+ protected ListenableFuture<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group,
+ final String name, Template template) {
+
+ ListenableFuture<AtomicReference<NodeMetadata>> future = super.createNodeInGroupWithNameAndTemplate(group, name, template);
+ NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
+
+ if (templateOptions.shouldAutoAssignFloatingIp()) {
+ return Futures.transform(future, createAndAddFloatingIpToNode, userExecutor);
+ } else {
+ return future;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java
new file mode 100644
index 0000000..7f31c27
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java
@@ -0,0 +1,159 @@
+/*
+ * 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.config;
+
+import java.beans.ConstructorProperties;
+import java.lang.reflect.Type;
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Singleton;
+
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.config.GsonModule;
+import org.jclouds.json.config.GsonModule.DateAdapter;
+import org.jclouds.openstack.nova.v2_0.domain.Address;
+import org.jclouds.openstack.nova.v2_0.domain.HostResourceUsage;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.jclouds.openstack.nova.v2_0.domain.ServerExtendedAttributes;
+import org.jclouds.openstack.nova.v2_0.domain.ServerExtendedStatus;
+import org.jclouds.openstack.nova.v2_0.domain.ServerWithSecurityGroups;
+import org.jclouds.openstack.v2_0.domain.Link;
+import org.jclouds.openstack.v2_0.domain.Resource;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+
+/**
+ * @author Adrian Cole
+ * @author Adam Lowe
+ */
+public class NovaParserModule extends AbstractModule {
+
+ @Provides
+ @Singleton
+ public Map<Type, Object> provideCustomAdapterBindings() {
+ return ImmutableMap.<Type, Object>of(
+ HostResourceUsage.class, new HostResourceUsageAdapter(),
+ ServerWithSecurityGroups.class, new ServerWithSecurityGroupsAdapter(),
+ Server.class, new ServerAdapter()
+ );
+ }
+
+ @Override
+ protected void configure() {
+ bind(DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
+ }
+
+ @Singleton
+ public static class HostResourceUsageAdapter implements JsonSerializer<HostResourceUsage>, JsonDeserializer<HostResourceUsage> {
+ public HostResourceUsage apply(HostResourceUsageView in) {
+ return in.resource.toBuilder().build();
+ }
+
+ @Override
+ public HostResourceUsage deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
+ return apply((HostResourceUsageView) context.deserialize(jsonElement, HostResourceUsageView.class));
+ }
+
+ @Override
+ public JsonElement serialize(HostResourceUsage hostResourceUsage, Type type, JsonSerializationContext context) {
+ return context.serialize(hostResourceUsage);
+ }
+
+ private static class HostResourceUsageView {
+ protected HostResourceUsageInternal resource;
+ }
+
+ private static class HostResourceUsageInternal extends HostResourceUsage {
+
+ @ConstructorProperties({
+ "host", "project", "memory_mb", "cpu", "disk_gb"
+ })
+ protected HostResourceUsageInternal(String host, @Nullable String project, int memoryMb, int cpu, int diskGb) {
+ super(host, project, memoryMb, cpu, diskGb);
+ }
+ }
+ }
+
+ @Singleton
+ public static class ServerWithSecurityGroupsAdapter implements JsonDeserializer<ServerWithSecurityGroups> {
+ @Override
+ public ServerWithSecurityGroups deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ Server server = context.deserialize(jsonElement, Server.class);
+ ServerWithSecurityGroups.Builder<?> result = ServerWithSecurityGroups.builder().fromServer(server);
+ Set<String> names = Sets.newLinkedHashSet();
+ if (jsonElement.getAsJsonObject().get("security_groups") != null) {
+ JsonArray x = jsonElement.getAsJsonObject().get("security_groups").getAsJsonArray();
+ for (JsonElement y : x) {
+ names.add(y.getAsJsonObject().get("name").getAsString());
+ }
+ result.securityGroupNames(names);
+ }
+ return result.build();
+ }
+ }
+
+ @Singleton
+ public static class ServerAdapter implements JsonDeserializer<Server> {
+ @Override
+ public Server deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ Server serverBase = apply((ServerInternal) context.deserialize(jsonElement, ServerInternal.class));
+ Server.Builder<?> result = Server.builder().fromServer(serverBase);
+ ServerExtendedStatus extendedStatus = context.deserialize(jsonElement, ServerExtendedStatus.class);
+ if (!Objects.equal(extendedStatus, ServerExtendedStatus.builder().build())) {
+ result.extendedStatus(extendedStatus);
+ }
+ ServerExtendedAttributes extraAttributes = context.deserialize(jsonElement, ServerExtendedAttributes.class);
+ if (!Objects.equal(extraAttributes, ServerExtendedAttributes.builder().build())) {
+ result.extendedAttributes(extraAttributes);
+ }
+ return result.build();
+ }
+
+ public Server apply(ServerInternal in) {
+ return in.toBuilder().build();
+ }
+
+ private static class ServerInternal extends Server {
+ @ConstructorProperties({
+ "id", "name", "links", "uuid", "tenant_id", "user_id", "updated", "created", "hostId", "accessIPv4", "accessIPv6", "status", "image", "flavor", "key_name", "config_drive", "addresses", "metadata", "extendedStatus", "extendedAttributes", "OS-DCF:diskConfig"
+ })
+ protected ServerInternal(String id, @Nullable String name, java.util.Set<Link> links, @Nullable String uuid, String tenantId,
+ String userId, Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4,
+ @Nullable String accessIPv6, Server.Status status, Resource image, Resource flavor, @Nullable String keyName,
+ @Nullable String configDrive, Multimap<String, Address> addresses, Map<String, String> metadata,
+ @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes, @Nullable String diskConfig) {
+ super(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, addresses, metadata, extendedStatus, extendedAttributes, diskConfig);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java
new file mode 100644
index 0000000..9b55439
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java
@@ -0,0 +1,43 @@
+/*
+ * 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.config;
+
+/**
+ * Configuration properties and constants used in openstack Nova connections.
+ *
+ * @author Adam Lowe
+ */
+public class NovaProperties {
+
+ /**
+ * Eventual consistency delay for retrieving a security group after it is created (in ms)
+ */
+ public static final String TIMEOUT_SECURITYGROUP_PRESENT = "jclouds.openstack-nova.timeout.securitygroup-present";
+
+ /**
+ * Whenever a node is created, automatically create and assign a floating ip address, also
+ * delete when the node is destroyed.
+ */
+ public static final String AUTO_ALLOCATE_FLOATING_IPS = "jclouds.openstack-nova.auto-create-floating-ips";
+
+ /**
+ * Whenever a node is created, automatically generate keypairs for groups, as needed, also
+ * delete the keypair(s) when the last node in the group is destroyed.
+ */
+ public static final String AUTO_GENERATE_KEYPAIRS = "jclouds.openstack-nova.auto-generate-keypairs";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java
new file mode 100644
index 0000000..556ec60
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java
@@ -0,0 +1,191 @@
+/*
+ * 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.config;
+import static org.jclouds.reflect.Reflection2.typeToken;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpErrorHandler;
+import org.jclouds.http.annotation.ClientError;
+import org.jclouds.http.annotation.Redirection;
+import org.jclouds.http.annotation.ServerError;
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.AvailabilityZoneAPI;
+import org.jclouds.openstack.nova.v2_0.extensions.AvailabilityZoneAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces;
+import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsApi;
+import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
+import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.HostAdministrationApi;
+import org.jclouds.openstack.nova.v2_0.extensions.HostAdministrationAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.HostAggregateApi;
+import org.jclouds.openstack.nova.v2_0.extensions.HostAggregateAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
+import org.jclouds.openstack.nova.v2_0.extensions.KeyPairAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.QuotaApi;
+import org.jclouds.openstack.nova.v2_0.extensions.QuotaAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.QuotaClassApi;
+import org.jclouds.openstack.nova.v2_0.extensions.QuotaClassAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi;
+import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.ServerAdminApi;
+import org.jclouds.openstack.nova.v2_0.extensions.ServerAdminAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.ServerWithSecurityGroupsApi;
+import org.jclouds.openstack.nova.v2_0.extensions.ServerWithSecurityGroupsAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.SimpleTenantUsageApi;
+import org.jclouds.openstack.nova.v2_0.extensions.SimpleTenantUsageAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VirtualInterfaceApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VirtualInterfaceAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VolumeApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VolumeAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VolumeAttachmentApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VolumeAttachmentAsyncApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VolumeTypeApi;
+import org.jclouds.openstack.nova.v2_0.extensions.VolumeTypeAsyncApi;
+import org.jclouds.openstack.nova.v2_0.features.FlavorApi;
+import org.jclouds.openstack.nova.v2_0.features.FlavorAsyncApi;
+import org.jclouds.openstack.nova.v2_0.features.ImageApi;
+import org.jclouds.openstack.nova.v2_0.features.ImageAsyncApi;
+import org.jclouds.openstack.nova.v2_0.features.ServerApi;
+import org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi;
+import org.jclouds.openstack.nova.v2_0.handlers.NovaErrorHandler;
+import org.jclouds.openstack.v2_0.domain.Extension;
+import org.jclouds.openstack.v2_0.features.ExtensionApi;
+import org.jclouds.openstack.v2_0.features.ExtensionAsyncApi;
+import org.jclouds.openstack.v2_0.functions.PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet;
+import org.jclouds.rest.ConfiguresRestClient;
+import org.jclouds.rest.config.RestClientModule;
+import org.jclouds.rest.functions.ImplicitOptionalConverter;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.reflect.TypeToken;
+import com.google.inject.Provides;
+
+/**
+ * Configures the Nova connection.
+ *
+ * @author Adrian Cole
+ */
+@ConfiguresRestClient
+public class NovaRestClientModule<S extends NovaApi, A extends NovaAsyncApi> extends RestClientModule<S, A> {
+
+ public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
+ .put(ServerApi.class, ServerAsyncApi.class)
+ .put(FlavorApi.class, FlavorAsyncApi.class)
+ .put(ImageApi.class, ImageAsyncApi.class)
+ .put(ExtensionApi.class, ExtensionAsyncApi.class)
+ .put(FloatingIPApi.class, FloatingIPAsyncApi.class)
+ .put(AvailabilityZoneAPI.class, AvailabilityZoneAsyncApi.class)
+ .put(SecurityGroupApi.class, SecurityGroupAsyncApi.class)
+ .put(KeyPairApi.class, KeyPairAsyncApi.class)
+ .put(HostAdministrationApi.class, HostAdministrationAsyncApi.class)
+ .put(SimpleTenantUsageApi.class, SimpleTenantUsageAsyncApi.class)
+ .put(VirtualInterfaceApi.class, VirtualInterfaceAsyncApi.class)
+ .put(ServerWithSecurityGroupsApi.class, ServerWithSecurityGroupsAsyncApi.class)
+ .put(ServerAdminApi.class, ServerAdminAsyncApi.class)
+ .put(HostAggregateApi.class, HostAggregateAsyncApi.class)
+ .put(FlavorExtraSpecsApi.class, FlavorExtraSpecsAsyncApi.class)
+ .put(QuotaApi.class, QuotaAsyncApi.class)
+ .put(QuotaClassApi.class, QuotaClassAsyncApi.class)
+ .put(VolumeApi.class, VolumeAsyncApi.class)
+ .put(VolumeAttachmentApi.class, VolumeAttachmentAsyncApi.class)
+ .put(VolumeTypeApi.class, VolumeTypeAsyncApi.class)
+ .build();
+
+ @SuppressWarnings("unchecked")
+ public NovaRestClientModule() {
+ super(TypeToken.class.cast(typeToken(NovaApi.class)), TypeToken.class.cast(typeToken(NovaAsyncApi.class)), DELEGATE_MAP);
+ }
+
+ protected NovaRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
+ Map<Class<?>, Class<?>> sync2Async) {
+ super(syncClientType, asyncClientType, sync2Async);
+ }
+
+ @Override
+ protected void configure() {
+ bind(ImplicitOptionalConverter.class).to(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
+ super.configure();
+ }
+
+ @Provides
+ @Singleton
+ public Multimap<URI, URI> aliases() {
+ return ImmutableMultimap.<URI, URI>builder()
+ .put(URI.create(ExtensionNamespaces.SECURITY_GROUPS),
+ URI.create("http://docs.openstack.org/compute/ext/securitygroups/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.FLOATING_IPS),
+ URI.create("http://docs.openstack.org/compute/ext/floating_ips/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.KEYPAIRS),
+ URI.create("http://docs.openstack.org/compute/ext/keypairs/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.SIMPLE_TENANT_USAGE),
+ URI.create("http://docs.openstack.org/compute/ext/os-simple-tenant-usage/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.HOSTS),
+ URI.create("http://docs.openstack.org/compute/ext/hosts/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.VOLUMES),
+ URI.create("http://docs.openstack.org/compute/ext/volumes/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.VIRTUAL_INTERFACES),
+ URI.create("http://docs.openstack.org/compute/ext/virtual_interfaces/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.CREATESERVEREXT),
+ URI.create("http://docs.openstack.org/compute/ext/createserverext/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.ADMIN_ACTIONS),
+ URI.create("http://docs.openstack.org/compute/ext/admin-actions/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.AGGREGATES),
+ URI.create("http://docs.openstack.org/compute/ext/aggregates/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.FLAVOR_EXTRA_SPECS),
+ URI.create("http://docs.openstack.org/compute/ext/flavor_extra_specs/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.QUOTAS),
+ URI.create("http://docs.openstack.org/compute/ext/quotas-sets/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.QUOTA_CLASSES),
+ URI.create("http://docs.openstack.org/compute/ext/quota-classes-sets/api/v1.1"))
+ .put(URI.create(ExtensionNamespaces.VOLUME_TYPES),
+ URI.create("http://docs.openstack.org/compute/ext/volume_types/api/v1.1"))
+ .build();
+ }
+
+ @Provides
+ @Singleton
+ public LoadingCache<String, Set<? extends Extension>> provideExtensionsByZone(final Provider<NovaApi> novaApi) {
+ return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS)
+ .build(new CacheLoader<String, Set<? extends Extension>>() {
+ @Override
+ public Set<? extends Extension> load(String key) throws Exception {
+ return novaApi.get().getExtensionApiForZone(key).list();
+ }
+ });
+ }
+
+ @Override
+ protected void bindErrorHandlers() {
+ bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(NovaErrorHandler.class);
+ bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(NovaErrorHandler.class);
+ bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(NovaErrorHandler.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java
new file mode 100644
index 0000000..38c744d
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java
@@ -0,0 +1,138 @@
+/*
+ * 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;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.beans.ConstructorProperties;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+
+/**
+ * IP address
+ *
+ * @author AdrianCole
+*/
+public class Address {
+
+ public static Builder<?> builder() {
+ return new ConcreteBuilder();
+ }
+
+ public Builder<?> toBuilder() {
+ return new ConcreteBuilder().fromAddress(this);
+ }
+
+ public static Address createV4(String addr) {
+ return builder().version(4).addr(addr).build();
+ }
+
+ public static Address createV6(String addr) {
+ return builder().version(6).addr(addr).build();
+ }
+
+ public abstract static class Builder<T extends Builder<T>> {
+ protected abstract T self();
+
+ protected String addr;
+ protected int version;
+
+ /**
+ * @see Address#getAddr()
+ */
+ public T addr(String addr) {
+ this.addr = addr;
+ return self();
+ }
+
+ /**
+ * @see Address#getVersion()
+ */
+ public T version(int version) {
+ this.version = version;
+ return self();
+ }
+
+ public Address build() {
+ return new Address(addr, version);
+ }
+
+ public T fromAddress(Address in) {
+ return this
+ .addr(in.getAddr())
+ .version(in.getVersion());
+ }
+ }
+
+ private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
+ @Override
+ protected ConcreteBuilder self() {
+ return this;
+ }
+ }
+
+ private final String addr;
+ private final int version;
+
+ @ConstructorProperties({
+ "addr", "version"
+ })
+ protected Address(String addr, int version) {
+ this.addr = checkNotNull(addr, "addr");
+ this.version = version;
+ }
+
+ /**
+ * @return the ip address
+ */
+ public String getAddr() {
+ return this.addr;
+ }
+
+ /**
+ * @return the IP version, ex. 4
+ */
+ public int getVersion() {
+ return this.version;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(addr, version);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Address that = Address.class.cast(obj);
+ return Objects.equal(this.addr, that.addr)
+ && Objects.equal(this.version, that.version);
+ }
+
+ protected ToStringHelper string() {
+ return Objects.toStringHelper(this)
+ .add("addr", addr).add("version", version);
+ }
+
+ @Override
+ public String toString() {
+ return string().toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/BackupType.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/BackupType.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/BackupType.java
new file mode 100644
index 0000000..97460d8
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/main/java/org/jclouds/openstack/nova/v2_0/domain/BackupType.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.CaseFormat;
+
+/**
+ * @author Adam Lowe
+ */
+public enum BackupType {
+ DAILY, WEEKLY;
+
+ public String value() {
+ return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
+ }
+
+ @Override
+ public String toString() {
+ return value();
+ }
+
+ public static BackupType fromValue(String backupType) {
+ return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(backupType, "backupType")));
+ }
+}