Idea: One place for orchestration priorities


#1

Hello,

the way we specify orchestration priorities today is terrible - there is the priority number which each orchestration implementation in core or plugins sets in local context to numbers like 1, 2, 5, 10 or 1000 when something should be called last. The problem with this is when creating or updating the code people tend to think locally not globally.

When orchestration framework sees a step with same priority (and we have many), it orders by enqueue time. Therefore order of execution depends on how ActiveRecord callbacks are called, which depends on how Rails loads source files and plugins. Essentially, renaming a plugin can possibly change ordering.

I suggest to create a list of priorities as constants or other form. The key thing is to have in single place, something like:

module Orchestration
  module Priority
    PRIORITY_CORE_DHCP_CREATE = 10
    PRIORITY_CORE_DHCP_REMOVE = 5
    PRIORITY_CORE_DHCP_RECREATE = 9
    PRIORITY_CORE_DHCP_CONFLICTS_REMOVE = 5

    PRIORITY_CORE_COMPUTE_RENDER_USERDATA = 2
    PRIORITY_CORE_COMPUTE_SET_INSTANCE = 3
    PRIORITY_CORE_COMPUTE_ACK_IP = 4
    PRIORITY_CORE_COMPUTE_QUERY_DETAILS = 5
    PRIORITY_CORE_COMPUTE_SET_IP = 6
    PRIORITY_CORE_COMPUTE_UPDATE = 7
    PRIORITY_CORE_COMPUTE_DESTROY = 100
    PRIORITY_CORE_COMPUTE_POWERUP = 1000

    PRIORITY_DISCOVERY_EDIT_HOST = 700
  end
end

These could be included into orchestration common class and reused across the codebase:

    queue.create(id: generate_dhcp_task_id("create"), name: _("Create DHCP Settings for %s") % self, priority: PRIORITY_CORE_DHCP_CREATE, action: [self, :set_dhcp]) if dhcp?

Once we gather all priorities from core and most plugins in a single place we can set those numbers accordingly to our needs making sure that things are really called in order for one and forever.

Opinions? Is this a good idea? Bad one?