use of org.apache.helix.ZNRecordAssembler in project helix by apache.
the class ZKHelixDataAccessor method getProperty.
@Override
public <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys, boolean throwException) throws HelixMetaDataAccessException {
if (keys == null || keys.size() == 0) {
return Collections.emptyList();
}
List<T> childValues = new ArrayList<T>();
// read all records
List<String> paths = new ArrayList<>();
List<Stat> stats = new ArrayList<>();
for (PropertyKey key : keys) {
paths.add(key.getPath());
stats.add(new Stat());
}
List<ZNRecord> children = _baseDataAccessor.get(paths, stats, 0, throwException);
// check if bucketized
for (int i = 0; i < keys.size(); i++) {
PropertyKey key = keys.get(i);
ZNRecord record = children.get(i);
Stat stat = stats.get(i);
PropertyType type = key.getType();
String path = key.getPath();
int options = constructOptions(type);
if (record != null) {
record.setCreationTime(stat.getCtime());
record.setModifiedTime(stat.getMtime());
record.setVersion(stat.getVersion());
}
switch(type) {
case CURRENTSTATES:
case IDEALSTATES:
case EXTERNALVIEW:
// check if bucketized
if (record != null) {
HelixProperty property = new HelixProperty(record);
int bucketSize = property.getBucketSize();
if (bucketSize > 0) {
// @see HELIX-574
// clean up list and map fields in case we write to parent node by mistake
property.getRecord().getMapFields().clear();
property.getRecord().getListFields().clear();
List<ZNRecord> childRecords = _baseDataAccessor.getChildren(path, null, options, 1, 0);
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;
}
@SuppressWarnings("unchecked") T t = (T) HelixProperty.convertToTypedInstance(key.getTypeClass(), record);
childValues.add(t);
}
return childValues;
}
use of org.apache.helix.ZNRecordAssembler 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.ZNRecordAssembler in project helix by apache.
the class ZKHelixDataAccessor method getProperty.
@Override
public <T extends HelixProperty> T getProperty(PropertyKey key) {
PropertyType type = key.getType();
String path = key.getPath();
int options = constructOptions(type);
ZNRecord record = null;
try {
Stat stat = new Stat();
record = _baseDataAccessor.get(path, stat, options);
if (record != null) {
record.setCreationTime(stat.getCtime());
record.setModifiedTime(stat.getMtime());
record.setVersion(stat.getVersion());
}
} catch (ZkNoNodeException e) {
// OK
}
switch(type) {
case CURRENTSTATES:
case IDEALSTATES:
case EXTERNALVIEW:
// check if bucketized
if (record != null) {
HelixProperty property = new HelixProperty(record);
int bucketSize = property.getBucketSize();
if (bucketSize > 0) {
// @see HELIX-574
// clean up list and map fields in case we write to parent node by mistake
property.getRecord().getMapFields().clear();
property.getRecord().getListFields().clear();
List<ZNRecord> childRecords = _baseDataAccessor.getChildren(path, 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;
}
@SuppressWarnings("unchecked") T t = (T) HelixProperty.convertToTypedInstance(key.getTypeClass(), record);
return t;
}
Aggregations