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;
 
  24 import java.util.concurrent.CompletableFuture;
 
  25 import javax.ws.rs.client.Entity;
 
  26 import javax.ws.rs.core.MediaType;
 
  27 import javax.ws.rs.core.Response;
 
  28 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 
  29 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
 
  30 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 
  31 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
 
  32 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 
  33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
 
  34 import org.onap.policy.sdnc.SdncRequest;
 
  35 import org.onap.policy.sdnc.SdncResponse;
 
  38  * Superclass for SDNC Operators.
 
  40 public abstract class SdncOperation extends HttpOperation<SdncResponse> {
 
  43      * Constructs the object.
 
  45      * @param params operation parameters
 
  46      * @param config configuration for this operation
 
  48     public SdncOperation(ControlLoopOperationParams params, HttpConfig config) {
 
  49         super(params, config, SdncResponse.class);
 
  56     protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
 
  57         return startGuardAsync();
 
  61     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
 
  63         SdncRequest request = makeRequest(attempt);
 
  64         outcome.setSubRequestId(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
 
  66         Entity<SdncRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
 
  68         Map<String, Object> headers = makeHeaders();
 
  70         headers.put("Accept", MediaType.APPLICATION_JSON);
 
  71         String path = getPath() + request.getUrl();
 
  72         String url = getClient().getBaseUrl() + path;
 
  74         logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
 
  77         return handleResponse(outcome, url,
 
  78             callback -> getClient().post(callback, path, entity, headers));
 
  85      * @param attempt current attempt, starting with "1"
 
  86      * @return a new request to be posted
 
  88     protected abstract SdncRequest makeRequest(int attempt);
 
  91      * Checks that the response has an "output" and that the output indicates success.
 
  94     protected boolean isSuccess(Response rawResponse, SdncResponse response) {
 
  95         return response.getResponseOutput() != null && "200".equals(response.getResponseOutput().getResponseCode());