Java Code Examples for org.apache.helix.model.IdealState#setRebalancerClassName()

The following examples show how to use org.apache.helix.model.IdealState#setRebalancerClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZkTestBase.java    From helix with Apache License 2.0 6 votes vote down vote up
private IdealState createResource(String clusterName, String db, String stateModel,
    int numPartition, int replica, int minActiveReplica, long delay, String rebalancerClassName,
    String rebalanceStrategy) {
  IdealState idealState =
      _gSetupTool.getClusterManagementTool().getResourceIdealState(clusterName, db);
  if (idealState == null) {
    _gSetupTool.addResourceToCluster(clusterName, db, numPartition, stateModel,
        IdealState.RebalanceMode.FULL_AUTO + "", rebalanceStrategy);
  }

  idealState = _gSetupTool.getClusterManagementTool().getResourceIdealState(clusterName, db);
  idealState.setMinActiveReplicas(minActiveReplica);
  if (!idealState.isDelayRebalanceEnabled()) {
    idealState.setDelayRebalanceEnabled(true);
  }
  if (delay > 0) {
    idealState.setRebalanceDelay(delay);
  }
  idealState.setRebalancerClassName(rebalancerClassName);
  _gSetupTool.getClusterManagementTool().setResourceIdealState(clusterName, db, idealState);
  _gSetupTool.rebalanceStorageCluster(clusterName, db, replica);
  idealState = _gSetupTool.getClusterManagementTool().getResourceIdealState(clusterName, db);

  return idealState;
}
 
Example 2
Source File: ZKHelixAdmin.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
public void addClusterToGrandCluster(String clusterName, String grandCluster) {
  logger.info("Add cluster {} to grand cluster {}.", clusterName, grandCluster);
  if (!ZKUtil.isClusterSetup(grandCluster, _zkClient)) {
    throw new HelixException("Grand cluster " + grandCluster + " is not setup yet");
  }

  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("Cluster " + clusterName + " is not setup yet");
  }

  IdealState idealState = new IdealState(clusterName);

  idealState.setNumPartitions(1);
  idealState.setStateModelDefRef("LeaderStandby");
  idealState.setRebalanceMode(RebalanceMode.FULL_AUTO);
  idealState.setRebalancerClassName(DelayedAutoRebalancer.class.getName());
  idealState.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
  // TODO: Give user an option, say from RestAPI to config the number of replicas.
  idealState.setReplicas(Integer.toString(DEFAULT_SUPERCLUSTER_REPLICA));
  idealState.getRecord().setListField(clusterName, new ArrayList<String>());

  List<String> controllers = getInstancesInCluster(grandCluster);
  if (controllers.size() == 0) {
    throw new HelixException("Grand cluster " + grandCluster + " has no instances");
  }

  ZKHelixDataAccessor accessor =
      new ZKHelixDataAccessor(grandCluster, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();

  accessor.setProperty(keyBuilder.idealStates(idealState.getResourceName()), idealState);
}
 
Example 3
Source File: TaskDriver.java    From helix with Apache License 2.0 5 votes vote down vote up
private IdealState buildWorkflowIdealState(String workflow) {
  CustomModeISBuilder IsBuilder = new CustomModeISBuilder(workflow);
  IsBuilder.setRebalancerMode(IdealState.RebalanceMode.TASK).setNumReplica(1).setNumPartitions(1)
      .setStateModel(TaskConstants.STATE_MODEL_NAME).disableExternalView();

  IdealState is = IsBuilder.build();
  is.getRecord().setListField(workflow, new ArrayList<>());
  is.getRecord().setMapField(workflow, new HashMap<>());
  is.setRebalancerClassName(WorkflowRebalancer.class.getName());

  return is;
}
 
Example 4
Source File: TestNoThrottleDisabledPartitions.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Set up delayed rebalancer and minimum active replica settings to mimic user's use case.
 * @param clusterName
 * @param participantCount
 * @throws Exception
 */
