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;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.context.annotation.Scope;
41 import org.springframework.scheduling.annotation.Async;
42 import org.springframework.stereotype.Component;
46 public class TenantIsolationRunnable {
48 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, TenantIsolationRunnable.class);
51 private RequestsDBHelper requestDb;
53 private CreateEcompOperationalEnvironment createEcompOpEnv;
55 private CreateVnfOperationalEnvironment createVnfOpEnv;
57 private ActivateVnfOperationalEnvironment activateVnfOpEnv;
59 private DeactivateVnfOperationalEnvironment deactivateVnfOpEnv;
61 private ActivateVnfStatusOperationalEnvironment activateVnfStatusOpEnv;
64 public void run(Action action, String operationalEnvType, CloudOrchestrationRequest cor, String requestId) throws ApiException {
66 msoLogger.debug ("Starting threadExecution in TenantIsolationRunnable for Action " + action.name() + " and OperationalEnvType: " + operationalEnvType);
69 if(Action.create.equals(action)) {
70 if(OperationalEnvironment.ECOMP.name().equalsIgnoreCase(operationalEnvType)) {
71 createEcompOpEnv.execute(requestId, cor);
72 } else if(OperationalEnvironment.VNF.name().equalsIgnoreCase(operationalEnvType)) {
73 createVnfOpEnv.execute(requestId, cor);
75 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
76 ValidateException validateException = new ValidateException.Builder("Invalid OperationalEnvironment Type specified for Create Action",
77 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
79 throw validateException;
81 } else if(Action.activate.equals(action)) {
82 activateVnfOpEnv.execute(requestId, cor);
83 } else if(Action.deactivate.equals(action)) {
84 deactivateVnfOpEnv.execute(requestId, cor);
85 } else if(Action.distributionStatus.equals(action)) {
86 activateVnfStatusOpEnv.execute(requestId, cor);
88 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
89 ValidateException validateException = new ValidateException.Builder("Invalid Action specified: " + action,
90 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
91 throw validateException;
93 }catch(ApiException e) {
94 requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, cor.getOperationalEnvironmentId());