Package org.rhq.cassandra.util

Examples of org.rhq.cassandra.util.ConfigEditor


        log4jProps.load(new FileInputStream(log4jFile));
        assertEquals(log4jProps.getProperty("log4j.appender.R.File"), StorageInstaller.STORAGE_LOG_FILE_PATH,
            "The log file is wrong");

        File yamlFile = new File(confDir, "cassandra.yaml");
        ConfigEditor yamlEditor = new ConfigEditor(yamlFile);
        yamlEditor.load();

        assertEquals(yamlEditor.getInternodeAuthenticator(), "org.rhq.cassandra.auth.RhqInternodeAuthenticator",
            "Failed to set the internode_authenticator property in " + yamlFile);
        assertEquals(yamlEditor.getAuthenticator(), "org.apache.cassandra.auth.PasswordAuthenticator",
            "The authenticator property is wrong");
        assertEquals(yamlEditor.getListenAddress(), address, "The listen_address property is wrong");
        assertEquals(yamlEditor.getNativeTransportPort(), (Integer) 9142, "The native_transport_port property is wrong");
        assertEquals(yamlEditor.getRpcAddress(), address, "The rpc_address property is wrong");
        assertEquals(yamlEditor.getStoragePort(), (Integer) 7100, "The storage_port property is wrong");

        File cassandraJvmPropsFile = new File(confDir, "cassandra-jvm.properties");
        Properties properties = new Properties();
        properties.load(new FileInputStream(cassandraJvmPropsFile));
View Full Code Here


        log4jProps.load(new FileInputStream(log4jFile));
        assertEquals(log4jProps.getProperty("log4j.appender.R.File"), StorageInstaller.STORAGE_LOG_FILE_PATH,
            "The log file is wrong");

        File yamlFile = new File(confDir, "cassandra.yaml");
        ConfigEditor yamlEditor = new ConfigEditor(yamlFile);
        yamlEditor.load();

        assertEquals(yamlEditor.getInternodeAuthenticator(), "org.rhq.cassandra.auth.RhqInternodeAuthenticator",
            "Failed to set the internode_authenticator property in " + yamlFile);
        assertEquals(yamlEditor.getAuthenticator(), "org.apache.cassandra.auth.PasswordAuthenticator",
            "The authenticator property is wrong");
        assertEquals(yamlEditor.getListenAddress(), address, "The listen_address property is wrong");
        assertEquals(yamlEditor.getNativeTransportPort(), (Integer) 9142, "The native_transport_port property is wrong");
        assertEquals(yamlEditor.getRpcAddress(), address, "The rpc_address property is wrong");
        assertEquals(yamlEditor.getStoragePort(), (Integer) 7100, "The storage_port property is wrong");

        File cassandraJvmPropsFile = new File(confDir, "cassandra-jvm.properties");
        Properties properties = new Properties();
        properties.load(new FileInputStream(cassandraJvmPropsFile));
View Full Code Here

        // src/test/resources/rhq48/storage/conf/cassandra-env.sh
        assertEquals(properties.getProperty("jmx_port"), "7399", "Failed to update the JMX port in "
            + cassandraJvmPropsFile);

        File yamlFile = new File(confDir, "cassandra.yaml");
        ConfigEditor newYamlEditor = new ConfigEditor(yamlFile);
        newYamlEditor.load();

        ConfigEditor oldYamlEditor = new ConfigEditor(oldCassandraYamlFile);
        oldYamlEditor.load();

        assertEquals(newYamlEditor.getInternodeAuthenticator(), "org.rhq.cassandra.auth.RhqInternodeAuthenticator",
            "Failed to set the internode_authenticator property in " + yamlFile);
        assertEquals(newYamlEditor.getAuthenticator(), oldYamlEditor.getAuthenticator(), "The authenticator property "
            + "is wrong");
        assertEquals(newYamlEditor.getCommitLogDirectory(), oldYamlEditor.getCommitLogDirectory(),
            "The commit_log property is wrong");
        assertEquals(newYamlEditor.getDataFileDirectories(), oldYamlEditor.getDataFileDirectories(),
            "The data_files property is wrong");
        assertEquals(newYamlEditor.getListenAddress(), oldYamlEditor.getListenAddress(),
            "The listen_address property is wrong");
        assertEquals(newYamlEditor.getNativeTransportPort(), oldYamlEditor.getNativeTransportPort(),
            "The native_transport_port property is wrong");
        assertEquals(newYamlEditor.getRpcAddress(), oldYamlEditor.getRpcAddress(), "The rpc_address property is wrong");
        assertEquals(newYamlEditor.getSavedCachesDirectory(), oldYamlEditor.getSavedCachesDirectory(),
            "The saved_caches_directory property is wrong");
        assertEquals(newYamlEditor.getStoragePort(), oldYamlEditor.getStoragePort(),
            "The storage_port property is wrong");
    }
