Esempio n. 1
0
param_fields = {
    'name': fields.String,
    'label': fields.String,
    # 'hint': fields.String,
    'default': fields.String,
    'required': fields.Boolean,
    'type': fields.String,
}


class WorkerList(Resource):
  """Shows a list of available workers"""

  def get(self):
    return AVAILABLE, 200


class WorkerParams(Resource):
  """Shows a list of all params for selected worker class"""

  @marshal_with(param_fields)
  def get(self, worker_class):
    klass = getattr(workers, worker_class)
    keys = ['name', 'type', 'required', 'default', 'label']
    return [dict(zip(keys, param)) for param in klass.PARAMS]


api.add_resource(WorkerList, '/workers')
api.add_resource(WorkerParams, '/workers/<worker_class>/params')
Esempio n. 2
0
                job = Job.find(entry.payload.get('labels').get('job_id'))
                if job:
                    log = {
                        'timestamp': entry.timestamp.__str__(),
                        'payload': entry.payload,
                        'job_name': job.name,
                        'log_level': entry.payload.get('log_level', 'INFO')
                    }
                else:
                    log = {
                        'timestamp': entry.timestamp.__str__(),
                        'payload': entry.payload,
                        'job_name': 'N/A',
                        'log_level': entry.payload.get('log_level', 'INFO')
                    }
                entries.append(log)
            next_page_token = iterator.next_page_token
        return {'entries': entries, 'next_page_token': next_page_token}


api.add_resource(PipelineList, '/pipelines')
api.add_resource(PipelineSingle, '/pipelines/<pipeline_id>')
api.add_resource(PipelineStart, '/pipelines/<pipeline_id>/start')
api.add_resource(PipelineStop, '/pipelines/<pipeline_id>/stop')
api.add_resource(PipelineExport, '/pipelines/<pipeline_id>/export')
api.add_resource(PipelineImport, '/pipelines/import')
api.add_resource(PipelineRunOnSchedule,
                 '/pipelines/<pipeline_id>/run_on_schedule')
api.add_resource(PipelineLogs, '/pipelines/<pipeline_id>/logs')
Esempio n. 3
0
                'Creating new jobs for active pipeline is unavailable'
            }, 422

        job = Job(args['name'], args['worker_class'], args['pipeline_id'])
        job.assign_attributes(args)
        job.save()
        job.save_relations(args)
        tracker = insight.GAProvider()
        tracker.track_event(category='jobs',
                            action='create',
                            label=args['worker_class'])
        return job, 201


class JobStart(Resource):
    """Class for running of job"""
    @marshal_with(job_fields)
    def post(self, job_id):
        job = Job.find(job_id)
        job.pipeline.start_single_job(job)
        tracker = insight.GAProvider()
        tracker.track_event(category='jobs',
                            action='manual_run',
                            label=job.worker_class)
        return job


api.add_resource(JobList, '/jobs')
api.add_resource(JobSingle, '/jobs/<job_id>')
api.add_resource(JobStart, '/jobs/<job_id>/start')
Esempio n. 4
0
            "sa_email": SA_DATA['client_email'],
            "variables": params,
            "settings": settings,
        }


class GlobalVariable(Resource):
    @marshal_with(global_variables_fields)
    def put(self):
        args = parser.parse_args()
        Param.update_list(args.get('variables'))
        return {"variables": Param.where(pipeline_id=None, job_id=None).all()}


class GeneralSettingsRoute(Resource):
    @marshal_with(settings_fields)
    def put(self):
        args = settings_parser.parse_args()
        settings = []
        for arg in args['settings']:
            setting = GeneralSetting.where(name=arg['name']).first()
            if setting:
                setting.update(value=arg['value'])
                settings.append(setting)
        return settings


api.add_resource(Configuration, '/configuration')
api.add_resource(GlobalVariable, '/global_variables')
api.add_resource(GeneralSettingsRoute, '/general_settings')
Esempio n. 5
0
    def put(self, stage_id):
        stage = Stage.find(stage_id)
        abort_if_stage_doesnt_exist(stage, stage_id)

        args = parser.parse_args()

        stage.assign_attributes(args)
        stage.save()
        return stage, 200


class StageList(Resource):
    """Shows a list of all stages, and lets you POST to add new stages"""
    @marshal_with(stage_fields)
    def get(self):
        stages = Stage.all()
        return stages

    @marshal_with(stage_fields)
    def post(self):
        args = parser.parse_args()
        print('args: ' + args.__str__())
        stage = Stage()
        stage.assign_attributes(args)
        stage.save()
        return stage, 201


api.add_resource(StageList, '/stages')
api.add_resource(StageSingle, '/stages/<stage_id>')