List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:org.apache.gobblin.scheduler.JobScheduler.java
/** * Schedule Gobblin jobs in general position *//* w w w . j a va 2s . co m*/ private void scheduleGeneralConfiguredJobs() throws ConfigurationException, JobException, IOException { LOG.info("Scheduling configured jobs"); for (Properties jobProps : loadGeneralJobConfigs()) { if (!jobProps.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { // A job without a cron schedule is considered a one-time job jobProps.setProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "true"); } boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false")); scheduleJob(jobProps, runOnce ? new RunOnceJobListener() : new EmailNotificationJobListener()); this.listener.addToJobNameMap(jobProps); } }
From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java
private boolean doRelocation(Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model, ArtifactRepository repository, FileTransaction transaction) throws IOException { Properties properties = v3Model.getProperties(); if (properties.containsKey("relocated.groupId") || properties.containsKey("relocated.artifactId") //$NON-NLS-1$ //$NON-NLS-2$ || properties.containsKey("relocated.version")) //$NON-NLS-1$ {/*ww w . jav a 2 s . c o m*/ String newGroupId = properties.getProperty("relocated.groupId", v3Model.getGroupId()); //$NON-NLS-1$ properties.remove("relocated.groupId"); //$NON-NLS-1$ String newArtifactId = properties.getProperty("relocated.artifactId", v3Model.getArtifactId()); //$NON-NLS-1$ properties.remove("relocated.artifactId"); //$NON-NLS-1$ String newVersion = properties.getProperty("relocated.version", v3Model.getVersion()); //$NON-NLS-1$ properties.remove("relocated.version"); //$NON-NLS-1$ String message = properties.getProperty("relocated.message", ""); //$NON-NLS-1$ //$NON-NLS-2$ properties.remove("relocated.message"); //$NON-NLS-1$ if (properties.isEmpty()) { v3Model.setProperties(null); } writeRelocationPom(v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId, newArtifactId, newVersion, message, repository, transaction); v3Model.setGroupId(newGroupId); v3Model.setArtifactId(newArtifactId); v3Model.setVersion(newVersion); artifact.setGroupId(newGroupId); artifact.setArtifactId(newArtifactId); artifact.setVersion(newVersion); return true; } else { return false; } }
From source file:org.gvnix.dynamic.configuration.roo.addon.config.PropertiesListDynamicConfiguration.java
/** * {@inheritDoc}/*ww w . j a va2 s .c o m*/ */ @Override public void write(DynPropertyList dynProps) { OutputStream outputStream = null; // Get the property files to write from resources String resources = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, ""), ""); List<FileDetails> files = getFiles(resources); for (FileDetails f : files) { try { // Get properties from the file MutableFile file = fileManager.updateFile(f.getCanonicalPath()); Properties props = new Properties(); props.load(file.getInputStream()); for (DynProperty dynProp : dynProps) { // If property belongs to file and exists on file, update it String key = getKeyValue(dynProp.getKey()); if (isPropertyRelatedToFile(dynProp, file)) { if (props.containsKey(key)) { props.put(key, dynProp.getValue()); } else { LOGGER.log(Level.WARNING, "Property key ".concat(dynProp.getKey()) .concat(" to put value not exists on file")); } } } outputStream = file.getOutputStream(); props.store(outputStream, null); } catch (IOException ioe) { throw new IllegalStateException(ioe); } finally { IOUtils.closeQuietly(outputStream); } } }
From source file:datafu.hourglass.jobs.AbstractJob.java
/** * Creates Hadoop configuration using the provided properties. * //ww w .j a v a 2 s . c o m * @param props * @return */ private void updateConfigurationFromProps(Properties props) { Configuration config = getConf(); if (config == null) { config = new Configuration(); } // to enable unit tests to inject configuration if (props.containsKey("test.conf")) { try { byte[] decoded = Base64.decodeBase64(props.getProperty("test.conf")); ByteArrayInputStream byteInput = new ByteArrayInputStream(decoded); DataInputStream inputStream = new DataInputStream(byteInput); config.readFields(inputStream); } catch (IOException e) { throw new RuntimeException(e); } } else { for (String key : props.stringPropertyNames()) { String newKey = key; String value = props.getProperty(key); if (key.toLowerCase().startsWith(HADOOP_PREFIX)) { newKey = key.substring(HADOOP_PREFIX.length()); config.set(newKey, value); } } } }
From source file:org.openremote.server.inventory.DiscoveryService.java
protected Adapter createAdapter(String name, String componentType, UriEndpointComponent component, Properties componentProperties) { LOG.info("Creating adapter for component: " + name); Class<? extends Endpoint> endpointClass = component.getEndpointClass(); String label = componentProperties.containsKey(COMPONENT_LABEL) ? componentProperties.get(COMPONENT_LABEL).toString() : null;// w ww . ja va 2s .co m if (label == null) throw new RuntimeException("Component missing label property: " + name); String discoveryEndpoint = componentProperties.containsKey(COMPONENT_DISCOVERY_ENDPOINT) ? componentProperties.get(COMPONENT_DISCOVERY_ENDPOINT).toString() : null; Adapter adapter = new Adapter(label, name, componentType, discoveryEndpoint); ComponentConfiguration config = component.createComponentConfiguration(); ObjectNode properties = JSON.createObjectNode(); for (Map.Entry<String, ParameterConfiguration> configEntry : config.getParameterConfigurationMap() .entrySet()) { try { Field field = endpointClass.getDeclaredField(configEntry.getKey()); if (field.isAnnotationPresent(UriParam.class)) { UriParam uriParam = field.getAnnotation(UriParam.class); ObjectNode property = JSON.createObjectNode(); if (uriParam.label().length() > 0) { property.put("label", uriParam.label()); } if (uriParam.description().length() > 0) { property.put("description", uriParam.description()); } if (uriParam.defaultValue().length() > 0) { property.put("defaultValue", uriParam.defaultValue()); } if (uriParam.defaultValueNote().length() > 0) { property.put("defaultValueNote", uriParam.defaultValueNote()); } if (String.class.isAssignableFrom(field.getType())) { property.put("type", "string"); } else if (Long.class.isAssignableFrom(field.getType())) { property.put("type", "long"); } else if (Integer.class.isAssignableFrom(field.getType())) { property.put("type", "integer"); } else if (Double.class.isAssignableFrom(field.getType())) { property.put("type", "double"); } else if (Boolean.class.isAssignableFrom(field.getType())) { property.put("type", "boolean"); } else { throw new RuntimeException( "Unsupported type of adapter endpoint property '" + name + "': " + field.getType()); } if (field.isAnnotationPresent(NotNull.class)) { for (Class<?> group : field.getAnnotation(NotNull.class).groups()) { if (ValidationGroupDiscovery.class.isAssignableFrom(group)) { property.put("required", true); break; } } } String propertyName = uriParam.name().length() != 0 ? uriParam.name() : field.getName(); LOG.debug("Adding adapter property '" + propertyName + "': " + property); properties.set(propertyName, property); } } catch (NoSuchFieldException ex) { // Ignoring config parameter if there is no annotated field on endpoint class // TODO: Inheritance of endpoint classes? Do we care? } } try { adapter.setProperties(JSON.writeValueAsString(properties)); } catch (Exception ex) { throw new RuntimeException(ex); } return adapter; }
From source file:com.virtualparadigm.packman.processor.JPackageManager.java
public static Properties validate(File tempDir) { logger.info("PackageManager::validate()"); // INVALID (return empty properties) IF: // package.properties not found // package properties does not contain name and version // found installed version greater than package to be installed Properties packageProperties = new Properties(); InputStream packagePropInputStream = null; try {//from w w w . ja va 2 s. c o m packagePropInputStream = new FileInputStream(new File(tempDir.getAbsolutePath() + "/" + JPackageManager.METADATA_DIR_NAME + "/" + JPackageManager.PACKAGE_PROPERTIES_FILE_NAME)); packageProperties.load(packagePropInputStream); logger.info(" loaded package properties."); } catch (IOException ioe) { logger.error("", ioe); } finally { if (packagePropInputStream != null) { try { packagePropInputStream.close(); } catch (Exception e) { logger.error("", e); } } } if (packageProperties.containsKey(JPackageManager.PACKAGE_NAME_KEY) && packageProperties.containsKey(JPackageManager.PACKAGE_VERSION_KEY)) { VersionNumber installedVersionNumber = null; Package installPackage = JPackageManager .findInstalledPackage(packageProperties.getProperty(PACKAGE_NAME_KEY)); if (installPackage == null) { installedVersionNumber = new VersionNumber("0"); } else { installedVersionNumber = installPackage.getVersionNumber(); } if (installedVersionNumber.compareTo( new VersionNumber(packageProperties.getProperty(JPackageManager.PACKAGE_VERSION_KEY))) >= 0) { logger.info(" installed version is more recent."); //installed version greater than or equal to package to install packageProperties = null; } } else { logger.info(" could not find package.name or package.version values for new package."); //return null to signify error/invalid packageProperties = null; } return packageProperties; }
From source file:org.accada.reader.hal.impl.sim.BatchSimulator.java
/** * initializes the fields and starts the simulator. * * @throws SimulatorException if the event input file could not be opened. *//*from w ww .j a va 2 s. c o m*/ private void initSimulator() throws SimulatorException { // load properties from properties file Properties props = new Properties(); try { props.load(this.getClass().getResourceAsStream(PROPERTIES_FILE_LOCATION)); } catch (IOException e) { throw new SimulatorException("Could not load the properties from properties file."); } // check properties if (!props.containsKey("batchfile")) { throw new SimulatorException("Property 'batchfile' not found."); } if (!props.containsKey("iterations")) { throw new SimulatorException("Property 'iterations' not found."); } // get properties String file = props.getProperty("batchfile"); cycles = Long.parseLong(props.getProperty("iterations")); eventFile = new File(file); rfidThread = null; threadRunning = false; stopRequested = false; try { // tries to open file FileReader in = new FileReader(eventFile); in.close(); // start simulator thread start(); } catch (IOException e) { throw new SimulatorException("Cannot open event file '" + file + "': " + e); } }
From source file:org.apache.zeppelin.hopshive.HopsHiveInterpreter.java
@Override public void open() { for (String propertyKey : property.stringPropertyNames()) { logger.debug("propertyKey: {}", propertyKey); String[] keyValue = propertyKey.split("\\.", 2); if (2 == keyValue.length) { logger.debug("key: {}, value: {}", keyValue[0], keyValue[1]); Properties prefixProperties; if (basePropretiesMap.containsKey(keyValue[0])) { prefixProperties = basePropretiesMap.get(keyValue[0]); } else { prefixProperties = new Properties(); basePropretiesMap.put(keyValue[0].trim(), prefixProperties); }// w ww . jav a 2s . c o m prefixProperties.put(keyValue[1].trim(), property.getProperty(propertyKey)); } } Set<String> removeKeySet = new HashSet<>(); for (String key : basePropretiesMap.keySet()) { if (!COMMON_KEY.equals(key)) { Properties properties = basePropretiesMap.get(key); if (!properties.containsKey(URL_KEY)) { logger.error("{} will be ignored. {}.{} is mandatory.", key, key, URL_KEY); removeKeySet.add(key); } } } for (String key : removeKeySet) { basePropretiesMap.remove(key); } logger.debug("HopsHive PropretiesMap: {}", basePropretiesMap); setMaxLineResults(); }
From source file:com.googlecode.janrain4j.conf.PropertyConfig.java
private void loadProperties(URL resource) { Properties properties = loadSystemProperties(); try {//from w w w . j av a2 s . c om if (resource == null) { log.warn("Unable to find janrain4j properties file"); } else { properties.load(resource.openStream()); log.info("Successfully loaded janrain4j properties file"); } } catch (IOException e) { log.error("Unable to load janrain4j properties file", e); } if (properties.containsKey(API_KEY_KEY)) { this.apiKey(properties.getProperty(API_KEY_KEY)); } if (properties.containsKey(APPLICATION_ID_KEY)) { this.applicationID(properties.getProperty(APPLICATION_ID_KEY)); } if (properties.containsKey(APPLICATION_DOMAIN_KEY)) { this.applicationDomain(properties.getProperty(APPLICATION_DOMAIN_KEY)); } if (properties.containsKey(TOKEN_URL_KEY)) { this.tokenUrl(properties.getProperty(TOKEN_URL_KEY)); } if (properties.containsKey(LANGUAGE_PREFERENCE_KEY)) { this.languagePreference(properties.getProperty(LANGUAGE_PREFERENCE_KEY)); } if (properties.containsKey(PROXY_HOST_KEY)) { this.proxyHost(properties.getProperty(PROXY_HOST_KEY)); } if (properties.containsKey(PROXY_PORT_KEY)) { this.proxyPort(parseInt(properties.getProperty(PROXY_PORT_KEY))); } if (properties.containsKey(PROXY_USERNAME_KEY)) { this.proxyUsername(properties.getProperty(PROXY_USERNAME_KEY)); } if (properties.containsKey(PROXY_PASSWORD_KEY)) { this.proxyPassword(properties.getProperty(PROXY_PASSWORD_KEY)); } if (properties.containsKey(CONNECT_TIMEOUT_KEY)) { this.connectTimeout(parseInt(properties.getProperty(CONNECT_TIMEOUT_KEY))); } if (properties.containsKey(READ_TIMEOUT_KEY)) { this.readTimeout(parseInt(properties.getProperty(READ_TIMEOUT_KEY))); } if (properties.containsKey(SET_STATUS_PROVIDER_NAMES_KEY)) { StringTokenizer st = new StringTokenizer(properties.getProperty(SET_STATUS_PROVIDER_NAMES_KEY), ",;|"); List<String> providerNames = new ArrayList<String>(); while (st.hasMoreTokens()) { providerNames.add(st.nextToken().trim()); } this.setStatusProviderNames(providerNames); } if (properties.containsKey(ACTIVITY_PROVIDER_NAMES_KEY)) { StringTokenizer st = new StringTokenizer(properties.getProperty(ACTIVITY_PROVIDER_NAMES_KEY), ",;|"); List<String> providerNames = new ArrayList<String>(); while (st.hasMoreTokens()) { providerNames.add(st.nextToken().trim()); } this.activityProviderNames(providerNames); } }
From source file:org.archive.hadoop.pig.HBaseStorage.java
@Override public void setStoreLocation(String location, Job job) throws IOException { if (location.startsWith("hbase://")) { job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, location.substring(8)); } else {//from w w w . j a v a2 s . c o m job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, location); } Properties props = UDFContext.getUDFContext().getUDFProperties(getClass(), new String[] { contextSignature }); if (!props.containsKey(contextSignature + "_schema")) { props.setProperty(contextSignature + "_schema", ObjectSerializer.serialize(schema_)); } m_conf = HBaseConfiguration.addHbaseResources(job.getConfiguration()); }