| 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.vcloud.compute.config; |
| 20 | |
| 21 | import javax.inject.Singleton; |
| 22 | |
| 23 | import org.jclouds.compute.ComputeServiceContext; |
| 24 | import org.jclouds.compute.config.BindComputeStrategiesByClass; |
| 25 | import org.jclouds.compute.config.BindComputeSuppliersByClass; |
| 26 | import org.jclouds.compute.domain.Image; |
| 27 | import org.jclouds.compute.domain.NodeMetadata; |
| 28 | import org.jclouds.compute.domain.OperatingSystem; |
| 29 | import org.jclouds.compute.internal.ComputeServiceContextImpl; |
| 30 | import org.jclouds.rest.RestContext; |
| 31 | import org.jclouds.rest.internal.RestContextImpl; |
| 32 | import org.jclouds.vcloud.VCloudExpressClient; |
| 33 | import org.jclouds.vcloud.compute.CommonVCloudComputeClient; |
| 34 | import org.jclouds.vcloud.compute.VCloudExpressComputeClient; |
| 35 | import org.jclouds.vcloud.compute.functions.ImagesInVCloudExpressOrg; |
| 36 | import org.jclouds.vcloud.compute.functions.ParseOsFromVAppTemplateName; |
| 37 | import org.jclouds.vcloud.compute.functions.VCloudExpressVAppToNodeMetadata; |
| 38 | import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl; |
| 39 | import org.jclouds.vcloud.domain.Org; |
| 40 | import org.jclouds.vcloud.domain.VCloudExpressVApp; |
| 41 | |
| 42 | import com.google.common.base.Function; |
| 43 | import com.google.inject.Provides; |
| 44 | import com.google.inject.Scopes; |
| 45 | import com.google.inject.TypeLiteral; |
| 46 | |
| 47 | /** |
| 48 | * Configures the {@link VCloudComputeServiceContext}; requires |
| 49 | * {@link VCloudExpressComputeClientImpl} bound. |
| 50 | * |
| 51 | * @author Adrian Cole |
| 52 | */ |
| 53 | public class VCloudExpressComputeServiceContextModule extends CommonVCloudComputeServiceContextModule { |
| 54 | |
| 55 | @Override |
| 56 | protected void configure() { |
| 57 | super.configure(); |
| 58 | bindVAppConverter(); |
| 59 | bind(new TypeLiteral<ComputeServiceContext>() { |
| 60 | }).to(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressClient>>() { |
| 61 | }).in(Scopes.SINGLETON); |
| 62 | bind(new TypeLiteral<RestContext<VCloudExpressClient, VCloudExpressClient>>() { |
| 63 | }).to(new TypeLiteral<RestContextImpl<VCloudExpressClient, VCloudExpressClient>>() { |
| 64 | }).in(Scopes.SINGLETON); |
| 65 | bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() { |
| 66 | }).to(new TypeLiteral<ImagesInVCloudExpressOrg>() { |
| 67 | }); |
| 68 | bind(new TypeLiteral<Function<String, OperatingSystem>>() { |
| 69 | }).to(ParseOsFromVAppTemplateName.class); |
| 70 | } |
| 71 | |
| 72 | protected void bindVAppConverter() { |
| 73 | bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() { |
| 74 | }).to(VCloudExpressVAppToNodeMetadata.class); |
| 75 | } |
| 76 | |
| 77 | @Provides |
| 78 | @Singleton |
| 79 | CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) { |
| 80 | return in; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public BindComputeStrategiesByClass defineComputeStrategyModule() { |
| 85 | return new VCloudExpressBindComputeStrategiesByClass(); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public BindComputeSuppliersByClass defineComputeSupplierModule() { |
| 90 | return new CommonVCloudBindComputeSuppliersByClass(); |
| 91 | } |
| 92 | } |