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:edu.kit.dama.mdm.content.mets.MetsMetadataExtractor.java

@Override
public final void configure(Properties pProperties) throws PropertyValidationException, ConfigurationException {
    LOGGER.debug("Configuring mets metadata extractor named {}", getName());
    communityDmdSectionId = pProperties.getProperty(COMMUNITY_DMD_SECTION_ID);
    communityMetadataId = pProperties.getProperty(COMMUNITY_METADATA_SCHEMA_ID);
    communityMDType = pProperties.getProperty(COMMUNITY_MD_TYPE_ID);

    if (communityDmdSectionId == null || communityMetadataId == null || communityMDType == null) {
        throw new ConfigurationException(
                "Missing mandatory properties detected. Unable to instantiate metadata extractor.");
    }/*from  w w  w.  j  av  a  2 s .  c  o m*/

    LOGGER.debug("Performing extractor-specific configuration.");
    for (String pluginKey : extractorMap.keySet()) {
        IMetsTypeExtractor plugin = extractorMap.get(pluginKey);
        LOGGER.debug("Check for plugin '{}'.", plugin.getName());
        if (pProperties.containsKey(pluginKey)) {
            LOGGER.debug("Property for plugin '{}' exists.", plugin.getName());
            if (validatePluginString(pluginKey, pProperties.getProperty(pluginKey))) {
                LOGGER.debug("Add plugin '{}'!", plugin.getName());
                additionalExtractors.add(plugin);
            }
        }
    }
    configureExtractor(pProperties);
}

From source file:org.broad.igv.feature.genome.GenomeManager.java

/**
 * Gets a list of all the locally cached genome archive files that
 * IGV knows about./* w ww . j  a v  a2 s  . c o m*/
 *
 * @return LinkedHashSet<GenomeListItem>
 * @throws IOException
 * @see GenomeListItem
 */
private List<GenomeListItem> getCachedGenomeArchiveList() throws IOException {

    if (cachedGenomeArchiveList == null) {
        cachedGenomeArchiveList = new LinkedList<GenomeListItem>();

        if (!DirectoryManager.getGenomeCacheDirectory().exists()) {
            return cachedGenomeArchiveList;
        }

        File[] files = DirectoryManager.getGenomeCacheDirectory().listFiles();
        for (File file : files) {

            if (file.isDirectory()) {
                continue;
            }

            if (!file.getName().toLowerCase().endsWith(Globals.GENOME_FILE_EXTENSION)) {
                continue;
            }

            ZipFile zipFile = null;
            FileInputStream fis = null;
            ZipInputStream zipInputStream = null;
            try {

                zipFile = new ZipFile(file);
                fis = new FileInputStream(file);
                zipInputStream = new ZipInputStream(new BufferedInputStream(fis));

                ZipEntry zipEntry = zipFile.getEntry(Globals.GENOME_ARCHIVE_PROPERTY_FILE_NAME);
                if (zipEntry == null) {
                    continue; // Should never happen
                }

                InputStream inputStream = zipFile.getInputStream(zipEntry);
                Properties properties = new Properties();
                properties.load(inputStream);

                int version = 0;
                if (properties.containsKey(Globals.GENOME_ARCHIVE_VERSION_KEY)) {
                    try {
                        version = Integer.parseInt(properties.getProperty(Globals.GENOME_ARCHIVE_VERSION_KEY));
                    } catch (Exception e) {
                        log.error("Error parsing genome version: " + version, e);
                    }
                }

                GenomeListItem item = new GenomeListItem(
                        properties.getProperty(Globals.GENOME_ARCHIVE_NAME_KEY), file.getAbsolutePath(),
                        properties.getProperty(Globals.GENOME_ARCHIVE_ID_KEY));
                cachedGenomeArchiveList.add(item);
            } catch (ZipException ex) {
                log.error("\nZip error unzipping cached genome.", ex);
                try {
                    file.delete();
                    zipInputStream.close();
                } catch (Exception e) {
                    //ignore exception when trying to delete file
                }
            } catch (IOException ex) {
                log.warn("\nIO error unzipping cached genome.", ex);
                try {
                    file.delete();
                } catch (Exception e) {
                    //ignore exception when trying to delete file
                }
            } finally {
                try {
                    if (zipInputStream != null) {
                        zipInputStream.close();
                    }
                    if (zipFile != null) {
                        zipFile.close();
                    }
                    if (fis != null) {
                        fis.close();
                    }
                } catch (IOException ex) {
                    log.warn("Error closing genome zip stream!", ex);
                }
            }
        }
    }
    return cachedGenomeArchiveList;
}

