2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-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.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.vfc;
24 import java.util.concurrent.CompletableFuture;
25 import javax.ws.rs.client.Entity;
26 import javax.ws.rs.core.MediaType;
27 import org.apache.commons.lang3.tuple.Pair;
28 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
31 import org.onap.policy.vfc.VfcRequest;
33 public class Restart extends VfcOperation {
34 public static final String NAME = "Restart";
36 public Restart(ControlLoopOperationParams params, HttpConfig config) {
37 super(params, config);
41 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
43 // starting a whole new attempt - reset the count
46 Pair<String, VfcRequest> pair = makeRequest();
47 Entity<VfcRequest> entity = Entity.entity(pair.getRight(), MediaType.APPLICATION_JSON);
48 String path = getPath() + pair.getLeft();
49 String url = getClient().getBaseUrl() + path;
51 Map<String, Object> headers = makeHeaders();
52 headers.put("Accept", MediaType.APPLICATION_JSON);
54 return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers));
60 * @return a pair containing the request URL and the new request
62 protected Pair<String, VfcRequest> makeRequest() {
64 var request = super.constructVfcRequest();
65 String requestUrl = "/" + request.getNsInstanceId() + "/heal";
66 return Pair.of(requestUrl, request);