return false;
}
+ private void sendAcInternalState(UUID instanceId, UUID elementId, Map<String, Object> outProperties,
+ DeployState deployState) {
+ outProperties.put(INTERNAL_STATE, deployState.name());
+ intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties);
+ }
+
/**
* Handle deploying an automation composition element.
*
* @param outProperties the outProperties
*/
public void deploy(UUID instanceId, UUID elementId, Map<String, Object> outProperties) {
+ sendAcInternalState(instanceId, elementId, outProperties, DeployState.DEPLOYING);
+
if (isInterrupted(getConfig().getDeployTimerMs(),
"Current Thread deploy is Interrupted during execution {}", elementId)) {
return;
}
if (getConfig().isDeploySuccess()) {
- outProperties.put(INTERNAL_STATE, DeployState.DEPLOYED.name());
- intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties);
+ sendAcInternalState(instanceId, elementId, outProperties, DeployState.DEPLOYED);
intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
} else {
- outProperties.put(INTERNAL_STATE, DeployState.UNDEPLOYED.name());
- intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties);
+ sendAcInternalState(instanceId, elementId, outProperties, DeployState.UNDEPLOYED);
intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!");
* @param outProperties the outProperties
*/
public void undeploy(UUID instanceId, UUID elementId, Map<String, Object> outProperties) {
+ sendAcInternalState(instanceId, elementId, outProperties, DeployState.UNDEPLOYING);
+
if (isInterrupted(getConfig().getUndeployTimerMs(),
"Current Thread undeploy is Interrupted during execution {}", elementId)) {
return;
}
if (getConfig().isUndeploySuccess()) {
- outProperties.put(INTERNAL_STATE, DeployState.UNDEPLOYED.name());
- intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties);
+ sendAcInternalState(instanceId, elementId, outProperties, DeployState.UNDEPLOYED);
intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
} else {
- outProperties.put(INTERNAL_STATE, DeployState.DEPLOYED.name());
- intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties);
+ sendAcInternalState(instanceId, elementId, outProperties, DeployState.DEPLOYED);
intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Undeploy failed!");
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.MessageProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
* @param acDefinition the AutomationCompositionDefinition
*/
public void deploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
- if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())) {
- automationComposition.setDeployState(DeployState.DEPLOYING);
+ if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
+ && DeployState.DEPLOYING.equals(automationComposition.getDeployState())
+ && automationComposition.getElements().size() > 1) {
+ automationComposition.setLastMsg(TimestampHelper.now());
for (var element : automationComposition.getElements().values()) {
if (!DeployState.DEPLOYED.equals(element.getDeployState())) {
element.setDeployState(DeployState.DEPLOYING);
* @param acDefinition the AutomationCompositionDefinition
*/
public void undeploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
- if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())) {
- automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
+ && DeployState.UNDEPLOYING.equals(automationComposition.getDeployState())
+ && automationComposition.getElements().size() > 1) {
+ automationComposition.setLastMsg(TimestampHelper.now());
for (var element : automationComposition.getElements().values()) {
if (!DeployState.UNDEPLOYED.equals(element.getDeployState())) {
element.setDeployState(DeployState.UNDEPLOYING);
+ element.setMessage(null);
}
}
} else {
* @param acDefinition the AutomationCompositionDefinition
*/
public void unlock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
- if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())) {
- automationComposition.setLockState(LockState.UNLOCKING);
+ if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
+ && LockState.UNLOCKING.equals(automationComposition.getLockState())
+ && automationComposition.getElements().size() > 1) {
+ automationComposition.setLastMsg(TimestampHelper.now());
for (var element : automationComposition.getElements().values()) {
if (!LockState.UNLOCKED.equals(element.getLockState())) {
element.setLockState(LockState.UNLOCKING);
* @param acDefinition the AutomationCompositionDefinition
*/
public void lock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
- if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())) {
- automationComposition.setLockState(LockState.LOCKING);
+ if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
+ && LockState.LOCKING.equals(automationComposition.getLockState())
+ && automationComposition.getElements().size() > 1) {
+ automationComposition.setLastMsg(TimestampHelper.now());
for (var element : automationComposition.getElements().values()) {
if (!LockState.LOCKED.equals(element.getLockState())) {
element.setLockState(LockState.LOCKING);
class SupervisionAcHandlerTest {
private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
+ private static final String AC_INSTANTIATION_SIMPLE_JSON =
+ "src/test/resources/rest/acm/AutomationCompositionSimple.json";
private static final UUID IDENTIFIER = UUID.randomUUID();
@Test
verify(messageProvider).save(any(AutomationCompositionDeployAck.class));
}
+ @Test
+ void testDeploy() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Deploy");
+ automationComposition.setDeployState(DeployState.UNDEPLOYED);
+ deploy(automationComposition);
+ }
+
@Test
void testDeployFailed() {
- var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = new SupervisionAcHandler(automationCompositionProvider,
- automationCompositionDeployPublisher, mock(AutomationCompositionStateChangePublisher.class),
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Deploy");
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.getElements().values()
+ .forEach(element -> element.setDeployState(DeployState.UNDEPLOYING));
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ deploy(automationComposition);
+
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values()
+ .forEach(element -> element.setDeployState(DeployState.DEPLOYING));
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.DEPLOYED);
+ deploy(automationComposition);
+ }
+
+ @Test
+ void testDeployFailedSimple() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_SIMPLE_JSON, "Deploy");
+ automationComposition.setDeployState(DeployState.UNDEPLOYED);
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.UNDEPLOYED);
+ deploy(automationComposition);
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.DEPLOYED);
+ deploy(automationComposition);
+
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.UNDEPLOYED);
+ deploy(automationComposition);
+ }
+
+ private void deploy(AutomationComposition automationComposition) {
+ var acDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var handler = new SupervisionAcHandler(acProvider, acDeployPublisher,
+ mock(AutomationCompositionStateChangePublisher.class),
mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class),
mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
-
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Deploy");
- automationComposition.setStateChangeResult(StateChangeResult.FAILED);
handler.deploy(automationComposition, acDefinition);
- verify(automationCompositionProvider).updateAutomationComposition(automationComposition);
- verify(automationCompositionDeployPublisher, timeout(1000)).send(automationComposition, 0, true);
+ verify(acProvider).updateAutomationComposition(automationComposition);
+ verify(acDeployPublisher, timeout(1000)).send(automationComposition, 0, true);
}
@Test
void testUndeploy() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Undeploy");
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ automationComposition.getElements().values()
+ .forEach(element -> element.setDeployState(DeployState.DEPLOYED));
+ undeploy(automationComposition);
+ }
+
+ private void undeploy(AutomationComposition automationComposition) {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Undeploy");
handler.undeploy(automationComposition, acDefinition);
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
@Test
void testUndeployFailed() {
- var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = new SupervisionAcHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class),
- mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
-
- var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnDeploy");
+ automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setStateChangeResult(StateChangeResult.FAILED);
automationComposition.getElements().values()
- .forEach(element -> element.setDeployState(DeployState.UNDEPLOYING));
- handler.undeploy(automationComposition, acDefinition);
- verify(automationCompositionProvider).updateAutomationComposition(automationComposition);
- verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ .forEach(element -> element.setDeployState(DeployState.UNDEPLOYED));
+ undeploy(automationComposition);
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values()
+ .forEach(element -> element.setDeployState(DeployState.DEPLOYING));
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.UNDEPLOYED);
+ undeploy(automationComposition);
+ }
+
+ @Test
+ void testUndeployFailedSimple() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_SIMPLE_JSON, "UnDeploy");
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.UNDEPLOYED);
+ undeploy(automationComposition);
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values().iterator().next().setDeployState(DeployState.DEPLOYED);
+ undeploy(automationComposition);
}
@Test
void testUnlock() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock");
+ automationComposition.setLockState(LockState.LOCKED);
+ automationComposition.getElements().values()
+ .forEach(element -> element.setLockState(LockState.LOCKED));
+ unlock(automationComposition);
+ }
+
+ private void unlock(AutomationComposition automationComposition) {
+ var acProvider = mock(AutomationCompositionProvider.class);
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = new SupervisionAcHandler(automationCompositionProvider,
+ var handler = new SupervisionAcHandler(acProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class),
mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock");
handler.unlock(automationComposition, acDefinition);
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acProvider).updateAutomationComposition(any(AutomationComposition.class));
verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean());
}
@Test
void testUnlockFailed() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = new SupervisionAcHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class),
- mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
- var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock");
automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.setLockState(LockState.LOCKING);
+ automationComposition.getElements().values().forEach(element -> element.setLockState(LockState.LOCKING));
+ unlock(automationComposition);
+
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.setLockState(LockState.UNLOCKING);
automationComposition.getElements().values().forEach(element -> element.setLockState(LockState.UNLOCKING));
- handler.unlock(automationComposition, acDefinition);
+ automationComposition.getElements().values().iterator().next().setLockState(LockState.UNLOCKED);
+ unlock(automationComposition);
+ }
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
- verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ @Test
+ void testUnlockSimple() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_SIMPLE_JSON, "UnLock");
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.setLockState(LockState.LOCKING);
+ automationComposition.getElements().values().iterator().next().setLockState(LockState.UNLOCKED);
+ unlock(automationComposition);
+
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.setLockState(LockState.UNLOCKING);
+ automationComposition.getElements().values().iterator().next().setLockState(LockState.LOCKED);
+ unlock(automationComposition);
}
@Test
void testLock() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
+ automationComposition.setLockState(LockState.UNLOCKED);
+ automationComposition.getElements().values().forEach(element -> element.setLockState(LockState.UNLOCKED));
+ lock(automationComposition);
+ }
+
+ private void lock(AutomationComposition automationComposition) {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
handler.lock(automationComposition, acDefinition);
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
@Test
void testLockFailed() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = new SupervisionAcHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class),
- mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class));
- var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
+ automationComposition.setLockState(LockState.UNLOCKING);
automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values().forEach(element -> element.setLockState(LockState.UNLOCKING));
+ lock(automationComposition);
+
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.setLockState(LockState.LOCKING);
automationComposition.getElements().values().forEach(element -> element.setLockState(LockState.LOCKING));
- handler.lock(automationComposition, acDefinition);
+ automationComposition.getElements().values().iterator().next().setLockState(LockState.LOCKED);
+ lock(automationComposition);
+ }
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
- verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ @Test
+ void testLockSimple() {
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_SIMPLE_JSON, "Lock");
+ automationComposition.setLockState(LockState.UNLOCKING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.getElements().values().iterator().next().setLockState(LockState.LOCKED);
+ lock(automationComposition);
+
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ automationComposition.setLockState(LockState.LOCKING);
+ automationComposition.getElements().values().iterator().next().setLockState(LockState.UNLOCKED);
+ lock(automationComposition);
}
@Test