Update Logging
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / tenantisolation / TenantIsolationRunnable.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra.tenantisolation;
22
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.slf4j.MDC;
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;
43
44 @Component
45 @Scope("prototype")
46 public class TenantIsolationRunnable {
47
48         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, TenantIsolationRunnable.class);
49         
50         @Autowired 
51         private RequestsDBHelper requestDb; 
52         @Autowired 
53         private CreateEcompOperationalEnvironment createEcompOpEnv;
54         @Autowired 
55         private CreateVnfOperationalEnvironment createVnfOpEnv;
56         @Autowired 
57         private ActivateVnfOperationalEnvironment activateVnfOpEnv;
58         @Autowired 
59         private DeactivateVnfOperationalEnvironment deactivateVnfOpEnv;
60         @Autowired 
61         private ActivateVnfStatusOperationalEnvironment activateVnfStatusOpEnv;
62         
63         @Async
64         public void run(Action action, String operationalEnvType, CloudOrchestrationRequest cor, String requestId) throws ApiException {
65                 
66                 msoLogger.debug ("Starting threadExecution in TenantIsolationRunnable for Action " + action.name() + " and OperationalEnvType: " + operationalEnvType);
67                 try {
68                         
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);
74                                 } else {
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();
78
79                     throw validateException;
80                                 }
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);
87                         } else {
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;
92                         }
93                 }catch(ApiException e) {
94             requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, cor.getOperationalEnvironmentId());
95             throw e;
96         }
97         }
98 }
99