for (var element : automationComposition.getElements().values()) {
var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
.get(element.getDefinition().getName());
- int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ int startPhase = toscaNodeTemplate != null
+ && element.getDefinition().getVersion().equals(toscaNodeTemplate.getVersion())
+ ? ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()) : 0;
minStartPhase = Math.min(minStartPhase, startPhase);
maxStartPhase = Math.max(maxStartPhase, startPhase);
}
this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ UNDEPLOYING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
assertThat(result).isEqualTo(1);
}
+ @Test
+ void testGetFirstStartPhaseWithNull() 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);
+
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().values()
+ .forEach(node -> node.setVersion("0.0.0"));
+ 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).isZero();
+
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().clear();
+ 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).isZero();
+ }
+
@Test
void testGetFirstStage() throws CoderException {
var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.stereotype.Component;
var automationComposition = automationCompositions.get(instanceId);
var map = acElementsDefinitions.get(automationComposition.getCompositionId());
var element = automationComposition.getElements().get(acElementId);
- return map.get(element.getDefinition()).getAutomationCompositionElementToscaNodeTemplate().getProperties();
+ return getAcElementDefinition(map, element.getDefinition())
+ .getAutomationCompositionElementToscaNodeTemplate().getProperties();
}
/**
*/
public Map<String, Object> getCommonProperties(@NonNull UUID compositionId,
@NonNull ToscaConceptIdentifier definition) {
- return acElementsDefinitions.get(compositionId).get(definition)
- .getAutomationCompositionElementToscaNodeTemplate().getProperties();
+ return getAcElementDefinition(acElementsDefinitions.get(compositionId), definition)
+ .getAutomationCompositionElementToscaNodeTemplate().getProperties();
+ }
+
+ private AutomationCompositionElementDefinition getAcElementDefinition(
+ Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map,
+ ToscaConceptIdentifier definition) {
+ var nodeTemplate = map.get(definition);
+ if (nodeTemplate == null) {
+ nodeTemplate = new AutomationCompositionElementDefinition();
+ nodeTemplate.setAutomationCompositionElementToscaNodeTemplate(new ToscaNodeTemplate());
+ nodeTemplate.getAutomationCompositionElementToscaNodeTemplate().setProperties(new HashMap<>());
+ }
+ return nodeTemplate;
}
/**
*/
public CompositionElementDto createCompositionElementDto(UUID compositionId, AutomationCompositionElement element,
Map<String, Object> compositionInProperties) {
- var compositionOutProperties = getAcElementsDefinitions()
- .get(compositionId).get(element.getDefinition()).getOutProperties();
+ var compositionOutProperties = getAcElementDefinition(acElementsDefinitions
+ .get(compositionId), element.getDefinition()).getOutProperties();
return new CompositionElementDto(compositionId,
element.getDefinition(), compositionInProperties, compositionOutProperties);
}
var definitions = acElementsDefinitions.get(compositionId);
Map<UUID, CompositionElementDto> map = new HashMap<>();
for (var element : automationComposition.getElements().values()) {
- var definition = definitions.get(element.getDefinition());
+ var definition = getAcElementDefinition(definitions, element.getDefinition());
var compositionElement = (definition != null)
? new CompositionElementDto(compositionId, element.getDefinition(),
definition.getAutomationCompositionElementToscaNodeTemplate().getProperties(),
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> cacheProvider.getCommonProperties(instanceId, (UUID) null))
.isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> cacheProvider.getCommonProperties(null, instanceId))
+ .isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> cacheProvider.removeAutomationComposition(null))
.isInstanceOf(NullPointerException.class);
for (var element : automationComposition.getElements().values()) {
var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
.get(element.getDefinition().getName());
- int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ int startPhase = toscaNodeTemplate != null
+ && element.getDefinition().getVersion().equals(toscaNodeTemplate.getVersion())
+ ? ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()) : 0;
defaultMin = Math.min(defaultMin, startPhase);
defaultMax = Math.max(defaultMax, startPhase);
if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState(),
any(ToscaServiceTemplate.class), anyInt(), anyBoolean());
}
+ @Test
+ void testStartPhaseWithNull() {
+ var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
+ automationComposition.setPhase(0);
+ automationComposition.setLastMsg(TimestampHelper.now());
+ automationComposition.setCompositionId(compositionId);
+ for (var element : automationComposition.getElements().values()) {
+ if (ELEMENT_NAME.equals(element.getDefinition().getName())) {
+ element.setDeployState(DeployState.DEPLOYING);
+ element.getDefinition().setName("NotExistElement");
+ element.setLockState(LockState.NONE);
+ } else {
+ element.setDeployState(DeployState.DEPLOYING);
+ element.getDefinition().setVersion("0.0.0");
+ element.setLockState(LockState.NONE);
+ }
+ }
+
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
+
+ var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
+ mock(AutomationCompositionStateChangePublisher.class), automationCompositionDeployPublisher,
+ mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup);
+
+ supervisionScanner.run();
+
+ verify(automationCompositionDeployPublisher, times(0)).send(any(AutomationComposition.class),
+ any(ToscaServiceTemplate.class), anyInt(), anyBoolean());
+ }
+
@Test
void testSendAutomationCompositionMigrate() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");