Package org.rhq.core.domain.plugin

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


        assert !pluginKeys.contains(p1key) : pluginKeys;
        assert !pluginKeys.contains(p2key) : pluginKeys;
    }

    private ServerPlugin registerPlugin(int index, Configuration pluginConfiguration) throws Exception {
        ServerPlugin plugin = new ServerPlugin(0, TEST_PLUGIN_NAME_PREFIX + index, TEST_PLUGIN_JAR_NAME, "displayName",
            true,
            PluginStatusType.INSTALLED, "description", "help", "md5", "version", "ampsVersion",
            pluginConfiguration, createScheduledJobsConfiguration(), new ServerPluginType(
                GenericPluginDescriptorType.class).stringify(), System.currentTimeMillis(), System.currentTimeMillis());

        plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
        assert plugin.getId() > 0;
        assert plugin.isEnabled() == true;
        assert plugin.getDeployment() == PluginDeploymentType.SERVER;
        assert plugin.getStatus() == PluginStatusType.INSTALLED;
        assert plugin.getPluginConfiguration() != null;
        assert plugin.getScheduledJobsConfiguration() != null;
        assert plugin.getType().equals(new ServerPluginType(GenericPluginDescriptorType.class).stringify());
        return plugin;
    }
View Full Code Here


                scheduledJobsConfig = configDef.getDefaultTemplate().createConfiguration();
            }

            File pluginFile = new File(pluginUrl.toURI());
            PluginKey pluginKey = PluginKey.createServerPluginKey(new ServerPluginType(pluginDescriptor).stringify(), pluginDescriptor.getName());
            ServerPlugin plugin =
                new ServerPlugin(0, pluginKey.getPluginName(), pluginFile.getName(),
                    pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED,
                    pluginDescriptor.getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile),
                    pluginDescriptor.getVersion(), pluginDescriptor.getVersion(), pluginConfig,
                    scheduledJobsConfig, new ServerPluginType(pluginDescriptor).stringify(),
                    System.currentTimeMillis(), System.currentTimeMillis());
View Full Code Here

            ComparableVersion version; // this must be non-null, the next line ensures this
            version = ServerPluginDescriptorUtil.getPluginVersion(pluginFile, descriptor);

            log.debug("Registering server plugin [" + pluginName + "], version " + version);

            ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
            plugin.setDisplayName((displayName != null) ? displayName : pluginName);
            plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
            plugin.setDescription(descriptor.getDescription());
            plugin.setMtime(pluginFile.lastModified());
            plugin.setVersion(version.toString());
            plugin.setAmpsVersion(descriptor.getApiVersion());
            plugin.setMD5(MessageDigestGenerator.getDigestString(pluginFile));
            plugin.setPluginConfiguration(getDefaultPluginConfiguration(descriptor));
            plugin.setScheduledJobsConfiguration(getDefaultScheduledJobsConfiguration(descriptor));
            plugin.setType(new ServerPluginType(descriptor).stringify());

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

            ServerPluginManagerLocal serverPluginsManager = LookupUtil.getServerPluginManager();

            // see if this plugin has been deleted previously; if so, don't register and delete the file
            PluginKey newPluginKey = new PluginKey(plugin);
            PluginStatusType status = serverPluginsManager.getServerPluginStatus(newPluginKey);

            if (PluginStatusType.DELETED == status) {
                log.warn("Plugin file [" + pluginFile + "] has been detected but that plugin with name [" + pluginName
                    + "] was previously undeployed. Will not re-register that plugin and the file will be deleted.");
                boolean succeeded = pluginFile.delete();
                if (!succeeded) {
                    log.error("Failed to delete obsolete plugin file [" + pluginFile + "].");
                }
            } else {
                // now attempt to register the plugin. "dbPlugin" will be the new updated plugin; but if
                // the scanned plugin does not obsolete the current plugin, then dbPlugin will be the old, still valid, plugin.
                SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
                ServerPlugin dbPlugin = serverPluginsManager.registerServerPlugin(subjectManager.getOverlord(), plugin,
                    pluginFile);
                log.info("Registered server plugin [" + dbPlugin.getName() + "], version " + dbPlugin.getVersion());
            }
        } catch (Exception e) {
            log.error("Failed to register server plugin file [" + pluginFile + "]", e);
        }
        return;
