Package org.rhq.core.util

Examples of org.rhq.core.util.PropertiesFileUpdate


            log.warn("The storage installer will exit due to previous errors");
            return e.getErrorCode();
        }

        log.info("Updating rhq-server.properties...");
        PropertiesFileUpdate serverPropertiesUpdater = getServerProperties();
        Properties properties = new Properties();

        properties.setProperty("rhq.storage.nodes", installerInfo.hostname);
        properties.setProperty(StorageProperty.CQL_PORT.property(), Integer.toString(installerInfo.cqlPort));
        properties.setProperty(StorageProperty.GOSSIP_PORT.property(), Integer.toString(installerInfo.gossipPort));

        // carry forward the required db props from the legacy install. We need these to contact the
        // DB to do a version stamp.
        if (isUpgrade) {
            File oldServerPropsFile = new File(fromDir, "bin/rhq-server.properties");
            // if the old props file exists then carry forward the props. If we're not doing a version stamp then
            // don't worry about a missing file, we're not contacting the db anyway (typically a test scenario).
            if (oldServerPropsFile.exists() || !noStamp) {
                Properties oldProperties = new Properties();
                FileInputStream oldServerPropsFileInputStream = new FileInputStream(oldServerPropsFile);
                try {
                    oldProperties.load(oldServerPropsFileInputStream);
                    properties.setProperty("rhq.server.database.connection-url",
                        oldProperties.getProperty("rhq.server.database.connection-url"));
                    properties.setProperty("rhq.server.database.user-name",
                        oldProperties.getProperty("rhq.server.database.user-name"));
                    properties.setProperty("rhq.server.database.password",
                        oldProperties.getProperty("rhq.server.database.password"));

                } finally {
                    oldServerPropsFileInputStream.close();
                }
            }
        }

        // update the properties file
        serverPropertiesUpdater.update(properties);

        Properties dbProperties = serverPropertiesUpdater.loadExistingProperties();

        // when upgrading, mark the upgrade by stamping the new version
        if (isUpgrade && !noStamp) {
            String version = StorageInstaller.class.getPackage().getImplementationVersion();
            stampStorageNodeVersion(dbProperties, installerInfo.hostname, version);
View Full Code Here


            newYamlEditor.save();

            if (isRHQ48Install) {
                Properties jvmProps = new Properties();
                jvmProps.load(new FileInputStream(cassandraJvmPropsFile));
                PropertiesFileUpdate propertiesUpdater = new PropertiesFileUpdate(
                    cassandraJvmPropsFile.getAbsolutePath());
                jvmProps.setProperty("jmx_port", Integer.toString(installerInfo.jmxPort));

                propertiesUpdater.update(jvmProps);

                deployer.updateStorageAuthConf(asSet(installerInfo.hostname));
            } else {
                File oldStorageAuthConfFile = new File(oldConfDir, "rhq-storage-auth.conf");
                File newStorageAuthConfFile = new File(newConfDir, "rhq-storage-auth.conf");
View Full Code Here

        File file = new File(sysprop);
        if (!(file.exists() && file.isFile())) {
            throw new RuntimeException("System property [" + sysprop + "] points to an invalid file.");
        }

        return new PropertiesFileUpdate(file.getAbsolutePath());
    }
View Full Code Here

        File jvmPropsFile = new File(confDir, "cassandra-jvm.properties");
        try {
            log.info("Applying configuration changes to " + jvmPropsFile);

            PropertiesFileUpdate propertiesUpdater = new PropertiesFileUpdate(jvmPropsFile.getAbsolutePath());
            Properties properties = propertiesUpdater.loadExistingProperties();

            properties.setProperty("heap_min", "-Xms" + deploymentOptions.getHeapSize());
            properties.setProperty("heap_max", "-Xmx" + deploymentOptions.getHeapSize());
            properties.setProperty("heap_new", "-Xmn" + deploymentOptions.getHeapNewSize());
            properties.setProperty("thread_stack_size", "-Xss" + deploymentOptions.getStackSize());
            properties.setProperty("jmx_port", deploymentOptions.getJmxPort().toString());

            String javaVersion = System.getProperty("java.version");
            // The check here is taken right from cassandra-env.sh
            if ((!isOpenJDK() || javaVersion.compareTo("1.6.0") > 0)
                || (javaVersion.equals("1.6.0") && getJavaPatchVersion() > 23)) {
                properties.put("java_agent", "-javaagent:$CASSANDRA_HOME/lib/jamm-0.2.5.jar");
            }

            propertiesUpdater.update(properties);
        } catch (IOException e) {
            log.error("An error occurred while updating " + jvmPropsFile, e);
            throw new DeploymentException("An error occurred while updating " + jvmPropsFile, e);
        }
    }
