aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/pom.xml3
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java8
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/OpenTelConfiguration.java6
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivator.java3
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java189
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/AcRuntimeParameterGroup.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/Topics.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java60
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java143
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcPreparePublisher.java78
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java20
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java4
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantStatusReqPublisher.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java2
-rw-r--r--runtime-acm/src/main/resources/application.yaml9
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java57
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java38
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/TestOpenTelemetry.java47
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java268
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java80
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/PrometheusNoAuthTest.java32
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java8
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java81
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java41
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java24
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java44
-rw-r--r--runtime-acm/src/test/resources/application-prometheus-noauth.yaml31
-rw-r--r--runtime-acm/src/test/resources/application-test.yaml57
-rw-r--r--runtime-acm/src/test/resources/application-tracing.yaml27
-rw-r--r--runtime-acm/src/test/resources/rest/acm/AutomationCompositionMigrate.json30
-rwxr-xr-xruntime-acm/src/test/resources/testscripts/listenOnTopic.sh31
34 files changed, 947 insertions, 486 deletions
diff --git a/runtime-acm/pom.xml b/runtime-acm/pom.xml
index 1110b3a6c..82283eaf7 100644
--- a/runtime-acm/pom.xml
+++ b/runtime-acm/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.clamp</groupId>
<artifactId>policy-clamp</artifactId>
- <version>8.0.0-SNAPSHOT</version>
+ <version>8.0.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-runtime-acm</artifactId>
@@ -139,7 +139,6 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
- <version>${version.jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java
index 084f7c774..f5c8368e2 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/MetricsConfiguration.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.runtime.config;
import io.micrometer.core.aop.TimedAspect;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,8 +35,9 @@ public class MetricsConfiguration {
* Load up the metrics registry.
*/
@Bean
- public InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor,
- MeterRegistry registry) {
+ public InitializingBean forcePrometheusPostProcessor(@Qualifier("meterRegistryPostProcessor")
+ BeanPostProcessor meterRegistryPostProcessor,
+ MeterRegistry registry) {
return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/OpenTelConfiguration.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/OpenTelConfiguration.java
index 3727333a4..05d47d4f7 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/OpenTelConfiguration.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/OpenTelConfiguration.java
@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
public class OpenTelConfiguration {
@Bean
- @ConditionalOnProperty(prefix = "tracing", name = "enabled", havingValue = "true", matchIfMissing = false)
+ @ConditionalOnProperty(prefix = "tracing", name = "enabled", havingValue = "true")
@ConditionalOnExpression("'http'.equals('${tracing.exporter.protocol}')")
OtlpHttpSpanExporter otlpHttpSpanExporter(@Value("${tracing.exporter.endpoint:http://jaeger:4318/v1/traces}") String url) {
return OtlpHttpSpanExporter.builder()
@@ -44,7 +44,7 @@ public class OpenTelConfiguration {
}
@Bean
- @ConditionalOnProperty(prefix = "tracing", name = "enabled", havingValue = "true", matchIfMissing = false)
+ @ConditionalOnProperty(prefix = "tracing", name = "enabled", havingValue = "true")
@ConditionalOnExpression("'grpc'.equals('${tracing.exporter.protocol}')")
OtlpGrpcSpanExporter otlpGrpcSpanExporter(@Value("${tracing.exporter.endpoint:http://jaeger:4317}") String url) {
return OtlpGrpcSpanExporter.builder()
@@ -53,7 +53,7 @@ public class OpenTelConfiguration {
}
@Bean
- @ConditionalOnProperty(prefix = "tracing", name = "enabled", havingValue = "true", matchIfMissing = false)
+ @ConditionalOnProperty(prefix = "tracing", name = "enabled", havingValue = "true")
JaegerRemoteSampler jaegerRemoteSampler(
@Value("${tracing.sampler.jaeger-remote.endpoint:http://jaeger:14250}") String url,
@Value("${SERVICE_ID:unknown_service}") String serviceId) {
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivator.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivator.java
index a3e55c3f7..ff1f60b69 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivator.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivator.java
@@ -22,7 +22,6 @@
package org.onap.policy.clamp.acm.runtime.config.messaging;
import java.io.Closeable;
-import java.io.IOException;
import java.util.List;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
@@ -139,7 +138,7 @@ public class MessageDispatcherActivator extends ServiceManagerContainer implemen
}
@Override
- public void close() throws IOException {
+ public void close() {
if (isAlive()) {
super.shutdown();
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 2bf08220a..51b7b714c 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -22,8 +22,8 @@
package org.onap.policy.clamp.acm.runtime.instantiation;
import jakarta.validation.Valid;
-import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
+import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.NonNull;
@@ -37,8 +37,12 @@ import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.SubOrder;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
@@ -47,6 +51,7 @@ import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.slf4j.Logger;
@@ -62,6 +67,7 @@ import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
public class AutomationCompositionInstantiationProvider {
private static final String DO_NOT_MATCH = " do not match with ";
+ private static final String ELEMENT_ID_NOT_PRESENT = "Element id not present ";
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionInstantiationProvider.class);
@@ -82,19 +88,19 @@ public class AutomationCompositionInstantiationProvider {
public InstantiationResponse createAutomationComposition(UUID compositionId,
AutomationComposition automationComposition) {
if (!compositionId.equals(automationComposition.getCompositionId())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
var checkAutomationCompositionOpt =
automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier());
if (checkAutomationCompositionOpt.isPresent()) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
automationComposition.getKey().asIdentifier() + " already defined");
}
var validationResult = validateAutomationComposition(automationComposition);
if (!validationResult.isValid()) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, validationResult.getResult());
}
automationComposition = automationCompositionProvider.createAutomationComposition(automationComposition);
@@ -120,7 +126,7 @@ public class AutomationCompositionInstantiationProvider {
var instanceId = automationComposition.getInstanceId();
var acToUpdate = automationCompositionProvider.getAutomationComposition(instanceId);
if (!compositionId.equals(acToUpdate.getCompositionId())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
if (DeployState.UNDEPLOYED.equals(acToUpdate.getDeployState())) {
@@ -131,22 +137,42 @@ public class AutomationCompositionInstantiationProvider {
acToUpdate.setDerivedFrom(automationComposition.getDerivedFrom());
var validationResult = validateAutomationComposition(acToUpdate);
if (!validationResult.isValid()) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, validationResult.getResult());
}
automationComposition = automationCompositionProvider.updateAutomationComposition(acToUpdate);
return createInstantiationResponse(automationComposition);
- } else if ((DeployState.DEPLOYED.equals(acToUpdate.getDeployState())
- || DeployState.UPDATING.equals(acToUpdate.getDeployState()))
- && LockState.LOCKED.equals(acToUpdate.getLockState())) {
- if (automationComposition.getCompositionTargetId() != null) {
- return migrateAutomationComposition(automationComposition, acToUpdate);
+ }
+
+ if (automationComposition.getRestarting() != null) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Update not allowed");
+ }
+
+ var deployOrder = DeployOrder.UPDATE;
+ var subOrder = SubOrder.NONE;
+
+ if (automationComposition.getCompositionTargetId() != null) {
+
+ if (Boolean.TRUE.equals(automationComposition.getPrecheck())) {
+ subOrder = SubOrder.MIGRATE_PRECHECK;
+ deployOrder = DeployOrder.NONE;
} else {
- return updateDeployedAutomationComposition(automationComposition, acToUpdate);
+ deployOrder = DeployOrder.MIGRATE;
}
}
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
- "Not allowed to update in the state " + acToUpdate.getDeployState());
+ var result = acInstanceStateResolver.resolve(deployOrder, LockOrder.NONE, subOrder,
+ acToUpdate.getDeployState(), acToUpdate.getLockState(), acToUpdate.getSubState(),
+ acToUpdate.getStateChangeResult());
+ return switch (result) {
+ case "UPDATE" -> updateDeployedAutomationComposition(automationComposition, acToUpdate);
+
+ case "MIGRATE" -> migrateAutomationComposition(automationComposition, acToUpdate);
+
+ case "MIGRATE_PRECHECK" -> migratePrecheckAc(automationComposition, acToUpdate);
+
+ default -> throw new PfModelRuntimeException(Status.BAD_REQUEST,
+ "Not allowed to " + deployOrder + " in the state " + acToUpdate.getDeployState());
+ };
}
/**
@@ -164,17 +190,14 @@ public class AutomationCompositionInstantiationProvider {
var elementId = element.getKey();
var dbAcElement = acToBeUpdated.getElements().get(elementId);
if (dbAcElement == null) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Element id not present " + elementId);
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, ELEMENT_ID_NOT_PRESENT + elementId);
}
AcmUtils.recursiveMerge(dbAcElement.getProperties(), element.getValue().getProperties());
}
- if (automationComposition.getRestarting() != null) {
- throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Update not allowed");
- }
var validationResult = validateAutomationComposition(acToBeUpdated);
if (!validationResult.isValid()) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, validationResult.getResult());
}
// Publish property update event to the participants
supervisionAcHandler.update(acToBeUpdated);
@@ -187,47 +210,106 @@ public class AutomationCompositionInstantiationProvider {
AutomationComposition automationComposition, AutomationComposition acToBeUpdated) {
if (!DeployState.DEPLOYED.equals(acToBeUpdated.getDeployState())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
"Not allowed to migrate in the state " + acToBeUpdated.getDeployState());
}
- if (automationComposition.getRestarting() != null) {
- throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Migrate not allowed");
- }
// Iterate and update the element property values
for (var element : automationComposition.getElements().entrySet()) {
var elementId = element.getKey();
var dbAcElement = acToBeUpdated.getElements().get(elementId);
+ // Add additional elements if present for migration
if (dbAcElement == null) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Element id not present " + elementId);
- }
- AcmUtils.recursiveMerge(dbAcElement.getProperties(), element.getValue().getProperties());
- var newDefinition = element.getValue().getDefinition();
- var compatibility =
- newDefinition.asConceptKey().getCompatibility(dbAcElement.getDefinition().asConceptKey());
- if (PfKey.Compatibility.DIFFERENT.equals(compatibility)) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
- dbAcElement.getDefinition() + " is not compatible with " + newDefinition);
- }
- if (PfKey.Compatibility.MAJOR.equals(compatibility) || PfKey.Compatibility.MINOR.equals(compatibility)) {
- LOGGER.warn("Migrate {}: Version {} has {} compatibility with {} ",
- automationComposition.getInstanceId(), newDefinition, compatibility, dbAcElement.getDefinition());
+ LOGGER.info("New Ac element {} added in Migration", elementId);
+ acToBeUpdated.getElements().put(elementId, element.getValue());
+ } else {
+ AcmUtils.recursiveMerge(dbAcElement.getProperties(), element.getValue().getProperties());
+ var newDefinition = element.getValue().getDefinition().asConceptKey();
+ var dbElementDefinition = dbAcElement.getDefinition().asConceptKey();
+ checkCompatibility(newDefinition, dbElementDefinition, automationComposition.getInstanceId());
+ dbAcElement.setDefinition(element.getValue().getDefinition());
}
- dbAcElement.setDefinition(element.getValue().getDefinition());
}
+ // Remove element which is not present in the new Ac instance
+ var elementsRemoved = getElementRemoved(acToBeUpdated, automationComposition);
+ elementsRemoved.forEach(uuid -> acToBeUpdated.getElements().remove(uuid));
var validationResult =
- validateAutomationComposition(acToBeUpdated, automationComposition.getCompositionTargetId());
+ validateAutomationComposition(acToBeUpdated, automationComposition.getCompositionTargetId());
if (!validationResult.isValid()) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, validationResult.getResult());
}
acToBeUpdated.setCompositionTargetId(automationComposition.getCompositionTargetId());
+ var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionTargetId());
+ // Publish migrate event to the participants
+ supervisionAcHandler.migrate(acToBeUpdated, acDefinition.getServiceTemplate());
+
+ var ac = automationCompositionProvider.updateAutomationComposition(acToBeUpdated);
+ elementsRemoved.forEach(automationCompositionProvider::deleteAutomationCompositionElement);
+ return createInstantiationResponse(ac);
+ }
+
+ private List<UUID> getElementRemoved(AutomationComposition acFromDb, AutomationComposition acFromMigration) {
+ return acFromDb.getElements().keySet().stream()
+ .filter(id -> acFromMigration.getElements().get(id) == null).toList();
+ }
+
+ void checkCompatibility(PfConceptKey newDefinition, PfConceptKey dbElementDefinition,
+ UUID instanceId) {
+ var compatibility = newDefinition.getCompatibility(dbElementDefinition);
+ if (PfKey.Compatibility.DIFFERENT.equals(compatibility)) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
+ dbElementDefinition + " is not compatible with " + newDefinition);
+ }
+ if (PfKey.Compatibility.MAJOR.equals(compatibility) || PfKey.Compatibility.MINOR
+ .equals(compatibility)) {
+ LOGGER.warn("Migrate {}: Version {} has {} compatibility with {} ", instanceId, newDefinition,
+ compatibility, dbElementDefinition);
+ }
+ }
+
+ private InstantiationResponse migratePrecheckAc(
+ AutomationComposition automationComposition, AutomationComposition acToBeUpdated) {
+
+ acToBeUpdated.setPrecheck(true);
+ var copyAc = new AutomationComposition(acToBeUpdated);
+ // Iterate and update the element property values
+ for (var element : automationComposition.getElements().entrySet()) {
+ var elementId = element.getKey();
+ var copyElement = copyAc.getElements().get(elementId);
+ // Add additional elements if present for migration
+ if (copyElement == null) {
+ LOGGER.info("New Ac element {} added in Migration", elementId);
+ copyAc.getElements().put(elementId, element.getValue());
+ } else {
+ AcmUtils.recursiveMerge(copyElement.getProperties(), element.getValue().getProperties());
+ var newDefinition = element.getValue().getDefinition().asConceptKey();
+ var copyElementDefinition = copyElement.getDefinition().asConceptKey();
+ checkCompatibility(newDefinition, copyElementDefinition, automationComposition.getInstanceId());
+ copyElement.setDefinition(element.getValue().getDefinition());
+ }
+ }
+ // Remove element which is not present in the new Ac instance
+ var elementsRemoved = getElementRemoved(copyAc, automationComposition);
+ elementsRemoved.forEach(uuid -> copyAc.getElements().remove(uuid));
+
+ var validationResult =
+ validateAutomationComposition(copyAc, automationComposition.getCompositionTargetId());
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, validationResult.getResult());
+ }
+ copyAc.setCompositionTargetId(automationComposition.getCompositionTargetId());
// Publish migrate event to the participants
- supervisionAcHandler.migrate(acToBeUpdated, automationComposition.getCompositionTargetId());
+ supervisionAcHandler.migratePrecheck(copyAc);
- automationComposition = automationCompositionProvider.updateAutomationComposition(acToBeUpdated);
- return createInstantiationResponse(automationComposition);
+ AcmUtils.setCascadedState(acToBeUpdated, DeployState.DEPLOYED, LockState.LOCKED,
+ SubState.MIGRATION_PRECHECKING);
+ acToBeUpdated.setStateChangeResult(StateChangeResult.NO_ERROR);
+ // excluding removed element in MIGRATION_PRECHECKING
+ elementsRemoved.forEach(uuid -> acToBeUpdated.getElements().get(uuid).setSubState(SubState.NONE));
+
+ return createInstantiationResponse(automationCompositionProvider.updateAutomationComposition(acToBeUpdated));
}
private BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition) {
@@ -296,7 +378,7 @@ public class AutomationCompositionInstantiationProvider {
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
if (!compositionId.equals(automationComposition.getCompositionId())
&& !compositionId.equals(automationComposition.getCompositionTargetId())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
return automationComposition;
@@ -312,17 +394,17 @@ public class AutomationCompositionInstantiationProvider {
public InstantiationResponse deleteAutomationComposition(UUID compositionId, UUID instanceId) {
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
if (!compositionId.equals(automationComposition.getCompositionId())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
if (!DeployState.UNDEPLOYED.equals(automationComposition.getDeployState())
&& !DeployState.DELETING.equals(automationComposition.getDeployState())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
"Automation composition state is still " + automationComposition.getDeployState());
}
if (DeployState.DELETING.equals(automationComposition.getDeployState())
&& StateChangeResult.NO_ERROR.equals(automationComposition.getStateChangeResult())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
"Automation composition state is still " + automationComposition.getDeployState());
}
if (automationComposition.getRestarting() != null) {
@@ -366,7 +448,7 @@ public class AutomationCompositionInstantiationProvider {
@Valid AcInstanceStateUpdate acInstanceStateUpdate) {
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
if (!compositionId.equals(automationComposition.getCompositionId())) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
@@ -376,8 +458,9 @@ public class AutomationCompositionInstantiationProvider {
participantProvider.verifyParticipantState(participantIds);
var result = acInstanceStateResolver.resolve(acInstanceStateUpdate.getDeployOrder(),
- acInstanceStateUpdate.getLockOrder(), automationComposition.getDeployState(),
- automationComposition.getLockState(), automationComposition.getStateChangeResult());
+ acInstanceStateUpdate.getLockOrder(), acInstanceStateUpdate.getSubOrder(),
+ automationComposition.getDeployState(), automationComposition.getLockState(),
+ automationComposition.getSubState(), automationComposition.getStateChangeResult());
switch (result) {
case "DEPLOY":
supervisionAcHandler.deploy(automationComposition, acDefinition);
@@ -395,6 +478,14 @@ public class AutomationCompositionInstantiationProvider {
supervisionAcHandler.unlock(automationComposition, acDefinition);
break;
+ case "PREPARE":
+ supervisionAcHandler.prepare(automationComposition);
+ break;
+
+ case "REVIEW":
+ supervisionAcHandler.review(automationComposition);
+ break;
+
default:
throw new PfModelRuntimeException(Status.BAD_REQUEST, "Not valid " + acInstanceStateUpdate);
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/AcRuntimeParameterGroup.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/AcRuntimeParameterGroup.java
index a0b6fe13e..e6ce61438 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/AcRuntimeParameterGroup.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/AcRuntimeParameterGroup.java
@@ -53,5 +53,5 @@ public class AcRuntimeParameterGroup {
@Valid
@NotNull
- private Topics topics;
+ private Topics topics = new Topics();
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/Topics.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/Topics.java
index d485a24ba..6e230d3df 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/Topics.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/Topics.java
@@ -20,6 +20,7 @@ package org.onap.policy.clamp.acm.runtime.main.parameters;
import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.validation.annotation.Validated;
@@ -27,6 +28,7 @@ import org.springframework.validation.annotation.Validated;
@Setter
@Validated
@AllArgsConstructor
+@NoArgsConstructor
public class Topics {
private String operationTopic;
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
index 3e2057ed5..66f035e5e 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
@@ -30,6 +30,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AcPreparePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionMigrationPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
@@ -42,10 +43,12 @@ import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -68,6 +71,7 @@ public class SupervisionAcHandler {
private final AcElementPropertiesPublisher acElementPropertiesPublisher;
private final AutomationCompositionMigrationPublisher acCompositionMigrationPublisher;
private final ParticipantSyncPublisher participantSyncPublisher;
+ private final AcPreparePublisher acPreparePublisher;
private final ExecutorService executor = Context.taskWrapping(Executors.newFixedThreadPool(1));
@@ -150,6 +154,30 @@ public class SupervisionAcHandler {
}
/**
+ * Handle prepare Pre Deploy an AutomationComposition instance.
+ *
+ * @param automationComposition the AutomationComposition
+ */
+ public void prepare(AutomationComposition automationComposition) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE, SubState.PREPARING);
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
+ executor.execute(() -> acPreparePublisher.sendPrepare(automationComposition));
+ }
+
+ /**
+ * Handle prepare Post Deploy an AutomationComposition instance.
+ *
+ * @param automationComposition the AutomationComposition
+ */
+ public void review(AutomationComposition automationComposition) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKED, SubState.REVIEWING);
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
+ executor.execute(() -> acPreparePublisher.sendRevew(automationComposition));
+ }
+
+ /**
* Handle Lock an AutomationComposition instance.
*
* @param automationComposition the AutomationComposition
@@ -247,8 +275,7 @@ public class SupervisionAcHandler {
for (var element : automationComposition.getElements().values()) {
if (element.getParticipantId().equals(automationCompositionAckMessage.getParticipantId())) {
element.setDeployState(DeployState.DELETED);
- automationCompositionProvider.updateAutomationCompositionElement(element,
- automationComposition.getInstanceId());
+ automationCompositionProvider.updateAutomationCompositionElement(element);
}
}
} else {
@@ -261,9 +288,9 @@ public class SupervisionAcHandler {
var updated = updateState(automationComposition,
automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet(),
- automationCompositionAckMessage.getStateChangeResult());
+ automationCompositionAckMessage.getStateChangeResult(), automationCompositionAckMessage.getStage());
if (updated) {
- automationCompositionProvider.updateAutomationComposition(automationComposition);
+ automationComposition = automationCompositionProvider.updateAcState(automationComposition);
var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
participantSyncPublisher.sendSync(acDefinition.getServiceTemplate(), automationComposition);
}
@@ -271,7 +298,7 @@ public class SupervisionAcHandler {
private boolean updateState(AutomationComposition automationComposition,
Set<Map.Entry<UUID, AcElementDeployAck>> automationCompositionResultSet,
- StateChangeResult stateChangeResult) {
+ StateChangeResult stateChangeResult, Integer stage) {
var updated = false;
boolean inProgress = !StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult());
if (inProgress && !stateChangeResult.equals(automationComposition.getStateChangeResult())) {
@@ -286,11 +313,12 @@ public class SupervisionAcHandler {
element.setOutProperties(acElementAck.getValue().getOutProperties());
element.setOperationalState(acElementAck.getValue().getOperationalState());
element.setUseState(acElementAck.getValue().getUseState());
+ element.setSubState(SubState.NONE);
element.setDeployState(acElementAck.getValue().getDeployState());
element.setLockState(acElementAck.getValue().getLockState());
+ element.setStage(stage);
element.setRestarting(null);
- automationCompositionProvider.updateAutomationCompositionElement(element,
- automationComposition.getInstanceId());
+ automationCompositionProvider.updateAutomationCompositionElement(element);
}
}
@@ -310,12 +338,22 @@ public class SupervisionAcHandler {
* Handle Migration of an AutomationComposition instance to other ACM Definition.
*
* @param automationComposition the AutomationComposition
- * @param compositionTargetId the ACM Definition Id
+ * @param serviceTemplate the ServiceTemplate
*/
- public void migrate(AutomationComposition automationComposition, UUID compositionTargetId) {
+ public void migrate(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate) {
AcmUtils.setCascadedState(automationComposition, DeployState.MIGRATING, LockState.LOCKED);
+ var stage = ParticipantUtils.getFirstStage(automationComposition, serviceTemplate);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
- executor.execute(
- () -> acCompositionMigrationPublisher.send(automationComposition, compositionTargetId));
+ automationComposition.setPhase(stage);
+ executor.execute(() -> acCompositionMigrationPublisher.send(automationComposition, stage));
+ }
+
+ /**
+ * Handle Migration precheck of an AutomationComposition instance to other ACM Definition.
+ *
+ * @param automationComposition the AutomationComposition
+ */
+ public void migratePrecheck(AutomationComposition automationComposition) {
+ executor.execute(() -> acCompositionMigrationPublisher.send(automationComposition, 0));
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
index 75a2f0540..31cc8babe 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
@@ -22,10 +22,12 @@
package org.onap.policy.clamp.acm.runtime.supervision;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.UUID;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionMigrationPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantSyncPublisher;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
@@ -34,6 +36,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
@@ -57,6 +60,7 @@ public class SupervisionScanner {
private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
private final ParticipantSyncPublisher participantSyncPublisher;
+ private final AutomationCompositionMigrationPublisher automationCompositionMigrationPublisher;
/**
* Constructor for instantiating SupervisionScanner.
@@ -72,12 +76,14 @@ public class SupervisionScanner {
final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
final AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
final ParticipantSyncPublisher participantSyncPublisher,
+ final AutomationCompositionMigrationPublisher automationCompositionMigrationPublisher,
final AcRuntimeParameterGroup acRuntimeParameterGroup) {
this.automationCompositionProvider = automationCompositionProvider;
this.acDefinitionProvider = acDefinitionProvider;
this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher;
this.automationCompositionDeployPublisher = automationCompositionDeployPublisher;
this.participantSyncPublisher = participantSyncPublisher;
+ this.automationCompositionMigrationPublisher = automationCompositionMigrationPublisher;
this.maxStatusWaitMs = acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs();
}
@@ -95,11 +101,9 @@ public class SupervisionScanner {
var acList = automationCompositionProvider.getAcInstancesInTransition();
HashMap<UUID, AutomationCompositionDefinition> acDefinitionMap = new HashMap<>();
for (var automationComposition : acList) {
- var acDefinition = acDefinitionMap.get(automationComposition.getCompositionId());
- if (acDefinition == null) {
- acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
- acDefinitionMap.put(acDefinition.getCompositionId(), acDefinition);
- }
+ var compositionId = automationComposition.getCompositionTargetId() != null
+ ? automationComposition.getCompositionTargetId() : automationComposition.getCompositionId();
+ var acDefinition = acDefinitionMap.computeIfAbsent(compositionId, acDefinitionProvider::getAcDefinition);
scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate());
}
LOGGER.debug("Automation composition scan complete . . .");
@@ -117,6 +121,7 @@ public class SupervisionScanner {
for (var element : acDefinition.getElementStateMap().values()) {
if (!finalState.equals(element.getState())) {
completed = false;
+ break;
}
}
if (completed) {
@@ -133,13 +138,24 @@ public class SupervisionScanner {
LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId());
if (!AcmUtils.isInTransitionalState(automationComposition.getDeployState(),
- automationComposition.getLockState())
+ automationComposition.getLockState(), automationComposition.getSubState())
|| StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())) {
LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId());
return;
}
+ if (DeployState.UPDATING.equals(automationComposition.getDeployState())
+ || DeployState.MIGRATING.equals(automationComposition.getDeployState())
+ || SubState.MIGRATION_PRECHECKING.equals(automationComposition.getSubState())) {
+
+ scanMigrate(automationComposition, serviceTemplate);
+ } else {
+ scanDeploy(automationComposition, serviceTemplate);
+ }
+ }
+
+ private void scanDeploy(final AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate) {
var completed = true;
var minSpNotCompleted = 1000; // min startPhase not completed
var maxSpNotCompleted = 0; // max startPhase not completed
@@ -151,7 +167,8 @@ public class SupervisionScanner {
int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
defaultMin = Math.min(defaultMin, startPhase);
defaultMax = Math.max(defaultMax, startPhase);
- if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) {
+ if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState(),
+ element.getSubState())) {
completed = false;
minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase);
@@ -167,22 +184,51 @@ public class SupervisionScanner {
LOGGER.debug("automation composition scan: transition state {} {} not completed",
automationComposition.getDeployState(), automationComposition.getLockState());
- if (DeployState.UPDATING.equals(automationComposition.getDeployState())
- || DeployState.MIGRATING.equals(automationComposition.getDeployState())) {
- // UPDATING do not need phases
- handleTimeoutUpdate(automationComposition);
- return;
- }
-
var isForward =
AcmUtils.isForward(automationComposition.getDeployState(), automationComposition.getLockState());
var nextSpNotCompleted = isForward ? minSpNotCompleted : maxSpNotCompleted;
if (nextSpNotCompleted != automationComposition.getPhase()) {
- sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted, false);
+ sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted);
+ } else {
+ handleTimeout(automationComposition);
+ }
+ }
+ }
+
+ private void scanMigrate(final AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate) {
+ var completed = true;
+ var minStageNotCompleted = 1000; // min stage not completed
+ for (var element : automationComposition.getElements().values()) {
+ if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState(),
+ element.getSubState())) {
+ var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ var stageSet = ParticipantUtils.findStageSet(toscaNodeTemplate.getProperties());
+ var minStage = stageSet.stream().min(Comparator.comparing(Integer::valueOf)).orElse(0);
+ int stage = element.getStage() != null ? element.getStage() : minStage;
+ minStageNotCompleted = Math.min(minStageNotCompleted, stage);
+ completed = false;
+ }
+ }
+
+ if (completed) {
+ LOGGER.debug("automation composition scan: transition state {} {} ", automationComposition.getDeployState(),
+ automationComposition.getLockState());
+
+ complete(automationComposition, serviceTemplate);
+ } else {
+ LOGGER.debug("automation composition scan: transition from state {} to {} not completed",
+ automationComposition.getDeployState(), automationComposition.getLockState());
+
+ if (DeployState.MIGRATING.equals(automationComposition.getDeployState())
+ && minStageNotCompleted != automationComposition.getPhase()) {
+ savePahese(automationComposition, minStageNotCompleted);
+ LOGGER.debug("retry message AutomationCompositionMigration");
+ automationCompositionMigrationPublisher.send(automationComposition, minStageNotCompleted);
} else {
- handleTimeoutWithPhase(automationComposition, serviceTemplate);
+ handleTimeout(automationComposition);
}
}
}
@@ -198,15 +244,18 @@ public class SupervisionScanner {
automationComposition.setDeployState(AcmUtils.deployCompleted(deployState));
automationComposition.setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState()));
automationComposition.setPhase(null);
+ automationComposition.setSubState(SubState.NONE);
+ automationComposition.setPrecheck(null);
if (StateChangeResult.TIMEOUT.equals(automationComposition.getStateChangeResult())) {
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
}
+ var acToUpdate = automationComposition;
if (DeployState.DELETED.equals(automationComposition.getDeployState())) {
automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId());
} else {
- automationCompositionProvider.updateAutomationComposition(automationComposition);
+ acToUpdate = automationCompositionProvider.updateAcState(acToUpdate);
}
- participantSyncPublisher.sendSync(serviceTemplate, automationComposition);
+ participantSyncPublisher.sendSync(serviceTemplate, acToUpdate);
}
private void handleTimeout(AutomationCompositionDefinition acDefinition) {
@@ -224,67 +273,37 @@ public class SupervisionScanner {
}
}
- private void handleTimeoutUpdate(AutomationComposition automationComposition) {
+ private void handleTimeout(AutomationComposition automationComposition) {
if (StateChangeResult.TIMEOUT.equals(automationComposition.getStateChangeResult())) {
LOGGER.debug("The ac instance is in timeout {}", automationComposition.getInstanceId());
return;
}
var now = TimestampHelper.nowEpochMilli();
var lastMsg = TimestampHelper.toEpochMilli(automationComposition.getLastMsg());
- for (var element : automationComposition.getElements().values()) {
- if (!AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) {
- continue;
- }
- if ((now - lastMsg) > maxStatusWaitMs) {
- LOGGER.debug("Report timeout for the ac instance {}", automationComposition.getInstanceId());
- automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT);
- automationCompositionProvider.updateAutomationComposition(automationComposition);
- break;
- }
+ if ((now - lastMsg) > maxStatusWaitMs) {
+ LOGGER.debug("Report timeout for the ac instance {}", automationComposition.getInstanceId());
+ automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT);
+ automationCompositionProvider.updateAcState(automationComposition);
}
}
- private void handleTimeoutWithPhase(AutomationComposition automationComposition,
- ToscaServiceTemplate serviceTemplate) {
- if (StateChangeResult.TIMEOUT.equals(automationComposition.getStateChangeResult())) {
- LOGGER.debug("The ac instance is in timeout {}", automationComposition.getInstanceId());
- return;
- }
- int currentPhase = automationComposition.getPhase();
- var now = TimestampHelper.nowEpochMilli();
- var lastMsg = TimestampHelper.toEpochMilli(automationComposition.getLastMsg());
- for (var element : automationComposition.getElements().values()) {
- if (!AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) {
- continue;
- }
- var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
- .get(element.getDefinition().getName());
- int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
- if (currentPhase != startPhase) {
- continue;
- }
- if ((now - lastMsg) > maxStatusWaitMs) {
- LOGGER.debug("Report timeout for the ac instance {}", automationComposition.getInstanceId());
- automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT);
- automationCompositionProvider.updateAutomationComposition(automationComposition);
- break;
- }
- }
+ private void savePahese(AutomationComposition automationComposition, int startPhase) {
+ automationComposition.setLastMsg(TimestampHelper.now());
+ automationComposition.setPhase(startPhase);
+ automationCompositionProvider.updateAcState(automationComposition);
}
private void sendAutomationCompositionMsg(AutomationComposition automationComposition,
- ToscaServiceTemplate serviceTemplate, int startPhase, boolean firstStartPhase) {
- automationComposition.setLastMsg(TimestampHelper.now());
- automationComposition.setPhase(startPhase);
- automationCompositionProvider.updateAutomationComposition(automationComposition);
+ ToscaServiceTemplate serviceTemplate, int startPhase) {
+ savePahese(automationComposition, startPhase);
if (DeployState.DEPLOYING.equals(automationComposition.getDeployState())) {
- LOGGER.debug("retry message AutomationCompositionUpdate");
+ LOGGER.debug("retry message AutomationCompositionDeploy");
automationCompositionDeployPublisher.send(automationComposition, serviceTemplate, startPhase,
- firstStartPhase);
+ false);
} else {
LOGGER.debug("retry message AutomationCompositionStateChange");
- automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, false);
}
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java
index 338f2960d..cc5d1461f 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java
@@ -56,7 +56,7 @@ public class AcElementPropertiesPublisher extends AbstractParticipantPublisher<P
propertiesUpdate.setParticipantUpdatesList(
AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.UPDATE));
- LOGGER.debug("AC Element properties update sent {}", propertiesUpdate);
+ LOGGER.debug("AC Element properties update sent {}", propertiesUpdate.getMessageId());
super.send(propertiesUpdate);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcPreparePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcPreparePublisher.java
new file mode 100644
index 000000000..acf403595
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcPreparePublisher.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision.comm;
+
+import io.micrometer.core.annotation.Timed;
+import java.time.Instant;
+import java.util.UUID;
+import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionPrepare;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+@AllArgsConstructor
+public class AcPreparePublisher extends AbstractParticipantPublisher<AutomationCompositionPrepare> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AcPreparePublisher.class);
+
+ /**
+ * Send AutomationCompositionPrepare Prepare message to Participant.
+ *
+ * @param automationComposition the AutomationComposition
+ */
+ @Timed(value = "publisher.prepare", description = "AC Prepare Pre Deploy published")
+ public void sendPrepare(AutomationComposition automationComposition) {
+ var acPrepare = createAutomationCompositionPrepare(automationComposition.getCompositionId(),
+ automationComposition.getInstanceId());
+ acPrepare.setParticipantList(
+ AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.NONE));
+ LOGGER.debug("AC Prepare sent {}", acPrepare);
+ super.send(acPrepare);
+ }
+
+ /**
+ * Send AutomationCompositionPrepare Review message to Participant.
+ *
+ * @param automationComposition the AutomationComposition
+ */
+ @Timed(value = "publisher.review", description = "AC Review Post Deploy published")
+ public void sendRevew(AutomationComposition automationComposition) {
+ var acPrepare = createAutomationCompositionPrepare(automationComposition.getCompositionId(),
+ automationComposition.getInstanceId());
+ acPrepare.setPreDeploy(false);
+ LOGGER.debug("AC Review sent {}", acPrepare);
+ super.send(acPrepare);
+ }
+
+ private AutomationCompositionPrepare createAutomationCompositionPrepare(UUID compositionId, UUID instanceId) {
+ var acPrepare = new AutomationCompositionPrepare();
+ acPrepare.setCompositionId(compositionId);
+ acPrepare.setAutomationCompositionId(instanceId);
+ acPrepare.setMessageId(UUID.randomUUID());
+ acPrepare.setTimestamp(Instant.now());
+ return acPrepare;
+ }
+}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
index 2b6435e67..7fe63a7c5 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
@@ -87,7 +87,7 @@ public class AutomationCompositionDeployPublisher extends AbstractParticipantPub
acDeployMsg.setTimestamp(Instant.now());
acDeployMsg.setParticipantUpdatesList(participantDeploys);
- LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg);
+ LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg.getMessageId());
super.send(acDeployMsg);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java
index e26a5403b..572f7b1fe 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java
@@ -36,20 +36,22 @@ public class AutomationCompositionMigrationPublisher
* Send AutomationCompositionMigration message to Participant.
*
* @param automationComposition the AutomationComposition
- * @param compositionTargetId the Composition Definition Target
+ * @param stage the stage to execute
*/
@Timed(
value = "publisher.automation_composition_migration",
description = "AUTOMATION_COMPOSITION_MIGRATION messages published")
- public void send(AutomationComposition automationComposition, UUID compositionTargetId) {
- var acsc = new AutomationCompositionMigration();
- acsc.setCompositionId(automationComposition.getCompositionId());
- acsc.setAutomationCompositionId(automationComposition.getInstanceId());
- acsc.setMessageId(UUID.randomUUID());
- acsc.setCompositionTargetId(compositionTargetId);
- acsc.setParticipantUpdatesList(
+ public void send(AutomationComposition automationComposition, int stage) {
+ var acMigration = new AutomationCompositionMigration();
+ acMigration.setPrecheck(Boolean.TRUE.equals(automationComposition.getPrecheck()));
+ acMigration.setCompositionId(automationComposition.getCompositionId());
+ acMigration.setAutomationCompositionId(automationComposition.getInstanceId());
+ acMigration.setMessageId(UUID.randomUUID());
+ acMigration.setCompositionTargetId(automationComposition.getCompositionTargetId());
+ acMigration.setStage(stage);
+ acMigration.setParticipantUpdatesList(
AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.MIGRATE));
- super.send(acsc);
+ super.send(acMigration);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java
index b0848bd51..360e526cc 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java
@@ -72,7 +72,7 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part
message.setParticipantId(participantId);
message.setTimestamp(Instant.now());
message.setParticipantDefinitionUpdates(participantDefinitions);
- LOGGER.debug("Participant Update sent {}", message);
+ LOGGER.debug("Participant Update sent {}", message.getMessageId());
super.send(message);
}
@@ -127,7 +127,7 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part
// DeCommission the automation composition but deleting participantdefinitions on participants
message.setParticipantDefinitionUpdates(null);
- LOGGER.debug("Participant Update sent {}", message);
+ LOGGER.debug("Participant Update sent {}", message.getMessageId());
super.send(message);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java
index 96d6338f1..540cf62be 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java
@@ -69,7 +69,7 @@ public class ParticipantRestartPublisher extends AbstractParticipantPublisher<Pa
message.getAutomationcompositionList().add(restartAc);
}
- LOGGER.debug("Participant Restart sent {}", message);
+ LOGGER.debug("Participant Restart sent {}", message.getMessageId());
super.send(message);
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantStatusReqPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantStatusReqPublisher.java
index 1f6b7c8a5..96abac494 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantStatusReqPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantStatusReqPublisher.java
@@ -44,7 +44,7 @@ public class ParticipantStatusReqPublisher extends AbstractParticipantPublisher<
message.setParticipantId(participantId);
message.setTimestamp(Instant.now());
- LOGGER.debug("Participant StatusReq sent {}", message);
+ LOGGER.debug("Participant StatusReq sent {}", message.getMessageId());
super.send(message);
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java
index b63bc0a6b..eb1db6f0e 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java
@@ -144,7 +144,7 @@ public class ParticipantSyncPublisher extends AbstractParticipantPublisher<Parti
}
message.getAutomationcompositionList().add(syncAc);
- LOGGER.debug("Participant AutomationComposition Sync sent {}", message);
+ LOGGER.debug("Participant AutomationComposition Sync sent {}", message.getMessageId());
super.send(message);
}
}
diff --git a/runtime-acm/src/main/resources/application.yaml b/runtime-acm/src/main/resources/application.yaml
index 0e2585dba..bca01ace8 100644
--- a/runtime-acm/src/main/resources/application.yaml
+++ b/runtime-acm/src/main/resources/application.yaml
@@ -44,21 +44,18 @@ runtime:
maxStatusWaitMs: 200000
topicParameterGroup:
topicSources:
- -
- topic: ${runtime.topics.operationTopic}
+ - topic: ${runtime.topics.operationTopic}
servers:
- ${topicServer:kafka:9092}
topicCommInfrastructure: NOOP
fetchTimeout: 15000
topicSinks:
- -
- topic: ${runtime.topics.operationTopic}
+ - topic: ${runtime.topics.operationTopic}
servers:
- ${topicServer:kafka:9092}
topicCommInfrastructure: NOOP
- -
- topic: ${runtime.topics.syncTopic}
+ - topic: ${runtime.topics.syncTopic}
servers:
- ${topicServer:kafka:9092}
topicCommInfrastructure: NOOP
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index 413719110..e001d91bc 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
@@ -53,8 +54,6 @@ class CommissioningProviderTest {
/**
* Test the fetching of automation composition definitions (ToscaServiceTemplates).
- *
- * @throws Exception .
*/
@Test
void testGetAutomationCompositionDefinitions() {
@@ -63,7 +62,7 @@ class CommissioningProviderTest {
var acRuntimeParameterGroup = mock(AcRuntimeParameterGroup.class);
var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null,
- acRuntimeParameterGroup);
+ acRuntimeParameterGroup);
var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
@@ -75,12 +74,11 @@ class CommissioningProviderTest {
/**
* Test the creation of automation composition definitions (ToscaServiceTemplates).
- *
- * @throws Exception .
*/
@Test
void testCreateAutomationCompositionDefinitions() {
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ assertNotNull(serviceTemplate);
serviceTemplate.setName("Name");
serviceTemplate.setVersion("1.0.0");
var acmDefinition = new AutomationCompositionDefinition();
@@ -88,15 +86,15 @@ class CommissioningProviderTest {
acmDefinition.setServiceTemplate(serviceTemplate);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate,
- CommonTestData.TOSCA_ELEMENT_NAME, CommonTestData.TOSCA_COMP_NAME)).thenReturn(acmDefinition);
+ CommonTestData.TOSCA_ELEMENT_NAME, CommonTestData.TOSCA_COMP_NAME)).thenReturn(acmDefinition);
var acProvider = mock(AutomationCompositionProvider.class);
var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null,
- CommonTestData.getTestParamaterGroup());
+ CommonTestData.getTestParamaterGroup());
var affectedDefinitions = provider.createAutomationCompositionDefinition(serviceTemplate)
- .getAffectedAutomationCompositionDefinitions();
+ .getAffectedAutomationCompositionDefinitions();
verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate,
- CommonTestData.TOSCA_ELEMENT_NAME, CommonTestData.TOSCA_COMP_NAME);
+ CommonTestData.TOSCA_ELEMENT_NAME, CommonTestData.TOSCA_COMP_NAME);
// Response should return the number of node templates present in the service template
assertThat(affectedDefinitions).hasSize(7);
}
@@ -104,7 +102,6 @@ class CommissioningProviderTest {
/**
* Test the fetching of a full ToscaServiceTemplate object - as opposed to the reduced template that is being
* tested in the testGetToscaServiceTemplateReduced() test.
- *
*/
@Test
void testGetToscaServiceTemplateList() {
@@ -113,6 +110,7 @@ class CommissioningProviderTest {
var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null, null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ assertNotNull(serviceTemplate);
when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
var returnedServiceTemplate = provider.getAutomationCompositionDefinitions(null, null);
@@ -121,7 +119,7 @@ class CommissioningProviderTest {
}
@Test
- void testDeletecDefinitionDabRequest() {
+ void testDeleteAcDefinitionDabRequest() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
@@ -131,7 +129,7 @@ class CommissioningProviderTest {
var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null, null);
assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId))
- .hasMessageMatching("Delete instances, to commission automation composition definitions");
+ .hasMessageMatching("Delete instances, to commission automation composition definitions");
}
@Test
@@ -139,6 +137,7 @@ class CommissioningProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var compositionId = UUID.randomUUID();
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ assertNotNull(serviceTemplate);
when(acDefinitionProvider.deleteAcDefintion(compositionId)).thenReturn(serviceTemplate);
var acmDefinition = new AutomationCompositionDefinition();
@@ -159,14 +158,14 @@ class CommissioningProviderTest {
void testPriming() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acmDefinition = CommonTestData.createAcDefinition(
- InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.COMMISSIONED);
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.COMMISSIONED);
var compositionId = acmDefinition.getCompositionId();
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
var participantPrimePublisher = mock(ParticipantPrimePublisher.class);
var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
- mock(ParticipantProvider.class), new AcTypeStateResolver(), participantPrimePublisher,
- CommonTestData.getTestParamaterGroup());
+ mock(ParticipantProvider.class), new AcTypeStateResolver(), participantPrimePublisher,
+ CommonTestData.getTestParamaterGroup());
var acTypeStateUpdate = new AcTypeStateUpdate();
acTypeStateUpdate.setPrimeOrder(PrimeOrder.PRIME);
@@ -179,15 +178,15 @@ class CommissioningProviderTest {
void testDepriming() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acmDefinition = CommonTestData.createAcDefinition(
- InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMED);
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMED);
var compositionId = acmDefinition.getCompositionId();
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
var participantPrimePublisher = mock(ParticipantPrimePublisher.class);
var participantProvider = mock(ParticipantProvider.class);
var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
- participantProvider, new AcTypeStateResolver(), participantPrimePublisher,
- CommonTestData.getTestParamaterGroup());
+ participantProvider, new AcTypeStateResolver(), participantPrimePublisher,
+ CommonTestData.getTestParamaterGroup());
var acTypeStateUpdate = new AcTypeStateUpdate();
acTypeStateUpdate.setPrimeOrder(PrimeOrder.DEPRIME);
@@ -201,19 +200,19 @@ class CommissioningProviderTest {
void testBadRequest() {
var acProvider = mock(AutomationCompositionProvider.class);
var provider = new CommissioningProvider(mock(AcDefinitionProvider.class), acProvider,
- mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class),
- mock(AcRuntimeParameterGroup.class));
+ mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class),
+ mock(AcRuntimeParameterGroup.class));
var compositionId = UUID.randomUUID();
when(acProvider.getAcInstancesByCompositionId(compositionId)).thenReturn(List.of(new AutomationComposition()));
var toscaServiceTemplate = new ToscaServiceTemplate();
assertThatThrownBy(() -> provider.updateCompositionDefinition(compositionId, toscaServiceTemplate))
- .hasMessageMatching("There are ACM instances, Update of ACM Definition not allowed");
+ .hasMessageMatching("There are ACM instances, Update of ACM Definition not allowed");
var acTypeStateUpdate = new AcTypeStateUpdate();
assertThatThrownBy(() -> provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate))
- .hasMessageMatching("There are instances, Priming/Depriming not allowed");
+ .hasMessageMatching("There are instances, Priming/Depriming not allowed");
}
@Test
@@ -225,14 +224,14 @@ class CommissioningProviderTest {
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
- mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class),
- mock(AcRuntimeParameterGroup.class));
+ mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class),
+ mock(AcRuntimeParameterGroup.class));
assertThatThrownBy(() -> provider.updateCompositionDefinition(compositionId, toscaServiceTemplate))
- .hasMessageMatching("ACM not in COMMISSIONED state, Update of ACM Definition not allowed");
+ .hasMessageMatching("ACM not in COMMISSIONED state, Update of ACM Definition not allowed");
assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId))
- .hasMessageMatching("ACM not in COMMISSIONED state, Delete of ACM Definition not allowed");
+ .hasMessageMatching("ACM not in COMMISSIONED state, Delete of ACM Definition not allowed");
}
@Test
@@ -245,11 +244,11 @@ class CommissioningProviderTest {
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
- mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class),
- mock(AcRuntimeParameterGroup.class));
+ mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class),
+ mock(AcRuntimeParameterGroup.class));
var acTypeStateUpdate = new AcTypeStateUpdate();
assertThatThrownBy(() -> provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate))
- .hasMessageMatching("There is a restarting process, Priming/Depriming not allowed");
+ .hasMessageMatching("There is a restarting process, Priming/Depriming not allowed");
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index ed8badf8b..16de37e7f 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,6 +34,7 @@ import jakarta.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -61,7 +62,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@ActiveProfiles({ "test", "default" })
+@ActiveProfiles({"test", "default"})
class CommissioningControllerTest extends CommonRestController {
private static final String COMMISSIONING_ENDPOINT = "compositions";
@@ -72,6 +73,7 @@ class CommissioningControllerTest extends CommonRestController {
@Autowired
private ParticipantProvider participantProvider;
+
@LocalServerPort
private int randomServerPort;
@@ -88,6 +90,11 @@ class CommissioningControllerTest extends CommonRestController {
super.setHttpPrefix(randomServerPort);
}
+ @AfterEach
+ void after() {
+ super.client.close();
+ }
+
@Test
void testSwagger() {
super.testSwagger(COMMISSIONING_ENDPOINT);
@@ -111,15 +118,16 @@ class CommissioningControllerTest extends CommonRestController {
@Test
void testCreateBadRequest() {
var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
- var resp = invocationBuilder.post(Entity.json("NotToscaServiceTempalte"));
+ var resp = invocationBuilder.post(Entity.json("NotToscaServiceTemplate"));
assertThat(Response.Status.BAD_REQUEST.getStatusCode()).isEqualTo(resp.getStatus());
var commissioningResponse = resp.readEntity(CommissioningResponse.class);
assertThat(commissioningResponse.getErrorDetails())
.isEqualTo("org.springframework.http.converter.HttpMessageNotReadableException "
- + "Bad Request Could not read JSON: java.lang.IllegalStateException: "
+ + "Could not read JSON: java.lang.IllegalStateException: "
+ "Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $");
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).isNull();
+ resp.close();
}
@Test
@@ -132,7 +140,7 @@ class CommissioningControllerTest extends CommonRestController {
var commissioningResponse = createServiceTemplate(serviceTemplateCreate, Response.Status.INTERNAL_SERVER_ERROR);
assertThat(commissioningResponse.getErrorDetails())
- .isEqualTo("java.lang.IllegalArgumentException Internal Server Error parameter "
+ .isEqualTo("java.lang.IllegalArgumentException parameter "
+ "\"version\": value \"1.0.wrong\", does not match regular expression \""
+ PfKey.VERSION_REGEXP + "\"");
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).isNull();
@@ -149,7 +157,7 @@ class CommissioningControllerTest extends CommonRestController {
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).hasSize(7);
for (var nodeTemplateName : serviceTemplateCreate.getToscaTopologyTemplate().getNodeTemplates().keySet()) {
assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
- .anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
+ .anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
}
}
@@ -161,6 +169,7 @@ class CommissioningControllerTest extends CommonRestController {
assertNull(commissioningResponse.getErrorDetails());
// Response should return the number of node templates present in the service template
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).hasSize(11);
+ assertNotNull(serviceTemplateCreate);
for (var nodeTemplateName : serviceTemplateCreate.getToscaTopologyTemplate().getNodeTemplates().keySet()) {
assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
.anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
@@ -168,7 +177,7 @@ class CommissioningControllerTest extends CommonRestController {
}
private CommissioningResponse createServiceTemplate(ToscaServiceTemplate serviceTemplateCreate,
- Response.Status statusExpected) {
+ Response.Status statusExpected) {
var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
try (var resp = invocationBuilder.post(Entity.json(serviceTemplateCreate))) {
assertEquals(statusExpected.getStatusCode(), resp.getStatus());
@@ -199,17 +208,17 @@ class CommissioningControllerTest extends CommonRestController {
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).hasSize(7);
for (var nodeTemplateName : serviceTemplateUpdate.getToscaTopologyTemplate().getNodeTemplates().keySet()) {
assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
- .anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
+ .anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
}
- var entity = getServiceTemplate(COMMISSIONING_ENDPOINT + "/" + compositionId, Response.Status.OK);
+ var entity = getServiceTemplate(COMMISSIONING_ENDPOINT + "/" + compositionId);
assertThat(entity.getServiceTemplate().getDataTypes()).containsKey(toscaDataType.getName());
}
- private AutomationCompositionDefinition getServiceTemplate(String url, Response.Status statusExpected) {
+ private AutomationCompositionDefinition getServiceTemplate(String url) {
var invocationBuilder = super.sendRequest(url);
try (var resp = invocationBuilder.buildGet().invoke()) {
- assertEquals(statusExpected.getStatusCode(), resp.getStatus());
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
return resp.readEntity(AutomationCompositionDefinition.class);
}
}
@@ -221,6 +230,7 @@ class CommissioningControllerTest extends CommonRestController {
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
var entityList = rawresp.readEntity(ToscaServiceTemplate.class);
assertThat(entityList.getNodeTypes()).isNull();
+ rawresp.close();
}
@Test
@@ -232,6 +242,7 @@ class CommissioningControllerTest extends CommonRestController {
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
var entityList = rawresp.readEntity(ToscaServiceTemplate.class);
assertNotNull(entityList);
+ rawresp.close();
}
@Test
@@ -264,14 +275,15 @@ class CommissioningControllerTest extends CommonRestController {
body.setPrimeOrder(PrimeOrder.PRIME);
var resp = invocationBuilder.put(Entity.json(body));
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ resp.close();
}
private UUID createEntryInDB(String name) {
var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate);
serviceTemplateCreate.setName(name);
var acmDefinition = acDefinitionProvider
- .createAutomationCompositionDefinition(serviceTemplateCreate, CommonTestData.TOSCA_ELEMENT_NAME,
- CommonTestData.TOSCA_COMP_NAME);
+ .createAutomationCompositionDefinition(serviceTemplateCreate, CommonTestData.TOSCA_ELEMENT_NAME,
+ CommonTestData.TOSCA_COMP_NAME);
return acmDefinition.getCompositionId();
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/TestOpenTelemetry.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/TestOpenTelemetry.java
new file mode 100644
index 000000000..8996d77cd
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/TestOpenTelemetry.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START===============================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.config;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ActiveProfiles;
+
+@ActiveProfiles("tracing")
+@SpringBootTest(classes = OpenTelConfiguration.class)
+class TestOpenTelemetry {
+
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ void testOpenTelemetry() {
+ assertThat(context).isNotNull();
+ assertTrue(context.containsBean("otlpGrpcSpanExporter"));
+ assertTrue(context.containsBean("jaegerRemoteSampler"));
+ assertFalse(context.containsBean("otlpHttpSpanExporter"));
+ }
+}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 2ee6a152e..90633e706 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.runtime.instantiation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
@@ -32,6 +33,7 @@ import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVIC
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
@@ -42,17 +44,23 @@ import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.SubOrder;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -64,6 +72,7 @@ class AutomationCompositionInstantiationProviderTest {
private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
private static final String AC_INSTANTIATION_UPDATE_JSON =
"src/test/resources/rest/acm/AutomationCompositionUpdate.json";
+ private static final String AC_MIGRATE_JSON = "src/test/resources/rest/acm/AutomationCompositionMigrate.json";
private static final String AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON =
"src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json";
@@ -71,15 +80,17 @@ class AutomationCompositionInstantiationProviderTest {
"src/test/resources/rest/acm/AutomationCompositionNotFound.json";
private static final String DELETE_BAD_REQUEST = "Automation composition state is still %s";
- private static final String AC_ELEMENT_NAME_NOT_FOUND =
- "\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n"
- + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
- + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\""
- + " INVALID, Not found\n";
- private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " item \"ServiceTemplate\" value \"%s\" INVALID,"
- + " Commissioned automation composition definition not found\n";
+ private static final String AC_ELEMENT_NAME_NOT_FOUND = """
+ "AutomationComposition" INVALID, item has status INVALID
+ "entry PMSHInstance0AcElementNotFound" INVALID, item has status INVALID
+ "entry org.onap.domain.pmsh.DCAEMicroservice" INVALID, Not found
+ "entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement" INVALID, Not found
+ """;
+ private static final String AC_DEFINITION_NOT_FOUND = """
+ "AutomationComposition" INVALID, item has status INVALID
+ item "ServiceTemplate" value "%s" INVALID, Commissioned automation composition definition not found
+ """;
+
private static final String DO_NOT_MATCH = " do not match with ";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
@@ -169,7 +180,7 @@ class AutomationCompositionInstantiationProviderTest {
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var participantProvider = mock(ParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
- null, supervisionAcHandler, participantProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider,
CommonTestData.getTestParamaterGroup());
var instantiationResponse = instantiationProvider.updateAutomationComposition(
automationCompositionUpdate.getCompositionId(), automationCompositionUpdate);
@@ -200,15 +211,15 @@ class AutomationCompositionInstantiationProviderTest {
.thenReturn(automationCompositionUpdate);
var instantiationProvider =
- new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class), null,
- mock(SupervisionAcHandler.class), mock(ParticipantProvider.class),
- mock(AcRuntimeParameterGroup.class));
+ new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class),
+ new AcInstanceStateResolver(), mock(SupervisionAcHandler.class), mock(ParticipantProvider.class),
+ mock(AcRuntimeParameterGroup.class));
var compositionId = automationCompositionUpdate.getCompositionId();
assertThatThrownBy(
() -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
.hasMessageMatching(
- "Not allowed to update in the state " + automationCompositionUpdate.getDeployState());
+ "Not allowed to UPDATE in the state " + automationCompositionUpdate.getDeployState());
automationCompositionUpdate.setDeployState(DeployState.UPDATING);
automationCompositionUpdate.setLockState(LockState.LOCKED);
@@ -216,7 +227,7 @@ class AutomationCompositionInstantiationProviderTest {
assertThatThrownBy(
() -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
.hasMessageMatching(
- "Not allowed to migrate in the state " + automationCompositionUpdate.getDeployState());
+ "Not allowed to MIGRATE in the state " + automationCompositionUpdate.getDeployState());
}
@Test
@@ -243,7 +254,7 @@ class AutomationCompositionInstantiationProviderTest {
automationCompositionUpdate.setCompositionTargetId(UUID.randomUUID());
assertThatThrownBy(
() -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
- .hasMessageMatching("There is a restarting process, Migrate not allowed");
+ .hasMessageMatching("There is a restarting process, Update not allowed");
automationCompositionUpdate.setDeployState(DeployState.UNDEPLOYED);
automationCompositionUpdate.setLockState(LockState.NONE);
@@ -275,13 +286,113 @@ class AutomationCompositionInstantiationProviderTest {
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var participantProvider = mock(ParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
- null, supervisionAcHandler, participantProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider,
mock(AcRuntimeParameterGroup.class));
+ var message =
+ """
+ "AutomationComposition" INVALID, item has status INVALID
+ item "ServiceTemplate.restarting" value "true" INVALID, There is a restarting process in composition
+ """;
+
assertThatThrownBy(
() -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
- .hasMessageMatching("\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " item \"ServiceTemplate.restarting\" value \"true\" INVALID,"
- + " There is a restarting process in composition\n");
+ .hasMessageMatching(message);
+ }
+
+ @Test
+ void testMigrationAddRemoveElements() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
+ var instanceId = UUID.randomUUID();
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_MIGRATE_JSON, "Crud");
+ automationComposition.setCompositionId(compositionId);
+ automationComposition.setInstanceId(instanceId);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ var acProvider = mock(AutomationCompositionProvider.class);
+ when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+
+ var automationCompositionTarget = new AutomationComposition(automationComposition);
+ automationCompositionTarget.setInstanceId(instanceId);
+ automationCompositionTarget.setCompositionId(compositionId);
+ // Add a new element
+ var uuid = UUID.randomUUID();
+ var newElement = new AutomationCompositionElement();
+ newElement.setId(uuid);
+ newElement.setDefinition(new ToscaConceptIdentifier(
+ "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "1.2.3"));
+ newElement.setProperties(Map.of("testVar", "1", "testVar2", "2"));
+ automationCompositionTarget.getElements().put(uuid, newElement);
+
+ //Remove an existing element
+ var elementIdToRemove = UUID.randomUUID();
+ for (var element : automationCompositionTarget.getElements().values()) {
+ if (element.getDefinition().getName()
+ .equals("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement")) {
+ elementIdToRemove = element.getId();
+ }
+ }
+ automationCompositionTarget.getElements().remove(elementIdToRemove);
+
+ var acDefinitionTarget = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionTargetId = acDefinitionTarget.getCompositionId();
+ automationCompositionTarget.setCompositionTargetId(compositionTargetId);
+ when(acDefinitionProvider.findAcDefinition(compositionTargetId)).thenReturn(Optional.of(acDefinitionTarget));
+ when(acDefinitionProvider.getAcDefinition(compositionTargetId)).thenReturn(acDefinitionTarget);
+ when(acProvider.updateAutomationComposition(any())).thenReturn(automationCompositionTarget);
+
+ var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider,
+ new AcRuntimeParameterGroup());
+
+ automationCompositionTarget.setPrecheck(true);
+ var preCheckResponse = instantiationProvider.updateAutomationComposition(compositionId,
+ automationCompositionTarget);
+ verify(supervisionAcHandler).migratePrecheck(any());
+ InstantiationUtils.assertInstantiationResponse(preCheckResponse, automationCompositionTarget);
+
+ automationCompositionTarget.setPrecheck(false);
+ AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKED,
+ SubState.NONE);
+ var instantiationResponse = instantiationProvider.updateAutomationComposition(compositionId,
+ automationCompositionTarget);
+
+ verify(supervisionAcHandler).migrate(any(), any());
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionTarget);
+
+ }
+
+ @Test
+ void testVersionCompatibility() {
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var newDefinition = new PfConceptKey("policy.clamp.element", "1.2.3");
+ var oldDefinition = new PfConceptKey("policy.clamp.element", "2.2.3");
+
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider,
+ new AcRuntimeParameterGroup());
+ var instanceId = UUID.randomUUID();
+ assertDoesNotThrow(() -> {
+ instantiationProvider.checkCompatibility(newDefinition, oldDefinition, instanceId);
+ }, "No exception for major version update");
+
+ // Not compatible
+ newDefinition.setName("policy.clamp.newElement");
+ newDefinition.setVersion("2.2.4");
+
+ assertThatThrownBy(() -> instantiationProvider
+ .checkCompatibility(newDefinition, oldDefinition, instanceId))
+ .hasMessageContaining("is not compatible");
}
@Test
@@ -305,7 +416,7 @@ class AutomationCompositionInstantiationProviderTest {
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var participantProvider = mock(ParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
- null, supervisionAcHandler, participantProvider, new AcRuntimeParameterGroup());
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider, new AcRuntimeParameterGroup());
assertThatThrownBy(() -> instantiationProvider
.updateAutomationComposition(automationComposition.getCompositionId(), automationComposition))
@@ -315,6 +426,7 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionTarget = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var compositionTargetId = acDefinitionTarget.getCompositionId();
when(acDefinitionProvider.findAcDefinition(compositionTargetId)).thenReturn(Optional.of(acDefinitionTarget));
+ when(acDefinitionProvider.getAcDefinition(compositionTargetId)).thenReturn(acDefinitionTarget);
automationComposition.setCompositionTargetId(compositionTargetId);
@@ -327,6 +439,49 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
+ void testInstantiationMigrationPrecheck() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ automationComposition.setCompositionId(compositionId);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ automationComposition.setCompositionTargetId(UUID.randomUUID());
+ automationComposition.setPrecheck(true);
+ var acProvider = mock(AutomationCompositionProvider.class);
+ when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(acProvider.updateAutomationComposition(automationComposition)).thenReturn(automationComposition);
+
+ var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var acmParticipantProvider = mock(ParticipantProvider.class);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler, acmParticipantProvider, new AcRuntimeParameterGroup());
+
+ assertThatThrownBy(() -> instantiationProvider
+ .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition))
+ .hasMessageMatching(
+ String.format(AC_DEFINITION_NOT_FOUND, automationComposition.getCompositionTargetId()));
+
+ var acDefinitionTarget = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionTargetId = acDefinitionTarget.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionTargetId)).thenReturn(Optional.of(acDefinitionTarget));
+
+ automationComposition.setCompositionTargetId(compositionTargetId);
+
+ var instantiationResponse = instantiationProvider
+ .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition);
+
+ verify(supervisionAcHandler).migratePrecheck(any());
+ verify(acProvider).updateAutomationComposition(automationComposition);
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationComposition);
+ }
+
+ @Test
void testMigrateBadRequest() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
@@ -349,16 +504,55 @@ class AutomationCompositionInstantiationProviderTest {
var acMigrate = new AutomationComposition(automationComposition);
acMigrate.setCompositionTargetId(compositionTargetId);
- automationComposition.getElements().clear();
+ automationComposition.setDeployState(DeployState.DEPLOYING);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var participantProvider = mock(ParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
- null, supervisionAcHandler, participantProvider, new AcRuntimeParameterGroup());
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider,
+ new AcRuntimeParameterGroup());
assertThatThrownBy(() -> instantiationProvider
.updateAutomationComposition(automationComposition.getCompositionId(), acMigrate))
- .hasMessageStartingWith("Element id not present");
+ .hasMessageStartingWith("Not allowed to MIGRATE in the state DEPLOYING");
+ }
+
+ @Test
+ void testMigratePrecheckBadRequest() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ automationComposition.setCompositionId(compositionId);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ automationComposition.setPrecheck(true);
+ var acProvider = mock(AutomationCompositionProvider.class);
+ when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(acProvider.updateAutomationComposition(automationComposition)).thenReturn(automationComposition);
+
+ var acDefinitionTarget = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionTargetId = acDefinitionTarget.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionTargetId)).thenReturn(Optional.of(acDefinitionTarget));
+
+ var acMigrate = new AutomationComposition(automationComposition);
+ acMigrate.setCompositionTargetId(compositionTargetId);
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setPrecheck(true);
+
+ var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler, participantProvider,
+ new AcRuntimeParameterGroup());
+
+ assertThatThrownBy(() -> instantiationProvider
+ .updateAutomationComposition(automationComposition.getCompositionId(), acMigrate))
+ .hasMessageStartingWith("Not allowed to NONE in the state DEPLOYING");
}
@Test
@@ -550,10 +744,14 @@ class AutomationCompositionInstantiationProviderTest {
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationComposition.setCompositionId(compositionId);
+ var message = """
+ "AutomationComposition" INVALID, item has status INVALID
+ item "ServiceTemplate.state" value "COMMISSIONED" INVALID, Commissioned automation composition \
+ definition not primed
+ """;
+
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
- .hasMessageMatching("\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " item \"ServiceTemplate.state\" value \"COMMISSIONED\" INVALID,"
- + " Commissioned automation composition definition not primed\n");
+ .hasMessageMatching(message);
}
@Test
@@ -605,5 +803,21 @@ class AutomationCompositionInstantiationProviderTest {
acInstanceStateUpdate.setLockOrder(LockOrder.LOCK);
provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
verify(supervisionAcHandler).lock(any(AutomationComposition.class), any(AutomationCompositionDefinition.class));
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYED);
+ automationComposition.setLockState(LockState.NONE);
+ acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE);
+ acInstanceStateUpdate.setLockOrder(LockOrder.NONE);
+ acInstanceStateUpdate.setSubOrder(SubOrder.PREPARE);
+ provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
+ verify(supervisionAcHandler).prepare(any(AutomationComposition.class));
+
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE);
+ acInstanceStateUpdate.setLockOrder(LockOrder.NONE);
+ acInstanceStateUpdate.setSubOrder(SubOrder.REVIEW);
+ provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
+ verify(supervisionAcHandler).review(any(AutomationComposition.class));
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java
index bdfaedc04..18911f461 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 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,84 +20,62 @@
package org.onap.policy.clamp.acm.runtime.main.rest;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
-import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@ActiveProfiles({ "test", "default" })
-class ActuatorControllerTest extends CommonRestController {
+@ActiveProfiles("test")
+class ActuatorControllerTest {
- private static final String HEALTH_ENDPOINT = "health";
- private static final String METRICS_ENDPOINT = "metrics";
- private static final String PROMETHEUS_ENDPOINT = "prometheus";
- private static final String SWAGGER_ENDPOINT = "v3/api-docs";
+ @Autowired
+ WebTestClient webClient;
- @LocalServerPort
- private int randomServerPort;
+ @Value("${spring.security.user.name}")
+ String username;
+ @Value("${spring.security.user.password}")
+ String password;
@BeforeEach
- public void setUpPort() {
- super.setHttpPrefix(randomServerPort);
- }
-
- @Test
- void testGetHealth_Unauthorized() {
- assertUnauthorizedActGet(HEALTH_ENDPOINT);
- }
-
- @Test
- void testGetMetrics_Unauthorized() {
- assertUnauthorizedActGet(METRICS_ENDPOINT);
- }
-
- @Test
- void testGetPrometheus_Unauthorized() {
- assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
- }
-
- @Test
- void testGetSwagger_Unauthorized() {
- assertUnauthorizedActGet(SWAGGER_ENDPOINT);
+ void beforeEach() {
+ var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+ webClient = webClient.mutate().filter(filter).build();
}
@Test
void testGetHealth() {
- var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
- var rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ webClient.get().uri("/health").accept(APPLICATION_JSON)
+ .exchange().expectStatus().isOk();
}
@Test
void testGetMetrics() {
- var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
- var rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+ .exchange().expectStatus().isOk();
}
@Test
void testGetPrometheus() {
- var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
- var rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+ .exchange().expectStatus().isOk();
}
@Test
void testGetSwagger() {
- var invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT);
- var rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ webClient.get().uri("/v3/api-docs").accept(APPLICATION_JSON)
+ .exchange().expectStatus().isOk();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/PrometheusNoAuthTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/PrometheusNoAuthTest.java
index 5b94814fb..87e43ea8c 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/PrometheusNoAuthTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/PrometheusNoAuthTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 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,39 +20,29 @@
package org.onap.policy.clamp.acm.runtime.main.rest;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
-import jakarta.ws.rs.client.Invocation;
-import jakarta.ws.rs.core.Response;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.reactive.server.WebTestClient;
@AutoConfigureObservability(tracing = false)
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-@ActiveProfiles({ "prometheus-noauth", "default" })
-class PrometheusNoAuthTest extends CommonRestController {
- private static final String PROMETHEUS_ENDPOINT = "prometheus";
+@ActiveProfiles({"prometheus-noauth", "default"})
+class PrometheusNoAuthTest {
- @LocalServerPort
- private int randomServerPort;
-
- @BeforeEach
- public void setUpPort() {
- super.setHttpPrefix(randomServerPort);
- }
+ @Autowired
+ WebTestClient webClient;
@Test
- void testGetPrometheusNoAuth() {
- Invocation.Builder invocationBuilder = super.sendNoAuthActRequest(PROMETHEUS_ENDPOINT);
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ void testGetPrometheus() {
+ webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+ .exchange().expectStatus().isOk();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
index 4842a77a8..ca3b9bfab 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
@@ -70,8 +70,8 @@ class ParticipantControllerTest extends CommonRestController {
private static final String PARTICIPANT_JSON2 = "src/test/resources/providers/TestParticipant2.json";
private static final List<Participant> inputParticipants = new ArrayList<>();
- private static final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
- private static final String originalJson2 = ResourceUtils.getResourceAsString(PARTICIPANT_JSON2);
+ private static final String ORIGINAL_JSON = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
+ private static final String ORIGINAL_JSON2 = ResourceUtils.getResourceAsString(PARTICIPANT_JSON2);
@Autowired
private ParticipantProvider participantProvider;
@@ -81,8 +81,8 @@ class ParticipantControllerTest extends CommonRestController {
*/
@BeforeAll
public static void setUpBeforeClass() throws CoderException {
- inputParticipants.add(CODER.decode(originalJson, Participant.class));
- inputParticipants.add(CODER.decode(originalJson2, Participant.class));
+ inputParticipants.add(CODER.decode(ORIGINAL_JSON, Participant.class));
+ inputParticipants.add(CODER.decode(ORIGINAL_JSON2, Participant.class));
}
@BeforeEach
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
index 0bec9d0ce..5f87db30c 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -36,6 +36,7 @@ import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AcPreparePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionMigrationPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
@@ -66,6 +67,8 @@ class SupervisionAcHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
+ when(automationCompositionProvider.updateAcState(any(AutomationComposition.class)))
+ .thenReturn(automationComposition);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()))
@@ -74,7 +77,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, acDefinitionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var automationCompositionAckMessage =
getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK,
@@ -82,7 +85,7 @@ class SupervisionAcHandlerTest {
handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
verify(automationCompositionProvider, times(3))
- .updateAutomationCompositionElement(any(AutomationCompositionElement.class), any());
+ .updateAutomationCompositionElement(any(AutomationCompositionElement.class));
}
private AutomationCompositionDeployAck getAutomationCompositionDeployAck(ParticipantMessageType messageType,
@@ -107,6 +110,8 @@ class SupervisionAcHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
+ when(automationCompositionProvider.updateAcState(any(AutomationComposition.class)))
+ .thenReturn(automationComposition);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()))
@@ -120,11 +125,11 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, acDefinitionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider).updateAcState(any(AutomationComposition.class));
}
@Test
@@ -157,12 +162,12 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher, null,
- null, mock(ParticipantSyncPublisher.class));
+ null, mock(ParticipantSyncPublisher.class), null);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
verify(automationCompositionProvider)
- .updateAutomationCompositionElement(any(AutomationCompositionElement.class), any());
+ .updateAutomationCompositionElement(any(AutomationCompositionElement.class));
}
@Test
@@ -171,7 +176,8 @@ class SupervisionAcHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
automationCompositionDeployPublisher, mock(AutomationCompositionStateChangePublisher.class),
- mock(AcElementPropertiesPublisher.class), null, mock(ParticipantSyncPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null,
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
@@ -191,7 +197,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -209,7 +215,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
@@ -230,7 +236,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -248,7 +254,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -268,7 +274,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -286,7 +292,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -317,12 +323,12 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
mock(AcElementPropertiesPublisher.class), null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
verify(automationCompositionProvider)
- .updateAutomationCompositionElement(any(AutomationCompositionElement.class), any());
+ .updateAutomationCompositionElement(any(AutomationCompositionElement.class));
}
@Test
@@ -331,7 +337,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(mock(AutomationCompositionProvider.class),
mock(AcDefinitionProvider.class), mock(AutomationCompositionDeployPublisher.class),
mock(AutomationCompositionStateChangePublisher.class), acElementPropertiesPublisher, null,
- mock(ParticipantSyncPublisher.class));
+ mock(ParticipantSyncPublisher.class), null);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
handler.update(automationComposition);
@@ -344,10 +350,47 @@ class SupervisionAcHandlerTest {
var acCompositionMigrationPublisher = mock(AutomationCompositionMigrationPublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AcDefinitionProvider.class),
null, null, null,
- acCompositionMigrationPublisher, mock(ParticipantSyncPublisher.class));
+ acCompositionMigrationPublisher, mock(ParticipantSyncPublisher.class), null);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate");
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ handler.migrate(automationComposition, serviceTemplate);
+ verify(acCompositionMigrationPublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt());
+ }
+
+ @Test
+ void testMigratePrecheck() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acCompositionMigrationPublisher = mock(AutomationCompositionMigrationPublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider, null, null, null,
+ null, acCompositionMigrationPublisher, null, null);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate");
+ handler.migratePrecheck(automationComposition);
+ verify(acCompositionMigrationPublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt());
+ }
+
+ @Test
+ void testPrepare() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acPreparePublisher = mock(AcPreparePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider, null, null, null,
+ null, null, null, acPreparePublisher);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate");
+ handler.prepare(automationComposition);
+ verify(acPreparePublisher, timeout(1000)).sendPrepare(any(AutomationComposition.class));
+ }
+
+ @Test
+ void testReview() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acPreparePublisher = mock(AcPreparePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider, null, null, null,
+ null, null, null, acPreparePublisher);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate");
- handler.migrate(automationComposition, UUID.randomUUID());
- verify(acCompositionMigrationPublisher, timeout(1000)).send(any(AutomationComposition.class), any());
+ handler.review(automationComposition);
+ verify(acPreparePublisher, timeout(1000)).sendRevew(any(AutomationComposition.class));
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index fa5929f0b..f7ccfe61e 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -102,7 +102,7 @@ class SupervisionScannerTest {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any());
}
@@ -114,7 +114,7 @@ class SupervisionScannerTest {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
// Ac Definition in Priming state
verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any());
@@ -122,7 +122,7 @@ class SupervisionScannerTest {
acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
// set Timeout
verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(),
@@ -165,7 +165,7 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
// not in transition
supervisionScanner.run();
@@ -186,6 +186,7 @@ class SupervisionScannerTest {
automationComposition.setCompositionId(compositionId);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.updateAcState(any())).thenReturn(automationComposition);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -193,10 +194,10 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider).updateAcState(any(AutomationComposition.class));
}
@Test
@@ -214,7 +215,7 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
verify(automationCompositionProvider).deleteAutomationComposition(automationComposition.getInstanceId());
@@ -233,7 +234,7 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
@@ -255,7 +256,7 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
-
+ when(automationCompositionProvider.updateAcState(any())).thenReturn(automationComposition);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
@@ -264,12 +265,12 @@ class SupervisionScannerTest {
// verify timeout scenario
var scannerObj2 = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
automationComposition.setLastMsg(TimestampHelper.now());
scannerObj2.run();
- verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider, times(1)).updateAcState(any(AutomationComposition.class));
assertEquals(StateChangeResult.TIMEOUT, automationComposition.getStateChangeResult());
//already in TIMEOUT
@@ -282,7 +283,7 @@ class SupervisionScannerTest {
entry.getValue().setDeployState(DeployState.DEPLOYED);
}
scannerObj2.run();
- verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider, times(1)).updateAcState(any(AutomationComposition.class));
assertEquals(StateChangeResult.NO_ERROR, automationComposition.getStateChangeResult());
}
@@ -313,7 +314,7 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
@@ -341,14 +342,20 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.updateAcState(any())).thenReturn(automationComposition);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
+ var definitionTarget = createAutomationCompositionDefinition(AcTypeState.PRIMED, StateChangeResult.NO_ERROR);
+ definitionTarget.setCompositionId(compositionTargetId);
+ var acDefinitionProvider = createAcDefinitionProvider();
+ when(acDefinitionProvider.getAcDefinition(compositionTargetId)).thenReturn(definitionTarget);
+
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
@@ -358,7 +365,7 @@ class SupervisionScannerTest {
automationComposition.getElements().entrySet().iterator().next().getValue()
.setDeployState(DeployState.DEPLOYED);
supervisionScanner.run();
- verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider, times(1)).updateAcState(any(AutomationComposition.class));
assertEquals(DeployState.DEPLOYED, automationComposition.getDeployState());
assertEquals(compositionTargetId, automationComposition.getCompositionId());
@@ -391,7 +398,7 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
- mock(ParticipantSyncPublisher.class), acRuntimeParameterGroup);
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
supervisionScanner.run();
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 7cf0bf84f..7fd0aa2e2 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -231,7 +231,29 @@ class SupervisionMessagesTest {
publisher.active(topicSink);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
- publisher.send(automationComposition, UUID.randomUUID());
+ publisher.send(automationComposition, 0);
+ verify(topicSink).send(anyString());
+ }
+
+ @Test
+ void testAcPreparePublisher() {
+ var publisher = new AcPreparePublisher();
+ var topicSink = mock(TopicSink.class);
+ publisher.active(topicSink);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ publisher.sendPrepare(automationComposition);
+ verify(topicSink).send(anyString());
+ }
+
+ @Test
+ void testAcReviewPublisher() {
+ var publisher = new AcPreparePublisher();
+ var topicSink = mock(TopicSink.class);
+ publisher.active(topicSink);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ publisher.sendRevew(automationComposition);
verify(topicSink).send(anyString());
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java
index 0df9719c2..9c765e1b3 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.runtime.util.rest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
@@ -45,6 +46,7 @@ public class CommonRestController {
public static final String ACTUATOR_ENDPOINT = CONTEXT_PATH + "/";
private static String httpPrefix;
+ protected Client client;
/**
* Verifies that an endpoint appears within the swagger response.
@@ -52,7 +54,7 @@ public class CommonRestController {
* @param endpoint the endpoint of interest
*/
protected void testSwagger(final String endpoint) {
- final var invocationBuilder = sendActRequest("v3/api-docs");
+ final var invocationBuilder = sendActRequest();
final var resp = invocationBuilder.get(String.class);
assertThat(resp).contains(endpoint);
@@ -71,15 +73,14 @@ public class CommonRestController {
/**
* Sends a request to an actuator endpoint.
*
- * @param endpoint the target endpoint
* @return a request builder
*/
- protected Invocation.Builder sendActRequest(final String endpoint) {
- return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, true);
+ protected Invocation.Builder sendActRequest() {
+ return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + "v3/api-docs", true);
}
/**
- * Sends a request to an Rest Api endpoint, without any authorization header.
+ * Sends a request to a Rest Api endpoint, without any authorization header.
*
* @param endpoint the target endpoint
* @return a request builder
@@ -89,16 +90,6 @@ public class CommonRestController {
}
/**
- * Sends a request to an actuator endpoint, without any authorization header.
- *
- * @param endpoint the target endpoint
- * @return a request builder
- */
- protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
- return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, false);
- }
-
- /**
* Sends a request to a fully qualified endpoint.
*
* @param fullyQualifiedEndpoint the fully qualified target endpoint
@@ -106,7 +97,7 @@ public class CommonRestController {
* @return a request builder
*/
protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
- final var client = ClientBuilder.newBuilder().build();
+ client = ClientBuilder.newBuilder().build();
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
client.register(GsonMessageBodyHandler.class);
@@ -124,11 +115,12 @@ public class CommonRestController {
* Assert that POST call is Unauthorized.
*
* @param endPoint the endpoint
- * @param entity the entity ofthe body
+ * @param entity the entity of the body
*/
protected void assertUnauthorizedPost(final String endPoint, final Entity<?> entity) {
var rawresp = sendNoAuthRequest(endPoint).post(entity);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
+ rawresp.close();
}
/**
@@ -140,6 +132,7 @@ public class CommonRestController {
protected void assertUnauthorizedPut(final String endPoint, final Entity<?> entity) {
var rawresp = sendNoAuthRequest(endPoint).put(entity);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
+ rawresp.close();
}
/**
@@ -150,16 +143,7 @@ public class CommonRestController {
protected void assertUnauthorizedGet(final String endPoint) {
var rawresp = sendNoAuthRequest(endPoint).buildGet().invoke();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
- }
-
- /**
- * Assert that GET call to actuator endpoint is Unauthorized.
- *
- * @param endPoint the endpoint
- */
- protected void assertUnauthorizedActGet(final String endPoint) {
- var rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
- assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
+ rawresp.close();
}
/**
@@ -170,6 +154,7 @@ public class CommonRestController {
protected void assertUnauthorizedDelete(final String endPoint) {
var rawresp = sendNoAuthRequest(endPoint).delete();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
+ rawresp.close();
}
/**
@@ -181,7 +166,4 @@ public class CommonRestController {
httpPrefix = "http://" + SELF + ":" + port + "/";
}
- protected String getHttpPrefix() {
- return httpPrefix;
- }
}
diff --git a/runtime-acm/src/test/resources/application-prometheus-noauth.yaml b/runtime-acm/src/test/resources/application-prometheus-noauth.yaml
index 57da3af18..a75c5d36f 100644
--- a/runtime-acm/src/test/resources/application-prometheus-noauth.yaml
+++ b/runtime-acm/src/test/resources/application-prometheus-noauth.yaml
@@ -10,37 +10,6 @@ spring:
ddl-auto: create
open-in-view: false
-server:
- servlet:
- context-path: /onap/policy/clamp/acm
-
-runtime:
- topics:
- operationTopic: policy-acruntime-participant
- syncTopic: acm-ppnt-sync
- participantParameters:
- updateParameters:
- maxRetryCount: 3
- topicParameterGroup:
- topicSources:
- -
- topic: ${runtime.topics.operationTopic}
- servers:
- - localhost
- topicCommInfrastructure: noop
- fetchTimeout: 15000
- topicSinks:
- -
- topicCommInfrastructure: noop
- servers:
- - localhost
- topic: ${runtime.topics.operationTopic}
-
- - topic: ${runtime.topics.syncTopic}
- servers:
- - ${topicServer:kafka:9092}
- topicCommInfrastructure: noop
-
tracing:
enabled: true
exporter:
diff --git a/runtime-acm/src/test/resources/application-test.yaml b/runtime-acm/src/test/resources/application-test.yaml
index 31e54737e..e3d4a48df 100644
--- a/runtime-acm/src/test/resources/application-test.yaml
+++ b/runtime-acm/src/test/resources/application-test.yaml
@@ -7,60 +7,5 @@ spring:
maximumPoolSize: 3
jpa:
hibernate:
- ddl-auto: create
+ ddl-auto: create-drop
open-in-view: false
-
-server:
- servlet:
- context-path: /onap/policy/clamp/acm
-
-runtime:
- topics:
- operationTopic: policy-acruntime-participant
- syncTopic: acm-ppnt-sync
- participantParameters:
- updateParameters:
- maxRetryCount: 3
- topicParameterGroup:
- topicSources:
- -
- topic: ${runtime.topics.operationTopic}
- servers:
- - kafka:9092
- topicCommInfrastructure: NOOP
- fetchTimeout: 15000
- topicSinks:
- -
- topicCommInfrastructure: NOOP
- servers:
- - kafka:9092
- topic: ${runtime.topics.operationTopic}
- -
- topic: ${runtime.topics.syncTopic}
- servers:
- - ${topicServer:kafka:9092}
- topicCommInfrastructure: NOOP
- acmParameters:
- acElementName: org.onap.policy.clamp.acm.AutomationCompositionElement
- acNodeType: org.onap.policy.clamp.acm.AutomationComposition
-
-management:
- endpoints:
- web:
- base-path: /
- exposure:
- include: health, metrics, prometheus
- tracing:
- propagation:
- produce: b3
- sampling:
- probability: 1.0
-
-tracing:
- enabled: true
- exporter:
- endpoint: http://jaeger:4317
- protocol: grpc
- sampler:
- jaeger-remote:
- endpoint: http://jaeger:14250 \ No newline at end of file
diff --git a/runtime-acm/src/test/resources/application-tracing.yaml b/runtime-acm/src/test/resources/application-tracing.yaml
new file mode 100644
index 000000000..d24fe9c53
--- /dev/null
+++ b/runtime-acm/src/test/resources/application-tracing.yaml
@@ -0,0 +1,27 @@
+spring:
+ datasource:
+ url: jdbc:h2:mem:testdb
+ driverClassName: org.h2.Driver
+ hikari:
+ maxLifetime: 1800000
+ maximumPoolSize: 3
+ jpa:
+ hibernate:
+ ddl-auto: create-drop
+ open-in-view: false
+
+management:
+ tracing:
+ propagation:
+ produce: b3
+ sampling:
+ probability: 1.0
+
+tracing:
+ enabled: true
+ exporter:
+ endpoint: http://jaeger:4317
+ protocol: grpc
+ sampler:
+ jaeger-remote:
+ endpoint: http://jaeger:14250 \ No newline at end of file
diff --git a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionMigrate.json b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionMigrate.json
new file mode 100644
index 000000000..d74970d4f
--- /dev/null
+++ b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionMigrate.json
@@ -0,0 +1,30 @@
+{
+ "name": "PMSHInstance1",
+ "version": "1.0.1",
+ "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40",
+ "deployState": "DEPLOYED",
+ "lockState": "LOCKED",
+ "description": "PMSH automation composition instance 0",
+ "elements": {
+ "709c62b3-8918-41b9-a747-d21eb79c6c21": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "definition": {
+ "name": "org.onap.domain.database.PMSH_K8SMicroserviceAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "deployState": "DEPLOYED",
+ "lockState": "LOCKED",
+ "description": "Automation composition element for the K8S microservice for PMSH"
+ },
+ "709c62b3-8918-41b9-a747-d21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "deployState": "DEPLOYED",
+ "lockState": "LOCKED",
+ "description": "Automation composition element for the operational policy for Performance Management Subscription Handling"
+ }
+ }
+} \ No newline at end of file
diff --git a/runtime-acm/src/test/resources/testscripts/listenOnTopic.sh b/runtime-acm/src/test/resources/testscripts/listenOnTopic.sh
deleted file mode 100755
index 5e661777b..000000000
--- a/runtime-acm/src/test/resources/testscripts/listenOnTopic.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#! /bin/bash
-# ============LICENSE_START=======================================================
-# Copyright (C) 2021 Nordix Foundation.
-# ================================================================================
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# SPDX-License-Identifier: Apache-2.0
-# ============LICENSE_END=========================================================
-
-if [ $# -ne 1 ]
-then
- echo invalid parameters $*, specify a single parameter as the topic to listen on
- exit 1
-fi
-
-while true
-do
- curl "http://localhost:3904/events/$1/TEST/1?timeout=60000"
- echo ""
-done
-