private void setupCluster(String clusterName, int participantCount) throws Exception {
  TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start port
      "localhost", // participant name prefix
      _resourceName, // resource name prefix
      3, // resources
      5, // partitions per resource
      participantCount, // number of nodes
      3, // replicas
      "MasterSlave", IdealState.RebalanceMode.FULL_AUTO, true); // do rebalance

  // Enable DelayedAutoRebalance
  ClusterConfig clusterConfig = _accessor.getProperty(_accessor.keyBuilder().clusterConfig());
  clusterConfig.setDelayRebalaceEnabled(true);
  clusterConfig.setRebalanceDelayTime(1800000L);
  _accessor.setProperty(_accessor.keyBuilder().clusterConfig(), clusterConfig);

  // Set minActiveReplicas at 2
  List<String> idealStates = _accessor.getChildNames(_accessor.keyBuilder().idealStates());
  for (String is : idealStates) {
    IdealState idealState = _accessor.getProperty(_accessor.keyBuilder().idealStates(is));
    idealState.setMinActiveReplicas(2);
    idealState.setRebalanceStrategy(
        "org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy");
    idealState
        .setRebalancerClassName("org.apache.helix.controller.rebalancer.DelayedAutoRebalancer");
    _accessor.setProperty(_accessor.keyBuilder().idealStates(is), idealState);
  }
}
 
Example 5
Source File: BaseStageTest.java    From helix with Apache License 2.0 5 votes vote down vote up
protected List<IdealState> setupIdealState(int nodes, String[] resources, int partitions,
    int replicas, RebalanceMode rebalanceMode, String stateModelName, String rebalanceClassName,
    String rebalanceStrategyName, int minActiveReplica) {
  List<IdealState> idealStates = new ArrayList<IdealState>();
  for (String resourceName : resources) {
    ZNRecord record = new ZNRecord(resourceName);
    for (int p = 0; p < partitions; p++) {
      List<String> value = new ArrayList<String>();
      for (int r = 0; r < replicas; r++) {
        value.add(HOSTNAME_PREFIX + (p + r + 1) % nodes);
      }
      record.setListField(resourceName + "_" + p, value);
    }
    IdealState idealState = new IdealState(record);
    idealState.setStateModelDefRef(stateModelName);
    if (rebalanceClassName != null) {
      idealState.setRebalancerClassName(rebalanceClassName);
    }
    if (rebalanceStrategyName != null) {
      idealState.setRebalanceStrategy(rebalanceStrategyName);
    }
    idealState.setRebalanceMode(rebalanceMode);
    idealState.setNumPartitions(partitions);
    idealStates.add(idealState);
    idealState.setReplicas(String.valueOf(replicas));

    if (minActiveReplica > 0) {
      idealState.setMinActiveReplicas(minActiveReplica);
    }

    Builder keyBuilder = accessor.keyBuilder();

    accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
  }
  return idealStates;
}
 
Example 6
Source File: TestClusterModelProvider.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
protected ResourceControllerDataProvider setupClusterDataCache() throws IOException {
  ResourceControllerDataProvider testCache = super.setupClusterDataCache();

  // Set up mock idealstate
  Map<String, IdealState> isMap = new HashMap<>();
  for (String resource : _resourceNames) {
    IdealState is = new IdealState(resource);
    is.setNumPartitions(_partitionNames.size());
    is.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
    is.setStateModelDefRef("MasterSlave");
    is.setReplicas("3");
    is.setRebalancerClassName(WagedRebalancer.class.getName());
    _partitionNames.stream()
        .forEach(partition -> is.setPreferenceList(partition, Collections.emptyList()));
    isMap.put(resource, is);
  }
  when(testCache.getIdealState(anyString())).thenAnswer(
      (Answer<IdealState>) invocationOnMock -> isMap.get(invocationOnMock.getArguments()[0]));

  // Set up 2 more instances
  for (int i = 1; i < 3; i++) {
    String instanceName = _testInstanceId + i;
    _instances.add(instanceName);
    // 1. Set up the default instance information with capacity configuration.
    InstanceConfig testInstanceConfig = createMockInstanceConfig(instanceName);
    Map<String, InstanceConfig> instanceConfigMap = testCache.getInstanceConfigMap();
    instanceConfigMap.put(instanceName, testInstanceConfig);
    when(testCache.getInstanceConfigMap()).thenReturn(instanceConfigMap);
    // 2. Mock the live instance node for the default instance.
    LiveInstance testLiveInstance = createMockLiveInstance(instanceName);
    Map<String, LiveInstance> liveInstanceMap = testCache.getLiveInstances();
    liveInstanceMap.put(instanceName, testLiveInstance);
    when(testCache.getLiveInstances()).thenReturn(liveInstanceMap);
  }

  return testCache;
}
 
