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.slicehost.compute.config; |
20 | |
21 | import java.util.Map; |
22 | |
23 | import javax.inject.Singleton; |
24 | |
25 | import org.jclouds.compute.ComputeServiceContext; |
26 | import org.jclouds.compute.domain.Hardware; |
27 | import org.jclouds.compute.domain.Image; |
28 | import org.jclouds.compute.domain.NodeMetadata; |
29 | import org.jclouds.compute.domain.NodeState; |
30 | import org.jclouds.compute.domain.OperatingSystem; |
31 | import org.jclouds.compute.internal.BaseComputeService; |
32 | import org.jclouds.compute.internal.ComputeServiceContextImpl; |
33 | import org.jclouds.rest.RestContext; |
34 | import org.jclouds.rest.internal.RestContextImpl; |
35 | import org.jclouds.slicehost.SlicehostAsyncClient; |
36 | import org.jclouds.slicehost.SlicehostClient; |
37 | import org.jclouds.slicehost.compute.functions.FlavorToHardware; |
38 | import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata; |
39 | import org.jclouds.slicehost.compute.functions.SlicehostImageToImage; |
40 | import org.jclouds.slicehost.compute.functions.SlicehostImageToOperatingSystem; |
41 | import org.jclouds.slicehost.domain.Flavor; |
42 | import org.jclouds.slicehost.domain.Slice; |
43 | |
44 | import com.google.common.annotations.VisibleForTesting; |
45 | import com.google.common.base.Function; |
46 | import com.google.common.collect.ImmutableMap; |
47 | import com.google.inject.AbstractModule; |
48 | import com.google.inject.Provides; |
49 | import com.google.inject.Scopes; |
50 | import com.google.inject.TypeLiteral; |
51 | |
52 | /** |
53 | * Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound. |
54 | * |
55 | * @author Adrian Cole |
56 | */ |
57 | public class SlicehostComputeServiceDependenciesModule extends AbstractModule { |
58 | |
59 | @Override |
60 | protected void configure() { |
61 | bind(new TypeLiteral<Function<Slice, NodeMetadata>>() { |
62 | }).to(SliceToNodeMetadata.class); |
63 | |
64 | bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, Image>>() { |
65 | }).to(SlicehostImageToImage.class); |
66 | |
67 | bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, OperatingSystem>>() { |
68 | }).to(SlicehostImageToOperatingSystem.class); |
69 | bind(new TypeLiteral<Function<Flavor, Hardware>>() { |
70 | }).to(FlavorToHardware.class); |
71 | |
72 | bind(new TypeLiteral<ComputeServiceContext>() { |
73 | }).to(new TypeLiteral<ComputeServiceContextImpl<SlicehostClient, SlicehostAsyncClient>>() { |
74 | }).in(Scopes.SINGLETON); |
75 | bind(new TypeLiteral<RestContext<SlicehostClient, SlicehostAsyncClient>>() { |
76 | }).to(new TypeLiteral<RestContextImpl<SlicehostClient, SlicehostAsyncClient>>() { |
77 | }).in(Scopes.SINGLETON); |
78 | |
79 | } |
80 | |
81 | @VisibleForTesting |
82 | public static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap |
83 | .<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)// |
84 | .put(Slice.Status.BUILD, NodeState.PENDING)// |
85 | .put(Slice.Status.REBOOT, NodeState.PENDING)// |
86 | .put(Slice.Status.HARD_REBOOT, NodeState.PENDING)// |
87 | .put(Slice.Status.TERMINATED, NodeState.TERMINATED)// |
88 | .put(Slice.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)// |
89 | .build(); |
90 | |
91 | @Singleton |
92 | @Provides |
93 | Map<Slice.Status, NodeState> provideSliceToNodeState() { |
94 | return sliceStatusToNodeState; |
95 | } |
96 | } |