Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:org.apache.hadoop.hive.ql.io.avro.AvroGenericRecordReader.java

/**
 * Attempt to retrieve the reader schema.  We have a couple opportunities
 * to provide this, depending on whether or not we're just selecting data
 * or running with a MR job.//from w w w. ja v  a  2s. co  m
 * @return  Reader schema for the Avro object, or null if it has not been provided.
 * @throws AvroSerdeException
 */
private Schema getSchema(JobConf job, FileSplit split) throws AvroSerdeException, IOException {
    // Inside of a MR job, we can pull out the actual properties
    if (AvroSerdeUtils.insideMRJob(job)) {
        MapWork mapWork = Utilities.getMapWork(job);

        // Iterate over the Path -> Partition descriptions to find the partition
        // that matches our input split.
        for (Map.Entry<String, PartitionDesc> pathsAndParts : mapWork.getPathToPartitionInfo().entrySet()) {
            String partitionPath = pathsAndParts.getKey();
            if (pathIsInPartition(split.getPath(), partitionPath)) {
                if (LOG.isInfoEnabled()) {
                    LOG.info("Matching partition " + partitionPath + " with input split " + split);
                }

                Properties props = pathsAndParts.getValue().getProperties();
                if (props.containsKey(AvroSerdeUtils.SCHEMA_LITERAL)
                        || props.containsKey(AvroSerdeUtils.SCHEMA_URL)) {
                    return AvroSerdeUtils.determineSchemaOrThrowException(job, props);
                } else {
                    return null; // If it's not in this property, it won't be in any others
                }
            }
        }
        if (LOG.isInfoEnabled()) {
            LOG.info("Unable to match filesplit " + split + " with a partition.");
        }
    }

    // In "select * from table" situations (non-MR), we can add things to the job
    // It's safe to add this to the job since it's not *actually* a mapred job.
    // Here the global state is confined to just this process.
    String s = job.get(AvroSerdeUtils.AVRO_SERDE_SCHEMA);
    if (s != null) {
        LOG.info("Found the avro schema in the job: " + s);
        return AvroSerdeUtils.getSchemaFor(s);
    }
    // No more places to get the schema from. Give up.  May have to re-encode later.
    return null;
}

From source file:eu.uqasar.util.UQasarUtil.java

/**
 * Get the temp directory to be used; in case JBoss is used, use 
 * its temp dir, otherwise the user temp.
 * @return/* w w  w . j  a v a2 s .  c  o  m*/
 */
public static String getTempDirPath() {
    String tempDirectory = null;

    Properties systemProp = System.getProperties();
    // In case JBoss is used, use the JBoss temp dir
    if (systemProp.containsKey("jboss.server.temp.dir")) {
        tempDirectory = systemProp.getProperty("jboss.server.temp.dir");
        if (!tempDirectory.endsWith(SEPARATOR)) {
            tempDirectory += SEPARATOR;
        }
    }
    // Otherwise use a temp directory
    else {
        tempDirectory = System.getProperty("java.io.tmpdir");
        if (!tempDirectory.endsWith(SEPARATOR)) {
            tempDirectory += SEPARATOR;
        }
    }

    return tempDirectory;
}

From source file:gobblin.compliance.retention.ComplianceRetentionJob.java

public void initDatasetFinder(Properties properties) throws IOException {
    Preconditions.checkArgument(properties.containsKey(GOBBLIN_COMPLIANCE_DATASET_FINDER_CLASS),
            "Missing required propety " + GOBBLIN_COMPLIANCE_DATASET_FINDER_CLASS);
    String finderClass = properties.getProperty(GOBBLIN_COMPLIANCE_DATASET_FINDER_CLASS);
    this.finder = GobblinConstructorUtils.invokeConstructor(DatasetsFinder.class, finderClass,
            new State(properties));

    Iterator<HiveDataset> datasetsIterator = new HiveDatasetFinder(FileSystem.newInstance(new Configuration()),
            properties).getDatasetsIterator();

    while (datasetsIterator.hasNext()) {
        // Drop partitions from empty tables if property is set, otherwise skip the table
        HiveDataset hiveDataset = datasetsIterator.next();
        List<Partition> partitionsFromDataset = hiveDataset.getPartitionsFromDataset();
        String completeTableName = hiveDataset.getTable().getCompleteName();
        if (!partitionsFromDataset.isEmpty()) {
            this.tableNamesList.add(completeTableName);
            continue;
        }/* ww  w.  ja v a  2 s  .  co m*/
        if (!Boolean.parseBoolean(properties.getProperty(ComplianceConfigurationKeys.SHOULD_DROP_EMPTY_TABLES,
                ComplianceConfigurationKeys.DEFAULT_SHOULD_DROP_EMPTY_TABLES))) {
            continue;
        }
        if (completeTableName.contains(ComplianceConfigurationKeys.TRASH)
                || completeTableName.contains(ComplianceConfigurationKeys.BACKUP)
                || completeTableName.contains(ComplianceConfigurationKeys.STAGING)) {
            this.tablesToDrop.add(hiveDataset);
        }
    }
}

