Containerization feature of SO
[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  * 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.asdc.client.test.rest;
22
23
24 import java.io.IOException;
25
26 import javax.transaction.Transactional;
27 import javax.ws.rs.HeaderParam;
28 import javax.ws.rs.POST;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.Response;
33
34 import org.onap.so.asdc.client.ASDCController;
35 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
36 import org.onap.so.asdc.client.exceptions.ASDCParametersException;
37 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
38 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
39 import org.onap.so.asdc.client.test.emulators.JsonStatusData;
40 import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
41 import org.onap.so.logger.MessageEnum;
42 import org.onap.so.logger.MsoLogger;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.context.annotation.Profile;
45 import org.springframework.stereotype.Component;
46
47 /**
48  * 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 
49  * 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.
50  * 
51  * i.e. http://localhost:8080/asdc/treatNotification/v1
52  * 
53  * i.e. http://localhost:8080/asdc/statusData/v1
54  * 
55  * @author jm5423
56  *
57  */
58
59 @Path("/")
60 @Component
61 @Profile("test")
62 public class ASDCRestInterface {
63
64         private static DistributionClientEmulator distributionClientEmulator;
65         
66         private static JsonStatusData statusData;
67         
68         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ASDCRestInterface.class );
69         
70         @Autowired
71         private ASDCController asdcController;
72         
73         @Autowired
74         private ToscaResourceInstaller toscaInstaller;
75
76         @POST
77         @Path("/treatNotification/v1")
78         @Produces(MediaType.APPLICATION_JSON)
79         @Transactional
80         public Response invokeASDCService(NotificationDataImpl request, @HeaderParam("resource-location") String resourceLocation)
81                         throws ASDCControllerException, ASDCParametersException, IOException {
82                 distributionClientEmulator = new DistributionClientEmulator(resourceLocation);
83                 
84                 asdcController.setControllerName("asdc-controller1");
85                 asdcController.setDistributionClient(distributionClientEmulator);       
86                 asdcController.initASDC();      
87                 asdcController.treatNotification(request);
88                 asdcController.closeASDC();
89                 return Response.status(200).build();
90         }
91         
92         @POST
93         @Path("/statusData/v1")
94         @Produces(MediaType.APPLICATION_JSON)
95         @Transactional
96         public Response invokeASDCStatusData(String request) {
97                                 
98                 try{
99                         distributionClientEmulator = new DistributionClientEmulator("resource-examples/");
100                         statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
101                 
102                         ASDCController asdcController = new ASDCController("asdc-controller1", distributionClientEmulator);
103                         //LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "initASDC()");
104                         asdcController.initASDC();
105                         //LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "treatNotification()");
106                         toscaInstaller.installTheComponentStatus(statusData);
107                         //asdcController.treatNotification(notifDataWithoutModuleInfo);
108                         //LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "closeASDC()");
109                         asdcController.closeASDC();
110                 }catch(Exception e){
111                         System.out.println("Error caught " + e.getMessage());
112                         LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION,
113                                         "Exception caught during ASDCRestInterface", "ASDC", "invokeASDCService", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in invokeASDCService", e);
114                 }
115                 System.out.println("ASDC Updates are complete");
116                 LOGGER.info(MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC, statusData.getDistributionID(), "ASDC", "ASDC Updates Are Complete");
117                 
118                 return null;
119         }
120 }