/** * Creates an instance of configuration. * * @return an instance of CConfiguration. */ public static CConfiguration create() { // Create a new configuration instance, but do NOT initialize with // the Hadoop default properties. CConfiguration conf = new CConfiguration(); conf.addResource("cdap-default.xml"); conf.addResource("cdap-site.xml"); return conf; }
/** * Creates an instance of configuration. * * @return an instance of CConfiguration. */ public static CConfiguration create() { // Create a new configuration instance, but do NOT initialize with // the Hadoop default properties. CConfiguration conf = new CConfiguration(); conf.addResource("cdap-default.xml"); conf.addResource("cdap-site.xml"); return conf; }
/** * Creates an instance of configuration. * @param resource the URL to be added to the configuration * @param moreResources the list of URL's to be added to the configuration * @return an instance of CConfiguration * @throws IllegalArgumentException when the resource cannot be converted to the URL */ public static CConfiguration create(URL resource, URL...moreResources) { CConfiguration conf = new CConfiguration(); conf.addResource(resource); for (URL resourceURL : moreResources) { conf.addResource(resourceURL); } return conf; }
/** * Creates an instance of configuration. * @param resource the URL to be added to the configuration * @param moreResources the list of URL's to be added to the configuration * @return an instance of CConfiguration * @throws IllegalArgumentException when the resource cannot be converted to the URL */ public static CConfiguration create(URL resource, URL...moreResources) { CConfiguration conf = new CConfiguration(); conf.addResource(resource); for (URL resourceURL : moreResources) { conf.addResource(resourceURL); } return conf; }
/** * Creates an instance of configuration. * @param file the file to be added to the configuration * @param moreFiles the list of more files to be added to the configuration * @return an instance of CConfiguration * @throws MalformedURLException if the error occurred while constructing the URL */ public static CConfiguration create(File file, File...moreFiles) throws MalformedURLException { CConfiguration conf = new CConfiguration(); conf.addResource(file.toURI().toURL()); for (File anotherFile : moreFiles) { conf.addResource(anotherFile.toURI().toURL()); } return conf; }
/** * Creates an instance of configuration. * @param file the file to be added to the configuration * @param moreFiles the list of more files to be added to the configuration * @return an instance of CConfiguration * @throws MalformedURLException if the error occurred while constructing the URL */ public static CConfiguration create(File file, File...moreFiles) throws MalformedURLException { CConfiguration conf = new CConfiguration(); conf.addResource(file.toURI().toURL()); for (File anotherFile : moreFiles) { conf.addResource(anotherFile.toURI().toURL()); } return conf; }
/** * Creates an instance of configuration. * @param resource the resource to be added to the configuration * @return an instance of CConfiguration */ public static CConfiguration create(InputStream resource) { CConfiguration conf = new CConfiguration(); conf.addResource(resource); return conf; }
/** * Creates an instance of configuration. * @param resource the resource to be added to the configuration * @return an instance of CConfiguration */ public static CConfiguration create(InputStream resource) { CConfiguration conf = new CConfiguration(); conf.addResource(resource); return conf; }
cConf.addResource(cConfFile.toURI().toURL());
cConf.addResource(cConfFile.toURI().toURL());
@Override public void init(String[] args) { try { conf = Configuration.create(); cConf = CConfiguration.create(); cConf.addResource("coopr-default.xml"); cConf.addResource("coopr-site.xml"); securityEnabled = conf.getBoolean(co.cask.cdap.common.conf.Constants.Security.ENABLED); if (securityEnabled) { // Enable Kerberos login SecurityUtil.enableKerberosLogin(cConf); } String zkQuorum = conf.get(Constants.ZOOKEEPER_QUORUM); if (zkQuorum == null) { String dataPath = conf.get(Constants.LOCAL_DATA_DIR) + "/zookeeper"; inMemoryZKServer = InMemoryZKServer.builder().setDataDir(new File(dataPath)).setTickTime(2000).build(); LOG.warn(Constants.ZOOKEEPER_QUORUM + " not specified, defaulting to in memory zookeeper with data dir " + dataPath); } else { zkClientService = getZKService(conf.get(Constants.ZOOKEEPER_QUORUM)); } solverNumThreads = conf.getInt(Constants.SOLVER_NUM_THREADS); } catch (Exception e) { LOG.error("Exception initializing server", e); } }
cConf.addResource(new File(systemArgs.getOption(ProgramOptionConstants.CDAP_CONF_FILE)).toURI().toURL());
cConf.addResource(new File(systemArgs.getOption(ProgramOptionConstants.CDAP_CONF_FILE)).toURI().toURL());
@Test public void testDeprecatedConfigProperties() throws Exception { CConfiguration conf = CConfiguration.create(); Map<String, String[]> deprecated = conf.getDeprecatedProps(); if (!deprecated.isEmpty()) { Map.Entry<String, String[]> property = deprecated.entrySet().iterator().next(); // Test a deprecated property on loading from resources InputStream resource = new ByteArrayInputStream(Bytes.toBytes( String.format("<configuration><property><name>%s</name><value>%s</value></property></configuration>", property.getKey(), DEPRECATED_PROPERTY_VALUE))); conf.addResource(resource); conf.reloadConfiguration(); // Validate new properties, which should be used instead of deprecated for (String newProperty : property.getValue()) { Assert.assertEquals(DEPRECATED_PROPERTY_VALUE, conf.get(newProperty)); } // Clear the Config before next test conf.clear(); // Test a deprecated property on set from the code conf.set(property.getKey(), DEPRECATED_PROPERTY_VALUE); // Validate new properties, which should be used instead of deprecated for (String newProperty : property.getValue()) { Assert.assertEquals(DEPRECATED_PROPERTY_VALUE, conf.get(newProperty)); } // Close the InputStream Closeables.closeQuietly(resource); } }
@Test public void testConfiguration() throws Exception { // first test empty config object CConfiguration conf = CConfiguration.create(); String a = conf.get("conf.test.A"); String b = conf.get("conf.test.B"); Assert.assertNull(a); Assert.assertNull(b); // load some defaults and make sure they work conf.addResource("test-default.xml"); a = conf.get("conf.test.A"); b = conf.get("conf.test.B"); Assert.assertNotNull(a); Assert.assertNotNull(b); Assert.assertEquals("A", a); Assert.assertEquals("B", b); // override one of the defaults and verify conf.addResource("test-override.xml"); a = conf.get("conf.test.A"); b = conf.get("conf.test.B"); Assert.assertNotNull(a); Assert.assertNotNull(b); Assert.assertEquals("A", a); Assert.assertEquals("B+", b); }
@Test public void testAddedConfiguration() throws Exception { CConfiguration conf = CConfiguration.create(); conf.addResource("test-default.xml"); conf.set("conf.test.addedA", "AddedA"); conf.set("conf.test.addedB", "AddedB"); conf.set("conf.test.A", "A+"); Assert.assertNotNull(conf.get("conf.test.A")); Assert.assertNotNull(conf.get("conf.test.B")); Assert.assertNotNull(conf.get("conf.test.addedA")); Assert.assertNotNull(conf.get("conf.test.addedB")); Assert.assertEquals("A+", conf.get("conf.test.A")); Assert.assertEquals("AddedA", conf.get("conf.test.addedA")); Assert.assertEquals("AddedB", conf.get("conf.test.addedB")); }