Cache merge timing on migrate
At the moment, the update of the properties in the cache at migrate time happens as soon as the participant receives the call. The participant may need to be aware of both the old properties and the new while it is carrying out checks and other processes.
@Override
public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, Map<String, Object> properties) throws PfModelException {
Current implementation
properties parameter contains the properties from migration POST
element.properties contains the properties from migration POST
The properties into elements that could be fetched by getAutomationComposition() method are the merge of old properties and properties from migration
Solution 1
Just using element.properties to hold the old properties.
properties contains the properties from migration POST
element.properties contains the old properties
The elements that could be fetched in cache are the merge of old properties and properties from migration
Solution 2
Hold the old properties in cache, and participant has to send an update methods for the merge with the new properties.
properties contains the properties from migration POST
element.properties contains the properties from migration POST
The properties into elements that could be fetched by getAutomationComposition() method are the old properties
participant calls a method to merge migrate properties
Solution 3
Refactor the migrate method.
Create two Document Transfer Object (using record) that contains all data:
public record CompositionElementDto(UUID compositionId, ToscaConceptIdentifier elementDefinitionId,
Map<String, Object> inProperties, Map<String, Object> outProperties) {
}
public record InstanceElementDto(UUID instanceId, UUID elementId, ToscaServiceTemplate toscaServiceTemplateFragment,
Map<String, Object> inProperties, Map<String, Object> outProperties) {
}
/**
* Migrate a automation composition element.
*
* @param compositionElement the old composition element, if new element elementDefinitionId will be null
* @param compositionElementTarget the composition element target, if removed element elementDefinitionId will be null
* @param instanceElement the old instance element, if new element elementId will be null
* @param instanceElementMigrate the instance element with removed properties, if new element elementId will be null
*/
@Override void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException {
}
Note:
The solution 3 will help the backward compatibility of the future versions.