Ejemplo n.º 1
0
    def get_visualizer(self,
                       app_id,
                       plugin,
                       enable_visualizer,
                       visualizer,
                       datasource,
                       user,
                       password,
                       database_data={}):
        """ Gets the visualizer executor of the job
        
        Arguments:
            app_id {string} -- Id of the job launched
            plugin {string} -- Plugin of the environment where the visualizer will be launched
            enable_visualizer {boolean} -- Flag that enables the visualization
            visualizer {int} -- Visualizer type that will be launched
            datasource {int} -- Datasource type of the visualizer launched
        
        Returns:
            Plugin -- Returns an object that represents a executions of a plugin
        """

        executor = None
        if plugin == "kubejobs" or plugin == "external_api":
            if visualizer == "k8s-grafana":
                executor = K8sGrafanaProgress(app_id, plugin,
                                              enable_visualizer, datasource,
                                              user, password, database_data)
        else:
            raise ex.BadRequestException()

        return executor
Ejemplo n.º 2
0
def start_visualization(data, app_id):
    """Starts the visualization of a job

    Arguments:
        app_id {string} -- Id of the job

    Returns:
        None
    """

    if 'plugin' not in data or 'enable_visualizer' not in data or \
            'visualizer_plugin' not in data or 'datasource_type' not in data:

        API_LOG.log("Missing parameters in request")
        raise exceptions.BadRequestException()

    plugin = data['plugin']
    enable_visualizer = data['enable_visualizer']
    visualizer_plugin = data['visualizer_plugin']
    datasource_type = data['datasource_type']
    user = data['username']
    password = data['password']

    if app_id not in visualized_apps:
        if 'database_data' in data:
            database_data = data['database_data']
            executor = builder.get_visualizer(app_id, plugin,
                                              enable_visualizer,
                                              visualizer_plugin,
                                              datasource_type, user, password,
                                              database_data)

        else:
            executor = builder.get_visualizer(app_id, plugin,
                                              enable_visualizer,
                                              visualizer_plugin,
                                              datasource_type, user, password)

        visualized_apps[app_id] = executor
        executor.start_visualization()

    else:
        API_LOG.log("The application is already being visualized")
        raise exceptions.BadRequestException()
Ejemplo n.º 3
0
def stop_visualization(data, app_id):
    """Stop the visualization of a job

    Arguments:
        app_id {string} -- Id of the job

    Returns:
        Plugin {Object} -- Returns a executor represeting the plugin executed
    """

    if ('enable_auth' in data.keys() and data['enable_auth']):
        if 'username' not in data or 'password' not in data:
            API_LOG.log("Missing parameters in request")
            raise exceptions.BadRequestException()

        # Commented because the authorization service not exists yet.
        # username = data['username']
        # password = data['password']

        # authorization = authorizer.get_authorization(api.authorization_url,
        #                                              username, password)

        # if not authorization['success']:
        #     API_LOG.log("Unauthorized request")
        #     raise exceptions.UnauthorizedException()

    if app_id not in visualized_apps.keys():
        raise exceptions.BadRequestException()

    if 'plugin' not in data\
        or 'visualizer_plugin' not in data\
            or 'datasource_type' not in data:

        API_LOG.log("Missing parameters in request")
        raise exceptions.BadRequestException()

    plugin = data['plugin']
    if plugin == 'kubejobs':
        # Call the executor by app_id and stop the visualization.
        visualized_apps[app_id].stop_visualization()

        return visualized_apps[app_id]
Ejemplo n.º 4
0
def visualizer_url(app_id):
    """Gets the URL to access the visualizer interface
    
    Arguments:
        app_id {string} -- Id of the job
    
    Returns:
        dict -- Key being 'url' and value being the visualizer URL access
    """

    if app_id not in visualized_apps.keys():
        API_LOG.log("Wrong request")
        raise ex.BadRequestException()
    try: 
        url = visualized_apps[app_id].get_visualizer_url()
    except Exception as ex:
        print ex
    return {"url": url}