Example 7
Source File: IdealStateBuilder.java    From helix with Apache License 2.0 4 votes vote down vote up
/**
 * @return
 */
public IdealState build() {
  IdealState idealstate = new IdealState(_record);
  idealstate.setNumPartitions(numPartitions);
  idealstate.setStateModelDefRef(stateModel);
  idealstate.setStateModelFactoryName(stateModelFactoryName);
  idealstate.setRebalanceMode(rebalancerMode);
  idealstate.setReplicas("" + numReplica);

  if (minActiveReplica >= 0) {
    idealstate.setMinActiveReplicas(minActiveReplica);
  }

  if (rebalancerClassName != null) {
    idealstate.setRebalancerClassName(rebalancerClassName);
  }

  if (rebalanceStrategy != null) {
    idealstate.setRebalanceStrategy(rebalanceStrategy);
  }

  if (maxPartitionsPerNode > 0) {
    idealstate.setMaxPartitionsPerInstance(maxPartitionsPerNode);
  }

  if (disableExternalView != null) {
    idealstate.setDisableExternalView(disableExternalView);
  }

  if (enableGroupRouting != null) {
    idealstate.enableGroupRouting(enableGroupRouting);
  }

  if (resourceGroupName != null) {
    idealstate.setResourceGroupName(resourceGroupName);
  }

  if (resourceType != null) {
    idealstate.setResourceType(resourceType);
  }

  if (rebalanceDelayInMs >= 0) {
    idealstate.setRebalanceDelay(rebalanceDelayInMs);
  }

  if (delayRebalanceEnabled != null) {
    idealstate.setDelayRebalanceEnabled(delayRebalanceEnabled);
  }

  if (!idealstate.isValid()) {
    throw new HelixException("invalid ideal-state: " + idealstate);
  }
  return idealstate;
}
 
Example 8
Source File: WorkflowDispatcher.java    From helix with Apache License 2.0 4 votes vote down vote up
/**
 * Posts new job to cluster
 */
private void scheduleSingleJob(String jobResource, JobConfig jobConfig) {
  HelixAdmin admin = _manager.getClusterManagmentTool();

  IdealState jobIS = admin.getResourceIdealState(_manager.getClusterName(), jobResource);
  if (jobIS != null) {
    LOG.info("Job " + jobResource + " idealstate already exists!");
    return;
  }

  // Set up job resource based on partitions from target resource

  // Create the UserContentStore for the job first
  TaskUtil.createUserContent(_manager.getHelixPropertyStore(), jobResource,
      new ZNRecord(TaskUtil.USER_CONTENT_NODE));

  int numPartitions = jobConfig.getTaskConfigMap().size();
  if (numPartitions == 0) {
    IdealState targetIs =
        admin.getResourceIdealState(_manager.getClusterName(), jobConfig.getTargetResource());
    if (targetIs == null) {
      LOG.warn("Target resource does not exist for job " + jobResource);
      // do not need to fail here, the job will be marked as failure immediately when job starts
      // running.
    } else {
      numPartitions = targetIs.getPartitionSet().size();
    }
  }

  admin.addResource(_manager.getClusterName(), jobResource, numPartitions,
      TaskConstants.STATE_MODEL_NAME);

  HelixDataAccessor accessor = _manager.getHelixDataAccessor();

  // Set the job configuration
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();
  HelixProperty resourceConfig = new HelixProperty(jobResource);
  resourceConfig.getRecord().getSimpleFields().putAll(jobConfig.getResourceConfigMap());
  Map<String, TaskConfig> taskConfigMap = jobConfig.getTaskConfigMap();
  if (taskConfigMap != null) {
    for (TaskConfig taskConfig : taskConfigMap.values()) {
      resourceConfig.getRecord().setMapField(taskConfig.getId(), taskConfig.getConfigMap());
    }
  }
  accessor.setProperty(keyBuilder.resourceConfig(jobResource), resourceConfig);

  // Push out new ideal state based on number of target partitions
  IdealStateBuilder builder = new CustomModeISBuilder(jobResource);
  builder.setRebalancerMode(IdealState.RebalanceMode.TASK);
  builder.setNumReplica(1);
  builder.setNumPartitions(numPartitions);
  builder.setStateModel(TaskConstants.STATE_MODEL_NAME);

  if (jobConfig.getInstanceGroupTag() != null) {
    builder.setNodeGroup(jobConfig.getInstanceGroupTag());
  }

  if (jobConfig.isDisableExternalView()) {
    builder.disableExternalView();
  }

  jobIS = builder.build();
  for (int i = 0; i < numPartitions; i++) {
    jobIS.getRecord().setListField(jobResource + "_" + i, new ArrayList<>());
    jobIS.getRecord().setMapField(jobResource + "_" + i, new HashMap<>());
  }
  jobIS.setRebalancerClassName(JobRebalancer.class.getName());
  admin.setResourceIdealState(_manager.getClusterName(), jobResource, jobIS);
}
 
