X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-actors%2FactorServiceProvider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontrolloop%2Factorserviceprovider%2Fimpl%2FHttpOperation.java;h=1e11bce4c80e0ddc7e740409f3e2cc5d6aa42b03;hb=938005505883cf7a636a8840e20e3dc8a0ad9176;hp=4800b3a4b8c15918754bf8c6f53a5d728a1c71fa;hpb=e9af3a2b3a430626c740b18ccf8592706db1dfb1;p=policy%2Fmodels.git diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java index 4800b3a4b..1e11bce4c 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java @@ -2,7 +2,8 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +21,15 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; +import jakarta.ws.rs.client.InvocationCallback; +import jakarta.ws.rs.core.Response; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.function.Function; -import javax.ws.rs.client.InvocationCallback; -import javax.ws.rs.core.Response; import lombok.Getter; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.http.client.HttpClient; @@ -36,12 +37,12 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; -import org.onap.policy.controlloop.policy.PolicyResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,9 +91,11 @@ public abstract class HttpOperation extends OperationPartial { * @param params operation parameters * @param config configuration for this operation * @param clazz response class + * @param propertyNames names of properties required by this operation */ - public HttpOperation(ControlLoopOperationParams params, HttpConfig config, Class clazz) { - super(params, config); + protected HttpOperation(ControlLoopOperationParams params, HttpConfig config, Class clazz, + List propertyNames) { + super(params, config, propertyNames); this.config = config; this.responseClass = clazz; } @@ -179,7 +182,7 @@ public abstract class HttpOperation extends OperationPartial { final PipelineControllerFuture controller = new PipelineControllerFuture<>(); final CompletableFuture future = new CompletableFuture<>(); - final Executor executor = params.getExecutor(); + final var executor = params.getExecutor(); // arrange for the callback to complete "future" InvocationCallback callback = new InvocationCallback<>() { @@ -212,7 +215,7 @@ public abstract class HttpOperation extends OperationPartial { * * @param outcome outcome to be populate * @param url URL to which to request was sent - * @param response raw response to process + * @param rawResponse raw response to process * @return a future to cancel or await the outcome */ protected CompletableFuture processResponse(OperationOutcome outcome, String url, @@ -240,11 +243,12 @@ public abstract class HttpOperation extends OperationPartial { if (!isSuccess(rawResponse, response)) { logger.info("{}.{} request failed with http error code {} for {}", params.getActor(), params.getOperation(), rawResponse.getStatus(), params.getRequestId()); - return CompletableFuture.completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); + return CompletableFuture.completedFuture( + setOutcome(outcome, OperationResult.FAILURE, rawResponse, response)); } logger.info("{}.{} request succeeded for {}", params.getActor(), params.getOperation(), params.getRequestId()); - setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response); + setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response); return postProcessResponse(outcome, url, rawResponse, response); } @@ -257,7 +261,7 @@ public abstract class HttpOperation extends OperationPartial { * @param response decoded response * @return the updated operation */ - public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response rawResponse, + public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, Response rawResponse, T response) { outcome.setResponse(response); @@ -285,32 +289,29 @@ public abstract class HttpOperation extends OperationPartial { HttpPollingConfig cfg = (HttpPollingConfig) config; switch (detmStatus(rawResponse, response)) { - case SUCCESS: + case SUCCESS -> { logger.info("{}.{} request succeeded for {}", params.getActor(), params.getOperation(), - params.getRequestId()); + params.getRequestId()); return CompletableFuture - .completedFuture(setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response)); - - case FAILURE: + .completedFuture(setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response)); + } + case FAILURE -> { logger.info("{}.{} request failed for {}", params.getActor(), params.getOperation(), - params.getRequestId()); + params.getRequestId()); return CompletableFuture - .completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); - - case STILL_WAITING: - default: - logger.info("{}.{} request incomplete for {}", params.getActor(), params.getOperation(), - params.getRequestId()); - break; + .completedFuture(setOutcome(outcome, OperationResult.FAILURE, rawResponse, response)); + } + default -> logger.info("{}.{} request incomplete for {}", params.getActor(), params.getOperation(), + params.getRequestId()); } // still incomplete // see if the limit for the number of polls has been reached if (pollCount++ >= cfg.getMaxPolls()) { - logger.warn("{}: execeeded 'poll' limit {} for {}", getFullName(), cfg.getMaxPolls(), + logger.warn("{}: exceeded 'poll' limit {} for {}", getFullName(), cfg.getMaxPolls(), params.getRequestId()); - setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT); + setOutcome(outcome, OperationResult.FAILURE_TIMEOUT); return CompletableFuture.completedFuture(outcome); }