Ejemplo n.º 1
0
def handleCmd(srvObj, reqPropsObj, httpRef):
    """
    Handle UNSUBSCRIBE command.

    srvObj:         Reference to NG/AMS server class object (ngamsServer).

    reqPropsObj:    Request Property object to keep track of actions done
                    during the request handling (ngamsReqProps).

    httpRef:        Reference to the HTTP request handler
                    object (ngamsHttpRequestHandler).

    Returns:        Void.
    """
    # added by [email protected]
    if (reqPropsObj.hasHttpPar("subscr_id")):
        id = reqPropsObj.getHttpPar("subscr_id")
        err, errStr = delSubscriber(srvObj, id)
        ###########
    else:
        if (reqPropsObj.hasHttpPar("url")):
            url = reqPropsObj.getHttpPar("url")
        else:
            errMsg = genLog("NGAMS_ER_CMD_SYNTAX",
                            [NGAMS_SUBSCRIBE_CMD, "Missing parameter: url"])
            raise Exception(errMsg)
        err, errStr = delSubscriber(srvObj, ngamsLib.getSubscriberId(url))

    if err:
        httpRef.send_status('UNSUBSCRIBE command failed: ' + errStr,
                            status=NGAMS_FAILURE,
                            code=NGAMS_HTTP_SUCCESS)
    else:
        return "Successfully handled UNSUBSCRIBE command"
Ejemplo n.º 2
0
def handleCmd(srvObj, reqPropsObj, httpRef):
    """
    Handle SUBSCRIBE Command.

    srvObj:         Reference to NG/AMS server class object (ngamsServer).

    reqPropsObj:    Request Property object to keep track of actions done
                    during the request handling (ngamsReqProps).

    httpRef:        Reference to the HTTP request handler
                    object (ngamsHttpRequestHandler).

    Returns:        Void.
    """
    T = TRACE()
    """
    if (srvObj.getDataMoverOnlyActive() and len(srvObj.getSubscriberDic()) > 0):
        srvObj.reply(reqPropsObj, httpRef, NGAMS_HTTP_SUCCESS, NGAMS_FAILURE,
                 "Data Mover NGAS server can have only one subscriber. Use command USUBSCRIBE to update an existing subscriber.")
        return
    """
    priority = 10
    url = ""
    startDate = time.time()
    filterPi = ""
    filterPiPars = ""
    if (reqPropsObj.hasHttpPar("priority")):
        priority = reqPropsObj.getHttpPar("priority")
    if (reqPropsObj.hasHttpPar("url")):
        url = reqPropsObj.getHttpPar("url")
        ngamsSubscriber.validate_url(url)
    else:
        errMsg = genLog("NGAMS_ER_CMD_SYNTAX",
                        [NGAMS_SUBSCRIBE_CMD, "Missing parameter: url"])
        raise Exception, errMsg
    if (reqPropsObj.hasHttpPar("start_date")):
        tmpStartDate = reqPropsObj.getHttpPar("start_date").strip()
        if tmpStartDate:
            startDate = fromiso8601(tmpStartDate, local=True)
    if (reqPropsObj.hasHttpPar("filter_plug_in")):
        filterPi = reqPropsObj.getHttpPar("filter_plug_in")
    if (reqPropsObj.hasHttpPar("plug_in_pars")):
        filterPiPars = reqPropsObj.getHttpPar("plug_in_pars")
    if (reqPropsObj.hasHttpPar("subscr_id")):
        id = reqPropsObj.getHttpPar("subscr_id")
    else:
        id = ngamsLib.getSubscriberId(url)

    logger.info("Creating subscription for files >= %s", toiso8601(startDate))
    subscrObj = ngamsSubscriber.ngamsSubscriber(srvObj.getHostId(),
                                                srvObj.getCfg().getPortNo(),
                                                priority,
                                                url,
                                                startDate,
                                                filterPi,
                                                filterPiPars,
                                                subscrId=id)
    # supports concurrent file transfer, added by [email protected]
    if (reqPropsObj.hasHttpPar("concurrent_threads")):
        concurthrds = reqPropsObj.getHttpPar("concurrent_threads")
        subscrObj.setConcurrentThreads(concurthrds)

    # If the Start Date given in before the Last Ingestion Date, we
    # reset the Last Ingestion Date
    subscrStat = srvObj.getDb().getSubscriberStatus([subscrObj.getId()],
                                                    subscrObj.getHostId(),
                                                    subscrObj.getPortNo())
    if subscrStat:
        lastIngDate = subscrStat[0][1]
        if startDate < lastIngDate:
            subscrObj.setLastFileIngDate(None)
        else:
            subscrObj.setLastFileIngDate(lastIngDate)

    # Register the Subscriber.
    addSubscriber(srvObj, subscrObj)

    # Trigger the Data Susbcription Thread to make it check if there are
    # files to deliver to the new Subscriber.
    srvObj.addSubscriptionInfo([], [subscrObj]).triggerSubscriptionThread()

    return "Handled SUBSCRIBE command"
