AT&T 1712 and 1802 release code
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / apihandlerinfra / tenantisolation / process / DeactivateVnfOperationalEnvironment.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.process;\r
22 \r
23 import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;\r
24 import org.openecomp.mso.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException;\r
25 import org.openecomp.mso.client.aai.entities.AAIResultWrapper;\r
26 import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;\r
27 import org.openecomp.mso.logger.MessageEnum;\r
28 import org.openecomp.mso.logger.MsoLogger;\r
29 \r
30 public class DeactivateVnfOperationalEnvironment extends OperationalEnvironmentProcess {\r
31 \r
32         private static final String SERVICE_NAME = "DeactivateVnfOperationalEnvironment"; \r
33         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);\r
34         private String className = this.getClass().getName();\r
35         \r
36         public DeactivateVnfOperationalEnvironment(CloudOrchestrationRequest request, String requestId) {\r
37                 super(request, requestId);\r
38                 MsoLogger.setServiceName (getRequestId());\r
39         MsoLogger.setLogContext(getRequestId(), getRequest().getOperationalEnvironmentId());\r
40         }\r
41 \r
42         @Override\r
43         public void execute() {\r
44                 String methodName = "deactivateOperationalEnvironment() method.";\r
45                 String classMethodMessage = className + " " + methodName;\r
46                 \r
47                 msoLogger.debug("Begin of execute method in " + SERVICE_NAME);          \r
48                 \r
49                 String operationalEnvironmentId = getRequest().getOperationalEnvironmentId();\r
50                 msoLogger.debug("Deactivate OperationalEnvironment on " + operationalEnvironmentId);\r
51                 try {\r
52                         msoLogger.debug("Start of AA&I Get client call in " + classMethodMessage);\r
53                         \r
54                         AAIResultWrapper aaiResult = getAaiHelper().getAaiOperationalEnvironment(operationalEnvironmentId);\r
55                         AAIOperationalEnvironment aaiOpEnv = aaiResult.asBean(AAIOperationalEnvironment.class).get();\r
56                         String operationalEnvironmentStatus = aaiOpEnv.getOperationalEnvironmentStatus();\r
57 \r
58                         msoLogger.debug("OperationalEnvironmentStatus is :" + operationalEnvironmentStatus);\r
59                         msoLogger.debug(" End of AA&I Get client call in " + classMethodMessage);\r
60                         \r
61                         if(operationalEnvironmentStatus == null) {\r
62                                 String error = "OperationalEnvironmentStatus is null on OperationalEnvironmentId: " + operationalEnvironmentId;\r
63                                 throw new TenantIsolationException(error);\r
64                         }\r
65                         \r
66                         if(operationalEnvironmentStatus.equalsIgnoreCase("ACTIVE")) {\r
67                                 msoLogger.debug("Start of AA&I UPDATE client call in " + classMethodMessage);\r
68                                 \r
69                                 aaiOpEnv.setOperationalEnvironmentStatus("INACTIVE");\r
70                                 getAaiHelper().updateAaiOperationalEnvironment(operationalEnvironmentId, aaiOpEnv);\r
71                                 \r
72                                 msoLogger.debug(" End of AA&I UPDATE client call in " + classMethodMessage);\r
73                         } else if(!operationalEnvironmentStatus.equalsIgnoreCase("INACTIVE")) {\r
74                                 String error = "Invalid OperationalEnvironmentStatus on OperationalEnvironmentId: " + operationalEnvironmentId;\r
75                                 throw new TenantIsolationException(error);\r
76                         }\r
77                         \r
78                         getRequestDb().updateInfraSuccessCompletion("SUCCESSFULLY Deactivated OperationalEnvironment", requestId, operationalEnvironmentId);\r
79                         \r
80                 } catch(Exception e) {\r
81                         msoLogger.error (MessageEnum.APIH_GENERAL_EXCEPTION, "", "", "", MsoLogger.ErrorCode.DataError, e.getMessage());\r
82                         getRequestDb().updateInfraFailureCompletion(e.getMessage(), requestId, operationalEnvironmentId);\r
83                 }\r
84                 \r
85                 msoLogger.debug("End of " + classMethodMessage);                \r
86         }\r
87         \r
88         @Override\r
89         protected String getServiceName() {\r
90                 return DeactivateVnfOperationalEnvironment.SERVICE_NAME;\r
91         }\r
92 }