Search in sources :

Example 1 with HttpMessage

use of com.creditease.agent.spi.HttpMessage in project uavstack by uavorg.

the class UpgradeDownloadRequestHandler method handle.

@Override
public void handle(UpgradeHttpMessage message) {
    HttpMessage httpMsg = (HttpMessage) message.getObjectParam("message");
    // Package downloading is time-consuming task, so use 1+n queue to execute it.
    I1NQueueWorker queueWorker = this.get1NQueueWorkerMgr().getQueueWorker(this.feature, UpgradeConstants.UPGRADE_1N_QUEUE_NAME);
    if (queueWorker == null) {
        if (log.isTraceEnable()) {
            log.warn(this, "Download 1N queue does not exit, so ignore this download request");
        }
        httpMsg.putResponseBodyInString("Internal error: 1N queue worker doese not exist", 500, "UTF-8");
        return;
    }
    String baseDir = this.getConfigManager().getFeatureConfiguration(feature, "download.dir");
    String target = httpMsg.getParameter(UpgradeConstants.DOWNLOAD_REQUEST_PARAM_KEY);
    String software = httpMsg.getParameter(UpgradeConstants.DOWNLOAD_TARGET_SOFTWARE);
    if ("list".equalsIgnoreCase(target)) {
        // get the list of upgrade package
        handleListFileRequest(baseDir, software, httpMsg);
        return;
    } else if ("listdir".equalsIgnoreCase(target)) {
        handleListDirRequest(baseDir, httpMsg);
        return;
    }
    int downloadThreshold = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "download.threshold"), 10);
    synchronized (this) {
        if (log.isTraceEnable()) {
            log.info(this, "Current download 1+N worker has " + queueWorker.getActiveCount() + " working tasks");
        }
        if (queueWorker.getActiveCount() >= downloadThreshold) {
            httpMsg.putResponseBodyInString("Too Many Requests", UpgradeConstants.HTTP_CODE_TOO_MANY_REQUESTS, "UTF-8");
            return;
        }
        Abstract1NTask task = new UpgradeDownloadTask(cName, feature, httpMsg);
        queueWorker.put(task);
    }
}
Also used : Abstract1NTask(com.creditease.agent.spi.Abstract1NTask) HttpMessage(com.creditease.agent.spi.HttpMessage) I1NQueueWorker(com.creditease.agent.spi.I1NQueueWorker)

Example 2 with HttpMessage

use of com.creditease.agent.spi.HttpMessage in project uavstack by uavorg.

the class MSCPPlusIT method onServiceEnd.

/**
 * onServiceEnd
 *
 * @param args
 */
@SuppressWarnings("rawtypes")
public void onServiceEnd(Object... args) {
    AbstractBaseHttpServComponent abhsc = (AbstractBaseHttpServComponent) args[0];
    HttpMessage message = (HttpMessage) args[1];
    String reqURL = abhsc.getHttpRootURL() + message.getContextPath();
    Map<String, Object> params = new HashMap<String, Object>();
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL, reqURL);
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_SERVLET, reqURL);
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT, "");
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT_REALPATH, "/" + System.getProperty("JAppID"));
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_RESPONSECODE, message.getResponseCode());
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_FORWARDADDR, message.getHeader("X-Forwarded-For"));
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_LISTENPORT, System.getProperty("JAppOperPort"));
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CLIENT_USRAGENT, message.getHeader("User-Agent"));
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_UAVCLIENT_TAG, message.getHeader("UAV-Client-Src"));
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_PROXY_HOST, message.getHeader("Host"));
    } catch (Exception e) {
    }
    try {
        params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CLIENTADDR, message.getClientAddress());
    } catch (Exception e) {
    }
    UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_SERVER_CONNECTOR, Monitor.CapturePhase.DOCAP, params);
}
Also used : HashMap(java.util.HashMap) HttpMessage(com.creditease.agent.spi.HttpMessage) AbstractBaseHttpServComponent(com.creditease.agent.spi.AbstractBaseHttpServComponent)

Aggregations

HttpMessage (com.creditease.agent.spi.HttpMessage)2 Abstract1NTask (com.creditease.agent.spi.Abstract1NTask)1 AbstractBaseHttpServComponent (com.creditease.agent.spi.AbstractBaseHttpServComponent)1 I1NQueueWorker (com.creditease.agent.spi.I1NQueueWorker)1 HashMap (java.util.HashMap)1