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.logging.filter.base.ErrorCode;
38 import org.onap.so.logger.MessageEnum;
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)
70 logger.debug("Starting threadExecution in TenantIsolationRunnable for Action {} and OperationalEnvType: {}",
71 action.name(), operationalEnvType);
74 if (Action.create.equals(action)) {
75 if (OperationalEnvironment.ECOMP.name().equalsIgnoreCase(operationalEnvType)) {
76 createEcompOpEnv.execute(requestId, cor);
77 } else if (OperationalEnvironment.VNF.name().equalsIgnoreCase(operationalEnvType)) {
78 createVnfOpEnv.execute(requestId, cor);
80 ErrorLoggerInfo errorLoggerInfo =
81 new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError)
83 ValidateException validateException = new ValidateException.Builder(
84 "Invalid OperationalEnvironment Type specified for Create Action",
85 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo)
88 throw validateException;
90 } else if (Action.activate.equals(action)) {
91 activateVnfOpEnv.execute(requestId, cor);
92 } else if (Action.deactivate.equals(action)) {
93 deactivateVnfOpEnv.execute(requestId, cor);
94 } else if (Action.distributionStatus.equals(action)) {
95 activateVnfStatusOpEnv.execute(requestId, cor);
97 ErrorLoggerInfo errorLoggerInfo =
98 new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
99 ValidateException validateException =
100 new ValidateException.Builder("Invalid Action specified: " + action, HttpStatus.SC_BAD_REQUEST,
101 ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
102 throw validateException;
104 } catch (ApiException e) {
105 requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, cor.getOperationalEnvironmentId());