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