示例#1
0
    def run(self, complect_revision_id):
        """
        Run deploy process
        :param complect_revision_id:
        :return:
        """

        # Check complect_revision_id exists
        if complect_revision_id is None:
            raise ApiError(code="COMPLECT_REVISION_ID",
                           message="Complect revision id can't be null")

        # Query complect revision information, we need Complect deploy_target
        complect_revision_response = post_request(
            url=PROCESSOR_HOST,
            headers=HEADERS,
            request_data=get_info_request(
                method="complect_revision.fetch",
                id=complect_revision_id,
            ))

        complect_revision_result = complect_revision_response["result"]
        if complect_revision_result.get("errors", {}).get("code") \
                is not None:
            raise ApiError(
                code=complect_revision_result["errors"]["code"],
                message=complect_revision_result["errors"]["message"],
            )

        # Query complect by complect_id
        complect_id = complect_revision_result["response"]["complect_id"]
        with self.create_session() as session:
            complect_model = session.query(Complect).get(complect_id)
            deploy_target = complect_model.deploy_target

        response = post_request(
            url=PROCESSOR_HOST,
            headers=HEADERS,
            request_data=get_create_request(
                method="task.create",
                script="scripts.deploy.run",
                type=self.TASK_TYPE,
                extra={"complect_revision_id": complect_revision_id},
                args={
                    "complect_revision_id": complect_revision_id,
                    "target": deploy_target,
                }))
        result = response["result"]

        if not result["status"]:
            raise ApiError(code="UNHANDLED",
                           message=result["errors"]["message"])

        return result["response"]
示例#2
0
    def _get_complect_revision_list(self, *, complect_id, offset, limit,
                                    order):
        result = post_request(url=PROCESSOR_HOST,
                              headers=HEADERS,
                              request_data=get_info_request(
                                  method="complect_revision.list",
                                  complect_id=complect_id,
                                  offset=offset,
                                  limit=limit,
                                  order=order))

        return result
示例#3
0
    def info(task_id):
        """
        Получение информации о задаче
        """
        result = post_request(
            url=PROCESSOR_HOST, headers=HEADERS,
            request_data=get_info_request(method="task.info", task_id=task_id)
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#4
0
    def result(task_id):
        """
        Получение результата по задаче
        """
        result = post_request(
            url=PROCESSOR_HOST, headers=None,
            request_data=get_info_request(method="task.info", task_id=task_id)
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(
            code="PROCESSOR_SERVICE", message=result["errors"]["message"]
        )
示例#5
0
    def result_list(offset=None, limit=None):
        """
        Получение списка задача/статус
        """
        result = post_request(
            url=PROCESSOR_HOST, headers=None,
            request_data=get_info_request(
                method="task.list", type=TYPE, offset=offset, limit=limit
            )
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#6
0
    def list_(cls, extra=None, offset=None, limit=None, order=None):
        """
        Get deploy task's list
        """
        result = post_request(url=PROCESSOR_HOST,
                              headers=HEADERS,
                              request_data=get_info_request(method="task.list",
                                                            type=cls.TASK_TYPE,
                                                            extra=extra,
                                                            offset=offset,
                                                            limit=limit,
                                                            order=order))

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#7
0
    def list_(extra=None, offset=None, limit=None, order=None):
        """
        Получение списка задач по типу
        """

        result = post_request(
            url=PROCESSOR_HOST, headers=HEADERS,
            request_data=get_info_request(
                method="task.list", type="compiler",
                extra=extra,
                offset=offset, limit=limit, order=order
            )
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])