Beispiel #1
0
 def get_results(self, request, task_id=None):
     unit = session.get_session()
     if task_id:
         task = unit.query(models.Task).filter_by(id=task_id).first()
         return json.dumps(task.to_dict())
     return json.dumps([node.to_dict() for node in
                        unit.query(models.Task).all()])
Beispiel #2
0
 def get_report(self, request, task_id=None):
     unit = session.get_session()
     if not task_id:
         raise exc.HTTPNotFound('Not found task')
     if os.path.isfile('%s/%s' % (self.conf.reports_dir, task_id)):
         return open('%s/%s' % (self.conf.reports_dir, task_id)).read()
     else:
         raise exc.HTTPNotFound('Not found report')
Beispiel #3
0
 def collect_report(self, context, component_name, binary_data, task_id):
     unit = session.get_session()
     with unit.begin():
         task = unit.query(models.Task).filter_by(id=task_id).first()
         report_path = '%s/%s' % (
                 self.conf.reports_dir,
                 task_id)
         with open(report_path, 'w') as f:
             f.write(binary_data.decode('base64'))
         task.status = 'Finished'
         task.report_file = report_path
Beispiel #4
0
    def get_report(self, context, task_id):
        unit = session.get_session()
        task_object = unit.query(models.Task).filter_by(id=task_id).first()
        task_object.status = 'Generating'
        task_object.action = 'gen_report'
        with unit.begin():
            unit.add(task_object)

        rpc.call('collector', 'handle_task', task={
            'action': 'gen_report',
            'component_name': task_object.component_name,
            'id': task_object.id
        })
Beispiel #5
0
    def stop_task(self, context, task_id):
        unit = session.get_session()
        task_object = unit.query(models.Task).filter_by(id=task_id).first()
        task_object.status = 'Stopping'
        task_object.action = 'stop'
        with unit.begin():
            unit.add(task_object)

        rpc.cast(task_object.component_name, 'handle_task', task={
            'action': 'stop',
            'services': task_object.service_list,
            'id': task_object.id
        })
Beispiel #6
0
 def list_services(self, request):
     unit = session.get_session()
     #services = []
     #services = [service.name for service in
     #            unit.query(models.Service).all() if service.name not in services]
     raw_services = unit.query(models.Service).all()
     services = []
     for service in raw_services:
         if {'name': service.name} not in services:
             services.append(
                     {'id': service.id,
                      'name': service.name}
                 )
     data_resp = json.dumps({"services": services})
     return data_resp
Beispiel #7
0
    def set_status(self, context, status):
        unit = session.get_session()
        with unit.begin():
            status_object = models.Status()
            status_object.task_id = status['task_id']
            status_object.text = status['status']

            node = unit.query(models.Node).filter_by(node_id=status['server_id']).first()

            service = unit.query(models.Service).filter_by(
                node_id=node.id,
                name=status['service_name']
            ).first()

            service.status = status['status']
            unit.add(status_object)
Beispiel #8
0
    def discover_services(self, context, services, node_uuid):
        unit = session.get_session()

        node = unit.query(models.Node).filter_by(node_id=node_uuid).first()
        if not node:
            with unit.begin():
                node = models.Node()
                node.node_id = node_uuid
                unit.add(node)

        with unit.begin():
            for component, service_list in services.items():
                for service_name in service_list:
                    service = unit.query(models.Service).filter_by(node_id=node.id, name=service_name).first()
                    if not service:
                        service = models.Service()
                        service.name = service_name
                        service.component = component
                        service.node_id = node.id
                        service.status = 'Ready'
                        unit.add(service)
                    else:
                        service.status = 'Ready'
Beispiel #9
0
    def create_task(self, context, service_list):
        unit = session.get_session()
        component_names = []
        tasks_list = []

        for service_name in service_list:
            cur_component = service_name.split('-')[0]
            if cur_component not in component_names:
                component_names.append(cur_component)

        for component in component_names:
            task_object = models.Task()
            task_object.status = 'Scheduled'

            task_object.service_list = service_list
            task_object.component_name = component
            task_object.action = 'start'

            component_service_list = []

            for service_name in service_list:
                if component in service_name:
                    component_service_list.append(component)

            rpc.cast(component, 'handle_task', task={
                'action': 'start',
                'services': component_service_list,
                'id': task_object.id
            })

            with unit.begin():
                unit.add(task_object)

            tasks_list.append(task_object.id)

        return {'task_id': tasks_list}