2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.adapter.iaas.provider.operation.api;
24 import org.openecomp.appc.adapter.iaas.provider.operation.impl.*;
25 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
26 import org.openecomp.appc.exceptions.APPCException;
28 import java.util.HashMap;
32 * Singleton factory of provider operations objects with cache
33 * @since September 26, 2016
35 public class ProviderOperationFactory {
38 * holds instance of the class
40 private static ProviderOperationFactory instance;
43 * holds concrete operations objects
45 private Map<Operation, IProviderOperation> operations;
50 private ProviderOperationFactory() {
51 this.operations = new HashMap<>();
55 * @return instance of the factory
57 public static ProviderOperationFactory getInstance() {
58 if (instance == null) {
59 instance = new ProviderOperationFactory();
66 * @return concrete operation impl
68 public IProviderOperation getOperationObject(Operation op) throws APPCException {
70 IProviderOperation opObject = operations.get(op);
71 if (opObject == null) {
73 case EVACUATE_SERVICE:
74 opObject = new EvacuateServer();
77 opObject = new MigrateServer();
80 opObject = new RebuildServer();
83 opObject = new RestartServer();
85 case VMSTATUSCHECK_SERVICE:
86 opObject = new VmStatuschecker();
88 case SNAPSHOT_SERVICE:
89 opObject = new CreateSnapshot();
92 opObject = new TerminateStack();
95 opObject = new SnapshotStack();
98 opObject = new RestoreStack();
101 opObject = new StartServer();
104 opObject = new StopServer();
106 case TERMINATE_SERVICE:
107 opObject = new TerminateServer();
110 opObject = new LookupServer();
113 throw new APPCException("Unsupported provider operation.");
115 operations.put(op,opObject);