Fix sonar issues in EvacuateServer
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / main / java / org / onap / 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  * Singleton factory of provider operations objects with cache
34  * 
35  * @since September 26, 2016
36  */
37 public class ProviderOperationFactory {
38     /**
39      * holds instance of the class
40      */
41     private static ProviderOperationFactory instance;
42     /**
43      * holds concrete operations objects
44      */
45     private Map<Operation, IProviderOperation> operations;
46     /**
47      * private constructor
48      */
49     private ProviderOperationFactory() {
50         this.operations = new HashMap<>();
51     }
52     /**
53      * @return instance of the factory
54      */
55     public static ProviderOperationFactory getInstance() {
56         if (instance == null) {
57             instance = new ProviderOperationFactory();
58         }
59         return instance;
60     }
61     /**
62      * @param op
63      * @return concrete operation impl
64      */
65     public IProviderOperation getOperationObject(Operation op) throws APPCException {
66         IProviderOperation opObject = operations.get(op);
67         if (opObject == null) {
68             switch (op) {
69                 case EVACUATE_SERVICE:
70                     opObject = new EvacuateServer();
71                     break;
72                 case MIGRATE_SERVICE:
73                     opObject = new MigrateServer();
74                     break;
75                 case REBUILD_SERVICE:
76                     opObject = new RebuildServer();
77                     break;
78                 case RESTART_SERVICE:
79                     opObject = new RestartServer();
80                     break;
81                 case VMSTATUSCHECK_SERVICE:
82                     opObject = new VmStatuschecker();
83                     break;
84                 case SNAPSHOT_SERVICE:
85                     opObject = new CreateSnapshot();
86                     break;
87                 case TERMINATE_STACK:
88                     opObject = new TerminateStack();
89                     break;
90                 case SNAPSHOT_STACK:
91                     opObject = new SnapshotStack();
92                     break;
93                 case RESTORE_STACK:
94                     opObject = new RestoreStack();
95                     break;
96                 case START_SERVICE:
97                     opObject = new StartServer();
98                     break;
99                 case STOP_SERVICE:
100                     opObject = new StopServer();
101                     break;
102                 case TERMINATE_SERVICE:
103                     opObject = new TerminateServer();
104                     break;
105                 case LOOKUP_SERVICE:
106                     opObject = new LookupServer();
107                     break;
108                 case ATTACHVOLUME_SERVICE:
109                     opObject = new AttachVolumeServer();
110                     break;
111                 case DETACHVOLUME_SERVICE:
112                     opObject = new DettachVolumeServer();
113                     break;
114                 default:
115                     throw new APPCException("Unsupported provider operation.");
116             }
117             operations.put(op, opObject);
118         }
119         return opObject;
120     }
121 }