How to use the brewtils.models.System function in brewtils

To help you get started, we’ve selected a few brewtils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beer-garden / beer-garden / src / app / beer_garden / router.py View on Github external
elif operation.operation_type.startswith("REQUEST"):
        request = db.query_unique(Request, id=operation.args[0])

        target_system = System(
            namespace=request.namespace,
            name=request.system,
            version=request.system_version,
        )

    elif operation.operation_type == "QUEUE_DELETE":
        # Need to deconstruct the queue name
        parts = operation.args[0].split(".")
        version = parts[2].replace("-", ".")

        target_system = System(namespace=parts[0], name=parts[1], version=version)

    return _garden_name_lookup(target_system)
github beer-garden / beer-garden / src / app / beer_garden / db / mongo / new_models.py View on Github external
"$status",
                    "$instance_name",
                ],
            },
        ],
    }

    logger = logging.getLogger(__name__)

    def save(self, *args, **kwargs):
        self.updated_at = datetime.datetime.utcnow()
        super(Request, self).save(*args, **kwargs)


class System(MongoModel, Document):
    brewtils_model = brewtils.models.System

    def deep_save(self):
        """Deep save. Saves Commands, Instances, and the System

        Mongoengine cannot save bidirectional references in one shot because
        'You can only reference documents once they have been saved to the database'
        So we must mangle the System to have no Commands, save it, save the individual
        Commands with the System reference, update the System with the Command list, and
        then save the System again
        """

        # Note if this system is already saved
        delete_on_error = self.id is None

        # Save these off here so we can 'revert' in case of an exception
        temp_commands = self.commands
github beer-garden / beer-garden / src / app / beer_garden / queue / rabbit.py View on Github external
def create(instance: Instance) -> dict:
    """Create request and admin queues for a given instance

    Args:
        instance: The instance to create queues for

    Returns:
        Dictionary describing the created queues
    """
    system = db.query_unique(System, instances__contains=instance)

    routing_words = [system.namespace, system.name, system.version, instance.name]
    request_queue_name = get_routing_key(*routing_words)
    clients["pika"].setup_queue(
        request_queue_name,
        {"durable": True, "arguments": {"x-max-priority": 1}},
        [request_queue_name],
    )

    suffix = [random.choice(string.ascii_lowercase + string.digits) for _ in range(10)]
    routing_words.append("".join(suffix))

    admin_keys = get_routing_keys(*routing_words, is_admin=True)
    admin_queue_name = admin_keys[-1]
    clients["pika"].setup_queue(admin_queue_name, {"durable": True}, admin_keys)
github beer-garden / beer-garden / src / app / beer_garden / local_plugins / manager.py View on Github external
def handle_associate(cls, event):
        runner_id = event.payload.metadata.get("runner_id")

        if runner_id:
            instance = event.payload
            system = db.query_unique(System, instances__contains=instance)

            runner = cls.from_runner_id(runner_id)
            runner.associate(system=system, instance=instance)
            runner.restart = True
github beer-garden / beer-garden / src / app / beer_garden / events / parent_http_processor.py View on Github external
def _build_system_from_instance(self, event):
        # Need to query DB for System Object
        system = db.query_unique(System, instances__contains=event.payload)
        return self._post("systems/", system)
github beer-garden / beer-garden / src / app / beer_garden / router.py View on Github external
or operation.operation_type in ("LOG_RELOAD", "SYSTEM_CREATE", "SYSTEM_RESCAN")
    ):
        return config.get("garden.name")

    # Otherwise, each operation needs to be "parsed"
    target_system = None

    if operation.operation_type in ("SYSTEM_DELETE", "SYSTEM_RELOAD", "SYSTEM_UPDATE"):
        target_system = db.query_unique(System, id=operation.args[0])

    elif "INSTANCE" in operation.operation_type:
        target_instance = db.query_unique(Instance, id=operation.args[0])
        target_system = db.query_unique(System, instances__contains=target_instance)

    elif operation.operation_type == "REQUEST_CREATE":
        target_system = System(
            namespace=operation.model.namespace,
            name=operation.model.system,
            version=operation.model.system_version,
        )

    elif operation.operation_type.startswith("REQUEST"):
        request = db.query_unique(Request, id=operation.args[0])

        target_system = System(
            namespace=request.namespace,
            name=request.system,
            version=request.system_version,
        )

    elif operation.operation_type == "QUEUE_DELETE":
        # Need to deconstruct the queue name
github beer-garden / beer-garden / src / app / beer_garden / queues.py View on Github external
def get_all_queue_info():
    """Get queue information for all queues

    :return size of the queue
    :raises Exception: If queue does not exist
    """
    queues = []
    systems = db.query(System)

    for system in systems:
        for instance in system.instances:
            queue_name = get_routing_key(
                system.namespace, system.name, system.version, instance.name
            )

            queue = Queue(
                name=queue_name,
                system=system.name,
                version=system.version,
                instance=instance.name,
                system_id=str(system.id),
                display=system.display_name,
                size=-1,
            )
github beer-garden / beer-garden / src / app / beer_garden / systems.py View on Github external
def remove_system(system_id: str) -> None:
    """Remove a system

    Args:
        system_id: The System ID

    Returns:
        None

    """
    system = db.query_unique(System, id=system_id)

    # Attempt to stop the plugins
    registered = beer_garden.application.plugin_registry.get_plugins_by_system(
        system.name, system.version
    )

    # Local plugins get stopped by us
    if registered:
        for plugin in registered:
            beer_garden.application.plugin_manager.stop_plugin(plugin)
            beer_garden.application.plugin_registry.remove(plugin.unique_name)

    # Remote plugins get a stop request
    else:
        beer_garden.application.clients["pika"].publish_request(
            beer_garden.stop_request,
github beer-garden / beer-garden / src / app / beer_garden / instances.py View on Github external
def start_instance(instance_id: str) -> Instance:
    """Starts an instance.

    Args:
        instance_id: The Instance ID

    Returns:
        The updated Instance
    """
    instance = db.query_unique(Instance, id=instance_id)
    system = db.query_unique(System, instances__contains=instance)

    logger.info(
        "Starting instance %s[%s]-%s", system.name, instance.name, system.version
    )

    beer_garden.application.plugin_manager.start_plugin(
        beer_garden.application.plugin_registry.get_plugin_from_instance_id(instance.id)
    )

    return instance
github beer-garden / beer-garden / src / app / beer_garden / db / sql / models.py View on Github external
sql_class,
                        "__table_args__",
                        getattr(sql_class, "__table_args__")
                        + (UniqueConstraint(*unique_args, name="unique_name")),
                    )
                else:
                    setattr(
                        sql_class,
                        "__table_args__",
                        (UniqueConstraint(*unique_args, name="unique_name")),
                    )


class System(Base):
    id = Column(sqlalchemy.Integer, primary_key=True)
    __tablename__ = brewtils.models.System.schema


class Instance(Base):
    id = Column(sqlalchemy.Integer, primary_key=True)
    __tablename__ = brewtils.models.Instance.schema


class Command(Base):
    id = Column(sqlalchemy.Integer, primary_key=True)
    __tablename__ = brewtils.models.Command.schema


class Parameter(Base):
    id = Column(sqlalchemy.Integer, primary_key=True)
    __tablename__ = brewtils.models.Parameter.schema