Package org.rhq.enterprise.server.plugin.pc

Examples of org.rhq.enterprise.server.plugin.pc.ServerPluginType


            if (configDef != null) {
                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());
            return plugin;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here


                File pluginFile = new File(env.getPluginUrl().toURI());
                ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().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());
                return plugin;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
View Full Code Here

        PluginStatusType status;

        PluginKey missingKey;
        missingKey = new PluginKey(PluginDeploymentType.SERVER,
            new ServerPluginType(GenericPluginDescriptorType.class).stringify(), TEST_PLUGIN_NAME_PREFIX + "1");
        status = this.serverPluginsBean.getServerPluginStatus(missingKey);
        assert status == null;
        missingKey = new PluginKey(PluginDeploymentType.SERVER,
            new ServerPluginType(GenericPluginDescriptorType.class).stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
        status = this.serverPluginsBean.getServerPluginStatus(missingKey);
        assert status == null;

        ServerPlugin p1 = registerPlugin(1);
        ServerPlugin p2 = registerPlugin(2);
View Full Code Here

        PluginStatusType status;

        PluginKey missingKey;
        missingKey = new PluginKey(PluginDeploymentType.SERVER,
            new ServerPluginType(GenericPluginDescriptorType.class).stringify(), TEST_PLUGIN_NAME_PREFIX + "1");
        status = this.serverPluginsBean.getServerPluginStatus(missingKey);
        assert status == null;
        missingKey = new PluginKey(PluginDeploymentType.SERVER,
            new ServerPluginType(GenericPluginDescriptorType.class).stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
        status = this.serverPluginsBean.getServerPluginStatus(missingKey);
        assert status == null;

        ServerPlugin p1 = registerPlugin(1);
        ServerPlugin p2 = registerPlugin(2);
View Full Code Here

    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

            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)));
            }
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

            String name = installedPlugin.getName();
            String path = installedPlugin.getPath();
            String md5 = installedPlugin.getMd5();
            long mtime = installedPlugin.getMtime();
            String version = installedPlugin.getVersion();
            ServerPluginType pluginType = new ServerPluginType(installedPlugin.getType());

            // 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.getServerPluginDir(), path);
            File currentFile = null; // will be non-null if we find that we have this plugin on the filesystem already
            PluginWithDescriptor pluginWithDescriptor = this.serverPluginsOnFilesystem.get(expectedFile);

            if (pluginWithDescriptor != null) {
                currentFile = expectedFile; // we have it where we are expected to have it
                if (!pluginWithDescriptor.plugin.getName().equals(name)
                    || !pluginType.equals(pluginWithDescriptor.pluginType)) {
                    // Happens if someone wrote a plugin of one type but later changed it to a different type (or changed names)
                    log.warn("For some reason, the server plugin file [" + expectedFile + "] is plugin ["
                        + pluginWithDescriptor.plugin.getName() + "] of type [" + pluginWithDescriptor.pluginType
                        + "] but the database says it should be [" + name + "] of type [" + pluginType + "]");
                } else {
                    log.debug("File system and db agree on server 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, PluginWithDescriptor> cacheEntry : this.serverPluginsOnFilesystem.entrySet()) {
                    if (cacheEntry.getValue().plugin.getName().equals(name)
                        && cacheEntry.getValue().pluginType.equals(pluginType)) {
                        currentFile = cacheEntry.getKey();
                        pluginWithDescriptor = cacheEntry.getValue();
                        log.info("Filesystem has a server 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 (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
            }
View Full Code Here

    private class PluginWithDescriptor {
        public PluginWithDescriptor(ServerPlugin plugin, ServerPluginDescriptorType descriptor) {
            this.plugin = plugin;
            this.descriptor = descriptor;
            this.pluginType = new ServerPluginType(descriptor);
        }
View Full Code Here

        super(master);
    }

    @Override
    public ServerPluginType getSupportedServerPluginType() {
        return new ServerPluginType(DriftPluginDescriptorType.class);
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.plugin.pc.ServerPluginType

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.