2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.adapter.iaas.provider.operation.api;
27 import org.openecomp.appc.adapter.iaas.provider.operation.impl.*;
28 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
29 import org.openecomp.appc.exceptions.APPCException;
31 import java.util.HashMap;
35 * Singleton factory of provider operations objects with cache
36 * @since September 26, 2016
38 public class ProviderOperationFactory {
41 * holds instance of the class
43 private static ProviderOperationFactory instance;
46 * holds concrete operations objects
48 private Map<Operation, IProviderOperation> operations;
53 private ProviderOperationFactory() {
54 this.operations = new HashMap<>();
58 * @return instance of the factory
60 public static ProviderOperationFactory getInstance() {
61 if (instance == null) {
62 instance = new ProviderOperationFactory();
69 * @return concrete operation impl
71 public IProviderOperation getOperationObject(Operation op) throws APPCException {
73 IProviderOperation opObject = operations.get(op);
74 if (opObject == null) {
76 case EVACUATE_SERVICE:
77 opObject = new EvacuateServer();
80 opObject = new MigrateServer();
83 opObject = new RebuildServer();
86 opObject = new RestartServer();
88 case VMSTATUSCHECK_SERVICE:
89 opObject = new VmStatuschecker();
91 case SNAPSHOT_SERVICE:
92 opObject = new CreateSnapshot();
95 opObject = new TerminateStack();
98 opObject = new SnapshotStack();
101 opObject = new RestoreStack();
104 opObject = new StartServer();
107 opObject = new StopServer();
109 case TERMINATE_SERVICE:
110 opObject = new TerminateServer();
113 opObject = new LookupServer();
116 throw new APPCException("Unsupported provider operation.");
118 operations.put(op,opObject);