Beispiel #1
0
    def test_openeo_usecase_1(self):

        g = Graph(USE_CASE_1)
        output_names, pc = g.to_actinia_process_list()
        pprint([str(o) for o in output_names])
        pprint(pc)
        self.assertEqual(len(pc), 9)
Beispiel #2
0
    def test_get_data_2(self):

        g = Graph(GET_DATA_2)
        output_names, pc = g.to_actinia_process_list()
        pprint([str(o) for o in output_names])
        pprint(pc)
        self.assertEqual(len(pc), 4)
Beispiel #3
0
    def send_actinia_processing_request(self, job: JobInformation):
        try:
            # Empty the process location
            ActiniaInterface.PROCESS_LOCATION = {}
            graph = Graph(job.process)
            result_name, process_list = graph.to_actinia_process_list()

            if len(ActiniaInterface.PROCESS_LOCATION) == 0 or len(
                    ActiniaInterface.PROCESS_LOCATION) > 1:
                raise Exception(
                    "Processes can only be defined for a single location!")

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

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

            # pprint.pprint(process_chain)

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

            return status, response
        except Exception:

            e_type, e_value, e_tb = sys.exc_info()
            traceback_model = dict(message=str(e_value),
                                   traceback=traceback.format_tb(e_tb),
                                   type=str(e_type))
            raise Exception(str(traceback_model))
Beispiel #4
0
    def test_filter_bbox(self):

        g = Graph(FILTER_BBOX)
        output_names, pc = g.to_actinia_process_list()
        pprint([str(o) for o in output_names])
        pprint(pc)
        self.assertEqual(len(pc), 3)
        self.assertTrue(pc[0]["module"] == "r.info")
        self.assertTrue(pc[1]["module"] == "g.region.bbox")
        self.assertTrue(pc[2]["module"] == "g.region.bbox")
Beispiel #5
0
    def test_get_data_3(self):

        g = Graph(GET_DATA_3)
        output_names, pc = g.to_actinia_process_list()
        pprint([str(o) for o in output_names])
        pprint(pc)
        self.assertEqual(len(pc), 3)
        self.assertTrue(pc[0]["module"] == "t.info")
        self.assertTrue(pc[1]["module"] == "g.region.bbox")
        self.assertTrue(pc[2]["module"] == "t.rast.extract")
Beispiel #6
0
    def test_daterange(self):

        g = Graph(DATERANGE)
        output_names, pc = g.to_actinia_process_list()
        pprint([str(o) for o in output_names])
        pprint(pc)
        self.assertEqual(len(pc), 4)
        self.assertTrue(pc[0]["module"] == "t.info")
        self.assertTrue(pc[1]["module"] == "g.region.bbox")
        self.assertTrue(pc[2]["module"] == "t.rast.extract")
        self.assertTrue(pc[3]["module"] == "t.rast.extract")
Beispiel #7
0
    def test_reduce_time_min(self):

        g = Graph(REDUCE_TIME_MIN)
        output_names, pc = g.to_actinia_process_list()
        pprint(output_names)
        pprint(pc)
        self.assertEqual(len(pc), 5)
        self.assertTrue(pc[0]["module"] == "t.info")
        self.assertTrue(pc[1]["module"] == "g.region.bbox")
        self.assertTrue(pc[2]["module"] == "t.rast.extract")
        self.assertTrue(pc[3]["module"] == "t.rast.series")
Beispiel #8
0
    def test_ndvi_1(self):

        g = Graph(NDVI_STRDS)
        output_names, pc = g.to_actinia_process_list()
        pprint([str(o) for o in output_names])
        pprint(pc)
        self.assertEqual(len(pc), 5)
        self.assertTrue(pc[0]["module"] == "t.info")
        self.assertTrue(pc[1]["module"] == "g.region.bbox")
        self.assertTrue(pc[2]["module"] == "t.rast.extract")
        self.assertTrue(pc[3]["module"] == "t.rast.ndvi")
        self.assertTrue(pc[4]["module"] == "t.rast.colors")
        strlen = len("lsat5_1987_load_collection_ndvi")
        # first part of name is uuid<uuid>_
        self.assertTrue("lsat5_1987_load_collection_ndvi" in
                        [o.name[-strlen:] for o in output_names])
Beispiel #9
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 post(self):
        """Run the job in an ephemeral mapset synchronously for 10 seconds.
        After 10 seconds the running job
        will be killed on the actinia server and the response will be an
        termination report.
        """

        try:
            # Empty the process location
            ActiniaInterface.PROCESS_LOCATION = {}
            request_doc = request.get_json()
            g = Graph(graph_description=request_doc)
            result_name, process_list = g.to_actinia_process_list()

            if len(ActiniaInterface.PROCESS_LOCATION) == 0 or len(
                    ActiniaInterface.PROCESS_LOCATION) > 1:
                descr = "Processes can only be defined for a single location!"
                return make_response(jsonify({"description": descr}, 400))

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

            if location == "stac":
                location = "latlong_wgs84"

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

            status, response = self.iface.async_ephemeral_processing_export(
                location=location, process_chain=process_chain)
            status, response = self.wait_until_finished(response=response,
                                                        max_time=1000)

            if status == 200:
                result_url = response["urls"]["resources"]
                if len(result_url) == 1:
                    # attempt to return an image
                    result_data = self.iface.get_resource(result_url[0])
                    if result_url[0][-4:] in ("tiff", ".tif"):
                        mimetype = "image/tiff"
                    else:
                        mimetype = "unknown"

                    return Response(result_data.content,
                                    mimetype=mimetype,
                                    direct_passthrough=True)

                return make_response(
                    jsonify({
                        "job_id": response["resource_id"],
                        "job_info": response
                    }), status)
            else:
                return ErrorSchema(
                    id="1234567890",
                    code=404,
                    message=str(response),
                    links=response["urls"]["status"]).as_response(status)
        except Exception:

            e_type, e_value, e_tb = sys.exc_info()
            traceback_model = dict(message=str(e_value),
                                   traceback=traceback.format_tb(e_tb),
                                   type=str(e_type))
            return ErrorSchema(id="1234567890",
                               code=404,
                               message=str(traceback_model)).as_response(404)