2 * ============LICENSE_START=======================================================
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
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 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.iaas.provider.operation.api;
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;
32 * Singleton factory of provider operations objects with cache
34 * @since September 26, 2016
36 public class ProviderOperationFactory {
38 * holds instance of the class
40 private static ProviderOperationFactory instance;
42 * holds concrete operations objects
44 private Map<Operation, IProviderOperation> operations;
48 private ProviderOperationFactory() {
49 this.operations = new HashMap<>();
52 * @return instance of the factory
54 public static ProviderOperationFactory getInstance() {
55 if (instance == null) {
56 instance = new ProviderOperationFactory();
62 * @return concrete operation impl
64 public IProviderOperation getOperationObject(Operation op) throws APPCException {
65 IProviderOperation opObject = operations.get(op);
66 if (opObject == null) {
68 case EVACUATE_SERVICE:
69 opObject = new EvacuateServer();
72 opObject = new MigrateServer();
75 opObject = new RebuildServer();
78 opObject = new RestartServer();
80 case VMSTATUSCHECK_SERVICE:
81 opObject = new VmStatuschecker();
83 case SNAPSHOT_SERVICE:
84 opObject = new CreateSnapshot();
87 opObject = new TerminateStack();
90 opObject = new SnapshotStack();
93 opObject = new RestoreStack();
96 opObject = new StartServer();
99 opObject = new StopServer();
101 case TERMINATE_SERVICE:
102 opObject = new TerminateServer();
105 opObject = new LookupServer();
107 case ATTACHVOLUME_SERVICE:
108 opObject = new AttachVolumeServer();
110 case DETACHVOLUME_SERVICE:
111 opObject = new DettachVolumeServer();
114 throw new APPCException("Unsupported provider operation.");
116 operations.put(op, opObject);