You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2014/11/25 16:25:24 UTC
[08/13] stratos git commit: Jclouds aws-ec2 provider 1.8.1 clone with
custom changes
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/LaunchSpecificationHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/LaunchSpecificationHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/LaunchSpecificationHandler.java
new file mode 100644
index 0000000..11ada98
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/LaunchSpecificationHandler.java
@@ -0,0 +1,147 @@
+/*
+ * 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.aws.ec2.xml;
+
+import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+
+import org.jclouds.aws.ec2.domain.LaunchSpecification;
+import org.jclouds.aws.ec2.domain.LaunchSpecification.Builder;
+import org.jclouds.date.DateCodec;
+import org.jclouds.date.DateCodecFactory;
+import org.jclouds.ec2.domain.BlockDeviceMapping;
+import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
+import org.jclouds.logging.Logger;
+import org.xml.sax.Attributes;
+
+public class LaunchSpecificationHandler extends HandlerForGeneratedRequestWithResult<LaunchSpecification> {
+
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ protected final DateCodec dateCodec;
+ protected final Builder builder;
+ protected final BlockDeviceMapping.Builder blockDeviceMappingBuilder;
+
+ @Inject
+ public LaunchSpecificationHandler(DateCodecFactory dateCodecFactory, LaunchSpecification.Builder builder,
+ BlockDeviceMapping.Builder blockDeviceMappingBuilder) {
+ this.dateCodec = dateCodecFactory.iso8601();
+ this.builder = builder;
+ this.blockDeviceMappingBuilder = blockDeviceMappingBuilder;
+ }
+
+ protected String currentOrNull() {
+ String returnVal = currentText.toString().trim();
+ return returnVal.equals("") ? null : returnVal;
+ }
+
+ protected StringBuilder currentText = new StringBuilder();
+
+ private boolean inBlockDeviceMapping;
+ private boolean inIamInstanceProfile;
+
+ private String groupId;
+
+ public void startElement(String uri, String name, String qName, Attributes attrs) {
+ if (qName.equals("blockDeviceMapping")) {
+ inBlockDeviceMapping = true;
+ } else if (equalsOrSuffix(qName, "iamInstanceProfile")) {
+ inIamInstanceProfile = true;
+ }
+ }
+
+ public void endElement(String uri, String name, String qName) {
+ if (qName.equals("blockDeviceMapping")) {
+ inBlockDeviceMapping = false;
+ } else if (equalsOrSuffix(qName, "iamInstanceProfile")) {
+ inIamInstanceProfile = false;
+ } else if (qName.equals("item") && inBlockDeviceMapping) {
+ try {
+ builder.blockDeviceMapping(blockDeviceMappingBuilder.build());
+ } finally {
+ blockDeviceMappingBuilder.clear();
+ }
+ } else if (equalsOrSuffix(qName, "arn") && inIamInstanceProfile) {
+ builder.iamInstanceProfileArn(currentOrNull());
+ } else if (equalsOrSuffix(qName, "name") && inIamInstanceProfile) {
+ builder.iamInstanceProfileName(currentOrNull());
+ } else if (qName.equals("deviceName")) {
+ blockDeviceMappingBuilder.deviceName(currentOrNull());
+ } else if (qName.equals("virtualName")) {
+ blockDeviceMappingBuilder.virtualName(currentOrNull());
+ } else if (qName.equals("snapshotId")) {
+ blockDeviceMappingBuilder.snapshotId(currentOrNull());
+ } else if (qName.equals("volumeSize")) {
+ String volumeSize = currentOrNull();
+ if (volumeSize != null)
+ blockDeviceMappingBuilder.sizeInGib(Integer.parseInt(volumeSize));
+ } else if (qName.equals("noDevice")) {
+ String noDevice = currentOrNull();
+ if (noDevice != null)
+ blockDeviceMappingBuilder.noDevice(Boolean.parseBoolean(noDevice));
+ } else if (qName.equals("deleteOnTermination")) {
+ String deleteOnTermination = currentOrNull();
+ if (deleteOnTermination != null)
+ blockDeviceMappingBuilder.deleteOnTermination(Boolean.parseBoolean(deleteOnTermination));
+ } else if (qName.equals("groupId")) {
+ groupId = currentOrNull();
+ } else if (qName.equals("groupName")) {
+ builder.securityGroupIdToName(groupId, currentOrNull());
+ groupId = null;
+ } else if (qName.equals("imageId")) {
+ builder.imageId(currentOrNull());
+ } else if (qName.equals("instanceType")) {
+ builder.instanceType(currentOrNull());
+ } else if (qName.equals("kernelId")) {
+ builder.kernelId(currentOrNull());
+ } else if (qName.equals("keyName")) {
+ builder.keyName(currentOrNull());
+ } else if (qName.equals("availabilityZone")) {
+ builder.availabilityZone(currentOrNull());
+ } else if (qName.equals("subnetId")) {
+ builder.subnetId(currentOrNull());
+ } else if (qName.equals("ramdiskId")) {
+ builder.ramdiskId(currentOrNull());
+ } else if (qName.equals("enabled")) {
+ String monitoringEnabled = currentOrNull();
+ if (monitoringEnabled != null)
+ builder.monitoringEnabled(Boolean.valueOf(monitoringEnabled));
+ } else if (qName.equals("publicIpAddressAssociated")) {
+ String publicIpAddressAssociated = currentOrNull();
+ if (publicIpAddressAssociated != null)
+ builder.publicIpAddressAssociated(Boolean.valueOf(publicIpAddressAssociated));
+ }
+ currentText = new StringBuilder();
+ }
+
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+
+ @Override
+ public LaunchSpecification getResult() {
+ try {
+ return builder.build();
+ } finally {
+ builder.clear();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/MonitoringStateHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/MonitoringStateHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/MonitoringStateHandler.java
new file mode 100644
index 0000000..dfae3b7
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/MonitoringStateHandler.java
@@ -0,0 +1,54 @@
+/*
+ * 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.aws.ec2.xml;
+
+import java.util.Map;
+
+import org.jclouds.aws.ec2.domain.MonitoringState;
+import org.jclouds.http.functions.ParseSax;
+
+import com.google.common.collect.Maps;
+
+public class MonitoringStateHandler extends
+ ParseSax.HandlerWithResult<Map<String, MonitoringState>> {
+ private StringBuilder currentText = new StringBuilder();
+
+ private Map<String, MonitoringState> monitoringState = Maps.newHashMap();
+ private String instanceId;
+ private MonitoringState state;
+
+ public Map<String, MonitoringState> getResult() {
+ return monitoringState;
+ }
+
+ public void endElement(String uri, String name, String qName) {
+ if (qName.equals("instanceId")) {
+ instanceId = currentText.toString().trim();
+ } else if (qName.equals("state")) {
+ state = MonitoringState.fromValue(currentText.toString().trim());
+ } else if (qName.equals("item")) {
+ monitoringState.put(instanceId, state);
+ this.instanceId = null;
+ this.state = null;
+ }
+ currentText = new StringBuilder();
+ }
+
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/PlacementGroupHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/PlacementGroupHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/PlacementGroupHandler.java
new file mode 100644
index 0000000..6fadf34
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/PlacementGroupHandler.java
@@ -0,0 +1,66 @@
+/*
+ * 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.aws.ec2.xml;
+
+import javax.inject.Inject;
+
+import org.jclouds.aws.ec2.domain.PlacementGroup;
+import org.jclouds.aws.ec2.domain.PlacementGroup.State;
+import org.jclouds.aws.util.AWSUtils;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.location.Region;
+
+import com.google.common.base.Supplier;
+
+public class PlacementGroupHandler extends
+ ParseSax.HandlerForGeneratedRequestWithResult<PlacementGroup> {
+ private StringBuilder currentText = new StringBuilder();
+
+ @Inject
+ @Region
+ Supplier<String> defaultRegion;
+
+ private String name;
+ private String strategy = "cluster";
+ private State state;
+
+ public PlacementGroup getResult() {
+ String region = AWSUtils.findRegionInArgsOrNull(getRequest());
+ if (region == null)
+ region = defaultRegion.get();
+ PlacementGroup returnVal = new PlacementGroup(region, name, strategy, state);
+ this.name = null;
+ this.strategy = "cluster";
+ this.state = null;
+ return returnVal;
+ }
+
+ public void endElement(String uri, String name, String qName) {
+ if (qName.equals("groupName")) {
+ this.name = currentText.toString().trim();
+ } else if (qName.equals("strategy")) {
+ strategy = currentText.toString().trim();
+ } else if (qName.equals("state")) {
+ state = PlacementGroup.State.fromValue(currentText.toString().trim());
+ }
+ currentText = new StringBuilder();
+ }
+
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ProductCodesHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ProductCodesHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ProductCodesHandler.java
new file mode 100644
index 0000000..6f4915b
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ProductCodesHandler.java
@@ -0,0 +1,50 @@
+/*
+ * 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.aws.ec2.xml;
+
+import java.util.Set;
+
+import org.jclouds.http.functions.ParseSax;
+
+import com.google.common.collect.Sets;
+
+/**
+ *
+ * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeImageAttribute.html"
+ * />
+ */
+public class ProductCodesHandler extends ParseSax.HandlerWithResult<Set<String>> {
+
+ private StringBuilder currentText = new StringBuilder();
+ private Set<String> productCodes = Sets.newHashSet();
+
+ public Set<String> getResult() {
+ return productCodes;
+ }
+
+ public void endElement(String uri, String name, String qName) {
+
+ if (qName.equalsIgnoreCase("productCode")) {
+ productCodes.add(currentText.toString().trim());
+ }
+ currentText = new StringBuilder();
+ }
+
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ReservedInstancesOfferingHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ReservedInstancesOfferingHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ReservedInstancesOfferingHandler.java
new file mode 100644
index 0000000..786c261
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/ReservedInstancesOfferingHandler.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.aws.ec2.xml;
+
+import javax.inject.Inject;
+
+import org.jclouds.aws.util.AWSUtils;
+import org.jclouds.ec2.domain.ReservedInstancesOffering;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.location.Region;
+
+import com.google.common.base.Supplier;
+
+/**
+ *
+ * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeReservedInstancesOfferingsResponseSetItemType.html"
+ * />
+ */
+public class ReservedInstancesOfferingHandler extends
+ ParseSax.HandlerForGeneratedRequestWithResult<ReservedInstancesOffering> {
+ @Inject
+ @Region
+ Supplier<String> defaultRegion;
+
+ private StringBuilder currentText = new StringBuilder();
+
+ private String availabilityZone;
+ private long duration = 0;
+ private float fixedPrice = 0;
+ private String instanceType;
+ private String productDescription;
+ private String id;
+ private float usagePrice = 0;
+
+ public ReservedInstancesOffering getResult() {
+ String region = AWSUtils.findRegionInArgsOrNull(getRequest());
+ if (region == null)
+ region = defaultRegion.get();
+
+ ReservedInstancesOffering returnVal = new ReservedInstancesOffering(region, availabilityZone, duration,
+ fixedPrice, instanceType, productDescription, id, usagePrice);
+ this.availabilityZone = null;
+ this.duration = 0;
+ this.fixedPrice = 0;
+ this.instanceType = null;
+ this.productDescription = null;
+ this.id = null;
+ this.usagePrice = 0;
+ return returnVal;
+ }
+
+ public void endElement(String uri, String name, String qName) {
+
+ if (qName.equalsIgnoreCase("reservedInstancesOfferingId")) {
+ this.id = currentText.toString().trim();
+ } else if (qName.equalsIgnoreCase("availabilityZone")) {
+ this.availabilityZone = currentText.toString().trim();
+ } else if (qName.equalsIgnoreCase("duration")) {
+ this.duration = Long.parseLong(currentText.toString().trim());
+ } else if (qName.equalsIgnoreCase("fixedPrice")) {
+ this.fixedPrice = Float.parseFloat(currentText.toString().trim());
+ } else if (qName.equalsIgnoreCase("instanceType")) {
+ this.instanceType = currentText.toString().trim();
+ } else if (qName.equalsIgnoreCase("productDescription")) {
+ this.productDescription = currentText.toString().trim();
+ } else if (qName.equalsIgnoreCase("usagePrice")) {
+ this.usagePrice = Float.parseFloat(currentText.toString().trim());
+ }
+ currentText = new StringBuilder();
+ }
+
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotHandler.java
new file mode 100644
index 0000000..78d29ef
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotHandler.java
@@ -0,0 +1,73 @@
+/*
+ * 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.aws.ec2.xml;
+
+import javax.inject.Inject;
+
+import org.jclouds.aws.ec2.domain.Spot;
+import org.jclouds.aws.util.AWSUtils;
+import org.jclouds.date.DateCodec;
+import org.jclouds.date.DateCodecFactory;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.location.Region;
+
+import com.google.common.base.Supplier;
+
+public class SpotHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Spot> {
+ private StringBuilder currentText = new StringBuilder();
+
+ protected final DateCodec dateCodec;
+ protected final Supplier<String> defaultRegion;
+
+ @Inject
+ public SpotHandler(DateCodecFactory dateCodecFactory, @Region Supplier<String> defaultRegion) {
+ this.dateCodec = dateCodecFactory.iso8601();
+ this.defaultRegion = defaultRegion;
+ }
+
+ private Spot.Builder builder = Spot.builder();
+
+ public Spot getResult() {
+ try {
+ String region = getRequest() == null ? null : AWSUtils.findRegionInArgsOrNull(getRequest());
+ if (region == null)
+ region = defaultRegion.get();
+ return builder.region(region).build();
+ } finally {
+ builder.clear();
+ }
+ }
+
+ public void endElement(String uri, String name, String qName) {
+ if (qName.equals("instanceType")) {
+ builder.instanceType(currentText.toString().trim());
+ } else if (qName.equals("productDescription")) {
+ builder.productDescription(currentText.toString().trim());
+ } else if (qName.equals("spotPrice")) {
+ builder.spotPrice(Float.parseFloat(currentText.toString().trim()));
+ } else if (qName.equals("timestamp")) {
+ builder.timestamp(dateCodec.toDate(currentText.toString().trim()));
+ } else if (qName.equals("availabilityZone")) {
+ builder.availabilityZone(currentText.toString().trim());
+ }
+ currentText = new StringBuilder();
+ }
+
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java
new file mode 100644
index 0000000..d5bf014
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java
@@ -0,0 +1,148 @@
+/*
+ * 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.aws.ec2.xml;
+
+import static org.jclouds.util.SaxUtils.currentOrNull;
+import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+
+import javax.inject.Inject;
+
+import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
+import org.jclouds.aws.ec2.domain.SpotInstanceRequest.Builder;
+import org.jclouds.aws.util.AWSUtils;
+import org.jclouds.date.DateCodec;
+import org.jclouds.date.DateCodecFactory;
+import org.jclouds.ec2.xml.TagSetHandler;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.location.Region;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import com.google.common.base.Supplier;
+
+public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SpotInstanceRequest> {
+ private StringBuilder currentText = new StringBuilder();
+
+ protected final DateCodec dateCodec;
+ protected final Supplier<String> defaultRegion;
+ protected final Builder builder;
+ protected boolean inLaunchSpecification;
+ protected final LaunchSpecificationHandler launchSpecificationHandler;
+ protected boolean inTagSet;
+ protected final TagSetHandler tagSetHandler;
+
+ @Inject
+ public SpotInstanceHandler(DateCodecFactory dateCodecFactory, @Region Supplier<String> defaultRegion,
+ LaunchSpecificationHandler launchSpecificationHandler, TagSetHandler tagSetHandler,
+ SpotInstanceRequest.Builder builder) {
+ this.dateCodec = dateCodecFactory.iso8601();
+ this.defaultRegion = defaultRegion;
+ this.launchSpecificationHandler = launchSpecificationHandler;
+ this.tagSetHandler = tagSetHandler;
+ this.builder = builder;
+ }
+
+ public SpotInstanceRequest getResult() {
+ try {
+ String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
+ if (region == null)
+ region = defaultRegion.get();
+ return builder.region(region).build();
+ } finally {
+ builder.clear();
+ }
+ }
+
+ @Override
+ public void startElement(String uri, String name, String qName, Attributes attrs) throws SAXException {
+ if (equalsOrSuffix(qName, "launchSpecification")) {
+ inLaunchSpecification = true;
+ } else if (equalsOrSuffix(qName, "tagSet")) {
+ inTagSet = true;
+ }
+ if (inLaunchSpecification) {
+ launchSpecificationHandler.startElement(uri, name, qName, attrs);
+ } else if (inTagSet) {
+ tagSetHandler.startElement(uri, name, qName, attrs);
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String name, String qName) throws SAXException {
+ if (equalsOrSuffix(qName, "tagSet")) {
+ inTagSet = false;
+ builder.tags(tagSetHandler.getResult());
+ } else if (inTagSet) {
+ tagSetHandler.endElement(uri, name, qName);
+ }
+
+ if (qName.equals("launchSpecification")) {
+ inLaunchSpecification = false;
+ builder.launchSpecification(launchSpecificationHandler.getResult());
+ } else if (inLaunchSpecification) {
+ launchSpecificationHandler.endElement(uri, name, qName);
+ }
+
+ if (qName.equals("spotInstanceRequestId")) {
+ builder.id(currentOrNull(currentText));
+ } else if (qName.equals("instanceId")) {
+ builder.instanceId(currentOrNull(currentText));
+ } else if (qName.equals("launchedAvailabilityZone")) {
+ builder.launchedAvailabilityZone(currentOrNull(currentText));
+ } else if (qName.equals("availabilityZoneGroup")) {
+ builder.availabilityZoneGroup(currentOrNull(currentText));
+ } else if (qName.equals("launchGroup")) {
+ builder.launchGroup(currentOrNull(currentText));
+ } else if (qName.equals("code")) {
+ builder.faultCode(currentOrNull(currentText));
+ } else if (qName.equals("message")) {
+ builder.faultMessage(currentOrNull(currentText));
+ } else if (qName.equals("spotPrice")) {
+ String price = currentOrNull(currentText);
+ if (price != null)
+ builder.spotPrice(Float.parseFloat(price));
+ } else if (qName.equals("type")) {
+ String type = currentOrNull(currentText);
+ if (type != null)
+ builder.type(SpotInstanceRequest.Type.fromValue(type));
+ } else if (qName.equals("state")) {
+ String rawState = currentOrNull(currentText);
+ if (rawState != null) {
+ builder.rawState(rawState);
+ builder.state(SpotInstanceRequest.State.fromValue(rawState));
+ }
+ } else if (qName.equals("createTime")) {
+ String createTime = currentOrNull(currentText);
+ if (createTime != null)
+ builder.createTime(dateCodec.toDate(createTime));
+ } else if (qName.equals("productDescription")) {
+ builder.productDescription(currentOrNull(currentText));
+ }
+ currentText = new StringBuilder();
+ }
+
+ @Override
+ public void characters(char ch[], int start, int length) {
+ if (inLaunchSpecification) {
+ launchSpecificationHandler.characters(ch, start, length);
+ } else if (inTagSet) {
+ tagSetHandler.characters(ch, start, length);
+ } else {
+ currentText.append(ch, start, length);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java
new file mode 100644
index 0000000..beea293
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java
@@ -0,0 +1,78 @@
+/*
+ * 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.aws.ec2.xml;
+
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.http.functions.ParseSax.HandlerWithResult;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+
+public class SpotInstancesHandler extends ParseSax.HandlerWithResult<Set<SpotInstanceRequest>> {
+
+ private final Builder<SpotInstanceRequest> spotRequests = ImmutableSet.builder();
+ private final SpotInstanceHandler spotRequestHandler;
+ private int itemDepth;
+
+ @Inject
+ public SpotInstancesHandler(SpotInstanceHandler spotRequestHandler) {
+ this.spotRequestHandler = spotRequestHandler;
+ }
+
+ public Set<SpotInstanceRequest> getResult() {
+ return spotRequests.build();
+ }
+
+ @Override
+ public HandlerWithResult<Set<SpotInstanceRequest>> setContext(HttpRequest request) {
+ spotRequestHandler.setContext(request);
+ return super.setContext(request);
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if (qName.equals("item"))
+ itemDepth++;
+ if (itemDepth >= 1)
+ spotRequestHandler.startElement(uri, localName, qName, attributes);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if (qName.equals("item") && itemDepth == 1) {
+ spotRequests.add(spotRequestHandler.getResult());
+ }
+ if (qName.equals("item"))
+ itemDepth--;
+ if (itemDepth >= 1)
+ spotRequestHandler.endElement(uri, localName, qName);
+ }
+
+ public void characters(char ch[], int start, int length) {
+ if (itemDepth >= 1)
+ spotRequestHandler.characters(ch, start, length);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata
new file mode 100644
index 0000000..636b065
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata
@@ -0,0 +1 @@
+org.jclouds.aws.ec2.AWSEC2ProviderMetadata
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/clojure/org/jclouds/aws/ec2_test.clj
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/clojure/org/jclouds/aws/ec2_test.clj b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/clojure/org/jclouds/aws/ec2_test.clj
new file mode 100644
index 0000000..bd00ef7
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/clojure/org/jclouds/aws/ec2_test.clj
@@ -0,0 +1,32 @@
+;
+; 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.
+;
+
+(ns org.jclouds.aws.ec2-test
+ (:use
+ org.jclouds.aws.ec2
+ clojure.test))
+
+(deftest translate-enum-value-test
+ (is (= org.jclouds.aws.ec2.domain.SpotInstanceRequest$Type/ONE_TIME
+ (org.jclouds.aws.ec2/translate-enum-value :type :one-time))))
+
+(deftest spot-options-est
+ (is (spot-options {:type :one-time
+ :valid-from (java.util.Date.)
+ :valid-until (java.util.Date.)
+ :launch-group "lg"
+ :availability-zone-group "ag"})))
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
new file mode 100644
index 0000000..14d0c09
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.aws.ec2;
+
+import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
+import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
+import static org.jclouds.reflect.Reflection2.typeToken;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.jclouds.ContextBuilder;
+import org.jclouds.View;
+import org.jclouds.aws.ec2.compute.config.ImageQuery;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.ec2.EC2Api;
+import org.testng.annotations.Test;
+
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+
+@Test(groups = "unit", testName = "AWSEC2ContextBuilderTest")
+public class AWSEC2ContextBuilderTest {
+ private Map<String, String> queriesForProperties(Properties input) {
+ return ContextBuilder.newBuilder(new AWSEC2ProviderMetadata()).overrides(input).credentials("foo", "bar")
+ .buildInjector().getInstance(Key.get(new TypeLiteral<Map<String, String>>() {
+ }, ImageQuery.class));
+ }
+
+ public void testAssignability() {
+ View view = ContextBuilder.newBuilder(new AWSEC2ProviderMetadata()).credentials("foo", "bar")
+ .buildView(typeToken(ComputeServiceContext.class));
+ view.unwrapApi(EC2Api.class);
+ view.unwrapApi(AWSEC2Api.class);
+ }
+
+ public void testConvertImageSyntax() {
+ Properties input = new Properties();
+ input.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317");
+ Map<String, String> queries = queriesForProperties(input);
+ assertEquals(queries.get(PROPERTY_EC2_AMI_OWNERS), null);
+ assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY),
+ "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
+ }
+
+ public void testConvertImageSyntaxWhenStar() {
+ Properties input = new Properties();
+ input.setProperty(PROPERTY_EC2_AMI_OWNERS, "*");
+ Map<String, String> queries = queriesForProperties(input);
+ assertEquals(queries.get(PROPERTY_EC2_AMI_OWNERS), null);
+ assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), "state=available;image-type=machine");
+ }
+
+ public void testBlankAmiOwnersRemovesAmiQuery() {
+ Properties input = new Properties();
+ input.setProperty(PROPERTY_EC2_AMI_OWNERS, "");
+ Map<String, String> queries = queriesForProperties(input);
+ assertEquals(queries.get(PROPERTY_EC2_AMI_OWNERS), null);
+ assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java
new file mode 100644
index 0000000..1661f2c
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.aws.ec2;
+
+import org.jclouds.providers.internal.BaseProviderMetadataTest;
+import org.testng.annotations.Test;
+
+/**
+ * The AWSEC2ProviderTest tests the org.jclouds.providers.AWSEC2Provider class.
+ */
+@Test(groups = "unit", testName = "AWSEC2ProviderTest")
+public class AWSEC2ProviderTest extends BaseProviderMetadataTest {
+
+ public AWSEC2ProviderTest() {
+ super(new AWSEC2ProviderMetadata(), new AWSEC2ApiMetadata());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java
new file mode 100644
index 0000000..5c3fad3
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.aws.ec2.binders;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static com.google.common.io.BaseEncoding.base64;
+import static org.testng.Assert.assertEquals;
+
+import java.net.UnknownHostException;
+
+import org.jclouds.aws.ec2.domain.LaunchSpecification;
+import org.jclouds.ec2.domain.InstanceType;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+@Test(groups = "unit")
+public class BindLaunchSpecificationToFormParamsTest {
+ BindLaunchSpecificationToFormParams binder = new BindLaunchSpecificationToFormParams();
+
+ @Test
+ public void testApplyWithBlockDeviceMappings() throws UnknownHostException {
+ LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123")
+ .mapNewVolumeToDevice("/dev/sda1", 120, true).build();
+
+ assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro",
+ "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.BlockDeviceMapping.1.DeviceName",
+ "/dev/sda1", "LaunchSpecification.BlockDeviceMapping.1.Ebs.VolumeSize", "120",
+ "LaunchSpecification.BlockDeviceMapping.1.Ebs.DeleteOnTermination", "true"));
+ }
+
+ @Test
+ public void testApplyWithUserData() throws UnknownHostException {
+ LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123")
+ .userData("hello".getBytes()).build();
+
+ assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro",
+ "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.UserData",
+ base64().encode("hello".getBytes(UTF_8))));
+ }
+
+ @Test
+ public void testApplyWithSecurityId() throws UnknownHostException {
+ LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123")
+ .securityGroupId("sid-foo").build();
+
+ assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro",
+ "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.SecurityGroupId.1", "sid-foo"));
+ }
+
+ @Test
+ public void testApplyWithSubnetId() throws UnknownHostException {
+ LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123")
+ .subnetId("subnet-xyz").build();
+
+ assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro",
+ "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.SubnetId", "subnet-xyz"));
+ }
+
+ @Test
+ public void testApplyWithIAMInstanceProfileArn() {
+ LaunchSpecification spec = LaunchSpecification.builder()
+ .instanceType(InstanceType.T1_MICRO)
+ .imageId("ami-123")
+ .iamInstanceProfileArn("arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver")
+ .build();
+
+ assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro",
+ "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.IamInstanceProfile.Arn",
+ "arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver"));
+ }
+
+ @Test
+ public void testApplyWithIAMInstanceProfileName() {
+ LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123")
+ .iamInstanceProfileName("Webserver").build();
+
+ assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro",
+ "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.IamInstanceProfile.Name", "Webserver"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindTagsToIndexedFormParamsTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindTagsToIndexedFormParamsTest.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindTagsToIndexedFormParamsTest.java
new file mode 100644
index 0000000..64283f7
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/binders/BindTagsToIndexedFormParamsTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.aws.ec2.binders;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.File;
+
+import org.jclouds.http.HttpRequest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+/**
+ * Tests behavior of {@code BindTagsToIndexedFormParams}
+ */
+@Test(groups = "unit")
+public class BindTagsToIndexedFormParamsTest {
+ Injector injector = Guice.createInjector();
+ BindTagsToIndexedFormParams binder = injector.getInstance(BindTagsToIndexedFormParams.class);
+
+ public void test() {
+ HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
+ request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("one", "alpha").put("two", "beta").build());
+ assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=one&Tag.1.Value=alpha&Tag.2.Key=two&Tag.2.Value=beta");
+ }
+
+ public void testEmpty() {
+ HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
+ request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("empty", "").build());
+ assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=empty&Tag.1.Value=");
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testMustBeArray() {
+ HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
+ binder.bindToRequest(request, new File("foo"));
+ }
+
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testNullIsBad() {
+ HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
+ binder.bindToRequest(request, null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceExpectTest.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceExpectTest.java
new file mode 100644
index 0000000..da2f898
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceExpectTest.java
@@ -0,0 +1,278 @@
+/*
+ * 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.aws.ec2.compute;
+
+import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.blockUntilRunning;
+import static org.testng.Assert.assertEquals;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.aws.ec2.compute.internal.BaseAWSEC2ComputeServiceExpectTest;
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.predicates.NodePredicates;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests the compute service abstraction of the EC2 api.
+ */
+@Test(groups = "unit", testName = "AWSEC2ComputeServiceExpectTest")
+public class AWSEC2ComputeServiceExpectTest extends BaseAWSEC2ComputeServiceExpectTest {
+
+ private HttpResponse requestSpotInstancesResponse;
+ private HttpRequest describeSpotInstanceRequest;
+ private HttpResponse describeSpotInstanceResponse;
+
+ @BeforeClass
+ @Override
+ protected void setupDefaultRequests() {
+ super.setupDefaultRequests();
+ requestSpotInstancesResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResourceWithContentType(
+ "/request_spot_instances-ebs.xml", MediaType.APPLICATION_XML)).build();
+
+ describeSpotInstanceRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "DescribeSpotInstanceRequests")
+ .addFormParam("SpotInstanceRequestId.1", "sir-228e6406").build());
+
+ describeSpotInstanceResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResourceWithContentType(
+ "/request_spot_instances-ebs.xml", MediaType.APPLICATION_XML)).build();
+ }
+
+ public void testLaunchVPCSpotInstanceSubnetId() throws Exception {
+ HttpRequest requestSpotInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "RequestSpotInstances")
+ .addFormParam("InstanceCount", "1")
+ .addFormParam("LaunchSpecification.ImageId", "ami-be3adfd7")
+ .addFormParam("LaunchSpecification.InstanceType", "m1.small")
+ .addFormParam("LaunchSpecification.KeyName", "Demo")
+ .addFormParam("LaunchSpecification.Placement.AvailabilityZone", "us-east-1a")
+ .addFormParam("LaunchSpecification.SubnetId", "subnet-xyz")
+ .addFormParam("LaunchSpecification.UserData", "I2Nsb3VkLWNvbmZpZwpyZXBvX3VwZ3JhZGU6IG5vbmUK")
+ .addFormParam("SpotPrice", "1.0").build());
+
+ Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
+ requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
+ requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
+ requestResponseMap.put(describeImagesRequest, describeImagesResponse);
+ requestResponseMap.put(createKeyPairRequest, createKeyPairResponse);
+ requestResponseMap.put(createSecurityGroupRequest, createSecurityGroupResponse);
+ requestResponseMap.put(describeSecurityGroupRequest, describeSecurityGroupResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequest22, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequestGroup, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(requestSpotInstancesRequest, requestSpotInstancesResponse);
+ requestResponseMap.put(describeSpotInstanceRequest, describeSpotInstanceResponse);
+
+ ComputeService createsVPCSpotInstance = requestsSendResponses(requestResponseMap.build());
+
+ Template template = createsVPCSpotInstance.templateBuilder().locationId("us-east-1a").build();
+
+ template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(1f).subnetId("subnet-xyz").keyPair("Demo").blockUntilRunning(false);
+
+ NodeMetadata node = Iterables.getOnlyElement(createsVPCSpotInstance.createNodesInGroup("test", 1, template));
+ assertEquals(node.getId(), "us-east-1/sir-228e6406");
+ }
+
+ String iamInstanceProfileArn = "arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver";
+
+ public void testLaunchSpotInstanceIAMInstanceProfileArn() throws Exception {
+ HttpRequest requestSpotInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "RequestSpotInstances")
+ .addFormParam("InstanceCount", "1")
+ .addFormParam("LaunchSpecification.IamInstanceProfile.Arn", iamInstanceProfileArn)
+ .addFormParam("LaunchSpecification.ImageId", "ami-be3adfd7")
+ .addFormParam("LaunchSpecification.InstanceType", "m1.small")
+ .addFormParam("LaunchSpecification.Placement.AvailabilityZone", "us-east-1a")
+ .addFormParam("LaunchSpecification.SecurityGroup.1", "jclouds#test")
+ .addFormParam("LaunchSpecification.UserData", "I2Nsb3VkLWNvbmZpZwpyZXBvX3VwZ3JhZGU6IG5vbmUK")
+ .addFormParam("SpotPrice", "1.0").build());
+
+ Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
+ requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
+ requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
+ requestResponseMap.put(describeImagesRequest, describeImagesResponse);
+ requestResponseMap.put(createKeyPairRequest, createKeyPairResponse);
+ requestResponseMap.put(createSecurityGroupRequest, createSecurityGroupResponse);
+ requestResponseMap.put(describeSecurityGroupRequest, describeSecurityGroupResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequest22, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequestGroup, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(requestSpotInstancesRequest, requestSpotInstancesResponse);
+ requestResponseMap.put(describeSpotInstanceRequest, describeSpotInstanceResponse);
+
+ ComputeService createsSpotInstance = requestsSendResponses(requestResponseMap.build());
+
+ Template template = createsSpotInstance.templateBuilder().locationId("us-east-1a").build();
+
+ template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(1f).iamInstanceProfileArn(iamInstanceProfileArn)
+ .noKeyPair().blockUntilRunning(false);
+
+ NodeMetadata node = Iterables.getOnlyElement(createsSpotInstance.createNodesInGroup("test", 1, template));
+ assertEquals(node.getId(), "us-east-1/sir-228e6406");
+ }
+
+ public void testLaunchSpotInstanceIAMInstanceProfileName() throws Exception {
+ HttpRequest requestSpotInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "RequestSpotInstances")
+ .addFormParam("InstanceCount", "1")
+ .addFormParam("LaunchSpecification.IamInstanceProfile.Name", "Webserver")
+ .addFormParam("LaunchSpecification.ImageId", "ami-be3adfd7")
+ .addFormParam("LaunchSpecification.InstanceType", "m1.small")
+ .addFormParam("LaunchSpecification.Placement.AvailabilityZone", "us-east-1a")
+ .addFormParam("LaunchSpecification.SecurityGroup.1", "jclouds#test")
+ .addFormParam("LaunchSpecification.UserData", "I2Nsb3VkLWNvbmZpZwpyZXBvX3VwZ3JhZGU6IG5vbmUK")
+ .addFormParam("SpotPrice", "1.0").build());
+
+ Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
+ requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
+ requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
+ requestResponseMap.put(describeImagesRequest, describeImagesResponse);
+ requestResponseMap.put(createKeyPairRequest, createKeyPairResponse);
+ requestResponseMap.put(createSecurityGroupRequest, createSecurityGroupResponse);
+ requestResponseMap.put(describeSecurityGroupRequest, describeSecurityGroupResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequest22, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequestGroup, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(requestSpotInstancesRequest, requestSpotInstancesResponse);
+ requestResponseMap.put(describeSpotInstanceRequest, describeSpotInstanceResponse);
+
+ ComputeService createsSpotInstance = requestsSendResponses(requestResponseMap.build());
+
+ Template template = createsSpotInstance.templateBuilder().locationId("us-east-1a").build();
+
+ template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(1f).iamInstanceProfileName("Webserver")
+ .noKeyPair().blockUntilRunning(false);
+
+ NodeMetadata node = Iterables.getOnlyElement(createsSpotInstance.createNodesInGroup("test", 1, template));
+ assertEquals(node.getId(), "us-east-1/sir-228e6406");
+ }
+
+ public void testCreateNodeWithIAMInstanceProfileArn() throws Exception {
+ HttpRequest runInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "RunInstances")
+ .addFormParam("IamInstanceProfile.Arn", iamInstanceProfileArn)
+ .addFormParam("ImageId", "ami-be3adfd7")
+ .addFormParam("InstanceType", "m1.small")
+ .addFormParam("MaxCount", "1")
+ .addFormParam("MinCount", "1")
+ .addFormParam("SecurityGroup.1", "jclouds#test")
+ .addFormParam("UserData", "I2Nsb3VkLWNvbmZpZwpyZXBvX3VwZ3JhZGU6IG5vbmUK").build());
+
+ Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
+ requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
+ requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
+ requestResponseMap.put(describeImagesRequest, describeImagesResponse);
+ requestResponseMap.put(createKeyPairRequest, createKeyPairResponse);
+ requestResponseMap.put(createSecurityGroupRequest, createSecurityGroupResponse);
+ requestResponseMap.put(describeSecurityGroupRequest, describeSecurityGroupResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequest22, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequestGroup, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(runInstancesRequest, runInstancesResponse);
+ requestResponseMap.put(describeInstanceRequest, describeInstanceResponse);
+ requestResponseMap.put(describeImageRequest, describeImagesResponse);
+
+ ComputeService apiThatCreatesNode = requestsSendResponses(requestResponseMap.build());
+
+ NodeMetadata node = Iterables.getOnlyElement(apiThatCreatesNode.createNodesInGroup("test", 1,
+ blockUntilRunning(false).iamInstanceProfileArn(iamInstanceProfileArn).noKeyPair()));
+ assertEquals(node.getId(), "us-east-1/i-2baa5550");
+ }
+
+ public void testCreateNodeWithIAMInstanceProfileName() throws Exception {
+ HttpRequest runInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "RunInstances")
+ .addFormParam("IamInstanceProfile.Name", "Webserver")
+ .addFormParam("ImageId", "ami-be3adfd7")
+ .addFormParam("InstanceType", "m1.small")
+ .addFormParam("MaxCount", "1")
+ .addFormParam("MinCount", "1")
+ .addFormParam("SecurityGroup.1", "jclouds#test")
+ .addFormParam("UserData", "I2Nsb3VkLWNvbmZpZwpyZXBvX3VwZ3JhZGU6IG5vbmUK").build());
+
+ Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
+ requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
+ requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
+ requestResponseMap.put(describeImagesRequest, describeImagesResponse);
+ requestResponseMap.put(createKeyPairRequest, createKeyPairResponse);
+ requestResponseMap.put(createSecurityGroupRequest, createSecurityGroupResponse);
+ requestResponseMap.put(describeSecurityGroupRequest, describeSecurityGroupResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequest22, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(authorizeSecurityGroupIngressRequestGroup, authorizeSecurityGroupIngressResponse);
+ requestResponseMap.put(runInstancesRequest, runInstancesResponse);
+ requestResponseMap.put(describeInstanceRequest, describeInstanceResponse);
+ requestResponseMap.put(describeImageRequest, describeImagesResponse);
+
+ ComputeService apiThatCreatesNode = requestsSendResponses(requestResponseMap.build());
+
+ NodeMetadata node = Iterables.getOnlyElement(apiThatCreatesNode.createNodesInGroup("test", 1,
+ blockUntilRunning(false).iamInstanceProfileName("Webserver").noKeyPair()));
+ assertEquals(node.getId(), "us-east-1/i-2baa5550");
+ }
+
+ public void testListNodesWhereImageDoesntExist() throws Exception {
+ HttpRequest describeInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "DescribeInstances").build());
+
+ HttpRequest describeSpotInstancesRequest = formSigner.filter(HttpRequest.builder().method("POST")
+ .endpoint("https://ec2." + region + ".amazonaws.com/")
+ .addHeader("Host", "ec2." + region + ".amazonaws.com")
+ .addFormParam("Action", "DescribeSpotInstanceRequests").build());
+
+ HttpResponse noSpotInstancesResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType(
+ "<DescribeSpotInstanceRequestsResponse><spotInstanceRequestSet></spotInstanceRequestSet></DescribeSpotInstanceRequestsResponse>",
+ MediaType.APPLICATION_XML)).build();
+
+ HttpResponse noImagesResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType(
+ "<DescribeImagesResponse><imagesSet></imagesSet></DescribeImagesResponse>",
+ MediaType.APPLICATION_XML)).build();
+
+ Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
+ requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
+ requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
+ requestResponseMap.put(describeImagesRequest, noImagesResponse);
+ requestResponseMap.put(describeInstancesRequest, describeInstanceResponse);
+ requestResponseMap.put(describeSpotInstancesRequest, noSpotInstancesResponse);
+
+ ComputeService listsWithoutImages = requestsSendResponses(requestResponseMap.build());
+
+ NodeMetadata node = Iterables.getOnlyElement(listsWithoutImages.listNodesDetailsMatching(NodePredicates.all()));
+ assertEquals(node.getId(), "us-east-1/i-2baa5550");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a5e842c0/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java
new file mode 100644
index 0000000..ba7431b
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.8.1-stratos/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java
@@ -0,0 +1,192 @@
+/*
+ * 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.aws.ec2.compute;
+
+import static com.google.common.collect.Iterables.getOnlyElement;
+import static com.google.common.collect.Sets.newTreeSet;
+import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
+import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
+import static org.jclouds.ec2.util.IpPermissions.permit;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Date;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.ContextBuilder;
+import org.jclouds.aws.cloudwatch.AWSCloudWatchProviderMetadata;
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.ec2.domain.AWSRunningInstance;
+import org.jclouds.aws.ec2.domain.MonitoringState;
+import org.jclouds.aws.ec2.features.AWSSecurityGroupApi;
+import org.jclouds.cloudwatch.CloudWatchApi;
+import org.jclouds.cloudwatch.domain.Dimension;
+import org.jclouds.cloudwatch.domain.EC2Constants;
+import org.jclouds.cloudwatch.domain.GetMetricStatistics;
+import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse;
+import org.jclouds.cloudwatch.domain.Statistics;
+import org.jclouds.cloudwatch.domain.Unit;
+import org.jclouds.compute.domain.ExecResponse;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.predicates.NodePredicates;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ec2.compute.EC2ComputeServiceLiveTest;
+import org.jclouds.ec2.domain.KeyPair;
+import org.jclouds.ec2.domain.SecurityGroup;
+import org.jclouds.ec2.features.InstanceApi;
+import org.jclouds.ec2.features.KeyPairApi;
+import org.jclouds.net.domain.IpProtocol;
+import org.jclouds.scriptbuilder.domain.Statements;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSortedSet;
+import com.google.common.util.concurrent.ListenableFuture;
+
+@Test(groups = "live", singleThreaded = true, testName = "AWSEC2ComputeServiceLiveTest")
+public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
+
+ public AWSEC2ComputeServiceLiveTest() {
+ provider = "aws-ec2";
+ group = "ec2";
+ }
+
+ @Override
+ @Test
+ public void testExtendedOptionsAndLogin() throws Exception {
+ String region = "us-west-2";
+
+ AWSSecurityGroupApi securityGroupApi = view.unwrapApi(AWSEC2Api.class).getSecurityGroupApi().get();
+
+ KeyPairApi keyPairApi = view.unwrapApi(AWSEC2Api.class).getKeyPairApi().get();
+
+ InstanceApi instanceApi = view.unwrapApi(AWSEC2Api.class).getInstanceApi().get();
+
+ String group = this.group + "o";
+
+ Date before = new Date();
+
+ ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("test", group);
+
+ ImmutableSet<String> tags = ImmutableSet.of(group);
+
+ // note that if you change the location, you must also specify image parameters
+ Template template = client.templateBuilder().locationId(region).osFamily(AMZN_LINUX).os64Bit(true).build();
+ template.getOptions().tags(tags);
+ template.getOptions().userMetadata(userMetadata);
+ template.getOptions().tags(tags);
+ template.getOptions().as(AWSEC2TemplateOptions.class).enableMonitoring();
+ template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(0.3f);
+
+ String startedId = null;
+ try {
+ cleanupExtendedStuffInRegion(region, securityGroupApi, keyPairApi, group);
+
+ Thread.sleep(3000);// eventual consistency if deletes actually occurred.
+
+ // create a security group that allows ssh in so that our scripts later
+ // will work
+ String groupId = securityGroupApi.createSecurityGroupInRegionAndReturnId(region, group, group);
+
+ securityGroupApi.authorizeSecurityGroupIngressInRegion(region, groupId, permit(IpProtocol.TCP).port(22));
+
+ template.getOptions().as(AWSEC2TemplateOptions.class).securityGroupIds(groupId);
+
+ // create a keypair to pass in as well
+ KeyPair result = keyPairApi.createKeyPairInRegion(region, group);
+ template.getOptions().as(AWSEC2TemplateOptions.class).keyPair(result.getKeyName());
+
+ // pass in the private key, so that we can run a script with it
+ assert result.getKeyMaterial() != null : result;
+ template.getOptions().overrideLoginPrivateKey(result.getKeyMaterial());
+
+ Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
+ NodeMetadata first = getOnlyElement(nodes);
+
+ checkUserMetadataContains(first, userMetadata);
+ checkTagsInNodeEquals(first, tags);
+
+ assert first.getCredentials() != null : first;
+ assert first.getCredentials().identity != null : first;
+
+ startedId = first.getProviderId();
+
+ AWSRunningInstance instance = AWSRunningInstance.class.cast(getOnlyElement(getOnlyElement(instanceApi
+ .describeInstancesInRegion(region, startedId))));
+
+ assertEquals(instance.getKeyName(), group);
+ assert instance.getSpotInstanceRequestId() != null;
+ assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED);
+
+ // generate some load
+ ListenableFuture<ExecResponse> future = client.submitScriptOnNode(first.getId(), Statements
+ .exec("while true; do true; done"), runAsRoot(false).nameTask("cpuSpinner"));
+
+ // monitoring granularity for free tier is 5 minutes, so lets make sure we have data.
+ Thread.sleep(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));
+
+ // stop the spinner
+ future.cancel(true);
+
+ CloudWatchApi monitoringApi = ContextBuilder.newBuilder(new AWSCloudWatchProviderMetadata())
+ .credentials(identity, credential)
+ .modules(setupModules())
+ .buildApi(CloudWatchApi.class);
+
+ try {
+ GetMetricStatisticsResponse datapoints = monitoringApi.getMetricApiForRegion(instance.getRegion())
+ .getMetricStatistics(GetMetricStatistics.builder()
+ .dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, instance.getId()))
+ .unit(Unit.PERCENT)
+ .namespace("AWS/EC2")
+ .metricName("CPUUtilization")
+ .startTime(before)
+ .endTime(new Date())
+ .period(60)
+ .statistic(Statistics.AVERAGE)
+ .build());
+ assert datapoints.size() > 0 : instance;
+ } finally {
+ monitoringApi.close();
+ }
+
+ // make sure we made our dummy group and also let in the user's group
+ assertEquals(newTreeSet(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group, group));
+
+ // make sure our dummy group has no rules
+ SecurityGroup secgroup = getOnlyElement(securityGroupApi.describeSecurityGroupsInRegion(instance
+ .getRegion(), "jclouds#" + group));
+
+ assert secgroup.size() == 0 : secgroup;
+
+ // try to run a script with the original keyPair
+ runScriptWithCreds(group, first.getOperatingSystem(), LoginCredentials.builder().user(
+ first.getCredentials().identity).privateKey(result.getKeyMaterial()).build());
+
+ } finally {
+ client.destroyNodesMatching(NodePredicates.inGroup(group));
+ if (startedId != null) {
+ // ensure we didn't delete these resources!
+ assertEquals(keyPairApi.describeKeyPairsInRegion(region, group).size(), 1);
+ assertEquals(securityGroupApi.describeSecurityGroupsInRegion(region, group).size(), 1);
+ }
+ cleanupExtendedStuffInRegion(region, securityGroupApi, keyPairApi, group);
+ }
+ }
+}