Merge of new rebased code
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / main / java / org / openecomp / appc / adapter / iaas / provider / operation / api / ProviderOperationFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.adapter.iaas.provider.operation.api;
23
24 import org.openecomp.appc.adapter.iaas.provider.operation.impl.*;
25 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
26 import org.openecomp.appc.exceptions.APPCException;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 /**
32  * Singleton factory of provider operations objects with cache
33  * @since September 26, 2016
34  */
35 public class ProviderOperationFactory {
36
37     /**
38      * holds instance of the class
39      */
40     private static ProviderOperationFactory instance;
41
42     /**
43      * holds concrete operations objects
44      */
45     private Map<Operation, IProviderOperation> operations;
46
47     /**
48      * private constructor
49      */
50     private ProviderOperationFactory() {
51         this.operations = new HashMap<>();
52     }
53
54     /**
55      * @return instance of the factory
56      */
57     public static ProviderOperationFactory getInstance() {
58         if (instance == null) {
59             instance = new ProviderOperationFactory();
60         }
61         return instance;
62     }
63
64     /**
65      * @param op
66      * @return concrete operation impl
67      */
68     public IProviderOperation getOperationObject(Operation op) throws APPCException {
69
70         IProviderOperation opObject = operations.get(op);
71         if (opObject == null) {
72             switch (op) {
73                 case EVACUATE_SERVICE:
74                     opObject = new EvacuateServer();
75                     break;
76                 case MIGRATE_SERVICE:
77                     opObject = new MigrateServer();
78                     break;
79                 case REBUILD_SERVICE:
80                     opObject = new RebuildServer();
81                     break;
82                 case RESTART_SERVICE:
83                     opObject = new RestartServer();
84                     break;
85                 case VMSTATUSCHECK_SERVICE:
86                     opObject = new VmStatuschecker();
87                     break;
88                 case SNAPSHOT_SERVICE:
89                     opObject = new CreateSnapshot();
90                     break;
91                 case TERMINATE_STACK:
92                     opObject = new TerminateStack();
93                     break;
94                 case SNAPSHOT_STACK:
95                     opObject = new SnapshotStack();
96                     break;
97                 case RESTORE_STACK:
98                     opObject = new RestoreStack();
99                     break;
100                 case START_SERVICE:
101                     opObject = new StartServer();
102                     break;
103                 case STOP_SERVICE:
104                     opObject = new StopServer();
105                     break;
106                 case TERMINATE_SERVICE:
107                     opObject = new TerminateServer();
108                     break;
109                 case LOOKUP_SERVICE:
110                     opObject = new LookupServer();
111                     break;
112                 default:
113                     throw new APPCException("Unsupported provider operation.");
114             }
115             operations.put(op,opObject);
116         }
117         return opObject;
118     }
119 }