Example #1
0
 public AbstractJoiner(Node node) {
   this.node = node;
   this.logger = node.loggingService.getLogger(getClass());
   this.config = node.config;
   this.clusterService = node.getClusterService();
   this.clusterJoinManager = clusterService.getClusterJoinManager();
   mergeNextRunDelayMs =
       node.groupProperties.getMillis(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS);
 }
  @Before
  public void setup() {
    when(node.getPartitionService()).thenReturn(partitionService);
    when(node.getClusterService()).thenReturn(clusterService);
    when(node.getNodeExtension()).thenReturn(mock(NodeExtension.class));
    when(node.getLogger(ClusterStateManager.class)).thenReturn(mock(ILogger.class));

    clusterStateManager = new ClusterStateManager(node, lock);
  }
  @Override
  public Map<ClientType, Integer> getConnectedClientStats() {

    int numberOfCppClients = 0;
    int numberOfDotNetClients = 0;
    int numberOfJavaClients = 0;
    int numberOfOtherClients = 0;

    Operation clientInfoOperation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Map<ClientType, Integer> resultMap = new HashMap<ClientType, Integer>();
    Map<String, ClientType> clientsMap = new HashMap<String, ClientType>();

    for (Member member : node.getClusterService().getMembers()) {
      Address target = member.getAddress();
      Future<Map<String, ClientType>> future =
          operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
      try {
        Map<String, ClientType> endpoints = future.get();
        if (endpoints == null) {
          continue;
        }
        // Merge connected clients according to their uuid.
        for (Map.Entry<String, ClientType> entry : endpoints.entrySet()) {
          clientsMap.put(entry.getKey(), entry.getValue());
        }
      } catch (Exception e) {
        logger.warning("Cannot get client information from: " + target.toString(), e);
      }
    }

    // Now we are regrouping according to the client type
    for (ClientType clientType : clientsMap.values()) {
      switch (clientType) {
        case JAVA:
          numberOfJavaClients++;
          break;
        case CSHARP:
          numberOfDotNetClients++;
          break;
        case CPP:
          numberOfCppClients++;
          break;
        default:
          numberOfOtherClients++;
      }
    }

    resultMap.put(ClientType.CPP, numberOfCppClients);
    resultMap.put(ClientType.CSHARP, numberOfDotNetClients);
    resultMap.put(ClientType.JAVA, numberOfJavaClients);
    resultMap.put(ClientType.OTHER, numberOfOtherClients);

    return resultMap;
  }
Example #4
0
  private void registerCoreServices() {
    logger.finest("Registering core services...");

    Node node = nodeEngine.getNode();
    registerService(ClusterServiceImpl.SERVICE_NAME, node.getClusterService());
    registerService(InternalPartitionService.SERVICE_NAME, node.getPartitionService());
    registerService(ProxyServiceImpl.SERVICE_NAME, nodeEngine.getProxyService());
    registerService(
        TransactionManagerServiceImpl.SERVICE_NAME, nodeEngine.getTransactionManagerService());
    registerService(ClientEngineImpl.SERVICE_NAME, node.clientEngine);
    registerService(QuorumServiceImpl.SERVICE_NAME, nodeEngine.getQuorumService());
  }
  public Map<String, String> phoneHome(Node hazelcastNode, String version, boolean isEnterprise) {

    String downloadId = "source";
    InputStream is = null;
    try {
      is = getClass().getClassLoader().getResourceAsStream("hazelcast-download.properties");
      if (is != null) {
        final Properties properties = new Properties();
        properties.load(is);
        downloadId = properties.getProperty("hazelcastDownloadId");
      }
    } catch (IOException ignored) {
      EmptyStatement.ignore(ignored);
    } finally {
      IOUtil.closeResource(is);
    }

    // Calculate native memory usage from native memory config
    NativeMemoryConfig memoryConfig = hazelcastNode.getConfig().getNativeMemoryConfig();
    final ClusterServiceImpl clusterService = hazelcastNode.getClusterService();
    long totalNativeMemorySize =
        clusterService.getSize(DATA_MEMBER_SELECTOR) * memoryConfig.getSize().bytes();
    String nativeMemoryParameter =
        (isEnterprise) ? Long.toString(MemoryUnit.BYTES.toGigaBytes(totalNativeMemorySize)) : "0";
    // Calculate connected clients to the cluster.
    Map<ClientType, Integer> clusterClientStats =
        hazelcastNode.clientEngine.getConnectedClientStats();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();

    Long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();

    PhoneHomeParameterCreator parameterCreator = new PhoneHomeParameterCreator();
    parameterCreator.addParam("version", version);
    parameterCreator.addParam("m", hazelcastNode.getLocalMember().getUuid());
    parameterCreator.addParam("e", Boolean.toString(isEnterprise));
    parameterCreator.addParam("l", MD5Util.toMD5String(hazelcastNode.getConfig().getLicenseKey()));
    parameterCreator.addParam("p", downloadId);
    parameterCreator.addParam("c", clusterService.getClusterId());
    parameterCreator.addParam("crsz", convertToLetter(clusterService.getMembers().size()));
    parameterCreator.addParam(
        "cssz", convertToLetter(hazelcastNode.clientEngine.getClientEndpointCount()));
    parameterCreator.addParam("hdgb", nativeMemoryParameter);
    parameterCreator.addParam("ccpp", Integer.toString(clusterClientStats.get(ClientType.CPP)));
    parameterCreator.addParam("cdn", Integer.toString(clusterClientStats.get(ClientType.CSHARP)));
    parameterCreator.addParam("cjv", Integer.toString(clusterClientStats.get(ClientType.JAVA)));
    parameterCreator.addParam("cuptm", Long.toString(clusterUpTime));
    parameterCreator.addParam("nuptm", Long.toString(runtimeMxBean.getUptime()));
    String urlStr = BASE_PHONE_HOME_URL + parameterCreator.build();
    fetchWebService(urlStr);

    return parameterCreator.getParameters();
  }