2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.dcae.httpclient;
23 import org.apache.http.HttpStatus;
24 import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ClampEndPoints;
25 import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
26 import org.onap.policy.clamp.controlloop.participant.dcae.model.ExternalComponent;
27 import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop;
28 import org.springframework.stereotype.Component;
31 public class ClampHttpClient extends AbstractHttpClient {
33 private final ClampEndPoints endPoints;
34 public static final String STATUS_NOT_FOUND = "STATUS_NOT_FOUND";
35 public static final String POLICY_NOT_FOUND = "POLICY_NOT_FOUND";
40 * @param parameters the DCAE parameters
42 public ClampHttpClient(ParticipantDcaeParameters parameters) {
43 super(parameters.getClampClientParameters());
44 this.endPoints = parameters.getClampClientEndPoints();
50 * @param loopName the loopName
51 * @param templateName the templateName
52 * @return the Loop object or null if error occurred
54 public Loop create(String loopName, String templateName) {
55 return executePost(String.format(endPoints.getCreate(), loopName, templateName), HttpStatus.SC_OK);
61 * @param loopName the loopName
64 public boolean deploy(String loopName) {
65 return executePut(endPoints.getDeploy() + loopName, HttpStatus.SC_ACCEPTED);
71 * @param loopName the loopName
72 * @return the Loop object or null if error occurred
74 public Loop getstatus(String loopName) {
75 return executeGet(endPoints.getStatus() + loopName, HttpStatus.SC_OK);
81 * @param loopName the loopName
84 public boolean undeploy(String loopName) {
85 return executePut(endPoints.getUndeploy() + loopName, HttpStatus.SC_ACCEPTED);
91 * @param loopName the loopName
94 public boolean stop(String loopName) {
95 return executePut(endPoints.getStop() + loopName, HttpStatus.SC_OK);
101 * @param loopName the loopName
104 public boolean delete(String loopName) {
105 return executePut(endPoints.getDelete() + loopName, HttpStatus.SC_OK);
109 * return status from Loop object.
114 public static String getStatusCode(Loop loop) {
115 if (loop == null || loop.getComponents() == null || loop.getComponents().isEmpty()) {
116 return STATUS_NOT_FOUND;
118 ExternalComponent externalComponent = loop.getComponents().get("DCAE");
119 if (externalComponent == null || externalComponent.getComponentState() == null) {
120 return STATUS_NOT_FOUND;
123 return externalComponent.getComponentState().getStateName();