Examples of ResourceId


Examples of buildcraft.api.robots.ResourceId

    if (resourcesTakenByRobot.containsKey(robot.getRobotId())) {
      HashSet<ResourceId> resourceSet = (HashSet<ResourceId>) resourcesTakenByRobot.get(robot.getRobotId())
          .clone();

      ResourceId mainId = null;

      for (ResourceId id : resourceSet) {
        release(id);
      }
View Full Code Here

Examples of com.google.api.services.youtube.model.ResourceId

            // Retrieve the channel ID that the user is subscribing to.
            String channelId = getChannelId();
            System.out.println("You chose " + channelId + " to subscribe.");

            // Create a resourceId that identifies the channel ID.
            ResourceId resourceId = new ResourceId();
            resourceId.setChannelId(channelId);
            resourceId.setKind("youtube#channel");

            // Create a snippet that contains the resourceId.
            SubscriptionSnippet snippet = new SubscriptionSnippet();
            snippet.setResourceId(resourceId);
View Full Code Here

Examples of com.google.gdata.data.extensions.ResourceId

   * Returns the document's resource id.
   *
   * @return the resource id.
   */
  public String getResourceId() {
    ResourceId resourceId = getExtension(ResourceId.class);
    return resourceId == null ? null : resourceId.getValue();
  }
View Full Code Here

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

    }

    // populate all the resources
    Map<ResourceId, Resource> resourceMap = Maps.newHashMap();
    for (String resourceName : idealStateMap.keySet()) {
      ResourceId resourceId = ResourceId.from(resourceName);
      resourceMap.put(
          resourceId,
          createResource(resourceId, resourceConfigMap.get(resourceName),
              idealStateMap.get(resourceName), externalViewMap.get(resourceName),
              resourceAssignmentMap.get(resourceName)));
View Full Code Here

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

    if (_accessor.getProperty(_keyBuilder.stateModelDef(stateModelDefId.stringify())) == null) {
      LOG.error("State model: " + stateModelDefId + " not found in cluster: " + _clusterId);
      return false;
    }

    ResourceId resourceId = resource.getId();
    if (_accessor.getProperty(_keyBuilder.idealStates(resourceId.stringify())) != null) {
      LOG.error("Skip adding resource: " + resourceId
          + ", because resource ideal state already exists in cluster: " + _clusterId);
      return false;
    }
    if (_accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify())) != null) {
      LOG.error("Skip adding resource: " + resourceId
          + ", because resource config already exists in cluster: " + _clusterId);
      return false;
    }

    // Persist the ideal state
    _accessor.setProperty(_keyBuilder.idealStates(resourceId.stringify()), idealState);

    // Add resource user config
    boolean persistConfig = false;
    ResourceConfiguration configuration = new ResourceConfiguration(resourceId);
    if (resource.getUserConfig() != null) {
      configuration.addNamespacedConfig(resource.getUserConfig());
      persistConfig = true;
    }
    RebalancerConfig rebalancerConfig = resource.getRebalancerConfig();
    if (rebalancerConfig != null) {
      // only persist if this is not easily convertible to an ideal state
      configuration.addNamespacedConfig(new RebalancerConfigHolder(rebalancerConfig)
          .toNamespacedConfig());
      persistConfig = true;
    }
    ProvisionerConfig provisionerConfig = resource.getProvisionerConfig();
    if (provisionerConfig != null) {
      configuration.addNamespacedConfig(new ProvisionerConfigHolder(provisionerConfig)
          .toNamespacedConfig());
      persistConfig = true;
    }
    if (persistConfig) {
      _accessor.setProperty(_keyBuilder.resourceConfig(resourceId.stringify()), configuration);
    }
    return true;
  }