Example 9
Source File: TestPartitionMovementThrottle.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {
    "testResourceThrottle"
})
public void testResourceThrottleWithDelayRebalancer() {
  // start a few participants
  for (int i = 0; i < NODE_NR - 2; i++) {
    _participants[i].syncStart();
  }

  int partition = 10;
  int replica = 3;
  int minActiveReplica = 2;
  int delay = 100;

  for (int i = 0; i < 5; i++) {
    String dbName = "TestDB-" + i;
    IdealState is =
        _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, dbName);
    if (is != null) {
      System.err.println(dbName + "exists!");
      is.setReplicas(String.valueOf(replica));
      is.setMinActiveReplicas(minActiveReplica);
      is.setRebalanceDelay(delay);
      is.setRebalancerClassName(DelayedAutoRebalancer.class.getName());
      _gSetupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, dbName, is);
    } else {
      createResourceWithDelayedRebalance(CLUSTER_NAME, dbName, STATE_MODEL, partition, replica,
          minActiveReplica, delay);
    }
    _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, dbName, _replica);
    _dbs.add(dbName);
  }

  Assert.assertTrue(_clusterVerifier.verifyByPolling());

  DelayedTransition.setDelay(20);
  DelayedTransition.enableThrottleRecord();

  // add 2 nodes
  for (int i = NODE_NR - 2; i < NODE_NR; i++) {
    _participants[i].syncStart();
  }

  Assert.assertTrue(_clusterVerifier.verifyByPolling());

  for (String db : _dbs) {
    int maxInParallel =
        getMaxParallelTransitionCount(DelayedTransition.getResourcePatitionTransitionTimes(), db);
    System.out.println("MaxInParallel: " + maxInParallel + " maxPendingTransition: " + 2);
    Assert.assertTrue(maxInParallel <= 2, "Throttle condition does not meet for " + db);
  }
}
 
Example 10
Source File: TestWagedRebalancerMigration.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "stateModels")
public void testMigrateToWagedRebalancerWhileExpandCluster(String stateModel,
    boolean delayEnabled)
    throws Exception {
  String db = "Test-DB-" + stateModel;
  if (delayEnabled) {
    createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica,
        _replica - 1, 3000000, CrushRebalanceStrategy.class.getName());
  } else {
    createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica,
        _replica, 0, CrushRebalanceStrategy.class.getName());
  }
  IdealState idealState =
      _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
  ClusterConfig config = _configAccessor.getClusterConfig(CLUSTER_NAME);
  config.setDelayRebalaceEnabled(delayEnabled);
  config.setRebalanceDelayTime(3000000);
  _configAccessor.setClusterConfig(CLUSTER_NAME, config);

  // add new instance to the cluster
  int numNodes = _participants.size();
  for (int i = numNodes; i < numNodes + NUM_NODE; i++) {
    String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
    MockParticipantManager participant = createAndStartParticipant(storageNodeName);
    _participants.add(participant);
    Thread.sleep(100);
  }
  Thread.sleep(2000);
  ZkHelixClusterVerifier clusterVerifier =
      new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
  Assert.assertTrue(clusterVerifier.verifyByPolling());

  _migrationVerifier =
      new MigrationStateVerifier(Collections.singletonMap(db, idealState), _manager);

  _migrationVerifier.reset();
  _migrationVerifier.start();

  IdealState currentIdealState =
      _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
  currentIdealState.setRebalancerClassName(WagedRebalancer.class.getName());
  _gSetupTool.getClusterManagementTool()
      .setResourceIdealState(CLUSTER_NAME, db, currentIdealState);
  Thread.sleep(2000);
  Assert.assertTrue(clusterVerifier.verifyByPolling());

  Assert.assertFalse(_migrationVerifier.hasLessReplica());
  Assert.assertFalse(_migrationVerifier.hasMoreReplica());

  _migrationVerifier.stop();
}
 
