Пример #1
0
def exceptionMsg(exn, request):
    """
    Takes a message queue, a dictionary that must contain the key `return_queue`
    and an exception, the exception will be dumped to json
    """
    returnQueueError(request.mq, request.body['return_queue'], str(exn))
    return defer_pipe.ret(request)
Пример #2
0
def exceptionMsg(exn, request):
    """
    Takes a message queue, a dictionary that must contain the key `return_queue`
    and an exception, the exception will be dumped to json
    """
    returnQueueError(request.mq, request.body['return_queue'], str(exn))
    return defer_pipe.ret(request)
Пример #3
0
def failureMsg(f, request):
    """
    Takes a message queue, a dictionary that must contain the key `return_queue`
    and a failure, the failure will be dumped to json
    """
    returnQueueFailure(request.mq, request.body['return_queue'], f)
    return defer_pipe.ret(request)
Пример #4
0
def failureMsg(f, request):
    """
    Takes a message queue, a dictionary that must contain the key `return_queue`
    and a failure, the failure will be dumped to json
    """
    returnQueueFailure(request.mq, request.body['return_queue'], f)
    return defer_pipe.ret(request)
Пример #5
0
def _returnTag(request):
    tag = persist.Tag(request.body['tag_name'],
                      [],
                      {},
                      None,
                      request.body['task_name'])
    return defer_pipe.ret(request.update(response=persist.tagToDict(tag)))
Пример #6
0
def handleListInstances(request):
    queue.returnQueueSuccess(request.mq,
                             request.body['return_queue'],
                             [request.credential.instanceToDict(i)
                              for i in request.state.credentialsCache.getCredential(request.credential.name)['instances']])

    return defer_pipe.ret(request)
Пример #7
0
def handleCredentialConfig(request):
    conf = config.configToDict(request.credential.credInstance.conf)
    conf = func.updateDict(conf,
                           {'general.ctype': request.credential.credential.getCType()})
    
    queue.returnQueueSuccess(request.mq, request.body['return_queue'], conf)
    
    return defer_pipe.ret(request)
Пример #8
0
def handleCredentialConfig(request):
    conf = config.configToDict(request.credential.credInstance.conf)
    conf = func.updateDict(
        conf, {'general.ctype': request.credential.credential.getCType()})

    queue.returnQueueSuccess(request.mq, request.body['return_queue'], conf)

    return defer_pipe.ret(request)
Пример #9
0
def wrapRequestHandler(state, f):
    _addState = lambda r : defer_pipe.ret(r.update(state=state))
    
    return defer_pipe.pipe([decodeRequest,
                            defer_pipe.hookError(defer_pipe.pipe([keysInBody(['return_queue']),
                                                                  _addState,
                                                                  f,
                                                                  ackMsg]),
                                                 ackMsgFailure)])
Пример #10
0
def wrapRequestHandler(state, f):
    _addState = lambda r: defer_pipe.ret(r.update(state=state))

    return defer_pipe.pipe([
        decodeRequest,
        defer_pipe.hookError(
            defer_pipe.pipe(
                [keysInBody(['return_queue']), _addState, f, ackMsg]),
            ackMsgFailure)
    ])
Пример #11
0
def handleUpdateInstances(request):
    convertedInstances = [request.credential.instanceFromDict(i) for i in request.body["instances"]]

    queue.returnQueueSuccess(
        request.mq,
        request.body["return_queue"],
        [
            request.credential.instanceToDict(ci)
            for ci in request.state.credentialsCache.getCredential(request.credential.name)["instances"]
            for i in convertedInstances
            if (ci.spotRequestId and ci.spotRequestId == i.spotRequestId) or ci.instanceId == i.instanceId
        ],
    )

    return defer_pipe.ret(request)
Пример #12
0
def handleUpdateInstances(request):
    convertedInstances = [
        request.credential.instanceFromDict(i)
        for i in request.body['instances']
    ]

    queue.returnQueueSuccess(request.mq, request.body['return_queue'], [
        request.credential.instanceToDict(ci)
        for ci in request.state.credentialsCache.getCredential(
            request.credential.name)['instances'] for i in convertedInstances
        if (ci.spotRequestId and ci.spotRequestId == i.spotRequestId)
        or ci.instanceId == i.instanceId
    ])

    return defer_pipe.ret(request)
