def test_dashboard_delete(quicksight_application_stub, mininmal_data_sets_stub,
                          template_arn):
    obj = Dashboard(quicksight_application=quicksight_application_stub,
                    data_sets=mininmal_data_sets_stub.data_sets_stub,
                    quicksight_template_arn=template_arn,
                    props=None)

    sub_type = 'main'

    dump_state(obj, 'Before delete')
    DashboardStubber.stub_delete_dashboard_call(sub_type)
    obj.delete()
    dump_state(obj, 'After delete')
Ejemplo n.º 2
0
def buildboard_startup(cfg):
    dashbrd = Dashboard(cfg)

    name = dashbrd.getName()
    branch = dashbrd.getBranch()
    logger.info("name: {0}  branch: {1}".format(name, branch))

    # Initialize git repo
    repo = dashbrd.getRepo()
    gitProj = dashbrd.getBuildProject()
    if gitProj:
        if not os.path.exists(gitProj):
            check_call(["git", "clone", repo + '/' + gitProj])
        gitRepo = Repo(gitProj)
        if gitRepo:
            dashbrd.setPyGitRepo(gitRepo)
        else:
            print("Error: Unable to clone {0}".format(cfg['gitProj']))
            return None
    else:
        print("Error: Need to specify the github project")
        return None

    #
    # Add build product to dashboard.html
    #
    ret = html_update_dashboard_table(cfg['name'])
    if ret:
        # Load last build from DB and update dashboard instance
        # Load last build from DB and start monitoring
        # Do nothing for now
        print("DEBUG: Created table {0} in Dashboard".format(cfg['name']))
    else:
        print("WARNING: Can't add {0} to Dashboard".format(cfg['name']))
        return None

    return dashbrd
def test_dashboard_update_source_entity(quicksight_application_stub,
                                        mininmal_data_sets_stub, template_arn):
    obj = Dashboard(quicksight_application=quicksight_application_stub,
                    data_sets=mininmal_data_sets_stub.data_sets_stub,
                    quicksight_template_arn=template_arn,
                    props=None)

    sub_type = 'main'
    assert sub_type in obj.config_data
    assert 'SourceEntity' in obj.config_data[sub_type]

    source_entity = obj.source_entity._get_map(sub_type, "SourceEntity")
    dump_state(source_entity, 'Dump SourceEntity before update')

    assert 'SourceTemplate' in source_entity
    source_template = source_entity.get('SourceTemplate', None)
    assert 'DataSetReferences' in source_template
    assert 'Arn' in source_template
    obj.source_entity._update_source_entity(source_entity)

    dump_state(source_entity, 'Dump SourceEntity after update')

    assert template_arn == source_template['Arn']
Ejemplo n.º 4
0
def buildboard_startup(cfg):
    dashbrd = Dashboard(cfg)

    name = dashbrd.getName()
    branch = dashbrd.getBranch()
    logger.info("name: {0}  branch: {1}".format(name, branch)) 

    # Initialize git repo
    repo = dashbrd.getRepo()
    gitProj = dashbrd.getBuildProject()
    if gitProj:
        if not os.path.exists(gitProj):
            check_call(["git", "clone", repo+'/'+ gitProj])
        gitRepo = Repo(gitProj)
        if gitRepo:
            dashbrd.setPyGitRepo(gitRepo)
        else:
            print ("Error: Unable to clone {0}".format(cfg['gitProj']))
            return None
    else:
        print ("Error: Need to specify the github project")
        return None


    #
    # Add build product to dashboard.html
    #
    ret = html_update_dashboard_table(cfg['name'])
    if ret:
        # Load last build from DB and update dashboard instance
        # Load last build from DB and start monitoring
        # Do nothing for now 
        print ("DEBUG: Created table {0} in Dashboard".format(cfg['name']))
    else:
        print ("WARNING: Can't add {0} to Dashboard".format(cfg['name']))
        return None

    return dashbrd
def test_dashboard_init(quicksight_application_stub, mininmal_data_sets_stub):
    obj = Dashboard(quicksight_application=quicksight_application_stub,
                    data_sets=mininmal_data_sets_stub.data_sets_stub,
                    quicksight_template_arn=template_arn,
                    props=None)
    dump_state(obj, 'Dump dashboard')
