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