use of org.apache.helix.PropertyKey in project helix by apache.
the class InstanceValidationUtil method hasErrorPartitions.
/**
* Method to check if the instance has error partitions
* @param dataAccessor
* @param clusterId
* @param instanceName
* @return
*/
public static boolean hasErrorPartitions(HelixDataAccessor dataAccessor, String clusterId, String instanceName) {
PropertyKey.Builder propertyKeyBuilder = new PropertyKey.Builder(clusterId);
PropertyKey liveInstanceKey = propertyKeyBuilder.liveInstance(instanceName);
LiveInstance liveInstance = dataAccessor.getProperty(liveInstanceKey);
if (liveInstance != null) {
String sessionId = liveInstance.getEphemeralOwner();
PropertyKey currentStatesKey = propertyKeyBuilder.currentStates(instanceName, sessionId);
List<String> resourceNames = dataAccessor.getChildNames(currentStatesKey);
for (String resourceName : resourceNames) {
PropertyKey key = propertyKeyBuilder.currentState(instanceName, sessionId, resourceName);
CurrentState currentState = dataAccessor.getProperty(key);
if (currentState != null && currentState.getPartitionStateMap().containsValue(HelixDefinedState.ERROR.name())) {
_logger.warn("The instance {} has error partitions on it.", instanceName);
return true;
}
}
}
return false;
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class InstanceValidationUtil method isResourceAssigned.
/**
* Method to check if the instance is assigned at least 1 resource, not in a idle state;
* Independent of the instance alive/enabled status
* @param dataAccessor
* @param instanceName
* @return
*/
public static boolean isResourceAssigned(HelixDataAccessor dataAccessor, String instanceName) {
PropertyKey.Builder propertyKeyBuilder = dataAccessor.keyBuilder();
LiveInstance liveInstance = dataAccessor.getProperty(propertyKeyBuilder.liveInstance(instanceName));
if (liveInstance != null) {
String sessionId = liveInstance.getEphemeralOwner();
List<String> resourceNames = dataAccessor.getChildNames(propertyKeyBuilder.currentStates(instanceName, sessionId));
for (String resourceName : resourceNames) {
PropertyKey currentStateKey = propertyKeyBuilder.currentState(instanceName, sessionId, resourceName);
CurrentState currentState = dataAccessor.getProperty(currentStateKey);
if (currentState != null && currentState.getPartitionStateMap().size() > 0) {
return true;
}
}
}
_logger.warn(String.format("The instance %s does not have resource assigned on it.", instanceName));
return false;
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class InstanceValidationUtil method hasValidConfig.
/**
* Method to check if the instance has valid configuration.
* Instance stability check requires PERSIST_INTERMEDIATE_ASSIGNMENT turned on!
*
* @param dataAccessor
* @param clusterId
* @param instanceName
* @return
*/
public static boolean hasValidConfig(HelixDataAccessor dataAccessor, String clusterId, String instanceName) {
PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
ClusterConfig clusterConfig = dataAccessor.getProperty(keyBuilder.clusterConfig());
if (clusterConfig == null) {
_logger.error("Cluster config is missing in cluster " + clusterId);
return false;
}
if (!clusterConfig.isPersistIntermediateAssignment()) {
_logger.error("Cluster config {} is not turned on, which is required for instance stability check.", ClusterConfig.ClusterConfigProperty.PERSIST_INTERMEDIATE_ASSIGNMENT.toString());
return false;
}
PropertyKey propertyKey = keyBuilder.instanceConfig(instanceName);
InstanceConfig instanceConfig = dataAccessor.getProperty(propertyKey);
return instanceConfig != null && instanceConfig.isValid();
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class TaskRunner method setZKCurrentState.
/**
* Request a state change for a specific task.
*
* @param accessor connected Helix data accessor
* @param instance the instance serving the task
* @param sessionId the current session of the instance
* @param resource the job name
* @param partition the task partition name
* @param state the requested state
* @return true if the request was persisted, false otherwise
*/
private boolean setZKCurrentState(HelixDataAccessor accessor, String instance, String sessionId, String resource, String partition, TaskPartitionState state) {
LOG.debug(String.format("Updating current state %s for partition %s.", state, partition));
try {
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
PropertyKey key = Boolean.getBoolean(SystemPropertyKeys.TASK_CURRENT_STATE_PATH_DISABLED) ? keyBuilder.currentState(instance, sessionId, resource) : keyBuilder.taskCurrentState(instance, sessionId, resource);
String prevState = _stateModel.getCurrentState();
CurrentState currentStateDelta = new CurrentState(resource);
currentStateDelta.setSessionId(sessionId);
currentStateDelta.setStateModelDefRef(TaskConstants.STATE_MODEL_NAME);
currentStateDelta.setState(partition, state.name());
currentStateDelta.setInfo(partition, _result.getInfo());
currentStateDelta.setPreviousState(partition, prevState);
return accessor.updateProperty(key, currentStateDelta);
} catch (Exception e) {
LOG.error(String.format("Error when updating current state to %s for partition %s.", state, partition), e);
return false;
}
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class TaskUtil method removeWorkflowJobConfig.
/**
* Remove workflow or job config.
* @param accessor
* @param workflowJobResource the workflow or job name
*/
private static boolean removeWorkflowJobConfig(HelixDataAccessor accessor, String workflowJobResource) {
PropertyKey cfgKey = accessor.keyBuilder().resourceConfig(workflowJobResource);
if (accessor.getPropertyStat(cfgKey) != null) {
if (!accessor.removeProperty(cfgKey)) {
LOG.warn("Error occurred while trying to remove config for {}. Failed to remove node {}.", workflowJobResource, cfgKey);
return false;
}
}
LOG.info("removed job config {}.", cfgKey.getPath());
return true;
}
Aggregations