View Full Code Here

            storageBasedir.mkdirs();
            deployer.unzipDistro();
            deployer.applyConfigChanges();
            deployer.updateFilePerms();

            ConfigEditor oldYamlEditor = new ConfigEditor(oldYamlFile);
            oldYamlEditor.load();
            ConfigEditor newYamlEditor = new ConfigEditor(newYamlFile);
            newYamlEditor.load();

            installerInfo.hostname = oldYamlEditor.getListenAddress();
            newYamlEditor.setListenAddress(installerInfo.hostname);
            newYamlEditor.setRpcAddress(installerInfo.hostname);

            installerInfo.cqlPort = oldYamlEditor.getNativeTransportPort();
            newYamlEditor.setNativeTransportPort(installerInfo.cqlPort);

            installerInfo.gossipPort = oldYamlEditor.getStoragePort();
            newYamlEditor.setStoragePort(installerInfo.gossipPort);

            newYamlEditor.setCommitLogDirectory(oldYamlEditor.getCommitLogDirectory());
            newYamlEditor.setSavedCachesDirectory(oldYamlEditor.getSavedCachesDirectory());
            newYamlEditor.setDataFileDirectories(oldYamlEditor.getDataFileDirectories());
            newYamlEditor.setSeeds(installerInfo.hostname);

            newYamlEditor.save();

            if (isRHQ48Install) {
                Properties jvmProps = new Properties();
                jvmProps.load(new FileInputStream(cassandraJvmPropsFile));
                PropertiesFileUpdate propertiesUpdater = new PropertiesFileUpdate(
View Full Code Here

                    + "existing RHQ storage node installation", STATUS_INVALID_UPGRADE);
            }

            File oldConfDir = new File(existingStorageDir, "conf");
            File oldYamlFile = new File(oldConfDir, "cassandra.yaml");
            ConfigEditor oldYamlEditor = new ConfigEditor(oldYamlFile);
            oldYamlEditor.load();

            String storageNodeAddress = oldYamlEditor.getListenAddress();

            Properties dbProperties;
            File oldServerPropsFile = new File(fromDir, "bin/rhq-server.properties");
            dbProperties = new Properties();
            FileInputStream oldServerPropsFileInputStream = new FileInputStream(oldServerPropsFile);
View Full Code Here

                }
            }

            if (yamlConfigurationPath != null) {
                File yamlConfigurationFile = new File(yamlConfigurationPath, "cassandra.yaml");
                ConfigEditor yamlEditor = new ConfigEditor(yamlConfigurationFile);
                yamlEditor.load();

                pluginConfig.put(new PropertySimple(YAML_PROPERTY, yamlConfigurationFile.getAbsolutePath()));
                pluginConfig.put(new PropertySimple(CLUSTER_NAME_PROPERTY, yamlEditor.getClusterName()));
                pluginConfig.put(new PropertySimple(HOST_PROPERTY, yamlEditor.getListenAddress()));
                pluginConfig.put(new PropertySimple(AUTHENTICATOR_PROPERTY, yamlEditor.getAuthenticator()));
            }
        }

        if (jmxPort != null) {
            pluginConfig.put(new PropertySimple(JMX_PORT_PROPERTY, jmxPort));
View Full Code Here

        } else {
            File basedir = jvmOptsFile.getParentFile().getParentFile();
            config.put(new PropertySimple("heapDumpDir", new File(basedir, "bin").getAbsolutePath()));
        }

        ConfigEditor yamlEditor = new ConfigEditor(cassandraYamlFile);
        yamlEditor.load();
        config.put(new PropertySimple("cqlPort", yamlEditor.getNativeTransportPort()));
        config.put(new PropertySimple("gossipPort", yamlEditor.getStoragePort()));

        // Read data directories here..
        config.put(new PropertySimple("CommitLogLocation", yamlEditor.getCommitLogDirectory()));
        config.put(new PropertySimple("SavedCachesLocation", yamlEditor.getSavedCachesDirectory()));
        PropertyList dataFileLocations = new PropertyList("AllDataFileLocations");
        for (String s : yamlEditor.getDataFileDirectories()) {
            dataFileLocations.add(new PropertySimple("directory", s));
        }
        config.put(dataFileLocations);

        return config;
