Exemple #1
0
    def get_results(self):
        if not self.results is None:
            return self.results

        if not self.has_completed():
            self.wait_until_completed()

        if not self.details.status == "Succeeded":
            raise RuntimeError(
                f"Cannot retrieve results as job execution failed (status: {self.details.status}. error: {self.details.error_data})"
            )

        url = urlparse(self.details.output_data_uri)
        if url.query.find('se=') == -1:
            # output_data_uri does not contains SAS token, get sas url from service
            blob_client = BlobClient.from_blob_url(
                self.details.output_data_uri)
            blob_uri = self.workspace._get_linked_storage_sas_uri(
                blob_client.container_name, blob_client.blob_name)
            payload = download_blob(blob_uri)
        else:
            # output_data_uri contains SAS token, use it
            payload = download_blob(self.details.output_data_uri)

        result = json.loads(payload.decode('utf8'))
        return result
    def download(self):
        """Downloads the uploaded problem as an instance of `Problem`"""
        if not self.uploaded_uri:
            raise Exception(
                'StreamingProblem may not be downloaded before it is uploaded')

        coords = self._get_upload_coords()
        blob = coords['container_client'].get_blob_client(coords['blob_name'])
        contents = download_blob(blob.url)
        return Problem.deserialize(contents, self.name)
Exemple #3
0
    def download_data(self, blob_uri: str) -> dict:
        """Download file from blob uri

        :param blob_uri: Blob URI
        :type blob_uri: str
        :return: Payload from blob
        :rtype: dict
        """
        url = urlparse(blob_uri)
        if url.query.find("se=") == -1:
            # blob_uri does not contains SAS token,
            # get sas url from service
            blob_client = BlobClient.from_blob_url(blob_uri)
            blob_uri = self.workspace._get_linked_storage_sas_uri(
                blob_client.container_name, blob_client.blob_name)
            payload = download_blob(blob_uri)
        else:
            # blob_uri contains SAS token, use it
            payload = download_blob(blob_uri)

        return payload
Exemple #4
0
 def download(self, workspace: "Workspace"):
     """Downloads the uploaded problem as an instance of `Problem`"""
     if not self.uploaded_blob_uri:
         raise Exception(
             "Problem may not be downloaded before it is uploaded")
     blob_client = BlobClient.from_blob_url(self.uploaded_blob_uri)
     container_client = ContainerClient.from_container_url(
         workspace._get_linked_storage_sas_uri(blob_client.container_name))
     blob_name = blob_client.blob_name
     blob = container_client.get_blob_client(blob_name)
     contents = download_blob(blob.url)
     return Problem.deserialize(contents, self.name)