Search in sources :

Example 6 with InstancedConfiguration

use of alluxio.conf.InstancedConfiguration in project alluxio by Alluxio.

the class Format method main.

/**
 * Formats the Alluxio file system.
 *
 * @param args either {@code MASTER} or {@code WORKER}
 */
public static void main(String[] args) {
    if (args.length != 1) {
        LOG.info(USAGE);
        System.exit(-1);
    }
    AlluxioConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults());
    // Set the process type as "MASTER" since format needs to access the journal like the master.
    CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.MASTER);
    Mode mode = null;
    try {
        mode = Mode.valueOf(args[0].toUpperCase());
    } catch (IllegalArgumentException e) {
        LOG.error("Unrecognized format mode: {}", args[0]);
        LOG.error("Usage: {}", USAGE);
        System.exit(-1);
    }
    try {
        format(mode, conf);
    } catch (Exception e) {
        LOG.error("Failed to format", e);
        System.exit(-1);
    }
    LOG.info("Formatting complete");
    System.exit(0);
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) IOException(java.io.IOException)

Example 7 with InstancedConfiguration

use of alluxio.conf.InstancedConfiguration in project alluxio by Alluxio.

the class ConfigurationUtils method merge.

/**
 * Merges the current configuration properties with new properties. If a property exists
 * both in the new and current configuration, the one from the new configuration wins if
 * its priority is higher or equal than the existing one.
 *
 * @param conf the base configuration
 * @param properties the source {@link Properties} to be merged
 * @param source the source of the the properties (e.g., system property, default and etc)
 * @return a new configuration representing the merged properties
 */
public static AlluxioConfiguration merge(AlluxioConfiguration conf, Map<?, ?> properties, Source source) {
    AlluxioProperties props = conf.copyProperties();
    props.merge(properties, source);
    return new InstancedConfiguration(props);
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AlluxioProperties(alluxio.conf.AlluxioProperties)

Example 8 with InstancedConfiguration

use of alluxio.conf.InstancedConfiguration in project alluxio by Alluxio.

the class ConfigurationUtils method getPathConf.

/**
 * Loads the path level configuration from the get configuration response.
 *
 * Only client scope properties will be loaded.
 *
 * @param response the get configuration RPC response
 * @param clusterConf cluster level configuration
 * @return the loaded path level configuration
 */
public static PathConfiguration getPathConf(GetConfigurationPResponse response, AlluxioConfiguration clusterConf) {
    String clientVersion = clusterConf.getString(PropertyKey.VERSION);
    LOG.debug("Alluxio client (version {}) is trying to load path level configurations", clientVersion);
    Map<String, AlluxioConfiguration> pathConfs = new HashMap<>();
    response.getPathConfigsMap().forEach((path, conf) -> {
        Properties props = filterAndLoadProperties(conf.getPropertiesList(), Scope.CLIENT, (key, value) -> String.format("Loading property: %s (%s) -> %s for path %s", key, key.getScope(), value, path));
        AlluxioProperties properties = new AlluxioProperties();
        properties.merge(props, Source.PATH_DEFAULT);
        pathConfs.put(path, new InstancedConfiguration(properties, true));
    });
    LOG.debug("Alluxio client has loaded path level configurations");
    return PathConfiguration.create(pathConfs);
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AlluxioProperties(alluxio.conf.AlluxioProperties) HashMap(java.util.HashMap) AlluxioProperties(alluxio.conf.AlluxioProperties) Properties(java.util.Properties) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration)

Example 9 with InstancedConfiguration

use of alluxio.conf.InstancedConfiguration in project alluxio by Alluxio.

the class ConfigurationUtils method reloadProperties.

/**
 * Reloads site properties from disk.
 */
public static void reloadProperties() {
    synchronized (DEFAULT_PROPERTIES_LOCK) {
        // Step1: bootstrap the configuration. This is necessary because we need to resolve alluxio
        // .home (likely to be in system properties) to locate the conf dir to search for the site
        // property file.
        AlluxioProperties properties = new AlluxioProperties();
        InstancedConfiguration conf = new InstancedConfiguration(properties);
        // Can't directly pass System.getProperties() because it is not thread-safe
        // This can cause a ConcurrentModificationException when merging.
        Properties sysProps = new Properties();
        System.getProperties().stringPropertyNames().forEach(key -> sysProps.setProperty(key, System.getProperty(key)));
        properties.merge(sysProps, Source.SYSTEM_PROPERTY);
        // whether in test mode by default properties and system properties (via getBoolean).
        if (conf.getBoolean(PropertyKey.TEST_MODE)) {
            conf.validate();
            sDefaultProperties = properties;
            return;
        }
        // we are not in test mode, load site properties
        String confPaths = conf.getString(PropertyKey.SITE_CONF_DIR);
        String[] confPathList = confPaths.split(",");
        String sitePropertyFile = ConfigurationUtils.searchPropertiesFile(Constants.SITE_PROPERTIES, confPathList);
        Properties siteProps = null;
        if (sitePropertyFile != null) {
            siteProps = loadPropertiesFromFile(sitePropertyFile);
            sSourcePropertyFile = sitePropertyFile;
        } else {
            URL resource = ConfigurationUtils.class.getClassLoader().getResource(Constants.SITE_PROPERTIES);
            if (resource != null) {
                siteProps = loadPropertiesFromResource(resource);
                if (siteProps != null) {
                    sSourcePropertyFile = resource.getPath();
                }
            }
        }
        properties.merge(siteProps, Source.siteProperty(sSourcePropertyFile));
        conf.validate();
        sDefaultProperties = properties;
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AlluxioProperties(alluxio.conf.AlluxioProperties) AlluxioProperties(alluxio.conf.AlluxioProperties) Properties(java.util.Properties) URL(java.net.URL)

Example 10 with InstancedConfiguration

use of alluxio.conf.InstancedConfiguration in project alluxio by Alluxio.

the class AuthenticatedClientUserResourceTest method userRestored.

@Test
public void userRestored() throws Exception {
    InstancedConfiguration conf = ConfigurationTestUtils.defaults();
    AuthenticatedClientUser.set(ORIGINAL_USER);
    User original = AuthenticatedClientUser.get(conf);
    new AuthenticatedClientUserResource(TESTCASE_USER, conf).close();
    assertSame(original, AuthenticatedClientUser.get(conf));
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AuthenticatedClientUser(alluxio.security.authentication.AuthenticatedClientUser) User(alluxio.security.User) Test(org.junit.Test)

Aggregations

InstancedConfiguration (alluxio.conf.InstancedConfiguration)94 Test (org.junit.Test)35 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)16 AlluxioURI (alluxio.AlluxioURI)14 AlluxioProperties (alluxio.conf.AlluxioProperties)11 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 HashMap (java.util.HashMap)9 BaseHubTest (alluxio.hub.test.BaseHubTest)8 InetSocketAddress (java.net.InetSocketAddress)8 FileSystemShell (alluxio.cli.fs.FileSystemShell)6 FileSystemContext (alluxio.client.file.FileSystemContext)6 HealthCheckClient (alluxio.HealthCheckClient)5 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)5 FileSystemShellUtilsTest (alluxio.client.cli.fs.FileSystemShellUtilsTest)5 MasterInquireClient (alluxio.master.MasterInquireClient)5 Properties (java.util.Properties)5 ParseException (org.apache.commons.cli.ParseException)5 ClientContext (alluxio.ClientContext)4 FileSystem (alluxio.client.file.FileSystem)4