Ejemplo n.º 1
0
 def _log(self, message, analysis, level):
     if self._mode == MODE_SEND:
         payload = {'level': level, 'analysis': analysis, 'data': message}
         ApiClient.post(ApiClient.res.logging_post(Store.performance_id),
                        data=payload)
     else:
         six.print_(self._format_message(message, level))
Ejemplo n.º 2
0
    def tabledata_list(self,
                       config_related,
                       datasetsid,
                       table_name,
                       start_index=None,
                       max_results=None,
                       page_token=None):
        """ Retrieves the contents of a table.

        Args:
          table_name: the name of the table as a tuple of components.
          start_index: the index of the row at which to start retrieval.
          max_results: an optional maximum number of rows to retrieve.
          page_token: an optional token to continue the retrieval.
        Returns:
          A parsed result object.
        Raises:
          Exception if there is an error performing the operation.
        """
        if config_related:
            url = ApiClient.res.sec_matrices_get(Store.config_id, datasetsid,
                                                 table_name)
        else:
            url = ApiClient.res.matrices_get(datasetsid, table_name)
        params = {}
        if start_index:
            params['startIndex'] = start_index
        if max_results:
            params['maxResults'] = max_results
        if page_token is not None:
            params['pageToken'] = page_token

        return ApiClient.get(url, params=params)
Ejemplo n.º 3
0
    def upload_object(self, datasetsid, file_name, file_path):
        """ Upload file to gcs.

        Args:
          file_name: the name of the file.
          file_path: the path of the file.
        Returns:
          A result object.
        Raises:
          Exception if there is an error performing the operation.
        """

        path = os.path.join(file_path, file_name)

        with open(path, 'rb') as f:
            multipart_data = MultipartEncoder(fields={
                # a file upload field
                'file': (file_name, f, 'text/plain')
            })
            headers = dict()
            headers['Content-Type'] = multipart_data.content_type

            return ApiClient.post(ApiClient.res.object(datasetsid, file_name),
                                  data=multipart_data,
                                  extra_headers=headers)
Ejemplo n.º 4
0
    def tables_get_parameters(self):
        """Issues a request to retrieve the parameter of the script execution configuration.

        Args:
        Returns:
          A parsed result object.
        Raises:
          Exception if there is an error performing the operation.
        """
        return ApiClient.get(ApiClient.res.sec_get_detail(Store.config_id))
Ejemplo n.º 5
0
    def tables_get(self, matrices_id):
        """Issues a request to retrieve information about a table.

        Args:
          matrices_id: .
        Returns:
          A parsed result object.
        Raises:
          Exception if there is an error performing the operation.
        """
        return ApiClient.get(ApiClient.res.matrices(matrices_id))
Ejemplo n.º 6
0
    def tables_get(self, table_name, matrices_id):
        """Issues a request to retrieve information about a table.

        Args:
          table_name: a tuple representing the full name of the table.
        Returns:
          A parsed result object.
        Raises:
          Exception if there is an error performing the operation.
        """

        return ApiClient.get(ApiClient.res.object(table_name, matrices_id))
Ejemplo n.º 7
0
    def delete_object(self, datasetsid, file_name):
        """ Delete an object.

        Args:
          datasetsid: the id of the dataset.
          file_name: the name of the dataset files.
        Returns:
          A url for downloading object.
        Raises:
          Exception if there is an error performing the operation.
        """

        return ApiClient.delete(ApiClient.res.object(datasetsid, file_name))
Ejemplo n.º 8
0
    def insert_sec_data(self, datasetsid, table_name, json_data):
        """ Insert streams data into matrix.

        Args:
          file_name: the name of the table as a tuple of components.
        Returns:
          A result object.
        Raises:
          Exception if there is an error performing the operation.
        """

        return ApiClient.post(ApiClient.res.sec_matrices_insert(
            Store.config_id, datasetsid, table_name),
                              data=json_data)
