http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java deleted file mode 100644 index 76c2a01..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RegisterImageOptions.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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> - * - * @author Adrian Cole - * @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.7.1-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java deleted file mode 100644 index 7ccb209..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/RunInstancesOptions.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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> - * - * @author Adrian Cole - * @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())); - i++; - } - 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(InstanceType) - */ - 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); - } - - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java deleted file mode 100644 index 3ec5e8d..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/options/internal/BaseEC2RequestOptions.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - -/** - * - * @author Adrian Cole - */ -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.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java deleted file mode 100644 index 57d576d..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceHasIpAddress.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - * - * @author Adrian Cole - */ -@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.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java deleted file mode 100644 index 893e689..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateRunning.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - * - * @author Adrian Cole - */ -@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.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java deleted file mode 100644 index 644d858..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateStopped.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - * - * @author Adrian Cole - */ -@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.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java deleted file mode 100644 index 8c9a3fd..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/InstanceStateTerminated.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - * - * @author Adrian Cole - */ -@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.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java deleted file mode 100644 index ef5281a..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/SnapshotCompleted.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - * - * @author Adrian Cole - */ -@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.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java deleted file mode 100644 index f3ebfaf..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAttached.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - * - * @author Adrian Cole - */ -@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; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAvailable.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAvailable.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAvailable.java deleted file mode 100644 index 9688add..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeAvailable.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.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.inject.Inject; - -/** - * - * Tests to see if a volume is completed. - * - * @author Adrian Cole - */ -@Singleton -public class VolumeAvailable implements Predicate<Volume> { - - private final ElasticBlockStoreApi client; - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public VolumeAvailable(ElasticBlockStoreApi client) { - this.client = client; - } - - public boolean apply(Volume volume) { - logger.trace("looking for status on volume %s", volume.getId()); - volume = Iterables.getOnlyElement(client.describeVolumesInRegion(volume.getRegion(), volume - .getId())); - logger.trace("%s: looking for status %s: currently: %s", volume, Volume.Status.AVAILABLE, - volume.getStatus()); - return volume.getStatus() == Volume.Status.AVAILABLE; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeDetached.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeDetached.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeDetached.java deleted file mode 100644 index accabe8..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/predicates/VolumeDetached.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 com.google.common.collect.Iterables.getLast; - -import javax.annotation.Resource; - -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.inject.Inject; -import com.google.inject.Singleton; - -/** - * Tests to see if a volume is detached. - * - * @author Karthik Arunachalam - */ -@Singleton -public class VolumeDetached implements Predicate<Attachment> { - - private final ElasticBlockStoreApi client; - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public VolumeDetached(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 attachment size is 0 volume is detached for sure.*/ - if (volume.getAttachments().size() == 0) { - return true; - } - - /* But if attachment size is > 0, then the attachment could be in any state. - * So we need to check if the status is DETACHED (return true) or not (return false). - */ - Attachment lastAttachment = getLast(volume.getAttachments()); - logger.trace("%s: looking for status %s: currently: %s", lastAttachment, - Attachment.Status.DETACHED, lastAttachment.getStatus()); - return lastAttachment.getStatus() == Attachment.Status.DETACHED; - } -} - http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/reference/EC2Constants.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/reference/EC2Constants.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/reference/EC2Constants.java deleted file mode 100644 index 0d45789..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/reference/EC2Constants.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.reference; - - -/** - * Configuration properties and constants used in EC2 connections. - * - * @author Adrian Cole - */ -public interface EC2Constants { - /** - * Listing the universe of amis is extremely expensive. set this to a comma separated value of - * the ami owners you wish to use in {@link ComputeService} - */ - public static final String PROPERTY_EC2_AMI_OWNERS = "jclouds.ec2.ami-owners"; - - /** - * Eventual consistency delay for retrieving a security group after it is created (in ms) - */ - public static final String PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT = "jclouds.ec2.timeout.securitygroup-present"; - - /** - * Whenever a node is created, automatically allocate and assign an elastic ip address, also - * deallocate when the node is destroyed. - */ - public static final String PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS = "jclouds.ec2.auto-allocate-elastic-ips"; - - /** - * If this property is set to true(default), jclouds generate a name for each instance based on the group. ex. - * i-ef34ae2 becomes hadoop-ef34ae2. Note that this depends on {@link EC2Api#getTagApi} returning present. - */ - public static final String PROPERTY_EC2_GENERATE_INSTANCE_NAMES = "jclouds.ec2.generate-instance-names"; - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegion.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegion.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegion.java deleted file mode 100644 index f97e962..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegion.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.suppliers; - -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.ec2.EC2Api; -import org.jclouds.ec2.domain.AvailabilityZoneInfo; -import org.jclouds.ec2.features.AvailabilityZoneAndRegionApi; -import org.jclouds.http.HttpResponseException; -import org.jclouds.location.Region; -import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier; -import org.jclouds.logging.Logger; -import org.jclouds.util.Suppliers2; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; - -@Singleton -public class DescribeAvailabilityZonesInRegion implements RegionIdToZoneIdsSupplier { - @Resource - protected Logger logger = Logger.NULL; - - private final AvailabilityZoneAndRegionApi client; - private final Supplier<Set<String>> regions; - - @Inject - public DescribeAvailabilityZonesInRegion(EC2Api client, @Region Supplier<Set<String>> regions) { - this.client = client.getAvailabilityZoneAndRegionApi().get(); - this.regions = regions; - } - - @Override - public Map<String, Supplier<Set<String>>> get() { - Builder<String, Set<String>> map = ImmutableMap.builder(); - HttpResponseException exception = null; - // TODO: this should be parallel - for (String region : regions.get()) { - try { - ImmutableSet<String> zones = ImmutableSet.copyOf(Iterables.transform(client - .describeAvailabilityZonesInRegion(region), new Function<AvailabilityZoneInfo, String>() { - - @Override - public String apply(AvailabilityZoneInfo arg0) { - return arg0.getZone(); - } - - })); - if (zones.size() > 0) - map.put(region, zones); - } catch (HttpResponseException e) { - // TODO: this should be in retry handler, not here. - if (e.getMessage().contains("Unable to tunnel through proxy")) { - exception = e; - logger.error(e, "Could not describe availability zones in Region: %s", region); - } else { - throw e; - } - } - } - ImmutableMap<String, Set<String>> result = map.build(); - if (result.isEmpty() && exception != null) { - throw exception; - } - return Maps.transformValues(result, Suppliers2.<Set<String>> ofInstanceFunction()); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeRegionsForRegionURIs.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeRegionsForRegionURIs.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeRegionsForRegionURIs.java deleted file mode 100644 index d8d7a51..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/suppliers/DescribeRegionsForRegionURIs.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.suppliers; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.ec2.EC2Api; -import org.jclouds.ec2.features.AvailabilityZoneAndRegionApi; -import org.jclouds.location.Region; -import org.jclouds.location.suppliers.RegionIdToURISupplier; -import org.jclouds.util.Suppliers2; - -import com.google.common.base.Supplier; -import com.google.common.collect.Maps; - -@Singleton -public class DescribeRegionsForRegionURIs implements RegionIdToURISupplier { - private final AvailabilityZoneAndRegionApi client; - - @Inject - public DescribeRegionsForRegionURIs(EC2Api client) { - this.client = client.getAvailabilityZoneAndRegionApi().get(); - } - - @Singleton - @Region - @Override - public Map<String, Supplier<URI>> get() { - Map<String, URI> regionToUris = client.describeRegions(); - return Maps.transformValues(regionToUris, Suppliers2.<URI> ofInstanceFunction()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/IpPermissions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/IpPermissions.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/IpPermissions.java deleted file mode 100644 index cc2b68a..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/IpPermissions.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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.util; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.net.domain.IpPermission; -import org.jclouds.net.domain.IpProtocol; -import org.jclouds.util.Maps2; - -import com.google.common.annotations.Beta; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; - -/** - * - * Shortcut to create ingress rules - * - * @author Adrian Cole - */ -public class IpPermissions extends IpPermission { - - protected IpPermissions(IpProtocol ipProtocol, int fromPort, int toPort, - Multimap<String, String> userIdGroupPairs, Iterable<String> groupIds, Iterable<String> ipRanges) { - super(ipProtocol, fromPort, toPort, userIdGroupPairs, groupIds, userIdGroupPairs.size() == 0 ? ipRanges - : ImmutableSet.<String> of()); - } - - /** - * don't rely on this being here.. it will move - */ - @Beta - public static Multimap<String, String> buildFormParametersForIndex(final int index, IpPermission permission) { - Map<String, String> headers = Maps.newLinkedHashMap(); - headers.put("IpPermissions.%d.IpProtocol", permission.getIpProtocol().toString()); - headers.put("IpPermissions.%d.FromPort", permission.getFromPort() + ""); - headers.put("IpPermissions.%d.ToPort", permission.getToPort() + ""); - String prefix = "IpPermissions.%d.IpRanges."; - int i = 0; - for (String cidrIp : checkNotNull(permission.getCidrBlocks(), "cidrIps")) { - headers.put(prefix + i++ + ".CidrIp", cidrIp); - } - prefix = "IpPermissions.%d.Groups."; - i = 0; - for (String groupId : checkNotNull(permission.getGroupIds(), "groupIds")) { - headers.put(prefix + i++ + ".GroupId", groupId); - } - prefix = "IpPermissions.%d.Groups."; - i = 0; - for (Entry<String, String> tenantIdGroupNamePair : checkNotNull(permission.getTenantIdGroupNamePairs(), - "tenantIdGroupNamePairs").entries()) { - headers.put(prefix + i + ".UserId", tenantIdGroupNamePair.getKey()); - headers.put(prefix + i + ".GroupId", tenantIdGroupNamePair.getValue()); - i++; - } - prefix = "IpPermissions.%d.IpRanges."; - i = 0; - for (String cidrIp : checkNotNull(permission.getCidrBlocks(), "cidrIps")) { - headers.put(prefix + i++ + ".CidrIp", cidrIp); - } - return Multimaps.forMap(Maps2.transformKeys(headers, new Function<String, String>() { - - @Override - public String apply(String arg0) { - return String.format(arg0, index); - } - - })); - } - - public static ICMPTypeSelection permitICMP() { - return new ICMPTypeSelection(); - } - - public static ToSourceSelection permitAnyProtocol() { - return new ToSourceSelection(IpProtocol.ALL, 1, 65535); - } - - public static PortSelection permit(IpProtocol protocol) { - return new PortSelection(checkNotNull(protocol, "protocol")); - } - - public static class ICMPTypeSelection extends ToSourceSelection { - - ICMPTypeSelection() { - super(IpProtocol.ICMP, -1, -1); - } - - /** - * @param type ex. 8 for ECHO (i.e. Ping) - * @see <a href="http://www.iana.org/assignments/icmp-parameters/icmp-parameters.xml"> ICMP Types</a> - */ - public AndCodeSelection type(int type) { - return new AndCodeSelection(type); - } - } - - public static class AndCodeSelection extends ToSourceSelection { - AndCodeSelection(int type) { - super(IpProtocol.ICMP, type, -1); - } - - public ToSourceSelection andCode(int code) { - return new ToSourceSelection(getIpProtocol(), getFromPort(), code); - } - - } - - public static class PortSelection extends ToSourceSelection { - - PortSelection(IpProtocol ipProtocol) { - super(ipProtocol, ipProtocol == IpProtocol.ICMP ? -1 : 1, ipProtocol == IpProtocol.ICMP ? -1 : 65535); - } - - public ToPortSelection fromPort(int port) { - return new ToPortSelection(getIpProtocol(), port); - } - - public ToSourceSelection port(int port) { - return new ToSourceSelection(getIpProtocol(), port, port); - } - } - - public static class ToPortSelection extends ToSourceSelection { - - ToPortSelection(IpProtocol ipProtocol, int fromPort) { - super(ipProtocol, fromPort, ipProtocol == IpProtocol.ICMP ? -1 : 65535); - } - - public ToSourceSelection to(int port) { - return new ToSourceSelection(getIpProtocol(), getFromPort(), port); - } - } - - public static class ToVPCSourceSelection extends IpPermissions { - - protected ToVPCSourceSelection(IpProtocol ipProtocol, int fromPort, int toPort) { - super(ipProtocol, fromPort, toPort, ImmutableMultimap.<String, String> of(), ImmutableSet.<String> of(), - ImmutableSet.of("0.0.0.0/0")); - } - - public IpPermissions originatingFromSecurityGroupId(String groupId) { - return toVPCSecurityGroups(ImmutableSet.of(checkNotNull(groupId, "groupId"))); - } - - public IpPermissions toVPCSecurityGroups(Iterable<String> groupIds) { - return new IpPermissions(getIpProtocol(), getFromPort(), getToPort(), getTenantIdGroupNamePairs(), groupIds, - ImmutableSet.<String> of()); - } - } - - public static class ToSourceSelection extends ToVPCSourceSelection { - ToSourceSelection(IpProtocol ipProtocol, int fromPort, int toPort) { - super(ipProtocol, fromPort, toPort); - } - - public IpPermissions originatingFromCidrBlock(String cidrIp) { - return originatingFromCidrBlocks(ImmutableSet.of(checkNotNull(cidrIp, "cidrIp"))); - } - - public IpPermissions originatingFromCidrBlocks(Iterable<String> cidrIps) { - return new IpPermissions(getIpProtocol(), getFromPort(), getToPort(), - ImmutableMultimap.<String, String> of(), ImmutableSet.<String> of(), cidrIps); - } - - public IpPermissions originatingFromUserAndSecurityGroup(String userId, String groupName) { - return toEC2SecurityGroups(ImmutableMultimap.of(checkNotNull(userId, "userId"), - checkNotNull(groupName, "groupName"))); - } - - public IpPermissions toEC2SecurityGroups(Multimap<String, String> tenantIdGroupNamePairs) { - return new IpPermissions(getIpProtocol(), getFromPort(), getToPort(), tenantIdGroupNamePairs, getGroupIds(), - ImmutableSet.<String> of()); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/SubnetFilterBuilder.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/SubnetFilterBuilder.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/SubnetFilterBuilder.java deleted file mode 100644 index 6944bb3..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/SubnetFilterBuilder.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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.util; - -import java.util.Comparator; -import java.util.Map.Entry; - -import org.jclouds.ec2.domain.Subnet; - -import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; - -/** - * You can specify filters so that the response includes information for only - * certain subnets. For example, you can use a filter to specify that you're - * interested in the subnets in the available state. You can specify multiple - * values for a filter. The response includes information for a subnet only if - * it matches at least one of the filter values that you specified. - * - * You can specify multiple filters; for example, specify subnets that are in a - * specific VPC and are in the available state. The response includes - * information for a subnet only if it matches all the filters that you - * specified. If there's no match, no special message is returned, the response - * is simply empty. - * - * <h4>Wildcards</h4> You can use wildcards with the filter values: {@code *} - * matches zero or more characters, and ? matches exactly one character. You can - * escape special characters using a backslash before the character. For - * example, a value of {@code \*amazon\?\\} searches for the literal string - * {@code *amazon?\}. - * - * @author Adrian Cole - * @author Andrew Bayer - * @see SubnetApi - */ -public class SubnetFilterBuilder extends ImmutableMultimap.Builder<String, String> { - - private static final String AVAILABILITY_ZONE = "availability-zone"; - private static final String AVAILABLE_IP_ADDRESS_COUNT = "available-ip-address-count"; - private static final String CIDR = "cidr"; - private static final String STATE = "state"; - private static final String SUBNET_ID = "subnet-id"; - private static final String TAG_KEY = "tag-key"; - private static final String TAG_VALUE = "tag-value"; - private static final String TAG_ARBITRARY_BASE = "tag:"; - private static final String VPC_ID = "vpc-id"; - - public SubnetFilterBuilder availabilityZone(String availabilityZone) { - return put(AVAILABILITY_ZONE, availabilityZone); - } - - public SubnetFilterBuilder availabilityZones(String... availabilityZones) { - return putAll(AVAILABILITY_ZONE, availabilityZones); - } - - public SubnetFilterBuilder availabilityZones(Iterable<String> availabilityZones) { - return putAll(AVAILABILITY_ZONE, availabilityZones); - } - - public SubnetFilterBuilder anyAvailabilityZone() { - return putAll(AVAILABILITY_ZONE, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder availableIpAddressCount(String availableIpAddressCount) { - return put(AVAILABLE_IP_ADDRESS_COUNT, availableIpAddressCount); - } - - public SubnetFilterBuilder availableIpAddressCounts(String... availableIpAddressCounts) { - return putAll(AVAILABLE_IP_ADDRESS_COUNT, availableIpAddressCounts); - } - - public SubnetFilterBuilder availableIpAddressCounts(Iterable<String> availableIpAddressCounts) { - return putAll(AVAILABLE_IP_ADDRESS_COUNT, availableIpAddressCounts); - } - - public SubnetFilterBuilder anyAvailableIpAddressCount() { - return putAll(AVAILABLE_IP_ADDRESS_COUNT, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder cidr(String cidr) { - return put(CIDR, cidr); - } - - public SubnetFilterBuilder cidrs(String... cidrs) { - return putAll(CIDR, cidrs); - } - - public SubnetFilterBuilder cidrs(Iterable<String> cidrs) { - return putAll(CIDR, cidrs); - } - - public SubnetFilterBuilder anyCidr() { - return putAll(CIDR, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder state(String state) { - return put(STATE, state); - } - - public SubnetFilterBuilder states(String... states) { - return putAll(STATE, states); - } - - public SubnetFilterBuilder states(Iterable<String> states) { - return putAll(STATE, states); - } - - public SubnetFilterBuilder anyState() { - return putAll(STATE, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder available() { - return put(STATE, Subnet.State.AVAILABLE.value()); - } - - public SubnetFilterBuilder pending() { - return put(STATE, Subnet.State.PENDING.value()); - } - - public SubnetFilterBuilder subnetId(String subnetId) { - return put(SUBNET_ID, subnetId); - } - - public SubnetFilterBuilder subnetIds(String... subnetIds) { - return putAll(SUBNET_ID, subnetIds); - } - - public SubnetFilterBuilder subnetIds(Iterable<String> subnetIds) { - return putAll(SUBNET_ID, subnetIds); - } - - public SubnetFilterBuilder anySubnetId() { - return putAll(SUBNET_ID, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder tagKey(String tagKey) { - return put(TAG_KEY, tagKey); - } - - public SubnetFilterBuilder tagKeys(String... tagKeys) { - return putAll(TAG_KEY, tagKeys); - } - - public SubnetFilterBuilder tagKeys(Iterable<String> tagKeys) { - return putAll(TAG_KEY, tagKeys); - } - - public SubnetFilterBuilder anyTagKey() { - return putAll(TAG_KEY, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder tagValue(String tagValue) { - return put(TAG_VALUE, tagValue); - } - - public SubnetFilterBuilder tagValues(String... tagValues) { - return putAll(TAG_VALUE, tagValues); - } - - public SubnetFilterBuilder tagValues(Iterable<String> tagValues) { - return putAll(TAG_VALUE, tagValues); - } - - public SubnetFilterBuilder anyTagValue() { - return putAll(TAG_VALUE, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder vpcId(String vpcId) { - return put(VPC_ID, vpcId); - } - - public SubnetFilterBuilder vpcIds(String... vpcIds) { - return putAll(VPC_ID, vpcIds); - } - - public SubnetFilterBuilder vpcIds(Iterable<String> vpcIds) { - return putAll(VPC_ID, vpcIds); - } - - public SubnetFilterBuilder anyVpcId() { - return putAll(VPC_ID, ImmutableSet.<String> of()); - } - - public SubnetFilterBuilder arbitraryTag(String arbitraryTagKey, String arbitraryTagValue) { - return put(TAG_ARBITRARY_BASE + arbitraryTagKey, arbitraryTagValue); - } - - public SubnetFilterBuilder arbitraryTag(String arbitraryTagKey, String... arbitraryTagValues) { - return putAll(TAG_ARBITRARY_BASE + arbitraryTagKey, arbitraryTagValues); - } - - public SubnetFilterBuilder arbitraryTag(String arbitraryTagKey, Iterable<String> arbitraryTagValues) { - return putAll(TAG_ARBITRARY_BASE + arbitraryTagKey, arbitraryTagValues); - } - - - // to set correct return val in chain - - @Override - public SubnetFilterBuilder put(String key, String value) { - return SubnetFilterBuilder.class.cast(super.put(key, value)); - } - - @Override - public SubnetFilterBuilder put(Entry<? extends String, ? extends String> entry) { - return SubnetFilterBuilder.class.cast(super.put(entry)); - } - - @Override - public SubnetFilterBuilder putAll(String key, Iterable<? extends String> values) { - return SubnetFilterBuilder.class.cast(super.putAll(key, values)); - } - - @Override - public SubnetFilterBuilder putAll(String key, String... values) { - return SubnetFilterBuilder.class.cast(super.putAll(key, values)); - } - - @Override - public SubnetFilterBuilder putAll(Multimap<? extends String, ? extends String> multimap) { - return SubnetFilterBuilder.class.cast(super.putAll(multimap)); - } - - @Override - @Beta - public SubnetFilterBuilder orderKeysBy(Comparator<? super String> keyComparator) { - return SubnetFilterBuilder.class.cast(super.orderKeysBy(keyComparator)); - } - - @Override - @Beta - public SubnetFilterBuilder orderValuesBy(Comparator<? super String> valueComparator) { - return SubnetFilterBuilder.class.cast(super.orderValuesBy(valueComparator)); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/TagFilterBuilder.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/TagFilterBuilder.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/TagFilterBuilder.java deleted file mode 100644 index c2ccedd..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/TagFilterBuilder.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * 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.util; - -import java.util.Comparator; -import java.util.Map.Entry; - -import org.jclouds.ec2.domain.Tag; - -import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; - -/** - * You can use filters to limit the results when describing tags. For example, - * you could get only the tags for a particular resource type. You can specify - * multiple values for a filter. A tag must match at least one of the specified - * values for it to be included in the results. - * - * You can specify multiple filters (for example, limit the results to a - * specific resource type, and get only tags with values that contain the string - * database). The result includes information for a particular tag only if it - * matches all your filters. If there's no match, no special message is - * returned; the response is simply empty. - * - * <h4>Wildcards</h4> You can use wildcards with the filter values: {@code *} - * matches zero or more characters, and ? matches exactly one character. You can - * escape special characters using a backslash before the character. For - * example, a value of {@code \*amazon\?\\} searches for the literal string - * {@code *amazon?\}. - * - * @author Adrian Cole - * @see TagApi - */ -public class TagFilterBuilder extends ImmutableMultimap.Builder<String, String> { - - private static final String KEY = "key"; - private static final String VALUE = "value"; - private static final String RESOURCE_ID = "resource-id"; - private static final String RESOURCE_TYPE = "resource-type"; - - public TagFilterBuilder key(String key) { - return put(KEY, key); - } - - public TagFilterBuilder keys(String... keys) { - return putAll(KEY, keys); - } - - public TagFilterBuilder keys(Iterable<String> keys) { - return putAll(KEY, keys); - } - - public TagFilterBuilder anyKey() { - return putAll(KEY, ImmutableSet.<String> of()); - } - - public TagFilterBuilder value(String value) { - return put(VALUE, value); - } - - public TagFilterBuilder values(String... values) { - return putAll(VALUE, ImmutableSet.<String> copyOf(values)); - } - - public TagFilterBuilder values(Iterable<String> values) { - return putAll(VALUE, ImmutableSet.<String> copyOf(values)); - } - - public TagFilterBuilder anyValue() { - return putAll(VALUE, ImmutableSet.<String> of()); - } - - public TagFilterBuilder resourceId(String resourceId) { - return put(RESOURCE_ID, resourceId); - } - - public TagFilterBuilder resourceIds(String... resourceIds) { - return putAll(RESOURCE_ID, resourceIds); - } - - public TagFilterBuilder resourceIds(Iterable<String> resourceIds) { - return putAll(RESOURCE_ID, resourceIds); - } - - public TagFilterBuilder anyResourceId() { - return putAll(RESOURCE_ID, ImmutableSet.<String> of()); - } - - public TagFilterBuilder resourceType(String resourceType) { - return put(RESOURCE_TYPE, resourceType); - } - - public TagFilterBuilder resourceTypes(String... resourceTypes) { - return putAll(RESOURCE_TYPE, resourceTypes); - } - - public TagFilterBuilder resourceTypes(Iterable<String> resourceTypes) { - return putAll(RESOURCE_TYPE, resourceTypes); - } - - public TagFilterBuilder anyResourceType() { - return putAll(RESOURCE_TYPE, ImmutableSet.<String> of()); - } - - public TagFilterBuilder customerGateway() { - return put(RESOURCE_TYPE, Tag.ResourceType.CUSTOMER_GATEWAY); - } - - public TagFilterBuilder dhcpOptions() { - return put(RESOURCE_TYPE, Tag.ResourceType.DHCP_OPTIONS); - } - - public TagFilterBuilder image() { - return put(RESOURCE_TYPE, Tag.ResourceType.IMAGE); - } - - public TagFilterBuilder instance() { - return put(RESOURCE_TYPE, Tag.ResourceType.INSTANCE); - } - - public TagFilterBuilder internetGateway() { - return put(RESOURCE_TYPE, Tag.ResourceType.INTERNET_GATEWAY); - } - - public TagFilterBuilder networkAcl() { - return put(RESOURCE_TYPE, Tag.ResourceType.NETWORK_ACL); - } - - public TagFilterBuilder reservedInstance() { - return put(RESOURCE_TYPE, Tag.ResourceType.RESERVED_INSTANCES); - } - - public TagFilterBuilder routeTable() { - return put(RESOURCE_TYPE, Tag.ResourceType.ROUTE_TABLE); - } - - public TagFilterBuilder securityGroup() { - return put(RESOURCE_TYPE, Tag.ResourceType.SECURITY_GROUP); - } - - public TagFilterBuilder snapshot() { - return put(RESOURCE_TYPE, Tag.ResourceType.SNAPSHOT); - } - - public TagFilterBuilder instancesRequest() { - return put(RESOURCE_TYPE, Tag.ResourceType.SPOT_INSTANCES_REQUEST); - } - - public TagFilterBuilder subnet() { - return put(RESOURCE_TYPE, Tag.ResourceType.SUBNET); - } - - public TagFilterBuilder volume() { - return put(RESOURCE_TYPE, Tag.ResourceType.VOLUME); - } - - public TagFilterBuilder vpc() { - return put(RESOURCE_TYPE, Tag.ResourceType.VPC); - } - - public TagFilterBuilder vpnConnection() { - return put(RESOURCE_TYPE, Tag.ResourceType.VPN_CONNECTION); - } - - public TagFilterBuilder vpnGateway() { - return put(RESOURCE_TYPE, Tag.ResourceType.VPN_GATEWAY); - } - - // to set correct return val in chain - - @Override - public TagFilterBuilder put(String key, String value) { - return TagFilterBuilder.class.cast(super.put(key, value)); - } - - @Override - public TagFilterBuilder put(Entry<? extends String, ? extends String> entry) { - return TagFilterBuilder.class.cast(super.put(entry)); - } - - @Override - public TagFilterBuilder putAll(String key, Iterable<? extends String> values) { - return TagFilterBuilder.class.cast(super.putAll(key, values)); - } - - @Override - public TagFilterBuilder putAll(String key, String... values) { - return TagFilterBuilder.class.cast(super.putAll(key, values)); - } - - @Override - public TagFilterBuilder putAll(Multimap<? extends String, ? extends String> multimap) { - return TagFilterBuilder.class.cast(super.putAll(multimap)); - } - - @Override - @Beta - public TagFilterBuilder orderKeysBy(Comparator<? super String> keyComparator) { - return TagFilterBuilder.class.cast(super.orderKeysBy(keyComparator)); - } - - @Override - @Beta - public TagFilterBuilder orderValuesBy(Comparator<? super String> valueComparator) { - return TagFilterBuilder.class.cast(super.orderValuesBy(valueComparator)); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/Tags.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/Tags.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/Tags.java deleted file mode 100644 index 23e5ca1..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/util/Tags.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.util; - -import static com.google.common.collect.Multimaps.index; - -import java.util.Map; - -import org.jclouds.ec2.domain.Tag; - -import com.google.common.base.Function; -import com.google.common.collect.Maps; - -/** - * - * @author Adrian Cole - */ -public class Tags { - private Tags() { - } - - /** - * maps the input on {@link Tag#getResourceId()} with a value of a map of its {@link Tag#getKey()} to - * {@link Tag#getValue()} - */ - public static Map<String, Map<String, String>> resourceToTagsAsMap(Iterable<Tag> tags) { - return Maps.transformValues(index(tags, resourceIdFunction()).asMap(), - new Function<Iterable<Tag>, Map<String, String>>() { - @Override - public Map<String, String> apply(Iterable<Tag> in) { - return Maps.transformValues(Maps.uniqueIndex(in, keyFunction()), valueFunction()); - } - }); - } - - public static enum ValueFunction implements Function<Tag, String> { - INSTANCE; - @Override - public String apply(Tag in) { - return in.getValue().or(""); - } - - @Override - public String toString() { - return "getValue()"; - } - } - - public static Function<Tag, String> valueFunction() { - return ValueFunction.INSTANCE; - } - - public static enum KeyFunction implements Function<Tag, String> { - INSTANCE; - @Override - public String apply(Tag in) { - return in.getKey(); - } - - @Override - public String toString() { - return "getKey()"; - } - } - - public static Function<Tag, String> keyFunction() { - return KeyFunction.INSTANCE; - } - - public static enum ResourceIdFunction implements Function<Tag, String> { - INSTANCE; - @Override - public String apply(Tag in) { - return in.getResourceId(); - } - - @Override - public String toString() { - return "getResourceId()"; - } - } - - public static Function<Tag, String> resourceIdFunction() { - return ResourceIdFunction.INSTANCE; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AllocateAddressResponseHandler.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AllocateAddressResponseHandler.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AllocateAddressResponseHandler.java deleted file mode 100644 index a798201..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AllocateAddressResponseHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.xml; - -import javax.annotation.Resource; - -import org.jclouds.http.functions.ParseSax.HandlerWithResult; -import org.jclouds.logging.Logger; - -/** - * @author Adrian Cole - */ -public class AllocateAddressResponseHandler extends HandlerWithResult<String> { - - @Resource - protected Logger logger = Logger.NULL; - - private String ipAddress; - private StringBuilder currentText = new StringBuilder(); - - protected String currentOrNull() { - String returnVal = currentText.toString().trim(); - return returnVal.equals("") ? null : returnVal; - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("publicIp")) { - ipAddress = currentOrNull(); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } - - @Override - public String getResult() { - return ipAddress; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AttachmentHandler.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AttachmentHandler.java b/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AttachmentHandler.java deleted file mode 100644 index 24affca..0000000 --- a/dependencies/jclouds/apis/ec2/1.7.1-stratos/src/main/java/org/jclouds/ec2/xml/AttachmentHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.xml; - -import java.util.Date; - -import javax.annotation.Resource; -import javax.inject.Inject; - -import org.jclouds.aws.util.AWSUtils; -import org.jclouds.date.DateCodec; -import org.jclouds.date.DateCodecFactory; -import org.jclouds.ec2.domain.Attachment; -import org.jclouds.http.functions.ParseSax; -import org.jclouds.location.Region; -import org.jclouds.logging.Logger; - -import com.google.common.base.Supplier; - -/** - * - * @author Adrian Cole - */ -public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Attachment> { - - @Resource - protected Logger logger = Logger.NULL; - - protected final DateCodec dateCodec; - protected final Supplier<String> defaultRegion; - - @Inject - AttachmentHandler(DateCodecFactory dateCodecFactory, @Region Supplier<String> defaultRegion) { - this.dateCodec = dateCodecFactory.iso8601(); - this.defaultRegion = defaultRegion; - } - - private StringBuilder currentText = new StringBuilder(); - private String volumeId; - private String instanceId; - private String device; - private Attachment.Status attachmentStatus; - private Date attachTime; - - public Attachment getResult() { - String region = AWSUtils.findRegionInArgsOrNull(getRequest()); - if (region == null) - region = defaultRegion.get(); - return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime); - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("volumeId")) { - volumeId = currentText.toString().trim(); - } else if (qName.equals("volumeId")) { - volumeId = currentText.toString().trim(); - } else if (qName.equals("status")) { - attachmentStatus = Attachment.Status.fromValue(currentText.toString().trim()); - } else if (qName.equals("instanceId")) { - instanceId = currentText.toString().trim(); - } else if (qName.equals("device")) { - device = currentText.toString().trim(); - } else if (qName.equals("attachTime")) { - attachTime = dateCodec.toDate(currentText.toString().trim()); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } -}
