2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.asdc.client.test.rest;
24 import java.io.IOException;
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;
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;
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.
51 * i.e. http://localhost:8080/asdc/treatNotification/v1
53 * i.e. http://localhost:8080/asdc/statusData/v1
62 public class ASDCRestInterface {
64 private static DistributionClientEmulator distributionClientEmulator;
66 private static JsonStatusData statusData;
68 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ASDCRestInterface.class );
71 private ASDCController asdcController;
74 private ToscaResourceInstaller toscaInstaller;
77 @Path("/treatNotification/v1")
78 @Produces(MediaType.APPLICATION_JSON)
80 public Response invokeASDCService(NotificationDataImpl request, @HeaderParam("resource-location") String resourceLocation)
81 throws ASDCControllerException, ASDCParametersException, IOException {
82 distributionClientEmulator = new DistributionClientEmulator(resourceLocation);
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();
93 @Path("/statusData/v1")
94 @Produces(MediaType.APPLICATION_JSON)
96 public Response invokeASDCStatusData(String request) {
99 distributionClientEmulator = new DistributionClientEmulator("resource-examples/");
100 statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
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();
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);
115 System.out.println("ASDC Updates are complete");
116 LOGGER.info(MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC, statusData.getDistributionID(), "ASDC", "ASDC Updates Are Complete");