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%2FOperationPartial.java;h=c19ad6c319c9d5de425b1f2b710430ec14d0ab6f;hb=49f07db935d114b72a44e446867b16262dd552aa;hp=e9f6b024c6ae33c2860dbb35fa0d325fc69361d1;hpb=ca468c57a4d09842f2608e32da74b30eba52d015;p=policy%2Fmodels.git diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index e9f6b024c..c19ad6c31 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,7 +118,7 @@ public abstract class OperationPartial implements Operation { * @param config configuration for this operation * @param propertyNames names of properties required by this operation */ - public OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List propertyNames) { + protected OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List propertyNames) { this.params = params; this.config = config; this.fullName = params.getActor() + "." + params.getOperation(); @@ -165,7 +165,7 @@ public abstract class OperationPartial implements Operation { * @return the property value */ @SuppressWarnings("unchecked") - protected T getRequiredProperty(String name, String propertyType) { + public T getRequiredProperty(String name, String propertyType) { T value = (T) properties.get(name); if (value == null) { throw new IllegalStateException("missing " + propertyType); @@ -217,7 +217,6 @@ public abstract class OperationPartial implements Operation { /** * Starts the operation attempt, without doing any retries. * - * @param params operation parameters * @param attempt attempt number, typically starting with 1 * @return a future that will return the result of a single operation attempt */ @@ -225,9 +224,9 @@ public abstract class OperationPartial implements Operation { logger.info("{}: start operation attempt {} for {}", getFullName(), attempt, params.getRequestId()); - final Executor executor = params.getExecutor(); - final OperationOutcome outcome = params.makeOutcome(getTargetEntity()); - final CallbackManager callbacks = new CallbackManager(); + final var executor = params.getExecutor(); + final var outcome = makeOutcome(); + final var callbacks = new CallbackManager(); // this operation attempt gets its own controller final PipelineControllerFuture controller = new PipelineControllerFuture<>(); @@ -357,7 +356,7 @@ public abstract class OperationPartial implements Operation { outcome = origOutcome; } else { logger.warn("{}: null outcome; treating as a failure for {}", getFullName(), params.getRequestId()); - outcome = this.setOutcome(params.makeOutcome(getTargetEntity()), OperationResult.FAILURE); + outcome = this.setOutcome(makeOutcome(), OperationResult.FAILURE); } // ensure correct actor/operation @@ -382,7 +381,7 @@ public abstract class OperationPartial implements Operation { } else { /* - * retries were specified and we've already tried them all - change to + * retries were specified, and we've already tried them all - change to * FAILURE_RETRIES */ logger.info("operation {} retries exhausted for {}", getFullName(), params.getRequestId()); @@ -456,7 +455,7 @@ public abstract class OperationPartial implements Operation { private Function fromException(String type) { return thrown -> { - OperationOutcome outcome = params.makeOutcome(getTargetEntity()); + OperationOutcome outcome = makeOutcome(); if (thrown instanceof CancellationException || thrown.getCause() instanceof CancellationException) { // do not include exception in the message, as it just clutters the log @@ -518,7 +517,7 @@ public abstract class OperationPartial implements Operation { return futures[0]; } - CompletableFuture.anyOf(futures).thenApply(outcome -> (OperationOutcome) outcome) + CompletableFuture.anyOf(futures).thenApply(OperationOutcome.class::cast) .whenCompleteAsync(controller.delayedComplete(), params.getExecutor()); return controller; @@ -594,14 +593,13 @@ public abstract class OperationPartial implements Operation { * @return an array of futures, possibly zero-length. If the array is of size one, * then that one item should be returned instead of the controller */ + @SuppressWarnings("unchecked") private CompletableFuture[] attachFutures(PipelineControllerFuture controller, List>> futureMakers, UnaryOperator> adorn) { if (futureMakers.isEmpty()) { - @SuppressWarnings("unchecked") - CompletableFuture[] result = new CompletableFuture[0]; - return result; + return new CompletableFuture[0]; } // the last, unadorned future that is created @@ -631,8 +629,7 @@ public abstract class OperationPartial implements Operation { } } - @SuppressWarnings("unchecked") - CompletableFuture[] result = new CompletableFuture[futures.size()]; + var result = new CompletableFuture[futures.size()]; if (result.length == 1) { // special case - return the unadorned future @@ -747,7 +744,7 @@ public abstract class OperationPartial implements Operation { * executing */ final PipelineControllerFuture controller = new PipelineControllerFuture<>(); - final Executor executor = params.getExecutor(); + final var executor = params.getExecutor(); // @formatter:off controller.wrap(nextTask) @@ -830,7 +827,7 @@ public abstract class OperationPartial implements Operation { outcome.setEnd(null); // pass a copy to the callback - OperationOutcome outcome2 = new OperationOutcome(outcome); + var outcome2 = new OperationOutcome(outcome); outcome2.setFinalOutcome(false); params.callbackStarted(outcome2); } @@ -892,6 +889,18 @@ public abstract class OperationPartial implements Operation { return operation; } + /** + * Makes an outcome, populating the "target" field with the contents of the target + * entity property. + * + * @return a new operation outcome + */ + protected OperationOutcome makeOutcome() { + OperationOutcome outcome = params.makeOutcome(); + outcome.setTarget(getProperty(OperationProperties.AAI_TARGET_ENTITY)); + return outcome; + } + /** * Determines if a throwable is due to a timeout. * @@ -975,16 +984,6 @@ public abstract class OperationPartial implements Operation { return DEFAULT_RETRY_WAIT_MS; } - /** - * Gets the target entity, first trying the properties and then the parameters. - * - * @return the target entity - */ - protected String getTargetEntity() { - String targetEntity = getProperty(OperationProperties.AAI_TARGET_ENTITY); - return (targetEntity != null ? targetEntity : params.getTargetEntity()); - } - /** * Gets the operation timeout. *