From source file:org.dcm4chee.proxy.forward.ForwardFiles.java

private void addFileToFwdTaskMap(ProxyAEExtension proxyAEE, String calledAET, File file,
        HashMap<String, ForwardTask> map) throws IOException {
    Properties prop = InfoFileUtils.getFileInfoProperties(proxyAEE, file);
    String callingAET = prop.containsKey("use-calling-aet") ? prop.getProperty("use-calling-aet")
            : prop.getProperty("source-aet");
    String cuid = prop.getProperty("sop-class-uid");
    String tsuid = prop.getProperty("transfer-syntax-uid");
    ForwardTask forwardTask = map.get(callingAET);
    if (forwardTask == null) {
        LOG.debug("Creating new forward task for Calling AET {} and Called AET {}", callingAET, calledAET);
        forwardTask = new ForwardTask(callingAET, calledAET);
        map.put(callingAET, forwardTask);
    } else {/*from  www  . j a  va 2  s.  c  om*/
        LOG.debug("Loaded forward task for Calling AET {} and Called AET {}", callingAET,
                forwardTask.getAAssociateRQ().getCalledAET());
    }
    LOG.debug(
            "Add file {} to forward task for Calling AET {} and Called AET {} with SOP Class UID = {} and Transfer Syntax UID = {}",
            new Object[] { file.getPath(), callingAET, forwardTask.getAAssociateRQ().getCalledAET(), cuid,
                    tsuid });
    forwardTask.addFile(file, cuid, tsuid);
}

From source file:org.alfresco.reporting.action.executer.ReportContainerExecutor.java

