use of org.apache.helix.HelixProperty in project helix by apache.
the class JobQueuesResource method getHostedEntitiesRepresentation.
StringRepresentation getHostedEntitiesRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException {
// Get all resources
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
Map<String, HelixProperty> resourceConfigMap = accessor.getChildValuesMap(keyBuilder.resourceConfigs());
// Create the result
ZNRecord hostedEntitiesRecord = new ZNRecord("JobQueues");
// Filter out non-workflow resources
Iterator<Map.Entry<String, HelixProperty>> it = resourceConfigMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, HelixProperty> e = it.next();
HelixProperty resource = e.getValue();
Map<String, String> simpleFields = resource.getRecord().getSimpleFields();
boolean isTerminable = resource.getRecord().getBooleanField(WorkflowConfig.WorkflowConfigProperty.Terminable.name(), true);
if (!simpleFields.containsKey(WorkflowConfig.WorkflowConfigProperty.TargetState.name()) || !simpleFields.containsKey(WorkflowConfig.WorkflowConfigProperty.Dag.name()) || isTerminable) {
it.remove();
}
}
// Populate the result
List<String> allResources = Lists.newArrayList(resourceConfigMap.keySet());
hostedEntitiesRecord.setListField("JobQueues", allResources);
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.HelixProperty in project helix by apache.
the class WorkflowsResource method getHostedEntitiesRepresentation.
StringRepresentation getHostedEntitiesRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException {
// Get all resources
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
Map<String, HelixProperty> resourceConfigMap = accessor.getChildValuesMap(keyBuilder.resourceConfigs());
// Create the result
ZNRecord hostedEntitiesRecord = new ZNRecord("Workflows");
// Filter out non-workflow resources
Iterator<Map.Entry<String, HelixProperty>> it = resourceConfigMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, HelixProperty> e = it.next();
HelixProperty resource = e.getValue();
Map<String, String> simpleFields = resource.getRecord().getSimpleFields();
if (!simpleFields.containsKey(WorkflowConfig.WorkflowConfigProperty.TargetState.name()) || !simpleFields.containsKey(WorkflowConfig.WorkflowConfigProperty.Dag.name())) {
it.remove();
}
}
// Populate the result
List<String> allResources = Lists.newArrayList(resourceConfigMap.keySet());
hostedEntitiesRecord.setListField("WorkflowList", allResources);
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.HelixProperty in project helix by apache.
the class ZKHelixDataAccessor method createChildren.
@Override
public <T extends HelixProperty> boolean[] createChildren(List<PropertyKey> keys, List<T> children) {
// TODO: add validation
int options = -1;
List<String> paths = new ArrayList<String>();
List<ZNRecord> records = new ArrayList<ZNRecord>();
for (int i = 0; i < keys.size(); i++) {
PropertyKey key = keys.get(i);
PropertyType type = key.getType();
String path = key.getPath();
paths.add(path);
HelixProperty value = children.get(i);
records.add(value.getRecord());
options = constructOptions(type);
}
return _baseDataAccessor.createChildren(paths, records, options);
}
use of org.apache.helix.HelixProperty in project helix by apache.
the class ZKHelixDataAccessor method getChildValues.
@Override
public <T extends HelixProperty> List<T> getChildValues(PropertyKey key, boolean throwException) {
PropertyType type = key.getType();
String parentPath = key.getPath();
int options = constructOptions(type);
List<T> childValues = new ArrayList<T>();
List<ZNRecord> children;
if (throwException) {
children = _baseDataAccessor.getChildren(parentPath, null, options, 1, 0);
} else {
children = _baseDataAccessor.getChildren(parentPath, null, options);
}
if (children != null) {
for (ZNRecord record : children) {
switch(type) {
case CURRENTSTATES:
case IDEALSTATES:
case EXTERNALVIEW:
if (record != null) {
HelixProperty property = new HelixProperty(record);
int bucketSize = property.getBucketSize();
if (bucketSize > 0) {
// TODO: fix this if record.id != pathName
String childPath = parentPath + "/" + record.getId();
List<ZNRecord> childRecords;
if (throwException) {
childRecords = _baseDataAccessor.getChildren(childPath, null, options, 1, 0);
} else {
childRecords = _baseDataAccessor.getChildren(childPath, null, options);
}
ZNRecord assembledRecord = new ZNRecordAssembler().assemble(childRecords);
// merge with parent node value
if (assembledRecord != null) {
record.getSimpleFields().putAll(assembledRecord.getSimpleFields());
record.getListFields().putAll(assembledRecord.getListFields());
record.getMapFields().putAll(assembledRecord.getMapFields());
}
}
}
break;
default:
break;
}
if (record != null) {
@SuppressWarnings("unchecked") T t = (T) HelixProperty.convertToTypedInstance(key.getTypeClass(), record);
childValues.add(t);
}
}
}
return childValues;
}
use of org.apache.helix.HelixProperty in project helix by apache.
the class ZKHelixDataAccessor method createStateModelDef.
@Override
public boolean createStateModelDef(StateModelDefinition stateModelDef) {
String path = PropertyPathBuilder.stateModelDef(_clusterName, stateModelDef.getId());
HelixProperty property = getProperty(new PropertyKey.Builder(_clusterName).stateModelDef(stateModelDef.getId()));
// Set new StateModelDefinition if it is different from old one.
if (property != null) {
// StateModelDefinition need to be updated
if (!new StateModelDefinition(property.getRecord()).equals(stateModelDef)) {
return stateModelDef.isValid() && _baseDataAccessor.set(path, stateModelDef.getRecord(), AccessOption.PERSISTENT);
}
} else {
// StateModeDefinition does not exist
return stateModelDef.isValid() && _baseDataAccessor.create(path, stateModelDef.getRecord(), AccessOption.PERSISTENT);
}
// StateModelDefinition exists but not need to be updated
return true;
}
Aggregations