Exemplo n.º 1
0
class GetJobSpecType(Resource):
    """Get list of job queues and return as JSON."""

    resp_model = api.model('Job Type Specification Response(JSON)', {
        'success': fields.Boolean(required=True, description="if 'false', " +
                                  "encountered exception; otherwise no errors " +
                                  "occurred"),
        'message': fields.String(required=True, description="message describing " +
                                 "success or failure"),
        'result':  fields.Raw(required=True, description="Job Type Specification")
        })
    parser = api.parser()
    parser.add_argument('id', required=True, type=str, help="Job Type ID")

    @api.expect(parser)
    @api.marshal_with(resp_model)
    def get(self):
        '''
        Gets a Job Type specification object for the given ID.
        '''
        try:
            ident = request.form.get('id',request.args.get('id', None))
            spec = hysds_commons.job_spec_utils.get_job_spec(app.config['ES_URL'], ident, logger=app.logger)
        except Exception as e:
            message = "Failed to query ES for Job spec. {0}:{1}".format(type(e),str(e))
            app.logger.warning(message)
            app.logger.warning(traceback.format_exc(e))
            return {'success': False, 'message': message}, 500
        return { 'success': True,
                 'message': "",
                 'result': spec }
Exemplo n.º 2
0
class GetJobInfo(Resource):
    """Get info of job IDs."""

    resp_model = api.model('Job Info Response(JSON)', {
        'success': fields.Boolean(required=True, description="if 'false', " +
                                  "encountered exception; otherwise no errors " +
                                  "occurred"),
        'message': fields.String(required=True, description="message describing " +
                                 "success or failure"),
        'result':  fields.Raw(required=True,description="Job Info Object")
    })
    parser = api.parser()
    parser.add_argument('id', required=True, type=str, help="Job ID")

    @api.expect(parser)
    @api.marshal_with(resp_model)
    def get(self):
        '''
        Get complete infor on submitted job based on id
        '''
        try:
            # get job id
            ident = request.form.get('id', request.args.get('id', None))
            info = mozart.lib.job_utils.get_job_info(ident)
        except Exception as e:
            message = "Failed to get job info for {2}. {0}:{1}".format(type(e),str(e),ident)
            app.logger.warning(message)
            app.logger.warning(traceback.format_exc(e))
            return {'success': False, 'message': message}, 500
        return { 'success': True,
                 'message': "",
                 'result': info }
Exemplo n.º 3
0
class GetContainerInfo(Resource):
    """Info a container"""

    resp_model = api.model('Container Info Response(JSON)', {
        'success': fields.Boolean(required=True, description="if 'false', " +
                                  "encountered exception; otherwise no errors " +
                                  "occurred"),
        'message': fields.String(required=True, description="message describing " +
                                 "success or failure"),
        'result':  fields.Raw(required=True,description="Container Info")
    })
    parser = api.parser()
    parser.add_argument('id', required=True, type=str, help="Container ID")

    @api.expect(parser)
    @api.marshal_with(resp_model)
    def get(self):
        '''
        Get information on container by ID
        '''
        try:
            # get job id
            ident = request.form.get('id', request.args.get('id', None))
            info = hysds_commons.container_utils.get_container(app.config['ES_URL'], ident, logger=app.logger)
        except Exception as e:
            message = "Failed to get info for container {2}. {0}:{1}".format(type(e),str(e),ident)
            app.logger.warning(message)
            app.logger.warning(traceback.format_exc(e))
            return {'success': False, 'message': message}, 500
        return { 'success': True,
                 'message': "",
                 'result': info }
Exemplo n.º 4
0
class QueryJson(Resource):
    """Get PROV-ES document by ID and return as JSON."""

    resp_model = api.model('JsonResponse', {
        'success': fields.Boolean(required=True, description="if 'false', encountered exception; otherwise no errors occurred"),
        'message': fields.String(required=True, description="message describing success or failure"),
        'result':  fields.Raw(required=True, description="PROV-ES JSON document")
    })

    @api.doc(params={ 'id': 'ID of PROV-ES document'})
    @api.marshal_with(resp_model)
    def get(self):
        id = request.args.get('id', None)
        if id is None:
            return { 'success': False,
                     'message': "Missing id parameter.",
                     'result': {} }, 400
    
        # query
        try: pej = get_prov_es_json(id)
        except Exception, e:
            message = "Failed to get PROV-ES document for id %s: %s" % (id, str(e))
            current_app.logger.debug(message)
            return { 'success': False,
                     'message': message,
                     'result': {} }, 500

        # set message
        if len(pej) == 0: message = "No document found with id %s." % id
        else: message = ""

        # return result
        return { 'success': True,
                 'message': message,
                 'result': pej.get('_source', {}) }
