Search in sources :

Example 1 with RetryHandlingMetaMasterConfigClient

use of alluxio.client.meta.RetryHandlingMetaMasterConfigClient in project alluxio by Alluxio.

the class ConfigHashSync method resetMetaMasterConfigClient.

/**
 * Resets the internal meta master client based on the new configuration.
 *
 * @param context the context containing the new configuration
 */
public void resetMetaMasterConfigClient(MasterClientContext context) {
    mClient.close();
    mClient = new RetryHandlingMetaMasterConfigClient(context);
}
Also used : RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient)

Example 2 with RetryHandlingMetaMasterConfigClient

use of alluxio.client.meta.RetryHandlingMetaMasterConfigClient in project alluxio by Alluxio.

the class GetConfTest method getConfFromMasterWithSource.

@Test
public void getConfFromMasterWithSource() throws Exception {
    // Prepare mock meta master client
    RetryHandlingMetaMasterConfigClient client = Mockito.mock(RetryHandlingMetaMasterConfigClient.class);
    Mockito.when(client.getConfiguration(any())).thenReturn(Configuration.fromProto(prepareGetConfigurationResponse()));
    assertEquals(0, GetConf.getConfImpl(() -> client, ServerConfiguration.global(), "--master", "--source"));
    // CHECKSTYLE.OFF: LineLengthExceed - Much more readable
    String expectedOutput = "alluxio.logger.type=MASTER_LOGGER (SYSTEM_PROPERTY)\n" + "alluxio.master.audit.logger.type=MASTER_AUDIT_LOGGER (SYSTEM_PROPERTY)\n" + "alluxio.master.hostname=localhost (SITE_PROPERTY (/alluxio/conf/alluxio-site.properties))\n" + "alluxio.master.mount.table.root.ufs=hdfs://localhost:9000 (SITE_PROPERTY (/alluxio/conf/alluxio-site.properties))\n" + "alluxio.master.rpc.port=19998 (DEFAULT)\n" + "alluxio.master.web.port=19999 (DEFAULT)\n";
    // CHECKSTYLE.ON: LineLengthExceed
    assertEquals(expectedOutput, mOutputStream.toString());
}
Also used : RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient) Test(org.junit.Test)

Example 3 with RetryHandlingMetaMasterConfigClient

use of alluxio.client.meta.RetryHandlingMetaMasterConfigClient in project alluxio by Alluxio.

the class GetConfTest method getConfFromMaster.

@Test
public void getConfFromMaster() throws Exception {
    // Prepare mock meta master client
    RetryHandlingMetaMasterConfigClient client = Mockito.mock(RetryHandlingMetaMasterConfigClient.class);
    Mockito.when(client.getConfiguration(any())).thenReturn(Configuration.fromProto(prepareGetConfigurationResponse()));
    assertEquals(0, GetConf.getConfImpl(() -> client, ServerConfiguration.global(), "--master"));
    String expectedOutput = "alluxio.logger.type=MASTER_LOGGER\n" + "alluxio.master.audit.logger.type=MASTER_AUDIT_LOGGER\n" + "alluxio.master.hostname=localhost\n" + "alluxio.master.mount.table.root.ufs=hdfs://localhost:9000\n" + "alluxio.master.rpc.port=19998\n" + "alluxio.master.web.port=19999\n";
    assertEquals(expectedOutput, mOutputStream.toString());
}
Also used : RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient) Test(org.junit.Test)

Example 4 with RetryHandlingMetaMasterConfigClient

use of alluxio.client.meta.RetryHandlingMetaMasterConfigClient in project alluxio by Alluxio.

the class FileSystemContextReinitIntegrationTest method updatePathConf.

private void updatePathConf() throws Exception {
    MetaMasterConfigClient client = new RetryHandlingMetaMasterConfigClient(MasterClientContext.newBuilder(mContext.getClientContext()).build());
    client.setPathConfiguration(PATH_TO_UPDATE, KEY_TO_UPDATE, UPDATED_VALUE);
}
Also used : RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient) MetaMasterConfigClient(alluxio.client.meta.MetaMasterConfigClient) RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient)

Example 5 with RetryHandlingMetaMasterConfigClient

use of alluxio.client.meta.RetryHandlingMetaMasterConfigClient 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)

Aggregations

RetryHandlingMetaMasterConfigClient (alluxio.client.meta.RetryHandlingMetaMasterConfigClient)9 FileSystemContext (alluxio.client.file.FileSystemContext)3 MetaMasterConfigClient (alluxio.client.meta.MetaMasterConfigClient)3 AlluxioURI (alluxio.AlluxioURI)2 InstancedConfiguration (alluxio.conf.InstancedConfiguration)2 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 ClientContext (alluxio.ClientContext)1 Context (alluxio.cli.fsadmin.command.Context)1 RetryHandlingBlockMasterClient (alluxio.client.block.RetryHandlingBlockMasterClient)1 RetryHandlingFileSystemMasterClient (alluxio.client.file.RetryHandlingFileSystemMasterClient)1 RetryHandlingJobMasterClient (alluxio.client.job.RetryHandlingJobMasterClient)1 RetryHandlingJournalMasterClient (alluxio.client.journal.RetryHandlingJournalMasterClient)1 RetryHandlingMetaMasterClient (alluxio.client.meta.RetryHandlingMetaMasterClient)1 RetryHandlingMetricsMasterClient (alluxio.client.metrics.RetryHandlingMetricsMasterClient)1 PropertyKey (alluxio.conf.PropertyKey)1 ConfigProperty (alluxio.grpc.ConfigProperty)1 MasterClientContext (alluxio.master.MasterClientContext)1 JobMasterClientContext (alluxio.worker.job.JobMasterClientContext)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1