Exemplo n.º 1
0
    def post(self):
        """Run the job in an ephemeral mapset

        :return:
        """

        try:
            # Empty the process location
            ActiniaInterface.PROCESS_LOCATION = {}
            process_graph = request.get_json()

            g = Graph(graph_description=process_graph)
            result_name, process_list = g.to_actinia_process_list()

            if len(ActiniaInterface.PROCESS_LOCATION) == 0 or len(
                    ActiniaInterface.PROCESS_LOCATION) > 1:
                msg = "Processes can only be defined for a single location!"
                status = 400
                es = ErrorSchema(id=str(datetime.now().isoformat()),
                                 code=status,
                                 message=str(msg))
                return make_response(es.to_json(), status)

            location = ActiniaInterface.PROCESS_LOCATION.keys()
            location = list(location)[0]

            process_chain = dict(list=process_list, version="1")

            status, response = self.iface.sync_ephemeral_processing_validation(
                location=location, process_chain=process_chain)

            if status == 200:
                errors = {"errors": []}
                return make_response(errors, 200)
            else:
                return ErrorSchema(
                    id=str(datetime.now().isoformat()),
                    code=status,
                    message=str(response)).as_response(http_status=status)

        except Exception as e:
            return ErrorSchema(id=str(datetime.now().isoformat()),
                               code=400,
                               message=str(e)).as_response(http_status=400)
    def __init__(self,
                 process_graph: ProcessGraphNode,
                 url: str,
                 type: str,
                 parameters: Dict,
                 attributes: Dict,
                 submitted: str = None,
                 title: str = None,
                 description: str = None,
                 enabled: bool = True,
                 plan: str = None,
                 costs: float = None,
                 budget: float = None):

        self.title = title
        self.description = description
        self.process_graph = process_graph
        self.url = url
        self.type = type
        self.enabled = enabled
        self.parameters = parameters
        self.attributes = attributes
        self.submitted = submitted
        self.plan = plan
        self.costs = costs
        self.budget = budget

        # Test id in pattern
        pattern = r"^[A-Za-z0-9_\-\.~]+$"
        x = re.search(pattern, id)
        if not x:
            es = ErrorSchema(
                id=str(datetime.now()),
                code=400,
                message="The id MUST match the following pattern: %s" %
                pattern)
            return make_response(es.to_json(), 400)
        self.id = id