List of usage examples for org.apache.hadoop.conf Configuration writeXml
public void writeXml(Writer out) throws IOException
From source file:org.apache.falcon.unit.FalconUnit.java
License:Apache License
private static void setupOozieConfigs() throws IOException { sysProps = new HashMap<>(); String oozieHomeDir = OOZIE_HOME_DIR; String oozieConfDir = oozieHomeDir + "/conf"; String oozieHadoopConfDir = oozieConfDir + "/hadoop-conf"; String oozieActionConfDir = oozieConfDir + "/action-conf"; String oozieLogsDir = oozieHomeDir + "/logs"; String oozieDataDir = oozieHomeDir + "/data"; LOCAL_FS.mkdirs(new Path(oozieHomeDir)); LOCAL_FS.mkdirs(new Path(oozieConfDir)); LOCAL_FS.mkdirs(new Path(oozieHadoopConfDir)); LOCAL_FS.mkdirs(new Path(oozieActionConfDir)); LOCAL_FS.mkdirs(new Path(oozieLogsDir)); LOCAL_FS.close();// w w w. j a v a2 s .co m setSystemProperty("oozie.home.dir", oozieHomeDir); setSystemProperty("oozie.data.dir", oozieDataDir); setSystemProperty("oozie.action.conf", oozieActionConfDir); setSystemProperty("oozie.log.dir", oozieLogsDir); setSystemProperty("oozie.log4j.file", "localoozie-log4j.properties"); setSystemProperty("oozielocal.log", "oozieLogsDir/oozielocal.log"); Configuration oozieSiteConf = new Configuration(false); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream oozieSiteInputStream = classLoader.getResourceAsStream(OOZIE_SITE_XML); XConfiguration configuration = new XConfiguration(oozieSiteInputStream); Properties props = configuration.toProperties(); for (String propName : props.stringPropertyNames()) { oozieSiteConf.set(propName, props.getProperty(propName)); } oozieSiteInputStream.close(); InputStream oozieDefaultInputStream = classLoader.getResourceAsStream(OOZIE_DEFAULT_XML); configuration = new XConfiguration(oozieDefaultInputStream); String classes = configuration.get(Services.CONF_SERVICE_CLASSES); oozieSiteConf.set(Services.CONF_SERVICE_CLASSES, classes.replaceAll("org.apache.oozie.service.ShareLibService,", "")); File target = new File(oozieConfDir, OOZIE_SITE_XML); FileOutputStream outStream = null; try { outStream = new FileOutputStream(target); oozieSiteConf.writeXml(outStream); } finally { if (outStream != null) { outStream.close(); } } oozieDefaultInputStream.close(); CurrentUser.authenticate(System.getProperty("user.name")); }
From source file:org.apache.flink.yarn.YarnTestBase.java
License:Apache License
public static File writeYarnSiteConfigXML(Configuration yarnConf) throws IOException { tmp.create();/* ww w . j a va2 s . co m*/ File yarnSiteXML = new File(tmp.newFolder().getAbsolutePath() + "/yarn-site.xml"); FileWriter writer = new FileWriter(yarnSiteXML); yarnConf.writeXml(writer); writer.flush(); writer.close(); return yarnSiteXML; }
From source file:org.apache.hama.bsp.ApplicationMaster.java
License:Apache License
/** * Writes the current configuration to a given path to reflect changes. For * example the sync server address is put after the file has been written. */// w w w .jav a 2s.c o m private static void rewriteSubmitConfiguration(String path, Configuration conf) throws IOException { Path jobSubmitPath = new Path(path); FileSystem fs = FileSystem.get(conf); FSDataOutputStream out = fs.create(jobSubmitPath); conf.writeXml(out); out.close(); LOG.info("Written new configuration back to " + path); }
From source file:org.apache.hive.http.ConfServlet.java
License:Apache License
/** * Guts of the servlet - extracted for easy testing. *///ww w . jav a2 s. c o m static void writeResponse(Configuration conf, Writer out, String format) throws IOException, BadFormatException { if (FORMAT_JSON.equals(format)) { Configuration.dumpConfiguration(conf, out); } else if (FORMAT_XML.equals(format)) { conf.writeXml(out); } else { throw new BadFormatException("Bad format: " + format); } }
From source file:org.apache.hoya.tools.ConfigHelper.java
License:Apache License
/** * Save a config// ww w .ja va 2 s .com * @param fs filesystem * @param destPath dest to save * @param confToSave config to save * @throws IOException IO problems */ public static void saveConfig(FileSystem fs, Path destPath, Configuration confToSave) throws IOException { FSDataOutputStream fos = fs.create(destPath); try { confToSave.writeXml(fos); } finally { IOUtils.closeStream(fos); } }
From source file:org.apache.hoya.tools.ConfigHelper.java
License:Apache License
/** * Generate a config file in a destination directory on the local filesystem * @param confdir the directory path where the file is to go * @param filename the filename/*from w ww.jav a 2 s. c o m*/ * @return the destination path */ public static File saveConfig(Configuration generatingConf, File confdir, String filename) throws IOException { File destPath = new File(confdir, filename); OutputStream fos = new FileOutputStream(destPath); try { generatingConf.writeXml(fos); } finally { IOUtils.closeStream(fos); } return destPath; }
From source file:org.apache.hoya.yarn.client.HoyaClient.java
License:Apache License
/** * get the cluster configuration//from ww w . j a v a 2 s .c o m * @param clustername cluster name * @return the cluster name */ @SuppressWarnings({ "UseOfSystemOutOrSystemErr", "IOResourceOpenedButNotSafelyClosed" }) public int actionGetConf(String clustername, ActionGetConfArgs confArgs) throws YarnException, IOException { File outfile = null; if (confArgs.getOutput() != null) { outfile = new File(confArgs.getOutput()); } String format = confArgs.getFormat(); verifyManagerSet(); HoyaUtils.validateClusterName(clustername); ClusterDescription status = getClusterDescription(clustername); Writer writer; boolean toPrint; if (outfile != null) { writer = new FileWriter(outfile); toPrint = false; } else { writer = new StringWriter(); toPrint = true; } try { String description = "Hoya cluster " + clustername; if (format.equals(Arguments.FORMAT_XML)) { Configuration siteConf = getSiteConf(status, clustername); siteConf.writeXml(writer); } else if (format.equals(Arguments.FORMAT_PROPERTIES)) { Properties props = new Properties(); props.putAll(status.clientProperties); props.store(writer, description); } else { throw new BadCommandArgumentsException("Unknown format: " + format); } } finally { // data is written. // close the file writer.close(); } // then, if this is not a file write, print it if (toPrint) { // not logged System.err.println(writer.toString()); } return EXIT_SUCCESS; }
From source file:org.apache.ignite.igfs.HadoopFIleSystemFactorySelfTest.java
License:Apache License
/** * Write configuration to file./*from ww w . j ava 2s . co m*/ * * @param conf Configuration. * @throws Exception If failed. */ @SuppressWarnings("ResultOfMethodCallIgnored") private static void writeConfigurationToFile(Configuration conf) throws Exception { final String path = U.getIgniteHome() + SECONDARY_CFG_PATH; File file = new File(path); file.delete(); assertFalse(file.exists()); try (FileOutputStream fos = new FileOutputStream(file)) { conf.writeXml(fos); } assertTrue(file.exists()); }
From source file:org.apache.ignite.igfs.HadoopSecondaryFileSystemConfigurationTest.java
License:Apache License
/** * Writes down the configuration to local disk and returns its path. * * @param cfg the configuration to write. * @param pathFromIgniteHome path relatively to Ignite home. * @return Full path of the written configuration. *///from www . j a v a 2 s .co m static String writeConfiguration(Configuration cfg, String pathFromIgniteHome) throws IOException { if (!pathFromIgniteHome.startsWith("/")) pathFromIgniteHome = "/" + pathFromIgniteHome; final String path = U.getIgniteHome() + pathFromIgniteHome; delete(path); File file = new File(path); try (FileOutputStream fos = new FileOutputStream(file)) { cfg.writeXml(fos); } assertTrue(file.exists()); return path; }
From source file:org.apache.ignite.igfs.IgfsHadoopFileSystemAbstractSelfTest.java
License:Apache License
/** {@inheritDoc} */ @Override//from w w w .j a v a 2 s . c o m protected void beforeTestsStarted() throws Exception { Configuration secondaryConf = configuration(SECONDARY_AUTHORITY, true, true); secondaryConf.setInt("fs.igfs.block.size", 1024); String path = U.getIgniteHome() + SECONDARY_CFG_PATH; File file = new File(path); try (FileOutputStream fos = new FileOutputStream(file)) { secondaryConf.writeXml(fos); } startNodes(); }