View Full Code Here

        propertiesUpdater.update(properties);
    }

    private void updateCassandraYaml(Configuration newConfig) {
        ConfigEditor editor = new ConfigEditor(cassandraYamlFile);
        try {
            editor.load();

            PropertySimple cqlPortProperty = newConfig.getSimple("cqlPort");
            if (cqlPortProperty != null) {
                editor.setNativeTransportPort(cqlPortProperty.getIntegerValue());
            }

            PropertySimple gossipPortProperty = newConfig.getSimple("gossipPort");
            if (gossipPortProperty != null) {
                editor.setStoragePort(gossipPortProperty.getIntegerValue());
            }

            editor.save();
        } catch (ConfigEditorException e) {
            if (e.getCause() instanceof YAMLException) {
                log.error("Failed to update " + cassandraYamlFile);
                log.info("Attempting to restore " + cassandraYamlFile);
                try {
                    editor.restore();
                    throw e;
                } catch (ConfigEditorException e1) {
                    log.error("Failed to restore " + cassandraYamlFile + ". A copy of the file prior to any " +
                        "modifications can be found at " + editor.getBackupFile());
                    throw new ConfigEditorException("There was an error updating " + cassandraYamlFile + " and " +
                        "undoing the changes failed. A copy of the file can be found at " + editor.getBackupFile() +
                        ". See the agent logs for more details.", e);
                }
            } else {
                log.error("No updates were made to " + cassandraYamlFile + " due to an unexpected error", e);
                throw e;
View Full Code Here

            result.setErrorMessage("Failed to shut down storage node: " + shutdownResult.getErrorMessage());
        } else {
            File basedir = getBasedir();
            if (basedir.exists()) {
                log.info("Purging data directories");
                ConfigEditor yamlEditor = getYamlConfigEditor();
                yamlEditor.load();
                purgeDataDirs(yamlEditor);

                log.info("Purging installation directory " + basedir);
                purgeDir(basedir);
View Full Code Here

                "node failed with this error: " + shutdownResult.getErrorMessage());
            return result;
        }

        Configuration pluginConfig = context.getPluginConfiguration();
        ConfigEditor configEditor = getYamlConfigEditor();

        try {
            configEditor.load();

            purgeDataDirs(configEditor);

            log.info("Updating cluster settings");

            String address = pluginConfig.getSimpleValue("host");
            int cqlPort = Integer.parseInt(params.getSimpleValue("cqlPort"));
            int gossipPort = Integer.parseInt(params.getSimpleValue("gossipPort"));
            List<String> addresses = getAddresses(params.getList("addresses"));

            // Make sure this node's address is not in the list; otherwise, it
            // won't bootstrap properly.
            List<String> seeds = new ArrayList<String>(addresses);
            seeds.remove(address);

            log.info("Updating seeds property to " + seeds);

            configEditor.setSeeds(seeds.toArray(new String[seeds.size()]));
            configEditor.setNativeTransportPort(cqlPort);
            configEditor.setStoragePort(gossipPort);

            configEditor.save();
            log.info("Cluster configuration settings have been applied to " + configEditor.getConfigFile());

            updateInternodeAuthConfFile(new HashSet<String>(addresses));

            log.info(this + " is ready to be bootstrap. Restarting storage node...");
            OperationResult startResult = startNode();
            if (startResult.getErrorMessage() != null) {
                log.error("Failed to restart storage node:\n" + startResult.getErrorMessage());
                result.setErrorMessage("Failed to restart storage node:\n" + startResult.getErrorMessage());
            } else {
                result.setSimpleResult("The storage node was successfully updated is now bootstrapping into the cluster.");
            }

            return result;
        } catch (ConfigEditorException e) {
            log.error("There was an error while trying to update " + configEditor.getConfigFile(), e);
            if (e.getCause() instanceof YAMLException) {
                log.info("Attempting to restore " + configEditor.getConfigFile());
                try {
                    configEditor.restore();
                    result.setErrorMessage("Failed to update configuration file [" + configEditor.getConfigFile() + "]: " +
                        ThrowableUtil.getAllMessages(e.getCause()));
                } catch (ConfigEditorException e1) {
                    log.error("Failed to restore " + configEditor.getConfigFile() + ". A copy of the file prior to any modifications " +
                        "can be found at " + configEditor.getBackupFile());
                    result.setErrorMessage("There was an error updating [" + configEditor.getConfigFile() + "] and undoing the changes " +
                        "Failed. A copy of the file can be found at " + configEditor.getBackupFile() + ". See the " +
                        "agent logs for more details");
                }
            }

            EmsConnection emsConnection = getEmsConnection();
View Full Code Here

TOP

Related Classes of org.rhq.cassandra.util.ConfigEditor

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.