View Full Code Here

        File wrapperEnvFile = new File(wrapperDir, "rhq-storage-wrapper.env");

        try {
            log.info("Applying configuration changes to " + wrapperEnvFile);

            PropertiesFileUpdate propertiesUpdater = new PropertiesFileUpdate(wrapperEnvFile.getAbsolutePath());
            Properties wrapperEnvProps = propertiesUpdater.loadExistingProperties();

            wrapperEnvProps.setProperty("set.heap_min", "-Xms" + deploymentOptions.getHeapSize());
            wrapperEnvProps.setProperty("set.heap_max", "-Xmx" + deploymentOptions.getHeapSize());
            wrapperEnvProps.setProperty("set.heap_new", "-Xmn" + deploymentOptions.getHeapNewSize());
            wrapperEnvProps.setProperty("set.thread_stack_size", "-Xss" + deploymentOptions.getStackSize());
            wrapperEnvProps.setProperty("set.jmx_port", deploymentOptions.getJmxPort().toString());
            // This is always on by default, just set it literally
            wrapperEnvProps.setProperty("set.heap_dump_on_OOMError", "-XX:+HeapDumpOnOutOfMemoryError");
            // This is always set to the bin directory initially
            wrapperEnvProps.setProperty("set.heap_dump_dir", "-XX:HeapDumpPath="
                + useForwardSlash(new File(deployDir, "bin").getAbsolutePath()));

            propertiesUpdater.update(wrapperEnvProps);
        } catch (IOException e) {
            log.error("An error occurred while updating " + wrapperEnvFile, e);
            throw new DeploymentException("An error occurred while updating " + wrapperEnvFile, e);
        }
    }
View Full Code Here

        }

        // Add the default admin user, or if for some reason this file does not exist, just log the issue
        if (mgmtUsers.exists()) {
            try {
                PropertiesFileUpdate mgmtUsersPropFile = new PropertiesFileUpdate(mgmtUsers.getAbsolutePath());
                Properties existingUsers = mgmtUsersPropFile.loadExistingProperties();
                if (existingUsers.containsKey(RHQ_MGMT_USER)) {
                    LOG.info("There is already a mgmt user named [" + RHQ_MGMT_USER + "], will not create another");
                    return;
                }
            } catch (Exception e) {
View Full Code Here

    }

    @Override
    public HashMap<String, String> getServerProperties() throws Exception {
        final File serverPropertiesFile = getServerPropertiesFile();
        final PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath());
        final Properties props = propsFile.loadExistingProperties();

        // the default algorithm that RHQ will use in the comm layer will be defined at runtime based on the VM
        // but if the user mistakenly set the algorithm to the Sun value while using IBM JVM, then force
        // some hardcoded defaults so it can more likely work for IBM JVMs.
        final boolean isIBM = System.getProperty("java.vendor", "").contains("IBM");
View Full Code Here

     */
    private void saveServerProperties(HashMap<String, String> serverProperties) throws Exception {
        ServerProperties.validate(serverProperties);

        final File serverPropertiesFile = getServerPropertiesFile();
        final PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath());

        // this code use to be used within GWT which is why the signature uses HashMap and we convert to Properties here
        final Properties props = new Properties();
        for (Map.Entry<String, String> entry : serverProperties.entrySet()) {
            props.setProperty(entry.getKey(), entry.getValue());
        }

        // BZ 1080508 - the server will fail to install if rhq.server.log-level isn't set
        // (as will be the case for upgrades from older versions), so force it to be set now
        if (!props.containsKey(ServerProperties.PROP_LOG_LEVEL)) {
            props.setProperty(ServerProperties.PROP_LOG_LEVEL, "INFO");
            serverProperties.put(ServerProperties.PROP_LOG_LEVEL, "INFO");
        }

        propsFile.update(props);

        // we need to put them as system properties now so when we hot deploy,
        // the replacement variables in the config files pick up the new values
        for (Map.Entry<String, String> entry : serverProperties.entrySet()) {
            System.setProperty(entry.getKey(), entry.getValue());
View Full Code Here

    public static void validate(File serverPropertiesFile, Set<String> additionalProperties) throws Exception {
        if (!serverPropertiesFile.isFile()) {
            throw new Exception("Properties file not found: [" + serverPropertiesFile.getAbsolutePath() + "]");
        }

        PropertiesFileUpdate pfu = new PropertiesFileUpdate(serverPropertiesFile);
        Properties props = pfu.loadExistingProperties();
        final HashMap<String, String> map = new HashMap<String, String>(props.size());
        for (Object property : props.keySet()) {
            map.put(property.toString(), props.getProperty(property.toString()));
        }
View Full Code Here

    public void persistStorageProperty(String key, String value) {
        if (Boolean.getBoolean("running.itests-2")) {
            // When running itests-2, there is no server props file, so avoid logging a confusing exception
            return;
        }
        PropertiesFileUpdate updater = new PropertiesFileUpdate(getServerPropsFile().getAbsolutePath());
        try {
            updater.update(key, value);
        } catch (IOException e) {
            // TODO should we propagate the exception?
            LOG.warn("Failed to persist property " + key + " due to unexpected I/O error",
                ThrowableUtil.getRootCause(e));
        }
View Full Code Here

TOP

Related Classes of org.rhq.core.util.PropertiesFileUpdate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.