private void processReport(final ReportTemplate report, final ReportingContainer reportingContainer,
        final ReportingRoot reportingRoot) {
    Properties keyValues = new Properties();

    if (logger.isDebugEnabled())
        logger.debug("enter processReport, report=" + report.getName());
    String targetPath = report.getTargetPath();
    Properties targetQueries = reportingRoot.getTargetQueries();

    // 1. Determine/get/create target Path
    //    Lets see if there is a relative distribution by Site
    if (targetPath != null) {
        targetPath = targetPath.trim();//from   w w w.j  av  a 2 s  . c  o m
        if ((targetPath.indexOf("${") == 0) && (targetPath.indexOf("}") > -1)) {
            // 1a. it is a distribution by Site or other placeholder
            logger.debug("processReportable: it is a distribution by container");

            // get the target container query key
            String placeHolder = targetPath.substring(2, targetPath.indexOf("}"));
            String relativePath = targetPath.substring(targetPath.indexOf("}") + 1);

            relativePath = processDateElementsInPath(relativePath);

            logger.debug("  placeholder:   " + placeHolder);
            logger.debug("  relative path: " + relativePath);

            if (placeHolder != null) {

                if (targetQueries.containsKey(placeHolder)) {
                    // execute Lucene query. For each result find node.
                    //   For each node, append relative path
                    //     get or create this path
                    //       execute ReportExecuter against each of these end nodes (in proper output format)
                    logger.debug("processReport: Processing with placeholder: " + placeHolder);
                    String placeHolderQuery = targetQueries.getProperty(placeHolder);
                    String searchLanguage = reportingHelper
                            .getSearchLanguage(reportingRoot.getRootQueryLanguage());

                    logger.debug("processReport: query2=" + placeHolderQuery + "(" + searchLanguage + ")");

                    ResultSet placeHolderResults = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
                            searchLanguage, placeHolderQuery);

                    // cycle the resultset of containers
                    for (ResultSetRow placeHolderRow : placeHolderResults) {
                        final NodeRef targetRootRef = placeHolderRow.getChildAssocRef().getChildRef();

                        logger.debug("Found targetRoot: "
                                + nodeService.getProperty(targetRootRef, ContentModel.PROP_NAME));

                        // Introduce a storageNodeRef. This is used if you do a query against 
                        // persons. The resulting report will be stored in the UserHome space.
                        // The value substitution will however be executed against the Person object.
                        NodeRef storageNodeRef = targetRootRef;
                        logger.debug("processReport: storageNodeRef before=" + storageNodeRef);

                        try {
                            // if a Person object is found, replace it by its HomeFolder. For the best fun!
                            if (nodeService.getType(targetRootRef).equals(ContentModel.TYPE_PERSON)) {
                                logger.debug("processReport: The value="
                                        + nodeService.getProperty(targetRootRef, ContentModel.PROP_HOMEFOLDER));

                                if (nodeService.getProperty(targetRootRef,
                                        ContentModel.PROP_HOMEFOLDER) != null) {
                                    logger.debug(
                                            "processReport: createGetRepositoryPath: SWAPPING Person for UserHome");
                                    storageNodeRef = (NodeRef) nodeService.getProperty(targetRootRef,
                                            ContentModel.PROP_HOMEFOLDER);
                                    logger.debug(
                                            "processReport: createGetRepositoryPath: storageNodeRef after swap="
                                                    + storageNodeRef);
                                } else {
                                    logger.debug(
                                            "processReport: createGetRepositoryPath: ow boy, no UserHome available for user "
                                                    + nodeService.getProperty(targetRootRef,
                                                            ContentModel.PROP_USERNAME));
                                    throw new ReportingException("No UserHome found for user " + nodeService
                                            .getProperty(targetRootRef, ContentModel.PROP_USERNAME));
                                }
                            } else {
                                logger.debug("createGetRepositoryPath: no SWAPPING");
                            }
                        } catch (ReportingException re) {
                            logger.fatal("processReport: User without a UserHome... Silent ignore");
                        }
                        logger.debug(
                                "processReport: processReportstorageNodeRef fully after=" + storageNodeRef);

                        // keyValues now contains the keys and the related short-form qnames
                        keyValues = report.getSubstitution();

                        logger.debug("processReport: initial keyValues = " + keyValues);

                        // process of *replacing* the short-form qnames into actual 
                        // node-property values
                        Enumeration keys = keyValues.keys();
                        while (keys.hasMoreElements()) {
                            final String key = (String) keys.nextElement();
                            final String value = keyValues.getProperty(key, "");
                            logger.debug("Initial key=value; " + key + "=" + value);

                            if (value.contains(":") && !"".equals(value)) {
                                // system property
                                final QName property = reportingHelper.replaceShortQNameIntoLong(value);
                                logger.debug("processReport: QName=" + property);
                                logger.debug("processReport: key=" + key + " value="
                                        + nodeService.getProperty(targetRootRef, property));

                                final String propertyValue = nodeService.getProperty(targetRootRef, property)
                                        .toString();
                                logger.debug("processReport: propertyValue=" + propertyValue);
                                keyValues.setProperty(key, propertyValue);
                            } else {
                                // ordinary property
                                keyValues.setProperty(key, value);
                                logger.debug("processReport: key=" + key + " value=" + value + " targetRootRef="
                                        + targetRootRef);
                            } // end if/else
                        } // end while
                        logger.debug("processReport: final keyValues = " + keyValues);

                        final NodeRef targetRef = createGetRepositoryPath(storageNodeRef, relativePath);

                        logger.debug("processReport: Found full path: " + nodeService.getPath(targetRef));
                        logger.debug("processReport: keyValues = " + keyValues);
                        createExecuteReport(targetRef, report, keyValues);

                    } // end for ResultSetRow

                } else {
                    // we cannot deal with this unknown placeholder.
                    // silently let go?!
                    logger.warn("Cannot deal with placeholder: " + placeHolder);

                } // end if/else targetQueries.containsKey
            } // end if matcher.find

        } else {
            // 1b. it is a single fixed path. Start at companyhome, and find your way in
            //NodeRef targetRef = createGetRepositoryPath(targetRootRef, relativePath);

            // execute ReportExecuter against each of these end nodes (in proper output format)

        }
    } // end if targetPath !=null

    if ((report.getTargetNode() != null) && (!"".equals(report.getTargetNode()))) {
        NodeRef newTarget = null;
        // create option to concatinate targetPath to targetNode
        if ((report.getTargetPath() != null) && (!"".equals(report.getTargetPath()))) {
            final String relativePath = processDateElementsInPath(report.getTargetPath());
            newTarget = createGetRepositoryPath(report.getTargetNode(), relativePath);
        } else {
            newTarget = report.getTargetNode();
        }
        logger.debug("executing fixed output path");
        logger.debug("  report    : " + report.getName());
        logger.debug("  targetNode: " + newTarget);
        // keyValues now contains the keys and the related short-form qnames
        keyValues = report.getSubstitution();

        logger.debug("processReport: initial keyValues = " + keyValues);

        // process of replacing the short-form qnames into actual 

        // node-property values
        Enumeration keys = keyValues.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String value = keyValues.getProperty(key, "");

            // ordinary property
            keyValues.setProperty(key, value);
            logger.debug("processReport: key=" + key + " value=" + value);
        }
        logger.debug("processReport: final keyValues = " + keyValues);

        createExecuteReport(newTarget, report, keyValues);
    } // end if targetPath != null

    if (logger.isDebugEnabled())
        logger.debug("exit processReportable");
}

