@NonNull
private SubState subState = SubState.NONE;
+ private Integer stage;
+
private String operationalState;
private String useState;
private String description;
this.subState = otherElement.subState;
this.operationalState = otherElement.operationalState;
this.useState = otherElement.useState;
+ this.stage = otherElement.stage;
this.message = otherElement.message;
}
}
/*-
* ============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.
package org.onap.policy.clamp.models.acm.concepts;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
}
return DeployState.DEPLOYING.equals(automationComposition.getDeployState())
- || LockState.UNLOCKING.equals(automationComposition.getLockState()) ? minStartPhase
- : maxStartPhase;
+ || LockState.UNLOCKING.equals(automationComposition.getLockState()) ? minStartPhase : maxStartPhase;
+ }
+
+ /**
+ * Get the First Stage.
+ *
+ * @param automationComposition the automation composition
+ * @param toscaServiceTemplate the ToscaServiceTemplate
+ * @return the First stage
+ */
+ public static int getFirstStage(
+ AutomationComposition automationComposition, ToscaServiceTemplate toscaServiceTemplate) {
+ Set<Integer> minStage = new HashSet<>();
+ for (var element : automationComposition.getElements().values()) {
+ var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ var stage = ParticipantUtils.findStageSet(toscaNodeTemplate.getProperties());
+ minStage.addAll(stage);
+ }
+ return minStage.stream().min(Integer::compare).orElse(0);
}
/**
public static int findStartPhase(Map<String, Object> properties) {
var objStartPhase = properties.get("startPhase");
if (objStartPhase != null) {
- return Integer.valueOf(objStartPhase.toString());
+ return Integer.parseInt(objStartPhase.toString());
}
return 0;
}
+
+
+ /**
+ * Finds stage from a map of properties.
+ *
+ * @param properties Map of properties
+ * @return stage
+ */
+ public static Set<Integer> findStageSet(Map<String, Object> properties) {
+ var objStage = properties.get("stage");
+ if (objStage instanceof List<?> stageSet) {
+ return stageSet.stream()
+ .map(obj -> Integer.valueOf(obj.toString()))
+ .collect(Collectors.toSet());
+ }
+ return Set.of(0);
+ }
}
public class AutomationCompositionDeployAck extends ParticipantAckMessage {
private UUID automationCompositionId;
- private Integer startPhase;
+ private Integer stage;
// A map with AutomationCompositionElementID as its key, and a pair of result and message as value per
// AutomationCompositionElement.
public AutomationCompositionDeployAck(final AutomationCompositionDeployAck source) {
super(source);
this.automationCompositionId = source.automationCompositionId;
- this.startPhase = source.startPhase;
+ this.stage = source.stage;
this.automationCompositionResultMap =
PfUtils.mapMap(source.automationCompositionResultMap, UnaryOperator.identity());
}
private List<ParticipantDeploy> participantUpdatesList = new ArrayList<>();
private Boolean precheck = false;
+ private Integer stage = 0;
public AutomationCompositionMigration() {
super(ParticipantMessageType.AUTOMATION_COMPOSITION_MIGRATION);
@Column
private String useState;
+ @Column
+ private Integer stage;
+
@Column
private String description;
this.subState = copyConcept.subState;
this.operationalState = copyConcept.operationalState;
this.useState = copyConcept.useState;
+ this.stage = copyConcept.stage;
this.message = copyConcept.message;
}
element.setSubState(subState);
element.setOperationalState(operationalState);
element.setUseState(useState);
+ element.setStage(stage);
element.setMessage(message);
return element;
this.subState = element.getSubState();
this.operationalState = element.getOperationalState();
this.useState = element.getUseState();
+ this.stage = element.getStage();
this.message = element.getMessage();
}
return result;
}
+ result = ObjectUtils.compare(stage, other.stage);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(operationalState, other.operationalState);
if (result != 0) {
return result;
jpaAcElement.setDeployState(element.getDeployState());
jpaAcElement.setLockState(element.getLockState());
jpaAcElement.setSubState(element.getSubState());
+ jpaAcElement.setStage(element.getStage());
jpaAcElement.setRestarting(element.getRestarting());
ProviderUtils.validate(element, jpaAcElement, "AutomationCompositionElement");
element.setLockState(lockState);
element.setSubState(subState);
element.setMessage(null);
+ element.setStage(null);
}
}
@Test
void testGetFirstStartPhase() throws CoderException {
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+ var automationComposition =
+ CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class)
+ .getAutomationCompositionList().get(0);
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
+ var result = ParticipantUtils.getFirstStartPhase(automationComposition, serviceTemplate);
+ assertThat(result).isZero();
+
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKING);
+ result = ParticipantUtils.getFirstStartPhase(automationComposition, serviceTemplate);
+ assertThat(result).isZero();
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
+ result = ParticipantUtils.getFirstStartPhase(automationComposition, serviceTemplate);
+ assertThat(result).isEqualTo(1);
+ }
+
+ @Test
+ void testGetFirstStage() throws CoderException {
var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
var automationCompositions =
CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class);
- var result = ParticipantUtils.getFirstStartPhase(automationCompositions.getAutomationCompositionList().get(0),
+ var result = ParticipantUtils.getFirstStage(automationCompositions.getAutomationCompositionList().get(0),
serviceTemplate);
assertThat(result).isZero();
}
testJpaAcElement.setOperationalState("DEFAULT");
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setStage(1);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setStage(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
testJpaAcElement.setMessage("Message");
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setMessage(null);
provider:
type: string
required: false
+ stage:
+ type: array
+ required: false
+ items:
+ type: integer
+ constraints:
+ - greater-or-equal: 0
+ metadata:
+ common: true
startPhase:
type: integer
required: false
description: Participant for DCAE microservices
properties:
provider: ONAP
+ startPhase: 0
org.onap.policy.acm.PolicyAutomationCompositionParticipant:
version: 2.3.1
type: org.onap.policy.clamp.acm.Participant
description: Participant for DCAE microservices
properties:
provider: ONAP
+ startPhase: 0
org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant:
version: 2.2.1
type: org.onap.policy.clamp.acm.Participant
description: Participant for DCAE microservices
properties:
provider: ONAP
+ startPhase: 1
org.onap.domain.pmsh.PMSH_DCAEMicroservice:
version: 1.2.3
type: org.onap.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElement
description: Automation composition element for the DCAE microservice for Performance Management Subscription Handling
properties:
provider: Ericsson
+ startPhase: 1
dcae_blueprint:
tosca_definitions_version: cloudify_dsl_1_3
imports:
version: 1.0.0
policy_id:
get_input: pmsh_monitoring_policy
+ stage: [0,1,2]
org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement:
version: 1.2.3
type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement