Package org.rhq.core.clientapi.agent

Examples of org.rhq.core.clientapi.agent.PluginContainerException


     */
    public static CannedGroupExpressions loadCannedExpressionsFromUrl(URL pluginJarFileUrl) throws PluginContainerException {
        final Log logger = LogFactory.getLog(AgentPluginDescriptorUtil.class);

        if (pluginJarFileUrl == null) {
            throw new PluginContainerException("A valid plugin JAR URL must be supplied.");
        }
        logger.debug("Loading plugin additions from plugin jar at [" + pluginJarFileUrl + "]...");
        ValidationEventCollector validationEventCollector = new ValidationEventCollector();
        testPluginJarIsReadable(pluginJarFileUrl);

        JarInputStream jis = null;
        JarEntry descriptorEntry = null;
        try {
            jis = new JarInputStream(pluginJarFileUrl.openStream());
            JarEntry nextEntry = jis.getNextJarEntry();
            while (nextEntry != null && descriptorEntry == null) {
                if (CANNED_GROUP_EXPRESSION_DESCRIPTOR_PATH.equals(nextEntry.getName())) {
                    descriptorEntry = nextEntry;
                } else {
                    jis.closeEntry();
                    nextEntry = jis.getNextJarEntry();
                }
            }

            if (descriptorEntry == null) {
                logger.debug("Plugin additions not found");
                // plugin additions are optional thing
                return null;
            }
            return parseCannedGroupExpressionsDescriptor(jis, validationEventCollector);
        } catch (Exception e) {
            throw new PluginContainerException("Could not parse the plugin additions ["
                + CANNED_GROUP_EXPRESSION_DESCRIPTOR_PATH + "] found in plugin jar at [" + pluginJarFileUrl + "].",
                new WrappedRemotingException(e));
        } finally {
            if (jis != null) {
                try {
View Full Code Here


    public static PluginDescriptor loadPluginDescriptorFromUrl(URL pluginJarFileUrl) throws PluginContainerException {

        final Log logger = LogFactory.getLog(AgentPluginDescriptorUtil.class);

        if (pluginJarFileUrl == null) {
            throw new PluginContainerException("A valid plugin JAR URL must be supplied.");
        }
        logger.debug("Loading plugin descriptor from plugin jar at [" + pluginJarFileUrl + "]...");

        testPluginJarIsReadable(pluginJarFileUrl);

        JarInputStream jis = null;
        JarEntry descriptorEntry = null;
        ValidationEventCollector validationEventCollector = new ValidationEventCollector();
        try {
            jis = new JarInputStream(pluginJarFileUrl.openStream());
            JarEntry nextEntry = jis.getNextJarEntry();
            while (nextEntry != null && descriptorEntry == null) {
                if (PLUGIN_DESCRIPTOR_PATH.equals(nextEntry.getName())) {
                    descriptorEntry = nextEntry;
                } else {
                    jis.closeEntry();
                    nextEntry = jis.getNextJarEntry();
                }
            }

            if (descriptorEntry == null) {
                throw new Exception("The plugin descriptor does not exist");
            }

            return parsePluginDescriptor(jis, validationEventCollector);
        } catch (Exception e) {
            throw new PluginContainerException("Could not successfully parse the plugin descriptor ["
                + PLUGIN_DESCRIPTOR_PATH + "] found in plugin jar at [" + pluginJarFileUrl + "].",
                new WrappedRemotingException(e));
        } finally {
            if (jis != null) {
                try {
View Full Code Here

            ValidationEventCollector validationEventCollector, String xsd, String jaxbPackage) throws PluginContainerException {
        JAXBContext jaxbContext;
        try {
            jaxbContext = JAXBContext.newInstance(jaxbPackage);
        } catch (Exception e) {
            throw new PluginContainerException("Failed to create JAXB Context.", new WrappedRemotingException(e));
        }

        Unmarshaller unmarshaller;
        try {
            unmarshaller = jaxbContext.createUnmarshaller();
            // Enable schema validation
            URL pluginSchemaURL = AgentPluginDescriptorUtil.class.getClassLoader().getResource(xsd);
            Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
                    pluginSchemaURL);
            unmarshaller.setSchema(pluginSchema);
            unmarshaller.setEventHandler(validationEventCollector);

            return unmarshaller.unmarshal(is);
        } catch (JAXBException e) {
            throw new PluginContainerException(e);
        } catch (SAXException e) {
            throw new PluginContainerException(e);
        }
    }
View Full Code Here

    private static void testPluginJarIsReadable(URL pluginJarFileUrl) throws PluginContainerException {
        InputStream inputStream = null;
        try {
            inputStream = pluginJarFileUrl.openStream();
        } catch (IOException e) {
            throw new PluginContainerException("Unable to open plugin jar at [" + pluginJarFileUrl + "] for reading.");
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
View Full Code Here

        public void updatePluginConfiguration(int resourceId, Configuration newPluginConfiguration)
            throws InvalidPluginConfigurationClientException, PluginContainerException {
            PropertySimple mybool = newPluginConfiguration.getSimple("fail");
            if ((mybool != null) && mybool.getBooleanValue()) {
                throw new PluginContainerException("Simulates a failure to update plugin config");
            }

            return;
        }
View Full Code Here

                operationName, operationComponent, operationServerService, operationGateway, operationDefinition);

            operationGateway.submit(theJob[0]);
        } catch (Exception e) {
            log.warn("Failed to submit operation invocation request", e);
            throw new PluginContainerException("Failed to submit invocation request. resource=[" + resourceId
                + "], operation=[" + operationName + "], jobId=[" + jobId + "]", new WrappedRemotingException(e));
        }

        return;
    }
View Full Code Here

                    Long timeout = timeoutProperty.getLongValue();
                    if (timeout != null) {
                        return timeout * 1000L;
                    }
                } catch (Exception e) {
                    throw new PluginContainerException("The timeout specified in the configuration was invalid: "
                        + timeoutProperty);
                }
            }
        }

View Full Code Here

    @Override
    public void updatePluginConfiguration(int resourceId, Configuration newPluginConfiguration)
        throws InvalidPluginConfigurationClientException, PluginContainerException {
        ResourceContainer container = getResourceContainer(resourceId);
        if (container == null) {
            throw new PluginContainerException("Cannot update plugin configuration for unknown Resource with id ["
                + resourceId + "]");
        }

        Resource resource = container.getResource();
        // First stop the resource component.
View Full Code Here

                if (discoveredResourceDetails == null) {
                    log.info("Plugin Error: During manual add, discovery component method ["
                        + discoveryComponent.getClass().getName() + ".discoverResource()] returned null "
                        + "(either the Resource type was blacklisted or the plugin developer "
                        + "did not implement support for manually discovered Resources correctly).");
                    throw new PluginContainerException("The [" + resourceType.getPlugin()
                        + "] plugin does not properly support manual addition of [" + resourceType.getName()
                        + "] Resources.");
                }
            } else {
                // The plugin is using the old manual add API, which we must continue to support to maintain
                // backward compatibility.
                log.info("Plugin Warning: Resource type '" + resourceType.getName() + "' from '"
                    + resourceType.getPlugin() + "' is still using the deprecated manual Resource add API, "
                    + "rather than the new ManualAddFacet interface.");
                List<Configuration> pluginConfigurations = new ArrayList<Configuration>(1);
                pluginConfigurations.add(pluginConfiguration);
                ResourceDiscoveryContext<ResourceComponent<?>> discoveryContext = new ResourceDiscoveryContext<ResourceComponent<?>>(
                    resourceType, parentResourceComponent, parentResourceContainer.getResourceContext(),
                    SystemInfoFactory.createSystemInfo(), new ArrayList<ProcessScanResult>(0), pluginConfigurations,
                    this.configuration.getContainerName(), this.configuration.getPluginContainerDeployment());

                // Ask the plugin's discovery component to find the new resource, throwing exceptions if it cannot be
                // found at all.
                try {
                    Set<DiscoveredResourceDetails> discoveredResources = invokeDiscoveryComponent(
                        parentResourceContainer, discoveryComponent, discoveryContext);
                    if ((discoveredResources == null) || discoveredResources.isEmpty()) {
                        log.info("Plugin Error: During manual add, discovery component method ["
                            + discoveryComponent.getClass().getName() + ".discoverResources()] returned "
                            + discoveredResources + " when passed a single plugin configuration "
                            + "(either the resource type was blacklisted or the plugin developer "
                            + "did not implement support for manually discovered resources correctly).");
                        throw new PluginContainerException("The [" + resourceType.getPlugin()
                            + "] plugin does not properly support manual addition of [" + resourceType.getName()
                            + "] resources.");
                    }
                    discoveredResourceDetails = discoveredResources.iterator().next();
                } catch (DiscoverySuspendedException e) {
                    String message = "The discovery class ["
                        + discoveryComponent.getClass().getName()
                        + "]"
                        + " uses a legacy implementation of \"manual add\" functionality. Some of the child resources"
                        + " with the resource type ["
                        + resourceType
                        + "] under the parent resource ["
                        + parentResourceContainer.getResource()
                        + "]"
                        + " failed to upgrade, which makes it impossible to support the legacy manual-add implementation. Either upgrade the plugin ["
                        + resourceType.getPlugin()
                        + "] to successfully upgrade all resources or consider implementing the ManualAdd facet.";
                    log.info(message);
                    throw new PluginContainerException(message, e);
                }
            }

            // Create the new Resource and add it to inventory if it isn't already there.
            resource = createNewResource(discoveredResourceDetails);
            Resource parentResource = getResourceContainer(parentResourceId).getResource();
            Resource existingResource = findMatchingChildResource(resource, parentResource);
            if (existingResource != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Manual add for resource type [" + resourceType.getName() + "] and parent resource id ["
                        + parentResourceId
                        + "] found a resource that already exists in inventory - updating existing resource ["
                        + existingResource + "]");
                }
                resourceAlreadyExisted = true;
                resource = existingResource;
                if (resource.getInventoryStatus() != InventoryStatus.COMMITTED) {
                    resource.setPluginConfiguration(pluginConfiguration);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Adding manually discovered resource [" + resource + "] to inventory...");
                }
                resource.setInventoryStatus(InventoryStatus.COMMITTED);
                parentResource.addChildResourceWithoutAncestry(resource);
                initResourceContainer(resource);
            }

            // Make sure the resource's component is activated (i.e. started).
            boolean newPluginConfig = true;
            ResourceContainer resourceContainer = getResourceContainer(resource);
            if (log.isDebugEnabled()) {
                log.debug("Activating resource [" + resource + "]...");
            }

            // NOTE: We don't mess with inventory status - that's the server's responsibility.

            // Tell the server to merge the resource into its inventory.
            DiscoveryServerService discoveryServerService = this.configuration.getServerServices()
                .getDiscoveryServerService();
            mergeResourceResponse = discoveryServerService.addResource(resource, ownerSubjectId);

            // Sync our local resource up with the one now in server inventory. Treat this like a newlyCommittedResource
            // - set mtime (same as ctime for a new resource) to ensure this does not get picked up in an inventory sync
            //   pass, we know we're currently in sync with the server.
            resource.setId(mergeResourceResponse.getResourceId());
            resource.setMtime(mergeResourceResponse.getMtime());
            Set newResources = new LinkedHashSet<Resource>();
            newResources.add(resource);
            postProcessNewlyCommittedResources(newResources);
            performServiceScan(resource.getId());

            // Note that it is important to activate the resource *AFTER* it has been synced with the
            // server so that the resource has a valid id (which is needed by at least the content
            // subsystem).
            try {
                activateResource(resource, resourceContainer, newPluginConfig);
            } catch (Throwable t) {
                // if it fails to start keep going, we already have the resource in inventory and
                // we are in sync with the server. The new resource will be unavailable but at least
                // it will be accessible and editable by the user. Report the start exception at the end.
                handleInvalidPluginConfigurationResourceError(resource, t);
                throw new PluginContainerException("The resource [" + resource
                    + "] has been added but could not be started. Verify the supplied configuration values: ", t);
            }
        }

        // Catch any other RuntimeExceptions or Errors, so the server doesn't have to worry about deserializing or
        // catching them. Before rethrowing, wrap them in a WrappedRemotingException and then wrap that in either an
        // InvalidPluginConfigurationException or a PluginContainerException.
        catch (Throwable t) {
            if ((resource != null) && !resourceAlreadyExisted && (getResourceContainer(resource) != null)) {
                // If the resource got added to inventory, roll it back (i.e. deactivate it, then remove it from inventory).
                if (log.isDebugEnabled()) {
                    log.debug("Rolling back manual add of resource of type [" + resourceType.getName()
                        + "] - removing resource with id [" + resource.getId() + "] from inventory...");
                }
                deactivateResource(resource);
                uninventoryResource(resource.getId());
            }

            if (t instanceof InvalidPluginConfigurationException) {
                String errorMessage = "Unable to connect to managed resource of type [" + resourceType.getName()
                    + "] using the specified connection properties - resource will not be added to inventory.";
                log.info(errorMessage, t);

                // In the exception we throw over to the server, strip the InvalidPluginConfigurationException out of the
                // stack trace, but append the message from that exception to the message of the exception we throw. This
                // will make for a nicer error message for the server to display in the UI.
                errorMessage += ((t.getLocalizedMessage() != null) ? (" " + t.getLocalizedMessage()) : "");
                throw new InvalidPluginConfigurationClientException(errorMessage,
                    (t.getCause() != null) ? new WrappedRemotingException(t.getCause()) : null);
            } else {
                log.error("Manual add failed for resource of type [" + resourceType.getName()
                    + "] and parent resource id [" + parentResourceId + "]", t);
                throw new PluginContainerException("Failed to add resource with type [" + resourceType.getName()
                    + "] and parent resource id [" + parentResourceId + "]", new WrappedRemotingException(t));
            }
        }

        return mergeResourceResponse;
View Full Code Here

            }
            try {
                // should not throw ResourceTypeNotEnabledException because we checked for that above - if it does, just handle it as an error
                component = pluginFactory.buildResourceComponent(resource);
            } catch (Throwable e) {
                throw new PluginContainerException("Could not build component for Resource [" + resource + "]", e);
            }
            container.setResourceComponent(component);
        }

        // Start the resource, but only if its parent component is running. If the parent is null, that means
View Full Code Here

TOP

Related Classes of org.rhq.core.clientapi.agent.PluginContainerException

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.