Package org.rhq.core.domain.plugin

Examples of org.rhq.core.domain.plugin.Plugin


            throw new IllegalStateException("DeploymentInfo was not found for plugin [" + pluginName
                + " ] - it should have been initialized by preprocessPlugin().");
        }

        PluginManagerLocal pluginMgr = LookupUtil.getPluginManager();
        Plugin plugin = pluginMgr.getPlugin(pluginName);
        if (null == plugin) {
            log.debug("New plugin [" + pluginName + "] detected.");
            return true;
        }

        String md5 = null;
        try {
            md5 = MessageDigestGenerator.getDigestString(new File(deploymentInfo.url.toURI()));
        } catch (Exception e) {
            log.error("Error generating MD5 for plugin [" + pluginName + "]. Cause: " + e);
        }

        if (!plugin.getMd5().equals(md5)) {
            log.debug("Updated plugin [" + pluginName + "] detected.");
            return true;
        }
        return false;
    }
View Full Code Here


            log.debug("Registering RHQ plugin " + pluginNameDisplayName + ", "
                + ((version != null) ? "version " + version : "undefined version") + "...");
            checkVersionCompatibility(pluginDescriptor.getAmpsVersion());

            String filename = getPluginJarFilename(deploymentInfo); // make sure this is only the filename
            Plugin plugin = new Plugin(pluginName, filename);
            plugin.setDisplayName((displayName != null) ? displayName : pluginName);
            plugin.setEnabled(true);
            plugin.setDescription(pluginDescriptor.getDescription());
            plugin.setAmpsVersion(getAmpsVersion(pluginDescriptor));

            // get the last modified of the "real" plugin jar since that's the one the user touches
            long mtime = deploymentInfo.url.openConnection().getLastModified();
            plugin.setMtime(mtime);

            if (pluginDescriptor.getHelp() != null && !pluginDescriptor.getHelp().getContent().isEmpty()) {
                plugin.setHelp(String.valueOf(pluginDescriptor.getHelp().getContent().get(0)));
            }

            plugin.setVersion(version);
            plugin.setMD5(MessageDigestGenerator.getDigestString(localPluginFile));

            // this manager is responsible for handling the munging of plugins that depend on other plugins
            // since we assume we are called in the proper deployment order, this should not fail
            // if we are called when hot-deploying a plugin whose dependencies aren't deployed, this will fail
            PluginManagerLocal pluginMgr = LookupUtil.getPluginManager();
View Full Code Here

       
        return ret;
    }
   
    private static DeployedAgentPluginsValidator.ConsistentPlugin createPlugin(String name, String version, String md5) {
        return new DeployedAgentPluginsValidator.ConsistentPlugin(new Plugin(0, name, null, null, true, PluginStatusType.INSTALLED, null, null, md5, version, null, 0, 0));
    }
View Full Code Here

                        log.warn("   caused by " + e.getCause().getMessage());
                    }
                }
            }

            Plugin plugin = this.agentPluginsOnFilesystem.get(pluginJar);
            try {
                if (plugin != null) {
                    if (pluginJar.lastModified() == 0L) {
                        // for some reason the operating system can't give us the last mod time, we need to do MD5 check
                        md5 = MessageDigestGenerator.getDigestString(pluginJar);
                        if (!md5.equals(plugin.getMd5())) {
                            plugin = null; // this plugin jar has changed - force it to refresh the cache.
                        }
                    } else if (pluginJar.lastModified() != plugin.getMtime()) {
                        plugin = null; // this plugin jar has changed - force it to refresh the cache.
                    }
                }

                if (plugin == null) {
                    cacheFilesystemAgentPluginJar(pluginJar, md5);
                    updated.add(pluginJar);
                }
            } catch (Exception e) {
                log.warn("Failed to scan agent plugin [" + pluginJar + "] found on filesystem. Skipping. Cause: " + e);
                if (e.getCause() != null) {
                    log.warn("   caused by " + e.getCause().getMessage());
                }
                this.agentPluginsOnFilesystem.remove(pluginJar); // act like we never saw it
                updated.remove(pluginJar);
            }
        }

        // Let's check to see if there are any obsolete plugins that need to be deleted.
        // This is needed if plugin-A-1.0.jar exists and someone deployed plugin-A-1.1.jar but fails to delete plugin-A-1.0.jar.
        doomedPluginFiles.clear();
        HashMap<String, Plugin> pluginsByName = new HashMap<String, Plugin>();
        for (Map.Entry<File, Plugin> currentPluginFileEntry : this.agentPluginsOnFilesystem.entrySet()) {
            Plugin currentPlugin = currentPluginFileEntry.getValue();
            Plugin existingPlugin = pluginsByName.get(currentPlugin.getName());
            if (existingPlugin == null) {
                // this is the usual case - this is the only plugin with the given name we've seen
                pluginsByName.put(currentPlugin.getName(), currentPlugin);
            } else {
                Plugin obsolete = AgentPluginDescriptorUtil.determineObsoletePlugin(currentPlugin, existingPlugin);
                if (obsolete == null) {
                    obsolete = currentPlugin; // both were identical, but we only want one file so pick one to get rid of
                }
                doomedPluginFiles.add(new File(this.agentPluginDeployer.getPluginDir(), obsolete.getPath()));
                if (obsolete == existingPlugin) { // yes use == for reference equality!
                    pluginsByName.put(currentPlugin.getName(), currentPlugin); // override the original one we saw with this latest one
                }
            }
        }
