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);
}
});
}
}
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);
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations