You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2014/12/23 05:27:12 UTC
[48/51] [partial] stratos git commit: dropping jclouds 1.8.0 clone
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2ImageExtension.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2ImageExtension.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2ImageExtension.java
deleted file mode 100644
index 03c18d7..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2ImageExtension.java
+++ /dev/null
@@ -1,140 +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.compute.extensions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Iterables.find;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_AVAILABLE;
-import static org.jclouds.location.predicates.LocationPredicates.idEquals;
-
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jclouds.Constants;
-import org.jclouds.aws.util.AWSUtils;
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.CloneImageTemplate;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.ImageBuilder;
-import org.jclouds.compute.domain.ImageTemplate;
-import org.jclouds.compute.domain.ImageTemplateBuilder;
-import org.jclouds.compute.domain.OperatingSystem;
-import org.jclouds.compute.extensions.ImageExtension;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.domain.Location;
-import org.jclouds.ec2.EC2Api;
-import org.jclouds.ec2.domain.Reservation;
-import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.ec2.options.CreateImageOptions;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.util.concurrent.Atomics;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.UncheckedTimeoutException;
-
-/**
- * EC2 implementation of {@link ImageExtension} please note that {@link #createImage(ImageTemplate)}
- * only works by cloning EBS backed instances for the moment.
- */
-public class EC2ImageExtension implements ImageExtension {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
- private final EC2Api ec2Api;
- private final ListeningExecutorService userExecutor;
- private final Supplier<Set<? extends Location>> locations;
- private final Predicate<AtomicReference<Image>> imageAvailablePredicate;
-
- @Inject
- public EC2ImageExtension(EC2Api ec2Api, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
- @Memoized Supplier<Set<? extends Location>> locations,
- @Named(TIMEOUT_IMAGE_AVAILABLE) Predicate<AtomicReference<Image>> imageAvailablePredicate) {
- this.ec2Api = checkNotNull(ec2Api, "ec2Api");
- this.userExecutor = checkNotNull(userExecutor, "userExecutor");
- this.locations = checkNotNull(locations, "locations");
- this.imageAvailablePredicate = checkNotNull(imageAvailablePredicate, "imageAvailablePredicate");
- }
-
- @Override
- public ImageTemplate buildImageTemplateFromNode(String name, String id) {
- String[] parts = AWSUtils.parseHandle(id);
- String region = parts[0];
- String instanceId = parts[1];
- Reservation<? extends RunningInstance> instance = getOnlyElement(ec2Api.getInstanceApi().get()
- .describeInstancesInRegion(region, instanceId));
- if (instance == null)
- throw new NoSuchElementException("Cannot find server with id: " + id);
- CloneImageTemplate template = new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build();
- return template;
- }
-
- @Override
- public ListenableFuture<Image> createImage(ImageTemplate template) {
- checkState(template instanceof CloneImageTemplate, " ec2 only supports creating images through cloning.");
- CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;
- String[] parts = AWSUtils.parseHandle(cloneTemplate.getSourceNodeId());
- String region = parts[0];
- String instanceId = parts[1];
-
- String imageId = ec2Api.getAMIApi().get().createImageInRegion(region, cloneTemplate.getName(), instanceId,
- CreateImageOptions.NONE);
-
- final AtomicReference<Image> image = Atomics.newReference(new ImageBuilder()
- .location(find(locations.get(), idEquals(region)))
- .id(region + "/" + imageId)
- .providerId(imageId)
- .description(cloneTemplate.getName())
- .operatingSystem(OperatingSystem.builder().description(cloneTemplate.getName()).build())
- .status(Image.Status.PENDING).build());
-
- return userExecutor.submit(new Callable<Image>() {
- @Override
- public Image call() throws Exception {
- if (imageAvailablePredicate.apply(image))
- return image.get();
- // TODO: get rid of the expectation that the image will be available, as it is very brittle
- throw new UncheckedTimeoutException("Image was not created within the time limit: " + image.get());
- }
- });
- }
-
- @Override
- public boolean deleteImage(String id) {
- String[] parts = AWSUtils.parseHandle(id);
- String region = parts[0];
- String instanceId = parts[1];
- try {
- ec2Api.getAMIApi().get().deregisterImageInRegion(region, instanceId);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2SecurityGroupExtension.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2SecurityGroupExtension.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2SecurityGroupExtension.java
deleted file mode 100644
index 789a7b6..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/extensions/EC2SecurityGroupExtension.java
+++ /dev/null
@@ -1,378 +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.compute.extensions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Predicates.notNull;
-import static com.google.common.collect.Iterables.concat;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static com.google.common.collect.Iterables.transform;
-
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jclouds.Constants;
-import org.jclouds.aws.util.AWSUtils;
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.SecurityGroup;
-import org.jclouds.compute.extensions.SecurityGroupExtension;
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.compute.functions.GroupNamingConvention.Factory;
-import org.jclouds.domain.Location;
-import org.jclouds.ec2.EC2Api;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.ec2.compute.domain.RegionNameAndIngressRules;
-import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.ec2.domain.UserIdGroupPair;
-import org.jclouds.location.Region;
-import org.jclouds.net.domain.IpPermission;
-import org.jclouds.net.domain.IpProtocol;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.ListeningExecutorService;
-
-/**
- * An extension to compute service to allow for the manipulation of {@link SecurityGroup}s. Implementation
- * is optional by providers.
- */
-public class EC2SecurityGroupExtension implements SecurityGroupExtension {
-
- protected final EC2Api client;
- protected final ListeningExecutorService userExecutor;
- protected final Supplier<Set<String>> regions;
- protected final Function<org.jclouds.ec2.domain.SecurityGroup, SecurityGroup> groupConverter;
- protected final Supplier<Set<? extends Location>> locations;
- protected final LoadingCache<RegionAndName, String> groupCreator;
- protected final Factory namingConvention;
-
- @Inject
- public EC2SecurityGroupExtension(EC2Api client,
- @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
- @Region Supplier<Set<String>> regions,
- Function<org.jclouds.ec2.domain.SecurityGroup, SecurityGroup> groupConverter,
- @Memoized Supplier<Set<? extends Location>> locations,
- @Named("SECURITY") LoadingCache<RegionAndName, String> groupCreator,
- GroupNamingConvention.Factory namingConvention) {
-
- this.client = checkNotNull(client, "client");
- this.userExecutor = checkNotNull(userExecutor, "userExecutor");
- this.regions = checkNotNull(regions, "regions");
- this.groupConverter = checkNotNull(groupConverter, "groupConverter");
- this.locations = checkNotNull(locations, "locations");
- this.groupCreator = checkNotNull(groupCreator, "groupCreator");
- this.namingConvention = checkNotNull(namingConvention, "namingConvention");
- }
-
- @Override
- public Set<SecurityGroup> listSecurityGroups() {
- Iterable<? extends org.jclouds.ec2.domain.SecurityGroup> rawGroups = pollSecurityGroups();
- Iterable<SecurityGroup> groups = transform(filter(rawGroups, notNull()),
- groupConverter);
- return ImmutableSet.copyOf(groups);
- }
-
-
- @Override
- public Set<SecurityGroup> listSecurityGroupsInLocation(final Location location) {
- String region = AWSUtils.getRegionFromLocationOrNull(location);
- if (region == null) {
- return ImmutableSet.of();
- }
- return listSecurityGroupsInLocation(region);
- }
-
- public Set<SecurityGroup> listSecurityGroupsInLocation(String region) {
- Iterable<? extends org.jclouds.ec2.domain.SecurityGroup> rawGroups = pollSecurityGroupsByRegion(region);
- Iterable<SecurityGroup> groups = transform(filter(rawGroups, notNull()),
- groupConverter);
- return ImmutableSet.copyOf(groups);
- }
-
- @Override
- public Set<SecurityGroup> listSecurityGroupsForNode(String id) {
- checkNotNull(id, "id");
- String[] parts = AWSUtils.parseHandle(id);
- String region = parts[0];
- String instanceId = parts[1];
-
- RunningInstance instance = getOnlyElement(Iterables.concat(client.getInstanceApi().get().describeInstancesInRegion(region, instanceId)));
-
- if (instance == null) {
- return ImmutableSet.of();
- }
-
- Set<String> groupNames = instance.getGroupNames();
- Set<? extends org.jclouds.ec2.domain.SecurityGroup> rawGroups =
- client.getSecurityGroupApi().get().describeSecurityGroupsInRegion(region, Iterables.toArray(groupNames, String.class));
-
- return ImmutableSet.copyOf(transform(filter(rawGroups, notNull()), groupConverter));
- }
-
- @Override
- public SecurityGroup getSecurityGroupById(String id) {
- checkNotNull(id, "id");
- String[] parts = AWSUtils.parseHandle(id);
- String region = parts[0];
- String groupId = parts[1];
-
- Set<? extends org.jclouds.ec2.domain.SecurityGroup> rawGroups =
- client.getSecurityGroupApi().get().describeSecurityGroupsInRegion(region, groupId);
-
- return getOnlyElement(transform(filter(rawGroups, notNull()), groupConverter));
- }
-
- @Override
- public SecurityGroup createSecurityGroup(String name, Location location) {
- String region = AWSUtils.getRegionFromLocationOrNull(location);
- if (region != null) {
- return createSecurityGroup(name, region);
- } else {
- return null;
- }
- }
-
- public SecurityGroup createSecurityGroup(String name, String region) {
- String markerGroup = namingConvention.create().sharedNameForGroup(name);
- RegionNameAndIngressRules regionAndName = new RegionNameAndIngressRules(region, markerGroup, new int[] {},
- false);
-
- groupCreator.getUnchecked(regionAndName);
-
- return getSecurityGroupById(regionAndName.slashEncode());
- }
-
- @Override
- public boolean removeSecurityGroup(String id) {
- checkNotNull(id, "id");
- String[] parts = AWSUtils.parseHandle(id);
- String region = parts[0];
- String groupName = parts[1];
-
- if (client.getSecurityGroupApi().get().describeSecurityGroupsInRegion(region, groupName).size() > 0) {
- client.getSecurityGroupApi().get().deleteSecurityGroupInRegion(region, groupName);
- // TODO: test this clear happens
- groupCreator.invalidate(new RegionNameAndIngressRules(region, groupName, null, false));
- return true;
- }
-
- return false;
- }
-
-
- @Override
- public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
- String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
- String name = group.getName();
-
- if (ipPermission.getCidrBlocks().size() > 0) {
- for (String cidr : ipPermission.getCidrBlocks()) {
- client.getSecurityGroupApi().get().
- authorizeSecurityGroupIngressInRegion(region,
- name,
- ipPermission.getIpProtocol(),
- ipPermission.getFromPort(),
- ipPermission.getToPort(),
- cidr);
- }
- }
-
- if (ipPermission.getTenantIdGroupNamePairs().size() > 0) {
- for (String userId : ipPermission.getTenantIdGroupNamePairs().keySet()) {
- for (String groupName : ipPermission.getTenantIdGroupNamePairs().get(userId)) {
- client.getSecurityGroupApi().get().
- authorizeSecurityGroupIngressInRegion(region,
- name,
- new UserIdGroupPair(userId, groupName));
- }
- }
- }
-
- return getSecurityGroupById(new RegionAndName(region, group.getName()).slashEncode());
- }
-
- @Override
- public SecurityGroup addIpPermission(IpProtocol protocol, int startPort, int endPort,
- Multimap<String, String> tenantIdGroupNamePairs,
- Iterable<String> ipRanges,
- Iterable<String> groupIds, SecurityGroup group) {
- String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
- String name = group.getName();
-
- if (Iterables.size(ipRanges) > 0) {
- for (String cidr : ipRanges) {
- client.getSecurityGroupApi().get().
- authorizeSecurityGroupIngressInRegion(region,
- name,
- protocol,
- startPort,
- endPort,
- cidr);
- }
- }
-
- if (tenantIdGroupNamePairs.size() > 0) {
- for (String userId : tenantIdGroupNamePairs.keySet()) {
- for (String groupName : tenantIdGroupNamePairs.get(userId)) {
- client.getSecurityGroupApi().get().
- authorizeSecurityGroupIngressInRegion(region,
- name,
- new UserIdGroupPair(userId, groupName));
- }
- }
- }
-
- return getSecurityGroupById(new RegionAndName(region, group.getName()).slashEncode());
- }
-
- @Override
- public SecurityGroup removeIpPermission(IpPermission ipPermission, SecurityGroup group) {
- String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
- String name = group.getName();
-
- if (ipPermission.getCidrBlocks().size() > 0) {
- for (String cidr : ipPermission.getCidrBlocks()) {
- client.getSecurityGroupApi().get().
- revokeSecurityGroupIngressInRegion(region,
- name,
- ipPermission.getIpProtocol(),
- ipPermission.getFromPort(),
- ipPermission.getToPort(),
- cidr);
- }
- }
-
- if (ipPermission.getTenantIdGroupNamePairs().size() > 0) {
- for (String userId : ipPermission.getTenantIdGroupNamePairs().keySet()) {
- for (String groupName : ipPermission.getTenantIdGroupNamePairs().get(userId)) {
- client.getSecurityGroupApi().get().
- revokeSecurityGroupIngressInRegion(region,
- name,
- new UserIdGroupPair(userId, groupName));
- }
- }
- }
-
- return getSecurityGroupById(new RegionAndName(region, group.getName()).slashEncode());
- }
-
- @Override
- public SecurityGroup removeIpPermission(IpProtocol protocol, int startPort, int endPort,
- Multimap<String, String> tenantIdGroupNamePairs,
- Iterable<String> ipRanges,
- Iterable<String> groupIds, SecurityGroup group) {
- String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
- String name = group.getName();
-
- if (Iterables.size(ipRanges) > 0) {
- for (String cidr : ipRanges) {
- client.getSecurityGroupApi().get().
- revokeSecurityGroupIngressInRegion(region,
- name,
- protocol,
- startPort,
- endPort,
- cidr);
- }
- }
-
- if (tenantIdGroupNamePairs.size() > 0) {
- for (String userId : tenantIdGroupNamePairs.keySet()) {
- for (String groupName : tenantIdGroupNamePairs.get(userId)) {
- client.getSecurityGroupApi().get().
- revokeSecurityGroupIngressInRegion(region,
- name,
- new UserIdGroupPair(userId, groupName));
- }
- }
- }
-
- return getSecurityGroupById(new RegionAndName(region, group.getName()).slashEncode());
- }
-
- @Override
- public boolean supportsTenantIdGroupNamePairs() {
- return true;
- }
-
- @Override
- public boolean supportsTenantIdGroupIdPairs() {
- return false;
- }
-
- @Override
- public boolean supportsGroupIds() {
- return false;
- }
-
- @Override
- public boolean supportsPortRangesForGroups() {
- return false;
- }
-
- protected Iterable<? extends org.jclouds.ec2.domain.SecurityGroup> pollSecurityGroups() {
- Iterable<? extends Set<? extends org.jclouds.ec2.domain.SecurityGroup>> groups
- = transform(regions.get(), allSecurityGroupsInRegion());
-
- return concat(groups);
- }
-
-
- protected Iterable<? extends org.jclouds.ec2.domain.SecurityGroup> pollSecurityGroupsByRegion(String region) {
- return allSecurityGroupsInRegion().apply(region);
- }
-
- protected Function<String, Set<? extends org.jclouds.ec2.domain.SecurityGroup>> allSecurityGroupsInRegion() {
- return new Function<String, Set<? extends org.jclouds.ec2.domain.SecurityGroup>>() {
-
- @Override
- public Set<? extends org.jclouds.ec2.domain.SecurityGroup> apply(String from) {
- return client.getSecurityGroupApi().get().describeSecurityGroupsInRegion(from);
- }
-
- };
- }
-
- protected Location findLocationWithId(final String locationId) {
- if (locationId == null)
- return null;
- try {
- Location location = Iterables.find(locations.get(), new Predicate<Location>() {
-
- @Override
- public boolean apply(Location input) {
- return input.getId().equals(locationId);
- }
-
- });
- return location;
-
- } catch (NoSuchElementException e) {
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/AddElasticIpsToNodemetadata.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/AddElasticIpsToNodemetadata.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/AddElasticIpsToNodemetadata.java
deleted file mode 100644
index 72528a1..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/AddElasticIpsToNodemetadata.java
+++ /dev/null
@@ -1,75 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.concurrent.ExecutionException;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.aws.util.AWSUtils;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-
-import com.google.common.base.Function;
-import com.google.common.base.Throwables;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableSet;
-
-/**
- * This class searches for elastic ip addresses that are associated with the node, and adds them to
- * the publicIpAddress collection if present.
- */
-@Singleton
-public class AddElasticIpsToNodemetadata implements Function<NodeMetadata, NodeMetadata> {
-
- private final LoadingCache<RegionAndName, String> cache;
-
- @Inject
- protected AddElasticIpsToNodemetadata(@Named("ELASTICIP") LoadingCache<RegionAndName, String> cache) {
- this.cache = checkNotNull(cache, "cache");
- }
-
- // Note: Instances only have one Internet routable IP address. When an Elastic IP is associated to an
- // instance, the instance's existing Public IP address mapping is removed and is no longer valid for this instance
- // http://aws.amazon.com/articles/1346
-
- // TODO can there be multiple elastic ips on one instance?
- @Override
- public NodeMetadata apply(NodeMetadata arg0) {
- String[] parts = AWSUtils.parseHandle(arg0.getId());
- String region = parts[0];
- String instanceId = parts[1];
- try {
- String publicIp = cache.get(new RegionAndName(region, instanceId));
- // Replace existing public addresses with elastic IP (see note above)
- return NodeMetadataBuilder.fromNodeMetadata(arg0)
- .publicAddresses(ImmutableSet.<String> builder().add(publicIp).build()).build();
- } catch (CacheLoader.InvalidCacheLoadException e) {
- // no ip was found
- return arg0;
- } catch (ExecutionException e) {
- throw Throwables.propagate(e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CreateUniqueKeyPair.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CreateUniqueKeyPair.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CreateUniqueKeyPair.java
deleted file mode 100644
index 37f4c15..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CreateUniqueKeyPair.java
+++ /dev/null
@@ -1,75 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.ec2.EC2Api;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.ec2.domain.KeyPair;
-import org.jclouds.logging.Logger;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.inject.Inject;
-
-@Singleton
-public class CreateUniqueKeyPair implements Function<RegionAndName, KeyPair> {
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
- protected final EC2Api ec2Api;
- protected final GroupNamingConvention.Factory namingConvention;
-
- @Inject
- public CreateUniqueKeyPair(EC2Api ec2Api, GroupNamingConvention.Factory namingConvention) {
- this.ec2Api = ec2Api;
- this.namingConvention = checkNotNull(namingConvention, "namingConvention");
- }
-
- @Override
- public KeyPair apply(RegionAndName from) {
- return createNewKeyPairInRegion(from.getRegion(), from.getName());
- }
-
- @VisibleForTesting
- KeyPair createNewKeyPairInRegion(String region, String group) {
- checkNotNull(region, "region");
- checkNotNull(group, "group");
- logger.debug(">> creating keyPair region(%s) group(%s)", region, group);
- KeyPair keyPair = null;
- String prefix = group;
-
- while (keyPair == null) {
- String keyName = namingConvention.create().uniqueNameForGroup(prefix);
- try {
- keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName);
- } catch (IllegalStateException e) {
- logger.trace(" invalid keyname (%s in %s); retrying", keyName, region);
- }
- }
-
- logger.debug("<< created keyPair(%s)", keyPair);
- return keyPair;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java
deleted file mode 100644
index f9ee0a7..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java
+++ /dev/null
@@ -1,75 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.compute.domain.Image;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.ec2.domain.KeyPair;
-import org.jclouds.ec2.domain.RunningInstance;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Supplier;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-
-@Singleton
-public class CredentialsForInstance extends CacheLoader<RunningInstance, Optional<LoginCredentials>> {
-
- private final ConcurrentMap<RegionAndName, KeyPair> credentialsMap;
- private final Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap;
- private final Function<RunningInstance, LoginCredentials> passwordCredentialsFromWindowsInstance;
-
- @Inject
- CredentialsForInstance(ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
- Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap, Function<RunningInstance, LoginCredentials> passwordCredentialsFromWindowsInstance) {
- this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
- this.imageMap = checkNotNull(imageMap, "imageMap");
- this.passwordCredentialsFromWindowsInstance = checkNotNull(passwordCredentialsFromWindowsInstance, "passwordCredentialsFromWindowsInstance");
- }
-
- @Override
- public Optional<LoginCredentials> load(final RunningInstance instance) throws ExecutionException {
- if ("windows".equals(instance.getPlatform())) {
- return Optional.of(passwordCredentialsFromWindowsInstance.apply(instance));
- } else if (instance.getKeyName() != null) {
- return Optional.of(LoginCredentials.builder().user(getLoginAccountFor(instance)).privateKey(getPrivateKeyOrNull(instance)).build());
- }
- return Optional.absent();
- }
-
- @VisibleForTesting
- String getPrivateKeyOrNull(RunningInstance instance) {
- KeyPair keyPair = credentialsMap.get(new RegionAndName(instance.getRegion(), instance.getKeyName()));
- return keyPair != null ? keyPair.getKeyMaterial() : null;
- }
-
- @VisibleForTesting
- String getLoginAccountFor(RunningInstance from) throws ExecutionException {
- return imageMap.get().get(new RegionAndName(from.getRegion(), from.getImageId())).getDefaultCredentials().identity;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java
deleted file mode 100644
index fc8b184..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java
+++ /dev/null
@@ -1,145 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized;
-
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.Image.Status;
-import org.jclouds.compute.domain.ImageBuilder;
-import org.jclouds.compute.domain.OperatingSystem;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
-import org.jclouds.compute.util.ComputeServiceUtils;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
-import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
-import org.jclouds.ec2.domain.Image.Architecture;
-import org.jclouds.ec2.domain.Image.ImageState;
-import org.jclouds.ec2.domain.Image.ImageType;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-
-@Singleton
-public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Image> {
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- private final Map<ImageState, Status> toPortableImageStatus;
- private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
- private final Supplier<Set<? extends Location>> locations;
- private final Supplier<Location> defaultLocation;
- private final Map<OsFamily, Map<String, String>> osVersionMap;
- private final ReviseParsedImage reviseParsedImage;
-
-
- @Inject
- public EC2ImageParser(Map<ImageState, Image.Status> toPortableImageStatus,
- PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
- Map<OsFamily, Map<String, String>> osVersionMap, @Memoized Supplier<Set<? extends Location>> locations,
- Supplier<Location> defaultLocation, ReviseParsedImage reviseParsedImage) {
- this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus");
- this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
- this.locations = checkNotNull(locations, "locations");
- this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
- this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
- this.reviseParsedImage = checkNotNull(reviseParsedImage, "reviseParsedImage");
- }
-
- @Override
- public Image apply(final org.jclouds.ec2.domain.Image from) {
- if (from.getImageType() != ImageType.MACHINE) {
- return null;
- }
- ImageBuilder builder = new ImageBuilder();
- builder.providerId(from.getId());
- builder.id(from.getRegion() + "/" + from.getId());
- builder.name(from.getName());
- builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation());
- builder.userMetadata(ImmutableMap.<String, String> builder().put("owner", from.getImageOwnerId()).put(
- "rootDeviceType", from.getRootDeviceType().value()).put("virtualizationType",
- from.getVirtualizationType().value()).put("hypervisor", from.getHypervisor().value()).build());
-
- OperatingSystem.Builder osBuilder = OperatingSystem.builder();
- osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64);
- OsFamily family = parseOsFamily(from);
- osBuilder.family(family);
- osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, from.getImageLocation(),
- osVersionMap));
- osBuilder.description(from.getImageLocation());
- osBuilder.arch(from.getVirtualizationType().value());
-
- reviseParsedImage.reviseParsedImage(from, builder, family, osBuilder);
-
- builder.defaultCredentials(credentialProvider.apply(from));
-
- try {
- builder.location(Iterables.find(locations.get(), new Predicate<Location>() {
-
- @Override
- public boolean apply(Location input) {
- return input.getId().equals(from.getRegion());
- }
-
- }));
- } catch (NoSuchElementException e) {
- logger.error("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations);
- builder.location(new LocationBuilder().scope(LocationScope.REGION).id(from.getRegion()).description(
- from.getRegion()).parent(defaultLocation.get()).build());
- }
- builder.operatingSystem(osBuilder.build());
- builder.status(toPortableImageStatus.get(from.getImageState()));
- builder.backendStatus(from.getRawState());
- return builder.build();
- }
-
- /**
- * First treats windows as a special case: check if platform==windows.
- * Then tries matching based on the image name.
- * And then falls back to checking other types of platform.
- */
- private OsFamily parseOsFamily(org.jclouds.ec2.domain.Image from) {
- if (from.getPlatform() != null && from.getPlatform().equalsIgnoreCase("windows")) {
- return OsFamily.WINDOWS;
- }
-
- OsFamily family = parseOsFamilyOrUnrecognized(from.getImageLocation());
- if (family == OsFamily.UNRECOGNIZED && from.getPlatform() != null) {
- family = parseOsFamilyOrUnrecognized(from.getPlatform());
- }
- return family;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupIdFromName.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupIdFromName.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupIdFromName.java
deleted file mode 100644
index 640a967..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupIdFromName.java
+++ /dev/null
@@ -1,48 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.aws.util.AWSUtils;
-import org.jclouds.ec2.EC2Api;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-
-@Singleton
-public class EC2SecurityGroupIdFromName implements Function<String, String> {
- protected EC2Api api;
-
- @Inject
- public EC2SecurityGroupIdFromName(EC2Api api) {
- this.api = checkNotNull(api, "api");
- }
-
- @Override
- public String apply(String input) {
- checkNotNull(input, "input");
- String[] parts = AWSUtils.parseHandle(input);
- String region = parts[0];
- String name = parts[1];
-
- return Iterables.getOnlyElement(api.getSecurityGroupApi().get().describeSecurityGroupsInRegion(region, name), null).getId();
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupToSecurityGroup.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupToSecurityGroup.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupToSecurityGroup.java
deleted file mode 100644
index ae3b5b5..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/EC2SecurityGroupToSecurityGroup.java
+++ /dev/null
@@ -1,96 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.SecurityGroup;
-import org.jclouds.compute.domain.SecurityGroupBuilder;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.domain.Location;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.collect.Iterables;
-import com.google.inject.Inject;
-
-
-/**
- * A function for transforming an EC2-specific SecurityGroup into a generic
- * SecurityGroup object.
- */
-@Singleton
-public class EC2SecurityGroupToSecurityGroup implements Function<org.jclouds.ec2.domain.SecurityGroup, SecurityGroup> {
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- protected final Supplier<Set<? extends Location>> locations;
-
- @Inject
- public EC2SecurityGroupToSecurityGroup(@Memoized Supplier<Set<? extends Location>> locations) {
- this.locations = checkNotNull(locations, "locations");
- }
-
- @Override
- public SecurityGroup apply(org.jclouds.ec2.domain.SecurityGroup group) {
- SecurityGroupBuilder builder = new SecurityGroupBuilder();
- Location location = findLocationWithId(group.getRegion());
- builder.location(location);
- builder.id(group.getRegion() + "/" + idOrName(group));
- builder.providerId(group.getId());
- builder.name(group.getName());
- builder.ipPermissions(group);
- builder.ownerId(group.getOwnerId());
-
- return builder.build();
- }
-
- protected String idOrName(org.jclouds.ec2.domain.SecurityGroup group) {
- return group.getName();
- }
-
- private Location findLocationWithId(final String locationId) {
- if (locationId == null)
- return null;
- try {
- Location location = Iterables.find(locations.get(), new Predicate<Location>() {
-
- @Override
- public boolean apply(Location input) {
- return input.getId().equals(locationId);
- }
-
- });
- return location;
-
- } catch (NoSuchElementException e) {
- logger.debug("couldn't match instance location %s in: %s", locationId, locations.get());
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/ImagesToRegionAndIdMap.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/ImagesToRegionAndIdMap.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/ImagesToRegionAndIdMap.java
deleted file mode 100644
index 1e71648..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/ImagesToRegionAndIdMap.java
+++ /dev/null
@@ -1,52 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Maps.uniqueIndex;
-
-import java.util.Map;
-
-import javax.inject.Singleton;
-
-import org.jclouds.compute.domain.Image;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-
-import com.google.common.base.Function;
-
-@Singleton
-public class ImagesToRegionAndIdMap implements Function<Iterable<? extends Image>, Map<RegionAndName, ? extends Image>> {
-
- public static Map<RegionAndName, ? extends Image> imagesToMap(Iterable<? extends Image> input) {
- return new ImagesToRegionAndIdMap().apply(input);
- }
-
- @Override
- public Map<RegionAndName, ? extends Image> apply(Iterable<? extends Image> input) {
- return uniqueIndex(input, new Function<Image, RegionAndName>() {
-
- @Override
- public RegionAndName apply(Image from) {
- checkState(from.getLocation() != null,
- "in ec2, image locations cannot be null; typically, they are Region-scoped");
- return new RegionAndName(from.getLocation().getId(), from.getProviderId());
- }
-
- });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java
deleted file mode 100644
index 93ea29e..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java
+++ /dev/null
@@ -1,119 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.jclouds.util.Predicates2.retry;
-
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.ec2.EC2Api;
-import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.ec2.domain.KeyPair;
-import org.jclouds.ec2.domain.PasswordData;
-import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.ec2.features.WindowsApi;
-import org.jclouds.javax.annotation.Nullable;
-import org.jclouds.logging.Logger;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.base.Strings;
-import com.google.common.util.concurrent.Atomics;
-
-@Singleton
-public class PasswordCredentialsFromWindowsInstance implements Function<RunningInstance, LoginCredentials> {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- private final ConcurrentMap<RegionAndName, KeyPair> credentialsMap;
- private final EC2Api ec2Api;
- private final Function<PasswordDataAndPrivateKey, LoginCredentials> pwDataToLoginCredentials;
-
- @Inject
- protected PasswordCredentialsFromWindowsInstance(ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
- EC2Api ec2Api, Function<PasswordDataAndPrivateKey, LoginCredentials> pwDataToLoginCredentials) {
- this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
- this.ec2Api = checkNotNull(ec2Api, "ec2Api");
- this.pwDataToLoginCredentials = checkNotNull(pwDataToLoginCredentials, "pwDataToLoginCredentials");
- }
-
- @Override
- public LoginCredentials apply(final RunningInstance instance) {
- Optional<? extends WindowsApi> windowsOption = ec2Api.getWindowsApiForRegion(instance.getRegion());
- checkState(windowsOption.isPresent(), "windows feature not present in region %s", instance.getRegion());
-
- final WindowsApi windowsApi = windowsOption.get();
-
- LoginCredentials credentials = LoginCredentials.builder().user("Administrator").noPrivateKey().build();
- String privateKey = getPrivateKeyOrNull(instance);
- if (privateKey == null) {
- return credentials;
- }
- // The Administrator password will take some time before it is ready - Amazon says
- // sometimes
- // 15 minutes.
- // So we create a predicate that tests if the password is ready, and wrap it in a retryable
- // predicate.
- final AtomicReference<PasswordData> data = Atomics.newReference();
- Predicate<String> passwordReady = new Predicate<String>() {
- @Override
- public boolean apply(@Nullable String s) {
- if (Strings.isNullOrEmpty(s))
- return false;
- data.set(windowsApi.getPasswordDataForInstance(instance.getId()));
- if (data.get() == null)
- return false;
- return !Strings.isNullOrEmpty(data.get().getPasswordData());
- }
- };
-
- // TODO: parameterize
- Predicate<String> passwordReadyRetryable = retry(passwordReady, 600, 10, SECONDS);
-
- logger.debug(">> awaiting password data for instance(%s/%s)", instance.getRegion(), instance.getId());
- if (passwordReadyRetryable.apply(instance.getId())) {
- credentials = pwDataToLoginCredentials.apply(new PasswordDataAndPrivateKey(data.get(), privateKey));
- logger.debug("<< obtained password data for instance(%s/%s)", instance.getRegion(), instance.getId());
- } else {
- logger.debug("<< unable to get password data for instance(%s/%s)", instance.getRegion(), instance.getId());
- }
- return credentials;
- }
-
- @VisibleForTesting
- String getPrivateKeyOrNull(RunningInstance instance) {
- KeyPair keyPair = credentialsMap.get(new RegionAndName(instance.getRegion(), instance.getKeyName()));
- return keyPair != null ? keyPair.getKeyMaterial() : null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PresentInstances.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PresentInstances.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PresentInstances.java
deleted file mode 100644
index b341007..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/PresentInstances.java
+++ /dev/null
@@ -1,82 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.concat;
-import static com.google.common.collect.Iterables.toArray;
-import static com.google.common.collect.Multimaps.index;
-import static com.google.common.collect.Multimaps.transformValues;
-import static org.jclouds.ec2.compute.domain.RegionAndName.nameFunction;
-import static org.jclouds.ec2.compute.domain.RegionAndName.regionFunction;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.Resource;
-import javax.inject.Singleton;
-
-import org.jclouds.ec2.EC2Api;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-import com.google.common.collect.Multimap;
-import com.google.inject.Inject;
-
-/**
- * returns the instances present in the list. Makes a single rest call per aggregate on region.
- */
-@Singleton
-public class PresentInstances implements Function<Set<RegionAndName>, Set<RunningInstance>> {
-
- @Resource
- protected Logger logger = Logger.NULL;
-
- private final EC2Api client;
-
- @Inject
- public PresentInstances(EC2Api client) {
- this.client = checkNotNull(client, "client");
- }
-
- @Override
- public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) {
- if (checkNotNull(regionAndIds, "regionAndIds").isEmpty())
- return ImmutableSet.of();
- Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder();
- Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()),
- nameFunction());
- for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) {
- String region = entry.getKey();
- Collection<String> instanceIds = entry.getValue();
- logger.trace("looking for instances %s in region %s", instanceIds, region);
- builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region,
- toArray(instanceIds, String.class))));
- }
- return builder.build();
- }
-
- @Override
- public String toString() {
- return "presentInstances()";
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java
deleted file mode 100644
index e0f5e95..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java
+++ /dev/null
@@ -1,254 +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.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Predicates.not;
-import static com.google.common.base.Strings.emptyToNull;
-import static com.google.common.collect.Iterables.filter;
-import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromValuesOfEmptyString;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import javax.annotation.Resource;
-import javax.inject.Singleton;
-
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.HardwareBuilder;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.Volume;
-import org.jclouds.compute.domain.internal.VolumeImpl;
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.domain.Credentials;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.ec2.domain.BlockDevice;
-import org.jclouds.ec2.domain.InstanceState;
-import org.jclouds.ec2.domain.RootDeviceType;
-import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.logging.Logger;
-import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.UncheckedExecutionException;
-import com.google.inject.Inject;
-
-@Singleton
-public class RunningInstanceToNodeMetadata implements Function<RunningInstance, NodeMetadata> {
-
- @Resource
- protected Logger logger = Logger.NULL;
-
- protected final Supplier<Set<? extends Location>> locations;
- protected final Supplier<Set<? extends Hardware>> hardware;
- protected final Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap;
- protected final Map<String, Credentials> credentialStore;
- protected final Map<InstanceState, Status> instanceToNodeStatus;
- protected final GroupNamingConvention.Factory namingConvention;
-
- @Inject
- protected RunningInstanceToNodeMetadata(Map<InstanceState, Status> instanceToNodeStatus,
- Map<String, Credentials> credentialStore, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap,
- @Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware,
- GroupNamingConvention.Factory namingConvention) {
- this.locations = checkNotNull(locations, "locations");
- this.hardware = checkNotNull(hardware, "hardware");
- this.imageMap = checkNotNull(imageMap, "imageMap");
- this.instanceToNodeStatus = checkNotNull(instanceToNodeStatus, "instanceToNodeStatus");
- this.credentialStore = checkNotNull(credentialStore, "credentialStore");
- this.namingConvention = checkNotNull(namingConvention, "namingConvention");
- }
-
- @Override
- public NodeMetadata apply(RunningInstance instance) {
- if (instance == null || instance.getId() == null)
- return null;
- NodeMetadataBuilder builder = new NodeMetadataBuilder();
- builder.name(instance.getTags().get("Name"));
- addMetadataAndParseTagsFromValuesOfEmptyString(builder, instance.getTags());
- builder.providerId(instance.getId());
- builder.id(instance.getRegion() + "/" + instance.getId());
- String group = getGroupForInstance(instance);
- builder.group(group);
- // standard convention from aws-ec2, which might not be re-used outside.
- if (instance.getPrivateDnsName() != null)
- builder.hostname(instance.getPrivateDnsName().replaceAll("\\..*", ""));
- addCredentialsForInstance(builder, instance);
- builder.status(instanceToNodeStatus.get(instance.getInstanceState()));
- builder.backendStatus(instance.getRawState());
-
- // collect all ip addresses into one bundle in case the api mistakenly put a private address
- // into the public address field
- Builder<String> addressesBuilder = ImmutableSet.builder();
- if (emptyToNull(instance.getIpAddress()) != null)
- addressesBuilder.add(instance.getIpAddress());
- if (emptyToNull(instance.getPrivateIpAddress()) != null)
- addressesBuilder.add(instance.getPrivateIpAddress());
-
- Set<String> addresses = addressesBuilder.build();
-
- builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
- builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
- builder.hardware(parseHardware(instance));
- Location location = getLocationForAvailabilityZoneOrRegion(instance);
- builder.location(location);
- builder.imageId(instance.getRegion() + "/" + instance.getImageId());
-
- // extract the operating system from the image
- RegionAndName regionAndName = new RegionAndName(instance.getRegion(), instance.getImageId());
- try {
- Image image = imageMap.get().getUnchecked(regionAndName);
- if (image != null)
- builder.operatingSystem(image.getOperatingSystem());
- } catch (CacheLoader.InvalidCacheLoadException e) {
- logger.debug("image not found for %s: %s", regionAndName, e);
- } catch (UncheckedExecutionException e) {
- logger.debug("error getting image for %s: %s", regionAndName, e);
- }
- return builder.build();
- }
-
- protected void addCredentialsForInstance(NodeMetadataBuilder builder, RunningInstance instance) {
- builder.credentials(LoginCredentials.fromCredentials(credentialStore.get("node#" + instance.getRegion() + "/"
- + instance.getId())));
- }
-
- protected Hardware parseHardware(final RunningInstance instance) {
- Hardware hardware = getHardwareForInstance(instance);
-
- if (hardware != null) {
- hardware = HardwareBuilder.fromHardware(hardware).volumes(addEBS(instance, hardware.getVolumes())).build();
- }
- return hardware;
- }
-
- @VisibleForTesting
- static List<Volume> addEBS(final RunningInstance instance, Iterable<? extends Volume> volumes) {
- Iterable<Volume> ebsVolumes = Iterables.transform(instance.getEbsBlockDevices().entrySet(),
- new Function<Entry<String, BlockDevice>, Volume>() {
-
- @Override
- public Volume apply(Entry<String, BlockDevice> from) {
- return new VolumeImpl(from.getValue().getVolumeId(), Volume.Type.SAN, null, from.getKey(),
- instance.getRootDeviceName() != null
- && instance.getRootDeviceName().equals(from.getKey()), true);
- }
- });
-
- if (instance.getRootDeviceType() == RootDeviceType.EBS) {
- volumes = Iterables.filter(volumes, new Predicate<Volume>() {
-
- @Override
- public boolean apply(Volume input) {
- return !input.isBootDevice();
- }
-
- });
-
- }
- return Lists.newArrayList(Iterables.concat(volumes, ebsVolumes));
-
- }
-
- @VisibleForTesting
- String getGroupForInstance(final RunningInstance instance) {
- String group = parseGroupFrom(instance, instance.getGroupNames());
- if (group == null && instance.getKeyName() != null) {
- // when not using a generated security group, e.g. in VPC, try from key:
- group = parseGroupFrom(instance, Sets.newHashSet(instance.getKeyName()));
- }
- return group;
- }
-
- private String parseGroupFrom(final RunningInstance instance, final Set<String> data) {
- String group = null;
- try {
- Predicate<String> containsAnyGroup = namingConvention.create().containsAnyGroup();
- String encodedGroup = Iterables.getOnlyElement(Iterables.filter(data, containsAnyGroup));
- group = namingConvention.create().extractGroup(encodedGroup);
- } catch (NoSuchElementException e) {
- logger.debug("no group parsed from %s's data: %s", instance.getId(), data);
- } catch (IllegalArgumentException e) {
- logger.debug("too many groups match naming convention; %s's data: %s", instance.getId(), data);
- }
- return group;
- }
-
- @VisibleForTesting
- Hardware getHardwareForInstance(final RunningInstance instance) {
- try {
- return Iterables.find(hardware.get(), new Predicate<Hardware>() {
-
- @Override
- public boolean apply(Hardware input) {
- return input.getId().equals(instance.getInstanceType());
- }
-
- });
- } catch (NoSuchElementException e) {
- logger.debug("couldn't match instance type %s in: %s", instance.getInstanceType(), hardware.get());
- return null;
- }
- }
-
- private Location getLocationForAvailabilityZoneOrRegion(final RunningInstance instance) {
- Location location = findLocationWithId(instance.getAvailabilityZone());
- if (location == null)
- location = findLocationWithId(instance.getRegion());
- return location;
- }
-
- private Location findLocationWithId(final String locationId) {
- if (locationId == null)
- return null;
- try {
- Location location = Iterables.find(locations.get(), new Predicate<Location>() {
-
- @Override
- public boolean apply(Location input) {
- return input.getId().equals(locationId);
- }
-
- });
- return location;
-
- } catch (NoSuchElementException e) {
- logger.debug("couldn't match instance location %s in: %s", locationId, locations.get());
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java
deleted file mode 100644
index 6e1b646..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java
+++ /dev/null
@@ -1,77 +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.compute.functions;
-
-import static com.google.common.io.BaseEncoding.base64;
-
-import java.security.KeyFactory;
-import java.security.PrivateKey;
-import java.security.spec.KeySpec;
-
-import javax.crypto.Cipher;
-import javax.inject.Inject;
-
-import org.jclouds.crypto.Crypto;
-import org.jclouds.crypto.Pems;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey;
-import org.jclouds.javax.annotation.Nullable;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Function;
-import com.google.common.base.Throwables;
-import com.google.inject.Singleton;
-
-/**
- * Given an encrypted Windows Administrator password and the decryption key, return a LoginCredentials instance.
- */
-@Singleton
-public class WindowsLoginCredentialsFromEncryptedData implements Function<PasswordDataAndPrivateKey, LoginCredentials> {
-
- private final Crypto crypto;
-
- @Inject
- public WindowsLoginCredentialsFromEncryptedData(Crypto crypto) {
- this.crypto = crypto;
- }
-
- @Override
- public LoginCredentials apply(@Nullable PasswordDataAndPrivateKey dataAndKey) {
- if (dataAndKey == null)
- return null;
-
- try {
- KeySpec keySpec = Pems.privateKeySpec(dataAndKey.getPrivateKey());
- KeyFactory kf = crypto.rsaKeyFactory();
- PrivateKey privKey = kf.generatePrivate(keySpec);
-
- Cipher cipher = crypto.cipher("RSA");
- cipher.init(Cipher.DECRYPT_MODE, privKey);
- byte[] cipherText = base64().decode(dataAndKey.getPasswordData().getPasswordData());
- byte[] plainText = cipher.doFinal(cipherText);
- String password = new String(plainText, Charsets.US_ASCII);
-
- return LoginCredentials.builder()
- .user("Administrator")
- .password(password)
- .noPrivateKey()
- .build();
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java
deleted file mode 100644
index 74d61c0..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java
+++ /dev/null
@@ -1,44 +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.compute.internal;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.Context;
-import org.jclouds.compute.Utils;
-import org.jclouds.compute.internal.ComputeServiceContextImpl;
-import org.jclouds.ec2.compute.EC2ComputeService;
-import org.jclouds.ec2.compute.EC2ComputeServiceContext;
-import org.jclouds.location.Provider;
-
-import com.google.common.reflect.TypeToken;
-
-@Singleton
-public class EC2ComputeServiceContextImpl extends ComputeServiceContextImpl implements EC2ComputeServiceContext {
- @Inject
- public EC2ComputeServiceContextImpl(@Provider Context backend, @Provider TypeToken<? extends Context> backendType,
- EC2ComputeService computeService, Utils utils) {
- super(backend, backendType, computeService, utils);
- }
-
- @Override
- public EC2ComputeService getComputeService() {
- return EC2ComputeService.class.cast(super.getComputeService());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a9834e9e/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImpl.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImpl.java b/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImpl.java
deleted file mode 100644
index 180bd62..0000000
--- a/dependencies/jclouds/apis/ec2/1.8.0-stratos/src/main/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImpl.java
+++ /dev/null
@@ -1,116 +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.compute.internal;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.TemplateBuilder;
-import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.compute.strategy.GetImageStrategy;
-import org.jclouds.compute.suppliers.ImageCacheSupplier;
-import org.jclouds.domain.Location;
-import org.jclouds.ec2.compute.domain.RegionAndName;
-import org.jclouds.util.Throwables2;
-
-import com.google.common.base.Supplier;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.UncheckedExecutionException;
-
-public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
-
- private final Supplier<LoadingCache<RegionAndName, ? extends Image>> lazyImageCache;
-
- @Inject
- protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
- ImageCacheSupplier images, @Memoized Supplier<Set<? extends Hardware>> sizes,
- Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
- @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, GetImageStrategy getImageStrategy,
- Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap) {
- super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, getImageStrategy);
- this.lazyImageCache = imageMap;
- }
-
- final Provider<Image> lazyImageProvider = new Provider<Image>() {
-
- @Override
- public Image get() {
- if (imageId != null) {
- String[] regionName = imageId.split("/");
- checkArgument(regionName.length == 2,
- "amazon image ids must include the region ( ex. us-east-1/ami-7ea24a17 ) you specified: " + imageId);
- RegionAndName key = new RegionAndName(regionName[0], regionName[1]);
- try {
- return lazyImageCache.get().get(key);
- } catch (ExecutionException e) {
- throw new NoSuchElementException(String.format("could not get imageId(%s/%s)", key.getRegion(), key.getName()));
- } catch (UncheckedExecutionException e) {
- // Primarily for testing: if cache is backed by a map, can get IllegalArgumentException instead of NPE
- IllegalArgumentException e2 = Throwables2.getFirstThrowableOfType(e, IllegalArgumentException.class);
- if (e2 != null && e2.getMessage() != null && e2.getMessage().contains("not present in")) {
- throw new NoSuchElementException(String.format("imageId(%s/%s) not found", key.getRegion(), key.getName()));
- }
- throw new NoSuchElementException(String.format("could not get imageId(%s/%s)", key.getRegion(), key.getName()));
- } catch (CacheLoader.InvalidCacheLoadException nex) {
- throw new NoSuchElementException(String.format("imageId(%s/%s) not found", key.getRegion(), key.getName()));
- }
- }
- return null;
- }
-
- };
-
- /**
- * @throws NoSuchElementException
- * if the image is not found
- */
- @Override
- protected Image resolveImage(Hardware size, Iterable<? extends Image> supportedImages) {
- try {
- return super.resolveImage(size, supportedImages);
- } catch (NoSuchElementException e) {
- Image returnVal = lazyImageProvider.get();
- if (returnVal != null)
- return returnVal;
- throw e;
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected Set<? extends Image> getImages() {
- if (imageId != null) {
- Image image = lazyImageProvider.get();
- return ImmutableSet.of(image);
- } else {
- return (Set<Image>) this.images.get();
- }
- }
-}