Examples of AugeasTree


Examples of org.rhq.augeas.tree.AugeasTree

        if (!virtualHost.isAugeasEnabled()) {
            return discoveredResources;
        }
        AugeasComponent comp = virtualHost.getAugeas();
        AugeasTree tree = null;
        try {

            tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);

            parentNode = virtualHost.getNode(tree);
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

        }

        AugeasComponent comp = null;
        try {
            comp = parentComponent.getAugeas();
            AugeasTree tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);
            ConfigurationDefinition resourceConfigDef = context.getResourceType().getResourceConfigurationDefinition();

            AugeasNode virtualHostNode = parentComponent.getNode(tree);
            ApacheAugeasMapping mapping = new ApacheAugeasMapping(tree);
            return mapping.updateConfiguration(getNode(virtualHostNode), resourceConfigDef);
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

            report.setErrorMessage(ApacheServerComponent.CONFIGURATION_NOT_SUPPORTED_ERROR_MESSAGE);
            return;
        }

        AugeasComponent comp = null;
        AugeasTree tree = null;
        try {
            comp = parentComponent.getAugeas();
            tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);
            ConfigurationDefinition resourceConfigDef = context.getResourceType().getResourceConfigurationDefinition();
            ApacheAugeasMapping mapping = new ApacheAugeasMapping(tree);

            AugeasNode directoryNode = getNode(parentComponent.getNode(tree));
            mapping.updateAugeas(directoryNode, report.getConfiguration(), resourceConfigDef);
            tree.save();

            report.setStatus(ConfigurationUpdateStatus.SUCCESS);
            log.info("Apache configuration was updated");

            context.getParentResourceComponent().finishConfigurationUpdate(report);
        } catch (Exception e) {
            if (tree != null)
                log.error("Augeas failed to save configuration " + tree.summarizeAugeasError());
            else
                log.error("Augeas failed to save configuration", e);
            report.setStatus(ConfigurationUpdateStatus.FAILURE);
        } finally {
            if (comp != null)
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

        ApacheServerComponent parent = resourceContext.getParentResourceComponent();

        AugeasComponent comp = getAugeas();
        try {
            AugeasTree tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);
            ConfigurationDefinition resourceConfigDef =
                resourceContext.getResourceType().getResourceConfigurationDefinition();

            ApacheAugeasMapping mapping = new ApacheAugeasMapping(tree);
            return mapping.updateConfiguration(getNode(tree), resourceConfigDef);
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

            report.setErrorMessage(ApacheServerComponent.CONFIGURATION_NOT_SUPPORTED_ERROR_MESSAGE);
            return;
        }

        AugeasComponent comp = getAugeas();
        AugeasTree tree = null;
        try {
            tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);
            ConfigurationDefinition resourceConfigDef =
                resourceContext.getResourceType().getResourceConfigurationDefinition();
            ApacheAugeasMapping mapping = new ApacheAugeasMapping(tree);
            AugeasNode virtHostNode = getNode(tree);
            mapping.updateAugeas(virtHostNode, report.getConfiguration(), resourceConfigDef);
            tree.save();

            report.setStatus(ConfigurationUpdateStatus.SUCCESS);
            LOG.info("Apache configuration was updated");

            finishConfigurationUpdate(report);
        } catch (Exception e) {
            if (tree != null) {
                String message = "Augeas failed to save configuration " + tree.summarizeAugeasError();
                report.setErrorMessage(message);
                LOG.error(message);
            } else {
                report.setErrorMessageFromThrowable(e);
                LOG.error("Augeas failed to save configuration", e);
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

        }

        AugeasComponent comp = getAugeas();

        try {
            AugeasTree tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);
            AugeasNode myNode = getNode(tree);

            tree.removeNode(myNode, true);
            tree.save();

            deleteEmptyFile(tree, myNode);
            conditionalRestart();
        } catch (IllegalStateException e) {
            //this means we couldn't find the augeas node for this vhost.
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

                String directoryName = report.getUserSpecifiedResourceName();

                //fill in the plugin configuration

                //get the directive index
                AugeasTree tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);
                AugeasNode myNode = getNode(tree);
                List<AugeasNode> directories = myNode.getChildByLabel("<Directory");
                int seq = 1;
                /*
                 * myNode will be parent node of the new Directory node.
                 * We need to create a new node for directory node which will contain child nodes.
                 * To create a node we can call method from AugeasTree which will create a node. In this method is
                 * parameter sequence, if we will leave this parameter empty and there will be more nodes with
                 * the same label, new node will be created but the method createNode will return node with index 0 resp 1.
                 * If that will happen we can not update the node anymore because we are updating wrong node.
                 * To avoid this situation we need to know what is the last sequence nr. of virtual host's child (directory) nodes.
                 * We can not just count child nodes with the same label because some of the child nodes
                 * could be stored in another file. So that in httpd configurationstructure they are child nodes of virtual host,
                 *  but in augeas configuration structure they can be child nodes of node Include[];.
                 */

                for (AugeasNode n : directories) {
                    String param = n.getFullPath();
                    int end = param.lastIndexOf(File.separatorChar);
                    if (end != -1)
                        if (myNode.getFullPath().equals(param.substring(0, end)))
                            seq++;
                }

                //pluginConfiguration.put(new PropertySimple(ApacheDirectoryComponent.DIRECTIVE_INDEX_PROP, seq));
                //we don't support this yet... need to figure out how...
                pluginConfiguration.put(new PropertySimple(ApacheDirectoryComponent.REGEXP_PROP, false));
                String dirNameToSet = AugeasNodeValueUtil.escape(directoryName);

                //now actually create the data in augeas
                try {
                    ApacheAugeasMapping mapping = new ApacheAugeasMapping(tree);
                    AugeasNode directoryNode = tree.createNode(myNode, "<Directory", null, seq);
                    String myNodeKey = AugeasNodeSearch.getNodeKey(myNode, tree.getRootNode());
                    tree.createNode(directoryNode, "param", dirNameToSet, 0);
                    mapping.updateAugeas(directoryNode, resourceConfiguration,
                        resourceType.getResourceConfigurationDefinition());

                    tree.save();
                    comp.close();
                    tree = comp.getAugeasTree(ApacheServerComponent.AUGEAS_HTTP_MODULE_NAME);

                    AugeasNode parentNode;
                    if (myNodeKey.equals("")) {
                        parentNode = tree.getRootNode();
                    } else
                        parentNode = AugeasNodeSearch.findNodeById(tree.getRootNode(), myNodeKey);

                    List<AugeasNode> nodes = parentNode.getChildByLabel("<Directory");
                    if (nodes.size() < seq) {
                        report.setStatus(CreateResourceStatus.FAILURE);
                        report.setErrorMessage("Could not create directory node.");
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

            //copy all configuration files to temporary folder
            String path = apacheUtil.prepareConfigFiles();
            //loading of augeas from temporary folder
            AugeasProxy proxy =
                apacheUtil.initAugeas(path + File.separator + ApacheTestConstants.ROOT_CONFIG_FILE_NAME, path, path);
            AugeasTree tree = proxy.getAugeasTree(ApacheTestConstants.MODULE_NAME, true);

            testLoadConfig(tree, cont);
            testSaveConfig(cont);
            apacheUtil.cleanConfigFiles();
        } catch (Exception e) {
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

        System.out.print("Test mapping of rhq configuration to augeas tree.");
        ApacheAugeasUtil apacheUtil = new ApacheAugeasUtil();
        //load augeas tree from temporary folder
        String path = ApacheTestConstants.getApacheConfigFilesPath();
        AugeasProxy proxy = apacheUtil.initAugeas(path + ApacheTestConstants.ROOT_CONFIG_FILE_NAME, path, path);
        AugeasTree tree = proxy.getAugeasTree(ApacheTestConstants.MODULE_NAME, true);
        //load augeas tree from temporary folder "updateconfig"
        String pathUpdate = ApacheTestConstants.getApacheConfigFilesPathForUpdate();
        AugeasProxy proxyUpdate =
            apacheUtil.initAugeas(pathUpdate + ApacheTestConstants.ROOT_CONFIG_FILE_NAME, pathUpdate, pathUpdate);
        AugeasTree treeUpdate = proxyUpdate.getAugeasTree(ApacheTestConstants.MODULE_NAME, true);

        for (Components component : Components.values()) {
            List<AugeasNode> nodes = component.getAllNodes(tree);
            ConfigurationDefinition configDef =
                ApacheConfigurationUtil.getConfigurationDefinition(container, component);

            for (int i = 0; i < nodes.size(); i++) {
                //load component from first tree - transfare that tree to configuration - and update second tree with that configuration
                String key = AugeasNodeSearch.getNodeKey(nodes.get(i), tree.getRootNode());
                Configuration config =
                    ApacheConfigurationUtil.componentToConfiguration(container, component, key, tree);
                AugeasNode updateNode = AugeasNodeSearch.findNodeById(treeUpdate.getRootNode(), key);

                ApacheAugeasMapping mapping = new ApacheAugeasMapping(treeUpdate);
                mapping.updateAugeas(updateNode, config, configDef);
            }
        }
        treeUpdate.save();
        //test if the updated augeas tree can be mapped to configuration stored at files in "loadconfig" temporary directory
        testLoadConfig(treeUpdate, container);
        System.out.println(" [success!]");
    }
View Full Code Here

Examples of org.rhq.augeas.tree.AugeasTree

    }

    public AugeasTree buildTree(AugeasProxy component, AugeasConfiguration moduleConfig, String name, boolean lazy)
        throws AugeasTreeException {

        AugeasTree tree;
        AugeasModuleConfig module = moduleConfig.getModuleByName(name);
        if (lazy)
            tree = new AugeasTreeLazy(component.getAugeas(), module);
        else
            tree = new AugeasTreeReal(component.getAugeas(), module);

        AugeasNode rootNode = new AugeasRootNode();

        for (String fileName : module.getConfigFiles()) {
            rootNode.addChildNode(tree.createNode(AUGEAS_DATA_PATH + File.separatorChar + fileName));
        }

        tree.setRootNode(rootNode);

        return tree;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.