public void addSession(KieServerInfo serverInfo, Session session) { List<Session> newSessions = new ArrayList<>(); List<Session> sessions = this.availableSessionsByUrl.putIfAbsent(serverInfo.getLocation(), newSessions); if (sessions == null) { sessions = newSessions; } sessions.add(session); this.sessionToUrl.put(session.getId(), serverInfo); logger.debug("Session '{}' associated with url: {}", session.getId(), serverInfo.getLocation()); }
public String removeSession(Session session) { this.availableSessionsById.remove(session.getId()); KieServerInfo serverInfo = sessionToUrl.remove(session.getId()); List<Session> sessions = availableSessionsByUrl.get(serverInfo.getLocation()); Iterator<Session> it = sessions.iterator(); while (it.hasNext()) { Session s = it.next(); if (s.getId().equals(session.getId())) { it.remove(); break; } } this.handlersPerSession.remove(session.getId()); logger.debug("Session '{}' removed to Web Socket manager", session.getId()); if (availableSessionsByUrl.get(serverInfo.getLocation()).isEmpty()) { return serverInfo.getLocation(); } return null; }
public boolean disconnectFromSingleController(KieServerInfo serverInfo, KieServerConfig config, String controllerUrl) { String connectAndSyncUrl = null; try { connectAndSyncUrl = controllerUrl + "/server/" + KieServerEnvironment.getServerId()+"/?location="+ URLEncoder.encode(serverInfo.getLocation(), "UTF-8"); String userName = config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_USER, "kieserver"); String password = loadControllerPassword(config); String token = config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_TOKEN); makeHttpDeleteRequestAndCreateCustomResponse(connectAndSyncUrl, null, userName, password, token); return true; } catch (Exception e) { // let's check all other controllers in case of running in cluster of controllers logger.debug("Exception encountered while syncing with controller at {} error {}", connectAndSyncUrl, e.getMessage(), e); return false; } }
@Override public synchronized void disconnect(KieServerInfo serverInfo) { ServerTemplate serverTemplate = templateStorage.load(serverInfo.getServerId()); if (serverTemplate != null) { logger.debug("Server id {} known to the controller, checking if given server exists", serverInfo.getServerId()); if (serverTemplate != null) { logger.info("Server {} disconnected from controller", serverInfo.getLocation()); ServerInstanceKey serverInstanceKey = ModelFactory.newServerInstanceKey(serverInfo.getServerId(), serverInfo.getLocation()); serverTemplate.deleteServerInstance(serverInstanceKey.getServerInstanceId()); templateStorage.update(serverTemplate); notifyOnDisconnect(serverInstanceKey, serverTemplate); } } }
@Override public void afterResponseSent() { ServerTemplate serverTemplate = controller.getTemplateStorage().load(serverInfo.getServerId()); ServerInstanceKey serverInstanceKey = serverTemplate.getServerInstanceKeys().stream() .filter(server -> server.getUrl().equals(serverInfo.getLocation())) .findFirst() .get(); ServerInstance serverInstance = new ServerInstance(); serverInstance.setServerName(serverInstanceKey.getServerName()); serverInstance.setServerTemplateId(serverInstanceKey.getServerTemplateId()); serverInstance.setServerInstanceId(serverInstanceKey.getServerInstanceId()); serverInstance.setUrl(serverInstanceKey.getUrl()); controller.getNotificationService().notify(new ServerInstanceUpdated(serverInstance)); controller.getNotificationService().notify(new ServerInstanceConnected(serverInstance)); }
ServerInstanceKey serverInstanceKey = ModelFactory.newServerInstanceKey(serverInfo.getServerId(), serverInfo.getLocation()); List<Container> containerList = new ArrayList<Container>(); if (!serverTemplate.hasServerInstance(serverInfo.getLocation())) { logger.debug("Server instance '{}' not yet registered", serverInfo.getLocation()); serverTemplate.addServerInstance(serverInstanceKey); logger.debug("KieServerInstance updated after connect from server {}", serverInfo.getLocation()); logger.debug("KieServerInstance stored after connect (register) from server {}", serverInfo.getLocation()); templateStorage.store(serverTemplate); logger.info("Server {} connected to controller", serverInfo.getLocation());