@Test public void testGossipInfo() throws Exception { String gossipInfoFromNodetool = FileUtils.getContentsAsString(new File(gossipInfo1)); new Expectations() { { nodeProbe.getGossipInfo(); result = gossipInfoFromNodetool; nodeProbe.getTokens("127.0.0.1"); result = "123,234"; } }; List<Map<String, String>> gossipInfoList = cassandraOperations.gossipInfo(); System.out.println(gossipInfoList); Assert.assertEquals(7, gossipInfoList.size()); gossipInfoList .stream() .forEach( gossipInfo -> { Assert.assertEquals("us-east", gossipInfo.get("DC")); Assert.assertNotNull(gossipInfo.get("PUBLIC_IP")); Assert.assertEquals("1565153", gossipInfo.get("HEARTBEAT")); if (gossipInfo.get("STATUS").equalsIgnoreCase("NORMAL")) Assert.assertNotNull(gossipInfo.get("TOKENS")); if (gossipInfo.get("PUBLIC_IP").equalsIgnoreCase("127.0.0.1")) Assert.assertEquals("[123,234]", gossipInfo.get("TOKENS")); }); }
@Override public List<Map<String, String>> gossipInfo() throws Exception { List<Map<String, String>> returnPublicIpSourceIpMap = new ArrayList(); try { JMXNodeTool nodeTool; try { nodeTool = JMXNodeTool.instance(configuration); } catch (JMXConnectionException e) { logger.error( "Exception in fetching c* jmx tool . Msg: {}", e.getLocalizedMessage(), e); throw e; } String gossipInfoLines[] = nodeTool.getGossipInfo().split("/"); Arrays.stream(gossipInfoLines) .forEach( gossipInfoLine -> { Map<String, String> gossipMap = new HashMap<>(); String gossipInfoSubLines[] = gossipInfoLine.split("\\r?\\n"); if (gossipInfoSubLines.length > 2) { gossipMap.put("PUBLIC_IP", gossipInfoSubLines[0].trim()); if (gossipMap.get("PUBLIC_IP") != null) { returnPublicIpSourceIpMap.add(gossipMap); } for (String gossipInfoSubLine : gossipInfoSubLines) { String gossipLineEntry[] = gossipInfoSubLine.split(":"); if (gossipLineEntry.length == 2) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[1].trim()); } else if (gossipLineEntry.length == 3) { if (gossipLineEntry[0] .trim() .equalsIgnoreCase("STATUS")) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].split(",")[0].trim()); } else if (gossipLineEntry[0] .trim() .equalsIgnoreCase("TOKENS")) { try { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), nodeTool.getTokens( gossipMap.get( "PUBLIC_IP")) .toString()); } catch (Exception e) { logger.warn( "Unable to find TOKEN(s) for the IP: {}", gossipMap.get("PUBLIC_IP")); } } else { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].trim()); } } } } }); } catch (Exception e) { logger.error("Unable to parse nodetool gossipinfo output from Cassandra.", e); } return returnPublicIpSourceIpMap; }
CassandraOperations implements ICassandraOperations { @Override public List<Map<String, String>> gossipInfo() throws Exception { List<Map<String, String>> returnPublicIpSourceIpMap = new ArrayList(); try { JMXNodeTool nodeTool; try { nodeTool = JMXNodeTool.instance(configuration); } catch (JMXConnectionException e) { logger.error( "Exception in fetching c* jmx tool . Msg: {}", e.getLocalizedMessage(), e); throw e; } String gossipInfoLines[] = nodeTool.getGossipInfo().split("/"); Arrays.stream(gossipInfoLines) .forEach( gossipInfoLine -> { Map<String, String> gossipMap = new HashMap<>(); String gossipInfoSubLines[] = gossipInfoLine.split("\\r?\\n"); if (gossipInfoSubLines.length > 2) { gossipMap.put("PUBLIC_IP", gossipInfoSubLines[0].trim()); if (gossipMap.get("PUBLIC_IP") != null) { returnPublicIpSourceIpMap.add(gossipMap); } for (String gossipInfoSubLine : gossipInfoSubLines) { String gossipLineEntry[] = gossipInfoSubLine.split(":"); if (gossipLineEntry.length == 2) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[1].trim()); } else if (gossipLineEntry.length == 3) { if (gossipLineEntry[0] .trim() .equalsIgnoreCase("STATUS")) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].split(",")[0].trim()); } else if (gossipLineEntry[0] .trim() .equalsIgnoreCase("TOKENS")) { try { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), nodeTool.getTokens( gossipMap.get( "PUBLIC_IP")) .toString()); } catch (Exception e) { logger.warn( "Unable to find TOKEN(s) for the IP: {}", gossipMap.get("PUBLIC_IP")); } } else { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].trim()); } } } } }); } catch (Exception e) { logger.error("Unable to parse nodetool gossipinfo output from Cassandra.", e); } return returnPublicIpSourceIpMap; } }
CassandraOperations implements ICassandraOperations { @Override public List<Map<String, String>> gossipInfo() throws Exception { List<Map<String, String>> returnPublicIpSourceIpMap = new ArrayList(); try { JMXNodeTool nodeTool; try { nodeTool = JMXNodeTool.instance(configuration); } catch (JMXConnectionException e) { logger.error( "Exception in fetching c* jmx tool . Msg: {}", e.getLocalizedMessage(), e); throw e; } String gossipInfoLines[] = nodeTool.getGossipInfo().split("/"); Arrays.stream(gossipInfoLines) .forEach( gossipInfoLine -> { Map<String, String> gossipMap = new HashMap<>(); String gossipInfoSubLines[] = gossipInfoLine.split("\\r?\\n"); if (gossipInfoSubLines.length > 2) { gossipMap.put("PUBLIC_IP", gossipInfoSubLines[0].trim()); if (gossipMap.get("PUBLIC_IP") != null) { returnPublicIpSourceIpMap.add(gossipMap); } for (String gossipInfoSubLine : gossipInfoSubLines) { String gossipLineEntry[] = gossipInfoSubLine.split(":"); if (gossipLineEntry.length == 2) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[1].trim()); } else if (gossipLineEntry.length == 3) { if (gossipLineEntry[0] .trim() .equalsIgnoreCase("STATUS")) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].split(",")[0].trim()); } else if (gossipLineEntry[0] .trim() .equalsIgnoreCase("TOKENS")) { try { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), nodeTool.getTokens( gossipMap.get( "PUBLIC_IP")) .toString()); } catch (Exception e) { logger.warn( "Unable to find TOKEN(s) for the IP: {}", gossipMap.get("PUBLIC_IP")); } } else { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].trim()); } } } } }); } catch (Exception e) { logger.error("Unable to parse nodetool gossipinfo output from Cassandra.", e); } return returnPublicIpSourceIpMap; } @Inject  CassandraOperations(IConfiguration configuration); }
CassandraOperations implements ICassandraOperations { @Override public List<Map<String, String>> gossipInfo() throws Exception { List<Map<String, String>> returnPublicIpSourceIpMap = new ArrayList(); try { JMXNodeTool nodeTool; try { nodeTool = JMXNodeTool.instance(configuration); } catch (JMXConnectionException e) { logger.error( "Exception in fetching c* jmx tool . Msg: {}", e.getLocalizedMessage(), e); throw e; } String gossipInfoLines[] = nodeTool.getGossipInfo().split("/"); Arrays.stream(gossipInfoLines) .forEach( gossipInfoLine -> { Map<String, String> gossipMap = new HashMap<>(); String gossipInfoSubLines[] = gossipInfoLine.split("\\r?\\n"); if (gossipInfoSubLines.length > 2) { gossipMap.put("PUBLIC_IP", gossipInfoSubLines[0].trim()); if (gossipMap.get("PUBLIC_IP") != null) { returnPublicIpSourceIpMap.add(gossipMap); } for (String gossipInfoSubLine : gossipInfoSubLines) { String gossipLineEntry[] = gossipInfoSubLine.split(":"); if (gossipLineEntry.length == 2) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[1].trim()); } else if (gossipLineEntry.length == 3) { if (gossipLineEntry[0] .trim() .equalsIgnoreCase("STATUS")) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].split(",")[0].trim()); } else if (gossipLineEntry[0] .trim() .equalsIgnoreCase("TOKENS")) { try { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), nodeTool.getTokens( gossipMap.get( "PUBLIC_IP")) .toString()); } catch (Exception e) { logger.warn( "Unable to find TOKEN(s) for the IP: {}", gossipMap.get("PUBLIC_IP")); } } else { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].trim()); } } } } }); } catch (Exception e) { logger.error("Unable to parse nodetool gossipinfo output from Cassandra.", e); } return returnPublicIpSourceIpMap; } @Inject  CassandraOperations(IConfiguration configuration); @Override synchronized void takeSnapshot(final String snapshotName); @Override void clearSnapshot(final String snapshotTag); @Override List<String> getKeyspaces(); @Override Map<String, List<String>> getColumnfamilies(); @Override void forceKeyspaceCompaction(String keyspaceName, String... columnfamilies); @Override void forceKeyspaceFlush(String keyspaceName); @Override List<Map<String, String>> gossipInfo(); }
CassandraOperations implements ICassandraOperations { @Override public List<Map<String, String>> gossipInfo() throws Exception { List<Map<String, String>> returnPublicIpSourceIpMap = new ArrayList(); try { JMXNodeTool nodeTool; try { nodeTool = JMXNodeTool.instance(configuration); } catch (JMXConnectionException e) { logger.error( "Exception in fetching c* jmx tool . Msg: {}", e.getLocalizedMessage(), e); throw e; } String gossipInfoLines[] = nodeTool.getGossipInfo().split("/"); Arrays.stream(gossipInfoLines) .forEach( gossipInfoLine -> { Map<String, String> gossipMap = new HashMap<>(); String gossipInfoSubLines[] = gossipInfoLine.split("\\r?\\n"); if (gossipInfoSubLines.length > 2) { gossipMap.put("PUBLIC_IP", gossipInfoSubLines[0].trim()); if (gossipMap.get("PUBLIC_IP") != null) { returnPublicIpSourceIpMap.add(gossipMap); } for (String gossipInfoSubLine : gossipInfoSubLines) { String gossipLineEntry[] = gossipInfoSubLine.split(":"); if (gossipLineEntry.length == 2) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[1].trim()); } else if (gossipLineEntry.length == 3) { if (gossipLineEntry[0] .trim() .equalsIgnoreCase("STATUS")) { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].split(",")[0].trim()); } else if (gossipLineEntry[0] .trim() .equalsIgnoreCase("TOKENS")) { try { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), nodeTool.getTokens( gossipMap.get( "PUBLIC_IP")) .toString()); } catch (Exception e) { logger.warn( "Unable to find TOKEN(s) for the IP: {}", gossipMap.get("PUBLIC_IP")); } } else { gossipMap.put( gossipLineEntry[0].trim().toUpperCase(), gossipLineEntry[2].trim()); } } } } }); } catch (Exception e) { logger.error("Unable to parse nodetool gossipinfo output from Cassandra.", e); } return returnPublicIpSourceIpMap; } @Inject  CassandraOperations(IConfiguration configuration); @Override synchronized void takeSnapshot(final String snapshotName); @Override void clearSnapshot(final String snapshotTag); @Override List<String> getKeyspaces(); @Override Map<String, List<String>> getColumnfamilies(); @Override void forceKeyspaceCompaction(String keyspaceName, String... columnfamilies); @Override void forceKeyspaceFlush(String keyspaceName); @Override List<Map<String, String>> gossipInfo();  }