List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:gobblin.util.SchedulerUtilsTest.java
@Test public void testloadGenericJobConfigs() throws ConfigurationException, IOException { Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getAbsolutePath()); List<Properties> jobConfigs = SchedulerUtils.loadGenericJobConfigs(properties); Assert.assertEquals(jobConfigs.size(), 4); // test-job-conf-dir/test1/test11/test111.pull Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull"); Assert.assertEquals(jobProps1.stringPropertyNames().size(), 7); Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps1.getProperty("k1"), "d1"); Assert.assertEquals(jobProps1.getProperty("k2"), "a2"); Assert.assertEquals(jobProps1.getProperty("k3"), "a3"); Assert.assertEquals(jobProps1.getProperty("k8"), "a8"); Assert.assertEquals(jobProps1.getProperty("k9"), "a8"); // test-job-conf-dir/test1/test11.pull Properties jobProps2 = getJobConfigForFile(jobConfigs, "test11.pull"); Assert.assertEquals(jobProps2.stringPropertyNames().size(), 6); Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps2.getProperty("k1"), "c1"); Assert.assertEquals(jobProps2.getProperty("k2"), "a2"); Assert.assertEquals(jobProps2.getProperty("k3"), "b3"); Assert.assertEquals(jobProps2.getProperty("k6"), "a6"); // test-job-conf-dir/test1/test12.PULL Properties jobProps3 = getJobConfigForFile(jobConfigs, "test12.PULL"); Assert.assertEquals(jobProps3.stringPropertyNames().size(), 6); Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps3.getProperty("k1"), "b1"); Assert.assertEquals(jobProps3.getProperty("k2"), "a2"); Assert.assertEquals(jobProps3.getProperty("k3"), "a3"); Assert.assertEquals(jobProps3.getProperty("k7"), "a7"); // test-job-conf-dir/test2/test21.PULL Properties jobProps4 = getJobConfigForFile(jobConfigs, "test21.PULL"); Assert.assertEquals(jobProps4.stringPropertyNames().size(), 5); Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps4.getProperty("k1"), "a1"); Assert.assertEquals(jobProps4.getProperty("k2"), "b2"); Assert.assertEquals(jobProps4.getProperty("k5"), "b5"); }
From source file:com.netflix.lipstick.pigtolipstick.BasicP2LClient.java
@Override @SuppressWarnings("unused") public void createPlan(MROperPlan plan) { if (plan != null && unopPlanGenerator != null && opPlanGenerator != null && context != null) { Configuration conf = null; for (MapReduceOper job : plan) { if (conf == null) { conf = new Configuration(); ScriptState.get().addSettingsToConf(job, conf); break; }// w w w .java 2s . com } try { Map<PhysicalOperator, Operator> p2lMap = Maps.newHashMap(); Map<Operator, PhysicalOperator> l2pMap = context.getExecutionEngine().getLogToPhyMap(); for (Entry<Operator, PhysicalOperator> i : l2pMap.entrySet()) { p2lMap.put(i.getValue(), i.getKey()); } String script = null; // suppress getting script from conf for now - do something smarter later if (conf != null && false) { script = new String(Base64.decodeBase64(conf.get("pig.script"))); } if ((script == null || script.length() == 0) && (ps != null)) { script = StringUtils.join(ps.getScriptCache(), '\n'); } MRPlanCalculator opPlan = new MRPlanCalculator(opPlanGenerator.getP2jPlan(), plan, p2lMap, opPlanGenerator.getReverseMap()); MRPlanCalculator unopPlan = new MRPlanCalculator(unopPlanGenerator.getP2jPlan(), plan, p2lMap, unopPlanGenerator.getReverseMap()); P2jPlanPackage plans = new P2jPlanPackage(opPlan.getP2jPlan(), unopPlan.getP2jPlan(), script, planId); Properties props = context.getProperties(); plans.setUserName(UserGroupInformation.getCurrentUser().getUserName()); if (props.containsKey(JOB_NAME_PROP)) { plans.setJobName(props.getProperty(JOB_NAME_PROP)); } else { plans.setJobName("unknown"); } plans.getStatus().setStartTime(); plans.getStatus().setStatusText(StatusText.running); psClient.savePlan(plans); } catch (Exception e) { LOG.error("Caught unexpected exception generating json plan.", e); } } else { LOG.warn("Not saving plan, missing necessary objects to do so"); } }
From source file:com.google.api.ads.adwords.awreporting.exporter.ReportExporter.java
/** * Generates the HashMap with all the data from reports * * @param dateStart the start date for the reports * @param dateEnd the end date for the reports * @param accountId the account CID to generate PDF for * @param properties the properties file containing all the configuration * @param sumAdExtensions to add up all the extensions *//* ww w . j a v a 2s .co m*/ public Map<String, Object> createReportDataMap(String dateStart, String dateEnd, Long accountId, Properties properties, Boolean sumAdExtensions) { Map<String, Object> reportDataMap = Maps.newHashMap(); Set<ReportDefinitionReportType> reports = csvReportEntitiesMapping.getDefinedReports(); for (ReportDefinitionReportType reportType : reports) { if (properties.containsKey(reportType.name())) { // Adding each report type rows from DB to the account's monthly reports list. List<Report> monthlyReports = Lists.newArrayList( persister.listMonthReports(csvReportEntitiesMapping.getReportBeanClass(reportType), accountId, DateUtil.parseDateTime(dateStart), DateUtil.parseDateTime(dateEnd))); if (monthlyReports != null && monthlyReports.size() > 0) { reportDataMap.put(reportType.name(), monthlyReports); // Add formatted string values to reportDateMap for use in templates DateTime startDate = DateUtil.parseDateTime(dateStart); DateTime endDate = DateUtil.parseDateTime(dateEnd); String monthStartText = TemplateStringsUtil.formatDateFullMonthYear(startDate); String monthEndText = TemplateStringsUtil.formatDateFullMonthYear(endDate); String monthRangeText = TemplateStringsUtil.formatFullMonthDateRange(startDate, endDate); Map<String, String> dateStrings = new HashMap<String, String>(); dateStrings.put("monthStart", monthStartText); dateStrings.put("monthEnd", monthEndText); dateStrings.put("monthRange", monthRangeText); reportDataMap.put("FORMATTED_DATE_STRINGS", dateStrings); } } } return reportDataMap; }
From source file:com.meltmedia.cadmium.servlets.jersey.StatusService.java
@GET @Produces(MediaType.APPLICATION_JSON)/*from w ww. j av a2 s .c o m*/ public Status status(@HeaderParam("Authorization") @DefaultValue("no token") String auth) throws Exception { boolean authorized = false; try { if (this.isAuth(auth)) { authorized = true; } } catch (Throwable t) { logger.warn("Authentication failed for status: " + auth, t); } Status returnObj = new Status(); String rev = null; String branch = null; String repo = null; String configRev = null; String configBranch = null; String configRepo = null; Properties configProperties = configManager.getDefaultProperties(); // Get content directory String contentDir = configProperties.getProperty("com.meltmedia.cadmium.lastUpdated", ""); // Get config directory String configDir = configProperties.getProperty("com.meltmedia.cadmium.config.lastUpdated", ""); GitService git = null; try { git = gitService.getGitServiceNoBlock(); rev = git.getCurrentRevision(); branch = git.getBranchName(); repo = git.getRemoteRepository(); } catch (IllegalStateException e) { logger.debug("Content git service is not yet set: " + e.getMessage()); } finally { try { gitService.releaseGitService(); } catch (IllegalMonitorStateException e) { logger.debug("Released unattained read lock."); } } // Get cadmium project info (branch, repo and revision) rev = configProperties.getProperty("git.ref.sha", rev); branch = configProperties.getProperty("branch", branch == null ? configProperties.getProperty("com.meltmedia.cadmium.branch") : branch); repo = configProperties.getProperty("repo", repo == null ? configProperties.getProperty("com.meltmedia.cadmium.git.uri") : repo); git = null; try { git = configGitService.getGitServiceNoBlock(); configRev = git.getCurrentRevision(); configBranch = git.getBranchName(); configRepo = git.getRemoteRepository(); } catch (IllegalStateException e) { logger.debug("Config git service is not yet set: " + e.getMessage()); } finally { try { configGitService.releaseGitService(); } catch (IllegalMonitorStateException e) { logger.debug("Released unattained read lock."); } } // Get cadmium project info (branch, repo and revision) configRev = configProperties.getProperty("config.git.ref.sha", configRev); configBranch = configProperties.getProperty("config.branch", configBranch == null ? configProperties.getProperty("com.meltmedia.cadmium.config.branch") : configBranch); configRepo = configProperties.getProperty("config.repo", configRepo == null ? configProperties.getProperty("com.meltmedia.cadmium.config.git.uri", repo) : configRepo); // Get source project info (branch, repo and revision) String sourceFile = contentDir + File.separator + "META-INF" + File.separator + "source"; String source = "{}"; if (FileSystemManager.canRead(sourceFile)) { source = FileSystemManager.getFileContents(sourceFile); } else { logger.trace("No source file [{}]", sourceFile); } logger.trace("Source [{}] is from [{}]", source, sourceFile); if (authorized) { // Get cluster members' status List<ChannelMember> members = lifecycleService.getPeirStates(); if (members != null) { List<StatusMember> peers = new ArrayList<StatusMember>(); for (ChannelMember member : members) { StatusMember peer = new StatusMember(); peer.setAddress(member.getAddress().toString()); peer.setCoordinator(member.isCoordinator()); peer.setState(member.getState()); peer.setConfigState(member.getConfigState()); peer.setMine(member.isMine()); peer.setExternalIp(member.getExternalIp()); peer.setWarInfo(member.getWarInfo()); peers.add(peer); } returnObj.setMembers(peers); } returnObj.setContentDir(contentDir); returnObj.setConfigDir(configDir); returnObj.setRepo(repo); returnObj.setConfigRepo(configRepo); InputStream in = null; try { in = getClass().getClassLoader().getResourceAsStream("cadmium-version.properties"); Properties props = new Properties(); props.load(in); if (props.containsKey("version")) { returnObj.setCadmiumVersion(props.getProperty("version")); } } catch (Throwable t) { logger.debug("Failed to get cadmium version.", t); } finally { if (in != null) { IOUtils.closeQuietly(in); } } } // Get environment status String environFromConfig = System.getProperty("com.meltmedia.cadmium.environment"); if (environFromConfig != null && environFromConfig.trim().length() > 0) { returnObj.setEnvironment(environFromConfig); } else { returnObj.setEnvironment(ENVIRON_DEV); } // Get Maintanence page status (on or off) String maintStatus; if (maintService.isOn()) { maintStatus = MAINT_ON; } else { maintStatus = MAINT_OFF; } returnObj.setGroupName(sender.getGroupName()); returnObj.setBranch(branch); returnObj.setRevision(rev); returnObj.setConfigBranch(configBranch); returnObj.setConfigRevision(configRev); returnObj.setMaintPageState(maintStatus); returnObj.setSource(source); return returnObj; }
From source file:org.accada.reader.hal.impl.sim.multi.BatchSimulatorServer.java
/** * Initiziale and start BatchSimulatorServer: * <ul><li>set controller</li> * <li>check and load properties from properties file PROPERTIES_FILE_LOCATION</li> * <li>check the batch file location</li></ul> */// w w w . j a va 2 s .co m public void initialize(SimulatorServerController controller) throws SimulatorServerException { this.controller = controller; // load properties from properties file Properties props = new Properties(); try { props.load(this.getClass().getResourceAsStream(PROPERTIES_FILE_LOCATION)); } catch (Exception e) { throw new SimulatorServerException("Could not load the properties from properties file."); } // check properties if (!props.containsKey("batchfile")) { throw new SimulatorServerException("Property 'batchfile' not found."); } if (!props.containsKey("iterations")) { throw new SimulatorServerException("Property 'iterations' not found."); } // get properties batchFile = props.getProperty("batchfile"); try { iterations = Integer.parseInt(props.getProperty("iterations")); } catch (NumberFormatException e) { throw new SimulatorServerException("Property 'iterations' must be a number"); } // check batch file if (!new File(batchFile).exists()) { throw new SimulatorServerException("Batch file '" + batchFile + "' not found."); } start(); }
From source file:com.adito.input.validators.StringValidator.java
public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException { // /*from www .jav a 2s.c om*/ if ("true".equalsIgnoreCase( properties == null ? "true" : properties.getProperty("trim", String.valueOf(trim)))) { value = value.trim(); } // Get the range int min = minLength; try { if (properties != null && properties.containsKey("minLength")) min = Integer.parseInt(properties.getProperty("minLength")); } catch (NumberFormatException nfe) { log.error("Failed to get minimum value for validator.", nfe); throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value); } int max = maxLength; try { if (properties != null && properties.containsKey("maxLength")) max = Integer.parseInt(properties.getProperty("maxLength")); } catch (NumberFormatException nfe) { log.error("Failed to get maximum value for validator.", nfe); throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value); } // Validate if (value.length() < min) { throw new CoreException(ErrorConstants.ERR_STRING_TOO_SHORT, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null); } if (value.length() > max) { throw new CoreException(ErrorConstants.ERR_STRING_TOO_LONG, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null); } // Regular expression String regExp = properties == null ? this.regExp : Util.trimmedOrBlank(properties.getProperty("regExp", this.regExp)); if (regExp != null && !regExp.equals("") && !value.matches(regExp)) { throw new CoreException(regExpErrCode, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(regExp), value, null, null); } // Simple pattern String pattern = Util.trimmedOrBlank( properties == null ? this.pattern : properties.getProperty("pattern", this.pattern)); if (!pattern.equals("")) { pattern = Util.parseSimplePatternToRegExp(pattern); if (!value.matches(pattern)) { throw new CoreException(ErrorConstants.ERR_STRING_DOESNT_MATCH_SIMPLE_PATTERN, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(pattern), value, null, null); } } }
From source file:com.ottogroup.bi.spqr.pipeline.component.source.RandomNumberTestSource.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties) *///ww w . ja v a 2 s . com public void initialize(Properties properties) throws RequiredInputMissingException, ComponentInitializationFailedException { this.maxNumGenerated = Integer.parseInt(StringUtils.trim(properties.getProperty(CFG_MAX_NUM_GENERATED))); try { this.seed = Long.parseLong(StringUtils.trim(properties.getProperty(CFG_SEED))); } catch (Exception e) { // } this.content = (properties.containsKey(CFG_CONTENT) ? properties.getProperty(CFG_CONTENT).getBytes() : new byte[0]); this.running = true; }
From source file:org.aon.esolutions.appconfig.client.web.SystemPropertiesListener.java
private void loadPropsFromClasspath(ServletContext sc) { String propertiesLocationProp = sc.getInitParameter("classpath.file.location"); Properties systemProps = System.getProperties(); Properties loadedProps = new Properties(); ClassPathResource appConfigResource = new ClassPathResource(propertiesLocationProp); if (appConfigResource.exists()) { try {/* w w w .j a v a2s .c om*/ loadedProps.load(appConfigResource.getInputStream()); for (Map.Entry<Object, Object> e : loadedProps.entrySet()) { if (systemProps.containsKey(e.getKey()) == false) systemProps.put(e.getKey(), e.getValue()); } } catch (Exception e) { logger.error("Error loading properties", e); } } }
From source file:com.cloudera.sqoop.TestSqoopOptions.java
public void testMapColumnHiveParams() throws Exception { String[] args = { "--map-column-hive", "id=STRING", }; SqoopOptions opts = parse(args);/*w ww . j a v a 2 s. com*/ Properties mapping = opts.getMapColumnHive(); assertTrue(mapping.containsKey("id")); assertEquals("STRING", mapping.get("id")); }
From source file:com.cloudera.sqoop.TestSqoopOptions.java
public void testMapColumnJavaParams() throws Exception { String[] args = { "--map-column-java", "id=String", }; SqoopOptions opts = parse(args);//from ww w .j a v a 2 s. co m Properties mapping = opts.getMapColumnJava(); assertTrue(mapping.containsKey("id")); assertEquals("String", mapping.get("id")); }