Java 17 Upgrade
[policy/models.git] / models-interactions / model-actors / actor.vfc / src / main / java / org / onap / policy / controlloop / actor / vfc / Restart.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.vfc;
23
24 import jakarta.ws.rs.client.Entity;
25 import jakarta.ws.rs.core.MediaType;
26 import java.util.Map;
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;
33
34 public class Restart extends VfcOperation {
35     public static final String NAME = "Restart";
36
37     public Restart(ControlLoopOperationParams params, HttpConfig config) {
38         super(params, config);
39     }
40
41     @Override
42     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
43
44         // starting a whole new attempt - reset the count
45         resetPollCount();
46
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;
51
52         Map<String, Object> headers = makeHeaders();
53         headers.put("Accept", MediaType.APPLICATION_JSON);
54
55         return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers));
56     }
57
58     /**
59      * Makes a request.
60      *
61      * @return a pair containing the request URL and the new request
62      */
63     protected Pair<String, VfcRequest> makeRequest() {
64
65         var request = super.constructVfcRequest();
66         String requestUrl = "/" + request.getNsInstanceId() + "/heal";
67         return Pair.of(requestUrl, request);
68     }
69 }