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 / CreateEcompOperationalEnvironment.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;
22
23 import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
24 import org.openecomp.mso.apihandlerinfra.tenantisolation.dmaap.DmaapOperationalEnvClient;
25 import org.openecomp.mso.logger.MessageEnum;
26 import org.openecomp.mso.logger.MsoLogger;
27
28
29 public class CreateEcompOperationalEnvironment extends OperationalEnvironmentProcess {
30         
31         private static final String SERVICE_NAME = "CreateEcompOperationalEnvironment";
32         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
33         
34         
35         public CreateEcompOperationalEnvironment(CloudOrchestrationRequest request, String requestId) {
36                 super(request, requestId);
37         MsoLogger.setServiceName (getRequestId());
38         MsoLogger.setLogContext(getRequestId(), getRequest().getOperationalEnvironmentId());
39         }
40
41         
42         protected DmaapOperationalEnvClient getDmaapClient() {
43                 return new DmaapOperationalEnvClient();
44         }
45
46
47         @Override
48         public void execute() {
49                 try {
50                         msoLogger.debug("Begin of execute method in " + SERVICE_NAME);
51                         msoLogger.debug("CloudOrchestrationRequest: " + request.toString());
52                         
53                         //Create ECOMP Managing Environment object in A&AI
54                         getAaiHelper().createOperationalEnvironment(getAaiClientObjectBuilder().buildAAIOperationalEnvironment("ACTIVE"));
55                         msoLogger.debug("ECOMP operational environment created in A&AI.");
56                                         
57                         // Call client to publish to DMaap      
58                         getDmaapClient().dmaapPublishOperationalEnvRequest(getRequest().getOperationalEnvironmentId(), 
59                                         getRequest().getRequestDetails().getRequestInfo().getInstanceName(),
60                                         getRequest().getRequestDetails().getRequestParameters().getOperationalEnvironmentType().toString(),
61                                         getRequest().getRequestDetails().getRequestParameters().getTenantContext(),
62                                         getRequest().getRequestDetails().getRequestParameters().getWorkloadContext(),
63                                         "Create");
64                         msoLogger.debug("ECOMP operational environment published in Dmaap/ASDC.");
65                 
66                         //Update request database
67                         getRequestDb().updateInfraSuccessCompletion("SUCCESSFULLY Created ECOMP OperationalEnvironment.", getRequestId(), getRequest().getOperationalEnvironmentId()); 
68                 } 
69                 catch (Exception e) {
70                         e.printStackTrace();
71                         msoLogger.error(MessageEnum.APIH_GENERAL_EXCEPTION, "", "", "", MsoLogger.ErrorCode.UnknownError, e.getMessage());
72                         getRequestDb().updateInfraFailureCompletion(e.getMessage(), getRequestId(), getRequest().getOperationalEnvironmentId());
73                 }       
74         }
75
76
77         @Override
78         protected String getServiceName() {
79                 return CreateEcompOperationalEnvironment.SERVICE_NAME;
80         }
81         
82 }