Package org.apache.helix.api.id

Examples of org.apache.helix.api.id.ResourceId


    return participantBuilder.build();
  }

  private static ResourceConfig getResource(StateModelDefinition stateModelDef) {
    // identify the resource
    ResourceId resourceId = ResourceId.from("exampleResource");

    // create a partition
    PartitionId partition1 = PartitionId.from(resourceId, "1");

    // create a second partition
View Full Code Here


        new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
            manager.getClusterName()).build();
    String json = clusterConfig.get(clusterScope, message.getResourceId().stringify());
    Dag.Node node = Dag.Node.fromJson(json);
    Set<String> parentIds = node.getParentIds();
    ResourceId resourceId = message.getResourceId();
    int numPartitions = node.getNumPartitions();
    Task task =
        _taskFactory.createTask(resourceId.stringify(), parentIds, manager, _taskResultStore);
    manager.addExternalViewChangeListener(task);

    LOG.debug("Starting task for " + _partition + "...");
    int partitionNum = Integer.parseInt(_partition.split("_")[1]);
    task.execute(resourceId.stringify(), numPartitions, partitionNum);
    LOG.debug("Task for " + _partition + " done");
  }
View Full Code Here

    final String KEY3 = "key3";
    final String VALUE3 = "value3";

    // add key1 through user config, key2 through resource config, key3 through ideal state,
    // resource type through resource config, rebalance mode through ideal state
    ResourceId resourceId = ResourceId.from("resourceId");
    UserConfig userConfig = new UserConfig(Scope.resource(resourceId));
    userConfig.setSimpleField(KEY1, VALUE1);
    ResourceConfiguration resourceConfig = new ResourceConfiguration(resourceId);
    resourceConfig.addNamespacedConfig(userConfig);
    resourceConfig.getRecord().setSimpleField(KEY2, VALUE2);
View Full Code Here

          + message.getMsgType() + ", msgId: " + message.getMessageId());
    }

    PartitionId partitionKey = message.getPartitionId();
    StateModelDefId stateModelId = message.getStateModelDefId();
    ResourceId resourceId = message.getResourceId();
    SessionId sessionId = message.getTypedTgtSessionId();
    int bucketSize = message.getBucketSize();

    if (stateModelId == null) {
      LOG.error("Fail to create msg-handler because message does not contain stateModelDef. msgId: "
          + message.getId());
      return null;
    }

    String factoryName = message.getStateModelFactoryName();
    if (factoryName == null) {
      factoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
    }

    StateTransitionHandlerFactory<? extends TransitionHandler> stateModelFactory =
        getStateModelFactory(stateModelId, factoryName);
    if (stateModelFactory == null) {
      LOG.warn("Fail to create msg-handler because cannot find stateModelFactory for model: "
          + stateModelId + " using factoryName: " + factoryName + " for resource: " + resourceId);
      return null;
    }

    // check if the state model definition exists and cache it
    if (!_stateModelDefs.containsKey(stateModelId)) {
      HelixDataAccessor accessor = _manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();
      StateModelDefinition stateModelDef =
          accessor.getProperty(keyBuilder.stateModelDef(stateModelId.stringify()));
      if (stateModelDef == null) {
        throw new HelixException("fail to create msg-handler because stateModelDef for "
            + stateModelId + " does NOT exist");
      }
      _stateModelDefs.put(stateModelId, stateModelDef);
    }

    if (message.getBatchMessageMode() == false) {
      // create currentStateDelta for this partition
      String initState = _stateModelDefs.get(message.getStateModelDefId()).getInitialState();
      TransitionHandler stateModel = stateModelFactory.getTransitionHandler(partitionKey);
      if (stateModel == null) {
        stateModel = stateModelFactory.createAndAddSTransitionHandler(partitionKey);
        stateModel.updateState(initState);
      }

      // TODO: move currentStateDelta to StateTransitionMsgHandler
      CurrentState currentStateDelta = new CurrentState(resourceId.stringify());
      currentStateDelta.setSessionId(sessionId);
      currentStateDelta.setStateModelDefRef(stateModelId.stringify());
      currentStateDelta.setStateModelFactoryName(factoryName);
      currentStateDelta.setBucketSize(bucketSize);
View Full Code Here

  }

  protected Map<ResourceId, ResourceConfig> getResourceMap(List<IdealState> idealStates) {
    Map<ResourceId, ResourceConfig> resourceMap = new HashMap<ResourceId, ResourceConfig>();
    for (IdealState idealState : idealStates) {
      ResourceId resourceId = idealState.getResourceId();
      ResourceConfig resourceConfig =
          new ResourceConfig.Builder(resourceId).idealState(idealState)
              .userConfig(new UserConfig(Scope.resource(resourceId))).build();
      resourceMap.put(resourceId, resourceConfig);
    }
View Full Code Here

    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);
    Assert.assertNotNull(resource.getIdealState());
    Assert.assertEquals(resource.getIdealState().getRebalanceMode(), RebalanceMode.SEMI_AUTO);
View Full Code Here

    // 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);
View Full Code Here

    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()
View Full Code Here

      InstanceConfig config = new InstanceConfig(instanceName);
      instanceConfigMap.put(instanceName, config);
    }

    Map<ResourceId, ResourceConfig> resourceMap = Maps.newHashMap();
    ResourceId resourceId = ResourceId.from(testDB);
    AutoModeISBuilder idealStateBuilder = new AutoModeISBuilder(resourceId).add(testDB_0);
    idealStateBuilder.setStateModel("MasterSlave");
    IdealState idealState = idealStateBuilder.build();
    ResourceConfig resourceConfig =
        new ResourceConfig.Builder(resourceId).idealState(idealState).build();
View Full Code Here

   * lists should prefer nodes in the current mapping at all times, but when all nodes are in the
   * current mapping, then it should distribute states as evenly as possible.
   */
  @Test
  public void testOrphansNotPreferred() {
    final ResourceId RESOURCE = ResourceId.from("resource");
    final PartitionId[] PARTITIONS =
        {
            PartitionId.from("resource_0"), PartitionId.from("resource_1"),
            PartitionId.from("resource_2")
        };
View Full Code Here

TOP

Related Classes of org.apache.helix.api.id.ResourceId

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.