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.model.ExternalComponent;
25 import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop;
26 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class ClampHttpClient extends AbstractHttpClient {
32 private static final Logger LOGGER = LoggerFactory.getLogger(ClampHttpClient.class);
34 private static final String STATUS = "/restservices/clds/v2/loop/getstatus/";
35 private static final String CREATE = "/restservices/clds/v2/loop/create/%s?templateName=%s";
36 private static final String UPDATE = "/restservices/clds/v2/loop/updateMicroservicePolicy/";
37 private static final String DEPLOY = "/restservices/clds/v2/loop/deploy/";
38 private static final String STOP = "/restservices/clds/v2/loop/stop/";
39 private static final String DELETE = "/restservices/clds/v2/loop/delete/";
40 private static final String UNDEPLOY = "/restservices/clds/v2/loop/undeploy/";
41 public static final String STATUS_NOT_FOUND = "STATUS_NOT_FOUND";
42 public static final String POLICY_NOT_FOUND = "POLICY_NOT_FOUND";
47 public ClampHttpClient(RestServerParameters restServerParameters) {
48 super(restServerParameters);
54 * @param loopName the loopName
55 * @param templateName the templateName
56 * @return the Loop object or null if error occurred
58 public Loop create(String loopName, String templateName) {
59 return executePost(String.format(CREATE, loopName, templateName), HttpStatus.SC_OK);
65 * @param loopName the loopName
66 * @param jsonEntity the Json entity
69 public boolean update(String loopName, String jsonEntity) {
70 return executePost(UPDATE + loopName, HttpStatus.SC_OK) != null;
76 * @param loopName the loopName
79 public boolean deploy(String loopName) { // DCAE
80 return executePut(DEPLOY + loopName, HttpStatus.SC_ACCEPTED);
86 * @param loopName the loopName
87 * @return the Loop object or null if error occurred
89 public Loop getstatus(String loopName) {
90 return executeGet(STATUS + loopName, HttpStatus.SC_OK);
96 * @param loopName the loopName
99 public boolean undeploy(String loopName) {
100 return executePut(UNDEPLOY + loopName, HttpStatus.SC_ACCEPTED);
106 * @param loopName the loopName
109 public boolean stop(String loopName) {
110 return executePut(STOP + loopName, HttpStatus.SC_OK);
116 * @param loopName the loopName
119 public boolean delete(String loopName) {
120 return executePut(DELETE + loopName, HttpStatus.SC_OK);
124 * return status from Loop object.
129 public static String getStatusCode(Loop loop) {
130 if (loop == null || loop.getComponents() == null || loop.getComponents().isEmpty()) {
131 return STATUS_NOT_FOUND;
133 ExternalComponent externalComponent = loop.getComponents().get("DCAE");
134 if (externalComponent == null || externalComponent.getComponentState() == null) {
135 return STATUS_NOT_FOUND;
138 return externalComponent.getComponentState().getStateName();