Package org.apache.helix.manager.zk

Examples of org.apache.helix.manager.zk.ZkClient


                100);

        public DatabusClusterUtilHelper(String zkAddr, String clusterName)
        {
            _clusterName = clusterName;
            _zkClient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
                    ZkClient.DEFAULT_CONNECTION_TIMEOUT,
                    new ZNRecordSerializer());
            _admin = new ZKHelixAdmin(_zkClient);
        }
View Full Code Here


    return presentation;
  }

  StringRepresentation getInstanceCurrentStatesRepresentation(String clusterName, String instanceName) throws JsonGenerationException, JsonMappingException, IOException
  {
    ZkClient zkClient = (ZkClient)getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);;
    String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName);
   
    String message = ClusterRepresentationUtil.getInstancePropertyNameListAsString(zkClient, clusterName, instanceName, PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON);

    StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON);
View Full Code Here

                                                     String resourceName) throws JsonGenerationException,
      JsonMappingException,
      IOException
  {
    Builder keyBuilder = new PropertyKey.Builder(clusterName);
    ZkClient zkClient = (ZkClient)getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);;
   
    String message =
        ClusterRepresentationUtil.getClusterPropertyAsString(zkClient,
                                                             clusterName,
                                                             keyBuilder.externalView(resourceName),
View Full Code Here

                                                             CountDownLatch countDown)
  {

    final Map<TestCommand, Boolean> testResults =
        new ConcurrentHashMap<TestCommand, Boolean>();
    ZkClient zkClient = null;

    zkClient = new ZkClient(zkAddr, ZkClient.DEFAULT_CONNECTION_TIMEOUT);
    zkClient.setZkSerializer(new ZNRecordSerializer());

    // sort on trigger's start time, stable sort
    Collections.sort(commandList, new Comparator<TestCommand>()
    {
      @Override
View Full Code Here

  public static ZkClient getZkClient(String zkServer)
  {
    // happy path that we cache the zkclient and it's still connected
    if (_zkClientMap.containsKey(zkServer))
    {
      ZkClient zkClient = _zkClientMap.get(zkServer);
      if (zkClient.getConnection().getZookeeperState() == States.CONNECTED)
      {
        return zkClient;
      }
    }

    synchronized (_zkClientMap)
    {
      // if we cache a stale zkclient, purge it
      if (_zkClientMap.containsKey(zkServer))
      {
        ZkClient zkClient = _zkClientMap.get(zkServer);
        if (zkClient.getConnection().getZookeeperState() != States.CONNECTED)
        {
          _zkClientMap.remove(zkServer);
        }
      }

      // get a new zkclient
      if (!_zkClientMap.containsKey(zkServer))
      {
        ZkClient zkClient = new ZkClient(zkServer, DEFAULT_SESSION_TIMEOUT,
            ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());

        _zkClientMap.put(zkServer, zkClient);
      }
      return _zkClientMap.get(zkServer);
View Full Code Here

                                                             String instanceName,
                                                             String resourceGroup) throws JsonGenerationException,
      JsonMappingException,
      IOException
  {
    ZkClient zkClient = (ZkClient)getRequest().getAttributes().get(RestAdminApplication.ZKCLIENT);
    String instanceSessionId =
        ClusterRepresentationUtil.getInstanceSessionId(zkClient,
                                                       clusterName,
                                                       instanceName);
    Builder keyBuilder = new PropertyKey.Builder(clusterName);
View Full Code Here

  StringRepresentation getClustersRepresentation() throws JsonGenerationException,
      JsonMappingException,
      IOException
  {
    ZkClient zkClient =
        (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    List<String> clusters = setupTool.getClusterManagementTool().getClusters();

    ZNRecord clustersRecord = new ZNRecord("Clusters Summary");
View Full Code Here

  public void post(String zkServer,
                   Message message,
                   String clusterName,
                   String instanceName)
  {
    ZkClient client = new ZkClient(zkServer);
    client.setZkSerializer(new ZNRecordSerializer());
    String path = HelixUtil.getMessagePath(clusterName, instanceName) + "/" + message.getId();
    client.delete(path);
    ZNRecord record = client.readData(HelixUtil.getLiveInstancePath(clusterName, instanceName));
    message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString()).toString());
    message.setTgtName(record.getId());
    //System.out.println(message);
    client.createPersistent(path, message.getRecord());
  }
View Full Code Here

      }
      else if (command.equalsIgnoreCase(ClusterSetup.addCluster))
      {
        jsonParameters.verifyCommand(ClusterSetup.addCluster);

        ZkClient zkClient =
            (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkClient);
        setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME),
                             false);
      }
View Full Code Here

    final String zkAddr = args[0];
    final int numNodes = Integer.parseInt(args[1]);
    final String clusterName = DEFAULT_CLUSTER_NAME;

    ZkClient zkclient = null;
    try
    {
      zkclient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
          ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
      ZKHelixAdmin admin = new ZKHelixAdmin(zkclient);

      // add cluster
      admin.addCluster(clusterName, true);

      // add state model definition
      StateModelConfigGenerator generator = new StateModelConfigGenerator();
      admin.addStateModelDef(clusterName, DEFAULT_STATE_MODEL,
          new StateModelDefinition(generator.generateConfigForOnlineOffline()));
      // addNodes
      for (int i = 0; i < numNodes; i++)
      {
        String port = "" +(12001+ i);
        String serverId = "localhost_"+ port;
        InstanceConfig config = new InstanceConfig(serverId);
        config.setHostName("localhost");
        config.setPort(port);
        config.setInstanceEnabled(true);
        admin.addInstance(clusterName, config);
      }
      // add resource "repository" which has 1 partition
      String resourceName = DEFAULT_RESOURCE_NAME;
      admin.addResource(clusterName, resourceName, DEFAULT_PARTITION_NUMBER,
          DEFAULT_STATE_MODEL, IdealStateModeProperty.AUTO.toString());
      admin.rebalance(clusterName, resourceName, 1);

    } finally
    {
      if (zkclient != null)
      {
        zkclient.close();
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.helix.manager.zk.ZkClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.