コード例 #1
0
 def get(self, user, execution_identifier):
     execution_db = get_execution(execution_identifier, db.session)
     execution, error = get_execution_as_model(user.username, execution_db)
     if error:
         return ErrorCodeAndMessageFormatter(EXECUTION_NOT_FOUND,
                                             execution_identifier)
     return execution
コード例 #2
0
    def test_put_valid_execution_name(self, test_client, session,
                                      execution_id):
        response = test_client.put('/executions/{}'.format(execution_id),
                                   headers={"apiKey": standard_user().api_key},
                                   data=json.dumps(PATCH_VALID_EXECUTION2))
        assert response.status_code == 204

        execution = session.query(ExecutionDB).filter_by(
            identifier=execution_id).first()
        execution, _ = get_execution_as_model(standard_user().username,
                                              execution)
        assert execution.name == PATCH_VALID_EXECUTION2["name"]
コード例 #3
0
    def test_put_parameter_no_change(self, test_client, session, execution_id):
        response = test_client.put('/executions/{}'.format(execution_id),
                                   headers={"apiKey": standard_user().api_key},
                                   data=json.dumps(PATCH_NO_CHANGE_PARAMETER))
        assert response.status_code == 204

        execution = session.query(ExecutionDB).filter_by(
            identifier=execution_id).first()
        execution, _ = get_execution_as_model(standard_user().username,
                                              execution)
        assert (execution.pipeline_identifier !=
                PATCH_NO_CHANGE_PARAMETER["pipelineIdentifier"])
コード例 #4
0
    def get(self, user):
        offset = request.args.get('offset', type=query_converter)
        limit = request.args.get(
            'limit', type=query_converter) or PLATFORM_PROPERTIES.get(
                'defaultLimitListExecutions')
        user_executions = get_all_executions_for_user(user.username, limit,
                                                      offset, db.session)
        for i, execution in enumerate(user_executions):
            exe, error = get_execution_as_model(user.username, execution)
            if error:
                return error
            user_executions[i] = exe

        return user_executions
コード例 #5
0
    def put(self, user, execution_identifier):
        execution_db = get_execution(execution_identifier, db.session)
        if not execution_db:
            return ErrorCodeAndMessageFormatter(EXECUTION_NOT_FOUND,
                                                execution_identifier)
        if execution_db.creator_username != user.username:
            return UNAUTHORIZED

        if execution_db.status != ExecutionStatus.Initializing:
            return ErrorCodeAndMessageFormatter(CANNOT_REPLAY_EXECUTION,
                                                execution_db.status.name)

        execution, error = get_execution_as_model(user.username, execution_db)
        if error:
            return CORRUPTED_EXECUTION

        # Get the descriptor path
        descriptor_path = get_descriptor_path(user.username,
                                              execution.identifier)

        # Get appriopriate descriptor object
        descriptor = Descriptor.descriptor_factory_from_type(
            execution_db.descriptor)

        if not descriptor:
            # We don't have any descriptor defined for this pipeline type
            logger = logging.getLogger('server-error')
            logger.error(
                "Unsupported descriptor type extracted from file at {}".format(
                    descriptor_path))
            return ErrorCodeAndMessageFormatter(UNSUPPORTED_DESCRIPTOR_TYPE,
                                                execution_db.descriptor)

        modified_inputs_path = get_absolute_path_inputs_path(
            user.username, execution.identifier)
        if not os.path.isfile(modified_inputs_path):
            logger = logging.getLogger('server-error')
            logger.error("Absolute path inputs file not found at {}".format(
                descriptor_path))
            return UNEXPECTED_ERROR

        # The execution is valid and we are now ready to start it
        start_execution(user, execution, descriptor, modified_inputs_path)
コード例 #6
0
def std_file_resource(user, execution_identifier, path_to_file):
    execution_db = get_execution(execution_identifier, db.session)
    if not execution_db:
        error = ErrorCodeAndMessageFormatter(EXECUTION_NOT_FOUND,
                                             execution_identifier)
        return marshal(error), 400

    if not is_safe_for_get(user, execution_db):
        return UNAUTHORIZED

    execution, error = get_execution_as_model(execution_db.creator_username,
                                              execution_db)
    if error:
        return marshal(error), 400

    std, error = get_std_file(user.username, execution_identifier,
                              path_to_file)
    if error:
        return marshal(error), 400

    return Response(std, mimetype='text/plain')
コード例 #7
0
    def post(self, model, user):
        _, error = validate_request_model(model, request.url_root)
        if error:
            return error

        try:
            # Get the descriptor path and type
            (descriptor_path,
             descriptor_type), error = get_original_descriptor_path_and_type(
                 model.pipeline_identifier)
            if error:
                return error

            # Insert new execution to DB
            new_execution = Execution(
                name=model.name,
                pipeline_identifier=model.pipeline_identifier,
                descriptor=descriptor_type,
                timeout=model.timeout,
                status=ExecutionStatus.Initializing,
                study_identifier=model.study_identifier,
                creator_username=user.username)
            db.session.add(new_execution)
            db.session.commit()

            # Execution directory creation
            (execution_path,
             carmin_files_path), error = create_execution_directory(
                 new_execution, user)
            if error:
                db.session.rollback()
                return error

            # Writing inputs to inputs file in execution directory
            error = write_inputs_to_file(model, carmin_files_path)
            if error:
                delete_execution_directory(execution_path)
                db.session.rollback()
                return error

            # Copying pipeline descriptor to execution folder
            error = copy_descriptor_to_execution_dir(carmin_files_path,
                                                     descriptor_path)
            if error:
                delete_execution_directory(execution_path)
                db.session.rollback()
                return UNEXPECTED_ERROR

            # Get appriopriate descriptor object
            descriptor = Descriptor.descriptor_factory_from_type(
                new_execution.descriptor)
            if not descriptor:
                delete_execution_directory(execution_path)
                db.session.rollback()
                # We don't have any descriptor defined for this pipeline type
                logger = logging.getLogger('server-error')
                logger.error(
                    "Unsupported descriptor type extracted from file at {}".
                    format(descriptor_path))
                return ErrorCodeAndMessageFormatter(
                    UNSUPPORTED_DESCRIPTOR_TYPE, descriptor_type)

            # Create a version of the inputs file with correct links
            modified_inputs_path, error = create_absolute_path_inputs(
                user.username, new_execution.identifier,
                new_execution.pipeline_identifier, request.url_root)
            if error:
                delete_execution_directory(execution_path)
                db.session.rollback()
                return UNEXPECTED_ERROR

            # We now validate the invocation
            success, error = descriptor.validate(descriptor_path,
                                                 modified_inputs_path)
            if not success:  # If this fails, we will change the execution status to InitializationFailed and return this error
                new_execution.status = ExecutionStatus.InitializationFailed
                db.session.commit()
                error_code_and_message = ErrorCodeAndMessageFormatter(
                    INVOCATION_INITIALIZATION_FAILED, new_execution.identifier)
                return ErrorCodeAndMessageAdditionalDetails(
                    error_code_and_message, str(error))

            # Get execution from DB (for safe measure)
            execution_db = get_execution(new_execution.identifier, db.session)
            if not execution_db:
                return UNEXPECTED_ERROR

            # Get execution back as a model from the DB for response
            execution, error = get_execution_as_model(user.username,
                                                      execution_db)
            if error:
                return UNEXPECTED_ERROR
            return execution
        except IntegrityError:
            db.session.rollback()