2 * ============LICENSE_START=======================================================
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
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.adapter.iaas.provider.operation.api;
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;
29 import java.util.HashMap;
33 * Singleton factory of provider operations objects with cache
34 * @since September 26, 2016
36 public class ProviderOperationFactory {
39 * holds instance of the class
41 private static ProviderOperationFactory instance;
44 * holds concrete operations objects
46 private Map<Operation, IProviderOperation> operations;
51 private ProviderOperationFactory() {
52 this.operations = new HashMap<>();
56 * @return instance of the factory
58 public static ProviderOperationFactory getInstance() {
59 if (instance == null) {
60 instance = new ProviderOperationFactory();
67 * @return concrete operation impl
69 public IProviderOperation getOperationObject(Operation op) throws APPCException {
71 IProviderOperation opObject = operations.get(op);
72 if (opObject == null) {
74 case EVACUATE_SERVICE:
75 opObject = new EvacuateServer();
78 opObject = new MigrateServer();
81 opObject = new RebuildServer();
84 opObject = new RestartServer();
86 case VMSTATUSCHECK_SERVICE:
87 opObject = new VmStatuschecker();
89 case SNAPSHOT_SERVICE:
90 opObject = new CreateSnapshot();
93 opObject = new TerminateStack();
96 opObject = new SnapshotStack();
99 opObject = new RestoreStack();
102 opObject = new StartServer();
105 opObject = new StopServer();
107 case TERMINATE_SERVICE:
108 opObject = new TerminateServer();
111 opObject = new LookupServer();
114 throw new APPCException("Unsupported provider operation.");
116 operations.put(op,opObject);