Example 11
Source File: TestWagedRebalancerMetrics.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
protected ResourceControllerDataProvider setupClusterDataCache() throws IOException {
  ResourceControllerDataProvider testCache = super.setupClusterDataCache();

  // Set up mock idealstate
  Map<String, IdealState> isMap = new HashMap<>();
  for (String resource : _resourceNames) {
    IdealState is = new IdealState(resource);
    is.setNumPartitions(_partitionNames.size());
    is.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
    is.setStateModelDefRef("MasterSlave");
    is.setReplicas("100");
    is.setRebalancerClassName(WagedRebalancer.class.getName());
    _partitionNames.stream()
        .forEach(partition -> is.setPreferenceList(partition, Collections.emptyList()));
    isMap.put(resource, is);
  }
  when(testCache.getIdealState(anyString())).thenAnswer(
      (Answer<IdealState>) invocationOnMock -> isMap.get(invocationOnMock.getArguments()[0]));
  when(testCache.getIdealStates()).thenReturn(isMap);
  when(testCache.getAsyncTasksThreadPool()).thenReturn(Executors.newSingleThreadExecutor());

  // Set up 2 more instances
  for (int i = 1; i < 3; i++) {
    String instanceName = _testInstanceId + i;
    _instances.add(instanceName);
    // 1. Set up the default instance information with capacity configuration.
    InstanceConfig testInstanceConfig = createMockInstanceConfig(instanceName);
    Map<String, InstanceConfig> instanceConfigMap = testCache.getInstanceConfigMap();
    instanceConfigMap.put(instanceName, testInstanceConfig);
    when(testCache.getInstanceConfigMap()).thenReturn(instanceConfigMap);
    // 2. Mock the live instance node for the default instance.
    LiveInstance testLiveInstance = createMockLiveInstance(instanceName);
    Map<String, LiveInstance> liveInstanceMap = testCache.getLiveInstances();
    liveInstanceMap.put(instanceName, testLiveInstance);
    when(testCache.getLiveInstances()).thenReturn(liveInstanceMap);
    when(testCache.getEnabledInstances()).thenReturn(liveInstanceMap.keySet());
    when(testCache.getEnabledLiveInstances()).thenReturn(liveInstanceMap.keySet());
    when(testCache.getAllInstances()).thenReturn(_instances);
  }

  return testCache;
}
 
Example 12
Source File: TestWagedRebalancer.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
protected ResourceControllerDataProvider setupClusterDataCache() throws IOException {
  ResourceControllerDataProvider testCache = super.setupClusterDataCache();

  // Set up mock idealstate
  Map<String, IdealState> isMap = new HashMap<>();
  for (String resource : _resourceNames) {
    IdealState is = new IdealState(resource);
    is.setNumPartitions(_partitionNames.size());
    is.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
    is.setStateModelDefRef("MasterSlave");
    is.setReplicas("3");
    is.setRebalancerClassName(WagedRebalancer.class.getName());
    _partitionNames.stream()
        .forEach(partition -> is.setPreferenceList(partition, Collections.emptyList()));
    isMap.put(resource, is);
  }
  when(testCache.getIdealState(anyString())).thenAnswer(
      (Answer<IdealState>) invocationOnMock -> isMap.get(invocationOnMock.getArguments()[0]));
  when(testCache.getIdealStates()).thenReturn(isMap);

  // Set up 2 more instances
  for (int i = 1; i < 3; i++) {
    String instanceName = _testInstanceId + i;
    _instances.add(instanceName);
    // 1. Set up the default instance information with capacity configuration.
    InstanceConfig testInstanceConfig = createMockInstanceConfig(instanceName);
    Map<String, InstanceConfig> instanceConfigMap = testCache.getInstanceConfigMap();
    instanceConfigMap.put(instanceName, testInstanceConfig);
    when(testCache.getInstanceConfigMap()).thenReturn(instanceConfigMap);
    // 2. Mock the live instance node for the default instance.
    LiveInstance testLiveInstance = createMockLiveInstance(instanceName);
    Map<String, LiveInstance> liveInstanceMap = testCache.getLiveInstances();
    liveInstanceMap.put(instanceName, testLiveInstance);
    when(testCache.getLiveInstances()).thenReturn(liveInstanceMap);
    when(testCache.getEnabledInstances()).thenReturn(liveInstanceMap.keySet());
    when(testCache.getEnabledLiveInstances()).thenReturn(liveInstanceMap.keySet());
    when(testCache.getAllInstances()).thenReturn(_instances);
  }

  return testCache;
}
 
