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.sdnc;
24 import jakarta.ws.rs.client.Entity;
25 import jakarta.ws.rs.core.MediaType;
26 import jakarta.ws.rs.core.Response;
27 import java.util.List;
29 import java.util.concurrent.CompletableFuture;
30 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
31 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
32 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
33 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
34 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
36 import org.onap.policy.sdnc.SdncRequest;
37 import org.onap.policy.sdnc.SdncResponse;
40 * Superclass for SDNC Operators.
42 public abstract class SdncOperation extends HttpOperation<SdncResponse> {
45 * Constructs the object.
47 * @param params operation parameters
48 * @param config configuration for this operation
49 * @param propertyNames names of properties required by this operation
51 protected SdncOperation(ControlLoopOperationParams params, HttpConfig config, List<String> propertyNames) {
52 super(params, config, SdncResponse.class, propertyNames);
56 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
58 SdncRequest request = makeRequest(attempt);
60 Map<String, Object> headers = makeHeaders();
62 headers.put("Accept", MediaType.APPLICATION_JSON);
63 String path = getPath();
64 String url = getClient().getBaseUrl() + path;
66 String strRequest = prettyPrint(request);
67 logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
69 Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
72 return handleResponse(outcome, url,
73 callback -> getClient().post(callback, path, entity, headers));
80 * @param attempt current attempt, starting with "1"
81 * @return a new request to be posted
83 protected abstract SdncRequest makeRequest(int attempt);
86 * Checks that the response has an "output" and that the output indicates success.
89 protected boolean isSuccess(Response rawResponse, SdncResponse response) {
90 return response.getResponseOutput() != null && "200".equals(response.getResponseOutput().getResponseCode());