Search in sources :

Example 36 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class HeartBeatClientReqWorker method doServiceDiscovery.

/**
 * 实现服务发现功能:MSCP的服务发现需要利用心跳客户端的支持
 *
 * @param serviceName
 * @return
 */
public String[] doServiceDiscovery(String serviceName) {
    /**
     * step 1: select a heartbeat server url
     */
    final String connectStr = cfmgr.getConnection();
    if (null == connectStr) {
        log.err(this, "Select HeartBeatServer URL Fail as no available HeartBeatServer.");
        return null;
    }
    String[] connectInfo = connectStr.split(":");
    /**
     * NOTE: hbQueryServer's port=hbServer's port +10
     */
    int hbServerPort = DataConvertHelper.toInt(connectInfo[1], 8010) + 10;
    String hbserverURL = "http://" + connectInfo[0] + ":" + hbServerPort + "/hb/query";
    if (log.isDebugEnable()) {
        log.debug(this, "Selected HeartBeatServer URL is " + hbserverURL);
    }
    /**
     * step 2: build msg
     */
    UAVHttpMessage msg = new UAVHttpMessage();
    msg.setIntent("services");
    msg.putRequest("service", serviceName);
    byte[] datab = null;
    try {
        datab = JSONHelper.toString(msg).getBytes("utf-8");
    } catch (UnsupportedEncodingException e1) {
        return null;
    }
    /**
     * step 3: request hbquery
     */
    final CountDownLatch cdl = new CountDownLatch(1);
    final StringBuffer resultStr = new StringBuffer();
    client.doAsyncHttpPost(hbserverURL, datab, "application/json", "utf-8", new HttpClientCallback() {

        @Override
        public void completed(HttpClientCallbackResult result) {
            /**
             * step 4: run handlers for downstream response
             */
            resultStr.append(result.getReplyDataAsString());
            // CountDownLatch unlock
            cdl.countDown();
        }

        @Override
        public void failed(HttpClientCallbackResult result) {
            /**
             * mark this hbserver is NOT OK
             */
            cfmgr.putFailConnection(connectStr);
            // CountDownLatch unlock
            cdl.countDown();
        }
    });
    /**
     * step 4: wait the async http invoking result
     */
    try {
        cdl.await(5000, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    // ignore
    }
    if (resultStr.length() == 0) {
        return null;
    }
    @SuppressWarnings("unchecked") Map<String, String> resMap = JSONHelper.toObject(resultStr.toString(), Map.class);
    if (resMap.containsKey("err")) {
        return null;
    }
    String servicesStr = resMap.get("rs");
    List<String> services = JSONHelper.toObjectArray(servicesStr, String.class);
    String[] urls = new String[services.size()];
    return services.toArray(urls);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientCallback(com.creditease.uav.httpasync.HttpClientCallback) HttpClientCallbackResult(com.creditease.uav.httpasync.HttpClientCallbackResult)

Example 37 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class NewLogQueryServerWorker method adaptRequest.

@Override
protected UAVHttpMessage adaptRequest(HttpMessage message) {
    String messageBody = message.getRequestBodyAsString("UTF-8");
    if (log.isDebugEnable()) {
        log.debug(this, "NewLogQueryServerWorker Request: " + messageBody);
    }
    UAVHttpMessage msg = new UAVHttpMessage(messageBody);
    return msg;
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage)

Example 38 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class GodEyeRestService method loadUavNetworkInfo.

/**
 * 应用容器监控+UAV节点信息
 *
 * @return
 */
@GET
@Path("node/q/cache")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void loadUavNetworkInfo(@QueryParam("fkey") String fkey, @QueryParam("fvalue") String fvalue, @Suspended AsyncResponse response) {
    UAVHttpMessage message = new UAVHttpMessage();
    message.setIntent("node");
    if (StringHelper.isEmpty(fkey) || StringHelper.isEmpty(fvalue)) {
        String groups = getUserGroupsByFilter(request);
        if ("NOMAPPING".equals(groups)) {
            response.resume("{\"rs\":\"{}\"}");
        } else if ("ALL".equals(groups)) {
            loadUavNetworkInfoFromHttp(message, response);
        } else {
            message.putRequest("fkey", "group");
            message.putRequest("fvalue", groups);
            loadUavNetworkInfoFromHttp(message, response);
        }
    } else {
        message.putRequest("fkey", fkey);
        message.putRequest("fvalue", fvalue);
        loadUavNetworkInfoFromHttp(message, response);
    }
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 39 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class GodEyeRestService method groupFilterLoadAppProfileList.

// -----------------------------------------filter begin -------------------------------------
/**
 * 应用服务监控:全网应用Profile SnapShot
 *
 * @return
 */
@GET
@Path("filter/profile/q/cache")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void groupFilterLoadAppProfileList(@Suspended AsyncResponse response) {
    UAVHttpMessage message = new UAVHttpMessage();
    message.setIntent("profile");
    loadAppProfileListFromHttp(message, response);
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with UAVHttpMessage

use of com.creditease.agent.http.api.UAVHttpMessage in project uavstack by uavorg.

the class GodEyeRestService method loadAppProfileList.

/**
 * 应用服务监控:全网应用Profile SnapShot
 *
 * @return
 */
@GET
@Path("profile/q/cache")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void loadAppProfileList(@QueryParam("fkey") String fkey, @QueryParam("fvalue") String fvalue, @Suspended AsyncResponse response) {
    UAVHttpMessage message = new UAVHttpMessage();
    message.setIntent("profile");
    if (StringHelper.isEmpty(fkey) || StringHelper.isEmpty(fvalue)) {
        String groups = getUserGroupsByFilter(request);
        if ("NOMAPPING".equals(groups)) {
            response.resume("{\"rs\":\"{}\"}");
        } else if ("ALL".equals(groups)) {
            loadAppProfileListFromHttp(message, response);
        } else {
            message.putRequest("fkey", "appgroup");
            message.putRequest("fvalue", groups);
            loadAppProfileListFromHttp(message, response);
        }
    } else {
        message.putRequest("fkey", fkey);
        message.putRequest("fvalue", fvalue);
        loadAppProfileListFromHttp(message, response);
    }
}
Also used : UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UAVHttpMessage (com.creditease.agent.http.api.UAVHttpMessage)58 Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)25 POST (javax.ws.rs.POST)22 HashMap (java.util.HashMap)14 HttpClientCallback (com.creditease.uav.httpasync.HttpClientCallback)5 HttpClientCallbackResult (com.creditease.uav.httpasync.HttpClientCallbackResult)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ApphubException (com.creditease.uav.exception.ApphubException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 GET (javax.ws.rs.GET)3 AbstractSystemInvoker (com.creditease.agent.spi.AbstractSystemInvoker)2 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)2 BASE64DecoderUrl (com.creditease.uav.helpers.url.BASE64DecoderUrl)2 Date (java.util.Date)2