本文整理汇总了Java中org.apache.helix.ZNRecord.getMapField方法的典型用法代码示例。如果您正苦于以下问题:Java ZNRecord.getMapField方法的具体用法?Java ZNRecord.getMapField怎么用?Java ZNRecord.getMapField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.ZNRecord
的用法示例。
在下文中一共展示了ZNRecord.getMapField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printDiff
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
/**
* Helper function to see how many partitions are mapped to different
* instances in two ideal states
*/
public static void printDiff(ZNRecord record1, ZNRecord record2) {
int diffCount = 0;
for (String key : record1.getMapFields().keySet()) {
Map<String, String> map1 = record1.getMapField(key);
Map<String, String> map2 = record2.getMapField(key);
for (String k : map1.keySet()) {
if (!map2.containsKey(k)) {
diffCount++;
} else if (!map1.get(k).equalsIgnoreCase(map2.get(k))) {
diffCount++;
}
}
}
System.out.println("diff count = " + diffCount);
}
示例2: printDiff
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
/**
* Helper function to see how many partitions are mapped to different
* instances in two ideal states
*/
public static void printDiff(ZNRecord record1, ZNRecord record2) {
int diffCount = 0;
int diffCountMaster = 0;
for (String key : record1.getMapFields().keySet()) {
Map<String, String> map1 = record1.getMapField(key);
Map<String, String> map2 = record2.getMapField(key);
for (String k : map1.keySet()) {
if (!map2.containsKey(k)) {
diffCount++;
} else if (!map1.get(k).equalsIgnoreCase(map2.get(k))) {
diffCountMaster++;
}
}
}
System.out.println("\ndiff count = " + diffCount);
System.out.println("\nmaster diff count:" + diffCountMaster);
}
示例3: StateTransitionTimeoutConfig
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
public StateTransitionTimeoutConfig(ZNRecord record) {
_resource = record.getId();
if (record.getMapFields().containsKey(StateTransitionTimeoutProperty.TIMEOUT.name())) {
_timeoutMap = record.getMapField(StateTransitionTimeoutProperty.TIMEOUT.name());
} else {
_timeoutMap = new HashMap<String, String>();
}
}
示例4: printNodeOfflineOverhead
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
public static void printNodeOfflineOverhead(ZNRecord record) {
// build node -> partition map
Map<String, Set<String>> nodeNextMap = new TreeMap<String, Set<String>>();
for (String partitionName : record.getMapFields().keySet()) {
Map<String, String> map1 = record.getMapField(partitionName);
String master = "", slave = "";
for (String nodeName : map1.keySet()) {
if (!nodeNextMap.containsKey(nodeName)) {
nodeNextMap.put(nodeName, new TreeSet<String>());
}
// String master = "", slave = "";
if (map1.get(nodeName).equalsIgnoreCase("MASTER")) {
master = nodeName;
} else {
if (slave.equalsIgnoreCase("")) {
slave = nodeName;
}
}
}
nodeNextMap.get(master).add(slave);
}
System.out.println("next count: ");
for (String key : nodeNextMap.keySet()) {
System.out.println(nodeNextMap.get(key).size() + " ");
}
System.out.println();
}
示例5: getSingleValue
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private static String getSingleValue(ZNRecord record, ZnodePropertyType type, String key) {
if (record == null || key == null) {
return null;
}
String value = null;
String keyParts[] = key.split("/");
switch (type) {
case SIMPLE:
value = record.getSimpleField(key);
break;
case LIST:
List<String> list = record.getListField(keyParts[0]);
if (list == null) {
logger.warn("invalid key for list field: " + key + ", map for key part-1 doesn't exist");
return null;
}
int idx = Integer.parseInt(keyParts[1]);
value = list.get(idx);
break;
case MAP:
Map<String, String> map = record.getMapField(keyParts[0]);
if (map == null) {
logger.warn("invalid key for map field: " + key + ", map for key part-1 doesn't exist");
return null;
}
value = map.get(keyParts[1]);
break;
default:
break;
}
return value;
}
示例6: setSingleValue
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private static void setSingleValue(ZNRecord record, ZnodePropertyType type, String key,
String value) {
String keyParts[] = key.split("/");
switch (type) {
case SIMPLE:
record.setSimpleField(key, value);
break;
case LIST:
List<String> list = record.getListField(keyParts[0]);
if (list == null) {
logger.warn("invalid key for list field: " + key + ", value for key part-1 doesn't exist");
return;
}
int idx = Integer.parseInt(keyParts[1]);
list.remove(idx);
list.add(idx, value);
break;
case MAP:
Map<String, String> map = record.getMapField(keyParts[0]);
if (map == null) {
logger.warn("invalid key for map field: " + key + ", value for key part-1 doesn't exist");
return;
}
map.put(keyParts[1], value);
break;
default:
break;
}
}
示例7: removeSingleValue
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private static void removeSingleValue(ZNRecord record, ZnodePropertyType type, String key) {
if (record == null) {
return;
}
String keyParts[] = key.split("/");
switch (type) {
case SIMPLE:
record.getSimpleFields().remove(key);
break;
case LIST:
List<String> list = record.getListField(keyParts[0]);
if (list == null) {
logger.warn("invalid key for list field: " + key + ", value for key part-1 doesn't exist");
return;
}
int idx = Integer.parseInt(keyParts[1]);
list.remove(idx);
break;
case MAP:
Map<String, String> map = record.getMapField(keyParts[0]);
if (map == null) {
logger.warn("invalid key for map field: " + key + ", value for key part-1 doesn't exist");
return;
}
map.remove(keyParts[1]);
break;
default:
break;
}
}
示例8: calculateIdealState
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
/**
* Calculate the initial ideal state given a batch of storage instances, the replication factor
* and
* number of partitions
* 1. Calculate the master assignment by random shuffling
* 2. for each storage instance, calculate the 1st slave assignment map, by another random
* shuffling
* 3. for each storage instance, calculate the i-th slave assignment map
* 4. Combine the i-th slave assignment maps together
* @param instanceNames
* list of storage node instances
* @param partitions
* number of partitions
* @param replicas
* The number of replicas (slave partitions) per master partition
* @param masterStateValue
* master state value: e.g. "MASTER" or "LEADER"
* @param slaveStateValue
* slave state value: e.g. "SLAVE" or "STANDBY"
* @param resourceName
* @return a ZNRecord that contain the idealstate info
*/
public static ZNRecord calculateIdealState(List<String> instanceNames, int partitions,
int replicas, String resourceName, String masterStateValue, String slaveStateValue) {
Collections.sort(instanceNames);
if (instanceNames.size() < replicas + 1) {
throw new HelixException("Number of instances must not be less than replicas + 1. "
+ "instanceNr:" + instanceNames.size() + ", replicas:" + replicas);
} else if (partitions < instanceNames.size()) {
ZNRecord idealState =
IdealStateCalculatorByShuffling.calculateIdealState(instanceNames, partitions, replicas,
resourceName, 12345, masterStateValue, slaveStateValue);
int i = 0;
for (String partitionId : idealState.getMapFields().keySet()) {
Map<String, String> partitionAssignmentMap = idealState.getMapField(partitionId);
List<String> partitionAssignmentPriorityList = new ArrayList<String>();
String masterInstance = "";
for (String instanceName : partitionAssignmentMap.keySet()) {
if (partitionAssignmentMap.get(instanceName).equalsIgnoreCase(masterStateValue)
&& masterInstance.equals("")) {
masterInstance = instanceName;
} else {
partitionAssignmentPriorityList.add(instanceName);
}
}
Collections.shuffle(partitionAssignmentPriorityList, new Random(i++));
partitionAssignmentPriorityList.add(0, masterInstance);
idealState.setListField(partitionId, partitionAssignmentPriorityList);
}
return idealState;
}
Map<String, Object> result = calculateInitialIdealState(instanceNames, partitions, replicas);
return convertToZNRecord(result, resourceName, masterStateValue, slaveStateValue);
}
示例9: verifyBalanceExternalView
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
static boolean verifyBalanceExternalView(ZNRecord externalView, int partitionCount,
String masterState, int replica, int instances) {
Map<String, Integer> masterPartitionsCountMap = new HashMap<String, Integer>();
for (String partitionName : externalView.getMapFields().keySet()) {
Map<String, String> assignmentMap = externalView.getMapField(partitionName);
// Assert.assertTrue(assignmentMap.size() >= replica);
for (String instance : assignmentMap.keySet()) {
if (assignmentMap.get(instance).equals(masterState)) {
if (!masterPartitionsCountMap.containsKey(instance)) {
masterPartitionsCountMap.put(instance, 0);
}
masterPartitionsCountMap.put(instance, masterPartitionsCountMap.get(instance) + 1);
}
}
}
int perInstancePartition = partitionCount / instances;
int totalCount = 0;
for (String instanceName : masterPartitionsCountMap.keySet()) {
int instancePartitionCount = masterPartitionsCountMap.get(instanceName);
totalCount += instancePartitionCount;
if (!(instancePartitionCount == perInstancePartition || instancePartitionCount == perInstancePartition + 1)) {
return false;
}
if (instancePartitionCount == perInstancePartition + 1) {
if (partitionCount % instances == 0) {
return false;
}
}
}
if (partitionCount != totalCount) {
return false;
}
return true;
}
示例10: verifyBalanceExternalView
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
static boolean verifyBalanceExternalView(ZNRecord externalView, int partitionCount,
String masterState, int replica, int instances) {
if (externalView == null) {
return false;
}
Map<String, Integer> masterPartitionsCountMap = new HashMap<String, Integer>();
for (String partitionName : externalView.getMapFields().keySet()) {
Map<String, String> assignmentMap = externalView.getMapField(partitionName);
// Assert.assertTrue(assignmentMap.size() >= replica);
for (String instance : assignmentMap.keySet()) {
if (assignmentMap.get(instance).equals(masterState)) {
if (!masterPartitionsCountMap.containsKey(instance)) {
masterPartitionsCountMap.put(instance, 0);
}
masterPartitionsCountMap.put(instance, masterPartitionsCountMap.get(instance) + 1);
}
}
}
int perInstancePartition = partitionCount / instances;
int totalCount = 0;
for (String instanceName : masterPartitionsCountMap.keySet()) {
int instancePartitionCount = masterPartitionsCountMap.get(instanceName);
totalCount += instancePartitionCount;
if (!(instancePartitionCount == perInstancePartition || instancePartitionCount == perInstancePartition + 1)) {
return false;
}
if (instancePartitionCount == perInstancePartition + 1) {
if (partitionCount % instances == 0) {
return false;
}
}
}
if (partitionCount != totalCount) {
return false;
}
return true;
}
示例11: verify
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
boolean verify(ZNRecord result) {
Map<String, Integer> masterPartitionCounts = new HashMap<String, Integer>();
Map<String, Integer> slavePartitionCounts = new HashMap<String, Integer>();
for (String key : result.getMapFields().keySet()) {
Map<String, String> mapField = result.getMapField(key);
int masterCount = 0;
for (String host : mapField.keySet()) {
if (mapField.get(host).equals("MASTER")) {
Assert.assertTrue(masterCount == 0);
masterCount++;
if (!masterPartitionCounts.containsKey(host)) {
masterPartitionCounts.put(host, 0);
} else {
masterPartitionCounts.put(host, masterPartitionCounts.get(host) + 1);
}
} else {
if (!slavePartitionCounts.containsKey(host)) {
slavePartitionCounts.put(host, 0);
} else {
slavePartitionCounts.put(host, slavePartitionCounts.get(host) + 1);
}
}
}
}
List<Integer> masterCounts = new ArrayList<Integer>();
List<Integer> slaveCounts = new ArrayList<Integer>();
masterCounts.addAll(masterPartitionCounts.values());
slaveCounts.addAll(slavePartitionCounts.values());
Collections.sort(masterCounts);
Collections.sort(slaveCounts);
Assert.assertTrue(masterCounts.get(masterCounts.size() - 1) - masterCounts.get(0) <= 1);
Assert.assertTrue(slaveCounts.get(slaveCounts.size() - 1) - slaveCounts.get(0) <= 2);
return true;
}
示例12: 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);
}
示例13: testDeleteConfigFields
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Test (dependsOnMethods = "testUpdateConfigFields")
public void testDeleteConfigFields()
throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
ClusterConfig config = getClusterConfigFromRest(cluster);
ZNRecord record = config.getRecord();
String simpleKey = record.getSimpleFields().keySet().iterator().next();
String value = record.getSimpleField(simpleKey);
record.getSimpleFields().clear();
record.setSimpleField(simpleKey, value);
String listKey = record.getListFields().keySet().iterator().next();
List<String> list = record.getListField(listKey);
record.getListFields().clear();
record.setListField(listKey, list);
String mapKey = record.getMapFields().keySet().iterator().next();
Map<String, String> map = record.getMapField(mapKey);
record.getMapFields().clear();
record.setMapField(mapKey, map);
ClusterConfig prevConfig = getClusterConfigFromRest(cluster);
updateClusterConfigFromRest(cluster, config, Command.delete);
ClusterConfig newConfig = getClusterConfigFromRest(cluster);
Assert.assertFalse(newConfig.getRecord().getSimpleFields().containsKey(simpleKey),
"Failed to delete key " + simpleKey + " from cluster config");
Assert.assertFalse(newConfig.getRecord().getListFields().containsKey(listKey),
"Failed to delete key " + listKey + " from cluster config");
Assert.assertFalse(newConfig.getRecord().getSimpleFields().containsKey(mapKey),
"Failed to delete key " + mapKey + " from cluster config");
prevConfig.getRecord().subtract(config.getRecord());
Assert.assertEquals(newConfig, prevConfig,
"cluster config from response: " + newConfig + " vs cluster config actually: "
+ prevConfig);
}
示例14: SegmentZKMetadata
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
public SegmentZKMetadata(ZNRecord znRecord) {
_segmentName = znRecord.getSimpleField(CommonConstants.Segment.SEGMENT_NAME);
_tableName = znRecord.getSimpleField(CommonConstants.Segment.TABLE_NAME);
_segmentType = znRecord.getEnumField(CommonConstants.Segment.SEGMENT_TYPE, SegmentType.class, SegmentType.OFFLINE);
_startTime = znRecord.getLongField(CommonConstants.Segment.START_TIME, -1);
_endTime = znRecord.getLongField(CommonConstants.Segment.END_TIME, -1);
if (znRecord.getSimpleFields().containsKey(CommonConstants.Segment.TIME_UNIT) && !znRecord.getSimpleField(
CommonConstants.Segment.TIME_UNIT).equals(NULL)) {
setTimeUnit(znRecord.getEnumField(CommonConstants.Segment.TIME_UNIT, TimeUnit.class, TimeUnit.DAYS));
}
_indexVersion = znRecord.getSimpleField(CommonConstants.Segment.INDEX_VERSION);
_totalRawDocs = znRecord.getLongField(CommonConstants.Segment.TOTAL_DOCS, -1);
_crc = znRecord.getLongField(CommonConstants.Segment.CRC, -1);
_creationTime = znRecord.getLongField(CommonConstants.Segment.CREATION_TIME, -1);
try {
String partitionMetadataJson = znRecord.getSimpleField(CommonConstants.Segment.PARTITION_METADATA);
if (partitionMetadataJson != null) {
_partitionMetadata = SegmentPartitionMetadata.fromJsonString(partitionMetadataJson);
}
} catch (IOException e) {
LOGGER.error(
"Exception caught while reading partition info from zk metadata for segment '{}', partition info dropped.",
_segmentName, e);
}
_segmentUploadStartTime = znRecord.getLongField(CommonConstants.Segment.SEGMENT_UPLOAD_START_TIME, -1);
_customMap = znRecord.getMapField(CommonConstants.Segment.CUSTOM_MAP);
}
示例15: getMapValue
import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
private static Map<String, String> getMapValue(ZNRecord record, String key) {
return record.getMapField(key);
}