http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/BundleInstanceS3StorageOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/BundleInstanceS3StorageOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/BundleInstanceS3StorageOptions.java new file mode 100644 index 0000000..6347e21 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/BundleInstanceS3StorageOptions.java @@ -0,0 +1,94 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import org.jclouds.domain.Credentials; +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; +import org.jclouds.location.Provider; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Supplier; +import com.google.common.collect.Multimap; +import com.google.inject.Inject; + +/** + * Contains options supported in the Form API for the RegisterImage operation. + * <h2> + * Usage</h2> The recommended way to instantiate a + * BundleInstanceS3StorageOptions object is to statically import + * BundleInstanceS3StorageOptions.Builder.* and invoke a static creation method + * followed by an instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.BundleInstanceS3StorageOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * String imageId = connection.getWindowsServices().bundleInstanceInRegion(...bucketOwnedBy(anotherAccessKey)); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-BundleInstance.html" + * /> + */ +public class BundleInstanceS3StorageOptions extends BaseEC2RequestOptions { + + @Inject + @VisibleForTesting + @Provider + Supplier<Credentials> creds; + + @Override + public Multimap<String, String> buildFormParameters() { + if (getAwsAccessKeyId() == null) { + checkState(creds != null, "creds should have been injected"); + bucketOwnedBy(creds.get().identity); + } + return super.buildFormParameters(); + } + + /** + * + * @param ccessKeyId + * The Access Key ID of the owner of the Amazon S3 bucket. + */ + public BundleInstanceS3StorageOptions bucketOwnedBy(String ccessKeyId) { + formParameters.put("Storage.S3.AWSAccessKeyId", checkNotNull(ccessKeyId, "ccessKeyId")); + return this; + } + + /** + * + * @return The Access Key ID of the owner of the Amazon S3 bucket. + */ + public String getAwsAccessKeyId() { + return getFirstFormOrNull("Storage.S3.AWSAccessKeyId"); + } + + public static class Builder { + /** + * @see BundleInstanceS3StorageOptions#bucketOwnedBy(accessKeyId) + */ + public static BundleInstanceS3StorageOptions bucketOwnedBy(String accessKeyId) { + BundleInstanceS3StorageOptions options = new BundleInstanceS3StorageOptions(); + return options.bucketOwnedBy(accessKeyId); + } + + } +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateImageOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateImageOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateImageOptions.java new file mode 100644 index 0000000..04a63d1 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateImageOptions.java @@ -0,0 +1,93 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the CreateImage operation. <h2> + * Usage</h2> The recommended way to instantiate a CreateImageOptions object is to statically import + * CreateImageOptions.Builder.* and invoke a static creation method followed by an instance mutator + * (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.CreateImageOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Future<Set<ImageMetadata>> images = connection.getAMIApi().get().createImage(withDescription("123125").noReboot()); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-CreateImage.html" + * /> + */ +public class CreateImageOptions extends BaseEC2RequestOptions { + public static final CreateImageOptions NONE = new CreateImageOptions(); + + /** + * The description of the AMI that was provided during image creation. + * <p/> + * + * Up to 255 characters + */ + public CreateImageOptions withDescription(String description) { + formParameters.put("Description", checkNotNull(description, "description")); + return this; + } + + public String getDescription() { + return getFirstFormOrNull("Description"); + + } + + /** + * By default this property is set to false, which means Amazon EC2 attempts to cleanly shut down + * the instance before image creation and reboots the instance afterwards. When set to true, + * Amazon EC2 does not shut down the instance before creating the image. When this option is + * used, file system integrity on the created image cannot be guaranteed. + */ + public CreateImageOptions noReboot() { + formParameters.put("NoReboot", "true"); + return this; + } + + public boolean getNoReboot() { + return getFirstFormOrNull("NoReboot") != null; + } + + public static class Builder { + + /** + * @see CreateImageOptions#withDescription(String ) + */ + public static CreateImageOptions withDescription(String description) { + CreateImageOptions options = new CreateImageOptions(); + return options.withDescription(description); + } + + /** + * @see CreateImageOptions#noReboot() + */ + public static CreateImageOptions noReboot() { + CreateImageOptions options = new CreateImageOptions(); + return options.noReboot(); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateSnapshotOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateSnapshotOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateSnapshotOptions.java new file mode 100644 index 0000000..ffe40fc --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateSnapshotOptions.java @@ -0,0 +1,69 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the CreateSnapshot operation. <h2> + * Usage</h2> The recommended way to instantiate a CreateSnapshotOptions object is to statically + * import CreateSnapshotOptions.Builder.* and invoke a static creation method followed by an + * instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.CreateSnapshotOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Snapshot snapshot = connection.getElasticBlockStoreApi().get().createSnapshotInRegion(volumeId, withDescription("123125")); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-CreateSnapshot.html" + * /> + */ +public class CreateSnapshotOptions extends BaseEC2RequestOptions { + + /** + * Description of the Amazon EBS snapshot. + * <p/> + * + * Up to 255 characters + */ + public CreateSnapshotOptions withDescription(String description) { + formParameters.put("Description", checkNotNull(description, "description")); + return this; + } + + public String getDescription() { + return getFirstFormOrNull("Description"); + + } + + public static class Builder { + + /** + * @see CreateSnapshotOptions#withDescription(String ) + */ + public static CreateSnapshotOptions withDescription(String identityId) { + CreateSnapshotOptions options = new CreateSnapshotOptions(); + return options.withDescription(identityId); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateVolumeOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateVolumeOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateVolumeOptions.java new file mode 100644 index 0000000..9c2e182 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/CreateVolumeOptions.java @@ -0,0 +1,146 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the CreateVolume operation. <h2> + * Usage</h2> The recommended way to instantiate a CreateVolumeOptions object is to statically + * import CreateVolumeOptions.Builder.* and invoke a static creation method followed by an + * instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.CreateVolumeOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Volume volume = connection.getElasticBlockStoreApi().get().createVolumeInAvailabilityZone(availabilityZone, fromSnapshotId("123125")); + * <code> + * + * @see <a + * href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html" + * /> + */ +public class CreateVolumeOptions extends BaseEC2RequestOptions { + + /** + * Snapshot ID to create this volume from. + */ + public CreateVolumeOptions withSize(int size) { + formParameters.put("Size", Integer.toString(size)); + return this; + } + + public int getSize() { + return Integer.parseInt(getFirstFormOrNull("Size")); + } + + /** + * Snapshot ID to create this volume from. + */ + public CreateVolumeOptions fromSnapshotId(String snapshotId) { + formParameters.put("SnapshotId", checkNotNull(snapshotId, "snapshotId")); + return this; + } + + public String getSnapshotId() { + return getFirstFormOrNull("SnapshotId"); + } + + /** + * EBS volume type to use - if not specified, will be "standard". + */ + public CreateVolumeOptions volumeType(String volumeType) { + formParameters.put("VolumeType", checkNotNull(volumeType, "volumeType")); + return this; + } + + public String getVolumeType() { + return getFirstFormOrNull("VolumeType"); + } + + /** + * EBS provisioned IOPS + */ + public CreateVolumeOptions withIops(Integer iops) { + formParameters.put("Iops", checkNotNull(iops, "iops").toString()); + return this; + } + + public Integer getIops() { + return Integer.valueOf(getFirstFormOrNull("Iops")); + } + + /** + * Should this EBS volume be encrypted? + */ + public CreateVolumeOptions isEncrypted(boolean encrypted) { + if (encrypted) + formParameters.put("Encrypted", "true"); + return this; + } + + public boolean getEncrypted() { + return Boolean.parseBoolean(getFirstFormOrNull("Encrypted")); + } + + public static class Builder { + + /** + * @see CreateVolumeOptions#fromSnapshotId(String) + */ + public static CreateVolumeOptions fromSnapshotId(String snapshotId) { + CreateVolumeOptions options = new CreateVolumeOptions(); + return options.fromSnapshotId(snapshotId); + } + + /** + * @see CreateVolumeOptions#withSize(int) + */ + public static CreateVolumeOptions withSize(int size) { + CreateVolumeOptions options = new CreateVolumeOptions(); + return options.withSize(size); + } + + /** + * @see CreateVolumeOptions#volumeType(String) + */ + public static CreateVolumeOptions volumeType(String volumeType) { + CreateVolumeOptions options = new CreateVolumeOptions(); + return options.volumeType(volumeType); + } + + /** + * @see CreateVolumeOptions#withIops(Integer) + */ + public static CreateVolumeOptions withIops(Integer iops) { + CreateVolumeOptions options = new CreateVolumeOptions(); + return options.withIops(iops); + } + + /** + * @see CreateVolumeOptions#isEncrypted(boolean) + */ + public static CreateVolumeOptions isEncrypted(boolean encrypted) { + CreateVolumeOptions options = new CreateVolumeOptions(); + return options.isEncrypted(encrypted); + } + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeAvailabilityZonesOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeAvailabilityZonesOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeAvailabilityZonesOptions.java new file mode 100644 index 0000000..daef882 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeAvailabilityZonesOptions.java @@ -0,0 +1,67 @@ +/* + * 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.ec2.options; + +import java.util.Arrays; +import java.util.Set; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the DescribeAvailabilityZones operation. <h2> + * Usage</h2> The recommended way to instantiate a DescribeAvailabilityZonesOptions object is to + * statically import DescribeAvailabilityZonesOptions.Builder.* and invoke a static creation method + * followed by an instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.DescribeAvailabilityZonesOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Future<Set<ImageMetadata>> images = connection.getAvailabilityZoneAndRegionApi().get().describeAvailabilityZones(zones("us-east-1a", "us-east-1b")); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DescribeAvailabilityZones.html" + * /> + */ +public class DescribeAvailabilityZonesOptions extends BaseEC2RequestOptions { + + /** + * Availability Zone name. + */ + public DescribeAvailabilityZonesOptions zones(String... zones) { + String[] zoneStrings = Arrays.copyOf(zones, zones.length, String[].class); + indexFormValuesWithPrefix("ZoneName", zoneStrings); + return this; + } + + public Set<String> getZones() { + return getFormValuesWithKeysPrefixedBy("ZoneName."); + } + + public static class Builder { + + /** + * @see DescribeAvailabilityZonesOptions#zones(String...) + */ + public static DescribeAvailabilityZonesOptions availabilityZones(String... zones) { + DescribeAvailabilityZonesOptions options = new DescribeAvailabilityZonesOptions(); + return options.zones(zones); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeImagesOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeImagesOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeImagesOptions.java new file mode 100644 index 0000000..5e47206 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeImagesOptions.java @@ -0,0 +1,114 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the DescribeImages operation. <h2> + * Usage</h2> The recommended way to instantiate a DescribeImagesOptions object is to statically + * import DescribeImagesOptions.Builder.* and invoke a static creation method followed by an + * instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Future<Set<ImageMetadata>> images = connection.getAMIApi().get().describeImages(executableBy("123125").imageIds(1000, 1004)); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DescribeImages.html" + * /> + */ +public class DescribeImagesOptions extends BaseEC2RequestOptions { + public static final DescribeImagesOptions NONE = new DescribeImagesOptions(); + + /** + * AMIs for which the specified user has explicit launch permissions. + * + */ + public DescribeImagesOptions executableBy(String identityId) { + formParameters.put("ExecutableBy", checkNotNull(identityId, "identityId")); + return this; + } + + public String getExecutableBy() { + return getFirstFormOrNull("ExecutableBy"); + } + + /** + * AMI IDs to describe. + */ + public DescribeImagesOptions imageIds(String... imageIds) { + indexFormValuesWithPrefix("ImageId", imageIds); + return this; + } + + public DescribeImagesOptions imageIds(Iterable<String> imageIds) { + indexFormValuesWithPrefix("ImageId", imageIds); + return this; + } + + public Set<String> getImageIds() { + return getFormValuesWithKeysPrefixedBy("ImageId."); + } + + /** + * Returns AMIs owned by the specified owner. Multiple owners can be specified. + */ + public DescribeImagesOptions ownedBy(String... owners) { + indexFormValuesWithPrefix("Owner", owners); + return this; + } + + public Set<String> getOwners() { + return getFormValuesWithKeysPrefixedBy("Owner."); + } + + public static class Builder { + + /** + * @see DescribeImagesOptions#executableBy(String ) + */ + public static DescribeImagesOptions executableBy(String identityId) { + DescribeImagesOptions options = new DescribeImagesOptions(); + return options.executableBy(identityId); + } + + /** + * @see DescribeImagesOptions#imageIds(String[] ) + */ + public static DescribeImagesOptions imageIds(String... imageIds) { + DescribeImagesOptions options = new DescribeImagesOptions(); + return options.imageIds(imageIds); + } + + /** + * @see DescribeImagesOptions#ownedBy(String[] ) + */ + public static DescribeImagesOptions ownedBy(String... owners) { + DescribeImagesOptions options = new DescribeImagesOptions(); + return options.ownedBy(owners); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java new file mode 100644 index 0000000..670b06f --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeRegionsOptions.java @@ -0,0 +1,67 @@ +/* + * 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.ec2.options; + +import java.util.Arrays; +import java.util.Set; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the DescribeRegions operation. <h2> + * Usage</h2> The recommended way to instantiate a DescribeRegionsOptions object is to statically + * import DescribeRegionsOptions.Builder.* and invoke a static creation method followed by an + * instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.DescribeRegionsOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Future<Set<ImageMetadata>> images = connection.getRegionsAndRegionsServices().describeRegions(regions("us-east-1a", "us-east-1b")); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DescribeRegions.html" + * /> + */ +public class DescribeRegionsOptions extends BaseEC2RequestOptions { + + /** + * Name of a Region. + */ + public DescribeRegionsOptions regions(String... regions) { + String[] regionStrings = Arrays.copyOf(regions, regions.length, String[].class); + indexFormValuesWithPrefix("RegionName", regionStrings); + return this; + } + + public Set<String> getZones() { + return getFormValuesWithKeysPrefixedBy("RegionName."); + } + + public static class Builder { + + /** + * @see DescribeRegionsOptions#regions(String[] ) + */ + public static DescribeRegionsOptions regions(String... regions) { + DescribeRegionsOptions options = new DescribeRegionsOptions(); + return options.regions(regions); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeSnapshotsOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeSnapshotsOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeSnapshotsOptions.java new file mode 100644 index 0000000..31a4486 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DescribeSnapshotsOptions.java @@ -0,0 +1,108 @@ +/* + * 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.ec2.options; + +import java.util.Set; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the DescribeSnapshots operation. <h2> + * Usage</h2> The recommended way to instantiate a DescribeSnapshotsOptions object is to statically + * import DescribeSnapshotsOptions.Builder.* and invoke a static creation method followed by an + * instance mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.DescribeSnapshotsOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Set<Snapshot> snapshots = connection.getElasticBlockStoreApi().get().describeSnapshots(restorableBy("123125").snapshotIds(1000, 1004)); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DescribeSnapshots.html" + * /> + */ +public class DescribeSnapshotsOptions extends BaseEC2RequestOptions { + + /** + * Account ID of a user that can create volumes from the snapshot. + * + */ + public DescribeSnapshotsOptions restorableBy(String... accountIds) { + indexFormValuesWithPrefix("RestorableBy", accountIds); + return this; + } + + public String getRestorableBy() { + return getFirstFormOrNull("RestorableBy"); + } + + /** + * The ID of the Amazon EBS snapshot. + */ + public DescribeSnapshotsOptions snapshotIds(String... snapshotIds) { + indexFormValuesWithPrefix("SnapshotId", snapshotIds); + return this; + } + + public Set<String> getSnapshotIds() { + return getFormValuesWithKeysPrefixedBy("SnapshotId."); + } + + /** + * Returns snapshots owned by the specified owner. Multiple owners can be specified. + * <p/> + * Valid Values: self | amazon | AWS Account ID + */ + public DescribeSnapshotsOptions ownedBy(String... owners) { + indexFormValuesWithPrefix("Owner", owners); + return this; + } + + public Set<String> getOwners() { + return getFormValuesWithKeysPrefixedBy("Owner."); + } + + public static class Builder { + + /** + * @see DescribeSnapshotsOptions#restorableBy(String[] ) + */ + public static DescribeSnapshotsOptions restorableBy(String... accountIds) { + DescribeSnapshotsOptions options = new DescribeSnapshotsOptions(); + return options.restorableBy(accountIds); + } + + /** + * @see DescribeSnapshotsOptions#snapshotIds(String[] ) + */ + public static DescribeSnapshotsOptions snapshotIds(String... snapshotIds) { + DescribeSnapshotsOptions options = new DescribeSnapshotsOptions(); + return options.snapshotIds(snapshotIds); + } + + /** + * @see DescribeSnapshotsOptions#ownedBy(String[] ) + */ + public static DescribeSnapshotsOptions ownedBy(String... owners) { + DescribeSnapshotsOptions options = new DescribeSnapshotsOptions(); + return options.ownedBy(owners); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DetachVolumeOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DetachVolumeOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DetachVolumeOptions.java new file mode 100644 index 0000000..0777402 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/DetachVolumeOptions.java @@ -0,0 +1,85 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the DetachVolume operation. <h2> + * Usage</h2> The recommended way to instantiate a DetachVolumeOptions object is to statically + * import DetachVolumeOptions.Builder.* and invoke a static creation method followed by an instance + * mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.DetachVolumeOptions.Builder.* + * <p/> + * EC2Api client = // get connection + * client.getElasticBlockStoreApi().get().detachVolumeInRegion(null, id, fromDevice("123125").force()); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DetachVolume.html" + * /> + */ +public class DetachVolumeOptions extends BaseEC2RequestOptions { + /** + * The ID of the instance. + */ + public DetachVolumeOptions fromInstance(String instanceId) { + formParameters.put("InstanceId", checkNotNull(instanceId, "instanceId")); + return this; + } + + public String getInstance() { + return getFirstFormOrNull("InstanceId"); + + } + + /** + * The device name. + */ + public DetachVolumeOptions fromDevice(String device) { + formParameters.put("Device", checkNotNull(device, "device")); + return this; + } + + public String getDevice() { + return getFirstFormOrNull("Device"); + + } + + public static class Builder { + /** + * @see DetachVolumeOptions#fromInstance(String ) + */ + public static DetachVolumeOptions fromInstance(String instance) { + DetachVolumeOptions options = new DetachVolumeOptions(); + return options.fromInstance(instance); + } + + /** + * @see DetachVolumeOptions#fromDevice(String ) + */ + public static DetachVolumeOptions fromDevice(String device) { + DetachVolumeOptions options = new DetachVolumeOptions(); + return options.fromDevice(device); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageBackedByEbsOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageBackedByEbsOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageBackedByEbsOptions.java new file mode 100644 index 0000000..813593a --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageBackedByEbsOptions.java @@ -0,0 +1,345 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ec2.domain.Image.Architecture; +import org.jclouds.javax.annotation.Nullable; + +/** + * Contains options supported in the Form API for the RegisterImage operation. <h2> + * Usage</h2> The recommended way to instantiate a RegisterImageBackedByEbsOptions object is to statically + * import RegisterImageBackedByEbsOptions.Builder.* and invoke a static creation method followed by an instance + * mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.RegisterImageBackedByEbsOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * String imageId = connection.getImageServices().registerImageBackedByEbs(...addEphemeralBlockDeviceFromSnapshot("/dev/sda2","virtual-1","snapshot-id")); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-RegisterImage.html" + * /> + */ +public class RegisterImageBackedByEbsOptions extends RegisterImageOptions { + + private int deviceIndex = 1; + + /** + * + * adds a block device to the image from an ebs snapshot. This device is deleted on instance + * termination. + * + * @param name + * The device name (e.g., /dev/sdh). + * @param virtualName + * The virtual device name. (nullable) + * @param snapshotId + * The ID of the snapshot. + */ + public RegisterImageBackedByEbsOptions addEphemeralBlockDeviceFromSnapshot(String deviceName, + @Nullable String virtualName, String snapshotId) { + formParameters.put("BlockDeviceMapping." + deviceIndex + ".DeviceName", checkNotNull( + deviceName, "deviceName")); + if (virtualName != null) + formParameters.put("BlockDeviceMapping." + deviceIndex + ".VirtualName", checkNotNull( + virtualName, "virtualName")); + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.SnapshotId", checkNotNull( + snapshotId, "snapshotId")); + deviceIndex++; + return this; + } + + /** + * + * adds a new block device to the image. This device is deleted on instance termination. + * + * @param name + * The device name (e.g., /dev/sdh). + * @param virtualName + * The virtual device name. + * @param volumeSize + * The size of the volume, in GiBs. + */ + public RegisterImageBackedByEbsOptions addNewEphemeralBlockDevice(String deviceName, + @Nullable String virtualName, int volumeSize) { + checkArgument(volumeSize > 0 && volumeSize < 1025, "volumeSize must be between 1 and 1024 gb"); + formParameters.put("BlockDeviceMapping." + deviceIndex + ".DeviceName", checkNotNull( + deviceName, "deviceName")); + if (virtualName != null) + formParameters.put("BlockDeviceMapping." + deviceIndex + ".VirtualName", checkNotNull( + virtualName, "virtualName")); + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.VolumeSize", volumeSize + ""); + deviceIndex++; + return this; + } + + /** + * + * adds a block device to the image from an ebs snapshot. + * + * @param deviceName + * The device name (e.g., /dev/sdh). + * @param virtualName + * The virtual device name. (nullable) + * @param snapshotId + * The ID of the snapshot. + * @param deleteOnTermination + * Whether this volume should be automatically deleted on instance termination. + * Defaults to false. + * @param volumeType + * What EBS volume type should be used. + * @param iops + * EBS provisioned IOPS for this volume. + * @param encrypted + * Whether this volume should be encrypted. + */ + public RegisterImageBackedByEbsOptions addBlockDeviceFromSnapshot(String deviceName, + @Nullable String virtualName, String snapshotId, boolean deleteOnTermination, + @Nullable String volumeType, @Nullable Integer iops, boolean encrypted) { + + addAdvancedEbsOptions(deleteOnTermination, volumeType, iops, encrypted); + addEphemeralBlockDeviceFromSnapshot(deviceName, virtualName, snapshotId); + + return this; + } + + /** + * + * adds a new block device to the image. + * + * @param deviceName + * The device name (e.g., /dev/sdh). + * @param virtualName + * The virtual device name. (nullable) + * @param volumeSize + * The size of the volume, in GiBs.. + * @param deleteOnTermination + * Whether this volume should be automatically deleted on instance termination. + * Defaults to false. + * @param volumeType + * What EBS volume type should be used. + * @param iops + * EBS provisioned IOPS for this volume. + * @param encrypted + * Whether this volume should be encrypted. + */ + public RegisterImageBackedByEbsOptions addNewBlockDevice(String deviceName, + @Nullable String virtualName, + int volumeSize, + boolean deleteOnTermination, + @Nullable String volumeType, + @Nullable Integer iops, + boolean encrypted) { + addAdvancedEbsOptions(deleteOnTermination, volumeType, iops, encrypted); + addNewEphemeralBlockDevice(deviceName, virtualName, volumeSize); + + return this; + } + + private RegisterImageBackedByEbsOptions addAdvancedEbsOptions(boolean deleteOnTermination, + @Nullable String volumeType, + @Nullable Integer iops, + boolean encrypted) { + + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.DeleteOnTermination", + Boolean.toString(deleteOnTermination)); + + if (volumeType != null) + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.VolumeType", volumeType); + if (iops != null) + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.Iops", iops.toString()); + if (encrypted) + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.Encrypted", "true"); + + return this; + } + + /** + * + * adds a block device to the image from an ebs snapshot. This device is retained on instance + * termination. + * + * @param name + * The device name (e.g., /dev/sdh). + * @param virtualName + * The virtual device name. (nullable) + * @param snapshotId + * The ID of the snapshot. + */ + public RegisterImageBackedByEbsOptions addBlockDeviceFromSnapshot(String deviceName, + @Nullable String virtualName, String snapshotId) { + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.DeleteOnTermination", "false"); + addEphemeralBlockDeviceFromSnapshot(deviceName, virtualName, snapshotId); + return this; + } + + /** + * + * adds a new block device to the image. This device is retained on instance termination. + * + * @param name + * The device name (e.g., /dev/sdh). + * @param virtualName + * The virtual device name. + * @param volumeSize + * The size of the volume, in GiBs.. + */ + public RegisterImageBackedByEbsOptions addNewBlockDevice(String deviceName, + @Nullable String virtualName, int volumeSize) { + formParameters.put("BlockDeviceMapping." + deviceIndex + ".Ebs.DeleteOnTermination", "false"); + addNewEphemeralBlockDevice(deviceName, virtualName, volumeSize); + return this; + } + + public static class Builder { + /** + * @see RegisterImageBackedByEbsOptions#asArchitecture(Architecture) + */ + public static RegisterImageBackedByEbsOptions asArchitecture(Architecture architecture) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.asArchitecture(architecture); + } + + /** + * @see RegisterImageBackedByEbsOptions#withDescription(String) + */ + public static RegisterImageBackedByEbsOptions withDescription(String additionalInfo) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.withDescription(additionalInfo); + } + + /** + * @see RegisterImageBackedByEbsOptions#withKernelId(String) + */ + public static RegisterImageBackedByEbsOptions withKernelId(String kernelId) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.withKernelId(kernelId); + } + + /** + * @see RegisterImageBackedByEbsOptions#withRamdisk(String) + */ + public static RegisterImageBackedByEbsOptions withRamdisk(String ramdiskId) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.withRamdisk(ramdiskId); + } + + /** + * @see RegisterImageBackedByEbsOptions#addBlockDeviceFromSnapshot(String, String, String) + */ + public static RegisterImageBackedByEbsOptions addBlockDeviceFromSnapshot(String deviceName, + @Nullable String virtualName, String snapshotId) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.addBlockDeviceFromSnapshot(deviceName, virtualName, snapshotId); + } + + /** + * @see RegisterImageBackedByEbsOptions#addBlockDeviceFromSnapshot(String, String, String, boolean, String, Integer, boolean) + */ + public static RegisterImageBackedByEbsOptions addBlockDeviceFromSnapshot(String deviceName, + @Nullable String virtualName, + String snapshotId, + boolean deleteOnTermination, + @Nullable String volumeType, + @Nullable Integer iops, + boolean encrypted) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.addBlockDeviceFromSnapshot(deviceName, virtualName, snapshotId, deleteOnTermination, + volumeType, iops, encrypted); + } + + /** + * @see RegisterImageBackedByEbsOptions#addEphemeralBlockDeviceFromSnapshot(String, String, + * String) + */ + public static RegisterImageBackedByEbsOptions addEphemeralBlockDeviceFromSnapshot( + String deviceName, @Nullable String virtualName, String snapshotId) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.addEphemeralBlockDeviceFromSnapshot(deviceName, virtualName, snapshotId); + } + + /** + * @see RegisterImageBackedByEbsOptions#addNewBlockDevice(String, String, int) + */ + public static RegisterImageBackedByEbsOptions addNewBlockDevice(String deviceName, + @Nullable String virtualName, int volumeSize) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.addNewBlockDevice(deviceName, virtualName, volumeSize); + } + + /** + * @see RegisterImageBackedByEbsOptions#addNewBlockDevice(String, String, int, boolean, String, Integer, boolean) + */ + public static RegisterImageBackedByEbsOptions addNewBlockDevice(String deviceName, + @Nullable String virtualName, + int volumeSize, + boolean deleteOnTermination, + @Nullable String volumeType, + @Nullable Integer iops, + boolean encrypted) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.addNewBlockDevice(deviceName, virtualName, volumeSize, deleteOnTermination, + volumeType, iops, encrypted); + } + + /** + * @see RegisterImageBackedByEbsOptions#addNewEphemeralBlockDevice(String, String, int) + */ + public static RegisterImageBackedByEbsOptions addNewEphemeralBlockDevice(String deviceName, + @Nullable String virtualName, int volumeSize) { + RegisterImageBackedByEbsOptions options = new RegisterImageBackedByEbsOptions(); + return options.addNewEphemeralBlockDevice(deviceName, virtualName, volumeSize); + } + } + + /** + * {@inheritDoc} + */ + @Override + public RegisterImageBackedByEbsOptions asArchitecture(Architecture architecture) { + return (RegisterImageBackedByEbsOptions) super.asArchitecture(architecture); + } + + /** + * {@inheritDoc} + */ + @Override + public RegisterImageBackedByEbsOptions withDescription(String info) { + return (RegisterImageBackedByEbsOptions) super.withDescription(info); + } + + /** + * {@inheritDoc} + */ + @Override + public RegisterImageBackedByEbsOptions withKernelId(String kernelId) { + return (RegisterImageBackedByEbsOptions) super.withKernelId(kernelId); + } + + /** + * {@inheritDoc} + */ + @Override + public RegisterImageBackedByEbsOptions withRamdisk(String ramDiskId) { + return (RegisterImageBackedByEbsOptions) super.withRamdisk(ramDiskId); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java new file mode 100644 index 0000000..178d9b2 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java @@ -0,0 +1,127 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ec2.domain.Image.Architecture; +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the RegisterImage operation. <h2> + * Usage</h2> The recommended way to instantiate a RegisterImageOptions object is to statically + * import RegisterImageOptions.Builder.* and invoke a static creation method followed by an instance + * mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.ec2.options.RegisterImageOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * String imageId = connection.getImageServices().registerImageFromManifest(...withArchitecture(Architecture.I386).withDescription("description")); + * <code> + * + * @see <a + * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-RegisterImage.html" + * /> + */ +public class RegisterImageOptions extends BaseEC2RequestOptions { + + /** + * The architecture of the image. + */ + public RegisterImageOptions asArchitecture(Architecture architecture) { + formParameters.put("Architecture", checkNotNull(architecture, "architecture").value()); + return this; + } + + String getArchitecture() { + return getFirstFormOrNull("Architecture"); + } + + /** + *The description of the AMI. "Up to 255 characters." + */ + public RegisterImageOptions withDescription(String info) { + formParameters.put("Description", checkNotNull(info, "info")); + return this; + } + + String getDescription() { + return getFirstFormOrNull("Description"); + } + + /** + * The ID of the kernel to select. + */ + public RegisterImageOptions withKernelId(String kernelId) { + formParameters.put("KernelId", checkNotNull(kernelId, "kernelId")); + return this; + } + + String getKernelId() { + return getFirstFormOrNull("KernelId"); + } + + /** + * The ID of the RAM disk to select. Some kernels require additional drivers at launch. Check the + * kernel requirements for information on whether you need to specify a RAM disk. To find kernel + * requirements, refer to the Resource Center and search for the kernel ID. + */ + public RegisterImageOptions withRamdisk(String ramDiskId) { + formParameters.put("RamdiskId", checkNotNull(ramDiskId, "ramDiskId")); + return this; + } + + String getRamdiskId() { + return getFirstFormOrNull("RamdiskId"); + } + + public static class Builder { + /** + * @see RegisterImageOptions#asArchitecture(Architecture) + */ + public static RegisterImageOptions asArchitecture(Architecture architecture) { + RegisterImageOptions options = new RegisterImageOptions(); + return options.asArchitecture(architecture); + } + + /** + * @see RegisterImageOptions#withDescription(String) + */ + public static RegisterImageOptions withDescription(String additionalInfo) { + RegisterImageOptions options = new RegisterImageOptions(); + return options.withDescription(additionalInfo); + } + + /** + * @see RegisterImageOptions#withKernelId(String) + */ + public static RegisterImageOptions withKernelId(String kernelId) { + RegisterImageOptions options = new RegisterImageOptions(); + return options.withKernelId(kernelId); + } + + /** + * @see RegisterImageOptions#withRamdisk(String) + */ + public static RegisterImageOptions withRamdisk(String ramdiskId) { + RegisterImageOptions options = new RegisterImageOptions(); + return options.withRamdisk(ramdiskId); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java new file mode 100644 index 0000000..95975da --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java @@ -0,0 +1,229 @@ +/* + * 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.ec2.options; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.io.BaseEncoding.base64; + +import java.util.Set; + +import org.jclouds.ec2.domain.BlockDeviceMapping; +import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; + +/** + * Contains options supported in the Form API for the RunInstances operation. <h2> + * Usage</h2> The recommended way to instantiate a RunInstancesOptions object is to statically + * import RunInstancesOptions.Builder.* and invoke a static creation method followed by an instance + * mutator (if needed): + * <p/> + * <code> + * import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.* + * <p/> + * EC2Api connection = // get connection + * Future<ReservationInfo> instances = connection.runInstances(executableBy("123125").imageIds(1000, 1004)); + * <code> + * + * @see <a href= + * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-RunInstances.html" + * /> + */ +public class RunInstancesOptions extends BaseEC2RequestOptions { + public static final RunInstancesOptions NONE = new RunInstancesOptions(); + + /** + * The name of the key pair. + */ + public RunInstancesOptions withKeyName(String keyName) { + formParameters.put("KeyName", checkNotNull(keyName, "keyName")); + return this; + } + + /** + * Attach multiple security groups + */ + public RunInstancesOptions withSecurityGroups(String... securityGroups) { + indexFormValuesWithPrefix("SecurityGroup", securityGroups); + return this; + } + + /** + * Attach multiple security groups + */ + public RunInstancesOptions withSecurityGroups(Iterable<String> securityGroups) { + indexFormValuesWithPrefix("SecurityGroup", securityGroups); + return this; + } + + /** + * Attaches a single security group. Multiple calls to this method won't add more groups. + * + * @param securityGroup + * name of an existing security group + */ + public RunInstancesOptions withSecurityGroup(String securityGroup) { + return withSecurityGroups(securityGroup); + } + + /** + * Unencoded data + */ + public RunInstancesOptions withUserData(byte[] unencodedData) { + int length = checkNotNull(unencodedData, "unencodedData").length; + checkArgument(length > 0, "userData cannot be empty"); + checkArgument(length <= 16 * 1024, "userData cannot be larger than 16kb"); + formParameters.put("UserData", base64().encode(unencodedData)); + return this; + } + + /** + * Specifies the instance type. default small; + */ + public RunInstancesOptions asType(String type) { + formParameters.put("InstanceType", checkNotNull(type, "type")); + return this; + } + + /** + * The ID of the kernel with which to launch the instance. + */ + public RunInstancesOptions withKernelId(String kernelId) { + formParameters.put("KernelId", checkNotNull(kernelId, "kernelId")); + return this; + } + + /** + * The ID of the RAM disk with which to launch the instance. Some kernels require additional + * drivers at launch. Check the kernel requirements for information on whether you need to + * specify a RAM disk. To find kernel requirements, go to the Resource Center and search for the + * kernel ID. + */ + public RunInstancesOptions withRamdisk(String ramDiskId) { + formParameters.put("RamdiskId", checkNotNull(ramDiskId, "ramDiskId")); + return this; + } + + /** + * Specifies the Block Device Mapping for the instance + * + */ + public RunInstancesOptions withBlockDeviceMappings(Set<? extends BlockDeviceMapping> mappings) { + int i = 1; + for (BlockDeviceMapping mapping : checkNotNull(mappings, "mappings")) { + checkNotNull(mapping.getDeviceName(), "deviceName"); + formParameters.put(String.format("BlockDeviceMapping.%d.DeviceName", i), mapping.getDeviceName()); + if (mapping.getVirtualName() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.VirtualName", i), mapping.getVirtualName()); + if (mapping.getEbsSnapshotId() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.SnapshotId", i), mapping.getEbsSnapshotId()); + if (mapping.getEbsVolumeSize() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.VolumeSize", i), + String.valueOf(mapping.getEbsVolumeSize())); + if (mapping.getEbsNoDevice() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.NoDevice", i), + String.valueOf(mapping.getEbsNoDevice())); + if (mapping.getEbsDeleteOnTermination() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.DeleteOnTermination", i), + String.valueOf(mapping.getEbsDeleteOnTermination())); + if (mapping.getEbsVolumeType() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.VolumeType", i), mapping.getEbsVolumeType()); + if (mapping.getEbsIops() != null) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.Iops", i), + String.valueOf(mapping.getEbsIops())); + if (mapping.getEbsEncrypted() != null && mapping.getEbsEncrypted()) + formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.Encrypted", i), String.valueOf(mapping.getEbsEncrypted())); + i++; + } + return this; + } + + /** + * Specifies the optional ClientToken field, which triggers idempotent RunInstances calls. + * See <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Run_Instance_Idempotency.html">here</a> for more details. + */ + public RunInstancesOptions withClientToken(String clientToken) { + formParameters.put("ClientToken", checkNotNull(clientToken, "clientToken")); + return this; + } + + public static class Builder { + /** + * @see RunInstancesOptions#withKeyName(String) + */ + public static RunInstancesOptions withKeyName(String keyName) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withKeyName(keyName); + } + + /** + * @see RunInstancesOptions#withSecurityGroup(String) + */ + public static RunInstancesOptions withSecurityGroup(String securityGroup) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withSecurityGroup(securityGroup); + } + + /** + * @see RunInstancesOptions#withUserData(byte []) + */ + public static RunInstancesOptions withUserData(byte[] unencodedData) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withUserData(unencodedData); + } + + /** + * @see RunInstancesOptions#asType(String) + */ + public static RunInstancesOptions asType(String instanceType) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.asType(instanceType); + } + + /** + * @see RunInstancesOptions#withKernelId(String) + */ + public static RunInstancesOptions withKernelId(String kernelId) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withKernelId(kernelId); + } + + /** + * @see RunInstancesOptions#withRamdisk(String) + */ + public static RunInstancesOptions withRamdisk(String ramdiskId) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withRamdisk(ramdiskId); + } + + /** + * @see RunInstancesOptions#withBlockDeviceMappings(Set<BlockDeviceMapping> mappings) + */ + public static RunInstancesOptions withBlockDeviceMappings(Set<? extends BlockDeviceMapping> mappings) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withBlockDeviceMappings(mappings); + } + + /** + * @see RunInstancesOptions#withClientToken(String) + */ + public static RunInstancesOptions withClientToken(String clientToken) { + RunInstancesOptions options = new RunInstancesOptions(); + return options.withClientToken(clientToken); + } + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java new file mode 100644 index 0000000..9173171 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java @@ -0,0 +1,55 @@ +/* + * 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.ec2.options.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import org.jclouds.http.options.BaseHttpRequestOptions; +import org.jclouds.util.Predicates2; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.Iterables; + +public class BaseEC2RequestOptions extends BaseHttpRequestOptions { + + @Override + public String toString() { + return "[formParameters=" + formParameters + "]"; + } + + protected void indexFormValuesWithPrefix(String prefix, String... values) { + for (int i = 0; i < values.length; i++) { + formParameters.put(prefix + "." + (i + 1), checkNotNull(values[i], prefix.toLowerCase() + "s[" + i + "]")); + } + } + + protected void indexFormValuesWithPrefix(String prefix, Iterable<String> values) { + indexFormValuesWithPrefix(prefix, Iterables.toArray(values, String.class)); + } + + protected Set<String> getFormValuesWithKeysPrefixedBy(final String prefix) { + Builder<String> values = ImmutableSet.builder(); + for (String key : Iterables.filter(formParameters.keySet(), Predicates2.startsWith(prefix))) { + values.add(Iterables.get(formParameters.get(key), 0)); + } + return values.build(); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java new file mode 100644 index 0000000..2f0b47a --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java @@ -0,0 +1,64 @@ +/* + * 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.ec2.predicates; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.aws.AWSResponseException; +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +/** + * + * Tests to see if a task succeeds. + */ +@Singleton +public class InstanceHasIpAddress implements Predicate<RunningInstance> { + + private final EC2Api client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public InstanceHasIpAddress(EC2Api client) { + this.client = client; + } + + public boolean apply(RunningInstance instance) { + logger.trace("looking for ipAddress on instance %s", instance); + try { + instance = refresh(instance); + return instance.getIpAddress() != null; + } catch (AWSResponseException e) { + if (e.getError().getCode().equals("InvalidInstanceID.NotFound")) + return false; + throw e; + } + } + + private RunningInstance refresh(RunningInstance instance) { + return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceApi().get() + .describeInstancesInRegion(instance.getRegion(), instance.getId()))); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java new file mode 100644 index 0000000..28fe078 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java @@ -0,0 +1,67 @@ +/* + * 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.ec2.predicates; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.domain.InstanceState; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.logging.Logger; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +/** + * + * Tests to see if a task succeeds. + */ +@Singleton +public class InstanceStateRunning implements Predicate<RunningInstance> { + + private final EC2Api client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public InstanceStateRunning(EC2Api client) { + this.client = client; + } + + public boolean apply(RunningInstance instance) { + logger.trace("looking for state on instance %s", instance); + try { + instance = refresh(instance); + logger.trace("%s: looking for instance state %s: currently: %s", + instance.getId(), InstanceState.RUNNING, instance + .getInstanceState()); + return instance.getInstanceState() == InstanceState.RUNNING; + } catch (ResourceNotFoundException e) { + return false; + } + } + + private RunningInstance refresh(RunningInstance instance) { + return Iterables.getOnlyElement(Iterables.getOnlyElement(client + .getInstanceApi().get().describeInstancesInRegion( + instance.getRegion(), instance.getId()))); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java new file mode 100644 index 0000000..1d8be7b --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java @@ -0,0 +1,60 @@ +/* + * 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.ec2.predicates; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.ec2.domain.InstanceState; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.ec2.features.InstanceApi; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +/** + * + * Tests to see if a task succeeds. + */ +@Singleton +public class InstanceStateStopped implements Predicate<RunningInstance> { + + private final InstanceApi client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public InstanceStateStopped(InstanceApi client) { + this.client = client; + } + + public boolean apply(RunningInstance instance) { + logger.trace("looking for state on instance %s", instance); + instance = refresh(instance); + logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(), + InstanceState.STOPPED, instance.getInstanceState()); + return instance.getInstanceState() == InstanceState.STOPPED; + } + + private RunningInstance refresh(RunningInstance instance) { + return Iterables.getOnlyElement(Iterables.getOnlyElement(client.describeInstancesInRegion( + instance.getRegion(), instance.getId()))); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java new file mode 100644 index 0000000..102b3e8 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.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.ec2.predicates; + +import java.util.NoSuchElementException; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.domain.InstanceState; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +/** + * + * Tests to see if a task succeeds. + */ +@Singleton +public class InstanceStateTerminated implements Predicate<RunningInstance> { + + private final EC2Api client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public InstanceStateTerminated(EC2Api client) { + this.client = client; + } + + public boolean apply(RunningInstance instance) { + logger.trace("looking for state on instance %s", instance); + try { + instance = refresh(instance); + } catch (NoSuchElementException e) { + return true; + } + logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(), + InstanceState.TERMINATED, instance.getInstanceState()); + return instance.getInstanceState() == InstanceState.TERMINATED; + } + + private RunningInstance refresh(RunningInstance instance) { + return Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceApi().get() + .describeInstancesInRegion(instance.getRegion(), instance.getId()))); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java new file mode 100644 index 0000000..9ec5a03 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java @@ -0,0 +1,58 @@ +/* + * 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.ec2.predicates; + +import static org.jclouds.ec2.options.DescribeSnapshotsOptions.Builder.snapshotIds; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.ec2.domain.Snapshot; +import org.jclouds.ec2.features.ElasticBlockStoreApi; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +/** + * + * Tests to see if a snapshot is completed. + */ +@Singleton +public class SnapshotCompleted implements Predicate<Snapshot> { + + private final ElasticBlockStoreApi client; + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public SnapshotCompleted(ElasticBlockStoreApi client) { + this.client = client; + } + + public boolean apply(Snapshot snapshot) { + logger.trace("looking for status on snapshot %s", snapshot.getId()); + + snapshot = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), + snapshotIds(snapshot.getId()))); + logger.trace("%s: looking for status %s: currently: %s; progress %d/100", snapshot, + Snapshot.Status.COMPLETED, snapshot.getStatus(), snapshot.getProgress()); + return snapshot.getStatus() == Snapshot.Status.COMPLETED; + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java new file mode 100644 index 0000000..8eb4303 --- /dev/null +++ b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.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.ec2.predicates; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.ec2.domain.Attachment; +import org.jclouds.ec2.domain.Volume; +import org.jclouds.ec2.features.ElasticBlockStoreApi; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import com.google.inject.Inject; + +/** + * + * Tests to see if a volume is attached. + */ +@Singleton +public class VolumeAttached implements Predicate<Attachment> { + + private final ElasticBlockStoreApi client; + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public VolumeAttached(ElasticBlockStoreApi client) { + this.client = client; + } + + public boolean apply(Attachment attachment) { + logger.trace("looking for volume %s", attachment.getVolumeId()); + Volume volume = Iterables.getOnlyElement(client.describeVolumesInRegion(attachment + .getRegion(), attachment.getVolumeId())); + if (volume.getAttachments().size() == 0) { + return false; + } + Attachment lastAttachment = Sets.newTreeSet(volume.getAttachments()).last(); + logger.trace("%s: looking for status %s: currently: %s", lastAttachment, + Attachment.Status.ATTACHED, lastAttachment.getStatus()); + return lastAttachment.getStatus() == Attachment.Status.ATTACHED; + } + +}
