modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
| 211 +++--
modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
| 37
modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
| 129 ++-
modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
| 170 ++--
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
| 76 +-
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
| 219 +++--
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
| 123 +--
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
| 267 +++----
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
| 131 ++-
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
| 235 +++---
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
| 54 +
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
| 35
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
| 335 ++++----
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
| 380 +++++-----
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
| 31
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
| 133 ++-
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
| 68 +
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
| 166 ++--
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
| 316 ++++----
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
| 52 +
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
| 104 +-
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
| 58 +
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
| 38 -
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
| 118 ---
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
| 170 ----
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
| 36
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java
| 40 +
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
| 109 +-
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java
| 25
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java
| 123 +++
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
| 197 +++++
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java
| 76 ++
32 files changed, 2585 insertions(+), 1677 deletions(-)
New commits:
commit 930a72f007d665f731f41587a1f740a6674e31c4
Author: Filip Drabek <fdrabek(a)dhcp-lab-136.englab.brq.redhat.com>
Date: Mon Nov 30 13:28:25 2009 +0100
update
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
index 68464d2..d3a7d15 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.augeas;
import java.io.File;
@@ -14,26 +36,31 @@ import org.rhq.augeas.tree.AugeasTreeLazy;
import org.rhq.augeas.tree.AugeasTreeReal;
import org.rhq.augeas.util.Glob;
+/**
+ *
+ * @author Filip Drabek
+ * @author Ian Springer
+ *
+ */
public class AugeasComponent {
- private AugeasConfiguration config;
- private Augeas augeas;
- private List<String> modules;
+ private AugeasConfiguration config;
+ private Augeas augeas;
+ private List<String> modules;
- public AugeasComponent(AugeasConfiguration config){
- this.config = config;
- modules = new ArrayList<String>();
- }
-
- public void load() throws Exception
- {
+ public AugeasComponent(AugeasConfiguration config){
+ this.config = config;
+ modules = new ArrayList<String>();
+ }
+
+ public void load() throws Exception
+ {
augeas = new Augeas(config.getRootPath(), config.getLoadPath(),
config.getMode());
for (AugeasModuleConfig module : config.getModules()){
-
- checkModule(module);
- modules.add(module.getModuletName());
- augeas.set("/augeas/load/" + module.getModuletName() +
"/lens", module.getLensPath());
+ checkModule(module);
+ modules.add(module.getModuletName());
+ augeas.set("/augeas/load/" + module.getModuletName() +
"/lens", module.getLensPath());
int idx = 1;
for (String incl : module.getIncludedGlobs()) {
@@ -45,88 +72,88 @@ public class AugeasComponent {
for (String excl : module.getExcludedGlobs()) {
augeas.set("/augeas/load/" + module.getModuletName()
+ "/excl[" + (idx++) + "]", excl);
}
-
+
}
- augeas.load();
- }
-
-
- private void checkModule(AugeasModuleConfig module) {
- File root = new File(config.getRootPath());
+ augeas.load();
+ }
+
- List<String> includeGlobs = module.getIncludedGlobs();
+ private void checkModule(AugeasModuleConfig module) {
+ File root = new File(config.getRootPath());
- if (includeGlobs.size()<=0) {
- throw new IllegalStateException("Expecting at least once inclusion
pattern for configuration files.");
- }
+ List<String> includeGlobs = module.getIncludedGlobs();
- List<File> files = Glob.matchAll(root, includeGlobs);
+ if (includeGlobs.size()<=0) {
+ throw new IllegalStateException("Expecting at least once
inclusion pattern for configuration files.");
+ }
- if (module.getExcludedGlobs()!=null)
- {
- List<String> excludeGlobs = module.getExcludedGlobs();
- Glob.excludeAll(files, excludeGlobs);
- }
-
- for (File configFile : files) {
- if (!configFile.isAbsolute()) {
- throw new IllegalStateException("Configuration files inclusion
patterns contain a non-absolute file.");
- }
- if (!configFile.exists()) {
- throw new IllegalStateException("Configuration files inclusion
patterns refer to a non-existent file.");
- }
- if (configFile.isDirectory()) {
- throw new IllegalStateException("Configuration files inclusion
patterns refer to a directory.");
- }
- }
- }
-
- public AugeasTree getAugeasTree(String name,boolean lazy) throws AugeasTreeException
- {
- if (!modules.contains(name))
- throw new AugeasTreeException("Augeas Module "+ name +" not
found.");
-
- try {
- if (augeas == null)
- load();
- }catch(Exception e){
- throw new AugeasTreeException("Loading of augeas failed");
- }
-
- AugeasModuleConfig module = null;
-
- for (AugeasModuleConfig conf : config.getModules())
- {
- if (conf.getModuletName().equals(name))
- {
- module = conf;
- break;
- }
- }
- AugeasTree tree;
-
- if (lazy==true)
- tree = new AugeasTreeLazy(augeas,module);
- else
- tree = new AugeasTreeReal(augeas,module);
+ List<File> files = Glob.matchAll(root, includeGlobs);
- return tree;
- }
-
- public String printTree(String path){
- StringBuilder builder = new StringBuilder();
- builder.append(path + " "+ augeas.get(path)+'\n');
- List<String> list = augeas.match(path+File.separatorChar+"*");
- for (String tempStr : list)
- {
- builder.append(printTree(tempStr));
- }
-
- return builder.toString();
- }
-
- public Augeas getAugeas()
- {
- return augeas;
- }
+ if (module.getExcludedGlobs()!=null)
+ {
+ List<String> excludeGlobs = module.getExcludedGlobs();
+ Glob.excludeAll(files, excludeGlobs);
+ }
+
+ for (File configFile : files) {
+ if (!configFile.isAbsolute()) {
+ throw new IllegalStateException("Configuration files
inclusion patterns contain a non-absolute file.");
+ }
+ if (!configFile.exists()) {
+ throw new IllegalStateException("Configuration files
inclusion patterns refer to a non-existent file.");
+ }
+ if (configFile.isDirectory()) {
+ throw new IllegalStateException("Configuration files
inclusion patterns refer to a directory.");
+ }
+ }
+ }
+
+ public AugeasTree getAugeasTree(String name,boolean lazy) throws
AugeasTreeException
+ {
+ if (!modules.contains(name))
+ throw new AugeasTreeException("Augeas Module "+ name
+" not found.");
+
+ try {
+ if (augeas == null)
+ load();
+ }catch(Exception e){
+ throw new AugeasTreeException("Loading of augeas failed");
+ }
+
+ AugeasModuleConfig module = null;
+
+ for (AugeasModuleConfig conf : config.getModules())
+ {
+ if (conf.getModuletName().equals(name))
+ {
+ module = conf;
+ break;
+ }
+ }
+ AugeasTree tree;
+
+ if (lazy==true)
+ tree = new AugeasTreeLazy(augeas,module);
+ else
+ tree = new AugeasTreeReal(augeas,module);
+
+ return tree;
+ }
+
+ public String printTree(String path){
+ StringBuilder builder = new StringBuilder();
+ builder.append(path + " "+
augeas.get(path)+'\n');
+ List<String> list =
augeas.match(path+File.separatorChar+"*");
+ for (String tempStr : list)
+ {
+ builder.append(printTree(tempStr));
+ }
+
+ return builder.toString();
+ }
+
+ public Augeas getAugeas()
+ {
+ return augeas;
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
index f3fd636..0bb7334 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
@@ -1,11 +1,38 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.augeas.config;
import java.util.List;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasConfiguration {
-
- public List<AugeasModuleConfig> getModules();
- public String getRootPath();
- public String getLoadPath();
- public int getMode();
+
+ public List<AugeasModuleConfig> getModules();
+ public String getRootPath();
+ public String getLoadPath();
+ public int getMode();
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
index 1c487db..48bf732 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
@@ -1,58 +1,85 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.config;
import java.util.ArrayList;
import java.util.List;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasConfigurationSimple implements AugeasConfiguration{
+
+ private String loadPath;
+ private int mode;
+ private String rootPath;
+ private List<AugeasModuleConfig> modules;
+
+ public void setLoadPath(String loadPath) {
+ this.loadPath = loadPath;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
+ public void setRootPath(String rootPath) {
+ this.rootPath = rootPath;
+ }
+
+ public void setModules(List<AugeasModuleConfig> modules) {
+ this.modules = modules;
+ }
+
+ public AugeasConfigurationSimple()
+ {
+ modules = new ArrayList<AugeasModuleConfig>();
+ }
+
+ public String getLoadPath() {
+ return loadPath;
+ }
+
+
+ public int getMode() {
+ return mode;
+ }
+
+ public List<AugeasModuleConfig> getModules() {
+ return modules;
+ }
+
+
+ public String getRootPath() {
+ return rootPath;
+ }
- private String loadPath;
- private int mode;
- private String rootPath;
- private List<AugeasModuleConfig> modules;
-
- public void setLoadPath(String loadPath) {
- this.loadPath = loadPath;
- }
-
- public void setMode(int mode) {
- this.mode = mode;
- }
-
- public void setRootPath(String rootPath) {
- this.rootPath = rootPath;
- }
-
- public void setModules(List<AugeasModuleConfig> modules) {
- this.modules = modules;
- }
-
- public AugeasConfigurationSimple()
- {
- modules = new ArrayList<AugeasModuleConfig>();
- }
-
- public String getLoadPath() {
- return loadPath;
- }
-
-
- public int getMode() {
- return mode;
- }
-
- public List<AugeasModuleConfig> getModules() {
- return modules;
- }
-
-
- public String getRootPath() {
- return rootPath;
- }
-
- public void addModuleConfig(AugeasModuleConfig config)
- {
- if (modules.contains(config))
- return;
- modules.add(config);
- }
+ public void addModuleConfig(AugeasModuleConfig config)
+ {
+ if (modules.contains(config))
+ return;
+ modules.add(config);
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
index bdf0192..42be1a0 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
@@ -1,78 +1,102 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.config;
import java.util.ArrayList;
import java.util.List;
-public class AugeasModuleConfig {
-
- private String moduletName;
- private String lensPath;
- private List<String> excludedGlobs;
- private List<String> includedGlobs;
-
- public AugeasModuleConfig(){
- excludedGlobs = new ArrayList<String>();
- includedGlobs = new ArrayList<String>();
- }
-
- public String getModuletName() {
- return moduletName;
- }
-
- public void setModuletName(String moduletName) {
- this.moduletName = moduletName;
- }
-
- public String getLensPath() {
- return lensPath;
- }
-
- public void setLensPath(String lensPath) {
- this.lensPath = lensPath;
- }
-
- public List<String> getExcludedGlobs() {
- return excludedGlobs;
- }
-
- public void setExcludedGlobs(List<String> excludedGlobs) {
- this.excludedGlobs = excludedGlobs;
- }
-
- public List<String> getIncludedGlobs() {
- return includedGlobs;
- }
-
- public void setIncludedGlobs(List<String> includedGlobs) {
- this.includedGlobs = includedGlobs;
- }
-
- public void addIncludedGlob(String name){
- if (!includedGlobs.contains(name))
- this.includedGlobs.add(name);
- }
-
- public void addExcludedGlob(String name){
- if (!excludedGlobs.contains(name))
- this.excludedGlobs.add(name);
- }
-
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null || getClass() != obj.getClass())
- return false;
-
- AugeasModuleConfig that = (AugeasModuleConfig) obj;
-
- if (!this.moduletName.equals(that.getModuletName()))
- return false;
-
- if (!this.lensPath.equals(that.getLensPath()))
- return false;
-
- return true;
- }
-
-}
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public class AugeasModuleConfig {
+
+ private String moduletName;
+ private String lensPath;
+ private List<String> excludedGlobs;
+ private List<String> includedGlobs;
+
+ public AugeasModuleConfig(){
+ excludedGlobs = new ArrayList<String>();
+ includedGlobs = new ArrayList<String>();
+ }
+
+ public String getModuletName() {
+ return moduletName;
+ }
+
+ public void setModuletName(String moduletName) {
+ this.moduletName = moduletName;
+ }
+
+ public String getLensPath() {
+ return lensPath;
+ }
+
+ public void setLensPath(String lensPath) {
+ this.lensPath = lensPath;
+ }
+
+ public List<String> getExcludedGlobs() {
+ return excludedGlobs;
+ }
+
+ public void setExcludedGlobs(List<String> excludedGlobs) {
+ this.excludedGlobs = excludedGlobs;
+ }
+
+ public List<String> getIncludedGlobs() {
+ return includedGlobs;
+ }
+
+ public void setIncludedGlobs(List<String> includedGlobs) {
+ this.includedGlobs = includedGlobs;
+ }
+
+ public void addIncludedGlob(String name){
+ if (!includedGlobs.contains(name))
+ this.includedGlobs.add(name);
+ }
+
+ public void addExcludedGlob(String name){
+ if (!excludedGlobs.contains(name))
+ this.excludedGlobs.add(name);
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || getClass() != obj.getClass())
+ return false;
+ AugeasModuleConfig that = (AugeasModuleConfig) obj;
+ if (!this.moduletName.equals(that.getModuletName()))
+ return false;
+ if (!this.lensPath.equals(that.getLensPath()))
+ return false;
+
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
index e620447..6ad60f7 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
@@ -1,40 +1,64 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.augeas.node;
import java.util.List;
-
-import org.rhq.augeas.tree.AugeasTreeException;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasNode {
- public String getPath();
+ public String getPath();
- public void setPath(String path) throws Exception;
-
- public String getLabel() ;
+ public void setPath(String path) throws Exception;
+
+ public String getLabel() ;
- public void setLabel(String label);
+ public void setLabel(String label);
- public String getValue();
+ public String getValue();
- public void setValue(String value) ;
+ public void setValue(String value) ;
- public int getSeq();
+ public int getSeq();
- public void setSeq(int seq);
+ public void setSeq(int seq);
- public AugeasNode getParentNode();
+ public AugeasNode getParentNode();
- public List<AugeasNode> getChildNodes() ;
-
- public boolean equals(Object obj);
-
- public String getFullPath();
-
- public void addChildNode(AugeasNode node);
-
- public List<AugeasNode> getChildByLabel(String labelName);
-
- public void remove(boolean updateSeq) throws Exception;
-
- public void updateFromParent();
+ public List<AugeasNode> getChildNodes() ;
+
+ public boolean equals(Object obj);
+
+ public String getFullPath();
+
+ public void addChildNode(AugeasNode node);
+
+ public List<AugeasNode> getChildByLabel(String labelName);
+
+ public void remove(boolean updateSeq) throws Exception;
+
+ public void updateFromParent();
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
index 8a8dfc5..21b4941 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
@@ -1,3 +1,26 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.node;
import java.io.File;
@@ -6,63 +29,67 @@ import java.util.List;
import org.rhq.augeas.tree.AugeasTree;
import org.rhq.augeas.tree.AugeasTreeException;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeLazy extends AugeasNodeParent implements AugeasNode {
- public AugeasNodeLazy(String FullPath,AugeasTree ag)
- {
- super();
-
- this.ag = ag;
- this.path = FullPath.substring(0,FullPath.lastIndexOf(File.separatorChar)+1);
- String val =
FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1,FullPath.length());
-
- int firstB = val.indexOf("[");
- if (firstB != -1){
- seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
- label = val.substring(0,firstB);
- }
- else{
- seq = 0;
- label = FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1);
- }
- }
-
- public List<AugeasNode> getChildNodes() {
- List <AugeasNode> nodes = null;
- try {
-
- nodes = ag.match(getFullPath()+File.separatorChar+"*");
-
- }catch(AugeasTreeException e)
- {
- //TODO loggin
- e.printStackTrace();
- }
- return nodes;
- }
-
-
- public AugeasNode getParentNode(){
- String parentNodePath = path.substring(0,path.length()-1);
- if (parentNodePath.equals(ag.getRootNode().getFullPath()))
- return ag.getRootNode();
- try {
- parentNode = ag.getNode(parentNodePath);
- }catch(Exception e)
- {
- return null;
- }
-
- return parentNode;
- }
-
- public String getValue() {
- if (value == null)
- value = ag.get(getFullPath());
-
- return value;
- }
+ public AugeasNodeLazy(String FullPath,AugeasTree ag)
+ {
+ super();
+
+ this.ag = ag;
+ this.path = FullPath.substring(0,FullPath.lastIndexOf(File.separatorChar)+1);
+ String val =
FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1,FullPath.length());
+
+ int firstB = val.indexOf("[");
+ if (firstB != -1){
+ seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
+ label = val.substring(0,firstB);
+ }
+ else{
+ seq = 0;
+ label =
FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1);
+ }
+ }
+
+ public List<AugeasNode> getChildNodes() {
+ List <AugeasNode> nodes = null;
+ try {
+
+ nodes = ag.match(getFullPath()+File.separatorChar+"*");
+
+ }catch(AugeasTreeException e)
+ {
+ //TODO loggin
+ e.printStackTrace();
+ }
+ return nodes;
+ }
+
+
+ public AugeasNode getParentNode(){
+ String parentNodePath = path.substring(0,path.length()-1);
+ if (parentNodePath.equals(ag.getRootNode().getFullPath()))
+ return ag.getRootNode();
+ try {
+ parentNode = ag.getNode(parentNodePath);
+ }catch(Exception e)
+ {
+ return null;
+ }
+
+ return parentNode;
+ }
+
+ public String getValue() {
+ if (value == null)
+ value = ag.get(getFullPath());
+
+ return value;
+ }
public boolean equals(Object obj) {
if (this == obj)
@@ -73,51 +100,51 @@ public class AugeasNodeLazy extends AugeasNodeParent implements
AugeasNode {
AugeasNode that = (AugeasNode) obj;
if (!this.getFullPath().equals(that.getFullPath()))
- return false;
+ return false;
return true;
}
public void setValue(String value){
- ag.setValue(this, value);
+ ag.setValue(this, value);
}
-
- public String getFullPath() {
- return path + label + (seq !=0 ? "["+String.valueOf(seq)+"]" :
"" );
- }
-
-
- public void addChildNode(AugeasNode node) {
- //TODO kontrola jestli sem patri
- childNodes.add(node);
- }
-
-
- public List<AugeasNode> getChildByLabel(String labelName){
- List<AugeasNode> nodes = getChildNodes();
- List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
-
- for (AugeasNode node : nodes){
- if (node.getLabel().equals(labelName))
- tempNode.add(node);
- }
- return tempNode;
- }
-
- public void remove(boolean updateSeq) throws Exception
- {
- ag.removeNode(this,updateSeq);
- }
-
- public void setPath(String path) throws Exception{
- this.path = path;
-
- }
-
- public void updateFromParent() {
- AugeasNode node = this.getParentNode();
- if (!this.path.equals(node.getFullPath())){
- this.path = node.getFullPath();
- }
- }
+
+ public String getFullPath() {
+ return path + label + (seq !=0 ?
"["+String.valueOf(seq)+"]" : "" );
+ }
+
+
+ public void addChildNode(AugeasNode node) {
+ //TODO kontrola jestli sem patri
+ childNodes.add(node);
+ }
+
+
+ public List<AugeasNode> getChildByLabel(String labelName){
+ List<AugeasNode> nodes = getChildNodes();
+ List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
+
+ for (AugeasNode node : nodes){
+ if (node.getLabel().equals(labelName))
+ tempNode.add(node);
+ }
+ return tempNode;
+ }
+
+ public void remove(boolean updateSeq) throws Exception
+ {
+ ag.removeNode(this,updateSeq);
+ }
+
+ public void setPath(String path) throws Exception{
+ this.path = path;
+
+ }
+
+ public void updateFromParent() {
+ AugeasNode node = this.getParentNode();
+ if (!this.path.equals(node.getFullPath())){
+ this.path = node.getFullPath();
+ }
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
index 4016a28..ed6e646 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
@@ -1,56 +1,83 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.node;
import java.util.ArrayList;
import java.util.List;
import org.rhq.augeas.tree.AugeasTree;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeParent {
-
- protected String path;
- protected String label;
- protected String value;
- protected AugeasTree ag;
- protected int seq;
- protected AugeasNode parentNode;
- protected List<AugeasNode> childNodes;
-
- public AugeasNodeParent(){
- childNodes = new ArrayList<AugeasNode>();
- }
- public String getPath() {
- return path;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public int getSeq() {
- return seq;
- }
-
- public void setSeq(int seq) {
- this.seq = seq;
- }
-
- public AugeasNode getParentNode() {
- return parentNode;
- }
-
- public List<AugeasNode> getChildNodes() {
- return childNodes;
- }
+
+ protected String path;
+ protected String label;
+ protected String value;
+ protected AugeasTree ag;
+ protected int seq;
+ protected AugeasNode parentNode;
+ protected List<AugeasNode> childNodes;
+
+ public AugeasNodeParent(){
+ childNodes = new ArrayList<AugeasNode>();
+ }
+ public String getPath() {
+ return path;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public int getSeq() {
+ return seq;
+ }
+
+ public void setSeq(int seq) {
+ this.seq = seq;
+ }
+
+ public AugeasNode getParentNode() {
+ return parentNode;
+ }
+
+ public List<AugeasNode> getChildNodes() {
+ return childNodes;
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
index 7ccc56c..68eb968 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
@@ -1,137 +1,164 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.node;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.rhq.augeas.tree.AugeasTree;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeReal extends AugeasNodeParent implements AugeasNode{
- public AugeasNodeReal()
- {
- super();
- }
-
- public AugeasNodeReal(AugeasNode parentNode,AugeasTree tree,String label,int seq)
- {
- super();
- ag = tree;
- this.parentNode = parentNode;
- path = parentNode.getPath()+ File.separatorChar + parentNode.getLabel() +
File.separatorChar;
- this.seq = seq;
- }
-
- public AugeasNodeReal(AugeasNode parentNode,AugeasTree ag,String fullPath)
- {
- super();
- this.parentNode = parentNode;
- if (fullPath == null)
- return ;
-
- this.path = fullPath.substring(0,fullPath.lastIndexOf(File.separatorChar)+1);
- String val =
fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1,fullPath.length());
-
- int firstB = val.indexOf("[");
-
- if (firstB != -1){
- seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
- label = val.substring(0,firstB);
- }
- else{
- seq = 0;
- label = fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1);
- }
- }
-
- public AugeasNodeReal(String path,String label,int seq,String value)
- {
- childNodes = new ArrayList<AugeasNode>();
-
- if (path == null)
- return ;
-
- this.path = path;
- this.value = value;
- this.label = label;
- this.seq = seq;
- }
+ public AugeasNodeReal()
+ {
+ super();
+ }
+
+ public AugeasNodeReal(AugeasNode parentNode,AugeasTree tree,String label,int seq)
+ {
+ super();
+ ag = tree;
+ this.parentNode = parentNode;
+ path = parentNode.getPath()+ File.separatorChar + parentNode.getLabel() +
File.separatorChar;
+ this.seq = seq;
+ }
+
+ public AugeasNodeReal(AugeasNode parentNode,AugeasTree ag,String fullPath)
+ {
+ super();
+ this.parentNode = parentNode;
+ if (fullPath == null)
+ return ;
+
+ this.path =
fullPath.substring(0,fullPath.lastIndexOf(File.separatorChar)+1);
+ String val =
fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1,fullPath.length());
+
+ int firstB = val.indexOf("[");
+
+ if (firstB != -1){
+ seq =
Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
+ label = val.substring(0,firstB);
+ }
+ else{
+ seq = 0;
+ label =
fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1);
+ }
+ }
+
+ public AugeasNodeReal(String path,String label,int seq,String value)
+ {
+ childNodes = new ArrayList<AugeasNode>();
+
+ if (path == null)
+ return ;
+
+ this.path = path;
+ this.value = value;
+ this.label = label;
+ this.seq = seq;
+ }
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null || getClass() != obj.getClass())
- return false;
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || getClass() != obj.getClass())
+ return false;
- AugeasNode that = (AugeasNode) obj;
+ AugeasNode that = (AugeasNode) obj;
- if (!this.getFullPath().equals(that.getFullPath()))
- return false;
+ if (!this.getFullPath().equals(that.getFullPath()))
+ return false;
- return true;
- }
+ return true;
+ }
-
- public String getFullPath() {
- return path + label + (seq !=0 ? "["+String.valueOf(seq)+"]" :
"" );
- }
-
- public void addChildNode(AugeasNode node) {
- //TODO kontrola jestli sem patri
- childNodes.add(node);
- }
-
- public List<AugeasNode> getChildByLabel(String labelName){
- List<AugeasNode> nodes = getChildNodes();
- List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
+
+ public String getFullPath() {
+ return path + label + (seq !=0 ?
"["+String.valueOf(seq)+"]" : "" );
+ }
+
+ public void addChildNode(AugeasNode node) {
+ //TODO kontrola jestli sem patri
+ childNodes.add(node);
+ }
+
+ public List<AugeasNode> getChildByLabel(String labelName){
+ List<AugeasNode> nodes = getChildNodes();
+ List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
- for (AugeasNode node : nodes){
- if (node.getLabel().equals(labelName))
- tempNode.add(node);
- }
- return tempNode;
- }
-
- public void remove(boolean updateSeq) throws Exception
- {
- ag.removeNode(this,updateSeq);
- }
+ for (AugeasNode node : nodes){
+ if (node.getLabel().equals(labelName))
+ tempNode.add(node);
+ }
+ return tempNode;
+ }
+
+ public void remove(boolean updateSeq) throws Exception
+ {
+ ag.removeNode(this,updateSeq);
+ }
- public void setPath(String path) throws Exception{
- int end;
- if (path.lastIndexOf(File.separatorChar) == path.length())
- {
- end = path.length()-1;
- this.path = path.substring(0,path.length()-1);
- }
- else
- {
- end = path.length();
- this.path = path;
- }
-
- AugeasNode parentNode = ag.getNode(path.substring(0,end));
- List<AugeasNode> nodes = parentNode.getChildByLabel(this.label);
- if (!nodes.isEmpty()){
- int indexes = nodes.size();
- this.setSeq(indexes+1);
- }
- parentNode.addChildNode(this);
- for (AugeasNode nd : this.getChildNodes())
- {
- nd.updateFromParent();
- }
- }
+ public void setPath(String path) throws Exception{
+ int end;
+ if (path.lastIndexOf(File.separatorChar) == path.length())
+ {
+ end = path.length()-1;
+ this.path = path.substring(0,path.length()-1);
+ }
+ else
+ {
+ end = path.length();
+ this.path = path;
+ }
+
+ AugeasNode parentNode = ag.getNode(path.substring(0,end));
+ List<AugeasNode> nodes = parentNode.getChildByLabel(this.label);
+ if (!nodes.isEmpty()){
+ int indexes = nodes.size();
+ this.setSeq(indexes+1);
+ }
+ parentNode.addChildNode(this);
+ for (AugeasNode nd : this.getChildNodes())
+ {
+ nd.updateFromParent();
+ }
+ }
- public void updateFromParent() {
- AugeasNode node = this.getParentNode();
- if (!this.path.equals(node.getFullPath())){
- this.path = node.getFullPath();
- }
-
- for (AugeasNode nd : this.getChildNodes())
- {
- nd.updateFromParent();
- }
- }
+ public void updateFromParent() {
+ AugeasNode node = this.getParentNode();
+ if (!this.path.equals(node.getFullPath())){
+ this.path = node.getFullPath();
+ }
+
+ for (AugeasNode nd : this.getChildNodes())
+ {
+ nd.updateFromParent();
+ }
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
index 908bdf5..f7d5a70 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
@@ -1,72 +1,99 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.node;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasRootNode extends AugeasNodeParent implements AugeasNode{
-
- public AugeasRootNode(List<AugeasNode> nodes){
- super();
- childNodes=nodes;
- }
-
- public AugeasRootNode(){
- super();
- }
-
- public void addChildNode(AugeasNode node) {
- childNodes.add(node);
- }
+
+ public AugeasRootNode(List<AugeasNode> nodes){
+ super();
+ childNodes=nodes;
+ }
+
+ public AugeasRootNode(){
+ super();
+ }
+
+ public void addChildNode(AugeasNode node) {
+ childNodes.add(node);
+ }
-
- public List<AugeasNode> getChildNodes() {
- return childNodes;
- }
+
+ public List<AugeasNode> getChildNodes() {
+ return childNodes;
+ }
- public String getFullPath() {
- return ""+File.pathSeparatorChar;
- }
+ public String getFullPath() {
+ return ""+File.pathSeparatorChar;
+ }
- public String getLabel() {
- return null;
- }
+ public String getLabel() {
+ return null;
+ }
- public AugeasNode getParentNode() {
- return null;
- }
+ public AugeasNode getParentNode() {
+ return null;
+ }
- public String getPath() {
- return File.separator;
- }
-
- public List<AugeasNode> getChildByLabel(String labelName) {
- List<AugeasNode> nodes = getChildNodes();
- List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
+ public String getPath() {
+ return File.separator;
+ }
+
+ public List<AugeasNode> getChildByLabel(String labelName) {
+ List<AugeasNode> nodes = getChildNodes();
+ List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
- for (AugeasNode node : nodes){
- if (node.getLabel().equals(labelName))
- tempNode.add(node);
- }
- return tempNode;
+ for (AugeasNode node : nodes){
+ if (node.getLabel().equals(labelName))
+ tempNode.add(node);
+ }
+ return tempNode;
}
-
- public void remove(boolean updateSeq) throws Exception
- {
- throw new Exception("Root node is virtual and can not be removed. If you want to
remove data remove all child nodes.");
- }
+
+ public void remove(boolean updateSeq) throws Exception
+ {
+ throw new Exception("Root node is virtual and can not be removed. If
you want to remove data remove all child nodes.");
+ }
- public void setPath(String path) throws Exception{
- // TODO Auto-generated method stub
-
- }
+ public void setPath(String path) throws Exception{
+ // TODO Auto-generated method stub
+
+ }
- public void updateFromParent() {
- // TODO Auto-generated method stub
-
- }
+ public void updateFromParent() {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
index b96bf70..d2aeb44 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
@@ -1,3 +1,26 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.tree;
import java.io.File;
@@ -7,113 +30,117 @@ import java.util.List;
import java.util.Map;
import org.rhq.augeas.node.AugeasNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeBuffer {
- private Map<String,AugeasNode> buffer;
-
- public AugeasNodeBuffer()
- {
- buffer = new HashMap<String,AugeasNode>();
- }
-
- public boolean isNodeLoaded(String name){
- return buffer.containsKey(name);
- }
-
- public AugeasNode getNode(String name){
- return buffer.get(name);
- }
-
- public void addNode(AugeasNode node){
- if (!isNodeLoaded(node.getFullPath()))
- buffer.put(node.getFullPath(), node);
- }
-
- public void removeNode(AugeasNode node,boolean updateSeq,boolean lazy)
- {
- if (buffer.containsKey(node.getFullPath()))
- buffer.remove(node.getFullPath());
-
- if (updateSeq)
- if (lazy)
- reloadLazy(node);
- else
- 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);
- }
- }
+ private Map<String,AugeasNode> buffer;
+
+ public AugeasNodeBuffer()
+ {
+ buffer = new HashMap<String,AugeasNode>();
+ }
+
+ public boolean isNodeLoaded(String name){
+ return buffer.containsKey(name);
+ }
+
+ public AugeasNode getNode(String name){
+ return buffer.get(name);
+ }
+
+ public void addNode(AugeasNode node){
+ if (!isNodeLoaded(node.getFullPath()))
+ buffer.put(node.getFullPath(), node);
+ }
+
+ public void removeNode(AugeasNode node,boolean updateSeq,boolean lazy)
+ {
+ if (buffer.containsKey(node.getFullPath()))
+ buffer.remove(node.getFullPath());
+
+ if (updateSeq)
+ if (lazy)
+ reloadLazy(node);
+ else
+ 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);
+ }
+ }
}
-
- 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;
+
+ 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
- }
- }
-
+ 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
+ }
+ }
+
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
index ad89c3a..e7f7a3f 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
@@ -1,20 +1,48 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.tree;
import java.util.List;
import org.rhq.augeas.node.AugeasNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasTree {
- public void load() throws AugeasTreeException;
- public void update();
- public void save();
- public AugeasNode getNode(String path) throws AugeasTreeException;
- public List<AugeasNode> match(String expression) throws AugeasTreeException;
- public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws
AugeasTreeException;
- public AugeasNode createNode(String fullPath) throws AugeasTreeException;
- public AugeasNode createNode(AugeasNode parentNode,String value,int seq);
- public String get(String expr);
- public AugeasNode getRootNode();
- public void removeNode(AugeasNode node,boolean updateSeq) throws Exception;
- public void setValue(AugeasNode node,String value);
+ public void load() throws AugeasTreeException;
+ public void update();
+ public void save();
+ public AugeasNode getNode(String path) throws AugeasTreeException;
+ public List<AugeasNode> match(String expression) throws
AugeasTreeException;
+ public List<AugeasNode> matchRelative(AugeasNode node,String expression)
throws AugeasTreeException;
+ public AugeasNode createNode(String fullPath) throws AugeasTreeException;
+ public AugeasNode createNode(AugeasNode parentNode,String name ,String value,int
seq)throws AugeasTreeException;
+ public String get(String expr);
+ public AugeasNode getRootNode();
+ public void removeNode(AugeasNode node,boolean updateSeq) throws Exception;
+ public void setValue(AugeasNode node,String value);
+ public String summarizeAugeasError();
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
index 82cd4e5..978103a 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
@@ -1,8 +1,35 @@
-package org.rhq.augeas.tree;
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.augeas.tree;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasTreeException extends Exception{
- public AugeasTreeException(String msg){
- super(msg);
- }
+ public AugeasTreeException(String msg){
+ super(msg);
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
index 903fd48..283d8b7 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
@@ -1,3 +1,26 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.augeas.tree;
import java.io.File;
@@ -10,158 +33,170 @@ import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.node.AugeasNodeLazy;
import org.rhq.augeas.node.AugeasRootNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasTreeLazy implements AugeasTree{
- private AugeasModuleConfig moduleConfig;
- private Augeas ag;
- private AugeasNode rootNode;
- private AugeasNode rootConfigNode;
- private AugeasNodeBuffer nodeBuffer;
-
- private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
-
- public AugeasTreeLazy(Augeas ag ,AugeasModuleConfig moduleConfig)
- {
- rootNode = new AugeasRootNode();
- nodeBuffer = new AugeasNodeBuffer();
- this.moduleConfig = moduleConfig;
- this.ag = ag;
- }
-
- public void load() throws AugeasTreeException
- {
- buildTree();
- }
-
- public void update()
- {
-
- }
-
- public void save()
- {
- ag.save();
- }
-
-
- private AugeasNode getLoadedNode(String path) throws AugeasTreeException
- {
- if (nodeBuffer.isNodeLoaded(path))
- return nodeBuffer.getNode(path);
-
- throw new AugeasTreeException("Node not found.");
- }
-
- public AugeasNode getNode(String path) throws AugeasTreeException
- {
- AugeasNode node;
- try {
- node = getLoadedNode(path);
- }catch(AugeasTreeException e)
- {
- node = createNode(path);
- }
-
- return node;
- }
-
- public List<AugeasNode> match(String expression) throws AugeasTreeException
- {
- List<String> res = ag.match(expression);
+ private AugeasModuleConfig moduleConfig;
+ private Augeas ag;
+ private AugeasNode rootNode;
+ private AugeasNode rootConfigNode;
+ private AugeasNodeBuffer nodeBuffer;
+ private String [] errorNodes =
{"pos","line","char","lens","message"};
+ private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
+
+ public AugeasTreeLazy(Augeas ag ,AugeasModuleConfig moduleConfig)
+ {
+ rootNode = new AugeasRootNode();
+ nodeBuffer = new AugeasNodeBuffer();
+ this.moduleConfig = moduleConfig;
+ this.ag = ag;
+ }
+
+ public void load() throws AugeasTreeException
+ {
+ buildTree();
+ }
+
+ public void update()
+ {
+
+ }
+
+ public void save()
+ {
+ ag.save();
+ }
+
+
+ private AugeasNode getLoadedNode(String path) throws AugeasTreeException
+ {
+ if (nodeBuffer.isNodeLoaded(path))
+ return nodeBuffer.getNode(path);
+
+ throw new AugeasTreeException("Node not found.");
+ }
+
+ public AugeasNode getNode(String path) throws AugeasTreeException
+ {
+ AugeasNode node;
+ try {
+ node = getLoadedNode(path);
+ }catch(AugeasTreeException e)
+ {
+ node = createNode(path);
+ }
+
+ return node;
+ }
+
+ public List<AugeasNode> match(String expression) throws AugeasTreeException
+ {
+ List<String> res = ag.match(expression);
- List<AugeasNode> nodes = new ArrayList<AugeasNode>();
-
- for (String name:res){
- nodes.add(getNode(name));
- }
-
- return nodes;
- }
-
- public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws
AugeasTreeException
- {
- if (rootNode.getChildNodes().isEmpty())
- throw new AugeasTreeException("Root node has not childs.");
-
- if (node.equals(rootNode)){
- List<AugeasNode> nodes = rootNode.getChildNodes();
- List<AugeasNode> returnNodes = new ArrayList<AugeasNode>();
- for (AugeasNode nd :nodes)
- {
- String tempName = nd.getFullPath()+expression;
- List<AugeasNode> temp = match(tempName);
- returnNodes.addAll(temp);
- }
- return returnNodes;
- }
-
- return match(node.getFullPath()+File.separatorChar+expression);
- }
-
- public AugeasNode createNode(String fullPath) throws AugeasTreeException
- {
- AugeasNode node=null;
-
- ag.set(fullPath, null);
- node = new AugeasNodeLazy(fullPath,this);
- nodeBuffer.addNode(node);
- return node;
- }
-
- public AugeasNode createNode(AugeasNode parentNode,String value,int seq)
- {
- return null;
- }
-
- public String get(String expr)
- {
- return ag.get(expr);
- }
-
- public AugeasNode getRootNode(){
- return rootNode;
- }
-
- private void buildTree() throws AugeasTreeException
- {
- rootConfigNode = createNode("/augeas");
-
- for (String name : moduleConfig.getIncludedGlobs())
- {
- rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
- }
- }
-
- public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
- {
- int res = ag.remove(node.getFullPath());
- nodeBuffer.removeNode(node,updateSeq,true);
-
+ List<AugeasNode> nodes = new ArrayList<AugeasNode>();
+
+ for (String name:res){
+ nodes.add(getNode(name));
+ }
+
+ return nodes;
+ }
+
+ public List<AugeasNode> matchRelative(AugeasNode node,String expression)
throws AugeasTreeException
+ {
+ if (rootNode.getChildNodes().isEmpty())
+ throw new AugeasTreeException("Root node has not
childs.");
+
+ if (node.equals(rootNode)){
+ List<AugeasNode> nodes = rootNode.getChildNodes();
+ List<AugeasNode> returnNodes = new
ArrayList<AugeasNode>();
+ for (AugeasNode nd :nodes)
+ {
+ String tempName = nd.getFullPath()+expression;
+ List<AugeasNode> temp = match(tempName);
+ returnNodes.addAll(temp);
+ }
+ return returnNodes;
+ }
+
+ return match(node.getFullPath()+File.separatorChar+expression);
+ }
+
+ public AugeasNode createNode(String fullPath) throws AugeasTreeException
+ {
+ AugeasNode node=null;
+
+ ag.set(fullPath, null);
+ node = new AugeasNodeLazy(fullPath,this);
+ nodeBuffer.addNode(node);
+ return node;
+ }
+
+ 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;
+ }
+
+ public String get(String expr)
+ {
+ return ag.get(expr);
+ }
+
+ public AugeasNode getRootNode(){
+ return rootNode;
+ }
+
+ private void buildTree() throws AugeasTreeException
+ {
+ rootConfigNode = createNode("/augeas");
+
+ for (String name : moduleConfig.getIncludedGlobs())
+ {
+
rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
+ }
+ }
+
+ public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
+ {
+ int res = ag.remove(node.getFullPath());
+ nodeBuffer.removeNode(node,updateSeq,true);
+
}
-
- public void setValue(AugeasNode node,String value)
- {
- ag.set(node.getFullPath(), value);
- }
- /*
- protected String summarizeAugeasError(Augeas augeas) {
- StringBuilder summary = new StringBuilder();
- String metadataNodePrefix = "/augeas/files";
- for (String glob : moduleConfig.getIncludedGlobs()) {
- if (glob.startsWith(""+File.separatorChar)) {
- glob = glob.substring(1);
- }
- AugeasNode metadataNode = new AugeasNodeLazy();
- AugeasNode errorNode = new AugeasNode(metadataNode, "error");
- List<String> nodePaths = augeas.match(errorNode.getPath() +
"/*");
- for (String path : nodePaths) {
- String error = augeas.get(path);
- summary.append("File
\"").append(path.substring(metadataNodePrefix.length(), path.length())).append(
- "\":\n").append(error).append("\n");
- }
- }
+
+ public void setValue(AugeasNode node,String value)
+ {
+ ag.set(node.getFullPath(), value);
+ }
+
+ public String summarizeAugeasError() {
+
+ String nodePrefix = "/augeas/files";
+ List<String> str = moduleConfig.getIncludedGlobs();
+ StringBuilder builder = new StringBuilder();
+
+ for (String path : str) {
+ String name = nodePrefix +
path+File.separatorChar+"error";
+ if (ag.exists(name))
+ {
+ builder.append("Error "+ag.get(name)+'\n');
+ for (String errNd : errorNodes)
+ {
+ String pathToMessage = name+File.separatorChar+errNd;
+ if (ag.exists(pathToMessage))
+ {
+ builder.append(errNd + "
"+ag.get(pathToMessage)+'\n');
+ }
+ }
+ }
+ }
+
+ return builder.toString();
+ }
- return summary.toString();
- }
-*/
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
index 7ad4783..02da23c 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.augeas.tree;
import java.io.File;
@@ -10,180 +32,194 @@ import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.node.AugeasNodeReal;
import org.rhq.augeas.node.AugeasRootNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasTreeReal implements AugeasTree{
- private AugeasModuleConfig moduleConfig;
- private Augeas ag;
- private AugeasNode rootNode;
- private AugeasNode rootConfigNode;
- private AugeasNodeBuffer nodeBuffer;
-
- private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
-
- public AugeasTreeReal(Augeas ag ,AugeasModuleConfig moduleConfig)
- {
- rootNode = new AugeasRootNode();
- nodeBuffer = new AugeasNodeBuffer();
- this.moduleConfig = moduleConfig;
- this.ag = ag;
- }
-
- public void load() throws AugeasTreeException
- {
- buildTree();
- }
-
- public void update()
- {
-
- }
-
- public void save()
- {
- ag.save();
- }
-
-
- private AugeasNode getLoadedNode(String path) throws AugeasTreeException
- {
- if (nodeBuffer.isNodeLoaded(path))
- return nodeBuffer.getNode(path);
-
- throw new AugeasTreeException("Node not found.");
- }
-
- public AugeasNode getNode(String path) throws AugeasTreeException
- {
- AugeasNode node;
- try {
- node = getLoadedNode(path);
- }catch(AugeasTreeException e)
- {
- node = createNode(path);
- }
-
- return node;
- }
-
- public List<AugeasNode> match(String expression) throws AugeasTreeException
- {
- List<String> res = ag.match(expression);
+ private AugeasModuleConfig moduleConfig;
+ private Augeas ag;
+ private AugeasNode rootNode;
+ private AugeasNode rootConfigNode;
+ private AugeasNodeBuffer nodeBuffer;
+ private String [] errorNodes =
{"pos","line","char","lens","message"};
+
+ private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
+
+ public AugeasTreeReal(Augeas ag ,AugeasModuleConfig moduleConfig)
+ {
+ rootNode = new AugeasRootNode();
+ nodeBuffer = new AugeasNodeBuffer();
+ this.moduleConfig = moduleConfig;
+ this.ag = ag;
+ }
+
+ public void load() throws AugeasTreeException
+ {
+ buildTree();
+ }
+
+ public void update()
+ {
+
+ }
+
+ public void save()
+ {
+ ag.save();
+ }
+
+
+ private AugeasNode getLoadedNode(String path) throws AugeasTreeException
+ {
+ if (nodeBuffer.isNodeLoaded(path))
+ return nodeBuffer.getNode(path);
+
+ throw new AugeasTreeException("Node not found.");
+ }
+
+ public AugeasNode getNode(String path) throws AugeasTreeException
+ {
+ AugeasNode node;
+ try {
+ node = getLoadedNode(path);
+ }catch(AugeasTreeException e)
+ {
+ node = createNode(path);
+ }
+
+ return node;
+ }
+
+ public List<AugeasNode> match(String expression) throws AugeasTreeException
+ {
+ List<String> res = ag.match(expression);
- List<AugeasNode> nodes = new ArrayList<AugeasNode>();
-
- for (String name:res){
- nodes.add(getNode(name));
- }
-
- return nodes;
- }
-
- public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws
AugeasTreeException
- {
- if (rootNode.getChildNodes().isEmpty())
- throw new AugeasTreeException("Root node has not childs.");
-
- if (node.equals(rootNode)){
- List<AugeasNode> nodes = rootNode.getChildNodes();
- List<AugeasNode> returnNodes = new ArrayList<AugeasNode>();
- for (AugeasNode nd :nodes)
- {
- String tempName = nd.getFullPath()+expression;
- List<AugeasNode> temp = match(tempName);
- returnNodes.addAll(temp);
- }
- return returnNodes;
- }
-
- return match(node.getFullPath()+File.separatorChar+expression);
- }
-
- public AugeasNode createNode(String fullPath) throws AugeasTreeException
- {
- AugeasNode node=null;
-
- int index = fullPath.lastIndexOf(File.separatorChar);
- if (index!=-1){
- String parentPath = fullPath.substring(0,index);
- AugeasNode parentNode = getNode(parentPath);
- node= new AugeasNodeReal(parentNode,this,fullPath);
- } else
- throw new AugeasTreeException("Node can not be created. Parent node does not
exist.");
-
- node.setValue(get(fullPath));
-
- List<AugeasNode> childs = match(fullPath + File.separatorChar+"*");
-
- for (AugeasNode chd : childs){
- node.addChildNode(chd);
- }
- nodeBuffer.addNode(node);
- return node;
-
- }
-
- public AugeasNode createNode(AugeasNode parentNode,String value,int seq)
- {
- return null;
- }
-
- public String get(String expr)
- {
- return ag.get(expr);
- }
-
- public AugeasNode getRootNode(){
- return rootNode;
- }
-
- private void buildTree() throws AugeasTreeException
- {
- rootConfigNode = createNode("/augeas");
-
- for (String name : moduleConfig.getIncludedGlobs())
- {
- rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
- }
- }
-
- public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
- {
- int seq = node.getSeq();
-
- List<AugeasNode> nodes = matchRelative(node.getParentNode(),
File.separatorChar+node.getLabel()+"[position() >
"+String.valueOf(seq)+"]");
-
- for (AugeasNode nds : nodes){
- nds.setSeq(nds.getSeq()-1);
- nds.updateFromParent();
- }
-
- int res = ag.remove(node.getFullPath());
- nodeBuffer.removeNode(node,updateSeq,false);
+ List<AugeasNode> nodes = new ArrayList<AugeasNode>();
+
+ for (String name:res){
+ nodes.add(getNode(name));
+ }
+
+ return nodes;
+ }
+
+ public List<AugeasNode> matchRelative(AugeasNode node,String expression)
throws AugeasTreeException
+ {
+ if (rootNode.getChildNodes().isEmpty())
+ throw new AugeasTreeException("Root node has not
childs.");
+
+ if (node.equals(rootNode)){
+ List<AugeasNode> nodes = rootNode.getChildNodes();
+ List<AugeasNode> returnNodes = new
ArrayList<AugeasNode>();
+ for (AugeasNode nd :nodes)
+ {
+ String tempName = nd.getFullPath()+expression;
+ List<AugeasNode> temp = match(tempName);
+ returnNodes.addAll(temp);
+ }
+ return returnNodes;
+ }
+
+ return match(node.getFullPath()+File.separatorChar+expression);
+ }
+
+ public AugeasNode createNode(String fullPath) throws AugeasTreeException
+ {
+ AugeasNode node=null;
+
+ int index = fullPath.lastIndexOf(File.separatorChar);
+ if (index!=-1){
+ String parentPath = fullPath.substring(0,index);
+ AugeasNode parentNode = getNode(parentPath);
+ node= new AugeasNodeReal(parentNode,this,fullPath);
+ } else
+ throw new AugeasTreeException("Node can not be
created. Parent node does not exist.");
+
+ node.setValue(get(fullPath));
+
+ List<AugeasNode> childs = match(fullPath +
File.separatorChar+"*");
+
+ for (AugeasNode chd : childs){
+ node.addChildNode(chd);
+ }
+ nodeBuffer.addNode(node);
+ return node;
+
+ }
+
+ 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;
+ }
+
+ public String get(String expr)
+ {
+ return ag.get(expr);
+ }
+
+ public AugeasNode getRootNode(){
+ return rootNode;
+ }
+
+ private void buildTree() throws AugeasTreeException
+ {
+ rootConfigNode = createNode("/augeas");
+
+ for (String name : moduleConfig.getIncludedGlobs())
+ {
+
rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
+ }
+ }
+
+ public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
+ {
+ int seq = node.getSeq();
+
+ List<AugeasNode> nodes = matchRelative(node.getParentNode(),
File.separatorChar+node.getLabel()+"[position() >
"+String.valueOf(seq)+"]");
+
+ for (AugeasNode nds : nodes){
+ nds.setSeq(nds.getSeq()-1);
+ nds.updateFromParent();
+ }
+
+ int res = ag.remove(node.getFullPath());
+ nodeBuffer.removeNode(node,updateSeq,false);
}
-
- public void setValue(AugeasNode node,String value)
- {
- ag.set(node.getFullPath(), value);
- }
- /*
- protected String summarizeAugeasError(Augeas augeas) {
- StringBuilder summary = new StringBuilder();
- String metadataNodePrefix = "/augeas/files";
- for (String glob : moduleConfig.getIncludedGlobs()) {
- if (glob.startsWith(""+File.separatorChar)) {
- glob = glob.substring(1);
- }
- AugeasNode metadataNode = new AugeasNodeLazy();
- AugeasNode errorNode = new AugeasNode(metadataNode, "error");
- List<String> nodePaths = augeas.match(errorNode.getPath() +
"/*");
- for (String path : nodePaths) {
- String error = augeas.get(path);
- summary.append("File
\"").append(path.substring(metadataNodePrefix.length(), path.length())).append(
- "\":\n").append(error).append("\n");
- }
- }
+
+ public void setValue(AugeasNode node,String value)
+ {
+ ag.set(node.getFullPath(), value);
+ }
+
+
+
+ public String summarizeAugeasError() {
+
+ String nodePrefix = "/augeas/files";
+ List<String> str = moduleConfig.getIncludedGlobs();
+ StringBuilder builder = new StringBuilder();
+
+ for (String path : str) {
+ String name = nodePrefix +
path+File.separatorChar+"error";
+ if (ag.exists(name))
+ {
+ builder.append("Error "+ag.get(name)+'\n');
+ for (String errNd : errorNodes)
+ {
+ String pathToMessage = name+File.separatorChar+errNd;
+ if (ag.exists(pathToMessage))
+ {
+ builder.append(errNd + "
"+ag.get(pathToMessage)+'\n');
+ }
+ }
+ }
+ }
- return summary.toString();
- }
-*/
+ return builder.toString();
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
index 6b8ddf4..dbdf10a 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
@@ -1,12 +1,39 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.plugins.iptables;
import org.rhq.augeas.AugeasComponent;
import org.rhq.augeas.tree.AugeasTree;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasRHQComponent <T extends ResourceComponent> extends
ResourceComponent<T>{
- public AugeasTree getAugeasTree() throws Exception;
+ public AugeasTree getAugeasTree() throws Exception;
public AugeasComponent getAugeasComponent() throws Exception;
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
index e3bbec1..d7f194d 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
@@ -1,3 +1,26 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.plugins.iptables;
import java.io.File;
@@ -16,68 +39,72 @@ import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesChainComponent implements
AugeasRHQComponent<IptablesTableComponent>, ConfigurationFacet{
- private String tableName;
- private String chainName;
- private AugeasTree augeasTree;
- private ResourceContext<IptablesTableComponent> context;
- private IptablesTableComponent parentComponent;
- private final Log log = LogFactory.getLog(this.getClass());
-
- public void start(ResourceContext<IptablesTableComponent> context)
- throws InvalidPluginConfigurationException, Exception {
- this.context = context;
- this.parentComponent = context.getParentResourceComponent();
- this.chainName = context.getResourceKey();
- this.tableName= context.getParentResourceComponent().getTableName();
- }
+ private String tableName;
+ private String chainName;
+ private AugeasTree augeasTree;
+ private ResourceContext<IptablesTableComponent> context;
+ private IptablesTableComponent parentComponent;
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public void start(ResourceContext<IptablesTableComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+ this.context = context;
+ this.parentComponent = context.getParentResourceComponent();
+ this.chainName = context.getResourceKey();
+ this.tableName= context.getParentResourceComponent().getTableName();
+ }
- public void stop() {
-
- }
+ public void stop() {
+
+ }
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
- }
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
- public Configuration loadResourceConfiguration() throws Exception {
- augeasTree = getAugeasTree();
-
- ConfigurationDefinition resourceConfigDef = this.context.getResourceType()
+ public Configuration loadResourceConfiguration() throws Exception {
+ augeasTree = getAugeasTree();
+
+ ConfigurationDefinition resourceConfigDef =
this.context.getResourceType()
.getResourceConfigurationDefinition();
- IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
- List<AugeasNode> nodes = getIptablesChainNode(chainName);
- Configuration config= null;
- if (!nodes.isEmpty())
- config = trans.transform(nodes, resourceConfigDef);
+ IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
+ List<AugeasNode> nodes = getIptablesChainNode(chainName);
+ Configuration config= null;
+ if (!nodes.isEmpty())
+ config = trans.transform(nodes, resourceConfigDef);
- return config;
- }
+ return config;
+ }
- public void updateResourceConfiguration(ConfigurationUpdateReport config) {
- IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
- trans.updateAugeas(config.getConfiguration(), new ArrayList<AugeasNode>());
- }
-
- public AugeasComponent getAugeasComponent() throws Exception {
- return parentComponent.getAugeasComponent();
- }
+ public void updateResourceConfiguration(ConfigurationUpdateReport config) {
+ IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
+ trans.updateAugeas(config.getConfiguration(), new
ArrayList<AugeasNode>());
+ }
+
+ public AugeasComponent getAugeasComponent() throws Exception {
+ return parentComponent.getAugeasComponent();
+ }
- public AugeasTree getAugeasTree() throws Exception {
- return parentComponent.getAugeasTree();
- }
-
- private List<AugeasNode> getIptablesChainNode(String chainName) throws Exception{
- if (augeasTree == null)
- return null;
- String expr = File.separatorChar+tableName+File.separatorChar+chainName;
-
- List<AugeasNode> nodes = augeasTree.matchRelative(augeasTree.getRootNode(),
expr);
-
- return nodes;
- }
+ public AugeasTree getAugeasTree() throws Exception {
+ return parentComponent.getAugeasTree();
+ }
+
+ private List<AugeasNode> getIptablesChainNode(String chainName) throws
Exception{
+ if (augeasTree == null)
+ return null;
+ String expr = File.separatorChar+tableName+File.separatorChar+chainName;
+
+ List<AugeasNode> nodes =
augeasTree.matchRelative(augeasTree.getRootNode(), expr);
+
+ return nodes;
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
index 44e8cc0..8c4a1ce 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.iptables;
import java.io.File;
@@ -14,27 +36,31 @@ import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesChainDiscoveryComponent implements
ResourceDiscoveryComponent<IptablesTableComponent>{
- private final Log log = LogFactory.getLog(this.getClass());
-
- public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext<IptablesTableComponent> context)
- throws InvalidPluginConfigurationException, Exception {
-
- AugeasTree tree = context.getParentResourceComponent().getAugeasTree();
- String tableName = context.getParentResourceComponent().getTableName();
-
- List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(),
File.separatorChar+tableName+File.separatorChar+"settings"+File.separatorChar+"chain");
- ResourceType resourceType = context.getResourceType();
-
- Set<DiscoveredResourceDetails> resources = new
HashSet<DiscoveredResourceDetails>();
-
- for (AugeasNode nd : nodes){
- String value = nd.getValue();
- resources.add(new DiscoveredResourceDetails(resourceType,value, value, "",
"Chain", null, null));
- }
-
- return resources;
- }
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext<IptablesTableComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ AugeasTree tree =
context.getParentResourceComponent().getAugeasTree();
+ String tableName =
context.getParentResourceComponent().getTableName();
+
+ List<AugeasNode> nodes =
tree.matchRelative(tree.getRootNode(),
File.separatorChar+tableName+File.separatorChar+"settings"+File.separatorChar+"chain");
+ ResourceType resourceType = context.getResourceType();
+
+ Set<DiscoveredResourceDetails> resources = new
HashSet<DiscoveredResourceDetails>();
+
+ for (AugeasNode nd : nodes){
+ String value = nd.getValue();
+ resources.add(new
DiscoveredResourceDetails(resourceType,value, value, "", "Chain",
null, null));
+ }
+
+ return resources;
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
index 7861ef1..e95c2a6 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.iptables;
import org.apache.commons.logging.Log;
@@ -11,86 +33,90 @@ import
org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.rhqtransform.RhqConfig;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesComponent implements AugeasRHQComponent, ConfigurationFacet{
- private ResourceContext context;
- private final Log log = LogFactory.getLog(this.getClass());
- private AugeasTree augeasTree;
- private AugeasComponent augeasComponent;
-
- public void start(ResourceContext context)
- throws InvalidPluginConfigurationException, Exception {
- this.context = context;
- }
+ private ResourceContext context;
+ private final Log log = LogFactory.getLog(this.getClass());
+ private AugeasTree augeasTree;
+ private AugeasComponent augeasComponent;
+
+ public void start(ResourceContext context)
+ throws InvalidPluginConfigurationException, Exception {
+ this.context = context;
+ }
- public void stop() {
-
- }
+ public void stop() {
+
+ }
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
- }
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
- public Configuration loadResourceConfiguration() throws Exception {
- Configuration pluginConfiguration = new Configuration();
-
- AugeasTree tree=null;
- AugeasComponent augeas =null;
- try {
- RhqConfig config = new RhqConfig(context.getPluginConfiguration());
- augeas = new AugeasComponent(config);
- augeas.load();
- tree = augeas.getAugeasTree("Iptables", true);
- tree.load();
-
- }catch(Exception e)
- {
- log.error(e.getMessage());
-
- }
- return pluginConfiguration;
- }
-
+ public Configuration loadResourceConfiguration() throws Exception {
+ Configuration pluginConfiguration = new Configuration();
+
+ AugeasTree tree=null;
+ AugeasComponent augeas =null;
+ try {
+ RhqConfig config = new
RhqConfig(context.getPluginConfiguration());
+ augeas = new AugeasComponent(config);
+ augeas.load();
+ tree = augeas.getAugeasTree("Iptables", true);
+ tree.load();
+
+ }catch(Exception e)
+ {
+ log.error(e.getMessage());
+
+ }
+ return pluginConfiguration;
+ }
+
- public void updateResourceConfiguration(ConfigurationUpdateReport report) {
- Configuration pluginConfiguration = new Configuration();
- AugeasTree tree=null;
- AugeasComponent augeas =null;
- try {
- RhqConfig config = new RhqConfig(context.getPluginConfiguration());
- augeas = new AugeasComponent(config);
-
- tree = augeas.getAugeasTree("Iptables", false);
-
-
- }catch(Exception e)
- {
- log.error(e);
- }
-
- }
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ Configuration pluginConfiguration = new Configuration();
+ AugeasTree tree=null;
+ AugeasComponent augeas =null;
+ try {
+ RhqConfig config = new
RhqConfig(context.getPluginConfiguration());
+ augeas = new AugeasComponent(config);
+
+ tree = augeas.getAugeasTree("Iptables", false);
+
+
+ }catch(Exception e)
+ {
+ log.error(e);
+ }
+
+ }
- public void loadAugeas() throws Exception{
- RhqConfig config = new RhqConfig(context.getPluginConfiguration());
- augeasComponent = new AugeasComponent(config);
- augeasComponent.load();
- augeasTree = augeasComponent.getAugeasTree("Iptables", true);
- augeasTree.load();
-
- }
- public AugeasComponent getAugeasComponent() throws Exception{
+ public void loadAugeas() throws Exception{
+ RhqConfig config = new RhqConfig(context.getPluginConfiguration());
+ augeasComponent = new AugeasComponent(config);
+ augeasComponent.load();
+ augeasTree = augeasComponent.getAugeasTree("Iptables", true);
+ augeasTree.load();
+
+ }
+ public AugeasComponent getAugeasComponent() throws Exception{
if (augeasComponent == null)
- loadAugeas();
+ loadAugeas();
return augeasComponent;
- }
+ }
- public AugeasTree getAugeasTree() throws Exception {
- if (augeasTree == null)
- loadAugeas();
-
- return augeasTree;
- }
+ public AugeasTree getAugeasTree() throws Exception {
+ if (augeasTree == null)
+ loadAugeas();
+
+ return augeasTree;
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
index 7002800..31b661a 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.iptables;
import java.io.File;
@@ -13,173 +35,143 @@ import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.PropertyDefinition;
-import org.rhq.rhqtransform.RhqTransform;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesConfigTransform {
- private AugeasTree tree;
- private RhqTransform transf;
-
- public IptablesConfigTransform(AugeasTree tree){
- this.tree = tree;
- this.transf = new RhqTransform(tree);
- }
- /*
- public Configuration transform(List<AugeasNode> startNodes,ConfigurationDefinition
resourceConfigDef) throws Exception
- {
-
- Configuration resourceConfig = new Configuration();
- Collection<PropertyDefinition> propDefs =
resourceConfigDef.getPropertyDefinitions().values();
+ private AugeasTree tree;
- if (propDefs.size()!=1)
- throw new Exception("Error in mapping.");
-
- PropertyList propList = new PropertyList("chains");
-
- for (PropertyDefinition propDef : propDefs) {
- if (propDef.getName().equals("chain")){
- PropertyDefinition definition =
((PropertyDefinitionList)propDef).getMemberDefinition();
- for (AugeasNode node : startNodes){
- //for (AugeasNode nd : node.getChildNodes())
- propList.add(transf.loadProperty(definition,node));
- }
- }
- }
-
- resourceConfig.put(propList);
- return resourceConfig;
- }*/
-
- public Configuration transform(List<AugeasNode> startNodes,ConfigurationDefinition
resourceConfigDef) throws Exception
- {
- Configuration resourceConfig = new Configuration();
+
+ public IptablesConfigTransform(AugeasTree tree){
+ this.tree = tree;
- if (startNodes.isEmpty())
- {
- PropertyList propList = new PropertyList("chains");
- PropertyMap mp = new PropertyMap("rule");
- propList.add(mp);
- resourceConfig.put(propList);
- return resourceConfig;
- }
-
- Collection<PropertyDefinition> propDefs =
resourceConfigDef.getPropertyDefinitions().values();
+ }
+
+ public Configuration transform(List<AugeasNode>
startNodes,ConfigurationDefinition resourceConfigDef) throws Exception
+ {
+ Configuration resourceConfig = new Configuration();
- if (propDefs.size()!=1)
- throw new Exception("Error in mapping.");
-
- PropertyList propList = new PropertyList("chains");
-
- for (AugeasNode node : startNodes){
- //for (AugeasNode nd : node.getChildNodes())
- PropertyMap mp = new PropertyMap("rule");
- for (AugeasNode nd : node.getChildByLabel("rule"))
- {//rules
-
- String rule = "";
-
- for (AugeasNode tempNode : nd.getChildByLabel("parameters"))
- {
- rule += buildRule(tempNode);
- }
-
- PropertySimple ruleProp = new PropertySimple("param",rule);
- mp.put(ruleProp);
- }
- propList.add(mp);
- }
-
- resourceConfig.put(propList);
- return resourceConfig;
- }
-
- private String buildRule(AugeasNode nd) throws Exception{
- String paramName = getValue(nd,"/param/paramName");
- String negation = getValue(nd, "/param/negation");
- String value = getValue(nd, "/param/value");
-
- return (((paramName.length()> 1) ?"--" : "-") + paramName +
" " + negation + " " +value);
- }
-
- private String getValue(AugeasNode nd,String nm) throws Exception{
- List<AugeasNode> nds = tree.matchRelative(nd, nm);
- if (!nds.isEmpty())
- return nds.get(0).getValue();
- else
- return "";
- }
-
-
- public void updateAugeas(Configuration config,List<AugeasNode> nodes)
- {
- List<String> values = new ArrayList<String>();
-
- Collection<Property> props = config.getAllProperties().values();
-
- for (Property prop : props)
- {
- if (prop.getName().equals("chains")){
- PropertyList propList = (PropertyList) prop;
- for (Property property : propList.getList())
- {
- if (property.getName().equals("rule"))
- {
- PropertyMap propMap = (PropertyMap) property;
- for (Property propVal : propMap.getMap().values()){
- if (propVal.getName().equals("param")){
- values.add(((PropertySimple)propVal).getStringValue());
- }
- }
- }
- }
- }
- }
- String name;
- }
-
-
- public void buildTree(List<AugeasNode> nodes) throws Exception
- {
- List<String> values = new ArrayList<String>();
+ if (startNodes.isEmpty())
+ {
+ PropertyList propList = new PropertyList("chains");
+ PropertyMap mp = new PropertyMap("rule");
+ propList.add(mp);
+ resourceConfig.put(propList);
+ return resourceConfig;
+ }
+
+ PropertyList propList = new PropertyList("chains");
+
+ for (AugeasNode node : startNodes){
+ //for (AugeasNode nd : node.getChildNodes())
+ PropertyMap mp = new PropertyMap("rule");
+ for (AugeasNode nd :
node.getChildByLabel("rule"))
+ {//rules
+
+ String rule = "";
+
+ for (AugeasNode tempNode :
nd.getChildByLabel("parameters"))
+ {
+ rule += buildRule(tempNode);
+ }
+
+ PropertySimple ruleProp = new
PropertySimple("param",rule);
+ mp.put(ruleProp);
+ }
+ propList.add(mp);
+ }
+
+ resourceConfig.put(propList);
+ return resourceConfig;
+ }
+
+ private String buildRule(AugeasNode nd) throws Exception{
+ String paramName = getValue(nd,"/param/paramName");
+ String negation = getValue(nd, "/param/negation");
+ String value = getValue(nd, "/param/value");
+
+ return (((paramName.length()> 1) ?"--" : "-") +
paramName + " " + negation + " " +value);
+ }
+
+ private String getValue(AugeasNode nd,String nm) throws Exception{
+ List<AugeasNode> nds = tree.matchRelative(nd, nm);
+ if (!nds.isEmpty())
+ return nds.get(0).getValue();
+ else
+ return "";
+ }
+
+
+ public void updateAugeas(Configuration config,List<AugeasNode> nodes)
+ {
+ List<String> values = new ArrayList<String>();
+
+ Collection<Property> props = config.getAllProperties().values();
+
+ for (Property prop : props)
+ {
+ if (prop.getName().equals("chains")){
+ PropertyList propList = (PropertyList) prop;
+ for (Property property : propList.getList())
+ {
+ if (property.getName().equals("rule"))
+ {
+ PropertyMap propMap = (PropertyMap) property;
+ for (Property propVal : propMap.getMap().values()){
+ if (propVal.getName().equals("param")){
+
values.add(((PropertySimple)propVal).getStringValue());
+ }
+ }
+ }
+ }
+ }
+ }
+ String name;
+ }
+
+
+ public void buildTree(List<AugeasNode> nodes) throws Exception
+ {
+ List<String> values = new ArrayList<String>();
- for (AugeasNode node : nodes){
- PropertyMap mp = new PropertyMap("rule");
- for (AugeasNode nd : node.getChildByLabel("rule"))
- {
- String rule = "";
- for (AugeasNode tempNode : nd.getChildByLabel("parameters"))
- {
- rule += buildRule(tempNode);
- }
-
- values.add(rule);
- }
+ for (AugeasNode node : nodes){
+ PropertyMap mp = new PropertyMap("rule");
+ for (AugeasNode nd : node.getChildByLabel("rule"))
+ {
+ String rule = "";
+ for (AugeasNode tempNode :
nd.getChildByLabel("parameters"))
+ {
+ rule += buildRule(tempNode);
+ }
+
+ values.add(rule);
+ }
}
- }
-
- public void compare(List<String> values,AugeasTree tree,String chainName,String
tableName) throws Exception
- {
- String expr = File.separatorChar+tableName+File.separatorChar+chainName;
-
- List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(), expr);
-
- for (AugeasNode node : nodes)
- {
- node.remove(false);
- }
- int i =1;
- for (String val : values){
-
- i = i + 1;
- String temp =
File.separatorChar+tableName+File.separatorChar+chainName+"["+String.valueOf(i)
+"]"+File.separatorChar+"rule";
-
-
- }
- }
-
- public void addToAugeas(String parent,String param){
-
- }
-
+ }
+
+ public void compare(List<String> values,AugeasTree tree,String
chainName,String tableName) throws Exception
+ {
+ String expr = File.separatorChar+tableName+File.separatorChar+chainName;
+
+ List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(),
expr);
+
+ for (AugeasNode node : nodes)
+ {
+ node.remove(false);
+ }
+ int i =1;
+ for (String val : values){
+ i = i + 1;
+ String temp =
File.separatorChar+tableName+File.separatorChar+chainName+"["+String.valueOf(i)
+"]"+File.separatorChar+"rule";
+
+ }
+ }
+
+ public void addToAugeas(String parent,String param){
+
+ }
+
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
index c99bc70..3c0f25d 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.iptables;
import java.util.HashSet;
@@ -9,26 +31,30 @@ import
org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.rhqtransform.RhqConfig;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesDiscoveryComponent implements ResourceDiscoveryComponent {
- public Set discoverResources(ResourceDiscoveryContext discoveryContext)
- throws InvalidPluginConfigurationException, Exception {
-
- Set<DiscoveredResourceDetails> discoveredResources = new
HashSet<DiscoveredResourceDetails>(1);
-
- Configuration pluginConfiguration = discoveryContext.getDefaultPluginConfiguration();
-
- RhqConfig config = new RhqConfig(pluginConfiguration);
-
- Set<DiscoveredResourceDetails> details = new
HashSet<DiscoveredResourceDetails>();
- DiscoveredResourceDetails resource =
+ public Set discoverResources(ResourceDiscoveryContext discoveryContext)
+ throws InvalidPluginConfigurationException, Exception {
+
+ Set<DiscoveredResourceDetails> discoveredResources = new
HashSet<DiscoveredResourceDetails>(1);
+
+ Configuration pluginConfiguration =
discoveryContext.getDefaultPluginConfiguration();
+
+ RhqConfig config = new RhqConfig(pluginConfiguration);
+
+ Set<DiscoveredResourceDetails> details = new
HashSet<DiscoveredResourceDetails>();
+ DiscoveredResourceDetails resource =
new DiscoveredResourceDetails(discoveryContext.getResourceType(),
"iptables", "IPTABLES",
"", "IPTABLES.", pluginConfiguration, null);
details.add(resource);
return details;
- }
+ }
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
index 032c41c..f88ab1a 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.iptables;
import org.rhq.augeas.AugeasComponent;
@@ -8,46 +30,50 @@ import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesTableComponent implements
AugeasRHQComponent<AugeasRHQComponent>, ConfigurationFacet{
- private String tableName;
- private AugeasRHQComponent parentComponent;
-
- public void start(ResourceContext<AugeasRHQComponent> context)
- throws InvalidPluginConfigurationException, Exception {
-
- tableName = context.getResourceKey();
- parentComponent = context.getParentResourceComponent();
- }
-
- public void stop() {
-
- }
-
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
- }
-
- public Configuration loadResourceConfiguration() throws Exception {
-
- return null;
- }
-
- public void updateResourceConfiguration(ConfigurationUpdateReport arg0) {
-
- }
-
- public String getTableName(){
- return tableName;
- }
-
- public AugeasComponent getAugeasComponent() throws Exception {
- return parentComponent.getAugeasComponent();
- }
-
- public AugeasTree getAugeasTree() throws Exception {
- return parentComponent.getAugeasTree();
- }
+ private String tableName;
+ private AugeasRHQComponent parentComponent;
+
+ public void start(ResourceContext<AugeasRHQComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ tableName = context.getResourceKey();
+ parentComponent = context.getParentResourceComponent();
+ }
+
+ public void stop() {
+
+ }
+
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
+
+ public Configuration loadResourceConfiguration() throws Exception {
+
+ return null;
+ }
+
+ public void updateResourceConfiguration(ConfigurationUpdateReport arg0) {
+
+ }
+
+ public String getTableName(){
+ return tableName;
+ }
+
+ public AugeasComponent getAugeasComponent() throws Exception {
+ return parentComponent.getAugeasComponent();
+ }
+
+ public AugeasTree getAugeasTree() throws Exception {
+ return parentComponent.getAugeasTree();
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
index cd4c20f..fd7c6e1 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
@@ -1,3 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.iptables;
import java.util.HashSet;
@@ -8,25 +30,29 @@ import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesTableDiscoveryComponent implements
ResourceDiscoveryComponent<IptablesComponent>{
- public String [] tables = {"filter","nat","mangle"};
-
- public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext<IptablesComponent> context)
- throws InvalidPluginConfigurationException, Exception {
-
- ResourceType resourceType = context.getResourceType();
- Set<DiscoveredResourceDetails> resources = new
HashSet<DiscoveredResourceDetails>();
-
- for (String tableName : tables)
- {
- resources.add(new DiscoveredResourceDetails(resourceType,
+ public String [] tables =
{"filter","nat","mangle"};
+
+ public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext<IptablesComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ ResourceType resourceType = context.getResourceType();
+ Set<DiscoveredResourceDetails> resources = new
HashSet<DiscoveredResourceDetails>();
+
+ for (String tableName : tables)
+ {
+ resources.add(new DiscoveredResourceDetails(resourceType,
tableName, tableName, "", "Table",
null, null));
- }
-
- return resources;
- }
+ }
+
+ return resources;
+ }
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
index 5ba2447..4176445 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
@@ -1,10 +1,36 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.rhqtransform;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasRhqException extends Exception{
- public AugeasRhqException(String text)
- {
- super(text);
- }
-
+ public AugeasRhqException(String text)
+ {
+ super(text);
+ }
+
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
index 5bf4694..ac24860 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
@@ -1,95 +1,49 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.rhqtransform;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.tree.AugeasTree;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-
-public class AugeasToConfiguration {
-
- private final Log log = LogFactory.getLog(this.getClass());
- private AugeasTree tree;
- private NameMap nameMap;
-
- public AugeasToConfiguration(){
-
- }
-
- public void setTree(AugeasTree tree)
- {
- this.tree = tree;
- }
-
- public void setNameMap(NameMap nameMap){
- this.nameMap = nameMap;
- }
-
- public Configuration loadResourceConfiguration(AugeasNode
startNode,ConfigurationDefinition resourceConfigDef) throws Exception {
-
- Configuration resourceConfig = new Configuration();
-
- Collection<PropertyDefinition> propDefs =
resourceConfigDef.getPropertyDefinitions().values();
-
- for (PropertyDefinition propDef : propDefs) {
- resourceConfig.put(loadProperty(propDef,startNode));
- }
-
- return resourceConfig;
- }
-
- public Property loadProperty(PropertyDefinition propDef, AugeasNode parentNode)
throws Exception{
-
- Property prop;
- if (propDef instanceof PropertyDefinitionSimple) {
- prop = createPropertySimple((PropertyDefinitionSimple) propDef,
parentNode);
- } else if (propDef instanceof PropertyDefinitionMap) {
- prop = createPropertyMap((PropertyDefinitionMap) propDef, parentNode);
- } else if (propDef instanceof PropertyDefinitionList) {
- prop = createPropertyList((PropertyDefinitionList) propDef, parentNode);
- } else {
- throw new IllegalStateException("Unsupported PropertyDefinition
subclass: " + propDef.getClass().getName());
- }
- return prop;
- }
-
- public Property createPropertySimple(PropertyDefinitionSimple propDefSimple,
AugeasNode node) throws Exception{
- Object value;
- value = node.getValue();
- return new PropertySimple(propDefSimple.getName(), value);
- }
-
- public PropertyMap createPropertyMap(PropertyDefinitionMap propDefMap, AugeasNode
node) throws Exception {
- PropertyMap propMap = new PropertyMap(propDefMap.getName());
- for (PropertyDefinition mapEntryPropDef :
propDefMap.getPropertyDefinitions().values()) {
- propMap.put(loadProperty(mapEntryPropDef, node));
- }
- return propMap;
- }
-
- public Property createPropertyList(PropertyDefinitionList propDefList, AugeasNode
node) throws Exception{
-
- PropertyList propList = new PropertyList(propDefList.getName());
-
- List<AugeasNode> nodes = tree.matchRelative(node, propDefList.getName());
- PropertyDefinition listMemberPropDef = propDefList.getMemberDefinition();
-
- for (AugeasNode listMemberNode : nodes){
- propList.add(loadProperty(listMemberPropDef,listMemberNode));
- }
-
- return propList;
- }
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public interface AugeasToConfiguration {
+
+ public void setTree(AugeasTree tree);
+ public void setNameMap(NameMap nameMap);
+ public Configuration loadResourceConfiguration(AugeasNode
startNode,ConfigurationDefinition resourceConfigDef)throws Exception;
+ public Property loadProperty(PropertyDefinition propDef, AugeasNode parentNode)
throws Exception;
+ public Property createPropertySimple(PropertyDefinitionSimple propDefSimple,
AugeasNode node) throws Exception;
+ public PropertyMap createPropertyMap(PropertyDefinitionMap propDefMap, AugeasNode
node) throws Exception;
+ public Property createPropertyList(PropertyDefinitionList propDefList, AugeasNode
node) throws Exception;
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
index 93d711f..1aea026 100644
---
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
+++
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
@@ -1,147 +1,47 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.rhqtransform;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.tree.AugeasTree;
-import org.rhq.core.domain.configuration.AbstractPropertyMap;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
-
-public class ConfigurationToAugeas {
-
- private AugeasTree tree;
-
- public void updateResourceConfiguration(ConfigurationDefinition
resourceConfigDef,Configuration resourceConfig) throws Exception{
-
- Collection<PropertyDefinition> propDefs =
resourceConfigDef.getPropertyDefinitions().values();
- for (PropertyDefinition propDef : propDefs) {
- setNode(propDef, resourceConfig, tree.getRootNode());
- }
- }
-
- protected void setNode(PropertyDefinition propDef, AbstractPropertyMap
parentPropMap,
- AugeasNode parentNode) throws Exception{
-
- String propName = propDef.getName();
-
- AugeasNode node;
-
- if (propName.equals("."))
- node = parentNode;
- else
- {
- List<AugeasNode> nodes = tree.matchRelative(parentNode, propName);
- if (nodes.isEmpty())
- throw new Exception("Error in mapping");
- node = nodes.get(0);
- }
-
- if (isPropertyDefined(propDef, parentPropMap)) {
- // The property *is* defined, which means we either need to add or update
the corresponding node in the
- // Augeas tree.
- if (propDef instanceof PropertyDefinitionSimple) {
- PropertyDefinitionSimple propDefSimple = (PropertyDefinitionSimple)
propDef;
- PropertySimple propSimple =
parentPropMap.getSimple(propDefSimple.getName());
- setNodeFromPropertySimple( node, propDefSimple, propSimple);
- } else if (propDef instanceof PropertyDefinitionMap) {
- PropertyDefinitionMap propDefMap = (PropertyDefinitionMap) propDef;
- PropertyMap propMap = parentPropMap.getMap(propDefMap.getName());
- setNodeFromPropertyMap(propDefMap, propMap, node);
- } else if (propDef instanceof PropertyDefinitionList) {
- PropertyDefinitionList propDefList = (PropertyDefinitionList) propDef;
- PropertyList propList = parentPropMap.getList(propDefList.getName());
- setNodeFromPropertyList(propDefList, propList, node);
- } else {
- throw new IllegalStateException("Unsupported PropertyDefinition
subclass: "
- + propDef.getClass().getName());
- }
- } else {
- // The property *is not* defined - remove the corresponding node from the
Augeas tree if it exists.
- node.remove();
- }
- }
-
- protected void setNodeFromPropertySimple(AugeasNode node, PropertyDefinitionSimple
propDefSimple,
- PropertySimple propSimple) {
- String value = propSimple.getStringValue();
-
- // Update the value of the existing node.
- node.setValue(value);
- }
-
- protected void setNodeFromPropertyMap(PropertyDefinitionMap propDefMap, PropertyMap
propMap,
- AugeasNode mapNode) throws Exception{
- for (PropertyDefinition mapEntryPropDef :
propDefMap.getPropertyDefinitions().values()) {
- setNode(mapEntryPropDef, propMap, mapNode);
- }
- }
-
- protected void setNodeFromPropertyList(PropertyDefinitionList propDefList,
PropertyList propList,
- AugeasNode listNode) {
- PropertyDefinition listMemberPropDef = propDefList.getMemberDefinition();
-
- PropertyDefinitionMap listMemberPropDefMap = (PropertyDefinitionMap)
listMemberPropDef;
-
- int listIndex = 0;
- String listMemberPropDefMapPath = listMemberPropDefMap.getName();
- List<AugeasNode> existingListMemberNodes =
listNode.getChildByLabel(listMemberPropDefMapPath);
-
- Set<AugeasNode> updatedListMemberNodes = new HashSet<AugeasNode>();
- for (Property listMemberProp : propList.getList()) {
- PropertyMap listMemberPropMap = (PropertyMap) listMemberProp;
- AugeasNode memberNodeToUpdate =
getExistingChildNodeForListMemberPropertyMap(listNode, propDefList,
- listMemberPropMap);
- if (memberNodeToUpdate != null) {
- // Keep track of the existing nodes that we'll be updating, so that
we can remove all other existing
- // nodes.
- updatedListMemberNodes.add(memberNodeToUpdate);
- } else {
- // The maps in the list are non-keyed, or there is no map in the list
with the same key as the map
- // being added, so create a new node for the map to add to the list.
- AugeasNode basePathNode = getNewListMemberNode(listNode,
listMemberPropDefMap, listIndex);
- String var = "prop" + listIndex;
- augeas.defineNode(var, basePathNode.getPath(), null);
- memberNodeToUpdate = new AugeasNode("$" + var);
- listIndex++;
- }
-
- // Update the node's children.
- setNodeFromPropertyMap(listMemberPropDefMap, listMemberPropMap, augeas,
memberNodeToUpdate);
- }
-
- // Now remove any existing nodes that we did not update in the previous loop.
- for (AugeasNode existingListMemberNode : existingListMemberNodes) {
- if (!updatedListMemberNodes.contains(existingListMemberNode)) {
- augeas.remove(existingListMemberNode.getPath());
- }
- }
- }
-
- protected AugeasNode getNewListMemberNode(AugeasNode listNode, PropertyDefinitionMap
listMemberPropDefMap,
- int listIndex) {
- return new AugeasNode(listNode,
getAugeasPathRelativeToParent(listMemberPropDefMap, listNode, getAugeas())
- + "[" + listIndex + "]");
- }
-
- private boolean isPropertyDefined(PropertyDefinition propDef, AbstractPropertyMap
parentPropMap) {
- Property prop = parentPropMap.get(propDef.getName());
- if (prop == null) {
- return false;
- } else {
- return (!(prop instanceof PropertySimple) || ((PropertySimple)
prop).getStringValue() != null);
- }
- }
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public interface ConfigurationToAugeas {
+
+ public void setTree(AugeasTree tree);
+ public void updateResourceConfiguration(AugeasNode node,ConfigurationDefinition
resourceConfigDef,Configuration resourceConfig) throws Exception;
+ public void updateMap(PropertyDefinitionMap propDefMap, Property prop,AugeasNode
mapNode,int seq) throws Exception;
+ public void updateList(PropertyDefinitionList propDef, Property prop,AugeasNode
listNode,int seq) throws Exception;
+ public void updateSimple(AugeasNode parentNode, PropertyDefinitionSimple
propDef,Property prop,int seq) throws Exception;
+ public void updateProperty(PropertyDefinition propDef, Property
parentProp,AugeasNode parentNode,int seq) throws Exception;
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
index afe74aa..0f18027 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
@@ -1,9 +1,35 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.rhqtransform;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface NameMap {
- public String getSimplePropertyName();
- public String getMapPropertyName();
- public String getListPropertyName();
-
+ public String getSimplePropertyName();
+ public String getMapPropertyName();
+ public String getListPropertyName();
+
}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java
new file mode 100644
index 0000000..043368d
--- /dev/null
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java
@@ -0,0 +1,40 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.rhqtransform;
+
+import org.rhq.augeas.AugeasComponent;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public interface RhqAugeasMapping {
+
+ public void updateAugeas(AugeasComponent augeasComponent,Configuration config,
+ ConfigurationDefinition configDef) throws Exception;
+ public Configuration updateConfiguration(AugeasComponent
augeasComponent,ConfigurationDefinition configDef) throws Exception;
+
+}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
index 91f6618..9f03a06 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
@@ -1,3 +1,26 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.rhqtransform;
import java.io.File;
@@ -5,53 +28,55 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-
import net.augeas.Augeas;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.augeas.config.AugeasConfiguration;
import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
-
-
+/**
+ *
+ * @author Filip Drabek
+ * @author Ian Springer
+ *
+ */
public class RhqConfig implements AugeasConfiguration{
- public static final String INCLUDE_GLOBS_PROP =
"configurationFilesInclusionPatterns";
- public static final String EXCLUDE_GLOBS_PROP =
"configurationFilesExclusionPatterns";
- public static final String AUGEAS_MODULE_NAME_PROP = "augeasModuleName";
- private static final String AUGEAS_LOAD_PATH = "augeasLoadPath";
-
- public static final String DEFAULT_AUGEAS_ROOT_PATH =
File.listRoots()[0].getPath();
-
- private final Log log = LogFactory.getLog(this.getClass());
- private List<AugeasModuleConfig> modules;
- private String loadPath;
-
- public RhqConfig(Configuration configuration) throws AugeasRhqException{
- List<String> includes = determineGlobs(configuration,INCLUDE_GLOBS_PROP);
- List<String> excludes = determineGlobs(configuration,EXCLUDE_GLOBS_PROP);
- modules = new ArrayList<AugeasModuleConfig>();
- if (includes.isEmpty())
- throw new AugeasRhqException("At least one Include glob must be
defined.");
+ public static final String INCLUDE_GLOBS_PROP =
"configurationFilesInclusionPatterns";
+ public static final String EXCLUDE_GLOBS_PROP =
"configurationFilesExclusionPatterns";
+ public static final String AUGEAS_MODULE_NAME_PROP =
"augeasModuleName";
+ private static final String AUGEAS_LOAD_PATH = "augeasLoadPath";
+
+ public static final String DEFAULT_AUGEAS_ROOT_PATH =
File.listRoots()[0].getPath();
+
+ private final Log log = LogFactory.getLog(this.getClass());
+ private List<AugeasModuleConfig> modules;
+ private String loadPath;
+
+ public RhqConfig(Configuration configuration) throws AugeasRhqException{
+ List<String> includes =
determineGlobs(configuration,INCLUDE_GLOBS_PROP);
+ List<String> excludes =
determineGlobs(configuration,EXCLUDE_GLOBS_PROP);
+ modules = new ArrayList<AugeasModuleConfig>();
+ if (includes.isEmpty())
+ throw new AugeasRhqException("At least one Include glob must be
defined.");
- AugeasModuleConfig config = new AugeasModuleConfig();
- config.setIncludedGlobs(includes);
- config.setExcludedGlobs(excludes);
- config.setLensPath(getAugeasModuleName(configuration)+".lns");
- config.setModuletName(getAugeasModuleName(configuration));
- modules.add(config);
-
- loadPath = configuration.getSimpleValue(AUGEAS_LOAD_PATH, null);
- }
-
-
+ AugeasModuleConfig config = new AugeasModuleConfig();
+ config.setIncludedGlobs(includes);
+ config.setExcludedGlobs(excludes);
+ config.setLensPath(getAugeasModuleName(configuration)+".lns");
+ config.setModuletName(getAugeasModuleName(configuration));
+ modules.add(config);
+
+ loadPath = configuration.getSimpleValue(AUGEAS_LOAD_PATH, null);
+ }
+
+
protected List<String> determineGlobs(Configuration configuration,String name) {
PropertySimple includeGlobsProp = configuration.getSimple(name);
if (includeGlobsProp== null)
- return null;
+ return null;
List<String> ret = new ArrayList<String>();
ret.addAll(getGlobList(includeGlobsProp));
@@ -60,7 +85,7 @@ public class RhqConfig implements AugeasConfiguration{
}
protected String getAugeasModuleName(Configuration configuration){
- return (configuration.getSimpleValue(AUGEAS_MODULE_NAME_PROP, null));
+ return (configuration.getSimpleValue(AUGEAS_MODULE_NAME_PROP, null));
}
public static PropertySimple getGlobList(String name, List<String> simples) {
@@ -85,10 +110,10 @@ public class RhqConfig implements AugeasConfiguration{
}
public Configuration updateConfiguration(Configuration configuration) throws
AugeasRhqException{
- if (modules.isEmpty())
- throw new AugeasRhqException("Error in augeas Configuration.");
- AugeasModuleConfig tempModule = modules.get(0);
-
+ if (modules.isEmpty())
+ throw new AugeasRhqException("Error in augeas
Configuration.");
+ AugeasModuleConfig tempModule = modules.get(0);
+
PropertySimple includeProps = getGlobList(INCLUDE_GLOBS_PROP,
tempModule.getIncludedGlobs());
PropertySimple excludeProps = getGlobList(EXCLUDE_GLOBS_PROP,
tempModule.getExcludedGlobs());
configuration.put(includeProps);
@@ -98,18 +123,18 @@ public class RhqConfig implements AugeasConfiguration{
}
public String getLoadPath() {
- return loadPath;
+ return loadPath;
}
public int getMode() {
- return Augeas.NO_MODL_AUTOLOAD;
+ return Augeas.NO_MODL_AUTOLOAD;
}
public List<AugeasModuleConfig> getModules() {
- return modules;
+ return modules;
}
public String getRootPath() {
- return DEFAULT_AUGEAS_ROOT_PATH;
+ return DEFAULT_AUGEAS_ROOT_PATH;
}
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java
deleted file mode 100644
index b284aa0..0000000
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.rhq.rhqtransform;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.augeas.tree.AugeasTree;
-import org.rhq.core.domain.configuration.Configuration;
-
-public class RhqTransform {
-
- private final Log log = LogFactory.getLog(this.getClass());
- private AugeasTree tree;
-
- public RhqTransform(AugeasTree tree){
- this.tree = tree;
- }
-
-
- public Configuration updateConfiguration(){
- return null;
- }
-
- public AugeasTree updateAugeas(){
- return null;
- }
-}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java
new file mode 100644
index 0000000..51fbafd
--- /dev/null
+++
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java
@@ -0,0 +1,123 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.rhqtransform.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.augeas.node.AugeasNode;
+import org.rhq.augeas.tree.AugeasTree;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.rhqtransform.AugeasToConfiguration;
+import org.rhq.rhqtransform.NameMap;
+/**
+ *
+ * @author Filip Drabek
+ * @author Ian Springer
+ */
+public class AugeasToConfigurationSimple implements AugeasToConfiguration {
+ private final Log log = LogFactory.getLog(this.getClass());
+ private AugeasTree tree;
+ private NameMap nameMap;
+
+ public AugeasToConfigurationSimple(){
+
+ }
+
+ public void setTree(AugeasTree tree)
+ {
+ this.tree = tree;
+ }
+
+ public void setNameMap(NameMap nameMap){
+ this.nameMap = nameMap;
+ }
+
+ public Configuration loadResourceConfiguration(AugeasNode
startNode,ConfigurationDefinition resourceConfigDef) throws Exception {
+
+ Configuration resourceConfig = new Configuration();
+
+ Collection<PropertyDefinition> propDefs =
resourceConfigDef.getPropertyDefinitions().values();
+
+ for (PropertyDefinition propDef : propDefs) {
+ resourceConfig.put(loadProperty(propDef,startNode));
+ }
+
+ return resourceConfig;
+ }
+
+ public Property loadProperty(PropertyDefinition propDef, AugeasNode
parentNode) throws Exception{
+
+ Property prop;
+ if (propDef instanceof PropertyDefinitionSimple) {
+ prop = createPropertySimple((PropertyDefinitionSimple) propDef,
parentNode);
+ } else if (propDef instanceof PropertyDefinitionMap) {
+ prop = createPropertyMap((PropertyDefinitionMap) propDef,
parentNode);
+ } else if (propDef instanceof PropertyDefinitionList) {
+ prop = createPropertyList((PropertyDefinitionList) propDef,
parentNode);
+ } else {
+ throw new IllegalStateException("Unsupported PropertyDefinition
subclass: " + propDef.getClass().getName());
+ }
+ return prop;
+ }
+
+ public Property createPropertySimple(PropertyDefinitionSimple propDefSimple,
AugeasNode node) throws Exception{
+ Object value;
+ value = node.getValue();
+ return new PropertySimple(propDefSimple.getName(), value);
+ }
+
+ public PropertyMap createPropertyMap(PropertyDefinitionMap propDefMap,
AugeasNode node) throws Exception {
+ PropertyMap propMap = new PropertyMap(propDefMap.getName());
+ for (PropertyDefinition mapEntryPropDef :
propDefMap.getPropertyDefinitions().values()) {
+ propMap.put(loadProperty(mapEntryPropDef, node));
+ }
+ return propMap;
+ }
+
+ public Property createPropertyList(PropertyDefinitionList propDefList,
AugeasNode node) throws Exception{
+
+ PropertyList propList = new PropertyList(propDefList.getName());
+
+ List<AugeasNode> nodes = tree.matchRelative(node,
propDefList.getName());
+ PropertyDefinition listMemberPropDef = propDefList.getMemberDefinition();
+
+ for (AugeasNode listMemberNode : nodes){
+ propList.add(loadProperty(listMemberPropDef,listMemberNode));
+ }
+
+ return propList;
+ }
+}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
new file mode 100644
index 0000000..2a23b33
--- /dev/null
+++
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
@@ -0,0 +1,197 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.rhqtransform.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.rhq.augeas.node.AugeasNode;
+import org.rhq.augeas.tree.AugeasTree;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.rhqtransform.ConfigurationToAugeas;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public class ConfigurationToAugeasSimple implements ConfigurationToAugeas{
+
+ private AugeasTree tree;
+
+ public ConfigurationToAugeasSimple(){
+
+ }
+
+ public void setTree(AugeasTree tree){
+ this.tree = tree;
+ }
+
+ public void updateResourceConfiguration(AugeasNode node,ConfigurationDefinition
resourceConfigDef,Configuration resourceConfig) throws Exception{
+
+ Collection<PropertyDefinition> propDefs =
resourceConfigDef.getPropertyDefinitions().values();
+ PropertyMap startProp = new PropertyMap();
+
+ for (Property property : resourceConfig.getProperties())
+ startProp.put(property);
+
+ for (PropertyDefinition propDef : propDefs) {
+ updateProperty(propDef, startProp, node,0);
+ }
+ }
+
+
+ public void updateMap(PropertyDefinitionMap propDefMap, Property prop,
+ AugeasNode mapNode,int seq) throws Exception{
+
+ PropertyMap map=null;
+
+ if (prop instanceof PropertyList){
+ PropertyList lst = (PropertyList) prop;
+ List<Property> props = lst.getList();
+ map = (PropertyMap) props.get(seq-1);
+ }
+
+ if (prop instanceof PropertyMap){
+ PropertyMap mp = (PropertyMap) prop;
+ map = (PropertyMap) mp.get(propDefMap.getName());
+ }
+
+ List<AugeasNode> nodes = tree.matchRelative(mapNode,
propDefMap.getName());
+
+ AugeasNode node;
+ int i=0;
+ if (nodes.isEmpty() | nodes.size()<seq)
+ {
+ node = tree.createNode(mapNode,propDefMap.getName(), null,
seq);
+ nodes.add(node);
+ i = ((seq == 0)? 0 : seq-1);
+ }else
+ if (seq==0){
+ node = nodes.get(0);
+ i=0;
+ }
+ else{
+ node = nodes.get(seq-1);
+ i=seq-1;
+ }
+
+ for (PropertyDefinition mapEntryPropDef :
propDefMap.getPropertyDefinitions().values()) {
+ updateProperty(mapEntryPropDef, map, nodes.get(i),0);
+ }
+
+ }
+
+
+
+ public void updateList(PropertyDefinitionList propDef, Property prop,
+ AugeasNode listNode,int seq) throws Exception{
+
+ PropertyList listProperty = null;
+ PropertyDefinition childDefinition = propDef.getMemberDefinition();
+
+ if (prop instanceof PropertyList){
+ PropertyList lst = (PropertyList) prop;
+ listProperty = (PropertyList) lst.getList().get(seq-1);
+ }
+
+ if (prop instanceof PropertyMap){
+ PropertyMap map = (PropertyMap) prop;
+ listProperty = (PropertyList) map.get(propDef.getName());
+ }
+
+ List<AugeasNode> nodes = tree.matchRelative(listNode,
propDef.getName());
+ AugeasNode node = null;
+
+ if (nodes.isEmpty() | nodes.size()<seq)
+ {
+ node =
tree.createNode(listNode,propDef.getName(), null, seq);
+ nodes.add(node);
+ }else
+ node = nodes.get(seq);
+
+ int i=1;
+ for (Property prp : listProperty.getList()){
+ System.out.println(prp.getName());
+ updateProperty(childDefinition, listProperty,
node,i);
+ i= i+1;
+ }
+ }
+
+ public void updateSimple(AugeasNode parentNode, PropertyDefinitionSimple
propDef,
+ Property prop,int seq) throws Exception{
+
+ PropertySimple simpleProp=null;
+ AugeasNode node = null;
+ if (prop instanceof PropertyList){
+ PropertyList lst = (PropertyList) prop;
+ List<Property> props = lst.getList();
+ simpleProp = (PropertySimple)props.get(seq-1);
+ }
+
+ if (prop instanceof PropertyMap){
+ PropertyMap map = (PropertyMap) prop;
+ simpleProp = (PropertySimple) map.get(propDef.getName());
+ }
+
+ List<AugeasNode> nodes = tree.matchRelative(parentNode,
propDef.getName());
+
+ if (nodes.isEmpty())
+ {
+ node = tree.createNode(parentNode,propDef.getName(),
null, 1);
+ }else
+ node = nodes.get(0);
+
+ node.setValue(simpleProp.getStringValue());
+
+ }
+
+
+ public void updateProperty(PropertyDefinition propDef, Property parentProp,
+ AugeasNode parentNode,int seq) throws Exception{
+
+ if (propDef instanceof PropertyDefinitionSimple) {
+ PropertyDefinitionSimple propDefSimple = (PropertyDefinitionSimple)
propDef;
+ updateSimple(parentNode, propDefSimple, parentProp,seq);
+ } else if (propDef instanceof PropertyDefinitionMap) {
+ PropertyDefinitionMap propDefMap = (PropertyDefinitionMap) propDef;
+ updateMap(propDefMap, parentProp, parentNode,seq);
+ } else if (propDef instanceof PropertyDefinitionList) {
+ PropertyDefinitionList propDefList = (PropertyDefinitionList) propDef;
+ updateList(propDefList, parentProp, parentNode,seq);
+ } else {
+ throw new IllegalStateException("Unsupported PropertyDefinition
subclass: "
+ + propDef.getClass().getName());
+ }
+
+ }
+}
diff --git
a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java
new file mode 100644
index 0000000..b88ffe2
--- /dev/null
+++
b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java
@@ -0,0 +1,76 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.rhqtransform.impl;
+
+import org.rhq.augeas.AugeasComponent;
+import org.rhq.augeas.node.AugeasNode;
+import org.rhq.augeas.tree.AugeasTree;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.rhqtransform.AugeasToConfiguration;
+import org.rhq.rhqtransform.ConfigurationToAugeas;
+import org.rhq.rhqtransform.RhqAugeasMapping;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public class RhqAugeasMappingSimple implements RhqAugeasMapping{
+
+ private AugeasToConfiguration augeasToConfiguration;
+ private ConfigurationToAugeas configurationToAugeas;
+ private String moduleName;
+
+
+ public RhqAugeasMappingSimple(String moduleName){
+ this.augeasToConfiguration = new AugeasToConfigurationSimple();
+ this.configurationToAugeas = new ConfigurationToAugeasSimple();
+ this.moduleName = moduleName;
+ }
+
+ public RhqAugeasMappingSimple(AugeasToConfiguration toConfig,ConfigurationToAugeas
toAugeas,String moduleName){
+ this.augeasToConfiguration = toConfig;
+ this.configurationToAugeas = toAugeas;
+ this.moduleName = moduleName;
+ }
+
+
+ public void updateAugeas(AugeasComponent component, Configuration config,
+ ConfigurationDefinition configDef) throws Exception{
+ AugeasTree tree = component.getAugeasTree(moduleName, true);
+ AugeasNode startNode = getStartNode(tree);
+ configurationToAugeas.updateResourceConfiguration(startNode, configDef,
config);
+ }
+
+ public Configuration updateConfiguration(AugeasComponent
augeasComponent,ConfigurationDefinition configDef) throws Exception{
+ AugeasTree tree = augeasComponent.getAugeasTree(moduleName, true);
+ AugeasNode startNode = getStartNode(tree);
+ return augeasToConfiguration.loadResourceConfiguration(startNode,
configDef);
+ }
+
+ protected AugeasNode getStartNode(AugeasTree tree) throws Exception{
+ return tree.getRootNode();
+ }
+
+}