View Full Code Here

        // now insert new cache items representing new jar files and update existing ones as appropriate
        for (File pluginJar : pluginJars) {
            String md5 = null;

            PluginWithDescriptor pluginWithDescriptor = this.serverPluginsOnFilesystem.get(pluginJar);
            ServerPlugin plugin = null;
            if (pluginWithDescriptor != null) {
                plugin = pluginWithDescriptor.plugin;
            }

            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) {
                    cacheFilesystemServerPluginJar(pluginJar, md5);
                    updated.add(pluginJar);
                }
            } catch (Exception e) {
                log.warn("Failed to scan server plugin [" + pluginJar + "] found on filesystem. Skipping. Cause: " + e);
                this.serverPluginsOnFilesystem.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, ServerPlugin> pluginsByName = new HashMap<String, ServerPlugin>(); // key on (name+type), not just name
        for (Entry<File, PluginWithDescriptor> currentPluginFileEntry : this.serverPluginsOnFilesystem.entrySet()) {
            ServerPlugin currentPlugin = currentPluginFileEntry.getValue().plugin;
            ServerPlugin existingPlugin = pluginsByName.get(currentPlugin.getName() + currentPlugin.getType());
            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.getType(), currentPlugin);
            } else {
                ServerPlugin obsolete = ServerPluginDescriptorUtil.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.getServerPluginDir(), obsolete.getPath()));
                if (obsolete == existingPlugin) { // yes use == for reference equality!
                    pluginsByName.put(currentPlugin.getName() + currentPlugin.getType(), currentPlugin); // override the original one we saw with this latest one
                }
            }
        }
View Full Code Here

        }
        URL pluginUrl = pluginJar.toURI().toURL();
        ServerPluginDescriptorType descriptor = ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
        String version = ServerPluginDescriptorUtil.getPluginVersion(pluginJar, descriptor).toString();
        String name = descriptor.getName();
        ServerPlugin plugin = new ServerPlugin(name, pluginJar.getName());
        plugin.setType(new ServerPluginType(descriptor).stringify());
        plugin.setMd5(md5);
        plugin.setVersion(version);
        plugin.setMtime(pluginJar.lastModified());
        this.serverPluginsOnFilesystem.put(pluginJar, new PluginWithDescriptor(plugin, descriptor));
        return plugin;
    }