Пример #13
0
def handleWWWObserver(request):
    """
    Input:
    { id: string
      file: string
      event: string
      retval: string
      props: string
      host: string
      time: string
      name: string
      message: string
    }

    Output:
    None
    """
    logging.debugPrint(lambda: repr(request.body))
    request.mq.send('/queue/pipelines/observer/' + request.body['props'],
                    json.dumps(request.body))
    return defer_pipe.ret(request.update(response=None))
Пример #14
0
def handleWWWObserver(request):
    """
    Input:
    { id: string
      file: string
      event: string
      retval: string
      props: string
      host: string
      time: string
      name: string
      message: string
    }

    Output:
    None
    """
    logging.debugPrint(lambda : repr(request.body))
    request.mq.send('/queue/pipelines/observer/' + request.body['props'],
                    json.dumps(request.body))
    return defer_pipe.ret(request.update(response=None))
Пример #15
0
def decodeRequest((mq, msg)):
    return defer_pipe.ret(QueueRequest(mq, msg))
Пример #16
0
def handleWWWListProtocols(request):
    """
    Input:
    { cluster: string
      ?criteria: { key/value }
      ?detail: boolean
      ?batch_mode: boolean
    }
    Output:
    [{ protocol: string, config: [ { key/value } ]}]
    """
    def _removeAlwaysHidden(protocolConfig):
        return [pc
                for pc in protocolConfig
                if pc[1].get('visibility') != 'always_hidden']

    # Create a criterial filter called protocolF
    if 'criteria' in request.body:
        if '$or' in request.body['criteria']:
            protocolNames = [p['protocol'] for p in request.body['criteria']['$or']]
            protocolF = lambda p : p in protocolNames
        elif 'protocol' in request.body['criteria']:
            protocolF = lambda p : p == request.body['criteria']['protocol']
        else:
            protocolF = lambda _ : True
    else:
        protocolF = lambda _ : True

    # Get all protocols and filter out the ones we don't need
    protocols = [p
                 for p in protocol_format.protocols(request.state.machineconf)
                 if protocolF(p)]

    if request.body.get('batch_mode'):
        batchConfig = [func.updateDict(c[1], {'name': c[0]})
                       for c in _removeAlwaysHidden(protocol_format.load(request.state.machineconf,
                                                                         'clovr_batch_wrapper'))]
    else:
        batchConfig = []
    
    protocolConfs = []
    for p in protocols:
        protocolConfig = protocol_format.load(request.state.machineconf, p)
        wrapperName = pipeline_misc.determineWrapper(request.state.machineconf, p)
        if wrapperName != p:
            protocolKeys = set([k for k, _ in protocolConfig])
            wrapperConfig = [(k, v) 
                             for (k,v) in protocol_format.load(request.state.machineconf, 
                                                               wrapperName) 
                             if k not in protocolKeys]

            protocolConfig += wrapperConfig

        if request.body.get('detail', False):
            conf = [func.updateDict(c[1], {'name': c[0]})
                    for c in _removeAlwaysHidden(protocolConfig)]
            if request.body.get('batch_mode', False):
                conf = batchConfig + [func.updateDict(c, {'name': 'batch_pipeline.' + c['name']})
                                      for c in conf]
        else:
            conf = []
            
        protocolConfs.append({'protocol': p, 'config': conf})
    
    return defer_pipe.ret(request.update(response=protocolConfs))
Пример #17
0
 def _(request):
     if core.keysInDict(ks, request.body):
         return defer_pipe.ret(request)
     else:
         raise Exception('Missing keys in request %r %r' % (ks, request.body))
Пример #18
0
def returnSuccess(request):
    returnQueueSuccess(request.mq, request.body['return_queue'], request.response)
    return defer_pipe.ret(request)
Пример #19
0
def ackMsgFailure(f, request):
    request.mq.ack(request.msg.headers['message-id'])
    return defer_pipe.ret(request)
Пример #20
0
def ackMsgFailure(f, request):
    request.mq.ack(request.msg.headers['message-id'])
    return defer_pipe.ret(request)
