| 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 java.util.Map; |
| 22 | |
| 23 | import javax.inject.Singleton; |
| 24 | |
| 25 | import org.jclouds.compute.config.BaseComputeServiceContextModule; |
| 26 | import org.jclouds.compute.config.BindComputeStrategiesByClass; |
| 27 | import org.jclouds.compute.config.BindComputeSuppliersByClass; |
| 28 | import org.jclouds.compute.domain.NodeState; |
| 29 | import org.jclouds.vcloud.domain.Status; |
| 30 | |
| 31 | import com.google.common.annotations.VisibleForTesting; |
| 32 | import com.google.common.collect.ImmutableMap; |
| 33 | import com.google.inject.Provides; |
| 34 | |
| 35 | /** |
| 36 | * Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl} |
| 37 | * bound. |
| 38 | * |
| 39 | * @author Adrian Cole |
| 40 | */ |
| 41 | public abstract class CommonVCloudComputeServiceContextModule extends BaseComputeServiceContextModule { |
| 42 | |
| 43 | @VisibleForTesting |
| 44 | public static final Map<Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap.<Status, NodeState> builder() |
| 45 | .put(Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING) |
| 46 | .put(Status.RESOLVED, NodeState.PENDING).put(Status.ERROR, NodeState.ERROR) |
| 47 | .put(Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Status.DEPLOYED, NodeState.PENDING) |
| 48 | .put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN, NodeState.UNRECOGNIZED) |
| 49 | .put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT, NodeState.PENDING) |
| 50 | .put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED, NodeState.PENDING).build(); |
| 51 | |
| 52 | @Singleton |
| 53 | @Provides |
| 54 | protected Map<Status, NodeState> provideVAppStatusToNodeState() { |
| 55 | return VAPPSTATUS_TO_NODESTATE; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected void configure() { |
| 60 | super.configure(); |
| 61 | install(defineComputeStrategyModule()); |
| 62 | install(defineComputeSupplierModule()); |
| 63 | } |
| 64 | |
| 65 | public abstract BindComputeStrategiesByClass defineComputeStrategyModule(); |
| 66 | |
| 67 | public abstract BindComputeSuppliersByClass defineComputeSupplierModule(); |
| 68 | |
| 69 | } |