2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.apihandlerinfra.tenantisolation;
23 import org.apache.http.HttpStatus;
24 import org.onap.so.apihandler.common.ErrorNumbers;
25 import org.onap.so.apihandlerinfra.exceptions.ApiException;
26 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
27 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
28 import org.onap.so.apihandlerinfra.tenantisolation.process.ActivateVnfOperationalEnvironment;
29 import org.onap.so.apihandlerinfra.tenantisolation.process.ActivateVnfStatusOperationalEnvironment;
30 import org.onap.so.apihandlerinfra.tenantisolation.process.CreateEcompOperationalEnvironment;
31 import org.onap.so.apihandlerinfra.tenantisolation.process.CreateVnfOperationalEnvironment;
32 import org.onap.so.apihandlerinfra.tenantisolation.process.DeactivateVnfOperationalEnvironment;
33 import org.onap.so.apihandlerinfra.tenantisolationbeans.Action;
34 import org.onap.so.apihandlerinfra.tenantisolationbeans.OperationalEnvironment;
35 import org.onap.so.logger.MessageEnum;
36 import org.onap.so.logger.MsoLogger;
37 import org.onap.so.requestsdb.RequestsDBHelper;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.Scope;
40 import org.springframework.scheduling.annotation.Async;
41 import org.springframework.stereotype.Component;
45 public class TenantIsolationRunnable {
47 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, TenantIsolationRunnable.class);
50 private RequestsDBHelper requestDb;
52 private CreateEcompOperationalEnvironment createEcompOpEnv;
54 private CreateVnfOperationalEnvironment createVnfOpEnv;
56 private ActivateVnfOperationalEnvironment activateVnfOpEnv;
58 private DeactivateVnfOperationalEnvironment deactivateVnfOpEnv;
60 private ActivateVnfStatusOperationalEnvironment activateVnfStatusOpEnv;
63 public void run(Action action, String operationalEnvType, CloudOrchestrationRequest cor, String requestId) throws ApiException {
64 msoLogger.debug ("Starting threadExecution in TenantIsolationRunnable for Action " + action.name() + " and OperationalEnvType: " + operationalEnvType);
67 if(Action.create.equals(action)) {
68 if(OperationalEnvironment.ECOMP.name().equalsIgnoreCase(operationalEnvType)) {
69 createEcompOpEnv.execute(requestId, cor);
70 } else if(OperationalEnvironment.VNF.name().equalsIgnoreCase(operationalEnvType)) {
71 createVnfOpEnv.execute(requestId, cor);
73 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
74 ValidateException validateException = new ValidateException.Builder("Invalid OperationalEnvironment Type specified for Create Action",
75 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
77 throw validateException;
79 } else if(Action.activate.equals(action)) {
80 activateVnfOpEnv.execute(requestId, cor);
81 } else if(Action.deactivate.equals(action)) {
82 deactivateVnfOpEnv.execute(requestId, cor);
83 } else if(Action.distributionStatus.equals(action)) {
84 activateVnfStatusOpEnv.execute(requestId, cor);
86 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
87 ValidateException validateException = new ValidateException.Builder("Invalid Action specified: " + action,
88 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
89 throw validateException;
91 }catch(ApiException e) {
92 requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, cor.getOperationalEnvironmentId());