* ============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.
* @param config configuration for this operation
* @param propertyNames names of properties required by this operation
*/
- public OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List<String> propertyNames) {
+ protected OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List<String> propertyNames) {
this.params = params;
this.config = config;
this.fullName = params.getActor() + "." + params.getOperation();
* @return the property value
*/
@SuppressWarnings("unchecked")
- protected <T> T getRequiredProperty(String name, String propertyType) {
+ public <T> T getRequiredProperty(String name, String propertyType) {
T value = (T) properties.get(name);
if (value == null) {
throw new IllegalStateException("missing " + propertyType);
/**
* 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
*/
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<OperationOutcome> controller = new PipelineControllerFuture<>();
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
} 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());
private Function<Throwable, OperationOutcome> 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
return futures[0];
}
- CompletableFuture.anyOf(futures).thenApply(outcome -> (OperationOutcome) outcome)
+ CompletableFuture.anyOf(futures).thenApply(OperationOutcome.class::cast)
.whenCompleteAsync(controller.delayedComplete(), params.getExecutor());
return controller;
* @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<OperationOutcome>[] attachFutures(PipelineControllerFuture<OperationOutcome> controller,
List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers,
UnaryOperator<CompletableFuture<OperationOutcome>> adorn) {
if (futureMakers.isEmpty()) {
- @SuppressWarnings("unchecked")
- CompletableFuture<OperationOutcome>[] result = new CompletableFuture[0];
- return result;
+ return new CompletableFuture[0];
}
// the last, unadorned future that is created
}
}
- @SuppressWarnings("unchecked")
- CompletableFuture<OperationOutcome>[] result = new CompletableFuture[futures.size()];
+ var result = new CompletableFuture[futures.size()];
if (result.length == 1) {
// special case - return the unadorned future
* executing
*/
final PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>();
- final Executor executor = params.getExecutor();
+ final var executor = params.getExecutor();
// @formatter:off
controller.wrap(nextTask)
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);
}
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.
*
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.
*