| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.trmk.vcloud_0_8.compute.strategy; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.Map; |
| 23 | import java.util.Set; |
| 24 | import java.util.concurrent.ExecutorService; |
| 25 | import java.util.concurrent.Future; |
| 26 | |
| 27 | import javax.inject.Inject; |
| 28 | import javax.inject.Named; |
| 29 | import javax.inject.Singleton; |
| 30 | |
| 31 | import org.jclouds.Constants; |
| 32 | import org.jclouds.compute.config.CustomizationResponse; |
| 33 | import org.jclouds.compute.domain.NodeMetadata; |
| 34 | import org.jclouds.compute.domain.Template; |
| 35 | import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; |
| 36 | import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; |
| 37 | import org.jclouds.compute.strategy.ListNodesStrategy; |
| 38 | import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet; |
| 39 | import org.jclouds.domain.LocationScope; |
| 40 | import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions; |
| 41 | |
| 42 | import com.google.common.collect.Multimap; |
| 43 | |
| 44 | /** |
| 45 | * creates futures that correlate to |
| 46 | * |
| 47 | * @author Adrian Cole |
| 48 | */ |
| 49 | @Singleton |
| 50 | public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends CreateNodesWithGroupEncodedIntoNameThenAddToSet { |
| 51 | |
| 52 | private final CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise; |
| 53 | |
| 54 | @Inject |
| 55 | protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy( |
| 56 | CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy, |
| 57 | ListNodesStrategy listNodesStrategy, |
| 58 | @Named("NAMING_CONVENTION") String nodeNamingConvention, |
| 59 | CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, |
| 60 | @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, |
| 61 | CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) { |
| 62 | super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, executor, |
| 63 | customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); |
| 64 | this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, |
| 69 | Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { |
| 70 | assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " |
| 71 | + template.getLocation(); |
| 72 | String orgId = template.getLocation().getParent().getId(); |
| 73 | assert orgId.startsWith("http") : "parent id should be a rest url: " + template.getLocation().getParent(); |
| 74 | createNewKeyPairUnlessUserSpecifiedOtherwise.execute(URI.create(orgId), tag, template.getImage() |
| 75 | .getDefaultCredentials().identity, template.getOptions().as(TerremarkVCloudTemplateOptions.class)); |
| 76 | return super.execute(tag, count, template, goodNodes, badNodes, customizationResponses); |
| 77 | } |
| 78 | } |