2 * ============LICENSE_START=======================================================
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
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.sdnc;
23 import java.util.List;
25 import java.util.concurrent.CompletableFuture;
26 import javax.ws.rs.client.Entity;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
30 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
31 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
32 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
34 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
35 import org.onap.policy.sdnc.SdncRequest;
36 import org.onap.policy.sdnc.SdncResponse;
39 * Superclass for SDNC Operators.
41 public abstract class SdncOperation extends HttpOperation<SdncResponse> {
44 * Constructs the object.
46 * @param params operation parameters
47 * @param config configuration for this operation
48 * @param propertyNames names of properties required by this operation
50 public SdncOperation(ControlLoopOperationParams params, HttpConfig config, List<String> propertyNames) {
51 super(params, config, SdncResponse.class, propertyNames);
55 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
57 SdncRequest request = makeRequest(attempt);
59 Map<String, Object> headers = makeHeaders();
61 headers.put("Accept", MediaType.APPLICATION_JSON);
62 String path = getPath();
63 String url = getClient().getBaseUrl() + path;
65 String strRequest = prettyPrint(request);
66 logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
68 Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
71 return handleResponse(outcome, url,
72 callback -> getClient().post(callback, path, entity, headers));
79 * @param attempt current attempt, starting with "1"
80 * @return a new request to be posted
82 protected abstract SdncRequest makeRequest(int attempt);
85 * Checks that the response has an "output" and that the output indicates success.
88 protected boolean isSuccess(Response rawResponse, SdncResponse response) {
89 return response.getResponseOutput() != null && "200".equals(response.getResponseOutput().getResponseCode());