Ejemplo n.º 3
0
def handleCmd(srvObj, reqPropsObj, httpRef):
    """
    Handle SUBSCRIBE Command.

    srvObj:         Reference to NG/AMS server class object (ngamsServer).

    reqPropsObj:    Request Property object to keep track of actions done
                    during the request handling (ngamsReqProps).

    httpRef:        Reference to the HTTP request handler
                    object (ngamsHttpRequestHandler).

    Returns:        Void.
    """
    """
    if (srvObj.getDataMoverOnlyActive() and len(srvObj.getSubscriberDic()) > 0):
        srvObj.reply(reqPropsObj, httpRef, NGAMS_HTTP_SUCCESS, NGAMS_FAILURE,
                 "Data Mover NGAS server can have only one subscriber. Use command USUBSCRIBE to update an existing subscriber.")
        return
    """
    priority = 10
    url = ""
    startDate = time.time()
    filterPi = ""
    filterPiPars = ""
    if (reqPropsObj.hasHttpPar("priority")):
        priority = reqPropsObj.getHttpPar("priority")
    if (reqPropsObj.hasHttpPar("url")):
        url = reqPropsObj.getHttpPar("url")
        ngamsSubscriber.validate_url(url)
    else:
        errMsg = genLog("NGAMS_ER_CMD_SYNTAX",
                        [NGAMS_SUBSCRIBE_CMD, "Missing parameter: url"])
        raise Exception(errMsg)
    if (reqPropsObj.hasHttpPar("start_date")):
        tmpStartDate = reqPropsObj.getHttpPar("start_date").strip()
        if tmpStartDate:
            startDate = fromiso8601(tmpStartDate, local=True)
    if (reqPropsObj.hasHttpPar("filter_plug_in")):
        filterPi = reqPropsObj.getHttpPar("filter_plug_in")
    if (reqPropsObj.hasHttpPar("plug_in_pars")):
        filterPiPars = reqPropsObj.getHttpPar("plug_in_pars")
    if (reqPropsObj.hasHttpPar("subscr_id")):
        id = reqPropsObj.getHttpPar("subscr_id")
    else:
        id = ngamsLib.getSubscriberId(url)

    logger.info("Creating subscription for files >= %s", toiso8601(startDate))
    subscrObj = ngamsSubscriber.ngamsSubscriber(srvObj.getHostId(),
                                                srvObj.getCfg().getPortNo(),
                                                priority,
                                                url,
                                                startDate,
                                                filterPi,
                                                filterPiPars,
                                                subscrId=id)
    # supports concurrent file transfer, added by [email protected]
    if (reqPropsObj.hasHttpPar("concurrent_threads")):
        concurthrds = reqPropsObj.getHttpPar("concurrent_threads")
        subscrObj.setConcurrentThreads(concurthrds)

    # If the Start Date given in before the Last Ingestion Date, we
    # reset the Last Ingestion Date
    #
    # TODO (rtobar, May 2021):
    #     This bit of logic seems to be in contention with the fact that adding
    #     a subscription with an ID that is already taken would be otherwise a
    #     failure. I'm leaving it here for the time being in order to avoid
    #     breaking anything, but it must probably be removed (or clarification
    #     should be sought otherwise).
    subscrStat = srvObj.getDb().getSubscriberStatus([subscrObj.getId()],
                                                    subscrObj.getHostId(),
                                                    subscrObj.getPortNo())
    if subscrStat and subscrStat[0][1]:
        lastIngDate = fromiso8601(subscrStat[0][1], local=True)
        if startDate < lastIngDate:
            subscrObj.setLastFileIngDate('')
        else:
            subscrObj.setLastFileIngDate(lastIngDate)

    # Register the Subscriber.
    existence_test = addSubscriber(srvObj, subscrObj)
    if existence_test == 'equal':
        return 201, NGAMS_SUCCESS, "Identical subscription with ID '%s' existed" % (
            id, )
    elif existence_test == 'unequal':
        return 409, NGAMS_FAILURE, "Different subscription with ID '%s' existed" % (
            id, )

    return "Handled SUBSCRIBE command"