View Full Code Here

        }
        URL pluginUrl = pluginJar.toURI().toURL();
        PluginDescriptor descriptor = AgentPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
        String version = AgentPluginDescriptorUtil.getPluginVersion(pluginJar, descriptor).toString();
        String name = descriptor.getName();
        Plugin plugin = new Plugin(name, pluginJar.getName());
        plugin.setMd5(md5);
        plugin.setVersion(version);
        plugin.setMtime(pluginJar.lastModified());
        this.agentPluginsOnFilesystem.put(pluginJar, plugin);
        return plugin;
    }
View Full Code Here

                String version = rs.getString(5);

                // let's see if we have this logical plugin on the filesystem (it may or may not be under the same filename)
                File expectedFile = new File(this.agentPluginDeployer.getPluginDir(), path);
                File currentFile = null; // will be non-null if we find that we have this plugin on the filesystem already
                Plugin cachedPluginOnFilesystem = this.agentPluginsOnFilesystem.get(expectedFile);

                if (cachedPluginOnFilesystem != null) {
                    currentFile = expectedFile; // we have it where we are expected to have it
                    if (!cachedPluginOnFilesystem.getName().equals(name)) {
                        // I have no idea when or if this would ever happen, but at least log it so we'll see it if it does happen
                        log.warn("For some reason, the plugin file [" + expectedFile + "] is plugin ["
                            + cachedPluginOnFilesystem.getName() + "] but the database says it should be [" + name
                            + "]");
                    } else {
                        log.debug("File system and database agree on a plugin location for [" + expectedFile + "]");
                    }
                } else {
                    // the plugin might still be on the file system but under a different filename, see if we can find it
                    for (Map.Entry<File, Plugin> cachePluginEntry : this.agentPluginsOnFilesystem.entrySet()) {
                        if (cachePluginEntry.getValue().getName().equals(name)) {
                            currentFile = cachePluginEntry.getKey();
                            cachedPluginOnFilesystem = cachePluginEntry.getValue();
                            log.info("Filesystem has a plugin [" + name + "] at the file [" + currentFile
                                + "] which is different than where the DB thinks it should be [" + expectedFile + "]");
                            break; // we found it, no need to continue the loop
                        }
                    }
                }

                if (cachedPluginOnFilesystem != null && currentFile != null && currentFile.exists()) {
                    Plugin dbPlugin = new Plugin(name, path);
                    dbPlugin.setMd5(md5);
                    dbPlugin.setVersion(version);
                    dbPlugin.setMtime(mtime);

                    Plugin obsoletePlugin = AgentPluginDescriptorUtil.determineObsoletePlugin(dbPlugin,
                        cachedPluginOnFilesystem);

                    if (obsoletePlugin == cachedPluginOnFilesystem) { // yes use == for reference equality!
                        StringBuilder logMsg = new StringBuilder();
                        logMsg.append("Found agent plugin [").append(name);
                        logMsg.append("] in the DB that is newer than the one on the filesystem: ");
                        logMsg.append("DB path=[").append(path);
                        logMsg.append("]; file path=[").append(currentFile.getName());
                        logMsg.append("]; DB MD5=[").append(md5);
                        logMsg.append("]; file MD5=[").append(cachedPluginOnFilesystem.getMd5());
                        logMsg.append("]; DB version=[").append(version);
                        logMsg.append("]; file version=[").append(cachedPluginOnFilesystem.getVersion());
                        logMsg.append("]; DB timestamp=[").append(new Date(mtime));
                        logMsg.append("]; file timestamp=[").append(new Date(cachedPluginOnFilesystem.getMtime()));
                        logMsg.append("]");
                        log.info(logMsg.toString());

                        updatedPlugins.add(dbPlugin);

                        if (currentFile.delete()) {
                            log.info("Deleted the obsolete agent plugin file to be updated: " + currentFile);
                            this.agentPluginsOnFilesystem.remove(currentFile);
                        } else {
                            log.warn("Failed to delete the obsolete (to-be-updated) agent plugin file: " + currentFile);
                        }
                        currentFile = null;
                    } else if (obsoletePlugin == null) {
                        // the db is up-to-date, but update the cache so we don't check MD5 or parse the descriptor again
                        currentFile.setLastModified(mtime);
                        cachedPluginOnFilesystem.setMtime(mtime);
                        cachedPluginOnFilesystem.setVersion(version);
                        cachedPluginOnFilesystem.setMd5(md5);
                    } else {
                        String message = "It appears the agent plugin [" + dbPlugin
                        + "] in the database may be obsolete. If so, it will be updated soon by the version on the filesystem [" + currentFile + "].";
                        if (currentFile.getAbsolutePath().equals(expectedFile.getAbsolutePath())) {
                            if (log.isDebugEnabled()) {
                                log.debug(message);
                            }
                        } else {
                            //inform on the info level so that it's clear from the logs that the new file
                            //is going to be used.
                            log.info(message);
                        }
                    }
                } else {
                    log.info("Found agent plugin in the DB that we do not yet have: " + name);
                    Plugin plugin = new Plugin(name, path, md5);
                    plugin.setMtime(mtime);
                    plugin.setVersion(version);
                    updatedPlugins.add(plugin);
                    this.agentPluginsOnFilesystem.remove(expectedFile); // paranoia, make sure the cache doesn't have this
                }
            }
            JDBCUtil.safeClose(ps, rs);

            // write all our updated plugins to the file system
            if (!updatedPlugins.isEmpty()) {
                ps = conn.prepareStatement("SELECT CONTENT FROM " + Plugin.TABLE_NAME
                    + " WHERE DEPLOYMENT = 'AGENT' AND NAME = ? AND ENABLED = ?");
                for (Plugin plugin : updatedPlugins) {
                    File file = new File(this.agentPluginDeployer.getPluginDir(), plugin.getPath());

                    ps.setString(1, plugin.getName());
                    setEnabledFlag(conn, ps, 2, true);
                    rs = ps.executeQuery();
                    rs.next();
                    InputStream content = rs.getBinaryStream(1);
                    StreamUtil.copy(content, new FileOutputStream(file));
                    rs.close();
                    file.setLastModified(plugin.getMtime()); // so our file matches the database mtime
                    updatedFiles.add(file);
                }
            }
        } finally {
            JDBCUtil.safeClose(conn, ps, rs);
View Full Code Here

            // determine if we need to upgrade any of our current plugins to the latest versions
            for (Plugin latest_plugin : latest_plugins) {
                String plugin_filename = latest_plugin.getPath();
                latest_plugins_map.put(plugin_filename, latest_plugin);
                Plugin current_plugin = current_plugins.get(plugin_filename);

                if (current_plugin == null) {
                    updated_plugins.add(latest_plugin); // we don't have any version of this plugin, we'll need to get it
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(AgentI18NResourceKeys.NEED_MISSING_PLUGIN, plugin_filename);
                    }
                } else {
                    if (latest_plugin.isEnabled() && !disabled_plugin_names.contains(latest_plugin.getName())) {
                        String latest_md5 = latest_plugin.getMD5();
                        String current_md5 = current_plugin.getMD5();

                        if (!current_md5.equals(latest_md5)) {
                            updated_plugins.add(latest_plugin);
                            if (LOG.isDebugEnabled()) {
                                LOG.debug(AgentI18NResourceKeys.PLUGIN_NEEDS_TO_BE_UPDATED, plugin_filename, current_md5,
View Full Code Here

        File[] plugin_files = plugin_dir.listFiles();

        for (File plugin_file : plugin_files) {
            String plugin_filename = plugin_file.getName();
            if (plugin_filename.endsWith(".jar")) {
                Plugin cur_plugin = new Plugin(plugin_filename, plugin_filename);
                cur_plugin.setMD5(MessageDigestGenerator.getDigestString(plugin_file));
                plugins.put(plugin_filename, cur_plugin);
            }
        }

        return plugins;
View Full Code Here

    @Override
    public Plugin getPlugin(String name) {
        Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
        query.setParameter("name", name);
        Plugin result = null;
        try {
            result = (Plugin) query.getSingleResult();
        } catch (NoResultException e) {
            result = null;
        }
View Full Code Here

            }
            return false;
        }

        //check that all the servers have acked the deletion
        Plugin inDbPlugin = entityManager.find(Plugin.class, plugin.getId());

        @SuppressWarnings("unchecked")
        List<Server> allServers = entityManager.createNamedQuery(Server.QUERY_FIND_ALL).getResultList();

        for (Server s : allServers) {
            if (!inDbPlugin.getServersAcknowledgedDelete().contains(s)) {
                if (log.isDebugEnabled()) {
                    log.debug(plugin + " is not ready to be purged. Server " + s +
                        " has not acknowledged it knows about its deletion.");
                }
                return false;
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.plugin.Plugin

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.