Ejemplo n.º 6
0
    def __init__(self, resource_properties):
        # TODO: use the config data / file to figure out the supported_data_set_types
        supported_data_set_types = ['sentiment', 'image-text', 'text', 'topic']

        self.resource_properties = resource_properties
        self.global_state = get_global_state()

        # use config data file if provided
        config_file = resource_properties.get('ConfigDataFile', None)
        if config_file:
            data = read_config(config_file)
            self.global_state.update(data)

        # TODO:RENAME: 'StackName' key name as this could be used out of stack. ApplicationName?
        # TODO: create/use a uuid if no attack provided
        self.prefix = resource_properties.get('StackName', 'Sample_Sol')

        # TODO:RENAME: quicksight_template_arn -> quicksight_source_template_arn
        self.quicksight_template_arn = resource_properties.get(
            'QuickSightSourceTemplateArn',
            'Uninitialized QuickSightSourceTemplateArn')
        logger.debug(
            f'Using QuickSightSourceTemplateArn: {self.quicksight_template_arn }'
        )

        self.quicksight_principal_arn = resource_properties.get(
            'QuickSightPrincipalArn', 'Uninitialized QuickSightPrincipalArn')
        logger.debug(
            f'Using QuickSightPrincipalArn: {self.quicksight_principal_arn }')

        self.data_source = DataSource(quicksight_application=self,
                                      props=self.global_state)
        self.data_source.athena_workgroup = resource_properties.get(
            'WorkGroupName', 'primary')

        self.data_set_sub_types = supported_data_set_types
        self.data_sets = dict()
        for data_set_sub_type in self.data_set_sub_types:
            data_set = DataSet(quicksight_application=self,
                               data_source=self.data_source,
                               data_set_sub_type=data_set_sub_type,
                               data_set_name=f"_{data_set_sub_type}_dataset",
                               props=self.global_state)
            self.data_sets[data_set_sub_type] = data_set

        self.analysis = Analysis(
            quicksight_application=self,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            data_source=self.data_source,
            props=self.global_state)

        self.dashboard = Dashboard(
            quicksight_application=self,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            props=self.global_state)

        self.template = Template(quicksight_application=self,
                                 data_sets=self.data_sets,
                                 props=self.global_state)

        global_state_json = json.dumps(self.global_state,
                                       indent=2,
                                       sort_keys=True)
        logger.debug(
            f'QuicksightApi: after init, global data json: {global_state_json}'
        )
    def __init__(self, resource_properties):
        # TODO: use the config data / file to figure out the supported_data_set_types
        supported_data_set_types = [
            "image-text", "topic", "image-moderation-label", "geo",
            "topic-mapping", "feed"
        ]

        self.resource_properties = resource_properties
        self.global_state = get_global_state()

        # use config data file if provided
        config_file = resource_properties.get("ConfigDataFile", None)
        if config_file:
            data = read_config(config_file)
            self.global_state.update(data)

        self.prefix = resource_properties.get("StackName", "Sample_Sol")

        # TODO:RENAME: quicksight_template_arn -> quicksight_source_template_arn
        self.quicksight_template_arn = resource_properties.get(
            "QuickSightSourceTemplateArn",
            "Uninitialized QuickSightSourceTemplateArn")
        logger.debug(
            f"Using QuickSightSourceTemplateArn: {self.quicksight_template_arn }"
        )

        self.quicksight_principal_arn = resource_properties.get(
            "QuickSightPrincipalArn", "Uninitialized QuickSightPrincipalArn")
        logger.debug(
            f"Using QuickSightPrincipalArn: {self.quicksight_principal_arn }")

        self.data_source = DataSource(quicksight_application=self,
                                      props=self.global_state)
        self.data_source.athena_workgroup = resource_properties.get(
            "WorkGroupName", "primary")

        self.data_set_sub_types = supported_data_set_types
        self.data_sets = dict()
        for data_set_sub_type in self.data_set_sub_types:
            data_set = DataSet(
                quicksight_application=self,
                data_source=self.data_source,
                data_set_sub_type=data_set_sub_type,
                props=self.global_state,
            )
            self.data_sets[data_set_sub_type] = data_set

        self.analysis = Analysis(
            quicksight_application=self,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            data_source=self.data_source,
            props=self.global_state,
        )

        self.dashboard = Dashboard(
            quicksight_application=self,
            data_source=self.data_source,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            props=self.global_state,
        )

        self.template = Template(quicksight_application=self,
                                 data_sets=self.data_sets,
                                 props=self.global_state)

        global_state_json = json.dumps(self.global_state,
                                       indent=2,
                                       sort_keys=True)
        logger.debug(
            f"QuicksightApi: after init, global data json: {global_state_json}"
        )