Package org.apache.helix.api

Examples of org.apache.helix.api.Resource


    ResourceConfig resourceConfig =
        new ResourceConfig.Builder(resourceId).idealState(idealState)
            .rebalancerConfig(rebalancerConfig).provisionerConfig(provisionerConfig)
            .schedulerTaskConfig(Resource.schedulerTaskConfig(idealState)).userConfig(userConfig)
            .build();
    return new Resource(resourceConfig, resourceAssignment, externalView);
  }
View Full Code Here


        continue;
      }

      // TODO have a logical model for transition
      Map<String, Integer> stateTransitionPriorities = getStateTransitionPriorityMap(stateModelDef);
      Resource configResource = cluster.getResource(resourceId);

      // if configResource == null, the resource has been dropped
      Map<State, Bounds> stateConstraints =
          computeStateConstraints(stateModelDef,
              configResource == null ? null : configResource.getIdealState(), cluster);

      // TODO fix it
      for (PartitionId partitionId : bestPossibleStateOutput.getResourceAssignment(resourceId)
          .getMappedPartitionIds()) {
        List<Message> messages = messageGenOutput.getMessages(resourceId, partitionId);
View Full Code Here

   * @param cluster snapshot of the cluster containing the task and target resource
   * @return target resource ideal state, or null
   */
  private static IdealState getTgtIdealState(JobConfig jobCfg, Cluster cache) {
    String tgtResourceId = jobCfg.getTargetResource();
    Resource resource = cache.getResource(ResourceId.from(tgtResourceId));
    return resource.getIdealState();
  }
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();
      RebalancerContext context = PartitionedRebalancerContext.from(idealState);
      Resource resource =
          new Resource(resourceId, ResourceType.DATA, idealState, null, null, context,
              new UserConfig(Scope.resource(resourceId)), idealState.getBucketSize(),
              idealState.getBatchMessageMode());
      resourceMap.put(resourceId, resource.getConfig());
    }

    return resourceMap;
  }
View Full Code Here

        Sets.newHashSet(_accessor.getChildNames(_keyBuilder.resourceConfigs()));
    resourceConfigNames.addAll(idealStateNames);
    ResourceAccessor accessor = new AtomicResourceAccessor(_clusterId, _accessor, _lockProvider);
    for (String resourceName : resourceConfigNames) {
      ResourceId resourceId = ResourceId.from(resourceName);
      Resource resource = accessor.readResource(resourceId);
      if (resource != null) {
        resources.put(resourceId, resource);
      }
    }
    return resources;
View Full Code Here

    String partitionName = optValues[2];

    ResourceId resourceId = ResourceId.from(resourceName);
    PartitionId partitionId = PartitionId.from(partitionName);
    ResourceAccessor accessor = resourceAccessor(clusterName);
    Resource resource = accessor.readResource(resourceId);

    StringBuilder sb = new StringBuilder();
    Map<ParticipantId, State> stateMap = resource.getExternalView().getStateMap(partitionId);
    sb.append(resourceName + "/" + partitionName + ", externalView: " + stateMap);
    PartitionedRebalancerContext partitionedContext =
        resource.getRebalancerConfig().getRebalancerContext(PartitionedRebalancerContext.class);
    if (partitionedContext != null) {
      // for partitioned contexts, check the mode and apply mode-specific information if possible
      if (partitionedContext.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
        SemiAutoRebalancerContext semiAutoContext =
            resource.getRebalancerConfig().getRebalancerContext(SemiAutoRebalancerContext.class);
        sb.append(", preferenceList: " + semiAutoContext.getPreferenceList(partitionId));
      } else if (partitionedContext.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
        CustomRebalancerContext customContext =
            resource.getRebalancerConfig().getRebalancerContext(CustomRebalancerContext.class);
        sb.append(", preferenceMap: " + customContext.getPreferenceMap(partitionId));
      }
      if (partitionedContext.anyLiveParticipant()) {
        sb.append(", anyLiveParticipant: " + partitionedContext.anyLiveParticipant());
      } else {
View Full Code Here

  void listResourceInfo(String[] optValues) {
    String clusterName = optValues[0];
    String resourceName = optValues[1];
    ResourceAccessor accessor = resourceAccessor(clusterName);
    ResourceId resourceId = ResourceId.from(resourceName);
    Resource resource = accessor.readResource(resourceId);
    StringBuilder sb =
        new StringBuilder("Resource ").append(resourceName).append(" in cluster ")
            .append(clusterName).append(":\n").append("externalView: ")
            .append(resource.getExternalView()).append(", userConfig: ")
            .append(resource.getUserConfig()).append(", rebalancerContext: ")
            .append(resource.getRebalancerConfig().getSerializedContext());
    System.out.println(sb.toString());
  }
View Full Code Here

    }
  }

  private void expandResource(ClusterId clusterId, ResourceId resourceId) {
    ResourceAccessor accessor = resourceAccessor(clusterId.stringify());
    Resource resource = accessor.readResource(resourceId);
    SemiAutoRebalancerContext context =
        resource.getRebalancerConfig().getRebalancerContext(SemiAutoRebalancerContext.class);
    if (context == null) {
      LOG.info("Only SEMI_AUTO mode supported for resource expansion");
      return;
    }
    if (context.anyLiveParticipant()) {
View Full Code Here

    }
    RunningInstance runningInstance = participant.getRunningInstance();

    // check that the resource exists
    ResourceAccessor resourceAccessor = resourceAccessor();
    Resource resource = resourceAccessor.readResource(resourceId);
    if (resource == null || resource.getRebalancerConfig() == null) {
      LOG.error("Cannot reset partitions because the resource is not present");
      return false;
    }

    // need the rebalancer context for the resource
    RebalancerContext context =
        resource.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
    if (context == null) {
      LOG.error("Rebalancer context for resource does not exist");
      return false;
    }
View Full Code Here

   * @param resourceId the resource id to update
   * @param resourceDelta changes to the resource
   * @return ResourceConfig, or null if the resource is not persisted
   */
  public ResourceConfig updateResource(ResourceId resourceId, ResourceConfig.Delta resourceDelta) {
    Resource resource = readResource(resourceId);
    if (resource == null) {
      LOG.error("Resource " + resourceId + " does not exist, cannot be updated");
      return null;
    }
    ResourceConfig config = resourceDelta.mergeInto(resource.getConfig());
    setResource(config);
    return config;
  }
View Full Code Here

TOP

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

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.