From source file:org.apache.geode.management.internal.cli.commands.ConnectCommand.java

Result httpConnect(Properties gfProperties, String url, boolean skipSslVerification) {
    Gfsh gfsh = getGfsh();//from  www  . j a v  a 2  s .c  o  m
    try {
        SSLConfig sslConfig = SSLConfigurationFactory.getSSLConfigForComponent(gfProperties,
                SecurableCommunicationChannel.WEB);
        if (sslConfig.isEnabled()) {
            configureHttpsURLConnection(sslConfig, skipSslVerification);
            if (url.startsWith("http:")) {
                url = url.replace("http:", "https:");
            }
        }

        // authentication check will be triggered inside the constructor
        HttpOperationInvoker operationInvoker = new HttpOperationInvoker(gfsh, url, gfProperties);

        gfsh.setOperationInvoker(operationInvoker);

        LogWrapper.getInstance()
                .info(CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, operationInvoker.toString()));
        return ResultBuilder.createInfoResult(
                CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, operationInvoker.toString()));

    } catch (SecurityException | AuthenticationFailedException e) {
        // if it's security exception, and we already sent in username and password, still returns the
        // connection error
        if (gfProperties.containsKey(ResourceConstants.USER_NAME)) {
            return handleException(e);
        }

        // otherwise, prompt for username and password and retry the connection
        gfProperties.setProperty(UserInputProperty.USERNAME.getKey(),
                UserInputProperty.USERNAME.promptForAcceptableValue(gfsh));
        gfProperties.setProperty(UserInputProperty.PASSWORD.getKey(),
                UserInputProperty.PASSWORD.promptForAcceptableValue(gfsh));
        return httpConnect(gfProperties, url, skipSslVerification);
    } catch (Exception e) {
        // all other exceptions, just logs it and returns a connection error
        return handleException(e);
    } finally {
        Gfsh.redirectInternalJavaLoggers();
    }
}

From source file:org.dcm4chee.proxy.forward.ForwardFiles.java

private void forwardScheduledNAction(ProxyAEExtension proxyAEE, String calledAET, File[] files)
        throws IOException {
    for (File file : files) {
        Properties prop = InfoFileUtils.getFileInfoProperties(proxyAEE, file);
        String callingAET = prop.containsKey("use-calling-aet") ? prop.getProperty("use-calling-aet")
                : prop.getProperty("source-aet");
        try {/*from w  w  w . j a  va2s  .  co m*/
            DicomInputStream in = new DicomInputStream(file);
            Attributes attrs = in.readDataset(-1, -1);
            if (pendingCStoreFileForwarding(proxyAEE, calledAET, attrs))
                continue;

            AAssociateRQ rq = new AAssociateRQ();
            rq.addPresentationContext(new PresentationContext(1, UID.StorageCommitmentPushModelSOPClass,
                    UID.ImplicitVRLittleEndian));
            rq.addRoleSelection(new RoleSelection(prop.getProperty("sop-class-uid"), true, true));
            rq.setCallingAET(callingAET);
            rq.setCalledAET(calledAET);
            Association asInvoked = null;
            try {
                asInvoked = proxyAEE.getApplicationEntity().connect(aeCache.findApplicationEntity(calledAET),
                        rq);
                if (asInvoked.isReadyForDataTransfer()) {
                    forwardScheduledNAction(proxyAEE, asInvoked, file, prop, attrs);
                } else {
                    renameFile(proxyAEE, RetryObject.ConnectionException.getSuffix(), file, calledAET, prop);
                }
            } finally {
                in.close();
                if (asInvoked != null) {
                    try {
                        asInvoked.waitForOutstandingRSP();
                        asInvoked.release();
                    } catch (InterruptedException e) {
                        LOG.error(asInvoked + ": unexpected exception: " + e.getMessage());
                        if (LOG.isDebugEnabled())
                            e.printStackTrace();
                    } catch (IOException e) {
                        LOG.error(asInvoked + ": failed to release association: " + e.getMessage());
                        if (LOG.isDebugEnabled())
                            e.printStackTrace();
                    }
                }
            }
        } catch (InterruptedException e) {
            LOG.error(e.getMessage());
            renameFile(proxyAEE, RetryObject.ConnectionException.getSuffix(), file, calledAET, prop);
        } catch (IncompatibleConnectionException e) {
            LOG.error(e.getMessage());
            renameFile(proxyAEE, RetryObject.IncompatibleConnectionException.getSuffix(), file, calledAET,
                    prop);
        } catch (ConfigurationException e) {
            LOG.error(e.getMessage());
            renameFile(proxyAEE, RetryObject.ConfigurationException.getSuffix(), file, calledAET, prop);
        } catch (IOException e) {
            LOG.error(e.getMessage());
            renameFile(proxyAEE, RetryObject.ConnectionException.getSuffix(), file, calledAET, prop);
        } catch (GeneralSecurityException e) {
            LOG.error(e.getMessage());
            renameFile(proxyAEE, RetryObject.GeneralSecurityException.getSuffix(), file, calledAET, prop);
        }
    }
}

