本文整理汇总了Java中org.apache.helix.ZNRecord.setSimpleField方法的典型用法代码示例。如果您正苦于以下问题:Java ZNRecord.setSimpleField方法的具体用法?Java ZNRecord.setSimpleField怎么用?Java ZNRecord.setSimpleField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.ZNRecord
的用法示例。
在下文中一共展示了ZNRecord.setSimpleField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public ZNRecord toZNRecord() {
ZNRecord znRecord = new ZNRecord(_segmentName);
znRecord.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, _segmentName);
znRecord.setSimpleField(CommonConstants.Segment.TABLE_NAME, _tableName);
znRecord.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, _segmentType);
if (_timeUnit == null) {
znRecord.setSimpleField(CommonConstants.Segment.TIME_UNIT, NULL);
} else {
znRecord.setEnumField(CommonConstants.Segment.TIME_UNIT, _timeUnit);
}
znRecord.setLongField(CommonConstants.Segment.START_TIME, _startTime);
znRecord.setLongField(CommonConstants.Segment.END_TIME, _endTime);
znRecord.setSimpleField(CommonConstants.Segment.INDEX_VERSION, _indexVersion);
znRecord.setLongField(CommonConstants.Segment.TOTAL_DOCS, _totalDocs);
znRecord.setLongField(CommonConstants.Segment.CRC, _crc);
znRecord.setLongField(CommonConstants.Segment.CREATION_TIME, _creationTime);
return znRecord;
}
示例2: getTestDoneRealtimeSegmentZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private ZNRecord getTestDoneRealtimeSegmentZNRecord() {
String segmentName = "testTable_R_1000_2000_groupId0_part0";
ZNRecord record = new ZNRecord(segmentName);
record.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, segmentName);
record.setSimpleField(CommonConstants.Segment.TABLE_NAME, "testTable");
record.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
record.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.REALTIME);
record.setEnumField(CommonConstants.Segment.Realtime.STATUS, CommonConstants.Segment.Realtime.Status.DONE);
record.setLongField(CommonConstants.Segment.START_TIME, 1000);
record.setLongField(CommonConstants.Segment.END_TIME, 2000);
record.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
record.setLongField(CommonConstants.Segment.TOTAL_DOCS, 10000);
record.setLongField(CommonConstants.Segment.CRC, 1234);
record.setLongField(CommonConstants.Segment.CREATION_TIME, 3000);
return record;
}
示例3: getTestInProgressRealtimeSegmentZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private ZNRecord getTestInProgressRealtimeSegmentZNRecord() {
String segmentName = "testTable_R_1000_groupId0_part0";
ZNRecord record = new ZNRecord(segmentName);
record.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, segmentName);
record.setSimpleField(CommonConstants.Segment.TABLE_NAME, "testTable");
record.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
record.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.REALTIME);
record.setEnumField(CommonConstants.Segment.Realtime.STATUS, CommonConstants.Segment.Realtime.Status.IN_PROGRESS);
record.setLongField(CommonConstants.Segment.START_TIME, 1000);
record.setLongField(CommonConstants.Segment.END_TIME, -1);
record.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
record.setLongField(CommonConstants.Segment.TOTAL_DOCS, -1);
record.setLongField(CommonConstants.Segment.CRC, -1);
record.setLongField(CommonConstants.Segment.CREATION_TIME, 1000);
return record;
}
示例4: getTestOfflineSegmentZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private ZNRecord getTestOfflineSegmentZNRecord() {
String segmentName = "testTable_O_3000_4000";
ZNRecord record = new ZNRecord(segmentName);
record.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, segmentName);
record.setSimpleField(CommonConstants.Segment.TABLE_NAME, "testTable");
record.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
record.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.OFFLINE);
record.setLongField(CommonConstants.Segment.START_TIME, 1000);
record.setLongField(CommonConstants.Segment.END_TIME, 2000);
record.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
record.setLongField(CommonConstants.Segment.TOTAL_DOCS, 50000);
record.setLongField(CommonConstants.Segment.CRC, 54321);
record.setLongField(CommonConstants.Segment.CREATION_TIME, 1000);
record.setSimpleField(CommonConstants.Segment.Offline.DOWNLOAD_URL, "http://localhost:8000/testTable_O_3000_4000");
record.setLongField(CommonConstants.Segment.Offline.PUSH_TIME, 4000);
record.setLongField(CommonConstants.Segment.Offline.REFRESH_TIME, 8000);
return record;
}
示例5: toZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public ZNRecord toZNRecord() {
ZNRecord znRecord = super.toZNRecord();
znRecord.setSimpleField(CommonConstants.Segment.Offline.DOWNLOAD_URL, _downloadUrl);
znRecord.setLongField(CommonConstants.Segment.Offline.PUSH_TIME, _pushTime);
znRecord.setLongField(CommonConstants.Segment.Offline.REFRESH_TIME, _refreshTime);
return znRecord;
}
示例6: toZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public ZNRecord toZNRecord() {
ZNRecord znRecord = super.toZNRecord();
znRecord.setLongField(START_OFFSET, _startOffset);
znRecord.setLongField(END_OFFSET, _endOffset);
znRecord.setIntField(NUM_REPLICAS, _numReplicas);
znRecord.setSimpleField(DOWNLOAD_URL, _downloadUrl);
return znRecord;
}
示例7: getClusterRepresentation
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
StringRepresentation getClusterRepresentation(String clusterName) throws JsonGenerationException,
JsonMappingException, IOException {
ZkClient zkClient =
ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> instances =
setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
ZNRecord clusterSummayRecord = new ZNRecord("Cluster Summary");
clusterSummayRecord.setListField("participants", instances);
List<String> resources =
setupTool.getClusterManagementTool().getResourcesInCluster(clusterName);
clusterSummayRecord.setListField("resources", resources);
List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName);
clusterSummayRecord.setListField("stateModelDefs", models);
HelixDataAccessor accessor =
ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader != null) {
clusterSummayRecord.setSimpleField("LEADER", leader.getInstanceName());
} else {
clusterSummayRecord.setSimpleField("LEADER", "");
}
StringRepresentation representation =
new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clusterSummayRecord),
MediaType.APPLICATION_JSON);
return representation;
}
示例8: compareSingleValue
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private static boolean compareSingleValue(String actual, String expect, String key, ZNRecord diff) {
boolean ret = (STRING_COMPARATOR.compare(actual, expect) == 0);
if (diff != null) {
diff.setSimpleField(key + "/expect", expect);
diff.setSimpleField(key + "/actual", actual);
}
return ret;
}
示例9: toZNRecord
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public ZNRecord toZNRecord() {
ZNRecord znRecord = new ZNRecord(_segmentName);
znRecord.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, _segmentName);
znRecord.setSimpleField(CommonConstants.Segment.TABLE_NAME, _tableName);
znRecord.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, _segmentType);
if (_timeUnit == null) {
znRecord.setSimpleField(CommonConstants.Segment.TIME_UNIT, NULL);
} else {
znRecord.setEnumField(CommonConstants.Segment.TIME_UNIT, _timeUnit);
}
znRecord.setLongField(CommonConstants.Segment.START_TIME, _startTime);
znRecord.setLongField(CommonConstants.Segment.END_TIME, _endTime);
znRecord.setSimpleField(CommonConstants.Segment.INDEX_VERSION, _indexVersion);
znRecord.setLongField(CommonConstants.Segment.TOTAL_DOCS, _totalRawDocs);
znRecord.setLongField(CommonConstants.Segment.CRC, _crc);
znRecord.setLongField(CommonConstants.Segment.CREATION_TIME, _creationTime);
if (_partitionMetadata != null) {
try {
String partitionMetadataJson = _partitionMetadata.toJsonString();
znRecord.setSimpleField(CommonConstants.Segment.PARTITION_METADATA, partitionMetadataJson);
} catch (IOException e) {
LOGGER.error(
"Exception caught while writing partition metadata into ZNRecord for segment '{}', will be dropped",
_segmentName, e);
}
}
if (_segmentUploadStartTime > 0) {
znRecord.setLongField(CommonConstants.Segment.SEGMENT_UPLOAD_START_TIME, _segmentUploadStartTime);
}
if (_customMap != null) {
znRecord.setMapField(CommonConstants.Segment.CUSTOM_MAP, _customMap);
}
return znRecord;
}
示例10: testUpdateConfigFields
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Test(dependsOnMethods = "testAddConfigFields")
public void testUpdateConfigFields() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
ClusterConfig config = getClusterConfigFromRest(cluster);
ZNRecord record = config.getRecord();
String key = record.getSimpleFields().keySet().iterator().next();
String value = record.getSimpleField(key);
record.getSimpleFields().clear();
record.setSimpleField(key, value + "--updated");
key = record.getListFields().keySet().iterator().next();
List<String> list = record.getListField(key);
list.remove(0);
list.add("newValue--updated");
record.getListFields().clear();
record.setListField(key, list);
key = record.getMapFields().keySet().iterator().next();
Map<String, String> map = record.getMapField(key);
Iterator it = map.entrySet().iterator();
it.next();
it.remove();
map.put("newKey--updated", "newValue--updated");
record.getMapFields().clear();
record.setMapField(key, map);
ClusterConfig prevConfig = getClusterConfigFromRest(cluster);
updateClusterConfigFromRest(cluster, config, Command.update);
ClusterConfig newConfig = getClusterConfigFromRest(cluster);
prevConfig.getRecord().update(config.getRecord());
Assert.assertEquals(newConfig, prevConfig,
"cluster config from response: " + newConfig + " vs cluster config actually: " + prevConfig);
}
示例11: setNodes
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private void setNodes(ZkClient zkClient, String root, char c, boolean needTimestamp) {
char[] data = new char[bufSize];
for (int i = 0; i < bufSize; i++) {
data[i] = c;
}
Map<String, String> map = new TreeMap<String, String>();
for (int i = 0; i < mapNr; i++) {
map.put("key_" + i, new String(data));
}
for (int i = 0; i < firstLevelNr; i++) {
String firstLevelKey = getFirstLevelKey(i);
for (int j = 0; j < secondLevelNr; j++) {
String nodeId = getNodeId(i, j);
ZNRecord record = new ZNRecord(nodeId);
record.setSimpleFields(map);
if (needTimestamp) {
long now = System.currentTimeMillis();
record.setSimpleField("SetTimestamp", Long.toString(now));
}
String key = getSecondLevelKey(i, j);
try {
zkClient.writeData(root + key, record);
} catch (ZkNoNodeException e) {
zkClient.createPersistent(root + firstLevelKey, true);
zkClient.createPersistent(root + key, record);
}
}
}
}
示例12: computeRoutingTable
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
public ZNRecord computeRoutingTable(List<String> instanceNames, int partitions, int replicas,
String dbName, long randomSeed) {
assert (instanceNames.size() > replicas);
Collections.sort(instanceNames);
ZNRecord result = new ZNRecord(dbName);
Map<String, Object> externalView = new TreeMap<String, Object>();
List<Integer> partitionList = new ArrayList<Integer>(partitions);
for (int i = 0; i < partitions; i++) {
partitionList.add(new Integer(i));
}
Random rand = new Random(randomSeed);
// Shuffle the partition list
Collections.shuffle(partitionList, rand);
for (int i = 0; i < partitionList.size(); i++) {
int partitionId = partitionList.get(i);
Map<String, String> partitionAssignment = new TreeMap<String, String>();
int masterNode = i % instanceNames.size();
// the first in the list is the node that contains the master
partitionAssignment.put(instanceNames.get(masterNode), "MASTER");
// for the jth replica, we put it on (masterNode + j) % nodes-th
// node
for (int j = 1; j <= replicas; j++) {
partitionAssignment
.put(instanceNames.get((masterNode + j) % instanceNames.size()), "SLAVE");
}
String partitionName = dbName + ".partition-" + partitionId;
result.setMapField(partitionName, partitionAssignment);
}
result.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(), "" + partitions);
return result;
}
示例13: basicTest
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
/**
* Test the normal case of serialize/deserialize where ZNRecord is well-formed
*/
@Test
public void basicTest() {
ZNRecord record = new ZNRecord("testId");
record.setMapField("k1", ImmutableMap.of("a", "b", "c", "d"));
record.setMapField("k2", ImmutableMap.of("e", "f", "g", "h"));
record.setListField("k3", ImmutableList.of("a", "b", "c", "d"));
record.setListField("k4", ImmutableList.of("d", "e", "f", "g"));
record.setSimpleField("k5", "a");
record.setSimpleField("k5", "b");
ZNRecordSerializer serializer = new ZNRecordSerializer();
ZNRecord result = (ZNRecord) serializer.deserialize(serializer.serialize(record));
Assert.assertEquals(result, record);
}
示例14: testBasicCompression
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Test
public void testBasicCompression() {
ZNRecord record = new ZNRecord("testId");
int numPartitions = 1024;
int replicas = 3;
int numNodes = 100;
Random random = new Random();
for (int p = 0; p < numPartitions; p++) {
Map<String, String> map = new HashMap<String, String>();
for (int r = 0; r < replicas; r++) {
map.put("host_" + random.nextInt(numNodes), "ONLINE");
}
record.setMapField("TestResource_" + p, map);
}
ZNRecordSerializer serializer = new ZNRecordSerializer();
byte[] serializedBytes;
serializedBytes = serializer.serialize(record);
int uncompressedSize = serializedBytes.length;
System.out.println("raw serialized data length = " + serializedBytes.length);
record.setSimpleField("enableCompression", "true");
serializedBytes = serializer.serialize(record);
int compressedSize = serializedBytes.length;
System.out.println("compressed serialized data length = " + serializedBytes.length);
System.out.printf("compression ratio: %.2f \n", (uncompressedSize * 1.0 / compressedSize));
ZNRecord result = (ZNRecord) serializer.deserialize(serializedBytes);
Assert.assertEquals(result, record);
}
示例15: call
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public Boolean call() throws Exception {
// create 10 current states in 2 steps
List<String> paths = new ArrayList<String>();
List<DataUpdater<ZNRecord>> updaters = new ArrayList<DataUpdater<ZNRecord>>();
for (int j = 0; j < 10; j++) {
paths.clear();
updaters.clear();
for (int i = 0; i < 10; i++) {
String path = PropertyPathBuilder.instanceCurrentState(
_clusterName, "localhost_8901", "session_0", "TestDB" + i);
ZNRecord newRecord = new ZNRecord("TestDB" + i);
newRecord.setSimpleField("" + j, "" + j);
DataUpdater<ZNRecord> updater = new ZNRecordUpdater(newRecord);
paths.add(path);
updaters.add(updater);
}
boolean[] success = _accessor.updateChildren(paths, updaters, AccessOption.PERSISTENT);
// System.out.println("thread-" + _id + " updates " + j + ": " + Arrays.toString(success));
for (int i = 0; i < 10; i++) {
Assert.assertEquals(success[i], true, "Should be all succeed");
}
}
return true;
}