Search in sources :

Example 1 with UserAgent

use of org.apache.eventmesh.common.protocol.tcp.UserAgent in project incubator-eventmesh by apache.

the class HelloTask method run.

@Override
public void run() {
    long taskExecuteTime = System.currentTimeMillis();
    Package res = new Package();
    Session session = null;
    UserAgent user = (UserAgent) pkg.getBody();
    try {
        // do acl check in connect
        if (eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerSecurityEnable) {
            String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            Acl.doAclCheckInTcpConnect(remoteAddr, user, HELLO_REQUEST.value());
        }
        if (eventMeshTCPServer.getEventMeshServer().getServiceState() != ServiceState.RUNNING) {
            logger.error("server state is not running:{}", eventMeshTCPServer.getEventMeshServer().getServiceState());
            throw new Exception("server state is not running, maybe deploying...");
        }
        validateUserAgent(user);
        session = eventMeshTCPServer.getClientSessionGroupMapping().createSession(user, ctx);
        res.setHeader(new Header(HELLO_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader().getSeq()));
        Utils.writeAndFlush(res, startTime, taskExecuteTime, session.getContext(), session);
    } catch (Throwable e) {
        messageLogger.error("HelloTask failed|address={},errMsg={}", ctx.channel().remoteAddress(), e);
        res.setHeader(new Header(HELLO_RESPONSE, OPStatus.FAIL.getCode(), e.getStackTrace().toString(), pkg.getHeader().getSeq()));
        ctx.writeAndFlush(res).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (!future.isSuccess()) {
                    Utils.logFailedMessageFlow(future, res, user, startTime, taskExecuteTime);
                } else {
                    Utils.logSucceedMessageFlow(res, user, startTime, taskExecuteTime);
                }
                logger.warn("HelloTask failed,close session,addr:{}", ctx.channel().remoteAddress());
                eventMeshTCPServer.getClientSessionGroupMapping().closeSession(ctx);
            }
        });
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Header(org.apache.eventmesh.common.protocol.tcp.Header) UserAgent(org.apache.eventmesh.common.protocol.tcp.UserAgent) Package(org.apache.eventmesh.common.protocol.tcp.Package) ChannelFutureListener(io.netty.channel.ChannelFutureListener) Session(org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session)

Example 2 with UserAgent

use of org.apache.eventmesh.common.protocol.tcp.UserAgent in project incubator-eventmesh by apache.

the class RecommendTask method run.

@Override
public void run() {
    long taskExecuteTime = System.currentTimeMillis();
    Package res = new Package();
    try {
        if (!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) {
            throw new Exception("registry enable config is false, not support");
        }
        UserAgent user = (UserAgent) pkg.getBody();
        validateUserAgent(user);
        String group = getGroupOfClient(user);
        EventMeshRecommendStrategy eventMeshRecommendStrategy = new EventMeshRecommendImpl(eventMeshTCPServer);
        String eventMeshRecommendResult = eventMeshRecommendStrategy.calculateRecommendEventMesh(group, user.getPurpose());
        res.setHeader(new Header(RECOMMEND_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader().getSeq()));
        res.setBody(eventMeshRecommendResult);
    } catch (Exception e) {
        messageLogger.error("RecommendTask failed|address={}|errMsg={}", ctx.channel().remoteAddress(), e);
        res.setHeader(new Header(RECOMMEND_RESPONSE, OPStatus.FAIL.getCode(), e.toString(), pkg.getHeader().getSeq()));
    } finally {
        writeAndFlush(res, startTime, taskExecuteTime, session.getContext(), session);
    // session.write2Client(res);
    }
}
Also used : EventMeshRecommendStrategy(org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendStrategy) Header(org.apache.eventmesh.common.protocol.tcp.Header) UserAgent(org.apache.eventmesh.common.protocol.tcp.UserAgent) Package(org.apache.eventmesh.common.protocol.tcp.Package) EventMeshRecommendImpl(org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl)

Example 3 with UserAgent

use of org.apache.eventmesh.common.protocol.tcp.UserAgent in project incubator-eventmesh by apache.

the class MessageUtils method generateSubServer.

public static UserAgent generateSubServer() {
    UserAgent user = new UserAgent();
    user.setHost("127.0.0.1");
    user.setPassword(generateRandomString(8));
    user.setUsername("PU4283");
    user.setPath("/data/app/umg_proxy");
    user.setPort(9437);
    user.setSubsystem("5023");
    user.setPid(23948);
    user.setVersion("2.0.11");
    return user;
}
Also used : UserAgent(org.apache.eventmesh.common.protocol.tcp.UserAgent)

Example 4 with UserAgent

use of org.apache.eventmesh.common.protocol.tcp.UserAgent in project incubator-eventmesh by apache.

the class UserAgentUtils method createUserAgent.

public static UserAgent createUserAgent() {
    UserAgent userAgent = new UserAgent();
    userAgent.setSubsystem("5123");
    // userAgent.setPid(UtilAll.getPid());
    // userAgent.setHost(RemotingUtil.getLocalAddress());
    userAgent.setVersion("2.0.8");
    userAgent.setUsername("username");
    userAgent.setPassword("1234");
    return userAgent;
}
Also used : UserAgent(org.apache.eventmesh.common.protocol.tcp.UserAgent)

Example 5 with UserAgent

use of org.apache.eventmesh.common.protocol.tcp.UserAgent in project incubator-eventmesh by apache.

the class ShowClientBySystemHandler method handle.

/**
 * print clientInfo by subsys
 *
 * @param httpExchange
 * @throws IOException
 */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
    String result = "";
    OutputStream out = httpExchange.getResponseBody();
    try {
        String queryString = httpExchange.getRequestURI().getQuery();
        Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
        String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
        String newLine = System.getProperty("line.separator");
        logger.info("showClientBySubsys,subsys:{}=================", subSystem);
        ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping();
        ConcurrentHashMap<InetSocketAddress, Session> sessionMap = clientSessionGroupMapping.getSessionMap();
        if (!sessionMap.isEmpty()) {
            for (Session session : sessionMap.values()) {
                if (session.getClient().getSubsystem().equals(subSystem)) {
                    UserAgent userAgent = session.getClient();
                    result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent.getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine;
                }
            }
        }
        httpExchange.sendResponseHeaders(200, 0);
        out.write(result.getBytes());
    } catch (Exception e) {
        logger.error("ShowClientBySystemAndHandler fail...", e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                logger.warn("out close failed...", e);
            }
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) UserAgent(org.apache.eventmesh.common.protocol.tcp.UserAgent) ClientSessionGroupMapping(org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping) IOException(java.io.IOException) IOException(java.io.IOException) Session(org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session)

Aggregations

UserAgent (org.apache.eventmesh.common.protocol.tcp.UserAgent)21 Properties (java.util.Properties)10 EventMeshTCPClientConfig (org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig)10 EventMeshMessage (org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)6 CloudEvent (io.cloudevents.CloudEvent)4 Package (org.apache.eventmesh.common.protocol.tcp.Package)4 Session (org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session)4 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Header (org.apache.eventmesh.common.protocol.tcp.Header)2 ClientSessionGroupMapping (org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping)2 InetSocketAddress (java.net.InetSocketAddress)1 ClientGroupWrapper (org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper)1 EventMeshRecommendImpl (org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl)1 EventMeshRecommendStrategy (org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendStrategy)1