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;
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;
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;
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.
55 * i.e. http://localhost:8080/asdc/treatNotification/v1
57 * i.e. http://localhost:8080/asdc/statusData/v1
66 public class ASDCRestInterface {
68 private static DistributionClientEmulator distributionClientEmulator;
70 private static JsonStatusData statusData;
72 private static final Logger logger = LoggerFactory.getLogger(ASDCRestInterface.class );
75 private ASDCController asdcController;
78 private ToscaResourceInstaller toscaInstaller;
81 @Path("/treatNotification/v1")
82 @Produces(MediaType.APPLICATION_JSON)
84 public Response invokeASDCService(NotificationDataImpl request, @HeaderParam("resource-location") String resourceLocation)
85 throws ASDCControllerException, ASDCParametersException, IOException {
86 distributionClientEmulator = new DistributionClientEmulator(resourceLocation);
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();
97 @Path("/statusData/v1")
98 @Produces(MediaType.APPLICATION_JSON)
100 public Response invokeASDCStatusData(String request) {
103 distributionClientEmulator = new DistributionClientEmulator("resource-examples/");
104 statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
106 ASDCController asdcController = new ASDCController("asdc-controller1", distributionClientEmulator);
107 asdcController.initASDC();
108 toscaInstaller.installTheComponentStatus(statusData);
109 asdcController.closeASDC();
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);
116 logger.info("ASDC Updates are complete");
117 logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC.toString(), statusData.getDistributionID(), "ASDC",
118 "ASDC Updates Are Complete");