def validate(self, data):
        data_model = {
            "enable_detailed_report": bool,
            "expected_time": int,
            "number_of_jobs": int,
            "redis_ip": six.string_types,
            "redis_port": int,
            "submission_time": six.string_types,
            "scaling_strategy": six.string_types
        }

        if 'enable_detailed_report' in data and data['enable_detailed_report']:
            data_model.update({
                "datasource_type": six.string_types,
                "database_data": dict
            })

        if 'scaling_strategy' in data and data['scaling_strategy'] == 'pid':
            data_model.update({"heuristic_options": dict})

        for key in data_model:
            if (key not in data):
                raise ex.BadRequestException(
                    "Variable \"{}\" is missing".format(key))

            if (not isinstance(data[key], data_model[key])):
                raise ex.BadRequestException(
                    "\"{}\" has unexpected variable type: {}. Was expecting {}"
                    .format(key, type(data[key]), data_model[key]))
    def get_monitor(self, plugin, app_id, plugin_info):
        executor = None

        if plugin == "spark_sahara":
            executor = SparkProgress(app_id, plugin_info)

        elif plugin == "web_app":
            executor = WebAppMonitor(app_id, plugin_info, api.os_keypair)

        elif plugin == "openstack_generic":
            executor = OSGeneric(app_id, plugin_info, api.os_keypair,
                                 api.retries)

        elif plugin == "spark_mesos":
            executor = SparkProgressUPV(app_id,
                                        plugin_info,
                                        retries=api.retries)

        elif plugin == "kubejobs":
            executor = KubeJobProgress(app_id,
                                       plugin_info,
                                       retries=api.retries)

        else:
            raise ex.BadRequestException()

        return executor
Exemple #3
0
def stop_monitoring(app_id):
    if app_id not in monitored_apps:
        API_LOG.log("App doesn't exist")
        raise ex.BadRequestException()

    # Stop the plugin and remove from the data structure
    monitored_apps.pop(app_id, None).stop()
Exemple #4
0
    def get_monitor(self, plugin, app_id, plugin_info):
        executor = None

        if plugin == "spark_sahara":
            executor = SparkProgress(app_id, plugin_info)

        elif plugin == "web_app":
            executor = WebAppMonitor(app_id, plugin_info, api.os_keypair)

        elif plugin == "openstack_generic":
            executor = OSGeneric(app_id, plugin_info, api.os_keypair,
                                 api.retries)

        elif plugin == "spark_mesos":
            executor = SparkProgressUPV(app_id, plugin_info, retries=api.retries)
       
        elif plugin == "kubejobs":
            executor = KubeJobProgress(app_id, plugin_info, retries=api.retries)

        elif plugin == "external_api":
            plugin_info['threshold'] = api.threshold
            plugin_info['metric_source'] = api.metric_source
            plugin_info['get_metric_endpoint'] = api.get_metric_endpoint
            plugin_info['k8s_manifest'] = api.k8s_manifest
            executor = VerticalProgress(app_id, plugin_info, retries=api.retries)

        else:
            raise ex.BadRequestException()

        return executor
Exemple #5
0
def get_job_report(app_id, detailed):
    if app_id not in monitored_apps:
        API_LOG.log("App doesn't exist")
        raise ex.BadRequestException()

    job = monitored_apps[app_id]
    if not job.report_flag:
        if detailed:
            return job.get_detailed_report(), 200
        else:
            return job.job_report.to_dict(), 200
    return {'message': 'Job is running yet!'}, 202
 def setup_datasource(self, info_plugin):
     if self.enable_detailed_report:
         datasource_type = info_plugin['datasource_type']
         if datasource_type == "monasca":
             return MonascaConnector()
         elif datasource_type == "influxdb":
             influx_url = info_plugin['database_data']['url']
             influx_port = info_plugin['database_data']['port']
             database_name = info_plugin['database_data']['name']
             return InfluxConnector(influx_url, influx_port, database_name)
         else:
             raise ex.BadRequestException("Unknown datasource type...!")
Exemple #7
0
def start_monitoring(data, app_id):
    """ These conditional cases choose the class executor's constructor of the
    application submitted
    Note: some executors need the keypair to access remotely some machine and
    execute the monitoring logic, but this attribute is not mandatory for all
    the executors."""

    if 'plugin' not in data or 'plugin_info' not in data:
        API_LOG.log("Missing parameters in request")
        raise ex.BadRequestException()

    plugin = data['plugin']
    plugin_info = data['plugin_info']

    if app_id not in monitored_apps:
        executor = plugin_service.get_plugin(plugin)(app_id, plugin_info)
        monitored_apps[app_id] = executor
        executor.start()

    else:
        API_LOG.log("The application is already being monitored")
        raise ex.BadRequestException()
Exemple #8
0
    def get_monitor(self, plugin, app_id, plugin_info):
        executor = None

        if plugin == "kubejobs":
            executor = kubejobs.PLUGIN(app_id,
                                       plugin_info,
                                       retries=api.retries)

        elif plugin == "kubejobs_cost":
            executor = kubejobs_cost.PLUGIN(app_id, plugin_info)

        else:
            raise ex.BadRequestException()

        return executor