Ejemplo n.º 9
0
    def set_performance_output_parameter_value(self, parameter_id,
                                               parameter_value):
        """
        Set output parameter to the Performance

        Parameters
        ----------
        parameter_id : str
        parameter_value : object

        Raises
        ------
        st_library.exceptions.PerformanceRequired
            If Performance is not defined for current Environment

        """
        if not Store.performance_id:
            raise exceptions.PerformanceRequired(
                'Performance is not defined for current Environment')

        performance_id = Store.performance_id
        ApiClient.post(ApiClient.res.performance_output_parameter_post(
            parameter_id, performance_id),
                       json={'value': parameter_value})
Ejemplo n.º 10
0
    def download_object(self, datasetsid, file_name):
        """ Download an object.

        Args:
          datasetsid: the id of the dataset.
          file_name: the name of the dataset files.
        Returns:
          A url for downloading object.
        Raises:
          Exception if there is an error performing the operation.
        """

        return ApiClient.get(ApiClient.res.object_download(
            datasetsid, file_name),
                             raw_response=True)
Ejemplo n.º 11
0
    def insert_batch_sec_data(self, datasetsid, table_name, file_path,
                              file_name):
        """ Insert streams data into matrix.

        Args:
          file_name: the name of the table as a tuple of components.
        Returns:
          A result object.
        Raises:
          Exception if there is an error performing the operation.
        """

        metadata_file = '/home/st/workspace/dataprovider-py/samples/data/structured_data/metadata_sec.json'
        data_file = file_path + file_name
        boundary = '----------%s' % hex(int(time.time() * 1000))
        data = []
        data.append('--%s' % boundary)
        fr1 = open(metadata_file, 'rb')
        data.append(
            'Content-Disposition: form-data; name="%s"; filename="metadata_sec.json"'
            % 'metadata')
        data.append('Content-Type: %s\r\n' % 'application/json')
        data.append(fr1.read())
        fr1.close()
        data.append('--%s' % boundary)
        fr2 = open(data_file, 'rb')
        data.append(
            'Content-Disposition: form-data; name="%s"; filename="data.csv"' %
            'data')
        data.append('Content-Type: %s\r\n' % 'application/vnd.ms-excel')
        data.append(fr2.read())
        fr2.close()
        data.append('--%s--\r\n' % boundary)

        http_body = '\r\n'.join(data)

        headers = {}
        headers['Content-Type'] = 'multipart/form-data; boundary=%s' % boundary

        return ApiClient.post(ApiClient.res.sec_matrices_batch_insert(
            Store.config_id, datasetsid, table_name),
                              data=http_body,
                              extra_headers=headers)
Ejemplo n.º 12
0
    def tabledata_post(self, datasetsid, table_name, file_name):
        """ Insert the contents of a table.

        Args:
          file_name: the name of the table as a tuple of components.
        Returns:
          A result object.
        Raises:
          Exception if there is an error performing the operation.
        """

        filepath1 = r"/home/st/workspace/st-dataprovider-python/datalab/structured_data/metadata.json"
        filepath2 = file_name
        boundary = '----------%s' % hex(int(time.time() * 1000))
        data = []
        data.append('--%s' % boundary)
        fr1 = open(filepath1, 'rb')
        data.append(
            'Content-Disposition: form-data; name="%s"; filename="metadata.json"'
            % 'metadata')
        data.append('Content-Type: %s\r\n' % 'application/json')
        data.append(fr1.read())
        fr1.close()
        data.append('--%s' % boundary)
        fr2 = open(filepath2, 'rb')
        data.append(
            'Content-Disposition: form-data; name="%s"; filename="data.csv"' %
            'file')
        data.append('Content-Type: %s\r\n' % 'application/vnd.ms-excel')
        data.append(fr2.read())
        fr2.close()
        data.append('--%s--\r\n' % boundary)

        http_body = '\r\n'.join(data)

        headers = {}
        headers['Content-Type'] = 'multipart/form-data; boundary=%s' % boundary

        return ApiClient.post(ApiClient.res.matrices_upload(
            datasetsid, table_name),
                              data=http_body,
                              extra_headers=headers)
 def get_initial_data(self):
     return ApiClient.get(ApiClient.res.sec_get_detail(Store.config_id))