Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleAcElementListenerV1
/**
 * Wrapper of AutomationCompositionElementListener.
 * Valid since 7.1.1 release.
 */
public abstract class AcElementListenerV1 implements AutomationCompositionElementListener {

    protected final ParticipantIntermediaryApi intermediaryApi;

    protected  AcElementListenerV1(ParticipantIntermediaryApi intermediaryApi) {
        this.intermediaryApi = intermediaryApi;
    }

    @Override
    public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        var element = new AcElementDeploy();
        element.setId(instanceElement.elementId());
        element.setDefinition(compositionElement.elementDefinitionId());
        element.setToscaServiceTemplateFragment(instanceElement.toscaServiceTemplateFragment());
        element.setProperties(instanceElement.inProperties());
        Map<String, Object> properties = new HashMap<>(instanceElement.inProperties());
        properties.putAll(compositionElement.inProperties());
        deploy(instanceElement.instanceId(), element, properties);
    }

    public abstract void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
        throws PfModelException;

    @Override
    public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        undeploy(instanceElement.instanceId(), instanceElement.elementId());
    }

    public abstract void undeploy(UUID instanceId, UUID elementId) throws PfModelException;

    @Override
    public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        lock(instanceElement.instanceId(), instanceElement.elementId());
    }

    public abstract void lock(UUID instanceId, UUID elementId) throws PfModelException;

    @Override
    public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        unlock(instanceElement.instanceId(), instanceElement.elementId());
    }

    public abstract void unlock(UUID instanceId, UUID elementId) throws PfModelException;

    @Override
    public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        delete(instanceElement.instanceId(), instanceElement.elementId());
    }

    public abstract void delete(UUID instanceId, UUID elementId) throws PfModelException;

    @Override
    public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
                       InstanceElementDto instanceElementUpdated) throws PfModelException {
        var element = new  AcElementDeploy();
        element.setId(instanceElementUpdated.elementId());
        element.setDefinition(compositionElement.elementDefinitionId());
        element.setProperties(instanceElementUpdated.inProperties());
        update(instanceElementUpdated.instanceId(), element, element.getProperties());
    }

    public abstract void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
        throws PfModelException;

    private List<AutomationCompositionElementDefinition> createAcElementDefinitionList(CompositionDto composition) {
        List<AutomationCompositionElementDefinition> elementDefinitionList = new ArrayList<>();
        for (var entry : composition.inPropertiesMap().entrySet()) {
            elementDefinitionList.add(createAcElementDefinition(entry.getKey(), entry.getValue(),
                composition.outPropertiesMap().get(entry.getKey())));
        }
        return elementDefinitionList;
    }

    private AutomationCompositionElementDefinition createAcElementDefinition(
        ToscaConceptIdentifier toscaConceptIdentifier, Map<String, Object> property,
        Map<String, Object> outProperties) {
        var acElementDefinition = new AutomationCompositionElementDefinition();
        acElementDefinition.setAcElementDefinitionId(toscaConceptIdentifier);
        var toscaNodeTemplate = new ToscaNodeTemplate();
        toscaNodeTemplate.setProperties(property);
        acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate);
        acElementDefinition.setOutProperties(outProperties);
        return acElementDefinition;
    }

    @Override
    public void prime(CompositionDto composition) throws PfModelException {
        prime(composition.compositionId(), createAcElementDefinitionList(composition));
    }

    public abstract void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
        throws PfModelException;

    @Override
    public void deprime(CompositionDto composition) throws PfModelException {
        deprime(composition.compositionId());
    }

    public abstract void deprime(UUID compositionId) throws PfModelException;

    @Override
    public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException {
        handleRestartComposition(composition.compositionId(), createAcElementDefinitionList(composition), state);
    }

    //public abstract void handleRestartComposition(UUID compositionId,
    //    List<AutomationCompositionElementDefinition> elementDefinitionList,
    //    AcTypeState state) throws PfModelException;

    public void handleRestartComposition(UUID compositionId,
        List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) throws PfModelException {
        switch List<AutomationCompositionElementDefinition> elementDefinitionList,(state) {
            case PRIMING -> prime(compositionId, elementDefinitionList);
            case DEPRIMING -> deprime(compositionId);
            default ->
      AcTypeState          intermediaryApi.updateCompositionState(compositionId, state) throws PfModelException;

    , StateChangeResult.NO_ERROR, "Restarted");
        }
    }

    @Override
    public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
        DeployState deployState, LockState lockState) throws PfModelException {
        var element = new  AcElementDeploy();
        element.setId(instanceElement.elementId());
        element.setDefinition(compositionElement.elementDefinitionId());
        element.setProperties(instanceElement.inProperties());
        Map<String, Object> properties = new HashMap<>(instanceElement.inProperties());
        properties.putAll(compositionElement.inProperties());
        handleRestartInstance(instanceElement.instanceId(), element, properties, deployState, lockState);
    }

    //public abstract void handleRestartInstance(UUID instanceId, AcElementDeploy element,
    //    Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException;

    @Override
    public void migratehandleRestartInstance(CompositionElementDtoUUID compositionElementinstanceId, CompositionElementDtoAcElementDeploy compositionElementTargetelement,
        InstanceElementDto instanceElementMap<String, Object> properties, DeployState deployState, InstanceElementDtoLockState instanceElementMigratelockState) throws PfModelException {

        if  var element = new  AcElementDeploy();
(DeployState.DEPLOYING.equals(deployState)) {
            deploy(instanceId, element.setId(instanceElement.elementId(), properties);
           element.setDefinition(compositionElement.elementDefinitionId());
 return;
        }
     element.setProperties(instanceElement.inProperties());   if (DeployState.UNDEPLOYING.equals(deployState)) {
        migrate(instanceElementMigrate.instanceId()    undeploy(instanceId, element, compositionElementTarget.compositionIdgetId(),);
            element.getProperties())return;
        }

    public abstract void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId,
if (DeployState.UPDATING.equals(deployState)) {
            update(instanceId, element, properties);
            return;
        }
 Map<String, Object> properties) throws PfModelException; 

  if  @Override(DeployState.DELETING.equals(deployState)) {
    public void migratePrecheck(CompositionElementDto compositionElement,
     delete(instanceId, element.getId());
     CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
    return;
    InstanceElementDto instanceElementMigrate) throws PfModelException {}

        if intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),(LockState.LOCKING.equals(lockState)) {
            instanceElementMigrate.elementIdlock()instanceId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR,
element.getId());
            return;
        }
      "Migrate precheck not supported");if (LockState.UNLOCKING.equals(lockState)) {
    }
}

