Removed MsoLogger class
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / client / test / rest / ASDCRestInterface.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.asdc.client.test.rest;
24
25
26 import java.io.IOException;
27
28 import javax.transaction.Transactional;
29 import javax.ws.rs.HeaderParam;
30 import javax.ws.rs.POST;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response;
35
36 import org.onap.so.asdc.client.ASDCController;
37 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
38 import org.onap.so.asdc.client.exceptions.ASDCParametersException;
39 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
40 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
41 import org.onap.so.asdc.client.test.emulators.JsonStatusData;
42 import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
43 import org.onap.so.logger.ErrorCode;
44 import org.onap.so.logger.MessageEnum;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.context.annotation.Profile;
49 import org.springframework.stereotype.Component;
50
51 /**
52  * This is a TEST only rest interface.  It is not used in production, it is used to aid in testing the ASDC service on jboss without the need to be connected 
53  * to the ASDC service broker.  It starts the test at the treatNotification step and simulates both the notification step as well as the artifact download step.
54  * 
55  * i.e. http://localhost:8080/asdc/treatNotification/v1
56  * 
57  * i.e. http://localhost:8080/asdc/statusData/v1
58  * 
59  * @author jm5423
60  *
61  */
62
63 @Path("/")
64 @Component
65 @Profile("test")
66 public class ASDCRestInterface {
67
68         private static DistributionClientEmulator distributionClientEmulator;
69         
70         private static JsonStatusData statusData;
71         
72         private static final Logger logger = LoggerFactory.getLogger(ASDCRestInterface.class );
73         
74         @Autowired
75         private ASDCController asdcController;
76         
77         @Autowired
78         private ToscaResourceInstaller toscaInstaller;
79
80         @POST
81         @Path("/treatNotification/v1")
82         @Produces(MediaType.APPLICATION_JSON)
83         @Transactional
84         public Response invokeASDCService(NotificationDataImpl request, @HeaderParam("resource-location") String resourceLocation)
85                         throws ASDCControllerException, ASDCParametersException, IOException {
86                 distributionClientEmulator = new DistributionClientEmulator(resourceLocation);
87                 
88                 asdcController.setControllerName("asdc-controller1");
89                 asdcController.setDistributionClient(distributionClientEmulator);       
90                 asdcController.initASDC();      
91                 asdcController.treatNotification(request);
92                 asdcController.closeASDC();
93                 return Response.status(200).build();
94         }
95         
96         @POST
97         @Path("/statusData/v1")
98         @Produces(MediaType.APPLICATION_JSON)
99         @Transactional
100         public Response invokeASDCStatusData(String request) {
101                                 
102                 try{
103                         distributionClientEmulator = new DistributionClientEmulator("resource-examples/");
104                         statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
105                 
106                         ASDCController asdcController = new ASDCController("asdc-controller1", distributionClientEmulator);
107                         asdcController.initASDC();
108                         toscaInstaller.installTheComponentStatus(statusData);
109                         asdcController.closeASDC();
110                 }catch(Exception e){
111                         logger.info("Error caught " + e.getMessage());
112                         logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION.toString(),
113                                 "Exception caught during ASDCRestInterface", "ASDC", "invokeASDCService",
114                                 ErrorCode.BusinessProcesssError.getValue(), "Exception in invokeASDCService", e);
115                 }
116                 logger.info("ASDC Updates are complete");
117                 logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC.toString(), statusData.getDistributionID(), "ASDC",
118                         "ASDC Updates Are Complete");
119                 return null;
120         }
121 }