Ejemplo n.º 1
0
    def get_datasource(self, name):
        if self.version == 'v4':
            _params = {
                'project': self.project,
                'page_offset': 0,
                'page_size': 1000,
                'model_name': name,
                'exact': True,
            }
            model_desc = self.service.models(params=_params)[0]
            return KE4ModelSource(
                model_desc=model_desc,
                tables_and_columns=self.service.tables_and_columns(),
                service=self.service,
            )

        cube_desc = self.service.cube_desc(name)
        if cube_desc is None:
            raise KylinCubeError('No Cube found: {}'.format(name))
        model_name = cube_desc.get('model_name')
        return CubeSource(
            cube_desc=cube_desc,
            model_desc=self.service.model_desc(model_name),
            tables_and_columns=self.service.tables_and_columns(),
            service=self.service,
        )
Ejemplo n.º 2
0
    def maintain_cube(self, cube_name, maintain_type):
        if maintain_type not in ('disable', 'enable', 'purge', 'clone'):
            raise KylinCubeError(
                "Unsupported maintain type: {}, "
                "The maintain type must be 'BUILD', 'MERGE', 'REFRESH'".format(maintain_type))

        endpoint = '/cubes/{}/{}'.format(cube_name, maintain_type)
        json = {}
        if maintain_type == 'clone':
            json = {
                'cubeName': '{}_clone'.format(cube_name),
                'project': self.project,
            }
        try:
            return self.api.maintain_cube(self.client, endpoint, json=json)
        except InternalServerError as e:
            raise KylinCubeError(e)
Ejemplo n.º 3
0
    def build_streaming(self, cube_name, build_type, offset_start, offset_end):
        if build_type not in ('BUILD', 'MERGE', 'REFRESH'):
            raise KylinCubeError(
                "Unsupported build type: {}, The build type must be 'BUILD', 'MERGE', 'REFRESH'".format(build_type))

        json = {
            'sourceOffsetStart': offset_start,
            'sourceOffsetEnd': offset_end,
            'buildType': build_type,
        }
        endpoint = '/cubes/{}/build2'.format(cube_name)
        return self.api.build_streaming(self.client, endpoint, json=json)
Ejemplo n.º 4
0
    def build(self, cube_name, build_type, start, end):
        if build_type not in ('BUILD', 'MERGE', 'REFRESH'):
            raise KylinCubeError(
                "Unsupported build type: {}, The build type must be 'BUILD', 'MERGE', 'REFRESH'".format(build_type))

        json = {
            'startTime': start,
            'endTime': end,
            'buildType': build_type,
        }
        endpoint = '/cubes/{}/build'.format(cube_name)
        return self.api.build(self.client, endpoint, json=json)
Ejemplo n.º 5
0
 def invoke_command(self, command, **kwargs):
     invoke_command_list = [
         'fullbuild', 'build', 'merge', 'refresh', 'delete',
         'build_streaming', 'merge_streaming', 'refresh_streaming',
         'disable', 'enable', 'purge', 'clone', 'drop'
     ]
     if command in invoke_command_list:
         return {"code": "000", "data": {}}
     else:
         raise KylinCubeError(
             'Unsupported invoke command for datasource: {}'.format(
                 command))
Ejemplo n.º 6
0
 def drop_cube(self, cube_name):
     endpoint = '/cubes/{}'.format(cube_name)
     try:
         return self.api.drop_cube(self.client, endpoint)
     except InternalServerError as e:
         raise KylinCubeError(e)