use of alluxio.grpc.ConfigProperty in project alluxio by Alluxio.
the class GetConf method getConfImpl.
/**
* Implements get configuration.
*
* @param clientSupplier a functor to return a config client of meta master
* @param alluxioConf Alluxio configuration
* @param args list of arguments
* @return 0 on success, 1 on failures
*/
@VisibleForTesting
public static int getConfImpl(Supplier<RetryHandlingMetaMasterConfigClient> clientSupplier, AlluxioConfiguration alluxioConf, String... args) {
CommandLineParser parser = new DefaultParser();
CommandLine cmd;
try {
cmd = parser.parse(OPTIONS, args, true);
} catch (ParseException e) {
printHelp("Unable to parse input args: " + e.getMessage());
return 1;
}
args = cmd.getArgs();
Map<String, ConfigProperty> confMap = new HashMap<>();
if (cmd.hasOption(MASTER_OPTION_NAME)) {
// load cluster-wide configuration
try (RetryHandlingMetaMasterConfigClient client = clientSupplier.get()) {
client.getConfiguration(GetConfigurationPOptions.newBuilder().setIgnorePathConf(true).build()).getClusterConf().forEach(prop -> confMap.put(prop.getName(), prop.toProto()));
} catch (IOException e) {
System.out.println("Unable to get master-side configuration: " + e.getMessage());
return -1;
}
} else {
// load local configuration
for (PropertyKey key : alluxioConf.keySet()) {
if (key.isBuiltIn()) {
ConfigProperty.Builder config = ConfigProperty.newBuilder().setName(key.getName()).setSource(alluxioConf.getSource(key).toString());
Object val = alluxioConf.getOrDefault(key, null, ConfigurationValueOptions.defaults().useDisplayValue(true));
if (val != null) {
config.setValue(String.valueOf(val));
}
confMap.put(key.getName(), config.build());
}
}
}
StringBuilder output = new StringBuilder();
switch(args.length) {
case 0:
List<ConfigProperty> properties = new ArrayList<>(confMap.values());
properties.sort(Comparator.comparing(ConfigProperty::getName));
for (ConfigProperty property : properties) {
String value = ConfigurationUtils.valueAsString(property.getValue());
output.append(String.format("%s=%s", property.getName(), value));
if (cmd.hasOption(SOURCE_OPTION_NAME)) {
output.append(String.format(" (%s)", property.getSource()));
}
output.append("\n");
}
System.out.print(output.toString());
break;
case 1:
if (!PropertyKey.isValid(args[0])) {
printHelp(String.format("%s is not a valid configuration key", args[0]));
return 1;
}
// args[0] can be the alias
String key = PropertyKey.fromString(args[0]).getName();
ConfigProperty property = confMap.get(key);
if (property == null) {
printHelp(String.format("%s is not found", key));
return 1;
}
if (property.getValue() == null) {
// value not set
System.out.println("");
} else {
if (cmd.hasOption(SOURCE_OPTION_NAME)) {
System.out.println(property.getSource());
} else if (cmd.hasOption(UNIT_OPTION_NAME)) {
String arg = cmd.getOptionValue(UNIT_OPTION_NAME).toUpperCase();
try {
ByteUnit byteUnit;
byteUnit = ByteUnit.valueOf(arg);
System.out.println(FormatUtils.parseSpaceSize(property.getValue()) / byteUnit.getValue());
break;
} catch (Exception e) {
// try next unit parse
}
try {
TimeUnit timeUnit;
timeUnit = TimeUnit.valueOf(arg);
System.out.println(FormatUtils.parseTimeSize(property.getValue()) / timeUnit.getValue());
break;
} catch (IllegalArgumentException ex) {
// try next unit parse
}
printHelp(String.format("%s is not a valid unit", arg));
return 1;
} else {
System.out.println(property.getValue());
}
}
break;
default:
printHelp(String.format("More arguments than expected. Args: %s", Arrays.toString(args)));
return 1;
}
return 0;
}
use of alluxio.grpc.ConfigProperty in project alluxio by Alluxio.
the class Configuration method toProto.
/**
* @return the proto representation
*/
public GetConfigurationPResponse toProto() {
GetConfigurationPResponse.Builder response = GetConfigurationPResponse.newBuilder();
if (mClusterConf != null) {
mClusterConf.forEach(property -> response.addClusterConfigs(property.toProto()));
}
if (mPathConf != null) {
mPathConf.forEach((path, properties) -> {
List<ConfigProperty> propertyList = properties.stream().map(Property::toProto).collect(Collectors.toList());
ConfigProperties configProperties = ConfigProperties.newBuilder().addAllProperties(propertyList).build();
response.putPathConfigs(path, configProperties);
});
}
if (mClusterConfHash != null) {
response.setClusterConfigHash(mClusterConfHash);
}
if (mPathConfHash != null) {
response.setPathConfigHash(mPathConfHash);
}
return response.build();
}
use of alluxio.grpc.ConfigProperty in project alluxio by Alluxio.
the class BlockMasterClient method register.
/**
* The method the worker should execute to register with the block master.
*
* @param workerId the worker id of the worker registering
* @param storageTierAliases a list of storage tier aliases in ordinal order
* @param totalBytesOnTiers mapping from storage tier alias to total bytes
* @param usedBytesOnTiers mapping from storage tier alias to used bytes
* @param currentBlocksOnLocation mapping from storage tier alias to the list of list of blocks
* @param lostStorage mapping from storage tier alias to the list of lost storage paths
* @param configList a list of configurations
*/
// TODO(yupeng): rename to workerBlockReport or workerInitialize?
public void register(final long workerId, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Map<BlockStoreLocation, List<Long>> currentBlocksOnLocation, final Map<String, List<String>> lostStorage, final List<ConfigProperty> configList) throws IOException {
final RegisterWorkerPOptions options = RegisterWorkerPOptions.newBuilder().addAllConfigs(configList).build();
final List<LocationBlockIdListEntry> currentBlocks = convertBlockListMapToProto(currentBlocksOnLocation);
final Map<String, StorageList> lostStorageMap = lostStorage.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> StorageList.newBuilder().addAllStorage(e.getValue()).build()));
final RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addAllStorageTiers(storageTierAliases).putAllTotalBytesOnTiers(totalBytesOnTiers).putAllUsedBytesOnTiers(usedBytesOnTiers).addAllCurrentBlocks(currentBlocks).putAllLostStorage(lostStorageMap).setOptions(options).build();
retryRPC(() -> {
mClient.registerWorker(request);
return null;
}, LOG, "Register", "workerId=%d", workerId);
}
use of alluxio.grpc.ConfigProperty in project alluxio by Alluxio.
the class ConfigurationUtils method filterAndLoadProperties.
/**
* Filters and loads properties with a certain scope from the property list returned by grpc.
* The given scope should only be {@link Scope#WORKER} or {@link Scope#CLIENT}.
*
* @param properties the property list returned by grpc
* @param scope the scope to filter the received property list
* @param logMessage a function with key and value as parameter and returns debug log message
* @return the loaded properties
*/
private static Properties filterAndLoadProperties(List<ConfigProperty> properties, Scope scope, BiFunction<PropertyKey, String, String> logMessage) {
Properties props = new Properties();
for (ConfigProperty property : properties) {
String name = property.getName();
// TODO(binfan): support propagating unsetting properties from master
if (PropertyKey.isValid(name) && property.hasValue()) {
PropertyKey key = PropertyKey.fromString(name);
if (!GrpcUtils.contains(key.getScope(), scope)) {
// Only propagate properties contains the target scope
continue;
}
String value = property.getValue();
props.put(key, value);
LOG.debug(logMessage.apply(key, value));
}
}
return props;
}
Aggregations