From source file:org.cloudfoundry.reconfiguration.play.StandardPropertySetter.java

private void setDatabaseSpecificProperties(String driverClass, Properties cloudProperties,
        RelationalServiceInfo serviceInfo, String type) {
    System.setProperty(String.format("cloud.services.%s.connection.driver", serviceInfo.getId()), driverClass);

    if (cloudProperties.containsKey(String.format("cloud.services.%s.connection.name", type))) {
        System.setProperty(String.format("cloud.services.%s.connection.driver", type), driverClass);
        System.setProperty(String.format("cloud.services.%s.connection.jdbcUrl", type),
                serviceInfo.getJdbcUrl());
    }/* www.j  av a2 s . com*/
}

From source file:org.apache.nifi.toolkit.cli.impl.command.registry.bucket.DeleteBucket.java

@Override
public OkResult doExecute(final NiFiRegistryClient client, final Properties properties)
        throws IOException, NiFiRegistryException, ParseException {

    final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
    final boolean forceDelete = properties.containsKey(CommandOption.FORCE.getLongName());

    final FlowClient flowClient = client.getFlowClient();
    final List<VersionedFlow> flowsInBucket = flowClient.getByBucket(bucketId);

    if (flowsInBucket != null && flowsInBucket.size() > 0 && !forceDelete) {
        throw new NiFiRegistryException(
                "Bucket is not empty, use --" + CommandOption.FORCE.getLongName() + " to delete");
    } else {//ww w  .  j a va 2s.c o  m
        final BucketClient bucketClient = client.getBucketClient();
        bucketClient.delete(bucketId);
        return new OkResult(getContext().isInteractive());
    }
}

From source file:org.obiba.mica.search.queries.NetworkQuery.java

@Nullable
@Override//from  w  ww. ja  v  a2 s .c  o  m
protected Properties getAggregationsProperties(List<String> filter) {
    Properties properties = getAggregationsProperties(filter, taxonomyService.getNetworkTaxonomy());
    if (!properties.containsKey(JOIN_FIELD))
        properties.put(JOIN_FIELD, "");
    return properties;
}

From source file:org.apache.nifi.toolkit.cli.impl.command.registry.flow.DeleteFlow.java

@Override
public OkResult doExecute(final NiFiRegistryClient client, final Properties properties)
        throws IOException, NiFiRegistryException, ParseException {

    final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID);
    final boolean forceDelete = properties.containsKey(CommandOption.FORCE.getLongName());

    final FlowClient flowClient = client.getFlowClient();
    final VersionedFlow versionedFlow = flowClient.get(flowId);

    final FlowSnapshotClient flowSnapshotClient = client.getFlowSnapshotClient();
    final List<VersionedFlowSnapshotMetadata> snapshotMetadata = flowSnapshotClient.getSnapshotMetadata(flowId);

    if (snapshotMetadata != null && snapshotMetadata.size() > 0 && !forceDelete) {
        throw new NiFiRegistryException(
                "Flow has versions, use --" + CommandOption.FORCE.getLongName() + " to delete");
    } else {//from  ww  w .j a  v  a  2  s.  c  om
        flowClient.delete(versionedFlow.getBucketIdentifier(), versionedFlow.getIdentifier());
        return new OkResult(getContext().isInteractive());
    }
}

From source file:org.apache.stratos.cloud.controller.validate.AWSEC2PartitionValidator.java

