2c5cf8eda4098d039b81244fb1202d5a91feed10
[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 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.vfc;
22
23 import java.util.concurrent.CompletableFuture;
24 import javax.ws.rs.client.Entity;
25 import javax.ws.rs.core.MediaType;
26 import org.apache.commons.lang3.tuple.Pair;
27 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
28 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
30 import org.onap.policy.vfc.VfcRequest;
31
32 public class Restart extends VfcOperation {
33     public static final String NAME = "VF Module Create";
34
35     public Restart(ControlLoopOperationParams params, HttpConfig config) {
36         super(params, config);
37     }
38
39     @Override
40     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
41
42         // starting a whole new attempt - reset the count
43         resetGetCount();
44
45         Pair<String, VfcRequest> pair = makeRequest();
46         Entity<VfcRequest> entity = Entity.entity(pair.getRight(), MediaType.APPLICATION_JSON);
47         String path = getPath() + pair.getLeft();
48         String url = getClient().getBaseUrl() + path;
49
50         return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, null));
51     }
52
53     /**
54      * Makes a request.
55      *
56      * @return a pair containing the request URL and the new request
57      */
58     protected Pair<String, VfcRequest> makeRequest() {
59
60         VfcRequest request = super.constructVfcRequest();
61         String requestUrl = "/ns/" + request.getNsInstanceId() + "/heal";
62         return Pair.of(requestUrl, request);
63     }
64 }