コード例 #1
0
    def import_schema(self, path, *, title=None, target_data_model=None):
        """Import schema file from path

        Sisense does not support this in Windows

        Can be used to update an existing data model by adding it to target data model.

        To add a new model with a new title
        import_schema(path, title='New Title')

        To update an existing model
        import_schema(path, target_data_model=old_data_model)

        If updating an existing data model, no modifications to title will happen.

        Args:
            path: The path to the schema smodel file
            title: (Optional) Title to give the data model
            target_data_model: (Optional) The data model to update.
        """
        PySenseUtils.validate_version(self, SisenseVersion.Version.LINUX,
                                      'import_schema')

        target_data_model_id = target_data_model.get_oid(
        ) if target_data_model is not None else None

        query_params = {'title': title, 'datamodelId': target_data_model_id}
        data_model_json = self.connector.rest_call(
            'post',
            'api/v2/datamodel-imports/schema',
            query_params=query_params,
            json_payload=PySenseUtils.read_json(path))

        return PySenseDataModel.DataModel(self, data_model_json)
コード例 #2
0
    def start_build(self, build_type, *, row_limit=None):
        """Initiates a build of the data model

        Only supported on Linux

        Args:
            build_type (str): Type of build (schema_changes, by_table, full, publish)
            row_limit (int): (Optional) Number of rows to build
        Returns:
            BuildTask: The build task object for the build
        """

        PySenseUtils.validate_version(self.py_client, SisenseVersion.Version.LINUX, 'start_build')

        build_type = build_type.lower()
        if build_type not in ['schema_changes', 'by_table', 'full', 'publish']:
            raise PySenseException.PySenseException('Unsupported build type {}'.format(build_type))

        json_payload = {
            'datamodelId': self.get_oid(),
            'buildType': build_type
        }
        if row_limit is not None:
            json_payload['rowLimit'] = row_limit

        resp_json = self.py_client.connector.rest_call('post', 'api/v2/builds',
                                                       json_payload=json_payload)

        return PySenseBuildTask.BuildTask(self.py_client, resp_json)
コード例 #3
0
    def start_build(self,
                    build_type,
                    *,
                    server_address=None,
                    orchestrator_task=None):
        """Start cube build

        Windows only. For Linux use data models.

        Args:
            build_type (str): The build type (SchemaChanges, Accumulate, or Entire)
            server_address (str): (Optional) The server address of the ElastiCube.
                Set this to your server ip if this method fails without it set.
            orchestrator_task (str): (Optional) The orchestrator task

        """

        PySenseUtils.validate_version(self.py_client,
                                      SisenseVersion.Version.WINDOWS,
                                      'start_build')

        query_params = {
            'type': build_type,
            'orchestratorTask': orchestrator_task
        }
        server_address = server_address if server_address else self.server_address
        self.py_client.connector.rest_call(
            'post',
            'api/elasticubes/{}/{}/startBuild'.format(
                server_address, self.get_title(url_encoded=True)),
            query_params=query_params)
コード例 #4
0
    def get_data_models(self,
                        *,
                        title=None,
                        fields=None,
                        sort=None,
                        limit=None,
                        skip=None):
        """Gets data model schemas

        Linux Only

        If fields is specified, PySense may experience issues.

        To get all data models:
        get_data_models()

        To get a data model called PySense:
        get_data_models(title='PySense')

        Args:
            title (str): (Optional) Datamodel Title to search for
            fields (list[str]): (Optional) A whitelist of fields to return for each object in the response.
            sort (str): (Optional) A field by which the results should be sorted.
                Results will be sorted in ascending order by default, or descending if the field name is prefixed by -.
            limit (int): (Optional) Number of results to be returned from the data set.
                This field must be used with the skip parameter, and is intended for paging.
            skip (int): (Optional) Number of results to skip from the start of the data set.
                This parameter must be used with the limit parameter, and is intended for paging.

        Returns:
            list[DataModel]: The data models found

        """
        PySenseUtils.validate_version(self, SisenseVersion.Version.LINUX,
                                      'get_data_models')

        query_params = {
            'title': title,
            'fields': fields,
            'sort': sort,
            'limit': limit,
            'skip': skip
        }

        data_models = self.connector.rest_call('get',
                                               'api/v2/datamodels/schema',
                                               query_params=query_params)
        if title is not None:
            if data_models is not None and len(data_models) > 0:
                return [PySenseDataModel.DataModel(self, data_models)]
            else:
                return None
        else:
            ret_arr = []
            for data_model in data_models:
                ret_arr.append(PySenseDataModel.DataModel(self, data_model))
            return ret_arr
