def retrieve(self, pipelineId):
     print(colored("Ragnar image search retrieval start", color='blue'))
     retr = Task(self.loop)
     retrieved = retr.do_the_task(
         self.RAGNAR_URL + "/imagery/search/retrieve", headers,
         json.dumps({"pipelineId": pipelineId}))
     assert retrieved[0].get('results'), print(
         colored("Error, Ragnar image retrieval failed", color='red'))
     self.retr_results = retrieved[0]
     print(
         colored("Ragnar image search retrieval OK, metadata saved to:\n{}".
                 format(self.path_RESULTS),
                 color='green'))
     write_json(self.retr_results,
                self.path_RESULTS + "Ragnar_retrieved_results.json")
    def initialize(self):
        print(colored("Ragnar image search initialization start",
                      color='blue'))
        init = Task(self.loop)
        search = init.do_the_task(self.RAGNAR_URL + "/imagery/search/initiate",
                                  headers, json.dumps(self.imagery))

        assert search[0].get('pipelineId'),\
            print(colored("Error, Ragnar image search failed: {}".format(str(search[0])), color='red'))

        result = init.wait_till_resolved(
            headers, json.dumps({"pipelineId": search[0]['pipelineId']}))
        assert result == 'RESOLVED',\
            print(colored("Error, Ragnar image search failed, pipelineId: {}".format(result), color='red'))

        self.pipelineId = search[0]['pipelineId']
        print(colored("Ragnar image search initialization OK", color='green'))
        return search[0]['pipelineId']
Exemple #3
0
    def retrieve(self, pipelines):
        print(colored("Kraken mapId retrieval start", color='blue'))

        URL = self.KRAKEN_URL + self.map_type + '/geojson/retrieve'

        retr = Task(self.loop)
        retrieved = retr.do_the_task(URL, headers,
                                     json.dumps(pipelines), True)

        result = retr.wait_till_resolved(headers, json.dumps(pipelines), True)
        for idx in retrieved:
            assert retrieved[idx].get('mapId'), \
                print(colored("Error, Kraken mapId retrieval failed: {}".format(retrieved[idx]), color='red'))

        self.retr_mapIds = retrieved
        os.makedirs(self.path_RESULTS + self.map_type, exist_ok=True)
        write_json(self.retr_mapIds, self.path_RESULTS + self.map_type + "/Kraken_retrieved_mapIds.json")
        print(colored("Kraken mapId retrieval OK, mapIds written to file {}".format(
            self.path_RESULTS + self.map_type + "/Kraken_retrieved_mapIds.json"), color='green'))
Exemple #4
0
    def initialize(self, dates):
        print(colored("Kraken map initialization start", color='blue'))

        URL = self.KRAKEN_URL + self.map_type + '/geojson/initiate'
        init = Task(self.loop)

        scenes_in_range = {}
        all_payloads = {}

        dto = dt.strptime((dates['to'][:10]), "%Y-%m-%d")
        dfrom = dt.strptime((dates['from'][:10]), "%Y-%m-%d")

        found = False
        when_are_maps_available = []
        for idx, band in enumerate(self.available_scenes['results']):
            date = dt.strptime((band['datetime'][:10]), "%Y-%m-%d")
            if dfrom < date < dto:
                scenes_in_range[len(scenes_in_range)] = band
                all_payloads[len(all_payloads)] = dict({
                    'sceneId': band['sceneId'],
                    'extent': self.area_of_interest
                })
                when_are_maps_available.append(str(date)[:10])
                found = True
        assert found, print(colored("No map available in the selected period: {}".format(dates), color='red'))
        print(colored("Maps available in the following dates: {}".format(when_are_maps_available), color='blue'))
        write_json(scenes_in_range, self.path_RESULTS + 'Ragnar_retrieved_results_in_dates.json')
        start = time.time()
        search = init.do_the_task(URL, headers, json.dumps(all_payloads), repeat=True)
        print(colored("Time to init Kraken: {}".format(time.time() - start), color='blue'))

        pipelines = dict()
        for idx in search:
            assert search[idx].get('pipelineId'), \
                print(colored("Error, Kraken map initialization failed: {}".format(str(search[idx])), color='red'))
            pipelines[idx] = dict(pipelineId=search[idx]['pipelineId'])

        result = init.wait_till_resolved(headers, json.dumps(pipelines), True)
        assert result == 'RESOLVED', \
            print(colored("Error, Kraken map initialization failed: {}".format(result), color='red'))

        print(colored("Kraken map initialization OK", color='green'))
        return pipelines
 def request_token(self, credentials_path):
     credentials = read_json(credentials_path)
     authentication = Task(self.loop)
     hdrs = {'Content-Type': 'application/json'}
     req_auth = authentication.do_the_task(self.TOKEN_REQ_URL, hdrs,
                                           json.dumps(credentials))
     self.TOKEN = req_auth[0]
     self.TOKEN['timestamp'] = time.time()
     headers.update(
         {'Authorization': 'Bearer {}'.format(self.TOKEN['id_token'])})
     write_json(self.TOKEN, path_token)
     if 'status_code' in req_auth[0] and req_auth[0]['status_code'] == 200:
         print(
             colored("New token saved in: {}".format(path_token),
                     color='green'))
     else:
         print(
             colored("New token request Failed, status code: {}".format(
                 req_auth[0]['status_code']),
                     color='red'))
    def check_token(self, TOKEN_path):
        valid = False
        try:
            TOKEN = read_json(TOKEN_path)
            authentication = Task(self.loop)

            if token_seems_valid(TOKEN):
                hdrs = copy.deepcopy(headers)
                hdrs.update(
                    {'Authorization': 'Bearer {}'.format(TOKEN['id_token'])})
                auth = authentication.do_the_task(
                    self.AUTHORISE_URL, hdrs,
                    json.dumps({"token": TOKEN['id_token']}))

                if 'status_code' in auth[0] and auth[0]['status_code'] == 200:
                    valid = True
                    print(
                        colored("Token authentication successful ",
                                color='green'))
                    self.TOKEN = TOKEN
                    headers.update({
                        'Authorization':
                        'Bearer {}'.format(self.TOKEN['id_token'])
                    })
                else:
                    print(
                        colored("Token authentication Failed, status code:{}".
                                format(auth[0]['status_code']),
                                color='red'),
                        colored("\nbut, new Token request will be called",
                                color='blue'))

                    valid = False
            else:
                valid = False
        except:
            print(colored("Token Not found!", color='red'),
                  colored("but, new request will be called", color='blue'))
        finally:
            return valid