Package org.rhq.core.pc.inventory

Examples of org.rhq.core.pc.inventory.ResourceContainer$ComponentInvocation


     */
    @Override
    public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDefinition) {

        // get the resource entity stored in our local inventory
        ResourceContainer container = inventoryManager.getResourceContainer(resourceId);

        if (container == null) {
            log.error("Cannot determine base directory for " + driftDefinition + ". No resource container found " +
                "for resource id " + resourceId + ". You may want to restart the agent with the -u option so that " +
                "the agent's local inventory is synchronized with and consistent with the server's inventory.");
            throw new IllegalArgumentException("Cannot determine base directory for " + driftDefinition +
                ". No resource container found for resource id " + resourceId);
        }

        Resource resource = container.getResource();

        // find out the type of base location that is specified by the drift def
        DriftDefinition.BaseDirectory baseDir = driftDefinition.getBasedir();
        if (baseDir == null) {
            throw new IllegalArgumentException("Base directory is null for drift definition ["
View Full Code Here


            typeResourceMap.put(serverTypeFS, serverFS);
            typeResourceMap.put(serverTypePC, serverPC);
            typeResourceMap.put(serverTypeRC, serverRC);
            typeResourceMap.put(serverTypeMT, serverMT);

            ResourceContainer platformContainer = new ResourceContainer(platform, null);
            ResourceContainer bundleHandlerContainer = new ResourceContainer(bundleHandler, null);
            ResourceContainer serverContainerFS = new ResourceContainer(serverFS, null);
            ResourceContainer serverContainerPC = new ResourceContainer(serverPC, null);
            ResourceContainer serverContainerRC = new ResourceContainer(serverRC, null);
            ResourceContainer serverContainerMT = new ResourceContainer(serverMT, null);
            idResourceContainerMap.put(platform.getId(), platformContainer);
            idResourceContainerMap.put(bundleHandler.getId(), bundleHandlerContainer);
            idResourceContainerMap.put(serverFS.getId(), serverContainerFS);
            idResourceContainerMap.put(serverPC.getId(), serverContainerPC);
            idResourceContainerMap.put(serverRC.getId(), serverContainerRC);
            idResourceContainerMap.put(serverMT.getId(), serverContainerMT);

            bundleHandlerContainer.setResourceContext(new MockResourceContext(bundleHandler));

            // each different resource type that supports bundle deployments needs to define its
            // bundle configuration to denote where the base directory location is found.
            // Today we support four ways: via plugin config property, resource config property,
            // measurement trait value, or strictly on the root file system (using no resource specific value)
            ResourceTypeBundleConfiguration rtbc = new ResourceTypeBundleConfiguration(new Configuration());
            rtbc.addBundleDestinationBaseDirectory(BUNDLE_CONFIG_NAME_FS, Context.fileSystem.name(),
                BUNDLE_CONFIG_CONTEXT_VALUE_FS, null);
            serverTypeFS.setResourceTypeBundleConfiguration(rtbc);

            rtbc = new ResourceTypeBundleConfiguration(new Configuration());
            rtbc.addBundleDestinationBaseDirectory(BUNDLE_CONFIG_NAME_PC, Context.pluginConfiguration.name(),
                BUNDLE_CONFIG_CONTEXT_VALUE_PC, null);
            serverTypePC.setResourceTypeBundleConfiguration(rtbc);

            rtbc = new ResourceTypeBundleConfiguration(new Configuration());
            rtbc.addBundleDestinationBaseDirectory(BUNDLE_CONFIG_NAME_RC, Context.resourceConfiguration.name(),
                BUNDLE_CONFIG_CONTEXT_VALUE_RC, null);
            serverTypeRC.setResourceTypeBundleConfiguration(rtbc);

            rtbc = new ResourceTypeBundleConfiguration(new Configuration());
            rtbc.addBundleDestinationBaseDirectory(BUNDLE_CONFIG_NAME_MT, Context.measurementTrait.name(),
                BUNDLE_CONFIG_CONTEXT_VALUE_MT, null);
            serverTypeMT.setResourceTypeBundleConfiguration(rtbc);

            // each different resource needs to specify where exactly it wants the bundles deployed
            // using the different contexts that are supported.
            Configuration pluginConfiguration = new Configuration();
            pluginConfiguration.put(new PropertySimple(BUNDLE_CONFIG_CONTEXT_VALUE_PC, BUNDLE_CONFIG_LOCATION_PC));
            serverPC.setPluginConfiguration(pluginConfiguration);

            Configuration resourceConfiguration = new Configuration();
            resourceConfiguration.put(new PropertySimple(BUNDLE_CONFIG_CONTEXT_VALUE_RC, BUNDLE_CONFIG_LOCATION_RC));
            serverRC.setResourceConfiguration(resourceConfiguration);

            MeasurementDefinition definition = new MeasurementDefinition(serverTypeMT, BUNDLE_CONFIG_CONTEXT_VALUE_MT);
            definition.setDataType(DataType.TRAIT);
            definition.setId(123);
            MeasurementSchedule schedule = new MeasurementSchedule(definition, serverMT);
            schedule.setId(123123);
            MeasurementScheduleRequest scheduleRequest = new MeasurementScheduleRequest(schedule);
            Set<MeasurementScheduleRequest> schedules = new HashSet<MeasurementScheduleRequest>(1);
            schedules.add(scheduleRequest);
            serverContainerMT.setMeasurementSchedule(schedules);
        }
View Full Code Here

    @SuppressWarnings("unchecked")
    public static ResourceType getResourceType(int resourceId) throws PluginContainerException {
        InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();

        // get the resource container that wraps the given resource
        ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resourceId);
        if (resourceContainer == null) {
            throw new PluginContainerException("Resource component container could not be retrieved for resource: "
                + resourceId);
        }

        return resourceContainer.getResource().getResourceType();
    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static <T> T getComponent(int resourceId, Class<T> facetInterface, FacetLockType lockType, long timeout,
        boolean daemonThread, boolean onlyIfStarted, boolean transferInterrupt) throws PluginContainerException {
        InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
        ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resourceId);
        if (resourceContainer == null) {
            throw new PluginContainerException("Resource component container could not be retrieved for resource: "
                + resourceId);
        }
        return resourceContainer.createResourceComponentProxy(facetInterface, lockType, timeout, daemonThread,
            onlyIfStarted, transferInterrupt);
    }
View Full Code Here

                        return result;
                    }
                }); // wrap in new TreeSet to avoid CCMEs and to sort by type
                children.addAll(resource.getChildResources());
                for (Resource child : children) {
                    ResourceContainer childContainer;

                    if (inventoryFile == null) {
                        // get the child from the in-memory inventory
                        childContainer = inventoryManager.getResourceContainer(child);
                    } else {
View Full Code Here

            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            ClassLoaderManager clm = this.pluginContainer.getPluginManager().getClassLoaderManager();
            InventoryManager im = this.pluginContainer.getInventoryManager();
            classloaders = clm.getResourceClassLoaders();
            for (CanonicalResourceKey canonicalId : classloaders.keySet()) {
                ResourceContainer container = im.getResourceContainer(canonicalId);
                String[] nameId = new String[3];
                if (container != null) {
                    nameId[0] = container.getResource().getName();
                    nameId[1] = Integer.toString(container.getResource().getId());
                    nameId[2] = container.getResource().getUuid();
                } else {
                    nameId[0] = "<unknown>";
                    nameId[1] = "<unknown>";
                    nameId[2] = "<unknown>";
                }
View Full Code Here

        if (enabled && requests.size() > 0) {
            try {
                //check the validity of the upgrades now that we have a complete picture
                //about the changes and the inventory looks like it was already upgraded.
                for (ResourceUpgradeRequest request : requests) {
                    ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId());
                    if (container != null) {
                        Resource resource = container.getResource();
                        String upgradeErrors = null;
                        if ((upgradeErrors = checkUpgradeValid(resource, request)) != null) {
                            //the resource is in its upgraded state but it's going to get reverted back to the original state
                            //in the code below. Let's use the original resource for the error message so that we don't confuse
                            //the user.
                            ResourceUpgradeRequest orig = findOriginal(request);

                            //orig should never be null, but let's be paranoid
                            if (orig != null) {
                                orig.updateResource(resource);
                            }

                            String errorString = "Upgrading the resource [" + resource + "] using these updates ["
                                + request + "] would render the inventory invalid because of the following reasons: "
                                + upgradeErrors;

                            //now switch the resource back to the upgraded state for the rest of the code below again
                            request.updateResource(resource);

                            log.error(errorString);

                            IllegalStateException ex = new IllegalStateException(errorString);
                            ex.fillInStackTrace();

                            //set the error and clear out everything else, so that we send the error
                            //to the server and locally roll back to the previous state.
                            request.setErrorProperties(ex);
                            request.clearUpgradeData();

                            if (request.getUpgradeErrorMessage() != null) {
                                rememberFailure(resource);
                                inventoryManager.deactivateResource(resource);
                            }

                        }
                    }
                }

                //now before we talk to server and sync up the upgraded data,
                //reset the resources to their original values so that any changes
                //the server makes to the upgrade data are applied to the "vanilla" state
                //of the resources. i.e we only want to make changes the server approves.
                for (ResourceUpgradeRequest request : originalResourceData) {
                    ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId());
                    if (container != null) {
                        Resource resource = container.getResource();
                        request.updateResource(resource);
                    }
                }

                //merge the resources with the data as received from the server
                //(this can differ from what the upgrade "wants" because the server is
                //free to disallow some changes, e.g. resource name change)
                inventoryManager.mergeResourcesFromUpgrade(requests);

                //and now restart all the "touched" resources with the true intended
                //data
                for (ResourceUpgradeRequest request : requests) {
                    ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId());
                    if (container != null) {
                        Resource resource = container.getResource();
                        try {
                            inventoryManager.activateResource(resource, container, true);
                        } catch (InvalidPluginConfigurationException e) {
                            log.debug("Resource [" + resource + "] failed to start up after upgrade.", e);
                            inventoryManager.handleInvalidPluginConfigurationResourceError(resource, e);
                        } catch (Throwable t) {
                            log.error("Failed to activate the resource [" + resource + "] after upgrade.", t);
                            inventoryManager.handleInvalidPluginConfigurationResourceError(resource, t);
                        }
                    }
                }
            } catch (Throwable t) {
                mergeFailed = true;

                //deactivate all the resources to be upgraded. We might have a problem
                //because they have not been upgraded because the merge failed.
                for (ResourceUpgradeRequest request : requests) {
                    ResourceContainer container = inventoryManager.getResourceContainer(request.getResourceId());
                    if (container != null) {
                        inventoryManager.deactivateResource(container.getResource());
                    }
                }

                throw t;
            }
View Full Code Here

        ResourceComponent<T> parentResourceComponent = resourceContainer.getResourceContext()
            .getParentResourceComponent();

        Resource parentResource = resourceContainer.getResource().getParentResource();

        ResourceContainer parentResourceContainer = (parentResource != null) ? inventoryManager
            .getResourceContainer(resourceContainer.getResource().getParentResource()) : null;

        ResourceContext<?> parentResourceContext = parentResourceContainer == null ? null : parentResourceContainer
            .getResourceContext();

        Resource resource = resourceContainer.getResource();

        ResourceDiscoveryComponent<ResourceComponent<T>> discoveryComponent;
View Full Code Here

    private void configureApacheServerToUseAugeas() throws Exception {
        ResourceTypes resourceTypes = new ResourceTypes(PluginLocation.APACHE_PLUGIN);

        InventoryManager im = PluginContainer.getInstance().getInventoryManager();

        ResourceContainer apacheServer = findApacheServerResource();

        Configuration config = apacheServer.getResourceContext().getPluginConfiguration();

        config.getSimple("augeasEnabled").setValue("yes");

        im.updatePluginConfiguration(apacheServer.getResource().getId(), config);

        //and run discovery so that the new resources can go into inventory

        im.executeServiceScanImmediately();
    }
View Full Code Here

                .equals(setup.getDeploymentConfig().serverRoot)) {
            return im.getResourceContainer(root);
        }

        for (Resource child : root.getChildResources()) {
            ResourceContainer rc = findApacheServerResource(im, rt, child);
            if (rc != null) {
                return rc;
            }
        }
View Full Code Here

TOP

Related Classes of org.rhq.core.pc.inventory.ResourceContainer$ComponentInvocation

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.