示例#1
0
async def put_stack_instance(
    background_tasks: BackgroundTasks,
    stack_instance_update: StackInstanceUpdate,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager),
    redis=Depends(get_redis)):
    """
    Updates a stack instance by using a StackInstanceUpdate object
    """
    logger.info("[StackInstances PUT] Received PUT request")
    to_be_deleted = stack_manager.check_delete_services(stack_instance_update)
    (stack_instance, return_result) = stack_manager.process_stack_request(
        stack_instance_update, "update")
    if stack_instance is None:
        return HTTPException(422, return_result)

    # Perform invocations
    if not stack_instance_update.disable_invocation:
        for service in to_be_deleted:
            background_tasks.add_task(create_job_per_service, service,
                                      document_manager, "delete", redis,
                                      stack_instance, to_be_deleted)
        copy_stack_instance = stack_instance.copy(deep=True)
        delete_services(to_be_deleted, copy_stack_instance)
        background_tasks.add_task(create_job_for_agent, copy_stack_instance,
                                  "update", redis)

    document_manager.write_stack_instance(stack_instance)

    return return_result
示例#2
0
def add_outputs(
    outputs_update: OutputsUpdate,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager)):
    """
    Function used to add outputs to a stack instance
    Returns the updated stack_instance
    """
    stack_instance = stack_manager.add_outputs(outputs_update)
    document_manager.write_stack_instance(stack_instance)
    return stack_instance
示例#3
0
async def post_stack_instance(
    background_tasks: BackgroundTasks,
    stack_instance_invocation: StackInstanceInvocation,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager),
    redis=Depends(get_redis)):
    """Creates a stack instance with a specific name"""
    logger.info("[StackInstances POST] Received POST request")
    (stack_instance, return_result) = stack_manager.process_stack_request(
        stack_instance_invocation, "create")
    if stack_instance is None:
        return HTTPException(422, return_result)

    document_manager.write_stack_instance(stack_instance)
    # Perform invocations
    background_tasks.add_task(create_job_for_agent, stack_instance, "create",
                              redis)
    return return_result
示例#4
0
async def put_stack_instance(
    background_tasks: BackgroundTasks,
    stack_instance_update: StackInstanceUpdate,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager),
    redis=Depends(get_redis)):
    """
    Updates a stack instance by using a StackInstanceUpdate object
    """
    logger.info("[StackInstances PUT] Received PUT request")

    (stack_instance, return_result) = stack_manager.process_stack_request(
        stack_instance_update, "update")
    if stack_instance is None:
        return HTTPException(422, return_result)

    document_manager.write_stack_instance(stack_instance)

    # Perform invocations
    if not stack_instance_update.disable_invocation:
        background_tasks.add_task(create_job_for_agent, stack_instance,
                                  "update", document_manager, redis)

    return return_result
示例#5
0
"""Module for easy access to the managers"""
from arq import create_pool
from arq.connections import RedisSettings

from core import config
from core.manager.document_manager import DocumentManager
from core.manager.snapshot_manager import SnapshotManager
from core.manager.stack_manager import StackManager

document_manager = DocumentManager()
snapshot_manager = SnapshotManager()
stack_manager = StackManager()


def get_document_manager():
    """Returns the document manager"""
    return document_manager


def get_snapshot_manager():
    """Returns the snapshot manager"""
    return snapshot_manager


def get_stack_manager():
    """Returns the stack manager"""
    return stack_manager


async def get_redis():
    """Returns a Redis from the pool"""