View Full Code Here

                    }
                }
            }

            if (pluginWithDescriptor != null && currentFile != null && currentFile.exists()) {
                ServerPlugin dbPlugin = new ServerPlugin(name, path);
                dbPlugin.setType(pluginType.stringify());
                dbPlugin.setMd5(md5);
                dbPlugin.setVersion(version);
                dbPlugin.setMtime(mtime);

                ServerPlugin obsoletePlugin = ServerPluginDescriptorUtil.determineObsoletePlugin(dbPlugin,
                    pluginWithDescriptor.plugin);

                if (obsoletePlugin == pluginWithDescriptor.plugin) { // yes use == for reference equality!
                    StringBuilder logMsg = new StringBuilder();
                    logMsg.append("Found server 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(pluginWithDescriptor.plugin.getMd5());
                    logMsg.append("]; DB version=[").append(version);
                    logMsg.append("]; file version=[").append(pluginWithDescriptor.plugin.getVersion());
                    logMsg.append("]; DB timestamp=[").append(new Date(mtime));
                    logMsg.append("]; file timestamp=[").append(new Date(pluginWithDescriptor.plugin.getMtime()));
                    logMsg.append("]");
                    log.info(logMsg.toString());

                    updatedPlugins.add(dbPlugin);

                    if (currentFile.delete()) {
                        log.info("Deleted the obsolete server plugin file to be updated: " + currentFile);
                        this.serverPluginsOnFilesystem.remove(currentFile);
                    } else {
                        log.warn("Failed to delete the obsolete (to-be-updated) server plugin: " + currentFile);
                    }
                } 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
                    boolean succeeded = currentFile.setLastModified(mtime);
                    if (!succeeded && log.isDebugEnabled()) {
                        log.debug("Failed to set mtime to [" + new Date(mtime) + "] on file [" + currentFile + "].");
                    }
                    pluginWithDescriptor.plugin.setMtime(mtime);
                    pluginWithDescriptor.plugin.setVersion(version);
                    pluginWithDescriptor.plugin.setMd5(md5);
                } else {
                    log.info("It appears that the server plugin [" + dbPlugin
                        + "] in the database may be obsolete. If so, it will be updated later.");
                }
            } else {
                log.info("Found server plugin in the DB that we do not yet have: " + name);
                ServerPlugin plugin = new ServerPlugin(name, path, md5);
                plugin.setType(pluginType.stringify());
                plugin.setMtime(mtime);
                plugin.setVersion(version);
                updatedPlugins.add(plugin);
                this.serverPluginsOnFilesystem.remove(expectedFile); // paranoia, make sure the cache doesn't have this
            }
        }

        // write all our updated plugins to the file system
        if (!updatedPlugins.isEmpty()) {
            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;

            try {
                DataSource ds = LookupUtil.getDataSource();
                conn = ds.getConnection();

                ps = conn.prepareStatement("SELECT CONTENT FROM " + ServerPlugin.TABLE_NAME
                    + " WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' AND NAME = ? AND PTYPE = ?");
                for (ServerPlugin plugin : updatedPlugins) {
                    File file = new File(this.getServerPluginDir(), plugin.getPath());

                    ps.setString(1, plugin.getName());
                    ps.setString(2, plugin.getType());
                    rs = ps.executeQuery();
                    rs.next();
                    InputStream content = rs.getBinaryStream(1);
                    StreamUtil.copy(content, new FileOutputStream(file));
                    rs.close();
                    boolean succeeded = file.setLastModified(plugin.getMtime());// so our file matches the database mtime
                    if (!succeeded && log.isDebugEnabled()) {
                        log.debug("Failed to set mtime to [" + plugin.getMtime() + "] on file [" + file + "].");
                    }
                    updatedFiles.add(file);

                    // we are writing a new file to the filesystem, cache it since we know about it now
                    cacheFilesystemServerPluginJar(file, null);
View Full Code Here

        File dataDir = new File(masterConfig.getDataDirectory(), pluginName);
        File tmpDir = masterConfig.getTemporaryDirectory();
        Configuration pluginConfig = null;
        List<ScheduledJobDefinition> schedules;
        try {
            ServerPlugin plugin = getPlugin(env);
            pluginConfig = plugin.getPluginConfiguration();
            Configuration scheduledJobsConfig = plugin.getScheduledJobsConfiguration();
            schedules = ServerPluginDescriptorMetadataParser.getScheduledJobs(scheduledJobsConfig);
        } catch (Exception e) {
            throw new RuntimeException("Failed to get plugin config/schedules from the database", e);
        }
View Full Code Here

     * @return the ServerPlugin object for the given plugin
     */
    protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
        // get the plugin data from the database
        ServerPluginManagerLocal serverPluginsManager = LookupUtil.getServerPluginManager();
        ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey());
        plugin = serverPluginsManager.getServerPluginRelationships(plugin);
        return plugin;
    }
View Full Code Here

        ServerPluginContext ctx = getServerPluginContext(env);
        PluginKey key = ctx.getPluginEnvironment().getPluginKey();

        ServerPluginManagerLocal pluginsMgr = LookupUtil.getServerPluginManager();
        ServerPlugin plugin = pluginsMgr.getServerPlugin(key);
        plugin = pluginsMgr.getServerPluginRelationships(plugin);

        sender.preferences = getNewOrCleansed(plugin.getPluginConfiguration());
        sender.pluginComponent = getServerPluginComponent(key.getPluginName());
        sender.serverPluginEnvironment = pluginEnvByName.get(senderName);

        return sender;
    }
View Full Code Here

            throw new IllegalArgumentException("Plugin [" + plugin.getName()
                + "] must be a server plugin to be registered");
        }

        PluginKey pluginKey = new PluginKey(plugin);
        ServerPlugin existingPlugin = null;
        boolean newOrUpdated = false;

        existingPlugin = getServerPlugin(pluginKey);
        if (existingPlugin == null) {
            newOrUpdated = true; // this is expected for new plugins
        }

        if (existingPlugin != null) {
            if (existingPlugin.getStatus() == PluginStatusType.DELETED) {
                throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
                    + "], it has been marked as deleted");
            }
            ServerPlugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
            if (obsolete == existingPlugin) { // yes use == for reference equality

                // in order to keep the same configuration that the old plugin had, let's set the new plugin's config objects
                // TODO: what happens if the plugin's metadata changes? we should clean the old config of old properties.
                plugin.setPluginConfiguration(existingPlugin.getPluginConfiguration());
View Full Code Here

TOP

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

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.