| 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.byon.config; |
| 20 | |
| 21 | import java.io.InputStream; |
| 22 | import java.net.URI; |
| 23 | import java.util.Map; |
| 24 | |
| 25 | import javax.inject.Singleton; |
| 26 | |
| 27 | import org.jclouds.byon.Node; |
| 28 | import org.jclouds.byon.functions.NodesFromYamlStream; |
| 29 | import org.jclouds.byon.internal.BYONComputeServiceAdapter; |
| 30 | import org.jclouds.byon.suppliers.NodesParsedFromSupplier; |
| 31 | import org.jclouds.byon.suppliers.SupplyFromProviderURIOrNodesProperty; |
| 32 | import org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule; |
| 33 | import org.jclouds.concurrent.SingleThreaded; |
| 34 | import org.jclouds.domain.Location; |
| 35 | import org.jclouds.location.Provider; |
| 36 | import org.jclouds.location.suppliers.OnlyLocationOrFirstZone; |
| 37 | |
| 38 | import com.google.common.base.Function; |
| 39 | import com.google.common.base.Supplier; |
| 40 | import com.google.inject.Provides; |
| 41 | import com.google.inject.TypeLiteral; |
| 42 | |
| 43 | /** |
| 44 | * |
| 45 | * @author Adrian Cole |
| 46 | */ |
| 47 | @SuppressWarnings("unchecked") |
| 48 | @SingleThreaded |
| 49 | public class BYONComputeServiceContextModule extends |
| 50 | JCloudsNativeComputeServiceAdapterContextModule<Supplier, Supplier> { |
| 51 | |
| 52 | public BYONComputeServiceContextModule() { |
| 53 | super(Supplier.class, Supplier.class, BYONComputeServiceAdapter.class); |
| 54 | } |
| 55 | |
| 56 | @Provides |
| 57 | @Singleton |
| 58 | Supplier provideApi(Supplier<Map<String, Node>> in) { |
| 59 | return in; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | protected void configure() { |
| 64 | super.configure(); |
| 65 | bind(new TypeLiteral<Supplier<Location>>() { |
| 66 | }).to(OnlyLocationOrFirstZone.class); |
| 67 | bind(new TypeLiteral<Supplier<Map<String, Node>>>() { |
| 68 | }).to(NodesParsedFromSupplier.class); |
| 69 | bind(new TypeLiteral<Supplier<InputStream>>() { |
| 70 | }).annotatedWith(Provider.class).to(SupplyFromProviderURIOrNodesProperty.class); |
| 71 | bind(new TypeLiteral<Function<URI, InputStream>>() { |
| 72 | }).to(SupplyFromProviderURIOrNodesProperty.class); |
| 73 | // TODO make this somehow overridable via user request |
| 74 | bind(new TypeLiteral<Function<InputStream, Map<String, Node>>>() { |
| 75 | }).to(NodesFromYamlStream.class); |
| 76 | } |
| 77 | |
| 78 | } |