summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-02-02 15:42:56 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-02-03 09:25:32 +0000
commit4ad78088b7d1098f5529611eff15b1d61fc66a04 (patch)
tree7babd109983b2ac320eb5890342905b6397d7766 /runtime-acm/src/main
parent26814a2d839be880fa56c658f0d88940d957e872 (diff)
Handle AC Element Instance Deployment and undeployment on ACM-R
Part of the implementation related to Deployment and undeployment, missing part will be implemented in POLICY-4509. push-upstream: POLICY-4506 Change-Id: Ie7ad2da6c0a3286938fc4993d70ee71caee833ba Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/main')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java123
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java6
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java19
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java2
4 files changed, 59 insertions, 91 deletions
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 4949c6612..5281cb537 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
@@ -21,25 +21,20 @@
package org.onap.policy.clamp.acm.runtime.instantiation;
-import java.util.List;
import java.util.UUID;
-import java.util.function.Function;
-import java.util.stream.Collectors;
+import javax.validation.Valid;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
-import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
+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.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
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.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
@@ -55,14 +50,11 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
@AllArgsConstructor
public class AutomationCompositionInstantiationProvider {
- private static final String AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE = "AutomationCompositionElement";
private static final String DO_NOT_MATCH = " do not match with ";
private final AutomationCompositionProvider automationCompositionProvider;
- private final SupervisionHandler supervisionHandler;
- private final ParticipantProvider participantProvider;
private final AcDefinitionProvider acDefinitionProvider;
- private static final String ENTRY = "entry ";
+ private final AcInstanceStateResolver acInstanceStateResolver;
/**
* Create automation composition.
@@ -142,10 +134,24 @@ public class AutomationCompositionInstantiationProvider {
if (acDefinitionOpt.isEmpty()) {
result.addResult(new ObjectValidationResult("ServiceTemplate", "", ValidationStatus.INVALID,
"Commissioned automation composition definition not found"));
- } else {
- result.addResult(AcmUtils.validateAutomationComposition(automationComposition,
- acDefinitionOpt.get().getServiceTemplate()));
+ return result;
}
+ if (!AcTypeState.PRIMED.equals(acDefinitionOpt.get().getState())) {
+ result.addResult(new ObjectValidationResult("ServiceTemplate", "", ValidationStatus.INVALID,
+ "Commissioned automation composition definition not primed"));
+ return result;
+ }
+ result.addResult(AcmUtils.validateAutomationComposition(automationComposition,
+ acDefinitionOpt.get().getServiceTemplate()));
+
+ if (result.isValid()) {
+ for (var element : automationComposition.getElements().values()) {
+ var name = element.getDefinition().getName();
+ var participantId = acDefinitionOpt.get().getElementStateMap().get(name).getParticipantId();
+ element.setParticipantId(participantId);
+ }
+ }
+
return result;
}
@@ -208,61 +214,42 @@ public class AutomationCompositionInstantiationProvider {
}
/**
- * Issue a command to automation compositions, setting their ordered state.
+ * Handle Composition Instance State.
*
- * @param automationComposition the AutomationComposition
- * @param command the command to issue to automation compositions
+ * @param compositionId the compositionId
+ * @param instanceId the instanceId
+ * @param acInstanceStateUpdate the AcInstanceStateUpdate
*/
- public void issueAutomationCompositionCommand(AutomationComposition automationComposition,
- InstantiationCommand command) {
-
- if (command.getOrderedState() == null) {
- throw new AutomationCompositionRuntimeException(Status.BAD_REQUEST,
- "ordered state invalid or not specified on command");
- }
-
- var participants = participantProvider.getParticipants();
- if (participants.isEmpty()) {
- throw new AutomationCompositionRuntimeException(Status.BAD_REQUEST, "No participants registered");
- }
- var validationResult = validateIssueAutomationComposition(automationComposition, participants);
- if (!validationResult.isValid()) {
- throw new AutomationCompositionRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
- }
-
- automationComposition.setCascadedOrderedState(command.getOrderedState());
- try {
- supervisionHandler.triggerAutomationCompositionSupervision(automationComposition);
- } catch (AutomationCompositionException e) {
- throw new AutomationCompositionRuntimeException(Response.Status.BAD_REQUEST, e.getMessage());
+ public void compositionInstanceState(UUID compositionId, UUID instanceId,
+ @Valid AcInstanceStateUpdate acInstanceStateUpdate) {
+ var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
+ if (!compositionId.equals(automationComposition.getCompositionId())) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
- automationCompositionProvider.updateAutomationComposition(automationComposition);
- }
-
- private BeanValidationResult validateIssueAutomationComposition(AutomationComposition automationComposition,
- List<Participant> participants) {
- var result = new BeanValidationResult("AutomationComposition", automationComposition);
-
- var participantMap = participants.stream()
- .collect(Collectors.toMap(participant -> participant.getParticipantId(), Function.identity()));
-
- for (var element : automationComposition.getElements().values()) {
-
- var subResult = new BeanValidationResult(ENTRY + element.getDefinition().getName(), element);
- var p = participantMap.get(element.getParticipantId());
- if (p == null) {
- subResult.addResult(new ObjectValidationResult(AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE,
- element.getDefinition().getName(), ValidationStatus.INVALID,
- "Participant with ID " + element.getParticipantId() + " is not registered"));
- } else if (!p.getParticipantId().equals(element.getParticipantId())) {
- subResult.addResult(new ObjectValidationResult(AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE,
- element.getDefinition().getName(), ValidationStatus.INVALID,
- "Participant with ID " + " - " + element.getParticipantId()
- + " is not registered"));
- }
- result.addResult(subResult);
+ var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
+ var result = acInstanceStateResolver.resolve(acInstanceStateUpdate.getDeployOrder(),
+ acInstanceStateUpdate.getLockOrder(), automationComposition.getDeployState(),
+ automationComposition.getLockState());
+ switch (result) {
+ case "DEPLOY":
+ //
+ break;
+
+ case "UNDEPLOY":
+ //
+ break;
+
+ case "LOCK":
+ //
+ break;
+
+ case "UNLOCK":
+ //
+ break;
+
+ default:
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, "Not valid " + acInstanceStateUpdate);
}
-
- return result;
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
index 94c111e00..afe09314f 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -116,7 +116,7 @@ public class InstantiationController extends AbstractRestController implements A
@Override
public ResponseEntity<Void> compositionInstanceState(UUID compositionId, UUID instanceId,
@Valid AcInstanceStateUpdate body, UUID requestId) {
- // TODO Auto-generated method stub
- return null;
+ provider.compositionInstanceState(compositionId, instanceId, body);
+ return ResponseEntity.accepted().build();
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
index b31a95b18..db726e09d 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
@@ -141,7 +141,6 @@ public class SupervisionHandler {
if (automationComposition.isPresent()) {
var updated = updateState(automationComposition.get(),
automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet());
- updated |= setPrimed(automationComposition.get());
if (updated) {
automationCompositionProvider.updateAutomationComposition(automationComposition.get());
}
@@ -165,24 +164,6 @@ public class SupervisionHandler {
return updated;
}
- private boolean setPrimed(AutomationComposition automationComposition) {
- var acElements = automationComposition.getElements().values();
- if (acElements != null) {
- Boolean primedFlag = true;
- var checkOpt = automationComposition.getElements().values().stream()
- .filter(acElement -> (!acElement.getState().equals(AutomationCompositionState.PASSIVE)
- || !acElement.getState().equals(AutomationCompositionState.RUNNING)))
- .findAny();
- if (checkOpt.isEmpty()) {
- primedFlag = false;
- }
- automationComposition.setPrimed(primedFlag);
- return true;
- }
-
- return false;
- }
-
/**
* Supervise a automation composition, performing whatever actions need to be performed on the automation
* composition.
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 4a0abc180..0811a5a44 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
@@ -78,7 +78,7 @@ public class AutomationCompositionDeployPublisher extends AbstractParticipantPub
List<ParticipantDeploy> participantDeploys = new ArrayList<>();
for (var element : automationComposition.getElements().values()) {
- AcmUtils.setAcPolicyInfo(element, toscaServiceTemplate);
+ element.setToscaServiceTemplateFragment(AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate));
AcmUtils.prepareParticipantUpdate(element, participantDeploys);
}
acDeployMsg.setParticipantUpdatesList(participantDeploys);