Search in sources :

Example 1 with ConfigurationEditor

use of alluxio.hub.agent.util.conf.ConfigurationEditor in project alluxio by Alluxio.

the class AgentProcessContext method updateConf.

/**
 * Update alluxio site property values.
 * @param props properties to be updated
 * @return true if property is updated
 */
public boolean updateConf(Properties props) {
    Properties fileProps = null;
    if (!validateConf(props)) {
        return false;
    }
    try {
        fileProps = ConfigurationUtils.loadProperties(new ByteArrayInputStream(getConf().getSiteProperties().getBytes()));
    } catch (Exception e) {
        LOG.info("Exception when reading old configuration " + e);
    }
    if (fileProps == null) {
        fileProps = props;
    } else {
        fileProps.putAll(props);
    }
    try (StringWriter stringWriter = new StringWriter()) {
        fileProps.store(stringWriter, "Updated Alluxio site properties generated by Alluxio hub agent");
        AlluxioConfigurationSet conf = AlluxioConfigurationSet.newBuilder().setSiteProperties(stringWriter.toString()).build();
        Path path = Paths.get(mConf.getString(PropertyKey.CONF_DIR), ConfigurationEditor.SITE_PROPERTIES);
        if (Files.notExists(path)) {
            Files.createFile(path);
        }
        new ConfigurationEditor(mConf.getString(PropertyKey.SITE_CONF_DIR)).writeConf(conf);
    } catch (IOException e) {
        return false;
    }
    return true;
}
Also used : Path(java.nio.file.Path) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties) ConfigurationEditor(alluxio.hub.agent.util.conf.ConfigurationEditor) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) AlluxioConfigurationSet(alluxio.hub.proto.AlluxioConfigurationSet)

Aggregations

ConfigurationEditor (alluxio.hub.agent.util.conf.ConfigurationEditor)1 AlluxioConfigurationSet (alluxio.hub.proto.AlluxioConfigurationSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1 Properties (java.util.Properties)1 TimeoutException (java.util.concurrent.TimeoutException)1