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