View Full Code Here

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

    }

    // Transform from partition id to fully qualified partition name
    List<Integer> partitionNums = Lists.newArrayList(partitionSet);
    Collections.sort(partitionNums);
    final ResourceId resourceId = prevAssignment.getResourceId();
    List<PartitionId> partitions =
        new ArrayList<PartitionId>(Lists.transform(partitionNums,
            new Function<Integer, PartitionId>() {
              @Override
              public PartitionId apply(Integer partitionNum) {
View Full Code Here

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

  @Override
  protected void init() {
    ClusterId clusterId = getClusterId();
    ClusterAccessor clusterAccessor = getConnection().createClusterAccessor(clusterId);
    ResourceId resourceId = ResourceId.from(_serviceName);
    Resource resource = clusterAccessor.readResource(resourceId);
    UserConfig userConfig = resource.getUserConfig();
    ServiceConfig serviceConfig = new ServiceConfig(Scope.resource(resourceId));
    serviceConfig.setSimpleFields(userConfig.getSimpleFields());
    serviceConfig.setListFields(userConfig.getListFields());
View Full Code Here

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

      LOG.info("No IdealState available");
      return null;
    }

    // get the rebalancer class
    ResourceId resourceId = idealState.getResourceId();
    StateModelDefinition stateModelDef =
        cluster.getStateModelMap().get(idealState.getStateModelDefId());
    if (stateModelDef == null) {
      LOG.info("StateModelDefinition unavailable for " + resourceId);
      return null;
    }
    String rebalancerClassName = idealState.getRebalancerClassName();
    if (rebalancerClassName == null) {
      LOG.info("No Rebalancer class available for " + resourceId);
      return null;
    }

    // try to instantiate the rebalancer class
    Rebalancer rebalancer = null;
    try {
      rebalancer =
          (Rebalancer) (HelixUtil.loadClass(getClass(), rebalancerClassName).newInstance());
    } catch (Exception e) {
      LOG.warn("rebalancer " + rebalancerClassName + " not available", e);
    }
    if (rebalancer == null) {
      LOG.warn("Rebalancer class " + rebalancerClassName + " could not be instantiated for "
          + resourceId);
      return null;
    }

    // get the cluster data cache (unfortunately involves a second read of the cluster)
    HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
    ClusterDataCache cache = new ClusterDataCache();
    cache.refresh(accessor);

    // adapt ResourceCurrentState to CurrentStateOutput
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    for (ResourceId resource : currentState.getResourceIds()) {
      currentStateOutput.setBucketSize(resource.stringify(), currentState.getBucketSize(resource));
      currentStateOutput.setResourceStateModelDef(resource.stringify(), currentState
          .getResourceStateModelDef(resource).stringify());
      Set<PartitionId> partitions = currentState.getCurrentStateMappedPartitions(resource);
      for (PartitionId partitionId : partitions) {
        // set current state
        Map<ParticipantId, State> currentStateMap =
            currentState.getCurrentStateMap(resource, partitionId);
        for (ParticipantId participantId : currentStateMap.keySet()) {
          currentStateOutput.setCurrentState(resource.stringify(),
              new Partition(partitionId.stringify()), participantId.stringify(), currentStateMap
                  .get(participantId).toString());
        }

        // set pending current state
        Map<ParticipantId, State> pendingStateMap =
            currentState.getPendingStateMap(resource, partitionId);
        for (ParticipantId participantId : pendingStateMap.keySet()) {
          currentStateOutput.setPendingState(resource.stringify(),
              new Partition(partitionId.stringify()), participantId.stringify(), pendingStateMap
                  .get(participantId).toString());
        }
      }
    }

    // call the rebalancer
    rebalancer.init(_helixManager);
    IdealState newIdealState =
        rebalancer.computeResourceMapping(resourceId.stringify(), idealState, currentStateOutput,
            cache);

    // do the resource assignments
    ResourceAssignment assignment = new ResourceAssignment(resourceId);
    if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
View Full Code Here

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

    HelixTaskResult taskResult =
        (HelixTaskResult) _notificationContext.get(MapKey.HELIX_TASK_RESULT.toString());
    Exception exception = taskResult.getException();

    PartitionId partitionId = _message.getPartitionId();
    ResourceId resource = _message.getResourceId();
    SessionId sessionId = _message.getTypedTgtSessionId();
    String instanceName = _manager.getInstanceName();

    HelixDataAccessor accessor = _manager.getHelixDataAccessor();
    Builder keyBuilder = accessor.keyBuilder();

    int bucketSize = _message.getBucketSize();
    ZNRecordBucketizer bucketizer = new ZNRecordBucketizer(bucketSize);

    // No need to sync on manager, we are cancel executor in expiry session before start executor in
    // new session
    // sessionId might change when we update the state model state.
    // for zk current state it is OK as we have the per-session current state node
    if (!_message.getTypedTgtSessionId().stringify().equals(_manager.getSessionId())) {
      logger.warn("Session id has changed. Skip postExecutionMessage. Old session "
          + _message.getTypedExecutionSessionId() + " , new session : " + _manager.getSessionId());
      return;
    }

    // Set the INFO property.
    _currentStateDelta.setInfo(partitionId, taskResult.getInfo());

    if (taskResult.isSuccess()) {
      // String fromState = message.getFromState();
      State toState = _message.getTypedToState();
      _currentStateDelta.setState(partitionId, toState);

      if (toState.toString().equalsIgnoreCase(HelixDefinedState.DROPPED.toString())) {
        // for "OnOfflineToDROPPED" message, we need to remove the resource key record
        // from the current state of the instance because the resource key is dropped.
        // In the state model it will be stayed as "OFFLINE", which is OK.

        ZNRecord rec = new ZNRecord(_currentStateDelta.getId());
        // remove mapField keyed by partitionId
        rec.setMapField(partitionId.stringify(), null);
        ZNRecordDelta delta = new ZNRecordDelta(rec, MergeOperation.SUBTRACT);

        List<ZNRecordDelta> deltaList = new ArrayList<ZNRecordDelta>();
        deltaList.add(delta);
        _currentStateDelta.setDeltaList(deltaList);
        _stateModelFactory.removeTransitionHandler(partitionId);
      } else {
        // if the partition is not to be dropped, update _stateModel to the TO_STATE
        _stateModel.updateState(toState.toString());
      }
    } else {
      if (exception instanceof HelixStateMismatchException) {
        // if fromState mismatch, set current state on zk to stateModel's current state
        logger.warn("Force CurrentState on Zk to be stateModel's CurrentState. partitionKey: "
            + partitionId + ", currentState: " + _stateModel.getCurrentState() + ", message: "
            + _message);
        _currentStateDelta.setState(partitionId, State.from(_stateModel.getCurrentState()));
      } else {
        StateTransitionError error =
            new StateTransitionError(ErrorType.INTERNAL, ErrorCode.ERROR, exception);
        if (exception instanceof InterruptedException) {
          if (_isTimeout) {
            error = new StateTransitionError(ErrorType.INTERNAL, ErrorCode.TIMEOUT, exception);
          } else {
            // State transition interrupted but not caused by timeout. Keep the current
            // state in this case
            logger
                .error("State transition interrupted but not timeout. Not updating state. Partition : "
                    + _message.getPartitionId() + " MsgId : " + _message.getMessageId());
            return;
          }
        }
        _stateModel.rollbackOnError(_message, _notificationContext, error);
        _currentStateDelta.setState(partitionId, State.from(HelixDefinedState.ERROR.toString()));
        _stateModel.updateState(HelixDefinedState.ERROR.toString());

        // if we have errors transit from ERROR state, disable the partition
        if (_message.getTypedFromState().toString()
            .equalsIgnoreCase(HelixDefinedState.ERROR.toString())) {
          disablePartition();
        }
      }
    }

    try {
      // Update the ZK current state of the node
      PropertyKey key =
          keyBuilder.currentState(instanceName, sessionId.stringify(), resource.stringify(),
              bucketizer.getBucketName(partitionId.stringify()));
      if (_message.getAttribute(Attributes.PARENT_MSG_ID) == null) {
        // normal message
        accessor.updateProperty(key, _currentStateDelta);
      } else {
View Full Code Here

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

    }
  }

  void disablePartition() {
    String instanceName = _manager.getInstanceName();
    ResourceId resourceId = _message.getResourceId();
    PartitionId partitionId = _message.getPartitionId();
    String clusterName = _manager.getClusterName();
    HelixAdmin admin = _manager.getClusterManagmentTool();
    admin.enablePartition(false, clusterName, instanceName, resourceId.stringify(),
        Arrays.asList(partitionId.stringify()));
    logger.info("error in transit from ERROR to " + _message.getTypedToState() + " for partition: "
        + partitionId + ". disable it on " + instanceName);

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.