コード例 #5
0
    def delete_data_models(self, data_models):
        """Deletes the given data models

        Args:
            data_models: One to many data models to delete
        """
        PySenseUtils.validate_version(self, SisenseVersion.Version.LINUX,
                                      'delete_data_model')

        for data_model in PySenseUtils.make_iterable(data_models):
            self.connector.rest_call(
                'delete', 'api/v2/datamodels/{}'.format(data_model.get_oid()))
コード例 #6
0
    def cancel_build(self):
        """ Cancels all builds for data model

        Only supported on Linux
        """

        PySenseUtils.validate_version(self.py_client, SisenseVersion.Version.LINUX, 'cancel_build')

        query_params = {
            'datamodelId': self.get_oid()
        }

        self.py_client.connector.rest_call('delete', 'api/v2/builds', query_params=query_params)
コード例 #7
0
    def restart_cube(self, *, server_address=None):
        """Start cube

        Windows only

        Args:
            server_address (str): (Optional) The server address of the ElastiCube.
                Set this to your server ip if this method fails without it set.
        """

        PySenseUtils.validate_version(self.py_client,
                                      SisenseVersion.Version.WINDOWS,
                                      'restart_cube')

        server_address = server_address if server_address else self.server_address
        self.py_client.connector.rest_call(
            'post', 'api/elasticubes/{}/{}/restart'.format(
                server_address, self.get_title(url_encoded=True)))
コード例 #8
0
    def add_data_model(self,
                       data_model,
                       *,
                       title=None,
                       target_data_model=None):
        """Adds a new data model to the instance.

        Sisense does not support this in Windows

        Can be used to update an existing data model by adding it to target data model.

        To add a new model with a new title
        add_data_model(model_to_add, title='New Title')

        To update an existing model
        add_data_model(new_data_model, target_data_model=old_data_model)

        If updating an existing data model, no modifications to title will happen.

        Args:
            data_model (DataModel): The PySense DataModel object to import
            title (str): (Optional) Title to give the data model
            target_data_model (DataModel): (Optional) The data model to update.

        Returns:
            DataModel: The newly added data model
        """

        PySenseUtils.validate_version(self, SisenseVersion.Version.LINUX,
                                      'add_data_model')

        target_data_model_id = target_data_model.get_oid(
        ) if target_data_model is not None else None

        query_params = {'title': title, 'datamodelId': target_data_model_id}
        data_model_json = self.connector.rest_call(
            'post',
            'api/v2/datamodel-imports/schema',
            query_params=query_params,
            json_payload=data_model.get_schema_json())

        return PySenseDataModel.DataModel(self, data_model_json)
コード例 #9
0
    def export_to_sdata(self, path):
        """Download data model as an sdata file.

        Only supported on Linux

        Args:
            path (str): Path to save location of the sdata file.

        Returns:
            str: The path of the created file
        """

        PySenseUtils.validate_version(self.py_client, SisenseVersion.Version.LINUX, 'export_to_sdata')

        query_params = {
            'datamodelId': self.get_oid()
        }
        self.py_client.connector.rest_call('get', '/api/v2/datamodel-exports/stream/full',
                                           query_params=query_params, path=path, raw=True)

        return path
コード例 #10
0
    def get_data_model(self):
        """Returns the data model object for the cube.

        Linux only

        Returns:
            DataModel: The data model for the cube
        """

        PySenseUtils.validate_version(self.py_client,
                                      SisenseVersion.Version.LINUX,
                                      'get_model')

        query_params = {'datamodelId': self.get_oid(), 'type': 'schema-latest'}

        data_model_json = self.py_client.connector.rest_call(
            'get',
            'api/v2/datamodel-exports/schema',
            query_params=query_params)

        data_model_json['oid'] = self.get_oid()

        return PySenseDataModel.DataModel(self.py_client, data_model_json)
コード例 #11
0
    def import_sdata(self, path, *, title=None, target_data_model=None):
        """Import sdata file from path

        Linux only

        Can be used to update an existing data model by adding it to target data model.

        To add a new model with a new title
        import_sdata(path, title='New Title')

        To update an existing model
        import_sdata(path, target_data_model=old_data_model)

        If updating an existing data model, no modifications to title will happen.

        This method sometimes throws 500 errors.
        If it does, try the file from UI to verify it is a PySense issue or a Sisense issue

        Args:
            path: The path to the schema smodel file
            title: (Optional) Title to give the data model
            target_data_model: (Optional) The data model to update.
        """
        PySenseUtils.validate_version(self, SisenseVersion.Version.LINUX,
                                      'import_schema')

        target_data_model_id = target_data_model.get_oid(
        ) if target_data_model is not None else None

        query_params = {'title': title, 'datamodelId': target_data_model_id}
        data_model_json = self.connector.rest_call(
            'post',
            'api/v2/datamodel-imports/stream/full',
            query_params=query_params,
            file=path)

        return PySenseDataModel.DataModel(self, data_model_json)