2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Modifications Copyright (C) 2021 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.clamp.controlloop.participant.dcae.httpclient;
25 import org.apache.http.HttpStatus;
26 import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ClampEndPoints;
27 import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
28 import org.onap.policy.clamp.controlloop.participant.dcae.model.ExternalComponent;
29 import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop;
30 import org.springframework.stereotype.Component;
33 public class ClampHttpClient extends AbstractHttpClient {
35 private final ClampEndPoints endPoints;
36 public static final String STATUS_NOT_FOUND = "STATUS_NOT_FOUND";
37 public static final String POLICY_NOT_FOUND = "POLICY_NOT_FOUND";
42 * @param parameters the DCAE parameters
44 public ClampHttpClient(ParticipantDcaeParameters parameters) {
45 super(parameters.getClampClientParameters());
46 this.endPoints = parameters.getClampClientEndPoints();
52 * @param loopName the loopName
53 * @param templateName the templateName
54 * @return the Loop object or null if error occurred
56 public Loop create(String loopName, String templateName) {
57 return executePost(String.format(endPoints.getCreate(), loopName, templateName), HttpStatus.SC_OK);
63 * @param loopName the loopName
66 public boolean deploy(String loopName) {
67 return executePut(endPoints.getDeploy() + loopName, HttpStatus.SC_ACCEPTED);
73 * @param loopName the loopName
74 * @return the Loop object or null if error occurred
76 public Loop getstatus(String loopName) {
77 return executeGet(endPoints.getStatus() + loopName, HttpStatus.SC_OK);
83 * @param loopName the loopName
86 public boolean undeploy(String loopName) {
87 return executePut(endPoints.getUndeploy() + loopName, HttpStatus.SC_ACCEPTED);
93 * @param loopName the loopName
96 public boolean stop(String loopName) {
97 return executePut(endPoints.getStop() + loopName, HttpStatus.SC_OK);
103 * @param loopName the loopName
106 public boolean delete(String loopName) {
107 return executePut(endPoints.getDelete() + loopName, HttpStatus.SC_OK);
111 * return status from Loop object.
116 public static String getStatusCode(Loop loop) {
117 if (loop == null || loop.getComponents() == null || loop.getComponents().isEmpty()) {
118 return STATUS_NOT_FOUND;
120 var externalComponent = loop.getComponents().get("DCAE");
121 if (externalComponent == null || externalComponent.getComponentState() == null) {
122 return STATUS_NOT_FOUND;
125 return externalComponent.getComponentState().getStateName();