Java Code Examples for org.apache.helix.model.InstanceConfig#getId()

The following examples show how to use org.apache.helix.model.InstanceConfig#getId() . 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: ZKHelixAdmin.java    From helix with Apache License 2.0 6 votes vote down vote up
@Override
public void addInstance(String clusterName, InstanceConfig instanceConfig) {
  logger.info("Add instance {} to cluster {}.", instanceConfig.getInstanceName(), clusterName);
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("cluster " + clusterName + " is not setup yet");
  }
  String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName);
  String nodeId = instanceConfig.getId();
  String instanceConfigPath = instanceConfigsPath + "/" + nodeId;

  if (_zkClient.exists(instanceConfigPath)) {
    throw new HelixException("Node " + nodeId + " already exists in cluster " + clusterName);
  }

  ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord());

  _zkClient.createPersistent(PropertyPathBuilder.instanceMessage(clusterName, nodeId), true);
  _zkClient.createPersistent(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), true);
  _zkClient.createPersistent(PropertyPathBuilder.instanceCustomizedState(clusterName, nodeId), true);
  _zkClient.createPersistent(PropertyPathBuilder.instanceError(clusterName, nodeId), true);
  _zkClient.createPersistent(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), true);
  _zkClient.createPersistent(PropertyPathBuilder.instanceHistory(clusterName, nodeId), true);
}
 
Example 2
Source File: MockHelixAdmin.java    From helix with Apache License 2.0 6 votes vote down vote up
@Override public void addInstance(String clusterName, InstanceConfig instanceConfig) {
  String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName);
  String nodeId = instanceConfig.getId();
  if (!_baseDataAccessor.exists(instanceConfigsPath, 0)) {
    _baseDataAccessor.create(instanceConfigsPath, new ZNRecord(nodeId), 0);
  }

  String instanceConfigPath = instanceConfigsPath + "/" + nodeId;

  _baseDataAccessor.create(instanceConfigPath, instanceConfig.getRecord(), 0);
  _baseDataAccessor
      .set(PropertyPathBuilder.instanceMessage(clusterName, nodeId), new ZNRecord(nodeId), 0);
  _baseDataAccessor
      .set(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), new ZNRecord(nodeId),
          0);
  _baseDataAccessor
      .set(PropertyPathBuilder.instanceCustomizedState(clusterName, nodeId), new ZNRecord(nodeId),
          0);
  _baseDataAccessor
      .set(PropertyPathBuilder.instanceError(clusterName, nodeId), new ZNRecord(nodeId), 0);
  _baseDataAccessor
      .set(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), new ZNRecord(nodeId),
          0);
  _baseDataAccessor
      .set(PropertyPathBuilder.instanceHistory(clusterName, nodeId), new ZNRecord(nodeId), 0);
}