@Override public ZNRecord toZNRecord() { ZNRecord znRecord = new ZNRecord(getId()); znRecord.setMapField(KAFKA_HIGH_LEVEL_CONSUMER_GROUP_MAP, _groupIdMap); znRecord.setMapField(KAFKA_HIGH_LEVEL_CONSUMER_PARTITION_MAP, _partitionMap); return znRecord; }
private ZNRecord getTestInstanceZNRecord() { ZNRecord record = new ZNRecord("Server_localhost_1234"); Map<String, String> groupIdMap = new HashMap<>(); Map<String, String> partitionMap = new HashMap<>(); for (int i = 0; i < 10; ++i) { groupIdMap.put("testRes" + i + "_REALTIME", "groupId" + i); partitionMap.put("testRes" + i + "_REALTIME", "part" + i); } record.setMapField("KAFKA_HLC_GROUP_MAP", groupIdMap); record.setMapField("KAFKA_HLC_PARTITION_MAP", partitionMap); return record; }
if (state.equals(ONLINE_STATE)) { metadata.put("count", "R"); record.setMapField(key, metadata); record.setMapField(key, metadata); record.setMapField(key, metadata); metadata.put(OFFLINE_STATE, OFFLINE_STATE); metadata.put(DROPPED_STATE, DROPPED_STATE); record.setMapField(key, metadata); metadata.put(ONLINE_STATE, ONLINE_STATE); metadata.put(DROPPED_STATE, DROPPED_STATE); record.setMapField(key, metadata);
private static InstanceZKMetadata getInstanceZKMetadata() { ZNRecord record = new ZNRecord("Server_localhost_1234"); Map<String, String> groupIdMap = new HashMap<>(); Map<String, String> partitionMap = new HashMap<>(); groupIdMap.put("mirror", "groupId_testTable_" + String.valueOf(System.currentTimeMillis())); partitionMap.put("testTable_R", "0"); record.setMapField("KAFKA_HLC_GROUP_MAP", groupIdMap); record.setMapField("KAFKA_HLC_PARTITION_MAP", partitionMap); return new InstanceZKMetadata(record); }
if (state.equals(ONLINE_STATE)) { metadata.put("count", "R"); record.setMapField(key, metadata); record.setMapField(key, metadata); record.setMapField(key, metadata); metadata.put(OFFLINE_STATE, OFFLINE_STATE); metadata.put(DROPPED_STATE, DROPPED_STATE); record.setMapField(key, metadata); metadata.put(ONLINE_STATE, ONLINE_STATE); metadata.put(DROPPED_STATE, DROPPED_STATE); record.setMapField(key, metadata);
/** * Add or update a {@link ZNRecord} to include a map field with the given key and value. If the supplied * {@link ZNRecord} is null, a new {@link ZNRecord} will be created. * @param oldRecord A {@link ZNRecord} to add or update its map field. {@code null} indicates to create a * new {@link ZNRecord}. * @param mapKey The key for the map field. * @param mapValue The value for the map field. * @return A {@link ZNRecord} including a map field with the given key and value. */ private ZNRecord makeZNRecordWithMapField(ZNRecord oldRecord, String mapKey, Map<String, String> mapValue) { ZNRecord zNRecord = oldRecord == null ? new ZNRecord(String.valueOf(System.currentTimeMillis())) : oldRecord; if (mapKey != null && mapValue != null) { zNRecord.setMapField(mapKey, mapValue); } return zNRecord; }
recordToUpdate.setMapField(ACCOUNT_METADATA_MAP_KEY, accountMap); potentialNewState = accountMap; return recordToUpdate;
/** * Tests reading {@link ZNRecord} from {@link HelixPropertyStore}, where the {@link ZNRecord} has an invalid account * record and a valid account record. This is a NOT good {@link ZNRecord} format and it should fail fetch or update * operations, with none of the record should be read. * @throws Exception Any unexpected exception. */ @Test public void testReadBadZNRecordCase6() throws Exception { ZNRecord zNRecord = new ZNRecord(String.valueOf(System.currentTimeMillis())); Map<String, String> accountMap = new HashMap<>(); accountMap.put(String.valueOf(refAccount.getId()), refAccount.toJson(true).toString()); accountMap.put(String.valueOf(refAccount.getId() + 1), BAD_ACCOUNT_METADATA_STRING); zNRecord.setMapField(ACCOUNT_METADATA_MAP_KEY, accountMap); updateAndWriteZNRecord(zNRecord, false); }
/** * Pre-populates a collection of {@link Account}s to the underlying {@link org.apache.helix.store.HelixPropertyStore} * using {@link com.github.ambry.clustermap.HelixStoreOperator} (not through the {@link HelixAccountService}). This method * does not check any conflict among the {@link Account}s to write. * @throws Exception Any unexpected exception. */ private void writeAccountsToHelixPropertyStore(Collection<Account> accounts, boolean shouldNotify) throws Exception { HelixStoreOperator storeOperator = new HelixStoreOperator(mockHelixAccountServiceFactory.getHelixStore(ZK_CONNECT_STRING, storeConfig)); ZNRecord zNRecord = new ZNRecord(String.valueOf(System.currentTimeMillis())); Map<String, String> accountMap = new HashMap<>(); for (Account account : accounts) { accountMap.put(String.valueOf(account.getId()), account.toJson(true).toString()); } zNRecord.setMapField(ACCOUNT_METADATA_MAP_KEY, accountMap); // Write account metadata into HelixPropertyStore. storeOperator.write(HelixAccountService.FULL_ACCOUNT_METADATA_PATH, zNRecord); if (shouldNotify) { notifier.publish(ACCOUNT_METADATA_CHANGE_TOPIC, FULL_ACCOUNT_METADATA_CHANGE_MESSAGE); } }
znRecord.setMapField(CommonConstants.Segment.CUSTOM_MAP, _customMap);
if (state.equals("ONLINE")) { metadata.put("count", "R"); record.setMapField(key, metadata); record.setMapField(key, metadata); record.setMapField(key, metadata); metadata.put("OFFLINE", "OFFLINE"); metadata.put("DROPPED", "OFFLINE"); record.setMapField(key, metadata); metadata.put("ONLINE", "ONLINE"); metadata.put("DROPPED", "DROPPED"); record.setMapField(key, metadata);
/** * For a given partition, indicate where and in what state each of its replicas is in * @param partitionName the partition to set * @param currentStateMap (instance, state) pairs */ public void setStateMap(String partitionName, Map<String, String> currentStateMap) { _record.setMapField(partitionName, currentStateMap); }
/** * Add a resource quota map to this LiveInstance. For resource quota map, key=resourceName; * value=quota of that resource. We assume that value can be casted into integers. Note that * this resourceName refers to compute / storage / network resource that this liveinstance * has, i.e. thread count, CPU cores, heap size, etc. * * @param resourceQuotaMap resourceQuotaMap */ public void setResourceCapacityMap(Map<String, String> resourceQuotaMap) { _record.setMapField(LiveInstanceProperty.RESOURCE_CAPACITY.name(), resourceQuotaMap); }
/** * Add instance, state pairs for a partition * @param partition the partition to set * @param replicaMap map of (instance name, state) */ public void addReplicaMap(Partition partition, Map<String, String> replicaMap) { _record.setMapField(partition.getPartitionName(), replicaMap); } }
@Override public ZNRecord update(ZNRecord znRecord) { if (znRecord.getMapField(task) == null) { znRecord.setMapField(task, new HashMap<String, String>()); } znRecord.getMapField(task).put(key, value); return znRecord; } }, AccessOption.PERSISTENT);
private void add(ZNRecord record, String stateUnitKey, String instanceName, String state) { Map<String, String> stateUnitKeyMap = record.getMapField(stateUnitKey); if (stateUnitKeyMap == null) { stateUnitKeyMap = new HashMap<>(); record.setMapField(stateUnitKey, stateUnitKeyMap); } stateUnitKeyMap.put(instanceName, state); record.setMapField(stateUnitKey, stateUnitKeyMap); } }
public void setJobState(String job, TaskState s) { Map<String, String> states = _record.getMapField(WorkflowContextProperties.JOB_STATES.name()); if (states == null) { states = new TreeMap<String, String>(); _record.setMapField(WorkflowContextProperties.JOB_STATES.name(), states); } states.put(job, s.name()); }
/** * Set task quota type with the ratio of this quota. * @param quotaType String * @param quotaRatio int */ public void setTaskQuotaRatio(String quotaType, int quotaRatio) { if (_record.getMapField(ClusterConfigProperty.QUOTA_TYPES.name()) == null) { _record.setMapField(ClusterConfigProperty.QUOTA_TYPES.name(), new HashMap<String, String>()); } _record.getMapField(ClusterConfigProperty.QUOTA_TYPES.name()) .put(quotaType, Integer.toString(quotaRatio)); }
private Message buildMessage( final MessageType type, final Map<String, String> content ) { return new Message( Message.MessageType.USER_DEFINE_MSG, randomUUID().toString() ) {{ setMsgState( Message.MessageState.NEW ); getRecord().setMapField( "content", content ); getRecord().setSimpleField( "type", type.toString() ); getRecord().setSimpleField( "origin", instanceName ); }}; }
private void createIS(HelixDataAccessor accessor, String resourceId, String stateModelDefRef, RebalanceMode rebalanceMode) { IdealState idealState = new IdealState(resourceId); idealState.setRebalanceMode(rebalanceMode); idealState.setStateModelDefRef(stateModelDefRef); idealState.setNumPartitions(1); idealState.setReplicas("1"); idealState.getRecord().setListField(resourceId + "_0", ImmutableList.of(PARTICIPANT)); idealState.getRecord().setMapField(resourceId + "_0", ImmutableMap.of(PARTICIPANT, STATE)); accessor.setProperty(accessor.keyBuilder().idealStates(resourceId), idealState); }