perfsonar-dev - perfsonar: r5317 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: authn/component/wssec configuration scheduler storage/xml
Subject: perfsonar development work
List archive
perfsonar: r5317 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: authn/component/wssec configuration scheduler storage/xml
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5317 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: authn/component/wssec configuration scheduler storage/xml
- Date: Wed, 21 Oct 2009 08:52:59 -0400
Author: trzaszcz
Date: 2009-10-21 08:52:59 -0400 (Wed, 21 Oct 2009)
New Revision: 5317
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/authn/component/wssec/WSSecAuthNComponent.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/Component.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/storage/xml/XMLDBComponent.java
Log:
ConfigurarionManager rectorization - support for unit testing
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/authn/component/wssec/WSSecAuthNComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/authn/component/wssec/WSSecAuthNComponent.java
2009-10-20 20:41:35 UTC (rev 5316)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/authn/component/wssec/WSSecAuthNComponent.java
2009-10-21 12:52:59 UTC (rev 5317)
@@ -13,8 +13,6 @@
import org.perfsonar.base2.service.authn.tokens.SecTokenManagerFactory;
import org.perfsonar.base2.service.authn.tokens.SecTokenSOAPManager;
import org.perfsonar.base2.service.authn.tokens.SecurityToken;
-import org.perfsonar.base2.service.configuration.Configuration;
-import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
public class WSSecAuthNComponent extends AuthNComponent {
@@ -27,64 +25,80 @@
}
@Override
+ public void run() throws PerfSONARException {
+ // do nothing
+ }
+
+ @Override
public void init() throws PerfSONARException {
logger.debug("WSSecAuthNComponent: init");
}
public void requestAuthN(String messageType) throws
PerfSONARException {
- SecurityToken st=new
SecurityToken(SecTokenManagerFactory.getDefaultSecTokenManager());
+ SecurityToken st = new SecurityToken(SecTokenManagerFactory
+ .getDefaultSecTokenManager());
if (!st.hasSecTokenInRequest()) {
- logger.error("WSSecAuthNComponent: It has not sent
any Security Token");
+ logger
+ .error("WSSecAuthNComponent: It has
not sent any Security Token");
throw new PerfSONARException("authn_not_sectoken");
}
st.setSecTokenFromRequest();
- AuthNRequest authnReq=new AuthNRequest(st);
- AADispatchProtocol aadp =
AADispatchProtocolFactory.getDefaultAADispatchProtocol();
+ AuthNRequest authnReq = new AuthNRequest(st);
+ AADispatchProtocol aadp = AADispatchProtocolFactory
+ .getDefaultAADispatchProtocol();
aadp.setAuthService(getOption(AS_POINT).getValue());
- AADispatchManager aadm=new AADispatchManager(aadp);
- AuthNResponse authnRes=aadm.getAuthentication(authnReq);
- if (authnRes.getStatus()!=AuthNResponse.AUTHENTICATED) {
- logger.error("WSSecAuthNComponent: Authentication
failed ("+authnRes.getResultCode()+")");
+ AADispatchManager aadm = new AADispatchManager(aadp);
+ AuthNResponse authnRes = aadm.getAuthentication(authnReq);
+ if (authnRes.getStatus() != AuthNResponse.AUTHENTICATED) {
+ logger.error("WSSecAuthNComponent: Authentication
failed ("
+ + authnRes.getResultCode() + ")");
throw new
PerfSONARException(authnRes.getResultCode());
}
}
private String getResource() throws PerfSONARException {
String res = this.getOption(COMP_ID_SERVICE).getValue();
- if (res==null) {
+ if (res == null) {
logger.error("Component ID not configured");
throw new PerfSONARException("as_edugain");
}
return res;
}
- public void requestAuthR(String messageType,String eventType) throws
PerfSONARException {
- boolean authr=true;
- SecurityToken st=new
SecurityToken(SecTokenManagerFactory.getDefaultSecTokenManager());
+ public void requestAuthR(String messageType, String eventType)
+ throws PerfSONARException {
+ boolean authr = true;
+ SecurityToken st = new SecurityToken(SecTokenManagerFactory
+ .getDefaultSecTokenManager());
if (!st.hasSecTokenInRequest()) {
- logger.error("WSSecAuthNComponent: It has not sent
any Security Token");
+ logger
+ .error("WSSecAuthNComponent: It has
not sent any Security Token");
throw new PerfSONARException("authn_not_sectoken");
}
st.setSecTokenFromRequest();
- AuthRRequest authrReq=new AuthRRequest(st, messageType);
+ AuthRRequest authrReq = new AuthRRequest(st, messageType);
authrReq.setResource(getResource());
- if (!(eventType==null||eventType.equals(""))) {
-
authrReq.setAction(URLEncoder.encode(messageType)+":"+URLEncoder.encode(eventType));
+ if (!(eventType == null || eventType.equals(""))) {
+ authrReq.setAction(URLEncoder.encode(messageType) +
":"
+ + URLEncoder.encode(eventType));
}
try {
authrReq.setSubject(SecTokenSOAPManager.getSubject(st));
} catch (Exception e) {
e.printStackTrace();
- logger.error("WSSecAuthNComponent: Cannot get authR
data from the Security Token");
+ logger
+ .error("WSSecAuthNComponent: Cannot
get authR data from the Security Token");
throw new PerfSONARException("authn_not_sectoken");
}
- AADispatchProtocol
prot=AADispatchProtocolFactory.getDefaultAADispatchProtocol();
+ AADispatchProtocol prot = AADispatchProtocolFactory
+ .getDefaultAADispatchProtocol();
prot.setAuthService(getOption("as_endpoint").getValue());
- AADispatchManager aadm=new AADispatchManager(prot);
- AuthRResponse authrRes=aadm.getAuthorization(authrReq);
- if (authrRes.getStatus()!=AuthRResponse.AUTHORIZED) {
- logger.error("WSSecAuthNComponent: Authentication
failed ("+authrRes.getResultCode()+")");
+ AADispatchManager aadm = new AADispatchManager(prot);
+ AuthRResponse authrRes = aadm.getAuthorization(authrReq);
+ if (authrRes.getStatus() != AuthRResponse.AUTHORIZED) {
+ logger.error("WSSecAuthNComponent: Authentication
failed ("
+ + authrRes.getResultCode() + ")");
throw new
PerfSONARException(authrRes.getResultCode());
}
}
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/Component.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/Component.java
2009-10-20 20:41:35 UTC (rev 5316)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/Component.java
2009-10-21 12:52:59 UTC (rev 5317)
@@ -29,6 +29,14 @@
public abstract void init() throws PerfSONARException;
+
+ /**
+ *
+ * method is used to activate SchedulerComponents
+ *
+ * @throws PerfSONARException
+ */
+ public abstract void run() throws PerfSONARException;
public abstract void destroy() throws PerfSONARException;
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
2009-10-20 20:41:35 UTC (rev 5316)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
2009-10-21 12:52:59 UTC (rev 5317)
@@ -1,7 +1,3 @@
-/**
- * $Id: ConfigurationManager.java 4684 2008-11-03 13:07:33Z roman $
- * Project: perfSONAR
- */
package org.perfsonar.base2.service.configuration;
@@ -17,7 +13,13 @@
import org.apache.log4j.Logger;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-
+/**
+ *
+ * This class is a singleton which creates one instance of configuration
+ *
+ * @author roman,trzaszcz
+ *
+ */
public class ConfigurationManager {
@@ -30,7 +32,7 @@
protected static String DEFAULT_CONFIG_DIR_PREFIX = "perfsonar/conf";
/**
- * Ibatis rules file.
+ * Configuration rules file.
*/
protected static String DEFAULT_CONFIG_RULES= "configuration-rules.xml";
@@ -63,27 +65,50 @@
// -----------------------------------------------------------
Constructor
+ /**
+ * initializes the instance of configuration manager and invokes run
method on components (scheduler are activated)
+ *
+ *
+ * @return an instance of ConfigurationManager
+ * @throws PerfSONARExceptiona
+ */
public static ConfigurationManager getInstance() throws
PerfSONARException {
-
- if (!initialised) {
- synchronized (initialiseMutex) {
- logger.info("Initialize Configuration Manager");
- if(!initialised && !isInitialising) {
- isInitialising = true;
- initialised = configurationManager.initConfiguration();
- isInitialising = false;
- }
- }
- }
- initialised = true;
- return configurationManager;
+ return initializeConfigurationManager(true);
}
+
+ /**
+ *
+ * initialize the instance of configuration manager without invoking run
method on created components (scheduler are disactivated)
+ *
+ * @return an instance of ConfigurationManager
+ * @throws PerfSONARExceptiona
+ */
+ public static ConfigurationManager getInstanceWithoutRunningComponents()
throws PerfSONARException {
+ return initializeConfigurationManager(false);
+ }
+
+
+ private static ConfigurationManager
initializeConfigurationManager(boolean runComponents) throws
PerfSONARException{
+
+ if (!initialised) {
+ synchronized (initialiseMutex) {
+ logger.info("Initialize Configuration Manager");
+ if(!initialised && !isInitialising) {
+ isInitialising = true;
+ initialised =
configurationManager.initConfiguration(runComponents);
+ isInitialising = false;
+ }
+ }
+ }
+ initialised = true;
+ return configurationManager;
+ }
// ----------------------------------------------------------- Methods
- protected boolean initConfiguration() throws PerfSONARException {
+ protected boolean initConfiguration(boolean runComponents) throws
PerfSONARException {
//check and read sys env variable with the path of config directory
readEnvVariable();
@@ -112,7 +137,7 @@
}
- initializeAuxiliaryComponents();
+ initializeAuxiliaryComponents(runComponents);
return true;
@@ -148,7 +173,7 @@
private InputStream getDigesterInputStream() throws PerfSONARException {
- logger.debug("Read ibatis configuration settings from the file [" +
digesterInput + "]");
+ logger.debug("Read configuration settings from the file [" +
digesterInput + "]");
InputStream digesterInputStream = null;
try {
@@ -173,16 +198,16 @@
return digesterInputStream;
}
-
-
+
/**
- * Initializes auxiliary components
+ *
+ * Initializes auxiliary components
+ *
+ * @param runComponents - if the value is true then in all components
run method is invoked (in case of SchedulerComponents - scheduler is
activated)
* @throws PerfSONARException
*/
+ private void initializeAuxiliaryComponents(boolean runComponents) throws
PerfSONARException {
- @SuppressWarnings("unchecked")
- private void initializeAuxiliaryComponents() throws PerfSONARException {
-
AuxiliaryComponents ac = configuration.getAuxiliaryComponents();
if (ac == null) return;
@@ -191,6 +216,10 @@
try {
logger.info("Initialize component ["+c.getName()+"] as
["+c.getClassName()+"]");
((Component)c).init();
+ if(runComponents){
+ c.run();
+ }
+
} catch (Exception ex) {
logger.error("Can not initialize auxiliary component ["+
c.getClass()+"]. Nested exception is:
"+ex.toString());
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
2009-10-20 20:41:35 UTC (rev 5316)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
2009-10-21 12:52:59 UTC (rev 5317)
@@ -33,10 +33,13 @@
loadSettings();
createScheduler();
- runScheduler();
}
+
+ @Override
+ public void run() throws PerfSONARException {
+ runScheduler();
+ }
-
@Override
public void destroy() throws PerfSONARException {
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/storage/xml/XMLDBComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/storage/xml/XMLDBComponent.java
2009-10-20 20:41:35 UTC (rev 5316)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/storage/xml/XMLDBComponent.java
2009-10-21 12:52:59 UTC (rev 5317)
@@ -29,6 +29,11 @@
checkConfiguration();
}
+
+ @Override
+ public void run() throws PerfSONARException {
+ //do nothing
+ }
@Override
public void destroy() throws PerfSONARException {
- perfsonar: r5317 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: authn/component/wssec configuration scheduler storage/xml, svnlog, 10/21/2009
Archive powered by MHonArc 2.6.16.