Updating licenses in all files
[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  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.adapter.iaas.provider.operation.api;
24
25 import org.openecomp.appc.adapter.iaas.provider.operation.impl.*;
26 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
27 import org.openecomp.appc.exceptions.APPCException;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 /**
33  * Singleton factory of provider operations objects with cache
34  * @since September 26, 2016
35  */
36 public class ProviderOperationFactory {
37
38     /**
39      * holds instance of the class
40      */
41     private static ProviderOperationFactory instance;
42
43     /**
44      * holds concrete operations objects
45      */
46     private Map<Operation, IProviderOperation> operations;
47
48     /**
49      * private constructor
50      */
51     private ProviderOperationFactory() {
52         this.operations = new HashMap<>();
53     }
54
55     /**
56      * @return instance of the factory
57      */
58     public static ProviderOperationFactory getInstance() {
59         if (instance == null) {
60             instance = new ProviderOperationFactory();
61         }
62         return instance;
63     }
64
65     /**
66      * @param op
67      * @return concrete operation impl
68      */
69     public IProviderOperation getOperationObject(Operation op) throws APPCException {
70
71         IProviderOperation opObject = operations.get(op);
72         if (opObject == null) {
73             switch (op) {
74                 case EVACUATE_SERVICE:
75                     opObject = new EvacuateServer();
76                     break;
77                 case MIGRATE_SERVICE:
78                     opObject = new MigrateServer();
79                     break;
80                 case REBUILD_SERVICE:
81                     opObject = new RebuildServer();
82                     break;
83                 case RESTART_SERVICE:
84                     opObject = new RestartServer();
85                     break;
86                 case VMSTATUSCHECK_SERVICE:
87                     opObject = new VmStatuschecker();
88                     break;
89                 case SNAPSHOT_SERVICE:
90                     opObject = new CreateSnapshot();
91                     break;
92                 case TERMINATE_STACK:
93                     opObject = new TerminateStack();
94                     break;
95                 case SNAPSHOT_STACK:
96                     opObject = new SnapshotStack();
97                     break;
98                 case RESTORE_STACK:
99                     opObject = new RestoreStack();
100                     break;
101                 case START_SERVICE:
102                     opObject = new StartServer();
103                     break;
104                 case STOP_SERVICE:
105                     opObject = new StopServer();
106                     break;
107                 case TERMINATE_SERVICE:
108                     opObject = new TerminateServer();
109                     break;
110                 case LOOKUP_SERVICE:
111                     opObject = new LookupServer();
112                     break;
113                 default:
114                     throw new APPCException("Unsupported provider operation.");
115             }
116             operations.put(op,opObject);
117         }
118         return opObject;
119     }
120 }