Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r3262 - trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine

Subject: perfsonar development work

List archive

perfsonar: r3262 - trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r3262 - trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine
  • Date: Wed, 23 Jan 2008 14:04:15 -0500

Author: fernandes
Date: 2008-01-23 14:04:15 -0500 (Wed, 23 Jan 2008)
New Revision: 3262

Modified:

trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine/CommandLineCronComponent.java
Log:


Modified:
trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine/CommandLineCronComponent.java
===================================================================
---
trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine/CommandLineCronComponent.java
2008-01-23 18:58:19 UTC (rev 3261)
+++
trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine/CommandLineCronComponent.java
2008-01-23 19:04:15 UTC (rev 3262)
@@ -3,10 +3,13 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Calendar;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

@@ -16,7 +19,6 @@
import org.ggf.ns.nmwg.base.v2_0.Metadata;
import org.ggf.ns.nmwg.tools.cron.v2_0.Parameters;
import org.ggf.ns.nmwg.tools.cron.v2_0.Subject;
-import org.omg.CORBA.SystemException;
import org.perfsonar.base.auxiliary.AuxiliaryComponent;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
@@ -293,7 +295,7 @@
totalEntries++;

return ResultCodesUtil.createResultCodeMetadata(null,
- new
PerfSONARException("success.mp.clmp.cron.entryInsert",
+ new
PerfSONARException("success.mp.clmp.cron.add",
"CommandLineCronComponent:
entry successfully added. Your key is "
+
metadata.getId()));
}
@@ -307,14 +309,26 @@

