Search in sources :

Example 6 with ConfigProperty

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) CommandLine(org.apache.commons.cli.CommandLine) ConfigProperty(alluxio.grpc.ConfigProperty) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient) PropertyKey(alluxio.conf.PropertyKey) DefaultParser(org.apache.commons.cli.DefaultParser) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with ConfigProperty

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();
}
Also used : ConfigProperties(alluxio.grpc.ConfigProperties) ConfigProperty(alluxio.grpc.ConfigProperty) GetConfigurationPResponse(alluxio.grpc.GetConfigurationPResponse)

Example 8 with ConfigProperty

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);
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PropertyKey(alluxio.conf.PropertyKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) BlockMasterWorkerServiceGrpc(alluxio.grpc.BlockMasterWorkerServiceGrpc) BlockHeartbeatPOptions(alluxio.grpc.BlockHeartbeatPOptions) Constants(alluxio.Constants) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) GrpcUtils(alluxio.grpc.GrpcUtils) GetWorkerIdPRequest(alluxio.grpc.GetWorkerIdPRequest) Map(java.util.Map) BlockHeartbeatPRequest(alluxio.grpc.BlockHeartbeatPRequest) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) AbstractMasterClient(alluxio.AbstractMasterClient) Metric(alluxio.grpc.Metric) RetryPolicy(alluxio.retry.RetryPolicy) BlockIdList(alluxio.grpc.BlockIdList) CommitBlockInUfsPRequest(alluxio.grpc.CommitBlockInUfsPRequest) FailedToAcquireRegisterLeaseException(alluxio.exception.FailedToAcquireRegisterLeaseException) Logger(org.slf4j.Logger) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) GetRegisterLeasePResponse(alluxio.grpc.GetRegisterLeasePResponse) IOException(java.io.IOException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ConfigProperty(alluxio.grpc.ConfigProperty) Command(alluxio.grpc.Command) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) MasterClientContext(alluxio.master.MasterClientContext) CommitBlockPRequest(alluxio.grpc.CommitBlockPRequest) ServiceType(alluxio.grpc.ServiceType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) StorageList(alluxio.grpc.StorageList) StorageList(alluxio.grpc.StorageList) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) HashMap(java.util.HashMap) Map(java.util.Map) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry)

Example 9 with ConfigProperty

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;
}
Also used : ConfigProperty(alluxio.grpc.ConfigProperty) AlluxioProperties(alluxio.conf.AlluxioProperties) Properties(java.util.Properties) PropertyKey(alluxio.conf.PropertyKey)

Aggregations

ConfigProperty (alluxio.grpc.ConfigProperty)9 PropertyKey (alluxio.conf.PropertyKey)5 Constants (alluxio.Constants)2 AlluxioProperties (alluxio.conf.AlluxioProperties)2 FailedToAcquireRegisterLeaseException (alluxio.exception.FailedToAcquireRegisterLeaseException)2 GetConfigurationPResponse (alluxio.grpc.GetConfigurationPResponse)2 GrpcUtils (alluxio.grpc.GrpcUtils)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ImmutableTriple (org.apache.commons.lang3.tuple.ImmutableTriple)2 Triple (org.apache.commons.lang3.tuple.Triple)2 AbstractMasterClient (alluxio.AbstractMasterClient)1 RuntimeConstants (alluxio.RuntimeConstants)1 StorageTierAssoc (alluxio.StorageTierAssoc)1 WorkerStorageTierAssoc (alluxio.WorkerStorageTierAssoc)1