From source file:com.couchbase.CBConnection.java

public CBConnection(String url, Properties props) throws SQLException {
    try {// w  w w  .j a v  a2  s. c om
        String connectionURL;

        if (props.containsKey(ConnectionParameters.ENABLE_SSL)
                && props.getProperty(ConnectionParameters.ENABLE_SSL).equals("true")) {
            logger.trace("Enabling SSL connection");
            connectionURL = HTTPS + url.substring(14);

        } else {
            logger.trace("Normal http connection");
            connectionURL = HTTP + url.substring(14);
        }

        List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(connectionURL), "UTF-8");

        for (NameValuePair param : parameters) {
            props.put(param.getName(), param.getValue());
        }
        protocol = new ProtocolImpl(connectionURL, props);
        protocol.connect();
        connected.set(true);
    } catch (Exception ex) {
        logger.error("Error opening connection for {} exception {}", url, ex.getMessage());
        throw new SQLException("Error opening connection", ex.getCause());
    }
}

From source file:org.dcm4chee.proxy.forward.ForwardFiles.java

protected void forwardScheduledMPPS(ProxyAEExtension proxyAEE, File[] files, String destinationAETitle,
        String protocol) throws IOException {
    for (File file : files) {
        Properties prop = InfoFileUtils.getFileInfoProperties(proxyAEE, file);
        String callingAET = prop.containsKey("use-calling-aet") ? prop.getProperty("use-calling-aet")
                : prop.getProperty("source-aet");
        try {/*  ww  w .ja  va2 s  . c  o  m*/
            if (protocol == "nset" && pendingNCreateForwarding(proxyAEE, destinationAETitle, file)) {
                String prevFilePath = file.getPath();
                File dst = new File(prevFilePath.substring(0, prevFilePath.length() - 4));
                if (file.renameTo(dst))
                    LOG.debug("{} has pending N-CREATE-RQ, rename to {}", prevFilePath, dst);
                else {
                    LOG.error("Error renaming {} to {}.", prevFilePath, dst);
                }
                continue;
            }
            AAssociateRQ rq = new AAssociateRQ();
            rq.addPresentationContext(new PresentationContext(1, UID.ModalityPerformedProcedureStepSOPClass,
                    UID.ExplicitVRLittleEndian));
            rq.setCallingAET(callingAET);
            rq.setCalledAET(destinationAETitle);
            Association as = proxyAEE.getApplicationEntity()
                    .connect(aeCache.findApplicationEntity(destinationAETitle), rq);
            try {
                if (as.isReadyForDataTransfer()) {
                    Attributes fmi = readFileMetaInformation(file);
                    forwardScheduledMPPS(proxyAEE, as, file, fmi, protocol, prop);
                } else {
                    renameFile(proxyAEE, RetryObject.ConnectionException.getSuffix(), file, destinationAETitle,
                            prop);
                }
            } finally {
                if (as != null) {
                    try {
                        as.waitForOutstandingRSP();
                        as.release();
                    } catch (InterruptedException e) {
                        LOG.error(as + ": unexpected exception: " + e.getMessage());
                        if (LOG.isDebugEnabled())
                            e.printStackTrace();
                    } catch (IOException e) {
                        LOG.error(as + ": failed to release association: " + e.getMessage());
                        if (LOG.isDebugEnabled())
                            e.printStackTrace();
                    }
                }
            }
        } catch (IOException e) {
            LOG.error("Error connecting to {}: {} ", destinationAETitle, e.getMessage());
            renameFile(proxyAEE, RetryObject.ConnectionException.getSuffix(), file, destinationAETitle, prop);
        } catch (InterruptedException e) {
            LOG.error("Connection exception: " + e.getMessage());
            renameFile(proxyAEE, RetryObject.ConnectionException.getSuffix(), file, destinationAETitle, prop);
        } catch (IncompatibleConnectionException e) {
            LOG.error("Incompatible connection: " + e.getMessage());
            renameFile(proxyAEE, RetryObject.IncompatibleConnectionException.getSuffix(), file,
                    destinationAETitle, prop);
        } catch (ConfigurationException e) {
            LOG.error("Unable to load configuration: " + e.getMessage());
            renameFile(proxyAEE, RetryObject.ConfigurationException.getSuffix(), file, destinationAETitle,
                    prop);
        } catch (GeneralSecurityException e) {
            LOG.error("Failed to create SSL context: " + e.getMessage());
            renameFile(proxyAEE, RetryObject.GeneralSecurityException.getSuffix(), file, destinationAETitle,
                    prop);
        }
    }
}

