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 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 import javax.ws.rs.core.Response.Status;
34 import org.onap.so.asdc.client.ASDCController;
35 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
36 import org.onap.so.asdc.client.test.emulators.JsonStatusData;
37 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
38 import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
39 import org.onap.so.logger.ErrorCode;
40 import org.onap.so.logger.LoggingAnchor;
41 import org.onap.so.logger.MessageEnum;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.context.annotation.Profile;
46 import org.springframework.stereotype.Component;
49 * This is a TEST only rest interface. It is not used in production, it is used to aid in testing the ASDC service
50 * without the need to be connected to the ASDC service broker. It starts the test at the treatNotification step and
51 * simulates both the notification step as well as the artifact download step.
53 * i.e. http://localhost:8085/test/treatNotification/v1
55 * i.e. http://localhost:8085/test/statusData/v1
57 * This interface is also used in CSIT to simulate a distribution of a service, without using SDC
65 public class ASDCRestInterface {
67 private static final Logger logger = LoggerFactory.getLogger(ASDCRestInterface.class);
69 private final ASDCController asdcController;
71 private final ToscaResourceInstaller toscaInstaller;
74 public ASDCRestInterface(final ASDCController asdcController, final ToscaResourceInstaller toscaInstaller) {
75 this.asdcController = asdcController;
76 this.toscaInstaller = toscaInstaller;
80 @Path("/treatNotification/v1")
81 @Produces(MediaType.APPLICATION_JSON)
83 public Response invokeASDCService(final NotificationDataImpl request,
84 @HeaderParam("resource-location") final String resourceLocation) {
87 logger.info("Received message : {}", request);
88 logger.info("resource-location : {}", resourceLocation);
89 final DistributionClientEmulator distributionClientEmulator =
90 getDistributionClientEmulator(resourceLocation);
92 asdcController.setControllerName("asdc-controller1");
93 asdcController.setDistributionClient(distributionClientEmulator);
95 if (asdcController.isStopped()) {
96 logger.info("{} not running will try to initialize it, currrent status: {}",
97 asdcController.getClass().getName(), asdcController.getControllerStatus());
98 asdcController.initASDC();
101 asdcController.treatNotification(request);
103 if (!asdcController.isBusy()) {
104 asdcController.closeASDC();
107 return Response.status(Status.OK).build();
108 } catch (final Exception exception) {
109 logger.error("Unable to process notification request", exception);
110 return Response.status(Status.INTERNAL_SERVER_ERROR).build();
115 private DistributionClientEmulator getDistributionClientEmulator(final String resourceLocation) {
116 return new DistributionClientEmulator(resourceLocation);
120 @Path("/statusData/v1")
121 @Produces(MediaType.APPLICATION_JSON)
123 public Response invokeASDCStatusData(final String request) {
126 final DistributionClientEmulator distributionClientEmulator =
127 getDistributionClientEmulator("resource-examples/");
128 final JsonStatusData statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
130 asdcController.setDistributionClient(distributionClientEmulator);
131 asdcController.initASDC();
132 toscaInstaller.installTheComponentStatus(statusData);
133 asdcController.closeASDC();
135 logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC.toString(),
136 statusData.getDistributionID(), "ASDC", "ASDC Updates Are Complete");
137 } catch (final Exception e) {
138 logger.info("Error caught " + e.getMessage());
139 logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION.toString(),
140 "Exception caught during ASDCRestInterface", "ASDC", "invokeASDCService",
141 ErrorCode.BusinessProcesssError.getValue(), "Exception in invokeASDCService", e);