AT&T 1712 and 1802 release code
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / 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.openecomp.mso.apihandlerinfra.tenantisolation;\r
22 \r
23 import org.openecomp.mso.apihandlerinfra.Constants;\r
24 import org.openecomp.mso.apihandlerinfra.tenantisolation.process.OperationalEnvironmentProcess;\r
25 import org.openecomp.mso.apihandlerinfra.tenantisolationbeans.Action;\r
26 import org.openecomp.mso.logger.MessageEnum;\r
27 import org.openecomp.mso.logger.MsoLogger;\r
28 import org.openecomp.mso.requestsdb.RequestsDBHelper;\r
29 \r
30 public class TenantIsolationRunnable implements Runnable {\r
31 \r
32         private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);\r
33         private OperationalEnvironmentProcessFactory factory = null;\r
34         private Action action;\r
35         private String operationalEnvType;\r
36         private CloudOrchestrationRequest cor;\r
37         private String requestId;\r
38         protected RequestsDBHelper requestDb;\r
39 \r
40         @Override\r
41         public void run() {\r
42                 msoLogger.debug ("Starting threadExecution in TenantIsolationRunnable for Action " + action.name() + " and OperationalEnvType: " + operationalEnvType);\r
43                 try {\r
44                         OperationalEnvironmentProcess isolation = getFactory().getOperationalEnvironmentProcess(action, operationalEnvType, cor, requestId);\r
45                         isolation.execute();\r
46                 } catch(Exception e) {\r
47                         msoLogger.debug ("Exception during Thread initiation: ", e);\r
48                         msoLogger.error (MessageEnum.APIH_GENERAL_EXCEPTION, Constants.MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.UnknownError, null, e);\r
49                         getRequestDb().updateInfraFailureCompletion(e.getMessage(), requestId, cor.getOperationalEnvironmentId());\r
50                 }\r
51         }\r
52 \r
53         public Action getAction() {\r
54                 return action;\r
55         }\r
56 \r
57         public void setAction(Action action) {\r
58                 this.action = action;\r
59         }\r
60 \r
61         public String getOperationalEnvType() {\r
62                 return operationalEnvType;\r
63         }\r
64 \r
65         public void setOperationalEnvType(String operationalEnvType) {\r
66                 this.operationalEnvType = operationalEnvType;\r
67         }\r
68 \r
69         public CloudOrchestrationRequest getCor() {\r
70                 return cor;\r
71         }\r
72 \r
73         public void setCor(CloudOrchestrationRequest cor) {\r
74                 this.cor = cor;\r
75         }\r
76 \r
77         public String getRequestId() {\r
78                 return requestId;\r
79         }\r
80 \r
81         public void setRequestId(String requestId) {\r
82                 this.requestId = requestId;\r
83         }\r
84         \r
85         public OperationalEnvironmentProcessFactory getFactory() {\r
86                 if(factory == null) {\r
87                         factory = new OperationalEnvironmentProcessFactory();\r
88                 }\r
89                 return factory;\r
90         }\r
91 \r
92         public void setFactory(OperationalEnvironmentProcessFactory factory) {\r
93                 this.factory = factory;\r
94         }\r
95         \r
96         protected RequestsDBHelper getRequestDb() {\r
97                 if(requestDb == null) {\r
98                         requestDb = new RequestsDBHelper();\r
99                 }\r
100                 return requestDb;\r
101         }\r
102         \r
103         protected void setRequestsDBHelper(RequestsDBHelper helper) {\r
104                 this.requestDb = helper;\r
105         }\r
106 }\r