public static boolean getClusterTenantIsolationEnabled(ZkHelixPropertyStore<ZNRecord> propertyStore) { String controllerConfigPath = constructPropertyStorePathForControllerConfig(CLUSTER_TENANT_ISOLATION_ENABLED_KEY); if (propertyStore.exists(controllerConfigPath, AccessOption.PERSISTENT)) { ZNRecord znRecord = propertyStore.get(controllerConfigPath, null, AccessOption.PERSISTENT); if (znRecord.getSimpleFields().keySet().contains(CLUSTER_TENANT_ISOLATION_ENABLED_KEY)) { return znRecord.getBooleanField(CLUSTER_TENANT_ISOLATION_ENABLED_KEY, true); } else { return true; } } else { return true; } } }
@Nonnull public static TableConfig fromZnRecord(@Nonnull ZNRecord znRecord) throws IOException { Map<String, String> simpleFields = znRecord.getSimpleFields(); TableType tableType = TableType.valueOf(simpleFields.get(TABLE_TYPE_KEY).toUpperCase()); String tableName = TableNameBuilder.forType(tableType).tableNameWithType(simpleFields.get(TABLE_NAME_KEY));
Map<String, String> simpleFieldMap1 = record1.getSimpleFields(); Map<String, String> simpleFieldMap2 = record2.getSimpleFields(); if (simpleFieldMap1.size() != simpleFieldMap2.size()) { return false;
public SegmentZKMetadata(ZNRecord znRecord) { _segmentName = znRecord.getSimpleField(CommonConstants.Segment.SEGMENT_NAME); _tableName = znRecord.getSimpleField(CommonConstants.Segment.TABLE_NAME); _crypterName = znRecord.getSimpleField(CommonConstants.Segment.CRYPTER_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); }
@Override public ZNRecord update(ZNRecord znRecord) { znRecord.getSimpleFields().putAll(contentToAddOrUpdate); return znRecord; } }, AccessOption.PERSISTENT);
/** * Determine whether the given config key is in the simple config * @param configKey The key to check whether exists * @return True if exists, otherwise false */ public boolean simpleConfigContains(String configKey) { return getRecord().getSimpleFields().containsKey(configKey); }
private static int getListFieldBound(ZNRecord record) { int max = Integer.MAX_VALUE; if (record.getSimpleFields().containsKey(ZNRecord.LIST_FIELD_BOUND)) { String maxStr = record.getSimpleField(ZNRecord.LIST_FIELD_BOUND); try { max = Integer.parseInt(maxStr); } catch (Exception e) { logger.error("IllegalNumberFormat for list field bound: " + maxStr); } } return max; }
/** * Get all simple configurations. * * @return all simple configurations. */ public Map<String, String> getSimpleConfigs() { return Collections.unmodifiableMap(getRecord().getSimpleFields()); }
/** * Get a single simple config value. * * @param configKey * @return configuration value, or NULL if not exist. */ public String getSimpleConfig(String configKey) { return getRecord().getSimpleFields().get(configKey); }
/** * Get all simple configurations. * * @return all simple configurations. */ public Map<String, String> getSimpleConfigs() { return Collections.unmodifiableMap(getRecord().getSimpleFields()); }
/** * Put a set of simple configs. * * @param configsMap */ public void putSimpleConfigs(Map<String, String> configsMap) { getRecord().getSimpleFields().putAll(configsMap); }
/** * Put a single simple config value. * * @param configKey * @param configVal */ public void putSimpleConfig(String configKey, String configVal) { getRecord().getSimpleFields().put(configKey, configVal); }
/** * Put a set of simple configs. * * @param configsMap */ public void putSimpleConfigs(Map<String, String> configsMap) { getRecord().getSimpleFields().putAll(configsMap); }
public static List<ZNRecordRow> convertSimpleFields(ZNRecord record) { List<ZNRecordRow> result = new ArrayList<ZNRecordRow>(); for (String key : record.getSimpleFields().keySet()) { ZNRecordRow row = new ZNRecordRow(); row.putField(ZNRECORD_ID, record.getId()); row.putField(SIMPLE_KEY, key); row.putField(SIMPLE_VALUE, record.getSimpleField(key)); result.add(row); } return result; }
public static JobConfig fromHelixProperty(HelixProperty property) throws IllegalArgumentException { Map<String, String> configs = property.getRecord().getSimpleFields(); return Builder.fromMap(configs).build(); }
public static JobConfig fromHelixProperty(HelixProperty property) throws IllegalArgumentException { Map<String, String> configs = property.getRecord().getSimpleFields(); return Builder.fromMap(configs).build(); }
public void removeResourceProperty(String clusterName, String resourceName, String propertyKey) { IdealState idealState = _admin.getResourceIdealState(clusterName, resourceName); if (idealState == null) { throw new HelixException("Resource: " + resourceName + " has NOT been added yet"); } idealState.getRecord().getSimpleFields().remove(propertyKey); _admin.setResourceIdealState(clusterName, resourceName, idealState); }
public static WorkflowConfig fromHelixProperty(HelixProperty property) throws IllegalArgumentException { Map<String, String> configs = property.getRecord().getSimpleFields(); if (!configs.containsKey(WorkflowConfigProperty.Dag.name())) { throw new IllegalArgumentException( String.format("%s is an invalid WorkflowConfig", property.getId())); } return Builder.fromMap(configs).setWorkflowId(property.getId()).build(); }
public void testGroupCommit() throws InterruptedException { final BaseDataAccessor<ZNRecord> accessor = new MockBaseDataAccessor(); final GroupCommit commit = new GroupCommit(); ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(400); for (int i = 0; i < 2400; i++) { Runnable runnable = new MyClass(accessor, commit, i); newFixedThreadPool.submit(runnable); } Thread.sleep(10000); System.out.println(accessor.get("test", null, 0)); System.out.println(accessor.get("test", null, 0).getSimpleFields().size()); }
protected static JobConfig.Builder getJobConfig(ZNRecord record) { JobConfig.Builder jobConfig = new JobConfig.Builder().fromMap(record.getSimpleFields()); jobConfig.addTaskConfigMap(getTaskConfigMap(record.getMapFields())); return jobConfig; }