Example 13
Source File: TestResourceAccessor.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = "deleteFromResourceIdealState")
public void testAddResourceWithWeight() throws IOException {
  // Test case 1: Add a valid resource with valid weights
  // Create a resource with IdealState and ResourceConfig
  String wagedResourceName = "newWagedResource";

  // Create an IdealState on full-auto with 1 partition
  IdealState idealState = new IdealState(wagedResourceName);
  idealState.getRecord().getSimpleFields().putAll(_gSetupTool.getClusterManagementTool()
      .getResourceIdealState(CLUSTER_NAME, RESOURCE_NAME).getRecord().getSimpleFields());
  idealState.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
  idealState.setRebalancerClassName(WagedRebalancer.class.getName());
  idealState.setNumPartitions(1); // 1 partition for convenience of testing

  // Create a ResourceConfig with FOO and BAR at 100 respectively
  ResourceConfig resourceConfig = new ResourceConfig(wagedResourceName);
  Map<String, Map<String, Integer>> partitionCapacityMap = new HashMap<>();
  Map<String, Integer> partitionCapacity = ImmutableMap.of("FOO", 100, "BAR", 100);
  partitionCapacityMap.put(wagedResourceName + "_0", partitionCapacity);
  // Also add a default key
  partitionCapacityMap.put(ResourceConfig.DEFAULT_PARTITION_KEY, partitionCapacity);
  resourceConfig.setPartitionCapacityMap(partitionCapacityMap);

  // Put both IdealState and ResourceConfig into a map as required
  Map<String, ZNRecord> inputMap = ImmutableMap.of(
      ResourceAccessor.ResourceProperties.idealState.name(), idealState.getRecord(),
      ResourceAccessor.ResourceProperties.resourceConfig.name(), resourceConfig.getRecord());

  // Create an entity using the inputMap
  Entity entity =
      Entity.entity(OBJECT_MAPPER.writeValueAsString(inputMap), MediaType.APPLICATION_JSON_TYPE);

  // Make a HTTP call to the REST endpoint
  put("clusters/" + CLUSTER_NAME + "/resources/" + wagedResourceName,
      ImmutableMap.of("command", "addWagedResource"), entity, Response.Status.OK.getStatusCode());

  // Test case 2: Add a resource with invalid weights
  String invalidResourceName = "invalidWagedResource";
  ResourceConfig invalidWeightResourceConfig = new ResourceConfig(invalidResourceName);
  IdealState invalidWeightIdealState = new IdealState(invalidResourceName);

  Map<String, ZNRecord> invalidInputMap = ImmutableMap.of(
      ResourceAccessor.ResourceProperties.idealState.name(), invalidWeightIdealState.getRecord(),
      ResourceAccessor.ResourceProperties.resourceConfig.name(),
      invalidWeightResourceConfig.getRecord());

  // Create an entity using invalidInputMap
  entity = Entity.entity(OBJECT_MAPPER.writeValueAsString(invalidInputMap),
      MediaType.APPLICATION_JSON_TYPE);

  // Make a HTTP call to the REST endpoint
  put("clusters/" + CLUSTER_NAME + "/resources/" + invalidResourceName,
      ImmutableMap.of("command", "addWagedResource"), entity,
      Response.Status.BAD_REQUEST.getStatusCode());
}