Esempio n. 1
0
def reload(request):
    """
  Reloads the configuration file; interface to config.reload.
  """
    if request.method != "POST":
        return _methodNotAllowed()
    options = _validateOptions(request, {})
    if type(options) is str:
        return _response(options)
    user = userauth.authenticateRequest(request)
    if type(user) is str:
        return _response(user)
    elif user == None:
        return _unauthorized()
    elif not user.isSuperuser:
        return _forbidden()
    try:
        oldValue = ezid.pause(True)
        # Wait for the system to become quiescent.
        while True:
            if len(ezid.getStatus()[0]) == 0:
                break
            time.sleep(1)
        config.reload()
    finally:
        ezid.pause(oldValue)
    return _response("success: configuration file reloaded and caches emptied")
Esempio n. 2
0
def _statusLineGenerator(includeSuccessLine):
    if includeSuccessLine:
        yield "success: server paused\n"
    while True:
        activeUsers, waitingUsers, isPaused = ezid.getStatus()
        na = sum(activeUsers.values())
        nw = sum(waitingUsers.values())
        ndo = datacite.numActiveOperations()
        ql = ezidapp.models.UpdateQueue.objects.count()
        bql = binder_async.getQueueLength()
        dql = datacite_async.getQueueLength()
        nas = search_util.numActiveSearches()
        s = ("STATUS %s activeOperations=%d%s waitingRequests=%d%s " +
             "activeDataciteOperations=%d updateQueueLength=%d " +
             "binderQueueLength=%d " +
             "dataciteQueueLength=%d activeSearches=%d\n") % (
                 "paused" if isPaused else "running",
                 na,
                 _formatUserCountList(activeUsers),
                 nw,
                 _formatUserCountList(waitingUsers),
                 ndo,
                 ql,
                 bql,
                 dql,
                 nas,
             )
        yield s.encode("UTF-8")
        time.sleep(3)
Esempio n. 3
0
def pause(request):
    """
  Pauses or unpauses the server.  If the server is paused, server
  status records are streamed back to the client indefinitely.
  """
    if request.method != "GET":
        return _methodNotAllowed()
    user = userauth.authenticateRequest(request)
    if type(user) is str:
        return _response(user)
    elif user == None:
        return _unauthorized()
    elif not user.isSuperuser:
        return _forbidden()
    options = _validateOptions(request,
                               {"op": ["on", "idlewait", "off", "monitor"]})
    if type(options) is str:
        return _response(options)
    if "op" not in options:
        return _response("error: bad request - no 'op' parameter")
    if options["op"] == "on":
        ezid.pause(True)
        return django.http.StreamingHttpResponse(
            _statusLineGenerator(True),
            content_type="text/plain; charset=UTF-8")
    elif options["op"] == "idlewait":
        ezid.pause(True)
        while True:
            activeUsers, waitingUsers, isPaused = ezid.getStatus()
            if len(activeUsers) == 0:
                break
            time.sleep(1)
        return _response("success: server paused and idle")
    elif options["op"] == "off":
        ezid.pause(False)
        return _response("success: server unpaused")
    elif options["op"] == "monitor":
        return django.http.StreamingHttpResponse(
            _statusLineGenerator(False),
            content_type="text/plain; charset=UTF-8")
    else:
        assert False, "unhandled case"
Esempio n. 4
0
def _statusDaemon():
    while _enabled and threading.currentThread().getName() == _threadName:
        try:
            activeUsers, waitingUsers, isPaused = ezid.getStatus()
            na = sum(activeUsers.values())
            nw = sum(waitingUsers.values())
            ndo = datacite.numActiveOperations()
            uql = ezidapp.models.UpdateQueue.objects.count()
            bql = binder_async.getQueueLength()
            daql = datacite_async.getQueueLength()
            cqs = crossref.getQueueStatistics()
            doql = download.getQueueLength()
            as_ = search_util.numActiveSearches()
            no = log.getOperationCount()
            log.resetOperationCount()
            log.status("pid=%d" % os.getpid(),
              "threads=%d" % threading.activeCount(),
              "paused" if isPaused else "running",
              "activeOperations=%d%s" % (na, _formatUserCountList(activeUsers)),
              "waitingRequests=%d%s" % (nw, _formatUserCountList(waitingUsers)),
              "activeDataciteOperations=%d" % ndo,
              "updateQueueLength=%d" % uql,
              "binderQueueLength=%d" % bql,
              "dataciteQueueLength=%d" % daql,
              "crossrefQueue:archived/unsubmitted/submitted=%d/%d/%d" %\
              (cqs[2]+cqs[3], cqs[0], cqs[1]),
              "downloadQueueLength=%d" % doql,
              "activeSearches=%d" % as_,
              "operationCount=%d" % no)
            if _cloudwatchEnabled:
                import boto3
                # Disable annoying boto3 logging.
                logging.getLogger("botocore").setLevel(logging.ERROR)
                try:
                    c = boto3.client("cloudwatch",
                                     region_name=_cloudwatchRegion)
                    d = [{
                        "Name": "InstanceName",
                        "Value": _cloudwatchInstanceName
                    }]
                    data = {
                        "ActiveOperations": na,
                        "WaitingRequests": nw,
                        "ActiveDataciteOperations": ndo,
                        "UpdateQueueLength": uql,
                        "BinderQueueLength": bql,
                        "DataciteQueueLength": daql,
                        "CrossrefQueueLength": cqs[0] + cqs[1],
                        "DownloadQueueLength": doql,
                        "ActiveSearches": as_,
                        "OperationRate": float(no) / _reportingInterval
                    }
                    r = c.put_metric_data(Namespace=_cloudwatchNamespace,
                      MetricData=[{ "MetricName": k, "Dimensions": d, "Value": float(v),
                      "Unit": "Count/Second" if k == "OperationRate" else "Count" }\
                      for k, v in data.items()])
                    assert r["ResponseMetadata"]["HTTPStatusCode"] == 200
                except:
                    # Ignore CloudWatch exceptions, as it's not essential.
                    pass
        except Exception, e:
            log.otherError("status._statusDaemon", e)
        django.db.connections["default"].close()
        time.sleep(_reportingInterval)