Examples of AugeasNode


Examples of org.rhq.augeas.node.AugeasNode

        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);
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

                //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.");
                    }

                    AugeasNode nd = nodes.get(seq - 1);
                    String key = AugeasNodeSearch.getNodeKey(nd, parentNode);

                    report.setResourceKey(key);
                    report.setResourceName(directoryName);

View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

        }, tree, server.getCurrentProcessInfo(), server.getCurrentBinaryInfo(), server.getModuleNames(), false);

        //transform the SNMP index into the index of the vhost
        int idx = allVhosts.size() - snmpIdx + 1;

        AugeasNode vhost = allVhosts.get(idx);

        //now check if there are any If* directives underneath this vhost.
        //we don't support configuring such beasts.
        if (vhost.getChildByLabel("<IfDefine").isEmpty() && vhost.getChildByLabel("<IfModule").isEmpty()
            && vhost.getChildByLabel("<IfVersion").isEmpty()) {

            return vhost;
        } else {
            throw new IllegalStateException("Configuration of the virtual host [" + resourceKey
                + "] contains conditional blocks. This is not supported by this plugin.");
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

                reload(node);
    }

    public void reload(AugeasNode nodes) {
        for (String key : buffer.keySet()) {
            AugeasNode nd = buffer.get(key);
            if (!key.equals(nd.getFullPath())) {
                buffer.remove(key);
                buffer.put(nd.getFullPath(), nd);
            }
        }
    }
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

            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);
            }
        }
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

    public void reloadLazy(AugeasNode node) {
        Map<String, String> nodesToChange = new HashMap<String, String>();
        List<String> nodesToChangeSeq = new ArrayList<String>();

        AugeasNode parentNode = node.getParentNode();
        for (String key : buffer.keySet()) {

            int index = key.indexOf(parentNode.getFullPath());
            if ((index == 0) && (key.length() > parentNode.getFullPath().length())) {
                String localPath = key.substring(parentNode.getFullPath().length());
                int endOfLabel = localPath.indexOf(File.separatorChar);
                String label;
                String restOfPath;

                if (endOfLabel != -1) {
                    label = localPath.substring(0, endOfLabel);
                    restOfPath = localPath.substring(endOfLabel + 1, localPath.length() - 1);
                } else {
                    label = localPath.substring(0, localPath.length() - 1);
                    restOfPath = "";
                }
                int startOfSeq = label.indexOf('[');
                if (startOfSeq != -1) {
                    String labelName = label.substring(0, startOfSeq);
                    if (labelName.equals(node.getLabel())) {
                        int endOfSeq = label.indexOf(']');
                        String seqNr = label.substring(startOfSeq, endOfSeq - 1);
                        int seq = Integer.valueOf(seqNr).intValue();
                        if (seq > node.getSeq()) {
                            if (restOfPath.equals(""))
                                nodesToChangeSeq.add(key);
                            else {
                                String newPath = parentNode.getFullPath() + File.separator + labelName + "["
                                    + String.valueOf(seq - 1) + "]"
                                    + (restOfPath.equals("") ? File.separator + restOfPath : "");

                                nodesToChange.put(key, newPath);
                            }
                        }
                    }
                }
            }

        }

        try {

            for (String key : nodesToChange.keySet()) {
                AugeasNode nd = buffer.get(key);
                nd.setPath((String) nodesToChange.get(key));
            }

            for (String key : nodesToChangeSeq) {
                AugeasNode nd = buffer.get(key);
                nd.setSeq(nd.getSeq() - 1);
            }

        } catch (Exception e) {
            //Exception is not thrown here because this method is called only for AugeasNodeLazy
        }
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

    protected AugeasNode instantiateNode(String fullPath) {
        return new AugeasNodeLazy(fullPath, this);
    }

    public AugeasNode createNode(String fullPath) throws AugeasTreeException {
        AugeasNode node = getLoadedNode(fullPath);

        if (node != null) {
            return node;
        }

        List<String> list = getAugeas().match(fullPath);
        if (!list.isEmpty()) {
            AugeasNode newNode = instantiateNode(fullPath);
            getNodeBuffer().addNode(newNode);
            return newNode;
        }

        getAugeas().set(fullPath, null);
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

        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

Examples of org.rhq.augeas.node.AugeasNode

    protected AugeasNodeBuffer getNodeBuffer() {
        return nodeBuffer;
    }

    public AugeasNode createNode(AugeasNode parentNode, String name, String value, int seq) throws AugeasTreeException {
        AugeasNode nd = createNode(parentNode.getFullPath() + File.separatorChar + name + "[" + String.valueOf(seq)
            + "]");
        nd.setValue(value);

        return nd;
    }
View Full Code Here

Examples of org.rhq.augeas.node.AugeasNode

        return null;
    }

    public AugeasNode getNode(String path) throws AugeasTreeException {
        AugeasNode node = getLoadedNode(path);
        return node == null ? createNode(path) : node;
    }
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.