2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.asdc.client.test.rest;
26 import java.io.IOException;
27 import javax.transaction.Transactional;
28 import javax.ws.rs.HeaderParam;
29 import javax.ws.rs.POST;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
34 import org.onap.so.logger.LoggingAnchor;
35 import org.onap.so.asdc.client.ASDCController;
36 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
37 import org.onap.so.asdc.client.exceptions.ASDCParametersException;
38 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
39 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
40 import org.onap.so.asdc.client.test.emulators.JsonStatusData;
41 import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
42 import org.onap.so.logger.ErrorCode;
43 import org.onap.so.logger.MessageEnum;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.context.annotation.Profile;
48 import org.springframework.stereotype.Component;
51 * This is a TEST only rest interface. It is not used in production, it is used to aid in testing the ASDC service on
52 * jboss without the need to be connected to the ASDC service broker. It starts the test at the treatNotification step
53 * and simulates both the notification step as well as the artifact download step.
55 * i.e. http://localhost:8080/asdc/treatNotification/v1
57 * i.e. http://localhost:8080/asdc/statusData/v1
65 public class ASDCRestInterface {
67 private static final Logger logger = LoggerFactory.getLogger(ASDCRestInterface.class);
70 private ASDCController asdcController;
73 private ToscaResourceInstaller toscaInstaller;
76 @Path("/treatNotification/v1")
77 @Produces(MediaType.APPLICATION_JSON)
79 public Response invokeASDCService(NotificationDataImpl request,
80 @HeaderParam("resource-location") String resourceLocation)
81 throws ASDCControllerException, ASDCParametersException, IOException {
82 DistributionClientEmulator 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 distributionClientEmulator =
100 new DistributionClientEmulator("resource-examples/");
101 JsonStatusData statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
103 ASDCController controller = new ASDCController("asdc-controller1", distributionClientEmulator);
104 controller.initASDC();
105 toscaInstaller.installTheComponentStatus(statusData);
106 controller.closeASDC();
108 logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC.toString(),
109 statusData.getDistributionID(), "ASDC", "ASDC Updates Are Complete");
110 } catch (Exception e) {
111 logger.info("Error caught " + e.getMessage());
112 logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION.toString(),
113 "Exception caught during ASDCRestInterface", "ASDC", "invokeASDCService",
114 ErrorCode.BusinessProcesssError.getValue(), "Exception in invokeASDCService", e);