Пример #21
0
def returnSuccess(request):
    returnQueueSuccess(request.mq, request.body['return_queue'],
                       request.response)
    return defer_pipe.ret(request)
Пример #22
0
def containsPipelineTemplate(request):
    if 'pipeline.PIPELINE_TEMPLATE' in request.body['config']:
        return defer_pipe.ret(request)
    else:
        raise Error('Must provide a config with pipeline.PIPELINE_TEMPLATE')
Пример #23
0
 def _forward(taskName):
     request.body['task_name'] = taskName
     request.mq.send(dstQueue, json.dumps(request.body))
     return defer_pipe.ret(request.update(response=taskName))
Пример #24
0
 def _(request):
     if core.keysInDict(ks, request.body):
         return defer_pipe.ret(request)
     else:
         raise Exception('Missing keys in request %r %r' %
                         (ks, request.body))
Пример #25
0
def handleWWWListProtocols(request):
    """
    Input:
    { cluster: string
      ?criteria: { key/value }
      ?detail: boolean
      ?batch_mode: boolean
    }
    Output:
    [{ protocol: string, config: [ { key/value } ]}]
    """
    def _removeAlwaysHidden(protocolConfig):
        return [
            pc for pc in protocolConfig
            if pc[1].get('visibility') != 'always_hidden'
        ]

    # Create a criterial filter called protocolF
    if 'criteria' in request.body:
        if '$or' in request.body['criteria']:
            protocolNames = [
                p['protocol'] for p in request.body['criteria']['$or']
            ]
            protocolF = lambda p: p in protocolNames
        elif 'protocol' in request.body['criteria']:
            protocolF = lambda p: p == request.body['criteria']['protocol']
        else:
            protocolF = lambda _: True
    else:
        protocolF = lambda _: True

    # Get all protocols and filter out the ones we don't need
    protocols = [
        p for p in protocol_format.protocols(request.state.machineconf)
        if protocolF(p)
    ]

    if request.body.get('batch_mode'):
        batchConfig = [
            func.updateDict(c[1], {'name': c[0]}) for c in _removeAlwaysHidden(
                protocol_format.load(request.state.machineconf,
                                     'clovr_batch_wrapper'))
        ]
    else:
        batchConfig = []

    protocolConfs = []
    for p in protocols:
        protocolConfig = protocol_format.load(request.state.machineconf, p)
        wrapperName = pipeline_misc.determineWrapper(request.state.machineconf,
                                                     p)
        if wrapperName != p:
            protocolKeys = set([k for k, _ in protocolConfig])
            wrapperConfig = [(k, v) for (k, v) in protocol_format.load(
                request.state.machineconf, wrapperName)
                             if k not in protocolKeys]

            protocolConfig += wrapperConfig

        if request.body.get('detail', False):
            conf = [
                func.updateDict(c[1], {'name': c[0]})
                for c in _removeAlwaysHidden(protocolConfig)
            ]
            if request.body.get('batch_mode', False):
                conf = batchConfig + [
                    func.updateDict(c, {'name': 'batch_pipeline.' + c['name']})
                    for c in conf
                ]
        else:
            conf = []

        protocolConfs.append({'protocol': p, 'config': conf})

    return defer_pipe.ret(request.update(response=protocolConfs))
Пример #26
0
def handleGetCType(request):
    queue.returnQueueSuccess(request.mq, request.body['return_queue'],
                             request.credential.credential.getCType())
    return defer_pipe.ret(request)
Пример #27
0
def _returnTag(request):
    tag = persist.Tag(request.body['tag_name'], [], {}, None,
                      request.body['task_name'])
    return defer_pipe.ret(request.update(response=persist.tagToDict(tag)))
Пример #28
0
def decodeRequest((mq, msg)):
    return defer_pipe.ret(QueueRequest(mq, msg))
Пример #29
0
def handleGetCType(request):
    queue.returnQueueSuccess(request.mq,
                             request.body['return_queue'],
                             request.credential.credential.getCType())
    return defer_pipe.ret(request)
Пример #30
0
 def _forward(taskName):
     request.body['task_name'] = taskName
     request.mq.send(dstQueue, json.dumps(request.body))
     return defer_pipe.ret(request.update(response=taskName))