Package org.rhq.enterprise.agent

Examples of org.rhq.enterprise.agent.AgentConfiguration


     */
    public boolean execute(AgentMain agent, String[] args) {
        PrintWriter out = agent.getOut();

        try {
            AgentConfiguration agent_config = agent.getConfiguration();
            Preferences preferences = agent_config.getPreferences();

            if ((args.length != 2) && (args.length != 3)) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            } else if (args.length == 2) {
                if (args[1].equals(MSG.getMsg(AgentI18NResourceKeys.CONFIG_LIST))) {
View Full Code Here


        @Override
        public void postProcess() {
            super.postProcess();

            Preferences preferences = getPreferences();
            AgentConfiguration agent_config = new AgentConfiguration(preferences);
            File agent_dir = agent_config.getDataDirectory();

            // let's forcibly make sure that the agent and comm dir values are stored in preferences
            // we need to make sure they are the same
            preferences.put(AgentConfigurationConstants.DATA_DIRECTORY, agent_dir.getPath());
            preferences.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, agent_dir.getPath());
View Full Code Here

        public boolean checkValidity(String pref_name, String value_to_check, Preferences preferences, PrintWriter out) {
            boolean is_valid = true;
            String err_msg_key = null;

            if (value_to_check != null) {
                AgentConfiguration agent_config = new AgentConfiguration(preferences);

                if (m_paramsType.equals(ParametersType.QUEUE_THROTTLING_PARAMS)) {
                    err_msg_key = AgentI18NResourceKeys.SETUP_BAD_QUEUE_THROTTLING_PARAMS;
                    is_valid = null != agent_config.isClientSenderQueueThrottlingValueValid(value_to_check);
                } else if (m_paramsType.equals(ParametersType.SEND_THROTTLING_PARAMS)) {
                    err_msg_key = AgentI18NResourceKeys.SETUP_BAD_SEND_THROTTLING_PARAMS;
                    is_valid = null != agent_config.isClientSenderSendThrottlingValueValid(value_to_check);
                } else if (m_paramsType.equals(ParametersType.COMMAND_SPOOL_PARAMS)) {
                    err_msg_key = AgentI18NResourceKeys.SETUP_BAD_COMMAND_SPOOL_PARAMS;
                    is_valid = null != agent_config.isClientSenderCommandSpoolFileParamsValueValid(value_to_check);
                }
            }

            if (!is_valid) {
                out.println(MSG.getMsg(err_msg_key, value_to_check));
View Full Code Here

         *
         * @see SetupInstruction#preProcess()
         */
        @Override
        public void preProcess() {
            String data_dir = new AgentConfiguration(getPreferences()).getDataDirectoryIfDefined();
            String default_file = getDefaultValue();

            if ((data_dir != null) && (default_file != null)) {
                setDefaultValue(new File(data_dir, default_file).getPath());
            }
View Full Code Here

            super(pref_name, default_value, validity_checker, prompt_msg, help, false);
        }

        @Override
        public void preProcess() {
            String address = new AgentConfiguration(getPreferences()).getServerBindAddress();
            if (address != null) {
                setDefaultValue(address);
            } else {
                super.preProcess();
            }
View Full Code Here

    /**
     * @see AgentPromptCommand#execute(AgentMain, String[])
     */
    public boolean execute(AgentMain agent, String[] args) {
        AgentConfiguration agent_config = agent.getConfiguration();
        ClientCommandSenderConfiguration sender_config = agent_config.getClientCommandSenderConfiguration();

        if (sender_config.commandSpoolFileName == null) {
            agent.getOut().println(MSG.getMsg(AgentI18NResourceKeys.DUMPSPOOL_NO_FILE));
            return true;
        }

        int raw_byte_base = -2; // -2 will indicate an error

        if (args.length > 1) {
            if (args.length == 2) {
                if (args[1].equals(MSG.getMsg(AgentI18NResourceKeys.DUMPSPOOL_OBJ))) {
                    raw_byte_base = 0;
                } else if (args[1].equals(MSG.getMsg(AgentI18NResourceKeys.DUMPSPOOL_HEX))) {
                    raw_byte_base = DumpBytes.BASE_HEX;
                }
            }
        } else {
            raw_byte_base = -1;
        }

        if (raw_byte_base == -2) {
            // wrong number of arguments or arguments were invalid
            agent.getOut().println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            return true;
        }

        File spool_file = new File(sender_config.dataDirectory, sender_config.commandSpoolFileName);

        try {
            PersistentFifo.dumpContents(agent.getOut(), spool_file, agent_config
                .isClientSenderCommandSpoolFileCompressed(), raw_byte_base);
        } catch (Exception e) {
            agent.getOut().println(MSG.getMsg(AgentI18NResourceKeys.DUMPSPOOL_ERROR, spool_file, e));
        }

View Full Code Here

                    }
                    out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_SERVER_ENDPOINT, sender.getRemoteCommunicator()
                        .getRemoteEndpoint()));
                } else {
                    out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_AGENT_NOT_STARTED));
                    AgentConfiguration agent_config = agent.getConfiguration();
                    out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_SERVER_ENDPOINT_CONFIG, agent_config
                        .getServerLocatorUri()));
                }
            }
        } catch (Exception e) {
            out.println(MSG.getMsg(AgentI18NResourceKeys.SENDER_FAILURE));
View Full Code Here

    public String getDetailedHelp() {
        return MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_DETAILED_HELP);
    }

    private void processCommand(AgentMain agent, String[] args, PrintWriter out) {
        AgentConfiguration agentConfig = agent.getConfiguration();
        String pcName = agentConfig.getAgentName();
        String pluginName = null;
        String resourceTypeName = null;
        Integer resourceId = null;
        boolean verbose = false;
        boolean full = false;

        String sopts = "-p:i:r:fvb:";
        LongOpt[] lopts = { new LongOpt("plugin", LongOpt.REQUIRED_ARGUMENT, null, 'p'), //
            new LongOpt("resourceId", LongOpt.REQUIRED_ARGUMENT, null, 'i'), //
            new LongOpt("resourceType", LongOpt.REQUIRED_ARGUMENT, null, 'r'), //
            new LongOpt("full", LongOpt.NO_ARGUMENT, null, 'f'), //
            new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v'), //
            new LongOpt("blacklist", LongOpt.REQUIRED_ARGUMENT, null, 'b') };

        Getopt getopt = new Getopt("discovery", args, sopts, lopts);
        int code;

        while ((code = getopt.getopt()) != -1) {
            switch (code) {
            case ':':
            case '?':
            case 1: {
                out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
                return;
            }

            case 'p': {
                pluginName = getopt.getOptarg();
                break;
            }

            case 'i': {
                resourceId = Integer.valueOf(getopt.getOptarg());
                break;
            }

            case 'r': {
                resourceTypeName = getopt.getOptarg();
                break;
            }

            case 'f': {
                full = true;
                break;
            }

            case 'b': {
                String opt = getopt.getOptarg();
                InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
                DiscoveryComponentProxyFactory factory = inventoryManager.getDiscoveryComponentProxyFactory();
                if (opt.equalsIgnoreCase("list")) {
                    HashSet<ResourceType> blacklist = factory.getResourceTypeBlacklist();
                    out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BLACKLIST_LIST, blacklist));
                } else if (opt.equalsIgnoreCase("clear")) {
                    factory.clearResourceTypeBlacklist();
                    out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BLACKLIST_CLEAR));
                } else {
                    out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
                }
                return;
            }

            case 'v': {
                verbose = true;
                break;
            }
            }
        }

        if ((getopt.getOptind() + 1) < args.length) {
            out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            return;
        }

        if (full) {
            // do a full discovery - we ignore the -p and -r and -i options and do everything

            if (!agent.getClientCommandSender().isSending()) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_AGENT_NOT_CONNECTED_TO_SERVER));
            }

            InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
            if (inventoryManager.isDiscoveryScanInProgress()) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_SCAN_ALREADY_IN_PROGRESS));
                return;
            }

            HashSet<ResourceType> blacklist = inventoryManager.getDiscoveryComponentProxyFactory()
                .getResourceTypeBlacklist();
            if (!blacklist.isEmpty()) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BLACKLISTED_TYPES, blacklist));
            }
            long start = System.currentTimeMillis();
            InventoryReport scan1 = inventoryManager.executeServerScanImmediately();
            InventoryReport scan2 = inventoryManager.executeServiceScanImmediately();
            out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_FULL_RUN, (System.currentTimeMillis() - start)));
            printInventoryReport(scan1, out, verbose);
            printInventoryReport(scan2, out, verbose);
        } else {
            try {
                if (resourceId == null) {
                    discovery(pcName, out, pluginName, resourceTypeName, verbose);
                } else {
                    // specifying a resource ID implies we must ignore -r and -p (since type/plugin is determined by the resource)
                    InventoryManager im = PluginContainer.getInstance().getInventoryManager();
                    ResourceContainer resourceContainer = im.getResourceContainer(resourceId);
                    if (resourceContainer != null) {
                        Resource resource = resourceContainer.getResource();
                        PluginContainerConfiguration pcc = agentConfig.getPluginContainerConfiguration();
                        RuntimeDiscoveryExecutor scanner = new RuntimeDiscoveryExecutor(im, pcc, resource);
                        InventoryReport report = scanner.call();
                        out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_RESOURCE_SERVICES, resource.getName()));
                        printInventoryReport(report, out, verbose);
                    } else {
View Full Code Here

        // because of the above, this loads in the config file, wiping any existing prefs away (except token)
        prepareConfigurationPreferences();
    }

    private void cleanDataDirectory() {
        AgentConfiguration config = new AgentConfiguration(getPreferencesNode());
        File dataDir = config.getDataDirectory();

        cleanDataFile(dataDir);

        // it is conceivable the comm services data directory was configured in a different
        // place than where the agent's data directory is - make sure we clean out that other data dir
        File commDataDir = config.getServiceContainerPreferences().getDataDirectory();
        if (!commDataDir.getAbsolutePath().equals(dataDir.getAbsolutePath())) {
            cleanDataFile(commDataDir);
        }

        return;
View Full Code Here

     *
     * @throws Exception
     */
    private AgentConfiguration prepareConfigurationPreferences() throws Exception {
        Preferences prefNode = getPreferencesNode();
        AgentConfiguration config = new AgentConfiguration(prefNode);

        if (config.getAgentConfigurationVersion() == 0) {
            config = loadConfigurationFile();
        }

        // now that the configuration preferences are loaded, we need to override them with any bootstrap override properties
        Map<String, String> overrides = configurationOverrides;
        if (overrides != null) {
            for (Map.Entry<String, String> entry : overrides.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();

                // allow ${var} notation in the values so we can provide variable replacements in the values
                value = StringPropertyReplacer.replaceProperties(value);

                prefNode.put(key, value);
            }
        }

        // let's make sure our configuration is upgraded to the latest schema
        AgentConfigurationUpgrade.upgradeToLatest(config.getPreferences());

        return config;
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.agent.AgentConfiguration

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.