perfsonar-dev - perfsonar: r5371 - in branches/new-structure-with-base2/ps-mdm-ls/src/main: java/org/perfsonar/service/lookupservice/dls/schedulerActions java/org/perfsonar/service/lookupservice/summarization resources/perfsonar/conf
Subject: perfsonar development work
List archive
perfsonar: r5371 - in branches/new-structure-with-base2/ps-mdm-ls/src/main: java/org/perfsonar/service/lookupservice/dls/schedulerActions java/org/perfsonar/service/lookupservice/summarization resources/perfsonar/conf
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5371 - in branches/new-structure-with-base2/ps-mdm-ls/src/main: java/org/perfsonar/service/lookupservice/dls/schedulerActions java/org/perfsonar/service/lookupservice/summarization resources/perfsonar/conf
- Date: Thu, 3 Dec 2009 07:42:28 -0500
Author: trzaszcz
Date: 2009-12-03 07:42:28 -0500 (Thu, 03 Dec 2009)
New Revision: 5371
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/dls/schedulerActions/GLSRegistrationAction.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/LSSummarySynchronizationAction.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/resources/perfsonar/conf/configuration.xml
Log:
LSRegistrationAction - enhancement - change to abstract class
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/dls/schedulerActions/GLSRegistrationAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/dls/schedulerActions/GLSRegistrationAction.java
2009-12-03 12:38:53 UTC (rev 5370)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/dls/schedulerActions/GLSRegistrationAction.java
2009-12-03 12:42:28 UTC (rev 5371)
@@ -1,83 +1,38 @@
package org.perfsonar.service.lookupservice.dls.schedulerActions;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLConnection;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
import java.util.LinkedList;
-import java.util.Set;
-import javax.xml.stream.XMLStreamException;
-
import org.apache.log4j.Logger;
-import org.perfsonar.base2.service.configuration.Action;
-import org.perfsonar.base2.service.configuration.Configuration;
import org.perfsonar.base2.service.configuration.ConfigurationManager;
-import org.perfsonar.base2.service.configuration.LookupInformation;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
-import org.perfsonar.base2.service.registration.LSRegistrator;
-import org.perfsonar.base2.service.registration.RegisterDataSource;
+import org.perfsonar.base2.service.registration.LSRegistrationAction;
import org.perfsonar.base2.service.requesthandler.ServiceMessage;
-import org.perfsonar.base2.service.scheduler.SchedulerAction;
import org.perfsonar.base2.xml.Element;
-import org.perfsonar.base2.xml.ElementSerializer;
-import org.perfsonar.base2.xml.nmwg.Data;
-import org.perfsonar.base2.xml.nmwg.EventType;
import org.perfsonar.base2.xml.nmwg.Message;
-import org.perfsonar.base2.xml.nmwg.Metadata;
-import org.perfsonar.base2.xml.nmwg.NMWGNamespaceFactory;
-import org.perfsonar.base2.xml.nmwg.Subject;
import
org.perfsonar.service.lookupservice.summarization.ModificationCounterComponent;
-public class GLSRegistrationAction extends Action implements SchedulerAction
{
+/**
+ *
+ * Action registering to other GLS. Configuration of the addresses is in
configuration.xml
+ * There is 2 opportunities of definition GLS address:
+ * - direct address to concrete GLS
+ * - address to root.hints file that contains list of GLS
+ *
+ * @author Slawomir Trzaszczka
+ */
+public class GLSRegistrationAction extends LSRegistrationAction {
- private boolean initialized = false;
-
- private Logger logger=Logger.getLogger(GLSRegistrationAction.class);
-
- /**
- * Message type.
- */
- protected static final String REGISTRATION_REQUEST_MESSAGE_TYPE =
"LSRegisterRequest";
- /**
- * EventType name which is included in the metadata of
LSRegisterRequest
- * message.
- */
- private static final String DEFAULT_REGISTRATION_EVENT_TYPE =
"http://ogf.org/ns/nmwg/tools/org/perfsonar/service/lookup/registration/service/2.0";
+ private Logger logger = Logger.getLogger(GLSRegistrationAction.class);
- /**
- * Provides metadatat configuration which is sent to LS(s).
- */
- private RegisterDataSource dataSource = null;
-
- private String registrationEventType =
DEFAULT_REGISTRATION_EVENT_TYPE;
-
- /**
- * Set of information about the service taken from the configuration.
- */
- private LookupInformation lookupInformation = null;
-
private ModificationCounterComponent modificationCounterComponent;
- /**
- * Sends messages to LS(s).
- */
- protected LSRegistrator registrator;
-
private LinkedList<URL> glsAddresses;
private Element registeredKey;
- private void init() throws PerfSONARException {
+ public void init() throws PerfSONARException {
dataSource = getRegisterDataSource();
registrationEventType = getRegistrationEventType();
lookupInformation = getLookupInformation();
@@ -88,107 +43,44 @@
registrator = getLSRegistrator();
}
- /**
- *
- * returns LSRegistrator configured in configuration.xml
- *
- * @return
- * @throws PerfSONARException
- */
- private LSRegistrator getLSRegistrator() throws PerfSONARException {
- String className = getOption("registrator").getValue();
- LSRegistrator registrator = null;
+
- try {
- registrator = (LSRegistrator) Class.forName(className)
- .newInstance();
- } catch (InstantiationException e) {
- e.printStackTrace();
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + e.toString());
+ public void execute() {
- } catch (IllegalAccessException e) {
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + e.toString());
-
- } catch (ClassNotFoundException e) {
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + e.toString());
- }
-
- return registrator;
-
- }
-
- @Override
- public void runAction() {
- if (!initialized) {
- try {
- init();
- initialized = true;
- } catch (PerfSONARException e) {
- e.printStackTrace();
- logger.warn("Cannot initialize "
- +
this.getClass().getCanonicalName());
- }
- }
- execute();
- refresh();
-
- }
-
- private void execute() {
-
boolean sendKeekAlive = false;
boolean registrationSuccess = false;
ServiceMessage response;
-
logger.info("---------------------------------------------------------------------------------------------");
- if
(modificationCounterComponent.getDiffsBetweenRegistrationCounter() > 0) {
- // There are no changes - send keep alive to GLS
- logger.info("no changes in DB");
+
+ if
(modificationCounterComponent.getDiffsBetweenRegistrationCounter() == 0) {
+ // There are no changes - send KeepAlive to GLS
+ logger.debug("no changes in DB");
sendKeekAlive = true;
} else {
// Get summarization data and send it to GLS
- logger.info("there are changes - send summarized
data");
+ logger.debug("there are changes - send summarized
data");
sendKeekAlive = false;
}
-
+
modificationCounterComponent.resetDiffsBetweenRegistrationCounter();
-
+
if (registeredKey != null && sendKeekAlive) {
// send keep alive to last used GLS
URL glsAddress = glsAddresses.getFirst();
try {
response =
registrator.keepalive(registeredKey, glsAddress);
- logger.info("KeepAlive message registered " +
glsAddress);
-
-// ElementSerializer es=new ElementSerializer();
-// try {
-// FileOutputStream fos=new
FileOutputStream(new File("/home/czacha/Desktop/k"+(new Date())));
-// es.write(fos, response.getElement());
-// } catch (FileNotFoundException e) {
-// e.printStackTrace();
-// } catch (XMLStreamException e) {
-// e.printStackTrace();
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-
- registeredKey = getKeyFromResponse(response);
- if (registeredKey == null) {
- // SOMETHING IS WRONG - TRY AGAIN
- registrationSuccess = false;
- logger.info("KEEP ALIVE rejected !");
- } else {
+ logger.debug("KeepAlive message registered "
+ glsAddress);
+
+ if
(isResponseSuccess(getResponseMetadata(response))) {
registrationSuccess = true;
- logger.info("KEEP ALIVE accepted");
+ logger.debug("KEEP ALIVE accepted");
+ } else {
+ registrationSuccess = false;
+ logger.debug("KEEP ALIVE rejected !");
}
+
} catch (PerfSONARException e) {
- logger.warn("Problem with sending KeepAlive
message to :"
+ logger.debug("Problem with sending KeepAlive
message to :"
+ glsAddress.toString());
URL brokenGLSURL = glsAddresses.poll();
glsAddresses.add(brokenGLSURL);
@@ -196,7 +88,8 @@
}
}
-
+
+ // if registration using KeepAlive message failed or there
wasn't any registration before ...
if (!registrationSuccess) {
int nrOfGls = glsAddresses.size();
@@ -205,39 +98,28 @@
try {
serviceRequestMessage =
getLSRegisterMessage();
} catch (PerfSONARException e) {
- e.printStackTrace();
+ logger.warn("Cannot build registration
message !");
+ logger.warn(e);
}
+
+ //try to register to first working GLS from list of
all
while (nrOfGls > 0) {
-
+
if (serviceRequestMessage != null) {
-
- Message requestMessage = (Message)
serviceRequestMessage.getElement();
-
+
+ Message requestMessage = (Message)
serviceRequestMessage
+ .getElement();
+
URL glsAddress =
glsAddresses.getFirst();
try {
response =
registrator.register(requestMessage,
glsAddress);
-
- ElementSerializer es=new
ElementSerializer();
- try {
- FileOutputStream
fos=new FileOutputStream(new File("/home/czacha/Desktop/r"+(new Date())));
- FileOutputStream
fos1=new FileOutputStream(new File("/home/czacha/Desktop/rr"+(new Date())));
- es.write(fos,
response.getElement());
- es.write(fos1,
requestMessage);
- } catch
(FileNotFoundException e) {
- e.printStackTrace();
- } catch (XMLStreamException
e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
+
logger.info("Registration
message sent");
registeredKey =
getKeyFromResponse(response);
if (registeredKey == null) {
- // SOMETHING IS WRONG
- TRY AGAIN
- logger.info("no
registerd key");
- }else{
+ logger.debug("no
registerd key in registration response");
+ } else {
break;
}
} catch (PerfSONARException e) {
@@ -253,268 +135,20 @@
}
}
- for(URL url :glsAddresses){
- logger.info(url);
+ for (URL url : glsAddresses) {
+ System.out.println(url);
}
-
+
if (registeredKey == null) {
logger.warn("Registration to GLS failed !!");
- }else{
- logger.info("Registration completed");
- }
-
- }
-
- private void refresh() {
-
- }
-
- /**
- *
- * returns RegisterDataSource configured in configuration.xml file
- *
- * @return
- * @throws PerfSONARException
- */
- private RegisterDataSource getRegisterDataSource()
- throws PerfSONARException {
-
- String className = getOption("registerDataSource").getValue();
- if (className == null || className.trim().equals(""))
- logger
- .warn("registerDataSource option of
register action is empty");
-
- logger.info("rds : " + className);
- RegisterDataSource registerDataSource = null;
-
- try {
- registerDataSource = (RegisterDataSource)
Class.forName(className)
- .newInstance();
- } catch (InstantiationException e) {
- e.printStackTrace();
- throwException(e);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- throwException(e);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- throwException(e);
- }
-
- return registerDataSource;
-
- }
-
- /**
- * get registerEventType option value. If not present, take default
- *
- * @return
- */
- private String getRegistrationEventType() {
- String evt = getOption("registerEventType").getValue();
- if (evt != null) {
- logger
- .debug("Found [registerEventType]
option value [" + evt
- + "]");
- return evt;
} else {
- logger.debug("Taking default [registerEventType]
value ["
- + DEFAULT_REGISTRATION_EVENT_TYPE +
"]");
- return DEFAULT_REGISTRATION_EVENT_TYPE;
+ logger.debug("Registration completed");
}
- }
- /**
- *
- * returns LookupInformation configured in configuration.xml file
- *
- * @return
- * @throws PerfSONARException
- */
- private LookupInformation getLookupInformation() throws
PerfSONARException {
-
- Configuration configuration =
ConfigurationManager.getInstance()
- .getConfiguration();
- LookupInformation lookupInformation = (LookupInformation)
configuration
-
.getService().getEntry(Configuration.LOOKUP_INFORMATION);
- return lookupInformation;
}
- /**
- *
- * throws exception
- *
- * @param ex
- * @throws PerfSONARException
- */
- private void throwException(Exception ex) throws PerfSONARException {
- throw new PerfSONARException("error",
- "Unable to create an object of : " +
className + ": "
- + ex.toString());
- }
+ public void refresh() {
- /**
- * Get list of URLs to Lookup Services to register to.
- *
- * @return
- * @throws PerfSONARException
- */
- private LinkedList<URL> getLSAddresses() throws PerfSONARException {
-
- Set<URL> addressesSet = new HashSet<URL>();
-
- // get values from options lsAddress-1, lsAddress-2,
lsAddress-3, ...
- // and get LSes lists from URLs
-
- for (String optName : options.keySet()) {
-
- // handles lsAddress-1, lsAddress-2, lsAddress-3, ...
- if (optName.startsWith("lsAddress")) {
-
- try {
- URL url = new
URL(getOption(optName).getValue());
- addressesSet.add(url);
- } catch (MalformedURLException ex) {
- logger.warn("Unable to convert LS
address [" + optName
- + "] into URL object.
Exception was: "
- + ex.getMessage());
- }
-
- // handles lsList-1, lsList-2, ...
- } else if (optName.startsWith("lsList")) {
-
- try {
- String remoteResource =
getOption(optName).getValue();
- addLSAddressesFromURL(addressesSet,
remoteResource);
- } catch (MalformedURLException ex) {
- logger.warn("Unable to read LS list
from URL address ["
- + optName + "] into
URL object. Exception was: "
- + ex.getMessage());
- } catch (IOException ex) {
- logger.warn("Unable to read LS list
from URL address ["
- + optName + "] into
URL object. Exception was: "
- + ex.getMessage());
- }
-
- }
- }
-
- if (addressesSet.size() == 0) {
- // TODO : warning ??
- throw new PerfSONARException("warning", "No LS
addresses");
- } else {
- LinkedList<URL> glsAddresses = new LinkedList<URL>();
- for (URL url : addressesSet) {
- glsAddresses.add(url);
- }
- return glsAddresses;
- }
}
- /**
- * Populates urls collection with urls/lines downloaded from urlString
- *
- * @param urls
- * @param urlString
- * @throws MalformedURLException
- * @throws IOException
- */
- private void addLSAddressesFromURL(Set<URL> urls, String urlString)
- throws MalformedURLException, IOException {
-
- URL rootHintsUrl = new URL(urlString);
- URLConnection rhc = rootHintsUrl.openConnection();
- BufferedReader in = new BufferedReader(new
InputStreamReader(rhc
- .getInputStream()));
- String line;
- while ((line = in.readLine()) != null) {
- String s = line.trim();
- if ((s.length() > 0) && // not empty
- (!s.startsWith("#")) &&
(!s.startsWith("//"))) { // not
- // commentary
- // # or
- // //
-
- URL lsUrl = new URL(line);
- urls.add(lsUrl);
- }
- }
- in.close();
-
- }
-
- private ServiceMessage getLSRegisterMessage() throws
PerfSONARException {
-
- ServiceMessage serviceMessage = new ServiceMessage();
-
- Message message = new Message();
- message.setType(REGISTRATION_REQUEST_MESSAGE_TYPE);
- serviceMessage.setElement(message);
-
- Metadata metadata = new Metadata();
- metadata.setId("serviceLookupInfo");
- message.setMetadata(metadata);
-
- EventType eventType = new EventType();
- eventType.setEventType(registrationEventType);
- metadata.setEventType(eventType);
-
- Subject subject = new Subject("perfsonar");
- subject.setId("commonParameters");
- metadata.setSubject(subject);
-
- Element service = new Element("service", "psservice",
-
NMWGNamespaceFactory.getNamespace("psservice"));
- service.setId("serviceParameters");
- subject.addChild(service);
-
- Collection<String> keys =
lookupInformation.getOptions().keySet();
- for (String name : keys) {
- Element element = new Element(name, "psservice",
-
NMWGNamespaceFactory.getNamespace("psservice"));
-
element.setText(lookupInformation.getOption(name).getValue());
- service.addChild(element);
- }
-
- Data data = null;
- Message msg = (Message)
dataSource.getRegisterData().getElement();
- Collection<Metadata> c = msg.getMetadataCollection();
- if(c.isEmpty()){
- for (Metadata m : c) {
- data = new Data();
- data.setMetadataIdRef(metadata.getId());
- data.addChild(m);
- message.addChild(data);
- }
- }else{
- data=new Data();
- data.setMetadataIdRef(metadata.getId());
- message.addChild(data);
- }
-
- return serviceMessage;
-
- }
-
- private Element getKeyFromResponse(ServiceMessage response) {
- Element responseMessage = response.getElement();
-
- Element responseMetadata = null;
- Element eventType = null;
-
- if (responseMessage != null) {
- responseMetadata =
responseMessage.getFirstChild("metadata");
- if (responseMetadata != null) {
- eventType =
responseMetadata.getFirstChild("eventType");
- }
- }
-
- if (eventType != null) {
- if (eventType.getText().trim().indexOf("success") !=
-1) {
- return responseMetadata.getFirstChild("key");
- }
- }
- return null;
- }
-
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/LSSummarySynchronizationAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/LSSummarySynchronizationAction.java
2009-12-03 12:38:53 UTC (rev 5370)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/LSSummarySynchronizationAction.java
2009-12-03 12:42:28 UTC (rev 5371)
@@ -82,6 +82,7 @@
if (firstIteration) {
// in first iteration summary data is
built
synchronizeSummarizationCollection();
+ component.resetCounter();
iteration++;
firstIteration = false;
} else if (iteration != NR_OF_ITERATIONS) {
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
2009-12-03 12:38:53 UTC (rev 5370)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ModificationCounterComponent.java
2009-12-03 12:42:28 UTC (rev 5371)
@@ -46,7 +46,7 @@
public void increaseCounter(){
counter++;
diffsBetweenRegistrationCounter++;
- logger.debug("Counter increased "+counter);
+ logger.debug("Counter increased " +counter+ " diffs "+
diffsBetweenRegistrationCounter);
}
/**
* resets counter. This method is invoked after summarization process
@@ -54,6 +54,7 @@
*/
public void resetCounter(){
counter=0;
+ logger.debug("reset counter");
}
/**
@@ -61,6 +62,7 @@
*
*/
public void resetDiffsBetweenRegistrationCounter(){
+ logger.debug("reset diffsBetweenRegistrationCounter");
diffsBetweenRegistrationCounter=0;
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/resources/perfsonar/conf/configuration.xml
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/resources/perfsonar/conf/configuration.xml
2009-12-03 12:38:53 UTC (rev 5370)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/resources/perfsonar/conf/configuration.xml
2009-12-03 12:42:28 UTC (rev 5371)
@@ -143,16 +143,10 @@
<option name="nrOfIterations" value="4"/>
</action>
- <!--
- <action name="registration"
className="org.perfsonar.base2.service.registration.LSRegistrationAction">
- -->
<action name="registration"
className="org.perfsonar.service.lookupservice.dls.schedulerActions.GLSRegistrationAction">
<option name="status" value="on" />
- <!--
<option name="interval" value="43200" />
- -->
- <option name="interval" value="432" />
<option name="registerDataSource"
- perfsonar: r5371 - in branches/new-structure-with-base2/ps-mdm-ls/src/main: java/org/perfsonar/service/lookupservice/dls/schedulerActions java/org/perfsonar/service/lookupservice/summarization resources/perfsonar/conf, svnlog, 12/03/2009
Archive powered by MHonArc 2.6.16.