Package org.rhq.core.pc

Examples of org.rhq.core.pc.PluginContainer


            out.println(MSG.getMsg(AgentI18NResourceKeys.INVENTORY_ID_AND_DUMP_TYPES_SPECIFIED));
            out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            return;
        }

        PluginContainer pc = PluginContainer.getInstance();

        // to get inventory data, the PC must be started
        if (!agent.isStarted() || !pc.isStarted()) {
            out.println(MSG.getMsg(AgentI18NResourceKeys.INVENTORY_MUST_BE_STARTED));
            return;
        }

        PrintWriter exportWriter = out; // default is to dump to console out
        if (exportFile != null) {
            try {
                FileOutputStream fos = new FileOutputStream(new File(exportFile));
                exportWriter = new PrintWriter(fos);
            } catch (Exception e) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.INVENTORY_BAD_EXPORT_FILE, exportFile, e));
                return;
            }
        }

        // process the inventory
        try {
            if (inventoryBinaryFile == null) {
                if (dumpTypesOnly) {
                    Set<ResourceType> rootTypes = pc.getPluginManager().getMetadataManager().getRootTypes();
                    InventoryPrinter.outputAllResourceTypes(exportWriter, dumpXml, rootTypes);
                } else {
                    ResourceContainer rc = null;
                    if (id != null) {
                        rc = pc.getInventoryManager().getResourceContainer(id);
                        if (rc == null) {
                            out.println(MSG.getMsg(AgentI18NResourceKeys.INVENTORY_INVALID_RESOURCE_ID, id));
                            return;
                        }
                    }
View Full Code Here


                // If the server thinks we are down, we need to do some things to get this agent in sync
                // with the server. Anything we do in here should be very fast.
                boolean serverThinksWeAreDown = request.isReplyAgentIsBackfilled();
                if (serverThinksWeAreDown) {
                    LOG.warn(AgentI18NResourceKeys.SERVER_THINKS_AGENT_IS_DOWN);
                    PluginContainer pluginContainer = PluginContainer.getInstance();
                    if (pluginContainer.isStarted()) {
                        // tell the plugin container to send a full avail report up so the server knows we are UP
                        pluginContainer.getInventoryManager().requestFullAvailabilityReport();
                    }
                }

            } catch (Throwable t) {
                // If the ping fails, typically do to a CannotConnectException, and we're not using autodiscovery,
View Full Code Here

        return;
    }

    private void discovery(String pcName, PrintWriter out, String pluginName, String resourceTypeName, boolean verbose)
        throws Exception {
        PluginContainer pc = PluginContainer.getInstance();
        PluginMetadataManager metadataManager = pc.getPluginManager().getMetadataManager();
        Set<ResourceType> typesToDiscover = new TreeSet<ResourceType>(new PluginPrimaryResourceTypeComparator());

        // make sure the plugin exists first (if one was specified)
        Set<String> allPlugins = metadataManager.getPluginNames();
        if (pluginName != null) {
            if (!allPlugins.contains(pluginName)) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BAD_PLUGIN_NAME, pluginName));
                return;
            }
        }

        // determine which resource types are to be discovered
        Set<ResourceType> allTypes = metadataManager.getAllTypes();
        if (resourceTypeName != null) {
            for (ResourceType type : allTypes) {
                if (type.getName().equals(resourceTypeName)) {
                    if ((pluginName == null) || (pluginName.equals(type.getPlugin()))) {
                        typesToDiscover.add(type);
                    }
                }
            }
        } else {
            // if a plugin was specified, only discover its types; otherwise, discover ALL types
            if (pluginName != null) {
                for (ResourceType type : allTypes) {
                    if (pluginName.equals(type.getPlugin())) {
                        typesToDiscover.add(type);
                    }
                }
            } else {
                typesToDiscover.addAll(allTypes);
            }
        }

        if (typesToDiscover.size() == 0) {
            if (pluginName == null) {
                out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BAD_RESOURCE_TYPE_NAME, resourceTypeName));
            } else {
                out.println(MSG.getMsg(AgentI18NResourceKeys.DISCOVERY_BAD_PLUGIN_RESOURCE_TYPE_NAME, pluginName,
                    resourceTypeName));
            }

            return;
        }

        InventoryManager inventoryManager = pc.getInventoryManager();
        HashSet<ResourceType> blacklist = inventoryManager.getDiscoveryComponentProxyFactory()
            .getResourceTypeBlacklist();
        Iterator<ResourceType> iterator = blacklist.iterator();
        while (iterator.hasNext()) {
            ResourceType type = iterator.next();
View Full Code Here

            // we got too many arguments on the command line
            out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
            return;
        }

        PluginContainer pc = PluginContainer.getInstance();

        // the PC must be started
        if (!agent.isStarted() || !pc.isStarted()) {
            out.println(MSG.getMsg(AgentI18NResourceKeys.AVAILABILITY_MUST_BE_STARTED));
            return;
        }

        // process the inventory
        InventoryManager inventoryManager = pc.getInventoryManager();
        AvailabilityReport report = inventoryManager.executeAvailabilityScanImmediately(changedOnly, force);

        if (report == null) {
            out.println(MSG.getMsg(AgentI18NResourceKeys.AVAILABILITY_NO_COMMITTED_INVENTORY));
            return;
View Full Code Here

        //this is just a dummy method that other classes can call to force the static
        //initialization of this class.
    }
   
    public static PluginContainer switchPluginContainer(String deploymentName) throws Exception {
        PluginContainer oldInstance = PluginContainer.getInstance();
        Method setInstance = PluginContainer.class.getMethod("setContainerInstance", String.class);
        setInstance.invoke(null, deploymentName);
        PluginContainer newInstance = PluginContainer.getInstance();

        if (newInstance != oldInstance) {
            Boolean enableNativeInfo = NATIVE_SYSTEM_INFO_ENABLEMENT_PER_PC.get(deploymentName);

            if (enableNativeInfo == null || !enableNativeInfo.booleanValue()) {
View Full Code Here

        if (wasStarted) {
            startPc();
        }

        PluginContainer pc = PluginContainer.getInstance();
        String pluginName = getPluginName(pluginArchive);
        PluginEnvironment plugin = pc.getPluginManager().getPlugin(pluginName);
        if (plugin == null) {
            throw new RuntimeException("Failed to deploy plugin '" + pluginName + "' (" + pluginArchive.getName()
                    + ") - check the log above for an error (and big stack trace) from PluginManager.initialize().");
        }
View Full Code Here

     * @return true if the plugin container needed to be started (i.e. was not running before), false otherwise.
     */
    boolean startPc() {
        LOG.debug("Starting PluginContainer on demand...");
       
        PluginContainer pc = PluginContainer.getInstance();
        if (pc.isStarted()) {
            return false;
        }

        //always refresh the plugin finder so that it reports all the plugins
        //each time (and doesn't remember the plugins from previous PC runs)
        configuration.setPluginFinder(new FileSystemPluginFinder(configuration.getPluginDirectory()));

        if (LOG.isDebugEnabled() && (configuration.getAdditionalPackagesForRootPluginClassLoaderToExclude() != null)) {
            LOG.debug("Using root plugin classloader regex [" + configuration.getRootPluginClassLoaderRegex() + "]...");
        }

        pc.setConfiguration(configuration);
        pc.initialize();
        return true;
    }
View Full Code Here

     *
     * @return true if PC was running before this call, false otherwise
     */
    boolean stopPc() {
        LOG.debug("Stopping PluginContainer on demand...");
        PluginContainer pc = PluginContainer.getInstance();
        boolean wasStarted = pc.isStarted();
        if (wasStarted) {
            boolean shutdownGracefully = pc.shutdown();
            if (shutdownGracefully) {
                LOG.debug("Stopped PluginContainer gracefully.");
            } else {
                LOG.debug("Stopped PluginContainer.");
            }
View Full Code Here

     *                               with the server; if 0 or less, this method blocks <b>indefinitely</b>
     *
     * @return <code>true</code> if the plugin container is started, <code>false</code> if it did not start
     */
    public boolean startPluginContainer(final long wait_for_registration) {
        PluginContainer plugin_container = PluginContainer.getInstance();

        if (plugin_container.isStarted()) {
            return true;
        }

        plugin_container.setRebootRequestListener(new RebootRequestListener() {
            public void reboot() {
                try {
                    shutdown();
                } catch (Throwable t) {
                    LOG.error(t, "The plugin container has requested the agent be restarted but the shutdown "
                        + "operation failed.");
                }
                if (isStarted()) {
                    // Pause for a few seconds and try to shut down one more time.
                    try {
                        Thread.sleep(3000);
                        shutdown();
                    } catch (Throwable t) {
                        LOG.error(t, "The plugin container has requested the agent be restarted but the shutdown "
                            + "operation failed again.");
                    }
                }
                if (isStarted()) {
                    // At this point agent shut down failed twice. We can get by with rebooting the plugin container
                    // so we will try that as last ditch effort.

                    LOG.warn("The agent shut down operation has failed twice. Attempting to reboot the plugin "
                        + "container so that stale resource types and deleted plugins are removed.");
                    try {
                        rebootPluginContainer();
                    } catch (Throwable t) {
                        // If rebooting the plugin container fails as well, there is not much else we can do besides
                        // reporting the failures. Manual intervention is needed.
                        LOG.error("The agent could not be shut down and rebooting the plugin container failed. "
                            + "Please check the logs for errors and manually restart the agent as soon as "
                            + "possible.");
                        return;
                    }
                } else {
                    try {
                        cleanDataDirectory();
                    } catch (Throwable t) {
                        LOG.warn(t, "The plugin container has requested the agent be restarted but purging the "
                            + "data directory failed.");
                    }
                    try {
                        start();
                    } catch (Throwable t) {
                        LOG.warn(t, "An error occurred while trying to restart the agent. Attempting restart "
                            + "one more time");
                        try {
                            shutdown();
                            start();
                        } catch (Throwable t1) {
                            LOG.error(t1, "Restarting the agent has failed. Please check the logs for errors and "
                                + "manually restart the agent as soon as possible.");
                            return;
                        }
                    }
                    getAgentRestartCounter().restartedAgent(AgentRestartReason.STALE_INVENTORY);
                }
            }

            private void rebootPluginContainer() throws Throwable {
                PluginContainer pc = PluginContainer.getInstance();

                if (pc.isStarted()) {
                    try {
                        shutdownPluginContainer();
                    } catch (Throwable t) {
                        LOG.error(t, "The plugin container shut down operation failed.");
                        throw t;
View Full Code Here

                // If the server thinks we are down, we need to do some things to get this agent in sync with the server.
                // Anything we do in here should be very fast.
                boolean serverThinksWeAreDown = results.isDown();
                if (serverThinksWeAreDown) {
                    LOG.warn(AgentI18NResourceKeys.SERVER_THINKS_AGENT_IS_DOWN);
                    PluginContainer plugin_container = PluginContainer.getInstance();
                    if (plugin_container.isStarted()) {
                        // tell the plugin container to send a full avail report up so the server knows we are UP
                        plugin_container.getInventoryManager().requestFullAvailabilityReport();
                    }
                }
            } catch (AgentNotSupportedException anse) {
                throw anse; // bubble this up to the outer try-catch so we can update this agent now
            } catch (Throwable t) {
View Full Code Here

TOP

Related Classes of org.rhq.core.pc.PluginContainer

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.