Removed MsoLogger class
[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  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.apihandlerinfra.tenantisolation.process;
24
25 import org.apache.http.HttpStatus;
26 import org.onap.so.apihandler.common.ErrorNumbers;
27 import org.onap.so.apihandlerinfra.exceptions.ApiException;
28 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
29 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
30 import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
31 import org.onap.so.apihandlerinfra.tenantisolation.dmaap.DmaapOperationalEnvClient;
32 import org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
33 import org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder;
34 import org.onap.so.logger.ErrorCode;
35 import org.onap.so.logger.MessageEnum;
36 import org.onap.so.requestsdb.RequestsDBHelper;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
41
42 @Component
43 public class CreateEcompOperationalEnvironment {
44         
45         private static Logger logger = LoggerFactory.getLogger(CreateEcompOperationalEnvironment.class);
46     
47         @Autowired 
48         private AAIClientObjectBuilder aaiClientObjectBuilder;
49         @Autowired 
50         private AAIClientHelper aaiHelper;
51         @Autowired 
52         private RequestsDBHelper requestDb;
53         @Autowired 
54         private DmaapOperationalEnvClient dmaapClient;
55
56         public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException{
57
58                 //Create ECOMP Managing Environment object in A&AI
59                         aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("ACTIVE", request));
60
61                         // Call client to publish to DMaap
62         try {
63                                         logger.debug("1 {}", request.getOperationalEnvironmentId());
64                                         logger.debug("2 {}", request.getRequestDetails().getRequestInfo().getInstanceName());
65                                         logger.debug("3 {}", request.getRequestDetails().getRequestParameters().getOperationalEnvironmentType()
66                                                 .toString());
67                                         logger.debug("4 {}", request.getRequestDetails().getRequestParameters().getTenantContext());
68                                         logger.debug("5 {}", request.getRequestDetails().getRequestParameters().getWorkloadContext());
69
70
71             dmaapClient.dmaapPublishOperationalEnvRequest(request.getOperationalEnvironmentId(),
72                     request.getRequestDetails().getRequestInfo().getInstanceName(),
73                     request.getRequestDetails().getRequestParameters().getOperationalEnvironmentType().toString(),
74                     request.getRequestDetails().getRequestParameters().getTenantContext(),
75                     request.getRequestDetails().getRequestParameters().getWorkloadContext(),
76                     "Create");
77         }catch(Exception e){
78             ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
79             ValidateException validateException = new ValidateException.Builder("Could not publish DMaap", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
80                     .errorInfo(errorLoggerInfo).build();
81             requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, request.getOperationalEnvironmentId());
82             throw validateException;
83         }
84                 //Update request database
85                 requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Created ECOMP OperationalEnvironment.", requestId, request.getOperationalEnvironmentId());
86
87         }
88 }