public void setZkNode(KaaThriftService service, ConnectionInfo connectionInfo, WorkerNodeTracker zkNode) { setZkNode(getServerId(service, connectionInfo), zkNode); }
/** * Bean init-method. */ @PostConstruct public void initBean() { LOG.info("Init default event service."); listeners = Collections.newSetFromMap(new ConcurrentHashMap<EventServiceListener, Boolean>()); neighbors = new Neighbors<>(KaaThriftService.OPERATIONS_SERVICE, new MessageTemplate(this), operationsServerConfig.getMaxNumberNeighborConnections()); }
public void brodcastMessage(V msg) { brodcastMessages(Collections.singleton(msg)); }
/** * Build server ID from ConnectionInfo object. * * @param info ConnectionInfo * @return server ID in format thriftHost:thriftPort */ public static String getServerId(ConnectionInfo info) { return getServerId(KaaThriftService.OPERATIONS_SERVICE, info); }
if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]", nf, Neighbors.getServerId(server.getConnectionInfo())); neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromServerProfileUpdateMessage(nf));
/** * Check neighbors. */ private void checkNeighbors() { if (neighbors == null) { synchronized (zkLock) { if (neighbors == null) { neighbors = new Neighbors<>( KaaThriftService.OPERATIONS_SERVICE, new NeighborTemplate<OperationsServiceMsg>() { @Override public void process(Iface client, List<OperationsServiceMsg> messages) throws TException { OperationsServiceMsg.dispatch(client, messages); } @Override public void onServerError(String serverId, Exception ex) { LOG.error("Can't send configuration update to {}", serverId, ex); } }, neighborConnectionsSize); ControlNode zkNode = controlZkService.getControlZkNode(); neighbors.setZkNode( KaaThriftService.KAA_NODE_SERVICE, zkNode.getControlServerInfo().getConnectionInfo(), zkNode); } } } }
private void sendOperationsServiceMessage(String serverId, OperationsServiceMsg msg) { NeighborConnection<MessageTemplate, OperationsServiceMsg> server = neighbors.getNeghborConnection(serverId); if (server == null) { LOG.warn("Specified server {} not found in neighbors list", serverId); } else { sendMessagesToServer(server, Collections.singleton(msg)); } }
@Override public void sendRouteInfo(Collection<RouteInfo> routeInfos, String... serverIdList) { List<EventRoute> routes = transformEventRouteFromRouteInfoCollection(routeInfos); String[] listServers = serverIdList; if (listServers == null || listServers.length <= 0) { List<NeighborConnection<MessageTemplate, Message>> servers = neighbors.getNeighbors(); listServers = servers.toArray(new String[servers.size()]); } for (String serverId : listServers) { sendMessagesToServer(packMessage(routes), serverId); } }
neighbors.brodcastMessage(OperationsServiceMsg.fromDeregistration(nf));
public void sendMessage(ConnectionInfo info, V msg) { sendMessages(info, Collections.singleton(msg)); }
addOpsServer(opServer);
/** * Create new instance of <code>NeighborConnection</code>. * * @param connectionInfo is connection info * @param maxNumberConnection os max number connection * @param socketTimeout is socket timeout * @param template is template */ public NeighborConnection(ConnectionInfo connectionInfo, int maxNumberConnection, long socketTimeout, T template) { this.connectionInfo = connectionInfo; this.maxNumberConnection = maxNumberConnection; this.socketTimeout = socketTimeout; this.template = template; this.id = Neighbors.getServerId(connectionInfo); }
private void sendEndpointConfigurationRefreshMessage(EndpointSpecificConfigurationDto configuration) { byte[] endpointKeyHashBytes = configuration.getEndpointKeyHash(); EndpointProfileDto endpointProfile = endpointService.findEndpointProfileByKeyHash(endpointKeyHashBytes); if (!configuration.getConfigurationSchemaVersion().equals(endpointProfile.getConfigurationVersion())) { return; } checkNeighbors(); String endpointKeyHash = Base64Util.encode(configuration.getEndpointKeyHash()); ApplicationDto appDto = applicationService.findAppById(endpointProfile.getApplicationId()); OperationsNodeInfo server = resolve(endpointKeyHash); if (server != null) { ThriftEndpointConfigurationRefreshMessage msg = new ThriftEndpointConfigurationRefreshMessage(); msg.setAddress(new ThriftEntityAddress(appDto.getTenantId(), appDto.getApplicationToken(), ThriftClusterEntityType.ENDPOINT, ByteBuffer.wrap(endpointKeyHashBytes))); msg.setActorClassifier(ThriftActorClassifier.GLOBAL); if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]", msg, Neighbors.getServerId(server.getConnectionInfo())); } neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromEndpointConfigurationRefresh(msg)); } else { LOG.warn("Can't find server for endpoint [{}]", endpointKeyHash); } }
private void sendMessagesToServer(List<Message> messages, String serverId) { NeighborConnection<MessageTemplate, Message> server = neighbors.getNeghborConnection(serverId); if (server == null) { LOG.debug("specified server {} not found in neighbors list", serverId); notifyListenersOnServerProblem(serverId); return; } sendMessagesToServer(server, messages); }
@Override public void sendUserRouteInfo( org.kaaproject.kaa.server.operations.service.event.UserRouteInfo routeInfo) { LOG.debug("EventService: sendUserRouteInfo()....."); List<NeighborConnection<MessageTemplate, Message>> servers = neighbors.getNeighbors(); UserRouteInfo userRoute = new UserRouteInfo(routeInfo.getUserId(), routeInfo.getTenantId(), id, transformUpdateType(routeInfo.getRouteOperation())); List<Message> messages = packMessage(userRoute); for (NeighborConnection<MessageTemplate, Message> server : servers) { LOG.debug("Send UserRouteInfo {} to neighbor {}....", userRoute, server.getId()); sendMessagesToServer(server, messages); } }
@Override public void removeEndpointProfile(EndpointProfileDto endpointProfile) throws ControlServiceException { checkNeighbors(); byte[] endpointKeyHash = endpointProfile.getEndpointKeyHash(); this.endpointService.removeEndpointProfileByKeyHash(endpointKeyHash); ApplicationDto appDto = getApplication(endpointProfile.getApplicationId()); ThriftEndpointDeregistrationMessage nf = new ThriftEndpointDeregistrationMessage(); nf.setAddress( new ThriftEntityAddress( appDto.getTenantId(), appDto.getApplicationToken(), ThriftClusterEntityType.ENDPOINT, ByteBuffer.wrap(endpointKeyHash) ) ); nf.setActorClassifier(ThriftActorClassifier.APPLICATION); neighbors.brodcastMessage(OperationsServiceMsg.fromDeregistration(nf)); }
@Override public void setZkNode(OperationsNode operationsNode) { this.operationsNode = operationsNode; this.id = Neighbors.getServerId(this.operationsNode.getNodeInfo().getConnectionInfo()); neighbors.setZkNode( KaaThriftService.OPERATIONS_SERVICE, this.operationsNode.getNodeInfo().getConnectionInfo(), operationsNode); if (resolver != null) { updateResolver(this.resolver); } }
@Override public void onNodeRemoved(OperationsNodeInfo nodeInfo) { String opId = getServerId(nodeInfo.getConnectionInfo()); if (!zkId.equals(opId)) { NeighborConnection<T, V> connection = neigbors.remove(opId); if (connection != null) { connection.shutdown(); } LOG.info("Operations server {} removed to {} Neighbors list ({}). Now {} neighbors", opId, neigbors.size()); } } });
if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]", nf, Neighbors.getServerId(server.getConnectionInfo())); neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromNotification(nf)); } else { LOG.warn("Can't find server for endpoint [{}]", endpointId);
@Override public void sendEvent(RemoteEndpointEvent remoteEndpointEvent) { String serverId = remoteEndpointEvent.getRecipient().getServerId(); NeighborConnection<MessageTemplate, Message> server = neighbors.getNeghborConnection(serverId); if (server == null) { LOG.debug("sendRouteInfo() specified server {} not found in neighbors list", serverId);