Exemplo n.º 5
0
class GetQueueNames(Resource):
    """Get list of job queues and return as JSON."""

    resp_model = api.model('Queue Listing Response(JSON)', {
        'success': fields.Boolean(required=True, description="if 'false', " +
                                  "encountered exception; otherwise no errors " +
                                  "occurred"),
        'message': fields.String(required=True, description="message describing " +
                                 "success or failure"),
        'result':  fields.Raw(required=True, description="queue response")
        })
    parser = api.parser()
    parser.add_argument('id', required=False, type=str, help="Job Type Specification ID")
    @api.expect(parser)
    @api.marshal_with(resp_model)
    def get(self):
        '''
        Gets a listing of non-celery queues handling jobs.
        '''
        try:
            ident = request.form.get('id',request.args.get('id', None))
            queues = mozart.lib.queue_utils.get_queue_names(ident)
            app.logger.warn("Queues:"+str(queues))
        except Exception as e:
            message = "Failed to list job queues. {0}:{1}".format(type(e),str(e))
            app.logger.warning(message)
            app.logger.warning(traceback.format_exc(e))
            return {'success': False, 'message': message}, 500
        return { 'success': True,
                 'message': "",
                 'result': queues }
Exemplo n.º 6
0
 def test_raw_field_with_title(self):
     field = fields.Raw(title='A title')
     self.assertFalse(field.required)
     self.assertEqual(field.__schema__, {
         'type': 'object',
         'title': 'A title'
     })
Exemplo n.º 7
0
 def test_raw_field_with_description(self):
     field = fields.Raw(description='A description')
     self.assertFalse(field.required)
     self.assertEqual(field.__schema__, {
         'type': 'object',
         'description': 'A description'
     })
Exemplo n.º 8
0
class StingerProxy(Resource):
    jsonSpec = api.model(
        'rpc', {
            'jsonrpc':
            fields.String(
                description='JSON-RPC Version', required=True, default="2.0"),
            'method':
            fields.String(description='Method for RPC server to execute',
                          required=True),
            'params':
            fields.Raw(
                description=
                'JSON object describing parameters for the requested method',
                required=False),
            'id':
            fields.Arbitrary(description='User-specified ID of the request',
                             required=True,
                             default=False)
        })

    @api.expect(jsonSpec)
    def post(self):
        return stingerRPC(request.json)
Exemplo n.º 9
0
 def test_marshal_field(self):
     model = OrderedDict({'foo': fields.Raw()})
     marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz')])
     output = marshal(marshal_fields, model)
     self.assertEquals(output, {'foo': 'bar'})
Exemplo n.º 10
0
 def test_type(self):
     field = fields.Raw()
     self.assertEqual(field.__schema__['type'], 'object')
Exemplo n.º 11
0
 def test_default(self):
     field = fields.Raw(default='aaa')
     self.assertEqual(field.__schema__['default'], 'aaa')
Exemplo n.º 12
0
 def test_raw_field_with_default(self):
     field = fields.Raw(default='aaa')
     self.assertEqual(field.__schema__, {
         'type': 'object',
         'default': 'aaa'
     })
Exemplo n.º 13
0
 def test_raw_field_with_readonly(self):
     field = fields.Raw(readonly=True)
     self.assertEqual(field.__schema__, {
         'type': 'object',
         'readOnly': True
     })
Exemplo n.º 14
0
 def test_raw_field_with_required(self):
     field = fields.Raw(required=True)
     self.assertTrue(field.required)
     self.assertEqual(field.__schema__, {'type': 'object'})
Exemplo n.º 15
0
 def test_simple_raw_field(self):
     field = fields.Raw()
     self.assertFalse(field.required)
     self.assertEqual(field.__schema__, {'type': 'object'})