private void connectImpl() throws IOException, ClientProtocolException, ConnectException { LOGGER.info("connecting to slack"); lastPingSent = 0; lastPingAck = 0; HttpClient httpClient = getHttpClient(); HttpGet request = new HttpGet(SLACK_HTTPS_AUTH_URL + authToken); HttpResponse response; response = httpClient.execute(request); LOGGER.debug(response.getStatusLine().toString()); String jsonResponse = CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); SlackJSONSessionStatusParser sessionParser = new SlackJSONSessionStatusParser(jsonResponse); try { sessionParser.parse(); } catch (ParseException e1) { LOGGER.error(e1.toString()); } if (sessionParser.getError() != null) { LOGGER.error("Error during authentication : " + sessionParser.getError()); throw new ConnectException(sessionParser.getError()); } users = sessionParser.getUsers(); channels = sessionParser.getChannels(); sessionPersona = sessionParser.getSessionPersona(); team = sessionParser.getTeam(); LOGGER.info("Team " + team.getId() + " : " + team.getName()); LOGGER.info("Self " + sessionPersona.getId() + " : " + sessionPersona.getUserName()); LOGGER.info(users.size() + " users found on this session"); LOGGER.info(channels.size() + " channels found on this session"); String wssurl = sessionParser.getWebSocketURL(); LOGGER.debug("retrieved websocket URL : " + wssurl); ClientManager client = ClientManager.createClient(); if (proxyAddress != null) { client .getProperties() .put(ClientProperties.PROXY_URI, "http://" + proxyAddress + ":" + proxyPort); } final MessageHandler handler = this; LOGGER.debug("initiating connection to websocket"); try { websocketSession = client.connectToServer( new Endpoint() { @Override public void onOpen(Session session, EndpointConfig config) { session.addMessageHandler(handler); } }, URI.create(wssurl)); } catch (DeploymentException e) { LOGGER.error(e.toString()); } if (websocketSession != null) { SlackConnectedImpl slackConnectedImpl = new SlackConnectedImpl(sessionPersona); dispatcher.dispatch(slackConnectedImpl); LOGGER.debug("websocket connection established"); LOGGER.info("slack session ready"); } }
public static Map<String, Double> parseResources(String input) { Map<String, Double> topology_resources = new HashMap<String, Double>(); JSONParser parser = new JSONParser(); LOG.debug("Input to parseResources {}", input); try { if (input != null) { Object obj = parser.parse(input); JSONObject jsonObject = (JSONObject) obj; if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB)) { Double topoMemOnHeap = backtype.storm.utils.Utils.getDouble( jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB), null); topology_resources.put( Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, topoMemOnHeap); } if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB)) { Double topoMemOffHeap = backtype.storm.utils.Utils.getDouble( jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB), null); topology_resources.put( Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB, topoMemOffHeap); } if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT)) { Double topoCPU = backtype.storm.utils.Utils.getDouble( jsonObject.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT), null); topology_resources.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, topoCPU); } LOG.debug("Topology Resources {}", topology_resources); } } catch (ParseException e) { LOG.error("Failed to parse component resources is:" + e.toString(), e); return null; } return topology_resources; }