/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2025 Nordix Foundation.
+ * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// State of the AutomationCompositionElement
private LockState lockState;
+ private MigrationState migrationState;
private String operationalState;
private String useState;
this.participantId = otherElement.participantId;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.migrationState = otherElement.migrationState;
this.operationalState = otherElement.operationalState;
this.useState = otherElement.useState;
this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
+ ", participantId=" + participantId
+ ", deployState=" + deployState
+ ", lockState=" + lockState
+ + ", migrationState=" + migrationState
+ ", operationalState='" + operationalState + '\''
+ ", useState='" + useState + '\''
+ ", toscaServiceTemplateFragment=" + toscaServiceTemplateFragment
private LockState lockState;
private StateChangeResult stateChangeResult;
private UUID revisionId;
+ private UUID compositionTargetId;
private List<AcElementRestart> acElementList = new ArrayList<>();
this.stateChangeResult = copyConstructor.stateChangeResult;
this.revisionId = copyConstructor.revisionId;
this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementRestart::new);
+ this.compositionTargetId = copyConstructor.compositionTargetId;
}
}
syncAc.setDeployState(automationComposition.getDeployState());
syncAc.setLockState(automationComposition.getLockState());
syncAc.setAutomationCompositionId(automationComposition.getInstanceId());
+ syncAc.setCompositionTargetId(automationComposition.getCompositionTargetId());
for (var element : automationComposition.getElements().values()) {
if (participantId.equals(element.getParticipantId())) {
var acElementSync = createAcElementRestart(element);
acElementRestart.setParticipantId(element.getParticipantId());
acElementRestart.setDeployState(element.getDeployState());
acElementRestart.setLockState(element.getLockState());
+ acElementRestart.setMigrationState(element.getMigrationState());
acElementRestart.setOperationalState(element.getOperationalState());
acElementRestart.setUseState(element.getUseState());
acElementRestart.setProperties(PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()));
LOGGER.debug("new element scenario");
}
if (ElementState.REMOVED.equals(instanceElementRollback.state())) {
- simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId(),
- instanceElement.outProperties());
- simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
+ simulatorService.deleteInRollback(instanceElement.instanceId(), instanceElement.elementId());
} else {
simulatorService.rollback(instanceElementRollback.instanceId(), instanceElementRollback.elementId(), stage,
compositionElementRollback.inProperties(), instanceElementRollback.outProperties());
public void deleteInMigration(UUID instanceId, UUID elementId) {
if (getConfig().isMigrateSuccess()) {
intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
} else {
intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Delete failed!");
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Migration - Delete failed!");
+ }
+ }
+
+ /**
+ * Handle deleting an automation composition element in rollback.
+ *
+ * @param instanceId the instanceId
+ * @param elementId the elementId
+ */
+ public void deleteInRollback(UUID instanceId, UUID elementId) {
+ if (getConfig().isRollback()) {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Rollback - Delete failed!");
}
}
.migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove, 0);
verify(intermediaryApi).updateAutomationCompositionElementState(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
}
@Test
.rollbackMigration(COMPOSITION_ELEMENT, compoElRollbackRemove, INSTANCE_ELEMENT, inElRollbackRemove, 0);
verify(intermediaryApi).updateAutomationCompositionElementState(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
- verify(intermediaryApi).updateAutomationCompositionElementState(
- INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
}
}
var elementId = UUID.randomUUID();
simulatorService.deleteInMigration(instanceId, elementId);
verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
simulatorService.getConfig().setMigrateSuccess(false);
simulatorService.deleteInMigration(instanceId, elementId);
verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Delete failed!");
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Migration - Delete failed!");
+ }
+
+
+ @Test
+ void testDeleteInRollback() {
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var instanceId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ simulatorService.deleteInRollback(instanceId, elementId);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
+
+ simulatorService.getConfig().setRollback(false);
+ simulatorService.deleteInRollback(instanceId, elementId);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Rollback - Delete failed!");
}
}
acStateChangeAck.setStateChangeResult(stateChangeResult);
acStateChangeAck.setAutomationCompositionId(instance);
acStateChangeAck.getAutomationCompositionResultMap().put(elementId,
- new AcElementDeployAck(deployState, null, null,
+ new AcElementDeployAck(deployState, LockState.NONE, null,
null, Map.of(), true, message));
LOGGER.debug(MSG_STATE_CHANGE, elementId, deployState);
publisher.sendAutomationCompositionAck(acStateChangeAck);
var automationComposition = new AutomationComposition();
automationComposition.setCompositionId(compositionId);
+ automationComposition.setCompositionTargetId(participantRestartAc.getCompositionTargetId());
automationComposition.setDeployState(participantRestartAc.getDeployState());
automationComposition.setLockState(participantRestartAc.getLockState());
automationComposition.setInstanceId(participantRestartAc.getAutomationCompositionId());
message.setMessageId(UUID.randomUUID());
message.setTimestamp(Instant.now());
var syncAc = new ParticipantRestartAc();
+ syncAc.setCompositionTargetId(automationComposition.getCompositionTargetId());
syncAc.setAutomationCompositionId(automationComposition.getInstanceId());
syncAc.setRevisionId(automationComposition.getRevisionId());
syncAc.setDeployState(automationComposition.getDeployState());