int pos = database.modifyEntry(key,
stringToEntry(scheduleRequest
.getEntry()));
-
+
+ if(pos < 0){
+ return ResultCodesUtil.createResultCodeMetadata(null,
+ new
PerfSONARException("failure.mp.clmp.cron.modify", CNAME
+ + ": No entry found
matching the key provided."));
+ }
+
+ HashMap<String, String> fields =
getFieldsFromString(scheduleRequest.getEntry());
try {
File db = new File(cronPath + "/" + DBFILE);
FileChannel outChannel = (new RandomAccessFile(db,
"rw"))
.getChannel();
- outChannel.position(ENTRYSIZE * (totalEntries - 1 -
pos));
-
outChannel.write(ByteBuffer.wrap(scheduleRequest.getEntry()
- .getBytes("ISO-8859-1")));
+
+ writeField(pos, fields.get("minutes"), 0, outChannel);
+ writeField(pos, fields.get("hours"), 80, outChannel);
+ writeField(pos, fields.get("dom"), 110, outChannel);
+ writeField(pos, fields.get("months"), 150,
outChannel);
+ writeField(pos, fields.get("dow"), 170, outChannel);
+ writeField(pos, fields.get("ma"), 176, outChannel);
+
outChannel.close();

} catch (Exception e) {
@@ -332,12 +346,19 @@
+ "Exception caught
while trying to access cron database file. "
+ e.getMessage());
}
-
+
return ResultCodesUtil.createResultCodeMetadata(null,
- new
PerfSONARException("success.mp.clmp.cron.entryModification",
+ new
PerfSONARException("success.mp.clmp.cron.modify",
CNAME + ": entry successfully
modified. "));
}

+ private void writeField(int pos, String field, int offset,
FileChannel outChannel) throws IOException, UnsupportedEncodingException {
+ if(!field.startsWith("null")){
+ outChannel.position((ENTRYSIZE * (totalEntries - 1 -
pos)) + offset);
+
outChannel.write(ByteBuffer.wrap(field.getBytes("ISO-8859-1")));
+ }
+ }
+
public Message remove(ScheduleRequest scheduleRequest)
throws PerfSONARException {

@@ -412,11 +433,11 @@

if(count > 0)
return ResultCodesUtil.createResultCodeMetadata(null,
- new
PerfSONARException("success.mp.clmp.cron.entryRemoval", CNAME
+ new
PerfSONARException("success.mp.clmp.cron.remove", CNAME
+ ": "+count+" entry(ies)
successfully removed. "));

return ResultCodesUtil.createResultCodeMetadata(null,
- new
PerfSONARException("failure.mp.clmp.cron.entryRemoval", CNAME
+ new
PerfSONARException("failure.mp.clmp.cron.remove", CNAME
+ ": No entry(ies) found with
provided key(s). "));
}

@@ -518,9 +539,11 @@

cron.getSubject().setMetadataIdRef(data.getMetadataIdRef());
data.setMetadataIdRef(cron.getId());

- if(actionMetadata.getMetadataIdRef() != null)
+ if(actionMetadata.getMetadataIdRef() != null
&& actionMetadata.getMetadataIdRef().length() > 0)

response.addChild(actionMessage.getMetadata(actionMetadata.getMetadataIdRef()));
- else if(actionMetadata.getSubject() != null
&& actionMetadata.getSubject().getMetadataIdRef() != null)
+ else if(actionMetadata.getSubject() != null
+ &&
actionMetadata.getSubject().getMetadataIdRef() != null
+ &&
actionMetadata.getSubject().getMetadataIdRef().length() > 0)

response.addChild(actionMessage.getMetadata(actionMetadata.getSubject().getMetadataIdRef()));

response.addChild(actionMetadata);
@@ -645,65 +668,81 @@

return cron;
}
-
+
+ private HashMap<String, String> getFieldsFromString(String entry){
+ HashMap<String, String> fields = new HashMap<String,
String>();
+ fields.put("minutes", entry.substring(0, 80));
+ fields.put("hours", entry.substring(80, 110));
+ fields.put("dom", entry.substring(110, 150));
+ fields.put("months", entry.substring(150, 170));
+ fields.put("dow", entry.substring(170, 176));
+ fields.put("ma", entry.substring(176, 326));
+ if(entry.length() > 326){
+ fields.put("key", entry.substring(326, 396));
+ if (entry.length() > 396)
+ fields.put("action", entry.substring(396,
ENTRYSIZE));
+ }
+ return fields;
+ }
+
private Entries stringToEntry(String str) {
-
- Entries entry = new Entries();
-
- String min = str.substring(0, 80).trim();
- String h = str.substring(80, 110).trim();
- String dofm = str.substring(110, 150).trim();
- String mon = str.substring(150, 170).trim();
- String dofw = str.substring(170, 176).trim();
- String ma = str.substring(176, 326).trim();
+ HashMap<String, String> fields = getFieldsFromString(str);
+
+ String min = fields.get("minutes").trim();
+ String h = fields.get("hours").trim();
+ String dofm = fields.get("dom").trim();
+ String mon = fields.get("months").trim();
+ String dofw = fields.get("dow").trim();
+ String ma = fields.get("ma").trim();
String key = "", action = "";
if(str.length() > 326){
- key= str.substring(326, 396).trim();
+ key = fields.get("key").trim();
if (str.length() > 396)
- action = str.substring(396, ENTRYSIZE).trim();
+ action = fields.get("action").trim();
}
-
+
+ Entries entry = new Entries();
entry.setMa(ma);
entry.setKey(key);
entry.setAction(action);

/*
- * logger.debug("min: " + min); logger.debug("h: " + h);
- * logger.debug("dofm: " + dofm); logger.debug("mon: " + mon);
- * logger.debug("dofw: " + dofw); logger.debug("ma: " + ma);
- * logger.debug("key: " + key); logger.debug("action: " +
action);
+ * TODO: Refactoring.
*/

long minutes = 0;
+ if(min.equals("null"))
+ minutes = -1;
+ else{
+ if (min.startsWith("*")) {
+ if (min.length() > 1) {
+ int div =
Integer.parseInt(min.substring(2));
+ for (int count = 0; count <= 59;
count += div)
+ minutes =
BitManipulation.setBit(minutes, count);
+ } else
+ for (int count = 0; count <= 59;
count++)
+ minutes =
BitManipulation.setBit(minutes, count);
+ } else {

- if (min.startsWith("*")) {
- if (min.length() > 1) {
- int div = Integer.parseInt(min.substring(2));
- for (int count = 0; count <= 59; count += div)
- minutes =
BitManipulation.setBit(minutes, count);
- } else
- for (int count = 0; count <= 59; count++)
- minutes =
BitManipulation.setBit(minutes, count);
- } else {
+ String[] minArray = min.split(",");

- String[] minArray = min.split(",");
+ for (int i = 0; i < minArray.length; i++) {

- for (int i = 0; i < minArray.length; i++) {
+ String[] range =
minArray[i].split("-");

- String[] range = minArray[i].split("-");
+ if (range.length == 1)
+ minutes =
BitManipulation.setBit(minutes, Integer
+
.parseInt(range[0]));

- if (range.length == 1)
- minutes =
BitManipulation.setBit(minutes, Integer
- .parseInt(range[0]));
+ else if (range.length == 2) {
+ int bottom =
Integer.parseInt(range[0]);
+ int top =
Integer.parseInt(range[1]);

- else if (range.length == 2) {
- int bottom =
Integer.parseInt(range[0]);
- int top = Integer.parseInt(range[1]);
+ for (; bottom <= top;
bottom++)
+ minutes =
BitManipulation.setBit(minutes, bottom);
+ }

- for (; bottom <= top; bottom++)
- minutes =
BitManipulation.setBit(minutes, bottom);
}
-
}
}

@@ -712,145 +751,153 @@
// Transforming hours

int hours = 0;
+ if(h.equals("null"))
+ hours = -1;
+ else{
+ if (h.startsWith("*")) {
+ if (h.length() > 1) {
+ int div =
Integer.parseInt(h.substring(2));
+ for (int count = 0; count <= 22;
count += div)
+ hours =
BitManipulation.setBit(hours, count);
+ } else
+ for (int count = 0; count <= 22;
count++)
+ hours =
BitManipulation.setBit(hours, count);
+ } else {

- if (h.startsWith("*")) {
- if (h.length() > 1) {
- int div = Integer.parseInt(h.substring(2));
- for (int count = 0; count <= 59; count += div)
- hours = BitManipulation.setBit(hours,
count);
- } else
- for (int count = 0; count <= 22; count++)
- hours = BitManipulation.setBit(hours,
count);
- } else {
+ String[] hourArray = h.split(",");

- String[] hourArray = h.split(",");
+ for (int i = 0; i < hourArray.length; i++) {

- for (int i = 0; i < hourArray.length; i++) {
+ String[] range =
hourArray[i].split("-");

- String[] range = hourArray[i].split("-");
+ if (range.length == 1)
+ hours =
BitManipulation.setBit(hours, Integer
+
.parseInt(range[0]));

- if (range.length == 1)
- hours = BitManipulation.setBit(hours,
Integer
- .parseInt(range[0]));
+ else if (range.length == 2) {
+ int bottom =
Integer.parseInt(range[0]);
+ int top =
Integer.parseInt(range[1]);

- else if (range.length == 2) {
- int bottom =
Integer.parseInt(range[0]);
- int top = Integer.parseInt(range[1]);
-
- for (; bottom <= top; bottom++)
- hours =
BitManipulation.setBit(hours, bottom);
+ for (; bottom <= top;
bottom++)
+ hours =
BitManipulation.setBit(hours, bottom);
+ }
}
}
}
-
entry.setHours(hours);

// Transforming dom

int dom = 0;
+ if(dofm.equals("null"))
+ dom = -1;
+ else{
+ if (dofm.startsWith("*")) {
+ if (dofm.length() > 1) {
+ int div =
Integer.parseInt(dofm.substring(2));
+ for (int count = 0; count <= 30;
count += div)
+ dom =
BitManipulation.setBit(dom, count);
+ } else
+ for (int count = 0; count <= 30;
count++)
+ dom =
BitManipulation.setBit(dom, count);
+ } else {

- if (dofm.startsWith("*")) {
- if (dofm.length() > 1) {
- int div = Integer.parseInt(dofm.substring(2));
- for (int count = 0; count <= 59; count += div)
- dom = BitManipulation.setBit(dom,
count);
- } else
- for (int count = 0; count <= 30; count++)
- dom = BitManipulation.setBit(dom,
count);
- } else {
+ String[] domArray = dofm.split(",");

- String[] domArray = dofm.split(",");
+ for (int i = 0; i < domArray.length; i++) {

- for (int i = 0; i < domArray.length; i++) {
+ String[] range =
domArray[i].split("-");

- String[] range = domArray[i].split("-");
+ if (range.length == 1)
+ dom =
BitManipulation.setBit(dom, Integer
+
.parseInt(range[0]));

- if (range.length == 1)
- dom = BitManipulation.setBit(dom,
Integer
- .parseInt(range[0]));
+ else if (range.length == 2) {
+ int bottom =
Integer.parseInt(range[0]);
+ int top =
Integer.parseInt(range[1]);

- else if (range.length == 2) {
- int bottom =
Integer.parseInt(range[0]);
- int top = Integer.parseInt(range[1]);
-
- for (; bottom <= top; bottom++)
- dom =
BitManipulation.setBit(dom, bottom);
+ for (; bottom <= top;
bottom++)
+ dom =
BitManipulation.setBit(dom, bottom);
+ }
}
}
}
-
entry.setDom(dom);

// Transforming months

short months = 0;
+ if(mon.equals("null"))
+ months = -1;
+ else{
+ if (mon.startsWith("*")) {
+ if (mon.length() > 1) {
+ int div =
Integer.parseInt(mon.substring(2));
+ for (int count = 0; count <= 11;
count += div)
+ months =
BitManipulation.setBit(months, count);
+ } else
+ for (int count = 0; count <= 11;
count++)
+ months =
BitManipulation.setBit(months, count);
+ } else {

- if (mon.startsWith("*")) {
- if (mon.length() > 1) {
- int div = Integer.parseInt(mon.substring(2));
- for (int count = 0; count <= 59; count += div)
- months =
BitManipulation.setBit(months, count);
- } else
- for (int count = 0; count <= 11; count++)
- months =
BitManipulation.setBit(months, count);
- } else {
+ String[] monthsArray = mon.split(",");

- String[] monthsArray = mon.split(",");
+ for (int i = 0; i < monthsArray.length; i++) {

- for (int i = 0; i < monthsArray.length; i++) {
+ String[] range =
monthsArray[i].split("-");

- String[] range = monthsArray[i].split("-");
+ if (range.length == 1)
+ months =
BitManipulation.setBit(months, Integer
+
.parseInt(range[0]));

- if (range.length == 1)
- months =
BitManipulation.setBit(months, Integer
- .parseInt(range[0]));
+ else if (range.length == 2) {
+ int bottom =
Integer.parseInt(range[0]);
+ int top =
Integer.parseInt(range[1]);

- else if (range.length == 2) {
- int bottom =
Integer.parseInt(range[0]);
- int top = Integer.parseInt(range[1]);
-
- for (; bottom <= top; bottom++)
- months =
BitManipulation.setBit(months, bottom);
+ for (; bottom <= top;
bottom++)
+ months =
BitManipulation.setBit(months, bottom);
+ }
}
}
}
-
entry.setMonths(months);

// Transforming dow

byte dow = 0;
+ if(dofw.equals("null"))
+ dow = -1;
+ else{
+ if (dofw.startsWith("*")) {
+ if (dofw.length() > 1) {
+ int div =
Integer.parseInt(dofw.substring(2));
+ for (int count = 0; count <= 6; count
+= div)
+ dow =
BitManipulation.setBit(dow, count);
+ } else
+ for (int count = 0; count <= 6;
count++)
+ dow =
BitManipulation.setBit(dow, count);
+ } else {

- if (dofw.startsWith("*")) {
- if (dofw.length() > 1) {
- int div = Integer.parseInt(dofw.substring(2));
- for (int count = 0; count <= 59; count += div)
- dow = BitManipulation.setBit(dow,
count);
- } else
- for (int count = 0; count <= 6; count++)
- dow = BitManipulation.setBit(dow,
count);
- } else {
+ String[] dowArray = dofw.split(",");

- String[] dowArray = dofw.split(",");
+ for (int i = 0; i < dowArray.length; i++) {

- for (int i = 0; i < dowArray.length; i++) {
+ String[] range =
dowArray[i].split("-");

- String[] range = dowArray[i].split("-");
+ if (range.length == 1)
+ dow =
BitManipulation.setBit(dow, Integer
+
.parseInt(range[0]));

- if (range.length == 1)
- dow = BitManipulation.setBit(dow,
Integer
- .parseInt(range[0]));
+ else if (range.length == 2) {
+ int bottom =
Integer.parseInt(range[0]);
+ int top =
Integer.parseInt(range[1]);

- else if (range.length == 2) {
- int bottom =
Integer.parseInt(range[0]);
- int top = Integer.parseInt(range[1]);
-
- for (; bottom <= top; bottom++)
- dow =
BitManipulation.setBit(dow, bottom);
+ for (; bottom <= top;
bottom++)
+ dow =
BitManipulation.setBit(dow, bottom);
+ }
}
}
}
-
entry.setDow(dow);

return entry;



  • perfsonar: r3262 - trunk/rnp_java-cl-mp/src/main/java/org/perfsonar/service/measurementPoint/commandLine, svnlog, 01/23/2008

Archive powered by MHonArc 2.6.16.

Top of Page