
org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jclouds-aws Show documentation
Show all versions of jclouds-aws Show documentation
jclouds Core components to access Amazon AWS
The newest version!
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC.
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.compute.suppliers;
import static com.google.common.collect.Maps.uniqueIndex;
import static com.google.common.collect.Sets.newLinkedHashSet;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.rest.annotations.Provider;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*/
@Singleton
public class EC2LocationSupplier implements Supplier> {
private final Map availabilityZoneToRegionMap;
private final String providerName;
@Inject
EC2LocationSupplier(Map availabilityZoneToRegionMap, @Provider String providerName) {
this.availabilityZoneToRegionMap = availabilityZoneToRegionMap;
this.providerName = providerName;
}
@Override
public Set extends Location> get() {
Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Set locations = newLinkedHashSet();
for (String region : newLinkedHashSet(availabilityZoneToRegionMap.values())) {
locations.add(new LocationImpl(LocationScope.REGION, region, region, ec2));
}
ImmutableMap idToLocation = uniqueIndex(locations, new Function() {
@Override
public String apply(Location from) {
return from.getId();
}
});
for (String zone : availabilityZoneToRegionMap.keySet()) {
locations.add(new LocationImpl(LocationScope.ZONE, zone, zone, idToLocation.get(availabilityZoneToRegionMap
.get(zone))));
}
return locations;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy