Class ProcessInstanceMigrationPreconditions

java.lang.Object
io.camunda.zeebe.engine.processing.processinstance.ProcessInstanceMigrationPreconditions

public final class ProcessInstanceMigrationPreconditions extends Object
  • Constructor Details

    • ProcessInstanceMigrationPreconditions

      public ProcessInstanceMigrationPreconditions()
  • Method Details

    • requireNonNullProcessInstance

      public static void requireNonNullProcessInstance(ElementInstance record, long processInstanceKey)
      Checks whether the given record exists. Throws exception if given process instance record is null.
      Parameters:
      record - process instance record to do the null check
      processInstanceKey - process instance key to be logged
    • requireAuthorizedTenant

      public static void requireAuthorizedTenant(Map<String,Object> authorizations, String tenantId, long processInstanceKey)
      Checks whether given tenant is authorized for the process given instance.
      Parameters:
      authorizations - list of authorizations available
      tenantId - tenant id to be checked
      processInstanceKey - process instance key to be logged
    • requireNonNullTargetProcessDefinition

      public static void requireNonNullTargetProcessDefinition(DeployedProcess targetProcessDefinition, long targetProcessDefinitionKey)
      Checks whether the given target process definition exists. Throws exception if given target process definition is null.
      Parameters:
      targetProcessDefinition - target process definition to do the null check
      targetProcessDefinitionKey - target process definition key to be logged
    • requireNonDuplicateSourceElementIds

      public static void requireNonDuplicateSourceElementIds(List<ProcessInstanceMigrationRecordValue.ProcessInstanceMigrationMappingInstructionValue> mappingInstructions, long processInstanceKey)
      Checks whether the given mapping instructions contain duplicate source element ids. Throws an exception if duplicate source element ids are found.
      Parameters:
      mappingInstructions - mapping instructions to do the check
      processInstanceKey - process instance key to be logged
    • requireReferredElementsExist

      public static void requireReferredElementsExist(DeployedProcess sourceProcessDefinition, DeployedProcess targetProcessDefinition, List<ProcessInstanceMigrationRecordValue.ProcessInstanceMigrationMappingInstructionValue> mappingInstructions, long processInstanceKey)
      Checks whether the given mapping instructions refer to existing elements in the source and the target process definition. Throws an exception if any of the mapping instructions refers to a non-existing element.
      Parameters:
      sourceProcessDefinition - source process definition
      targetProcessDefinition - target process definition
      mappingInstructions - mapping instructions to do the check
      processInstanceKey - process instance key to be logged
    • requireNoEventSubprocessInSource

      public static void requireNoEventSubprocessInSource(DeployedProcess sourceProcessDefinition, ProcessInstanceRecord elementInstanceRecord, EnumSet<BpmnEventType> allowedEventTypes)
      Checks whether the given source process definition contains an event subprocess. Throws an exception if the source process definition contains an event subprocess that is not allowed.
      Parameters:
      sourceProcessDefinition - source process definition to do the check
      elementInstanceRecord - element instance to be logged
      allowedEventTypes - allowed event types for the boundary event
    • requireNoEventSubprocessInTarget

      public static void requireNoEventSubprocessInTarget(DeployedProcess targetProcessDefinition, String targetElementId, ProcessInstanceRecord elementInstanceRecord, EnumSet<BpmnEventType> allowedEventTypes)
      Checks whether the given target process definition contains an event subprocess. Throws an exception if the target process definition contains an event subprocess that is not allowed.
      Parameters:
      targetProcessDefinition - target process definition to do the check
      targetElementId - target element id to retrieve the target element
      elementInstanceRecord - element instance to be logged
      allowedEventTypes - allowed event types for the boundary event
    • requireSupportedElementType

      public static void requireSupportedElementType(ProcessInstanceRecord elementInstanceRecord, long processInstanceKey, DeployedProcess sourceProcessDefinition)
      Checks whether the given element instance is of a supported type. Throws an exception if the element instance is of an unsupported type.
      Parameters:
      elementInstanceRecord - element instance to do the check
      processInstanceKey - process instance key to be logged
    • requireNonNullTargetElementId

      public static void requireNonNullTargetElementId(String targetElementId, long processInstanceKey, String sourceElementId)
      Checks whether the given target element id exists. Throws an exception if the target element id is null.
      Parameters:
      targetElementId - target element id to do the null check
      processInstanceKey - process instance key to be logged
      sourceElementId - source element id to be logged
    • requireSameElementType

      public static void requireSameElementType(DeployedProcess targetProcessDefinition, String targetElementId, ElementInstance elementInstance, long processInstanceKey)
      Checks whether the given element instance has the same element type as the target element. Throws an exception if the element instance has a different type.
      Parameters:
      targetProcessDefinition - target process definition to retrieve the target element type
      targetElementId - target element id
      elementInstance - element instance to do the check
      processInstanceKey - process instance key to be logged
    • requireSameUserTaskImplementation

      public static void requireSameUserTaskImplementation(DeployedProcess targetProcessDefinition, String targetElementId, ElementInstance elementInstance, long processInstanceKey)
      Since we introduce zeebe user tasks and job worker tasks has the same bpmn element type, we need to check whether the given element instance and target element has the same user task type. Throws an exception if they have different types.
      Parameters:
      targetProcessDefinition - target process definition to retrieve the target element type
      targetElementId - target element id
      elementInstance - element instance to do the check
      processInstanceKey - process instance key to be logged
    • requireUnchangedFlowScope

      public static void requireUnchangedFlowScope(ElementInstanceState elementInstanceState, ProcessInstanceRecord elementInstanceRecord, DeployedProcess targetProcessDefinition, String targetElementId)
      Checks whether the given element instance has the same flow scope id as the target element. Throws an exception if the element instance has a different flow scope.
      Parameters:
      elementInstanceState - element instance state to retrieve the source flow scope element
      elementInstanceRecord - element instance to do the check
      targetProcessDefinition - target process definition to retrieve the target element
      targetElementId - target element id to retrieve the target flow scope
    • requireNoBoundaryEventInSource

      public static void requireNoBoundaryEventInSource(DeployedProcess sourceProcessDefinition, ProcessInstanceRecord elementInstanceRecord, EnumSet<BpmnEventType> allowedEventTypes)
      Checks whether the given source process definition contains a boundary event. Throws an exception if the source process definition contains a boundary event that is not allowed.
      Parameters:
      sourceProcessDefinition - source process definition to do the check
      elementInstanceRecord - element instance to be logged
      allowedEventTypes - allowed event types for the boundary event
    • requireNoBoundaryEventInTarget

      public static void requireNoBoundaryEventInTarget(DeployedProcess targetProcessDefinition, String targetElementId, ProcessInstanceRecord elementInstanceRecord, EnumSet<BpmnEventType> allowedEventTypes)
      Checks whether the given target process definition contains a boundary event. Throws an exception if the target process definition contains a boundary event.
      Parameters:
      targetProcessDefinition - target process definition to do the check
      targetElementId - target element id to retrieve the target element
      elementInstanceRecord - element instance to be logged
      allowedEventTypes - allowed event types for the boundary event
    • requireMappedCatchEventsToStayAttachedToSameElement

      public static void requireMappedCatchEventsToStayAttachedToSameElement(long processInstanceKey, DeployedProcess sourceProcessDefinition, DeployedProcess targetProcessDefinition, String sourceElementId, String targetElementId, Map<String,String> sourceElementIdToTargetElementId)
      It should not be possible for a mapped element's catch events to be moved to another element. This would mean an element instance is subscribed to a catch event that does not belong to this element. Triggering the catch event could lead to unexpected behavior.

      To avoid this, we check each catch event of the source element and ensure that they are mapped to a catch event on the target element. This check includes all catch events like boundary events, intermediate catch events, and start events (e.g. from event-subprocesses).

      Parameters:
      processInstanceKey - process instance key to be logged
      sourceProcessDefinition - source process definition to check
      targetProcessDefinition - target process definition to check
      sourceElementId - source element id to check
      targetElementId - target element id to check
      sourceElementIdToTargetElementId - mapping instructions (source element id to target
    • requireNoDuplicateTargetsInCatchEventMappings

      public static void requireNoDuplicateTargetsInCatchEventMappings(long processInstanceKey, DeployedProcess sourceProcessDefinition, String sourceElementId, Map<String,String> mappingInstructions)
      It should not be possible for a mapped element's catch events to be merged into a single catch event. This would mean an element instance is subscribed multiple times to the same catch event.

      To avoid this, we check each catch event attached to the source element and ensure that they are the target of a mapping instruction only once.

      Parameters:
      processInstanceKey - process instance key to be logged
      sourceProcessDefinition - source process definition to check
      sourceElementId - source element id to check
      mappingInstructions - mapping instructions (source element id to target element id)
    • requireNoCatchEventMappingToChangeEventType

      public static void requireNoCatchEventMappingToChangeEventType(long processInstanceKey, Map<String,String> mappingInstructions, DeployedProcess sourceProcessDefinition, DeployedProcess targetProcessDefinition, String sourceElementId)
      It should not be possible to change the event type of a catch event during process instance migration. This would mean that the catch event is subscribed to a different event type than before.
      Parameters:
      processInstanceKey - process instance key to be logged
      mappingInstructions - mapping instructions (source catch event id to target catch event id)
      sourceProcessDefinition - source process definition to check
      targetProcessDefinition - target process definition to check
      sourceElementId - source element id to check
    • requireNoConcurrentCommand

      public static void requireNoConcurrentCommand(EventScopeInstanceState eventScopeInstanceState, ElementInstance elementInstance, long processInstanceKey)
      Checks whether the given process instance has a concurrent command. Throws an exception if the given process instance has a concurrent command.

      Some concurrent commands are a job complete, a timer trigger, or a message correlation. Since the concurrent command modifies the process instance, it is not safe to apply the migration in between.

      Parameters:
      eventScopeInstanceState - event scope instance state to retrieve the event trigger
      elementInstance - element instance to do the check active sequence flows
      processInstanceKey - process instance key to be logged
    • requireNoSubscriptionForMessage

      public static void requireNoSubscriptionForMessage(boolean existSubscriptionForMessageName, ElementInstance elementInstance, org.agrona.DirectBuffer messageName, String targetCatchEventId)
      Throws an exception if the element instance is already subscribed to the same message.

      We cannot support re-subscribing to message catch events that we're already subscribed to. The user must provide a mapping instruction for such catch events to migrate them instead.

      Parameters:
      existSubscriptionForMessageName - whether the element instance is already subscribed to the message, if true this method throws an exception
      elementInstance - the element instance to check for subscriptions
      messageName - the name of the message that the element should not be subscribed to
      targetCatchEventId - the id of the catch event that would subscribe to this message
    • requireNoPendingMsgSubMigrationDistribution

      public static void requireNoPendingMsgSubMigrationDistribution(DistributionState distributionState, long distributionKey, String elementId, long processInstanceKey, String eventElementId)
      Throws an exception if the given message subscription distribution is pending.
      Parameters:
      distributionState - the distribution state to check for pending distributions
      distributionKey - the distribution key of the distribution that is being checked
      elementId - the element id of the element that is being migrated (for logging)
      processInstanceKey - the process instance key of the process instance that is being migrated (for logging)
      eventElementId - the element id of the event that is being migrated (for logging)
    • requireSameMultiInstanceLoopCharacteristics

      public static void requireSameMultiInstanceLoopCharacteristics(DeployedProcess sourceProcessDefinition, String sourceElementId, DeployedProcess targetProcessDefinition, String targetElementId, long processInstanceKey)