From source file:org.apache.falcon.workflow.engine.OozieWorkflowEngine.java

@Override
public void reRun(String cluster, String jobId, Properties props, boolean isForced) throws FalconException {

    OozieClient client = OozieClientFactory.get(cluster);
    try {/*from w w w .  jav a2  s  .  c  o m*/
        WorkflowJob jobInfo = client.getJobInfo(jobId);
        Properties jobprops = OozieUtils.toProperties(jobInfo.getConf());
        if (props != null) {
            jobprops.putAll(props);
        }
        //if user has set any of these oozie rerun properties then force rerun flag is ignored
        if (!jobprops.containsKey(OozieClient.RERUN_FAIL_NODES)
                && !jobprops.containsKey(OozieClient.RERUN_SKIP_NODES)) {
            jobprops.put(OozieClient.RERUN_FAIL_NODES, String.valueOf(!isForced));
        }
        jobprops.remove(OozieClient.COORDINATOR_APP_PATH);
        jobprops.remove(OozieClient.BUNDLE_APP_PATH);
        client.reRun(jobId, jobprops);
        assertStatus(cluster, jobId, Job.Status.RUNNING);
        LOG.info("Rerun job {} on cluster {}", jobId, cluster);
    } catch (Exception e) {
        LOG.error("Unable to rerun workflows", e);
        throw new FalconException(e);
    }
}

From source file:com.elasticgrid.amazon.boot.Bootstrapper.java

public Bootstrapper() throws IOException, EC2Exception {
    // retrieve EC2 launch parameters
    Properties launchParameters = fetchLaunchParameters();
    if (launchParameters.getProperty(LAUNCH_PARAMETER_CLUSTER_NAME) == null) {
        System.err.println("No cluster name given. Assuming 'elastic-grid' as cluster name.");
        launchParameters.setProperty(LAUNCH_PARAMETER_CLUSTER_NAME, "elastic-grid");
    }//from   ww w. j  a  v a  2s.  c  o m
    Properties egParameters = translateProperties(launchParameters);

    // save configuration into an Elastic Grid configuration file
    File file = saveConfiguration(egParameters);
    System.out.printf("Elastic Grid configuration file generated in '%s'\n", file.getAbsolutePath());

    String securityGroups = FileUtils.readFileToString(new File("/tmp/security-groups"));
    System.out.printf("Security groups for this EC2 instances are '%s'\n", securityGroups);
    String profile = "monitor-agent";
    boolean hasMonitor = securityGroups.contains(Discovery.MONITOR.getGroupName());
    boolean hasAgent = securityGroups.contains(Discovery.AGENT.getGroupName());
    if (!hasAgent && !hasMonitor) {
        System.err
                .println("Missing node profile information! Make sure this node has required security groups!");
        System.exit(-1);
    } else if (hasAgent && hasMonitor) {
        profile = "monitor-and-agent";
    } else if (hasMonitor) {
        profile = "monitor";
    } else {
        profile = "agent";
    }

    FileUtils.writeStringToFile(new File("/tmp/eg-node-to-start"), profile);
    System.out.printf("Local machine is morphed into a %s\n", profile);

    String overridesURL = "";
    if (launchParameters.containsKey(LAUNCH_PARAMETER_OVERRIDES_URL))
        overridesURL = launchParameters.getProperty(LAUNCH_PARAMETER_OVERRIDES_URL);
    FileUtils.writeStringToFile(new File("/tmp/overrides"), overridesURL);
}