Containerization feature of SO
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / 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.onap.so.apihandlerinfra.tenantisolation.process;
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.CloudOrchestrationRequest;
29 import org.onap.so.apihandlerinfra.tenantisolation.dmaap.DmaapOperationalEnvClient;
30 import org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
31 import org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder;
32 import org.onap.so.logger.MessageEnum;
33 import org.onap.so.logger.MsoLogger;
34 import org.onap.so.requestsdb.RequestsDBHelper;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
37
38 @Component
39 public class CreateEcompOperationalEnvironment {
40         
41         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, CreateEcompOperationalEnvironment.class);
42     
43         @Autowired 
44         private AAIClientObjectBuilder aaiClientObjectBuilder;
45         @Autowired 
46         private AAIClientHelper aaiHelper;
47         @Autowired 
48         private RequestsDBHelper requestDb;
49         @Autowired 
50         private DmaapOperationalEnvClient dmaapClient;
51
52         public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException{
53
54                 //Create ECOMP Managing Environment object in A&AI
55                         aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("ACTIVE", request));
56
57                         // Call client to publish to DMaap
58         try {
59                 msoLogger.debug("1" + request.getOperationalEnvironmentId());
60                 msoLogger.debug("2" + request.getRequestDetails().getRequestInfo().getInstanceName());
61                 msoLogger.debug("3" + request.getRequestDetails().getRequestParameters().getOperationalEnvironmentType().toString());
62                 msoLogger.debug("4" + request.getRequestDetails().getRequestParameters().getTenantContext());
63                 msoLogger.debug("5" + request.getRequestDetails().getRequestParameters().getWorkloadContext());
64
65
66             dmaapClient.dmaapPublishOperationalEnvRequest(request.getOperationalEnvironmentId(),
67                     request.getRequestDetails().getRequestInfo().getInstanceName(),
68                     request.getRequestDetails().getRequestParameters().getOperationalEnvironmentType().toString(),
69                     request.getRequestDetails().getRequestParameters().getTenantContext(),
70                     request.getRequestDetails().getRequestParameters().getWorkloadContext(),
71                     "Create");
72         }catch(Exception e){
73             ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
74             ValidateException validateException = new ValidateException.Builder("Could not publish DMaap", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
75                     .errorInfo(errorLoggerInfo).build();
76             requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, request.getOperationalEnvironmentId());
77             throw validateException;
78         }
79                         //Update request database
80                         requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Created ECOMP OperationalEnvironment.", requestId, request.getOperationalEnvironmentId());
81
82         }
83 }