List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:org.apache.gobblin.scheduler.JobScheduler.java
/** * Run a job./*from w w w . j a va2 s . com*/ * * <p> * This method runs the job immediately without going through the Quartz scheduler. * This is particularly useful for testing. * </p> * * <p> * This method does what {@link #runJob(Properties, JobListener)} does, and additionally it allows * the caller to pass in a {@link JobLauncher} instance used to launch the job to run. * </p> * * @param jobProps Job configuration properties * @param jobListener {@link JobListener} used for callback, can be <em>null</em> if no callback is needed. * @param jobLauncher a {@link JobLauncher} object used to launch the job to run * @return If current job is a stop-early job based on {@link Source#isEarlyStopped()} * @throws JobException when there is anything wrong with running the job */ public boolean runJob(Properties jobProps, JobListener jobListener, JobLauncher jobLauncher) throws JobException { Preconditions.checkArgument(jobProps.containsKey(ConfigurationKeys.JOB_NAME_KEY), "A job must have a job name specified by job.name"); String jobName = jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY); // Check if the job has been disabled boolean disabled = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_DISABLED_KEY, "false")); if (disabled) { LOG.info("Skipping disabled job " + jobName); return false; } // Launch the job try (Closer closer = Closer.create()) { closer.register(jobLauncher).launchJob(jobListener); boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false")); boolean isEarlyStopped = jobLauncher.isEarlyStopped(); if (!isEarlyStopped && runOnce && this.scheduledJobs.containsKey(jobName)) { this.scheduler.getScheduler().deleteJob(this.scheduledJobs.remove(jobName)); } return isEarlyStopped; } catch (Throwable t) { throw new JobException("Failed to launch and run job " + jobName, t); } }
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
public WADL2UDDI(UDDIClerk clerk, URLLocalizer urlLocalizer, Properties properties) throws ConfigurationException { super();/*from www . j av a 2s . co m*/ this.clerk = clerk; this.urlLocalizer = urlLocalizer; this.properties = properties; if (clerk != null) { if (!properties.containsKey("keyDomain")) { throw new ConfigurationException("Property keyDomain is a required property when using WADL2UDDI."); } if (!properties.containsKey("businessKey") && !properties.containsKey("businessName")) { throw new ConfigurationException( "Either property businessKey, or businessName, is a required property when using WADL2UDDI."); } if (!properties.containsKey("nodeName")) { if (properties.containsKey("serverName") && properties.containsKey("serverPort")) { String nodeName = properties.getProperty("serverName") + "_" + properties.getProperty("serverPort"); properties.setProperty("nodeName", nodeName); } else { throw new ConfigurationException( "Property nodeName is not defined and is a required property when using WADL2UDDI."); } } } //Obtaining values from the properties this.keyDomainURI = "uddi:" + properties.getProperty("keyDomain") + ":"; if (properties.contains(Property.BUSINESS_KEY)) { this.businessKey = properties.getProperty(Property.BUSINESS_KEY); } else { //using the BusinessKey Template, and the businessName to construct the key this.businessKey = UDDIKeyConvention.getBusinessKey(properties); } this.lang = properties.getProperty(Property.LANG, Property.DEFAULT_LANG); }
From source file:gobblin.runtime.mapreduce.MRJobLauncherTest.java
/** * Byteman test that ensures the {@link MRJobLauncher} successfully cleans up all staging data even * when an exception is thrown in the {@link MRJobLauncher#countersToMetrics(GobblinMetrics)} method. * The {@link BMRule} is to inject an {@link IOException} when the * {@link MRJobLauncher#countersToMetrics(GobblinMetrics)} method is called. *//*w ww .j ava 2s. co m*/ @Test @BMRule(name = "testJobCleanupOnError", targetClass = "gobblin.runtime.mapreduce.MRJobLauncher", targetMethod = "countersToMetrics(GobblinMetrics)", targetLocation = "AT ENTRY", condition = "true", action = "throw new IOException(\"Exception for testJobCleanupOnError\")") public void testJobCleanupOnError() throws IOException { Properties props = loadJobProps(); try { this.jobLauncherTestHelper.runTest(props); Assert.fail("Byteman is not configured properly, the runTest method should have throw an exception"); } catch (Exception e) { // The job should throw an exception, ignore it } finally { this.jobLauncherTestHelper.deleteStateStore(props.getProperty(ConfigurationKeys.JOB_NAME_KEY)); } Assert.assertTrue(props.containsKey(ConfigurationKeys.WRITER_STAGING_DIR)); Assert.assertTrue(props.containsKey(ConfigurationKeys.WRITER_OUTPUT_DIR)); File stagingDir = new File(props.getProperty(ConfigurationKeys.WRITER_STAGING_DIR)); File outputDir = new File(props.getProperty(ConfigurationKeys.WRITER_OUTPUT_DIR)); Assert.assertEquals(FileUtils.listFiles(stagingDir, null, true).size(), 0); if (outputDir.exists()) { Assert.assertEquals(FileUtils.listFiles(outputDir, null, true).size(), 0); } }
From source file:fr.xebia.cloud.amazon.aws.iam.AmazonAwsIamAccountCreator.java
public AmazonAwsIamAccountCreator(Environment environment) { this.environment = Preconditions.checkNotNull(environment); try {//from ww w .j a v a 2 s.c o m keyPairGenerator = KeyPairGenerator.getInstance("RSA", BOUNCY_CASTLE_PROVIDER_NAME); keyPairGenerator.initialize(1024, new SecureRandom()); String credentialsFileName = "AwsCredentials-" + environment.getIdentifier() + ".properties"; InputStream credentialsAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(credentialsFileName); Preconditions.checkNotNull(credentialsAsStream, "File '/" + credentialsFileName + "' NOT found in the classpath"); AWSCredentials awsCredentials = new PropertiesCredentials(credentialsAsStream); iam = new AmazonIdentityManagementClient(awsCredentials); ses = new AmazonSimpleEmailServiceClient(awsCredentials); ec2 = new AmazonEC2Client(awsCredentials); ec2.setEndpoint("ec2.eu-west-1.amazonaws.com"); InputStream smtpPropertiesAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("smtp.properties"); Preconditions.checkNotNull(smtpPropertiesAsStream, "File '/smtp.properties' NOT found in the classpath"); final Properties smtpProperties = new Properties(); smtpProperties.load(smtpPropertiesAsStream); mailSession = Session.getInstance(smtpProperties, null); mailTransport = mailSession.getTransport(); if (smtpProperties.containsKey("mail.username")) { mailTransport.connect(smtpProperties.getProperty("mail.username"), smtpProperties.getProperty("mail.password")); } else { mailTransport.connect(); } try { mailFrom = new InternetAddress(smtpProperties.getProperty("mail.from")); } catch (Exception e) { throw new MessagingException("Exception parsing 'mail.from' from 'smtp.properties'", e); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:com.fluidops.iwb.api.ProviderServiceImpl.java
@Override public void registerProviderClass(String providerClass) throws RemoteException, Exception { Class provider = DynamicScriptingSupport.loadClass(providerClass); Object o = provider.newInstance(); if (o instanceof AbstractFlexProvider) { Properties providersProp = getProvidersProp(); if (providersProp.containsKey(providerClass)) { // If the specified provider already exists, check if it's already enabled if (Boolean.valueOf(providersProp.getProperty(providerClass))) { logger.info("Provider " + providerClass + " is already registered"); return; } else { // If it's not enabled, enable it providersProp.setProperty(providerClass, "true"); }/*w w w . java 2s .c o m*/ } else { // If specified provider doesn't exist, add it and set it to true providersProp.put(providerClass, "true"); } saveProvidersProp(providersProp); } else throw new APIException("Provider class must extend AbstractFlexProvider"); }
From source file:eu.planets_project.tb.impl.data.util.DataHandlerImpl.java
/** * Fetches for a given file (the resource's physical file name on the disk) its * original logical name which is stored within an index. * e.g. ce37d69b-64c0-4476-9040-72512f07bb49.TIF to Test1.TIF * @param sFileRandomNumber the corresponding file name or its logical random number if none is available *///from w ww. j a v a 2s.co m private String getIndexFileEntryName(File sFileRandomNumber) { log.debug("Looking for name of: " + sFileRandomNumber.getAbsolutePath()); if (sFileRandomNumber != null) { try { Properties props = this.getIndex(); if (props.containsKey(sFileRandomNumber.getName())) { //return the corresponding name from the index return props.getProperty(sFileRandomNumber.getName()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } log.warn("Could not find name for File: " + sFileRandomNumber.getName()); //else return the physical file name return sFileRandomNumber.getName(); }
From source file:org.cloudfoundry.identity.uaa.impl.config.YamlProcessor.java
private void process(Map<String, Object> map, MatchCallback callback) { Properties properties = new Properties(); assignProperties(properties, map, null); if (documentMatchers.isEmpty()) { logger.debug("Merging document (no matchers set)" + UaaStringUtils.redactValues(map)); callback.process(properties, map); } else {/*from w w w.ja v a2 s . c o m*/ boolean keyFound = false; boolean valueFound = false; for (Entry<String, String> entry : documentMatchers.entrySet()) { String key = entry.getKey(); String pattern = entry.getValue(); if (properties.containsKey(key)) { keyFound = true; String value = properties.getProperty(key); if (value.matches(pattern)) { logger.debug("Matched document with " + key + "=" + value + " (pattern=/" + pattern + "/): " + UaaStringUtils.redactValues(map)); callback.process(properties, map); valueFound = true; // No need to check for more matches break; } } } if (!keyFound && matchDefault) { logger.debug("Matched document with default matcher: " + UaaStringUtils.redactValues(map)); callback.process(properties, map); } else if (!valueFound) { logger.debug("Unmatched document"); } } }
From source file:org.cloudfoundry.identity.uaa.config.YamlProcessor.java
private void process(Map<String, Object> map, MatchCallback callback) { Properties properties = new Properties(); assignProperties(properties, map, null); if (documentMatchers.isEmpty()) { logger.debug("Merging document (no matchers set)" + UaaStringUtils.hidePasswords(map)); callback.process(properties, map); } else {/*from ww w . j a v a 2s. c om*/ boolean keyFound = false; boolean valueFound = false; for (Entry<String, String> entry : documentMatchers.entrySet()) { String key = entry.getKey(); String pattern = entry.getValue(); if (properties.containsKey(key)) { keyFound = true; String value = properties.getProperty(key); if (value.matches(pattern)) { logger.debug("Matched document with " + key + "=" + value + " (pattern=/" + pattern + "/): " + UaaStringUtils.hidePasswords(map)); callback.process(properties, map); valueFound = true; // No need to check for more matches break; } } } if (!keyFound && matchDefault) { logger.debug("Matched document with default matcher: " + UaaStringUtils.hidePasswords(map)); callback.process(properties, map); } else if (!valueFound) { logger.debug("Unmatched document"); } } }
From source file:org.ala.spatial.web.services.SitesBySpeciesWSControllerTabulated.java
@RequestMapping(value = { "sxs/add", "sxs/sxs/add" }, method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView sxsAdd(HttpServletRequest req, HttpServletResponse resp) throws IOException { String speciesquery = req.getParameter("speciesquery"); String layers = req.getParameter("layers"); String bs = URLEncoder.encode(AlaspatialProperties.getBiocacheWsURL(), "UTF-8"); String gridsize = req.getParameter("gridsize"); String minuncertainty = req.getParameter("minuncertainty") == null ? "" : req.getParameter("minuncertainty"); String maxuncertainty = req.getParameter("maxuncertainty") == null ? "" : req.getParameter("maxuncertainty"); String nulluncertainty = req.getParameter("nulluncertainty") == null ? "false" : req.getParameter("nulluncertainty"); String min = minuncertainty.length() == 0 ? "*" : minuncertainty; String max = maxuncertainty.length() == 0 ? "*" : maxuncertainty; if (nulluncertainty.equals("true")) { speciesquery = "(" + speciesquery + ")%20AND%20coordinate_uncertainty:%5B" + min + "%20TO%20" + max + "%5D"; } else if (minuncertainty.length() + maxuncertainty.length() > 0) { speciesquery = "(" + speciesquery + ")%20AND%20-(coordinate_uncertainty:*%20AND%20-coordinate_uncertainty:%5B" + min + "%20TO%20" + max + "%5D)"; }/*w w w. java 2 s . c om*/ String url = req.getParameter("u"); try { if (url == null) { url = "q=" + speciesquery + "&gridsize=" + gridsize + "&layers=" + layers; } String pth = AlaspatialProperties.getAnalysisWorkingDir() + File.separator + "sxs" + File.separator; initListProperties(); Properties p = new Properties(); p.load(new FileReader(pth + "list.properties")); synchronized (lockProperties) { FileWriter fw = new FileWriter(pth + "list.properties", true); if (!p.containsValue(url)) { for (int i = 1; i < Integer.MAX_VALUE; i++) { if (!p.containsKey(String.valueOf(i))) { fw.write("\n" + i + "=" + url); new File(pth + i).delete(); break; } } } fw.flush(); fw.close(); } for (Entry<Object, Object> entry : p.entrySet()) { if (((String) entry.getValue()).equals(url)) { File f = new File(pth + ((String) entry.getKey())); if (f.exists()) { new File(pth + ((String) entry.getKey())).delete(); } } } run(); } catch (Exception e) { e.printStackTrace(); } return new ModelAndView("redirect:" + AlaspatialProperties.getAlaspatialUrl() + "/sxs"); }