Note: "migratePrecheck" is just an example and it will be not delivered in Q1.

Into participant-library will be an abstract class for each version that we would be code compatible; after a specific number of versions we can decide to deprecate the oldest abstract class and remove it in new version.

With that solution a Participant that was developed in Montreal release, could be use the wrapper "AcElementListenerV1" and do not need other changes.

Code Block
languagejava
titleAutomationCompositionElementHandler
@Component
public class AutomationCompositionElementHandler extends AcElementListenerV1 {

    public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi) {
        super(intermediaryApi);
    }

    @Override
    public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
            throws PfModelException {
----------

If participant needs the functionality of New Delhi version, they can use "AcElementListenerV2"

        unlock(instanceId, element.getId());
            return;
        }
        intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(),
            deployState, lockState, StateChangeResult.NO_ERROR, "Restarted");
    }

    @Override
    public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException {
        var element = new  AcElementDeploy();
        element.setId(instanceElement.elementId());
        element.setDefinition(compositionElement.elementDefinitionId());
        element.setProperties(instanceElement.inProperties());
        migrate(instanceElementMigrate.instanceId(), element, compositionElementTarget.compositionId(),
            element.getProperties());
    }

    public abstract void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId,
                                 Map<String, Object> properties) throws PfModelException; 

    @Override
    public void migratePrecheck(CompositionElementDto compositionElement,
        CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
        InstanceElementDto instanceElementMigrate) throws PfModelException {

        intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
            instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR,
            "Migrate precheck not supported");
    }
}

Note: "migratePrecheck" is just an example and it will be not delivered in Q1.

Into participant-library will be an abstract class for each version that we would be code compatible; after a specific number of versions we can decide to deprecate the oldest abstract class and remove it in new version.

With that solution a Participant that was developed in Montreal release, could be use the wrapper "AcElementListenerV1" and do not need other changes.

Code Block
languagejava
titleAutomationCompositionElementHandler
@Component
public class AutomationCompositionElementHandler extends AcElementListenerV1 {

    public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi) {
        super(intermediaryApi);
    }

    @Override
    public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
            throws PfModelException {
----------


If participant needs the functionality of New Delhi version, they can use "AcElementListenerV2"

Code Block
languagejava
titleAcElementListenerV2
/**
 * Wrapper of AutomationCompositionElementListener.
 * Valid since 7.1.2 release.
 */
public abstract class AcElementListenerV2 implements AutomationCompositionElementListener {
     private final ParticipantIntermediaryApi intermediaryApi;

    protected  AcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) {
        this.intermediaryApi = intermediaryApi;
    }

    @Override
    public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
            instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
    }

    @Override
    public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
        throws PfModelException {
        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
            instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
    }

    @Override
    public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException {
        switch (state) {
            case PRIMING -> prime(composition);
            case DEPRIMING -> deprime(composition);
            default ->
                intermediaryApi.updateCompositionState(composition.compositionId(), state, StateChangeResult.NO_ERROR, "Restarted");
        }
    }

    @Override
    public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
                                      DeployState deployState, LockState lockState) throws PfModelException {

        if (DeployState.DEPLOYING.equals(deployState)) {
            deploy(compositionElement, instanceElement);
            return;
        }
        if (DeployState.UNDEPLOYING.equals(deployState)) {
            undeploy(compositionElement, instanceElement);
            return;
        }
        if (DeployState.UPDATING.equals(deployState)) {
            update(compositionElement, instanceElement, instanceElement);
            return;
        }
        if (DeployState.DELETING.equals(deployState)) {
            delete(compositionElement, instanceElement);
            return;
        }
        if (LockState.LOCKING.equals(lockState)) {
            lock(compositionElement, instanceElement);
            return;
        }
        if (LockState.UNLOCKING.equals(lockState)) {
            unlock(compositionElement, instanceElement);
            return;
        }
        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(),
            deployState, lockState, StateChangeResult.NO_ERROR, "Restarted")
Code Block
languagejava
titleAcElementListenerV2
/**
 * Wrapper of AutomationCompositionElementListener.
 * Valid since 7.1.2 release.
 */
public abstract class AcElementListenerV2 implements AutomationCompositionElementListener {
     private final ParticipantIntermediaryApi intermediaryApi;

    protected  AcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) {
        this.intermediaryApi = intermediaryApi;
    }
  }