| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.aws.ec2.compute.suppliers; |
| 20 | |
| 21 | import static com.google.common.collect.Iterables.find; |
| 22 | import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs; |
| 23 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium; |
| 24 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge; |
| 25 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge; |
| 26 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_large; |
| 27 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small32; |
| 28 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge; |
| 29 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge; |
| 30 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge; |
| 31 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_xlarge; |
| 32 | import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.t1_micro; |
| 33 | |
| 34 | import java.util.Set; |
| 35 | |
| 36 | import javax.inject.Inject; |
| 37 | import javax.inject.Named; |
| 38 | import javax.inject.Singleton; |
| 39 | |
| 40 | import org.jclouds.collect.Memoized; |
| 41 | import org.jclouds.compute.domain.Hardware; |
| 42 | import org.jclouds.domain.Location; |
| 43 | import org.jclouds.domain.LocationScope; |
| 44 | import org.jclouds.ec2.compute.suppliers.EC2HardwareSupplier; |
| 45 | import org.jclouds.location.Provider; |
| 46 | |
| 47 | import com.google.common.base.Predicate; |
| 48 | import com.google.common.base.Supplier; |
| 49 | import com.google.common.collect.ImmutableSet; |
| 50 | import com.google.common.collect.ImmutableSet.Builder; |
| 51 | |
| 52 | /** |
| 53 | * |
| 54 | * @author Adrian Cole |
| 55 | */ |
| 56 | @Singleton |
| 57 | public class AWSEC2HardwareSupplier extends EC2HardwareSupplier { |
| 58 | |
| 59 | private final Supplier<Set<? extends Location>> locations; |
| 60 | private final String[] ccAmis; |
| 61 | |
| 62 | @Inject |
| 63 | public AWSEC2HardwareSupplier(@Memoized Supplier<Set<? extends Location>> locations, @Provider String providerName, |
| 64 | @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) { |
| 65 | this.locations = locations; |
| 66 | this.ccAmis = ccAmis; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public Set<? extends Hardware> get() { |
| 71 | Builder<Hardware> sizes = ImmutableSet.builder(); |
| 72 | for (String ccAmi : ccAmis) { |
| 73 | final String region = ccAmi.split("/")[0]; |
| 74 | Location location = find(locations.get(), new Predicate<Location>() { |
| 75 | |
| 76 | @Override |
| 77 | public boolean apply(Location input) { |
| 78 | return input.getScope() == LocationScope.REGION && input.getId().equals(region); |
| 79 | } |
| 80 | |
| 81 | }); |
| 82 | sizes.add(cc1_4xlarge().location(location).supportsImageIds(ccAmi).build()); |
| 83 | } |
| 84 | sizes.addAll(ImmutableSet.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large() |
| 85 | .build(), m1_small32().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), |
| 86 | m2_4xlarge().build())); |
| 87 | return sizes.build(); |
| 88 | } |
| 89 | } |