Package org.apache.helix.api

Examples of org.apache.helix.api.Cluster


  }

  @Override
  public boolean verify() throws Exception {
    ClusterAccessor clusterAccessor = new ClusterAccessor(ClusterId.from(_clusterName), _accessor);
    Cluster cluster = clusterAccessor.readCluster();

    List<ParticipantId> liveInstances = new ArrayList<ParticipantId>();
    liveInstances.addAll(cluster.getLiveParticipantMap().keySet());
    boolean success = verifyLiveNodes(liveInstances);
    if (!success) {
      LOG.info("liveNodes not match, expect: " + _expectSortedLiveNodes + ", actual: "
          + liveInstances);
      return false;
View Full Code Here


    accessor.dropCluster();
  }

  private static void printExternalView(HelixConnection connection, ClusterId clusterId, ResourceId resourceId) {
    ClusterAccessor accessor = connection.createClusterAccessor(clusterId);
    Cluster cluster = accessor.readCluster();
    ExternalView externalView = cluster.getResource(resourceId).getExternalView();
    System.out.println("ASSIGNMENTS:");
    for (PartitionId partitionId : externalView.getPartitionIdSet()) {
      System.out.println(partitionId + ": " + externalView.getStateMap(partitionId));
    }
  }
View Full Code Here

      ClusterAccessor accessor = connection.createClusterAccessor(clusterId);
      TaskDriver driver = new TaskDriver(manager);
      while (true) {
        System.out.println("CONTAINER STATUS");
        System.out.println("----------------");
        Cluster cluster = accessor.readCluster();
        Collection<Participant> participants = cluster.getParticipantMap().values();
        for (Participant participant : participants) {
          ContainerConfig containerConfig = participant.getContainerConfig();
          if (containerConfig != null) {
            System.out.println(participant.getId() + "[" + containerConfig.getId() + "]: "
                + containerConfig.getState());
View Full Code Here

    // create a cluster
    boolean created = createCluster(clusterId, accessor, MODIFIER, 1);
    Assert.assertTrue(created);

    // read the cluster
    Cluster clusterSnapshot = accessor.readCluster();
    Assert.assertEquals(clusterSnapshot.getUserConfig().getIntField(MODIFIER, -1), 1);

    // create a cluster with the same id
    boolean created2 = createCluster(clusterId, accessor, MODIFIER, 2);
    Assert.assertFalse(created2); // should fail since cluster exists

    // remove a required property
    helixAccessor.removeProperty(helixAccessor.keyBuilder().liveInstances());

    // try again, should work this time
    created2 = createCluster(clusterId, accessor, MODIFIER, 2);
    Assert.assertTrue(created2);

    // read the cluster again
    clusterSnapshot = accessor.readCluster();
    Assert.assertEquals(clusterSnapshot.getUserConfig().getIntField(MODIFIER, -1), 2);

    accessor.dropCluster();
  }
View Full Code Here

    String testName = className + "_" + methodName;

    System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));

    ClusterAccessor clusterAccessor = new ClusterAccessor(_clusterId, _dataAccessor);
    Cluster cluster = clusterAccessor.readCluster();

    ClusterId id = cluster.getId();
    Assert.assertEquals(id, _clusterId);
    Map<ParticipantId, Participant> liveParticipantMap = cluster.getLiveParticipantMap();
    Assert.assertEquals(liveParticipantMap.size(), n);

    for (ParticipantId participantId : liveParticipantMap.keySet()) {
      Participant participant = liveParticipantMap.get(participantId);
      Map<ResourceId, CurrentState> curStateMap = participant.getCurrentStateMap();
      Assert.assertEquals(curStateMap.size(), 1);

      ResourceId resourceId = ResourceId.from("TestDB0");
      Assert.assertTrue(curStateMap.containsKey(resourceId));
      CurrentState curState = curStateMap.get(resourceId);
      Map<PartitionId, State> partitionStateMap = curState.getTypedPartitionStateMap();
      Assert.assertEquals(partitionStateMap.size(), p);
    }

    Map<ResourceId, Resource> resourceMap = cluster.getResourceMap();
    Assert.assertEquals(resourceMap.size(), 1);

    ResourceId resourceId = ResourceId.from("TestDB0");
    Assert.assertTrue(resourceMap.containsKey(resourceId));
    Resource resource = resourceMap.get(resourceId);
View Full Code Here

    System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));

    // Set up the event
    ClusterAccessor clusterAccessor = new ClusterAccessor(_clusterId, _dataAccessor);
    Cluster cluster = clusterAccessor.readCluster();
    ClusterEvent event = new ClusterEvent(testName);
    event.addAttribute(AttributeName.CURRENT_STATE.toString(), new ResourceCurrentState());
    Map<ResourceId, ResourceConfig> resourceConfigMap =
        Maps.transformValues(cluster.getResourceMap(), new Function<Resource, ResourceConfig>() {
          @Override
          public ResourceConfig apply(Resource resource) {
            return resource.getConfig();
          }
        });
    event.addAttribute(AttributeName.RESOURCES.toString(), resourceConfigMap);
    event.addAttribute("Cluster", cluster);

    // Run the stage
    try {
      new BestPossibleStateCalcStage().process(event);
    } catch (Exception e) {
      Assert.fail(e.toString());
    }

    // Verify the result
    BestPossibleStateOutput bestPossibleStateOutput =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
    Assert.assertNotNull(bestPossibleStateOutput);
    ResourceId resourceId = ResourceId.from("TestDB0");
    ResourceAssignment assignment = bestPossibleStateOutput.getResourceAssignment(resourceId);
    Assert.assertNotNull(assignment);
    Resource resource = cluster.getResource(resourceId);
    verifySemiAutoRebalance(resource, assignment);

    System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

    String testName = className + "_" + methodName;

    System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));

    ClusterAccessor clusterAccessor = new ClusterAccessor(_clusterId, _dataAccessor);
    Cluster cluster = clusterAccessor.readCluster();

    ResourceId resourceId = ResourceId.from("TestDB0");
    Resource resource = cluster.getResource(resourceId);
    ResourceCurrentState currentStateOutput = new ResourceCurrentState();
    ResourceAssignment semiAutoResult =
        resource
            .getIdealState()
            .getRebalancerRef()