@Override
public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException {
    // validate the existence of the region and zone properties.
    try {/*from   w  ww .j av  a 2s  .  c  o m*/
        if (properties.containsKey(Scope.region.toString())) {
            String region = properties.getProperty(Scope.region.toString());

            if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) {

                String msg = "Invalid Partition Detected : " + partitionId + " - Cause: Invalid Region: "
                        + region;
                log.error(msg);
                throw new InvalidPartitionException(msg);
            }

            iaas.isValidRegion(region);

            IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);

            Iaas updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider);
            updatedIaas.setIaasProvider(updatedIaasProvider);

            if (properties.containsKey(Scope.zone.toString())) {
                String zone = properties.getProperty(Scope.zone.toString());
                iaas.isValidZone(region, zone);
                updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone);
                updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider);
                updatedIaas.setIaasProvider(updatedIaasProvider);
            }

            updateOtherProperties(updatedIaasProvider, properties);

            return updatedIaasProvider;

        } else {

            return iaasProvider;
        }
    } catch (Exception ex) {
        String msg = "Invalid Partition Detected : " + partitionId + ". Cause: " + ex.getMessage();
        log.error(msg, ex);
        throw new InvalidPartitionException(msg, ex);
    }

}

From source file:com.adito.input.validators.IntegerValidator.java

public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException {

    // Get the range
    int min = defaultMin;
    try {//from   w w w. j  a  v  a  2s .co m
        if (properties != null && properties.containsKey("minValue"))
            min = Integer.parseInt(properties.getProperty("minValue"));
    } 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 = defaultMax;
    try {
        if (properties != null && properties.containsKey("maxValue"))
            max = Integer.parseInt(properties.getProperty("maxValue"));
    } 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);
    }

    /* We may support replacement variables so
     * to validate we must replace with the minimum value 
     */
    if (properties != null && "true".equalsIgnoreCase(properties.getProperty("replacementVariables"))) {
        Replacer r = new Replacer() {
            public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
                return replacementPattern;
            }
        };
        ReplacementEngine re = new ReplacementEngine();
        re.addPattern(VariableReplacement.VARIABLE_PATTERN, r, String.valueOf(min));
        value = re.replace(value);
    }

    // Validate
    try {
        int i = Integer.parseInt(value);
        if (i < min || i > max) {
            throw new CoreException(ErrorConstants.ERR_INTEGER_OUT_OF_RANGE, ErrorConstants.CATEGORY_NAME,
                    ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null);
        }
    } catch (NumberFormatException nfe) {
        throw new CoreException(ErrorConstants.ERR_NOT_AN_INTEGER, ErrorConstants.CATEGORY_NAME,
                ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null);
    }
}

From source file:coral.CoralHeadServable.java

@Override
public void init(Properties properties, BlockingQueue<Message> loopQueue, Linker linker) {

    shell = (Shell) properties.get("shell");

    if (!properties.containsKey("coral.head.res")) {
        try {/*from www . ja  v  a2s.com*/
            res = File.createTempFile("coral", "server");
            res.delete();
            res.mkdirs();
        } catch (IOException e1) {
            throw new RuntimeException(
                    "problem creating temporary directory for polyp, please specify with coral.polyp.res", e1);
        }
    } else {
        res = new File(properties.getProperty("coral.head.res"), "server_res/");
        res.mkdirs();
    }

    mainfilename = properties.getProperty("coral.head.main", "main.html");

    String sidebarfilename = properties.getProperty("coral.head.sidebar", "servervm/sidebar.html");

    File dir = new File(properties.getProperty("exp.basepath", "./"));
    File sidebarfile = new File(dir, sidebarfilename);

    String sidebartext = "<html><a href='" + CoralUtils.getHostStr() + CoralUtils.SERVER_KEY
            + "/info.vm'>SERVER</a></html>";
    if (sidebarfile.exists()) {
        try {
            sidebartext = new Scanner(sidebarfile).useDelimiter("\\Z").next();
        } catch (FileNotFoundException e) {
            logger.warn("Could not read sidebar file " + sidebarfilename, e);
        }
    }

    try {
        sidebrowser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        logger.warn("Could not instantiate sidebar Browser: ", e);
        throw new RuntimeException("Could not instantiate Browser", e);
    }

    super.setup();

    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));

    sidebrowser.setText(sidebartext);
    sidebrowser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));

    sidebrowser.addLocationListener(getLocationListener());

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 5;
    gridLayout.makeColumnsEqualWidth = true;
    shell.setLayout(gridLayout);

    // Shell shell = new Shell(SWT.NO_TRIM | SWT.ON_TOP);
    // shell.setLayout(new FillLayout());
    // shell.setBounds(Display.getDefault().getPrimaryMonitor().getBounds());

    // shell.setBounds(20,20,1044,788);
    // shell.open();

    // res.mkdirs();

    logger.debug("ready");
}