2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.actor.vfc;
24 import jakarta.ws.rs.client.Entity;
25 import jakarta.ws.rs.core.MediaType;
27 import java.util.concurrent.CompletableFuture;
28 import org.apache.commons.lang3.tuple.Pair;
29 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
32 import org.onap.policy.vfc.VfcRequest;
34 public class Restart extends VfcOperation {
35 public static final String NAME = "Restart";
37 public Restart(ControlLoopOperationParams params, HttpConfig config) {
38 super(params, config);
42 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
44 // starting a whole new attempt - reset the count
47 Pair<String, VfcRequest> pair = makeRequest();
48 Entity<VfcRequest> entity = Entity.entity(pair.getRight(), MediaType.APPLICATION_JSON);
49 String path = getPath() + pair.getLeft();
50 String url = getClient().getBaseUrl() + path;
52 Map<String, Object> headers = makeHeaders();
53 headers.put("Accept", MediaType.APPLICATION_JSON);
55 return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers));
61 * @return a pair containing the request URL and the new request
63 protected Pair<String, VfcRequest> makeRequest() {
65 var request = super.constructVfcRequest();
66 String requestUrl = "/" + request.getNsInstanceId() + "/heal";
67 return Pair.of(requestUrl, request);