Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r3924 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin

Subject: perfsonar development work

List archive

perfsonar: r3924 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r3924 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin
  • Date: Fri, 30 May 2008 10:30:12 -0400

Author: mac
Date: 2008-05-30 10:30:11 -0400 (Fri, 30 May 2008)
New Revision: 3924

Modified:

trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin/LSWizardHandler.java
Log:
Adding configuration options for LSRegistration and Authentication

Modified:
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin/LSWizardHandler.java
===================================================================
---
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin/LSWizardHandler.java
2008-05-30 14:29:09 UTC (rev 3923)
+++
trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin/LSWizardHandler.java
2008-05-30 14:30:11 UTC (rev 3924)
@@ -1,8 +1,12 @@
package org.perfsonar.service.lookupService.xmlType.webadmin;

+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.Hashtable;
@@ -27,568 +31,926 @@
*
* @author Michalis Michael
* @author Maciej Glowiak
- *
+ *
*/
public class LSWizardHandler implements ConfigurationHandler {

-
- //
-----------------------------------------------------------------------
- // class fields
+ //
-----------------------------------------------------------------------
+ // class fields

-
- // Hashtable containg Wizard Properties as values and the various
groups in
- // which the properties are divided to as keys
- private Hashtable<String, WizardProperties> groupedProperties = null;
+ // Hashtable containg Wizard Properties as values and the various groups
in
+ // which the properties are divided to as keys
+ private Hashtable<String, WizardProperties> groupedProperties = null;

- // All of the Wizard Properties
- private WizardProperties properties = null;
+ // All of the Wizard Properties
+ private WizardProperties properties = null;

- // The HtTMLOutput class that is used for outputting html code to
the user.
- // Currently not used by this reference implementation
- @SuppressWarnings("unused")
- private HTMLOutput htmlOutput;
+ // The HtTMLOutput class that is used for outputting html code to the
user.
+ // Currently not used by this reference implementation
+ @SuppressWarnings("unused")
+ private HTMLOutput htmlOutput;

- // The path to the configuration directory
- private static final String confPath =
"WEB-INF/classes/perfsonar/conf/";
+ // The path to the configuration directory
+ private static final String confPath = "WEB-INF/classes/perfsonar/conf/";

- // The path to the service.properties file
- private static final String ServicePropertiesPath = confPath
- + "service.properties";
+ // The path to the service.properties file
+ private static final String ServicePropertiesPath = confPath
+ + "service.properties";

- // The path to the logging properties file
- private static final String LoggingPropertiesPath = confPath
- + "log4j.properties";
+ // The path to the logging properties file
+ private static final String LoggingPropertiesPath = confPath
+ + "log4j.properties";

- // The path to the componenets.properties file
- @SuppressWarnings("unused")
- private static final String ComponentsPropertiesPath =
confPath
- + "components.properties";
+ // The path to the componenets.properties file
+ @SuppressWarnings("unused")
+ private static final String ComponentsPropertiesPath = confPath
+ + "components.properties";

- // The path to the objects properties file
- private static final String ObjectsConfigPath = confPath +
"objects.config";
+ // The path to the objects properties file
+ private static final String ObjectsConfigPath = confPath +
"objects.config";

- // The path to the wizard.properties file
- private static final String WizardPropertiesPath = confPath
- + "wizard.properties";
+ // The path to the wizard.properties file
+ private static final String WizardPropertiesPath = confPath
+ + "wizard.properties";

- // The path to the servlet.properties file
- private static final String ServletPropertiesPath = confPath
- + "servlet.properties";
+ // The path to the servlet.properties file
+ private static final String ServletPropertiesPath = confPath
+ + "servlet.properties";

- // The path to the directory under the webapps folder in which the
service
- // is installed
- private static String ServicePath;
+ // The path to the directory under the webapps folder in which the
service
+ // is installed
+ private static String ServicePath;

- // Bollean that states if the configuration process is finished
- private static boolean configured = false;
-
-
-
- //
-----------------------------------------------------------------------
- // constructors
+ // Bollean that states if the configuration process is finished
+ private static boolean configured = false;

- /**
- * Class constructor
- */
- public LSWizardHandler() {

- }
+ //
-----------------------------------------------------------------------
+ // constructors

-
-
- //
-----------------------------------------------------------------------
- // public methods
+ /**
+ * Class constructor
+ */
+ public LSWizardHandler() {

-
-
-
- /*
- * (non-Javadoc)
- *
- * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#handleRequest(javax.servlet.http.HttpServletRequest)
- */
- public boolean handleRequest(HttpServletRequest request) throws
Exception {
-
- // Setting configured to false
- configured = false;
- // Also definining some more booleans for every different group
to be
- // configured
- boolean eXistDone = false;
+ }

- // Each group is independent from each other and can be
configured
- // without any depemdencies
- try {
-
- // Handling exist configuration
- // True if this is done properly
- eXistDone = handleExist(request);
-
- } catch (Exception e) {

- throw new Exception(
- "Problem with eXist configuration!Please check your
input.\n"
- + getFault(e));
- }
-
- // if every group has configured successfully then the final
- // configuration procedures are called
- if (eXistDone) {
- try {
-
- configured = finishConfiguration();
-
- } catch (Exception e) {
- throw new Exception("Problem finishing configuration.\n"
+ //
-----------------------------------------------------------------------
+ // public methods
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#handleRequest(javax.servlet.http.HttpServletRequest)
+ */
+ public boolean handleRequest(HttpServletRequest request) throws
Exception {
+
+ // Setting configured to false
+ configured = false;
+ // Also definining some more booleans for every different group to be
+ // configured
+ boolean eXistDone = false;
+ boolean lsDone = false;
+ boolean otherDone = false;
+
+ // Each group is independent from each other and can be configured
+ // without any depemdencies
+ try {
+
+ // Handling exist configuration
+ // True if this is done properly
+ eXistDone = handleExist(request);
+
+ } catch (Exception e) {
+
+ throw new Exception(
+ "Problem with eXist configuration!Please check your
input.\n"
+ getFault(e));
- }
- }
-
- return configured;
+ }

+ try {
+
+ // Handling LS configuration
+ // True if all is done properly
+ lsDone = handleLS(request);
+
+ } catch (Exception e) {
+ throw new Exception(
+ "Problem with LS configuration!Please check your
input.\n"
+ + getFault(e));
}
+ try {

- /*
- * (non-Javadoc)
- *
- * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#isConfigured()
- */
- public boolean isConfigured() {
+ // Handling other groups configuration
+ // True if all is done properly
+ otherDone = handleOther(request);

+ } catch (Exception e) {
+
+ throw new Exception(
+ "Problem with Store configuration!Please check your
input.\n"
+ + getFault(e));
+ }
+
+ // if every group has configured successfully then the final
+ // configuration procedures are called
+ if (eXistDone && lsDone && otherDone) {
+ try {
+ configured = finishConfiguration();
+ // if everything has gone OK then true is returned
+ return configured;
+ } catch (Exception e) {
+ throw new Exception("Problem finishing configuration.\n"
+ + getFault(e));
+ }
+ } else {
return configured;
}

- /*
- * (non-Javadoc)
- *
- * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setHTMLOutput(perfSONARWebAdmin.auxiliary.wizard.HTMLOutput)
- */
- public void setHTMLOutput(HTMLOutput output) {
+ }

- htmlOutput = output;

- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#isConfigured()
+ */
+ public boolean isConfigured() {

- /*
- * (non-Javadoc)
- *
- * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setProperties(perfSONARWebAdmin.auxiliary.wizard.WizardProperties)
- */
- public void setProperties(WizardProperties loadedProperties) {
+ return configured;
+ }

- properties = loadedProperties;
- }

- /*
- * (non-Javadoc)
- *
- * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setGroupedProperties(java.util.Hashtable)
- */
- public void setGroupedProperties(
- Hashtable<String, WizardProperties> otherProperties) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setHTMLOutput(perfSONARWebAdmin.auxiliary.wizard.HTMLOutput)
+ */
+ public void setHTMLOutput(HTMLOutput output) {

- groupedProperties = otherProperties;
+ htmlOutput = output;

- }
+ }

- /*
- * (non-Javadoc)
- *
- * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setServicePath(java.lang.String)
- */
- public void setServicePath(String servicePath) {

- ServicePath = servicePath;
+ /*
+ * (non-Javadoc)
+ *
+ * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setProperties(perfSONARWebAdmin.auxiliary.wizard.WizardProperties)
+ */
+ public void setProperties(WizardProperties loadedProperties) {

- }
+ properties = loadedProperties;
+ }

-
-
-
- //
-----------------------------------------------------------------------
- // private methods

-
-
+ /*
+ * (non-Javadoc)
+ *
+ * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setGroupedProperties(java.util.Hashtable)
+ */
+ public void setGroupedProperties(
+ Hashtable<String, WizardProperties> otherProperties) {

- /**
- * Method used for handling eXist database configuration
- *
- * @param request
- * The HttpServletRequest containing input from the user
- * @return True if LS registration is configured successfully
- * @throws Exception
- */
- private boolean handleExist(HttpServletRequest request) throws
Exception {
-
- boolean done = false;
-
- // Getting the exist database associated properties
- WizardProperties existProperties =
groupedProperties.get("eXist");
-
- Iterator it = existProperties.orderedKeys();
-
- // The first key is about using or not the database.So this
parameter is
- // retrieved from the request
- String statusKey = (String) it.next();
- String status = request.getParameter(statusKey);
- WizardProperty useExistProperty = existProperties
- .getWizardProperty(statusKey);
+ groupedProperties = otherProperties;

- if (status.equals("off")) {
- // if the user does not wish to use exist then the property
is set
- // to off
- // and nothing else happens
+ }

- // Seeting property value
- useExistProperty.setPropertyValue("off");
- // Setting property to exist group properties
- existProperties.setWizardProperty(statusKey,
useExistProperty);
- // Set property to wizard properties
- properties.setWizardProperty(statusKey, useExistProperty);
- // Update exist group properties
- groupedProperties.put("eXist", existProperties);
- try {
- // Using the serviceProperties class for setting the
property
-
- //Changing to PerfsonarProperties to maintain
grouping and description
- PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
-
- //Loading properties from service.properties file
- serviceProperties.loadProperties(new
FileInputStream(ServicePath
- + ServicePropertiesPath));
-
- String key = useExistProperty.getKey();
- // Retrieve the PerfsonarProperty from service.properties
- PerfsonarProperty property =
serviceProperties.getProperty(key);
- // If key property does not exist the throw
an exception
- if (property == null) {
- throw new IOException("Key is invalid
" + statusKey + " ");
- } else {
- // Change the value of the property
-
property.setValue(useExistProperty.getValue());
- serviceProperties.setProperty(key,
property);
- }
- // new Properties stored
- serviceProperties.storeProperties(new
FileOutputStream(ServicePath
- + ServicePropertiesPath));
- // Set done to true
- done = true;
-
- } catch (IOException e) {

- // If anything happens set done to false
- done = false;
- throw new Exception(getFault(e));
+ /*
+ * (non-Javadoc)
+ *
+ * @see
perfSONARWebAdmin.auxiliary.wizard.ConfigurationHandler#setServicePath(java.lang.String)
+ */
+ public void setServicePath(String servicePath) {

- }
+ ServicePath = servicePath;

+ }

-
- return done;
-
-
- } else {
-
-
- // If the user wishes to use exist then set the property
value
- useExistProperty.setPropertyValue("on");
- // Set the wizard property to the exist group properties
- existProperties.setWizardProperty(statusKey,
useExistProperty);
- // Get all other parameters regarding exist in the users
reqauest
+
+ //
-----------------------------------------------------------------------
+ // private methods
+
+ /**
+ * Method used for handling other groups configuration(That is other
than LS
+ * and exist)
+ *
+ * @param request
+ * The HttpServletRequest containing input from the user
+ * @return True if other groups are configured successfully
+ * @throws Exception
+ */
+ private boolean handleOther(HttpServletRequest request) throws Exception
{
+
+ // Getting all groups
+ Iterator groupIt = groupedProperties.keySet().iterator();
+ // Setting done to true, You will see later why
+ boolean done = true;
+ // Iterating through the groups
+ while (groupIt.hasNext()) {
+ String group = (String) groupIt.next();
+ // Every other group should be handled except for eXist and LS
+ if (!(group.equals("eXist") || group.equals("LS"))) {
+
+ // Retrieving the properties belonging to the group
+ WizardProperties groupProperties =
groupedProperties.get(group);
+ // Iterating through the properties. This way using the key
of
+ // each property we can retrieve the users input from the
+ // request
+ Iterator it = groupProperties.orderedKeys();
while (it.hasNext()) {
String key = (String) it.next();
- // Get the parameter
+ // get the value from the request
String value = request.getParameter(key).trim();
- // Get the property
- WizardProperty pr =
existProperties.getWizardProperty(key);
- // Set value and proposed value
+ WizardProperty pr =
groupProperties.getWizardProperty(key);
+ // Set the property value
pr.setPropertyValue(value);
- pr.setProposedValue(value);
- // Set the property in the exist group properties
- existProperties.setWizardProperty(key, pr);
+ // if the property does not the check field set, the also
+ // put the user input as the proposed value also
+ // This happens, because properties that have the check
+ // property set, are usually important for the rest of
the
+ // group properties since their value would determine if
the
+ // rest need to be configured. So their proposed value is
+ // left to thr developer
+ if (!pr.getCheck()) {
+ pr.setProposedValue(value);
+ }
+ // Updating the property inside the group propereties
+ groupProperties.setWizardProperty(key, pr);
}
- // Update the exist group Property
- groupedProperties.put("eXist", existProperties);
+ // Updating the grouped properties
+ groupedProperties.put(group, groupProperties);
+ // Applying the configuration input from the user to the
service
try {
- // Call for the needed actions for exist
configuration.The exist
- // group properties are used as input
- existActions(existProperties);
- done = true;
+ otherActions(group, groupProperties);
} catch (Exception e) {
- // Set doen to false if anything happens
+ // If actions had a problem then done is set to false
done = false;
throw new Exception(getFault(e));
}
- return done;
}
+ }

+ return done;
+ }
+
+
+ /**
+ * Method used for handling LS registration configuration
+ *
+ * @param request
+ * The HttpServletRequest containing input from the user
+ * @return True if LS registration is configured successfully
+ * @throws Exception
+ */
+ private boolean handleLS(HttpServletRequest request) throws Exception {
+
+ // Retrieving the useLS parameter. The useLS parammeter is inserted
as
+ // input by the shoaAllProperties method of the HTMLOutput class
+ // automatically. It is the answer to if the user wants to register
to
+ // an LS since their is no service property that corresponds to this
+ // question
+ String useLS = request.getParameter("useLS").trim();
+ // If yes all other properties regarding LS registration are
retrieved
+ if (useLS.equals("yes")) {
+ // Retrieving all propertie associated with LS
+ WizardProperties lsProperties = groupedProperties.get("LS");
+ // Getting the keys of the properties
+ Iterator it = lsProperties.orderedKeys();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ // Using the keys for retrieving the users input
+ String value = request.getParameter(key).trim();
+ WizardProperty pr = lsProperties.getWizardProperty(key);
+ // Setting property value and proposed value
+ pr.setPropertyValue(value);
+ pr.setProposedValue(value);
+ // Setting property
+ lsProperties.setWizardProperty(key, pr);
+ }
+ // Setting the LS group properties
+ groupedProperties.put("LS", lsProperties);
+ boolean done = false;
+ // Trying to perfom the LS configuration actions to the service
+ try {
+ lsActions(lsProperties);
+ done = true;
+ } catch (Exception e) {
+ // False if an error happens
+ done = false;
+ throw new Exception(getFault(e));
+ }
+
+ return done;
}
+ // If no then the registration componenets are commented in the
+ // components.properties file
+ else {
+ removeRegistrationComponents();
+ return true;
+ }
+ }

-

- /**
- * Method used for handling all actions associated with exist db
- * confoguration
- *
- * @param finalProperties
- * The Wizard Properties associated with the exist group
- * @throws Exception
- */
- private void existActions(WizardProperties finalProperties)
- throws Exception {
+ /**
+ * Method used for handling eXist database configuration
+ *
+ * @param request
+ * The HttpServletRequest containing input from the user
+ * @return True if LS registration is configured successfully
+ * @throws Exception
+ */
+ private boolean handleExist(HttpServletRequest request) throws Exception
{

- // Initiating ServiceProperties classes for handling input to the
- // service.properties and servlet.properties file
+ boolean done = false;

-
- //Change from ServicePropereties to PerfsonarProperties
- //This is necessay to keep grouping and description for
properties
- PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
- serviceProperties.loadProperties(new
FileInputStream(ServicePath
- + ServicePropertiesPath));
+ // Getting the exist database associated properties
+ WizardProperties existProperties = groupedProperties.get("eXist");

- // Any changes happening to the URL of the exist db and on the
admin
- // password should be reflected on the servlet.properties as well
-
- //The change to PerfsonarProperties in to necessary for
servlet.properties because
- //no grouping or description is needed there
- ServiceProperties servletProperties = new ServicePropertiesImpl(
- ServicePath + ServletPropertiesPath);
-
- // Get an iterator for all service properties
- Iterator it = serviceProperties.getKeysIterator();
-
- // Get the type of the service. Will be used for making the new
db
- // collection
- @SuppressWarnings("unused")
- String serviceName = servletProperties.getProperty(
- "servlet.service_type").trim();
-
- // Naming the new collection on exist db
- //String dbCollection = serviceName + "config";
- // Initializing all necessary fileds
- String adminPass = null;
- String existURI = "";
- String newAdminPass = null;
- String username = null;
- String password = null;
- // Need to get the new xmlDBURI and old and new admin password
so that
- // we can make the changes
-
- while (it.hasNext()) {
-
- String key = (String) it.next();
-
- if (key.endsWith(".db_adminpassword")) {
- adminPass =
serviceProperties.getProperty(key).getValue()
- .trim();
- newAdminPass = finalProperties.getProperty(key).trim();
+ Iterator it = existProperties.orderedKeys();
+
+ // The first key is about using or not the database.So this
parameter is
+ // retrieved from the request
+ String statusKey = (String) it.next();
+ String status = request.getParameter(statusKey);
+ WizardProperty useExistProperty = existProperties
+ .getWizardProperty(statusKey);
+
+ if (status.equals("off")) {
+ // if the user does not wish to use exist then the property is
set
+ // to off
+ // and nothing else happens
+
+ // Seeting property value
+ useExistProperty.setPropertyValue("off");
+ // Setting property to exist group properties
+ existProperties.setWizardProperty(statusKey, useExistProperty);
+ // Set property to wizard properties
+ properties.setWizardProperty(statusKey, useExistProperty);
+ // Update exist group properties
+ groupedProperties.put("eXist", existProperties);
+ try {
+ // Using the serviceProperties class for setting the property
+
+ // Changing to PerfsonarProperties to maintain grouping and
+ // description
+ PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
+
+ // Loading properties from service.properties file
+ serviceProperties.loadProperties(new FileInputStream(
+ ServicePath + ServicePropertiesPath));
+
+ String key = useExistProperty.getKey();
+ // Retrieve the PerfsonarProperty from service.properties
+ PerfsonarProperty property =
serviceProperties.getProperty(key);
+ // If key property does not exist the throw an exception
+ if (property == null) {
+ throw new IOException("Key is invalid " + statusKey + "
");
+ } else {
+ // Change the value of the property
+ property.setValue(useExistProperty.getValue());
+ serviceProperties.setProperty(key, property);
}
- if (key.endsWith(".db_uri")) {
- existURI = finalProperties.getProperty(key);
- }
+ // new Properties stored
+ serviceProperties.storeProperties(new FileOutputStream(
+ ServicePath + ServicePropertiesPath));
+ // Set done to true
+ done = true;

+ } catch (IOException e) {
+
+ // If anything happens set done to false
+ done = false;
+ throw new Exception(getFault(e));
+
}
- // If admin pass is not set than its considered to be empty
- if (adminPass == null) {
- adminPass = "";
+
+ return done;
+
+ } else {
+
+ // If the user wishes to use exist then set the property value
+ useExistProperty.setPropertyValue("on");
+ // Set the wizard property to the exist group properties
+ existProperties.setWizardProperty(statusKey, useExistProperty);
+ // Get all other parameters regarding exist in the users reqauest
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ // Get the parameter
+ String value = request.getParameter(key).trim();
+ // Get the property
+ WizardProperty pr = existProperties.getWizardProperty(key);
+ // Set value and proposed value
+ pr.setPropertyValue(value);
+ pr.setProposedValue(value);
+ // Set the property in the exist group properties
+ existProperties.setWizardProperty(key, pr);
}
+ // Update the exist group Property
+ groupedProperties.put("eXist", existProperties);
+ try {
+ // Call for the needed actions for exist configuration.The
exist
+ // group properties are used as input
+ existActions(existProperties);
+ done = true;
+ } catch (Exception e) {
+ // Set doen to false if anything happens
+ done = false;
+ throw new Exception(getFault(e));
+ }
+ return done;
+ }

- it = finalProperties.orderedKeys();
- // Iterating though tthe users input
+ }
+
+
+ /**
+ * Method for handling all configuration actions regarding the LS
+ * registration
+ *
+ * @param finalProperties
+ * The WizardProperties that belong to the LS registration
group
+ * @throws IOException
+ */
+ private void lsActions(WizardProperties finalProperties) throws
IOException {
+
+ // Changes happen into the service.property file that uses groupig
and
+ // description
+ // In order to keep that functionality we need in this case to use
the
+ // PerfsonarProperties class
+ PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
+ serviceProperties.loadProperties(new FileInputStream(ServicePath
+ + ServicePropertiesPath));
+ Iterator it = finalProperties.orderedKeys();
+ // Iterating through the LS registration properties properties
+
+ // Initializing the PerfsonarProperty object that holds information
+ // about grouping and description
+ PerfsonarProperty property = new PerfsonarProperty();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ // Set the service properties
+
+ // Get the PerfsonarProperty object
+ property = serviceProperties.getProperty(key);
+
+ // If property key does not exist throw an exceptrion
+ if (property == null) {
+ throw new IOException("Key is invalid " + key + " ");
+ } else {
+ // Else set the value right
+ property.setValue(finalProperties.getProperty(key));
+ serviceProperties.setProperty(key, property);
+ }
+ // Set the wizard properties
+ properties.setWizardProperty(key, finalProperties
+ .getWizardProperty(key));
+ }
+ // Storing service properties
+ serviceProperties.storeProperties(new FileOutputStream(ServicePath
+ + ServicePropertiesPath));
+ // Setting the LS registration componenets in components properties
file
+ addRegistrationComponents();
+ // Storing the wizard properties
+ properties.storeToXML(new FileOutputStream(new File(ServicePath
+ + WizardPropertiesPath)), " Last Modification "
+ + Calendar.getInstance().getTime().toString());
+ }
+
+
+ /**
+ * Method for handling all configuration actions regarding any other
group
+ * besides LS and eXist
+ *
+ * @param group
+ * The group
+ * @param functionProperties
+ * The properties regardung the group
+ * @throws IOException
+ */
+ private void otherActions(String group, WizardProperties
functionProperties)
+ throws IOException {
+
+ // The only other group for rrd ma is the Store group
+ // So in this case changes go into the service.property file that
uses
+ // groupig and description
+ // In order to keep that functionality we need in this case to use
the
+ // PerfsonarProperties class
+ if (!group.equals("Administration")) {
+
+ // Using PerfsonarProperties in order to keep the grouping and
+ // description
+ PerfsonarProperties serviceProperties = null;
+ serviceProperties = new PerfsonarPropertiesImpl();
+ serviceProperties.loadProperties(new FileInputStream(ServicePath
+ + ServicePropertiesPath));
+ // Getting the names for every property of the group
+ Iterator it = functionProperties.orderedKeys();
+ // Setting the value of each property
+
+ // An object that holds the property group,description,value and
key
+ PerfsonarProperty property = new PerfsonarProperty();
while (it.hasNext()) {
String key = (String) it.next();
- // The input from the user is also set in service properties
with a
- // slight modification for tyhe xmldb uri. We need to add the
- // collection at the end of the URI
- PerfsonarProperty property = new PerfsonarProperty();
+ // Setting service properties and wizard properties
+
+ // Get the property
property = serviceProperties.getProperty(key);
- property.setValue(finalProperties.getProperty(key));
- serviceProperties.setProperty(key,property);
+ // If key property does not exist the throw an exception
+ if (property == null) {
+ throw new IOException("Key is invalid " + key + " ");
+ } else {
+ // Change the value of the property
+ if (functionProperties.getProperty(key).equals("yes"))
+ property.setValue("on");
+ else if
(functionProperties.getProperty(key).equals("no"))
+ property.setValue("off");
+ else
+
property.setValue(functionProperties.getProperty(key));

- if (key.endsWith(".db_uri")) {
- property = new PerfsonarProperty();
- property = serviceProperties.getProperty(key);
- property.setValue(existURI);
- serviceProperties.setProperty(key,property);
-
- property =
serviceProperties.getProperty(key+".xmlrpc");
- property.setValue(getXMLDBUri(existURI));
- serviceProperties.setProperty(key+".xmlrpc",property);
-
- property = serviceProperties.getProperty(key+".http");
- property.setValue(getHTTPUri(existURI));
- serviceProperties.setProperty(key+".http",property);
-
+ serviceProperties.setProperty(key, property);
}
-
- // Setting also the wizard properties
- properties.setWizardProperty(key, finalProperties
+ properties.setWizardProperty(key, functionProperties
.getWizardProperty(key));
-
- // Also getting all needed information in orer to configure
the
- // exist db
- if (key.endsWith(".db_username")) {
- username = finalProperties.getProperty(key);
+ }
+ // Storing all changes
+ serviceProperties.storeProperties(new
FileOutputStream(ServicePath
+ + ServicePropertiesPath));
+ }
+ // We don't really have any other groups just the ones for the
servlet
+ // administration, that does not use grouping and description so we
can
+ // use
+ // the ServiceProperties class as usual
+ else {
+ // A class that makes modifying service properties a little bit
+ // easier
+ ServiceProperties serviceProperties = new ServicePropertiesImpl(
+ ServicePath + ServletPropertiesPath);
+ // Getting the names for every property of the group
+ Iterator it = functionProperties.orderedKeys();
+ // Setting the value of each property
+ String value = null;
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ // Setting service properties and wizard properties
+ value = functionProperties.getProperty(key);
+ if (value == null) {
+ throw new IOException("Key is invalid " + key + " ");
+ } else {
+ serviceProperties.setProperty(key, value);
}
- if (key.endsWith(".db_password")) {
- password = finalProperties.getProperty(key);
- }
-
- //mac
- serviceProperties.storeProperties(new
FileOutputStream(ServicePath
- + ServicePropertiesPath));
-
+ properties.setWizardProperty(key, functionProperties
+ .getWizardProperty(key));
}
+ serviceProperties.storeProperties();

- log("results: ");
- log(" username="+username);
- log(" password="+password);
- log(" adminPass="+adminPass);
- log(" newAdminPass="+newAdminPass);
- log(" existURI="+existURI);
-
- //if not to initialize db, don't do it!
- String initDb = finalProperties.getProperty("initialize.db");
- if ("yes".equals(initDb)) {
- log(" initdb=yes");
-
- //System.out.println("[ ] Initialize DB "+existURI+",
"+adminPass);
-
- // Creating all necessary collections and users in exist
- if (existURI == null) {
- throw new Exception("eXist xmldb URI is empty!\n");
- } else {
- //xmldb:exist://localhost:8080/exist/xmlrpc/db/ls
- //http://localhost:8080/exist/rest/db/ls
- String uri = getXMLDBUri(existURI);
- log(" uri1="+uri);
+ }
+ properties.storeToXML(new FileOutputStream(new File(ServicePath
+ + WizardPropertiesPath)), " Last Modification "
+ + Calendar.getInstance().getTime().toString());
+ }

- //remove /db/anything
- String dbCollection="";
- int a = uri.indexOf("/db/");
- if (a>-1) {
- dbCollection=uri.substring(a+4);
- //dbCollection=uri.substring(a);
- try {
- uri = uri.substring(0,a); //try to get
collection after /db/
- //catch errors (IndexOutOfBounds)
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- log(" uri2="+uri);

- xmlDBManager manager = new xmlDBManagerImpl(uri, "admin",
- adminPass);
+ /**
+ * Method used for handling all actions associated with exist db
+ * confoguration
+ *
+ * @param finalProperties
+ * The Wizard Properties associated with the exist group
+ * @throws Exception
+ */
+ private void existActions(WizardProperties finalProperties)
+ throws Exception {

- // Creating collection and users
- manager.createCollection(dbCollection);
- manager.createUser(dbCollection, username, password,
null);
+ // Initiating ServiceProperties classes for handling input to the
+ // service.properties and servlet.properties file

- // Adding documents
- File file;
-
- file = new
File(this.getClass().getResource("/perfsonar/conf/LSStore.xml").toURI());
-
- manager.getCollection(dbCollection).addDocument(file,
username);
- file = new
File(this.getClass().getResource("/perfsonar/conf/LSStore-control.xml").toURI());
- manager.getCollection(dbCollection).addDocument(file,
username);
+ // Change from ServicePropereties to PerfsonarProperties
+ // This is necessay to keep grouping and description for properties
+ PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
+ serviceProperties.loadProperties(new FileInputStream(ServicePath
+ + ServicePropertiesPath));

- }
- //Modifying the admin user password
- //manager.modifyUser("admin", newAdminPass, null, null);
-
- //mac - moved here, check it!!
- serviceProperties.storeProperties(new
FileOutputStream(ServicePath
- + ServicePropertiesPath));
+ // Any changes happening to the URL of the exist db and on the admin
+ // password should be reflected on the servlet.properties as well

-
+ // The change to PerfsonarProperties in to necessary for
+ // servlet.properties because
+ // no grouping or description is needed there
+ ServiceProperties servletProperties = new ServicePropertiesImpl(
+ ServicePath + ServletPropertiesPath);
+
+ // Get an iterator for all service properties
+ Iterator it = serviceProperties.getKeysIterator();
+
+ // Get the type of the service. Will be used for making the new db
+ // collection
+ @SuppressWarnings("unused")
+ String serviceName = servletProperties.getProperty(
+ "servlet.service_type").trim();
+
+ // Naming the new collection on exist db
+ // String dbCollection = serviceName + "config";
+ // Initializing all necessary fileds
+ String adminPass = null;
+ String existURI = "";
+ String newAdminPass = null;
+ String username = null;
+ String password = null;
+ // Need to get the new xmlDBURI and old and new admin password so
that
+ // we can make the changes
+
+ while (it.hasNext()) {
+
+ String key = (String) it.next();
+
+ if (key.endsWith(".db_adminpassword")) {
+ adminPass = serviceProperties.getProperty(key).getValue()
+ .trim();
+ newAdminPass = finalProperties.getProperty(key).trim();
}
-
- properties.storeToXML(new FileOutputStream(new File(ServicePath
- + WizardPropertiesPath)), " Last Modification "
- + Calendar.getInstance().getTime().toString());

-
+ if (key.endsWith(".db_uri")) {
+ existURI = finalProperties.getProperty(key);
+ }
+
}
+ // If admin pass is not set than its considered to be empty
+ if (adminPass == null) {
+ adminPass = "";
+ }

+ it = finalProperties.orderedKeys();
+ // Iterating though tthe users input
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ // The input from the user is also set in service properties
with a
+ // slight modification for tyhe xmldb uri. We need to add the
+ // collection at the end of the URI
+ PerfsonarProperty property = new PerfsonarProperty();
+ property = serviceProperties.getProperty(key);
+ property.setValue(finalProperties.getProperty(key));
+ serviceProperties.setProperty(key, property);

- /**
- * Method for performing final actions for service configuration
- *
- * @return
- * @throws Exception
- */
- public boolean finishConfiguration() throws Exception {
-
- PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
- serviceProperties.loadProperties(new
FileInputStream(ServicePath
- + ServicePropertiesPath));
- PerfsonarProperty property = new PerfsonarProperty();
- property.setKey("service.sax_parser.config");
- property.setValue(ServicePath + ObjectsConfigPath);
- property.setGroup("Internals");
- property.setDescription("Sax parser configuration parameter");
- serviceProperties.setProperty(property.getKey(), property);
- property = new PerfsonarProperty();
- property.setKey("service.log.log4j.config");
- property.setValue(ServicePath + LoggingPropertiesPath);
- property.setGroup("Internals");
- property.setDescription("Logging Properties path");
- serviceProperties.setProperty(property.getKey(), property);
- serviceProperties.storeProperties(new
FileOutputStream(ServicePath
- + ServicePropertiesPath));
+ if (key.endsWith(".db_uri")) {
+ property = new PerfsonarProperty();
+ property = serviceProperties.getProperty(key);
+ property.setValue(existURI);
+ serviceProperties.setProperty(key, property);

- return true;
+ property = serviceProperties.getProperty(key + ".xmlrpc");
+ property.setValue(getXMLDBUri(existURI));
+ serviceProperties.setProperty(key + ".xmlrpc", property);

+ property = serviceProperties.getProperty(key + ".http");
+ property.setValue(getHTTPUri(existURI));
+ serviceProperties.setProperty(key + ".http", property);
+
+ }
+
+ // Setting also the wizard properties
+ properties.setWizardProperty(key, finalProperties
+ .getWizardProperty(key));
+
+ // Also getting all needed information in orer to configure the
+ // exist db
+ if (key.endsWith(".db_username")) {
+ username = finalProperties.getProperty(key);
+ }
+ if (key.endsWith(".db_password")) {
+ password = finalProperties.getProperty(key);
+ }
+
+ // mac
+ serviceProperties.storeProperties(new
FileOutputStream(ServicePath
+ + ServicePropertiesPath));
+
}

- /**
- * Method to get the stack trace of an exception
- *
- * @param e
- * The exception
- * @return A string with stack the trace
- */
- private String getFault(Exception e) {
- StackTraceElement[] trace = e.getStackTrace();
- String fault = e.getMessage();
- for (int j = 0; j < trace.length; j++) {
- fault += trace[j].toString() + "\n";
+ log("results: ");
+ log(" username=" + username);
+ log(" password=" + password);
+ log(" adminPass=" + adminPass);
+ log(" newAdminPass=" + newAdminPass);
+ log(" existURI=" + existURI);
+
+ // if not to initialize db, don't do it!
+ String initDb = finalProperties.getProperty("initialize.db");
+ if ("yes".equals(initDb)) {
+ log(" initdb=yes");
+
+ // System.out.println("[ ] Initialize DB "+existURI+",
"+adminPass);
+
+ // Creating all necessary collections and users in exist
+ if (existURI == null) {
+ throw new Exception("eXist xmldb URI is empty!\n");
+ } else {
+ // xmldb:exist://localhost:8080/exist/xmlrpc/db/ls
+ // http://localhost:8080/exist/rest/db/ls
+ String uri = getXMLDBUri(existURI);
+ log(" uri1=" + uri);
+
+ // remove /db/anything
+ String dbCollection = "";
+ int a = uri.indexOf("/db/");
+ if (a > -1) {
+ dbCollection = uri.substring(a + 4);
+ // dbCollection=uri.substring(a);
+ try {
+ uri = uri.substring(0, a); // try to get collection
+ // after /db/
+ // catch errors (IndexOutOfBounds)
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ log(" uri2=" + uri);
+
+ xmlDBManager manager = new xmlDBManagerImpl(uri, "admin",
+ adminPass);
+
+ // Creating collection and users
+ manager.createCollection(dbCollection);
+ manager.createUser(dbCollection, username, password, null);
+
+ // Adding documents
+ File file;
+
+ file = new File(this.getClass().getResource(
+ "/perfsonar/conf/LSStore.xml").toURI());
+
+ manager.getCollection(dbCollection).addDocument(file,
username);
+ file = new File(this.getClass().getResource(
+ "/perfsonar/conf/LSStore-control.xml").toURI());
+ manager.getCollection(dbCollection).addDocument(file,
username);
+
}
- return fault;
+ // Modifying the admin user password
+ // manager.modifyUser("admin", newAdminPass, null, null);
+
+ // mac - moved here, check it!!
+ serviceProperties.storeProperties(new
FileOutputStream(ServicePath
+ + ServicePropertiesPath));
+
}

-
- /**
- * Translate to XML RPC uri if necessary
- */
- private String getXMLDBUri(String uri) {
-
- if (uri.startsWith("http://";)) {
- uri = uri.replace("http://";, "xmldb:exist://");
- uri = uri.replace("/exist/rest/", "/exist/xmlrpc/");
+ properties.storeToXML(new FileOutputStream(new File(ServicePath
+ + WizardPropertiesPath)), " Last Modification "
+ + Calendar.getInstance().getTime().toString());
+
+ }
+
+
+ /**
+ * Method used for adding registration componenets to the
+ * componenets.properties file
+ *
+ * @throws IOException
+ */
+ private void addRegistrationComponents() throws IOException {
+
+ log("addRegistrationComponents");
+ File comp = new File(ServicePath + ComponentsPropertiesPath);
+ FileReader fr = new FileReader(comp);
+ StringBuffer contents = new StringBuffer();
+ BufferedReader br = new BufferedReader(fr);
+ String line = "";
+ while (line != null) {
+ // if (line.startsWith("#ls_scheduler")) {
+ // line = line.substring(1);
+ // }
+ if (line.startsWith("#registrator")) {
+ line = line.substring(1);
}
- return uri;
-
+ contents.append(line + "\n");
+ line = br.readLine();
}
-
-
- /**
- * Translate to HTTP uri if necessary
- */
- private String getHTTPUri(String uri) {
-
- if (uri.startsWith("xmldb:exist://")) {
- uri = uri.replace("xmldb:exist://", "http://";);
- uri = uri.replace("/exist/xmlrpc/", "/exist/rest/");
+
+ FileWriter fw = new FileWriter(comp);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write(contents.toString().trim());
+ bw.close();
+ fw.close();
+ br.close();
+ fr.close();
+ }
+
+
+ /**
+ * Method for removing ls registration components from
components.properties
+ * file
+ *
+ * @throws IOException
+ */
+ private void removeRegistrationComponents() throws IOException {
+
+ log("removeRegistrationComponents");
+ File comp = new File(ServicePath + ComponentsPropertiesPath);
+ FileReader fr = new FileReader(comp);
+ StringBuffer contents = new StringBuffer();
+ BufferedReader br = new BufferedReader(fr);
+ String line = "";
+ while (line != null) {
+ // if (line.startsWith("ls_scheduler")) {
+ // line = "#" + line;
+ // }
+ if (line.startsWith("registrator")) {
+ line = "#" + line;
}
- return uri;
+ contents.append(line + "\n");
+ line = br.readLine();
}
-
-
- private void log(String s) {
- //System.out.println("[LS Wizard] "+s);
+
+ FileWriter fw = new FileWriter(comp);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write(contents.toString().trim());
+ bw.close();
+ fw.close();
+ br.close();
+ fr.close();
+ }
+
+
+ /**
+ * Method for performing final actions for service configuration
+ *
+ * @return
+ * @throws Exception
+ */
+ public boolean finishConfiguration() throws Exception {
+
+ PerfsonarProperties serviceProperties = new
PerfsonarPropertiesImpl();
+ serviceProperties.loadProperties(new FileInputStream(ServicePath
+ + ServicePropertiesPath));
+ PerfsonarProperty property = new PerfsonarProperty();
+ property.setKey("service.sax_parser.config");
+ property.setValue(ServicePath + ObjectsConfigPath);
+ property.setGroup("Internals");
+ property.setDescription("Sax parser configuration parameter");
+ serviceProperties.setProperty(property.getKey(), property);
+ property = new PerfsonarProperty();
+ property.setKey("service.log.log4j.config");
+ property.setValue(ServicePath + LoggingPropertiesPath);
+ property.setGroup("Internals");
+ property.setDescription("Logging Properties path");
+ serviceProperties.setProperty(property.getKey(), property);
+ serviceProperties.storeProperties(new FileOutputStream(ServicePath
+ + ServicePropertiesPath));
+
+ return true;
+
+ }
+
+
+ /**
+ * Method to get the stack trace of an exception
+ *
+ * @param e
+ * The exception
+ * @return A string with stack the trace
+ */
+ private String getFault(Exception e) {
+
+ StackTraceElement[] trace = e.getStackTrace();
+ String fault = e.getMessage();
+ for (int j = 0; j < trace.length; j++) {
+ fault += trace[j].toString() + "\n";
}
-
-} //LSWizardHandler
+ return fault;
+ }
+
+
+ /**
+ * Translate to XML RPC uri if necessary
+ */
+ private String getXMLDBUri(String uri) {
+
+ if (uri.startsWith("http://";)) {
+ uri = uri.replace("http://";, "xmldb:exist://");
+ uri = uri.replace("/exist/rest/", "/exist/xmlrpc/");
+ }
+ return uri;
+
+ }
+
+
+ /**
+ * Translate to HTTP uri if necessary
+ */
+ private String getHTTPUri(String uri) {
+
+ if (uri.startsWith("xmldb:exist://")) {
+ uri = uri.replace("xmldb:exist://", "http://";);
+ uri = uri.replace("/exist/xmlrpc/", "/exist/rest/");
+ }
+ return uri;
+ }
+
+
+ private void log(String s) {
+
+ System.out.println("[LS Wizard] " + s);
+ }
+
+} // LSWizardHandler



  • perfsonar: r3924 - trunk/geant2_java-xml-ls/src/main/java/org/perfsonar/service/lookupService/xmlType/webadmin, svnlog, 05/30/2008

Archive powered by MHonArc 2.6.16.

Top of Page