2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
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.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.apihandlerinfra.tenantisolation;
25 import org.apache.http.HttpStatus;
26 import org.onap.so.apihandler.common.ErrorNumbers;
27 import org.onap.so.apihandlerinfra.exceptions.ApiException;
28 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
29 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
30 import org.onap.so.apihandlerinfra.tenantisolation.process.ActivateVnfOperationalEnvironment;
31 import org.onap.so.apihandlerinfra.tenantisolation.process.ActivateVnfStatusOperationalEnvironment;
32 import org.onap.so.apihandlerinfra.tenantisolation.process.CreateEcompOperationalEnvironment;
33 import org.onap.so.apihandlerinfra.tenantisolation.process.CreateVnfOperationalEnvironment;
34 import org.onap.so.apihandlerinfra.tenantisolation.process.DeactivateVnfOperationalEnvironment;
35 import org.onap.so.apihandlerinfra.tenantisolationbeans.Action;
36 import org.onap.so.apihandlerinfra.tenantisolationbeans.OperationalEnvironment;
37 import org.onap.so.logger.MessageEnum;
38 import org.onap.so.logger.MsoLogger;
39 import org.onap.so.requestsdb.RequestsDBHelper;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.context.annotation.Scope;
44 import org.springframework.scheduling.annotation.Async;
45 import org.springframework.stereotype.Component;
49 public class TenantIsolationRunnable {
51 private static final Logger logger = LoggerFactory.getLogger(TenantIsolationRunnable.class);
54 private RequestsDBHelper requestDb;
56 private CreateEcompOperationalEnvironment createEcompOpEnv;
58 private CreateVnfOperationalEnvironment createVnfOpEnv;
60 private ActivateVnfOperationalEnvironment activateVnfOpEnv;
62 private DeactivateVnfOperationalEnvironment deactivateVnfOpEnv;
64 private ActivateVnfStatusOperationalEnvironment activateVnfStatusOpEnv;
67 public void run(Action action, String operationalEnvType, CloudOrchestrationRequest cor, String requestId) throws ApiException {
69 logger.debug("Starting threadExecution in TenantIsolationRunnable for Action {} and OperationalEnvType: {}",
70 action.name(), operationalEnvType);
73 if(Action.create.equals(action)) {
74 if(OperationalEnvironment.ECOMP.name().equalsIgnoreCase(operationalEnvType)) {
75 createEcompOpEnv.execute(requestId, cor);
76 } else if(OperationalEnvironment.VNF.name().equalsIgnoreCase(operationalEnvType)) {
77 createVnfOpEnv.execute(requestId, cor);
79 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
80 ValidateException validateException = new ValidateException.Builder("Invalid OperationalEnvironment Type specified for Create Action",
81 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo)
84 throw validateException;
86 } else if(Action.activate.equals(action)) {
87 activateVnfOpEnv.execute(requestId, cor);
88 } else if(Action.deactivate.equals(action)) {
89 deactivateVnfOpEnv.execute(requestId, cor);
90 } else if(Action.distributionStatus.equals(action)) {
91 activateVnfStatusOpEnv.execute(requestId, cor);
93 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
94 ValidateException validateException = new ValidateException.Builder("Invalid Action specified: " + action,
95 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
96 throw validateException;
98 }catch(ApiException e) {
99 requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, cor.getOperationalEnvironmentId());