View Full Code Here

          idealStates.put(resource, new IdealState(resource));
        }
      }

      ClusterAccessor clusterAccessor = new ClusterAccessor(ClusterId.from(clusterName), accessor);
      Cluster cluster = clusterAccessor.readCluster();
      // calculate best possible state
      BestPossibleStateOutput bestPossOutput =
          ClusterStateVerifier.calcBestPossState(cluster, resources);

      // set error states
View Full Code Here

    // refresh the cache
    ClusterEvent event = new ClusterEvent("testEvent");
    ClusterId clusterId = new ClusterId("sampleClusterId");
    ClusterAccessor clusterAccessor = new MockClusterAccessor(clusterId, accessor);
    Cluster cluster = clusterAccessor.readCluster();
    event.addAttribute("Cluster", cluster);
    event.addAttribute(AttributeName.IDEAL_STATE_RULES.toString(),
        clusterConfiguration.getIdealStateRules());

    // run resource computation
View Full Code Here

    // refresh the cache
    ClusterEvent event = new ClusterEvent("testEvent");
    ClusterId clusterId = new ClusterId("sampleClusterId");
    ClusterAccessor clusterAccessor = new MockClusterAccessor(clusterId, accessor);
    Cluster cluster = clusterAccessor.readCluster();
    event.addAttribute("Cluster", cluster);
    Map<String, Map<String, String>> emptyMap = Maps.newHashMap();
    event.addAttribute(AttributeName.IDEAL_STATE_RULES.toString(), emptyMap);

    // run resource computation
View Full Code Here

TOP

Related Classes of org.apache.helix.api.Cluster

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.