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.onap.appc.adapter.iaas.provider.operation.api;
27 import org.onap.appc.adapter.iaas.provider.operation.impl.*;
28 import org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation;
29 import org.onap.appc.exceptions.APPCException;
30 import java.util.HashMap;
33 * Singleton factory of provider operations objects with cache
35 * @since September 26, 2016
37 public class ProviderOperationFactory {
39 * holds instance of the class
41 private static ProviderOperationFactory instance;
43 * holds concrete operations objects
45 private Map<Operation, IProviderOperation> operations;
49 private ProviderOperationFactory() {
50 this.operations = new HashMap<>();
53 * @return instance of the factory
55 public static ProviderOperationFactory getInstance() {
56 if (instance == null) {
57 instance = new ProviderOperationFactory();
63 * @return concrete operation impl
65 public IProviderOperation getOperationObject(Operation op) throws APPCException {
66 IProviderOperation opObject = operations.get(op);
67 if (opObject == null) {
69 case EVACUATE_SERVICE:
70 opObject = new EvacuateServer();
73 opObject = new MigrateServer();
76 opObject = new RebuildServer();
79 opObject = new RestartServer();
81 case VMSTATUSCHECK_SERVICE:
82 opObject = new VmStatuschecker();
84 case SNAPSHOT_SERVICE:
85 opObject = new CreateSnapshot();
88 opObject = new TerminateStack();
91 opObject = new SnapshotStack();
94 opObject = new RestoreStack();
97 opObject = new StartServer();
100 opObject = new StopServer();
102 case TERMINATE_SERVICE:
103 opObject = new TerminateServer();
106 opObject = new LookupServer();
108 case ATTACHVOLUME_SERVICE:
109 opObject = new AttachVolumeServer();
111 case DETACHVOLUME_SERVICE:
112 opObject = new DettachVolumeServer();
115 throw new APPCException("Unsupported provider operation.");
117 operations.put(op, opObject);