working CREAM job registration example (via client-java)
authorAleš Křenek <ljocha@ics.muni.cz>
Mon, 14 Sep 2009 11:07:59 +0000 (11:07 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Mon, 14 Sep 2009 11:07:59 +0000 (11:07 +0000)
15 files changed:
org.glite.jobid.api-java/src/org/glite/jobid/CheckedString.java [deleted file]
org.glite.jobid.api-java/src/org/glite/jobid/Jobid.java
org.glite.lb.client-java/Makefile
org.glite.lb.client-java/examples/CreamTest.java [new file with mode: 0644]
org.glite.lb.client-java/project/genEventTypes.pl
org.glite.lb.client-java/src/org/glite/lb/Context.java
org.glite.lb.client-java/src/org/glite/lb/ContextDirect.java [new file with mode: 0644]
org.glite.lb.client-java/src/org/glite/lb/Escape.java [new file with mode: 0644]
org.glite.lb.client-java/src/org/glite/lb/ILProto.java [moved from org.glite.lb.client-java/src/org/glite/lb/ILProtoReceiver.java with 62% similarity]
org.glite.lb.client-java/src/org/glite/lb/LBException.java
org.glite.lb.client-java/src/org/glite/lb/Notification.java
org.glite.lb.client-java/src/org/glite/lb/SSL.java
org.glite.lb.client-java/src/org/glite/lb/SeqCode.java
org.glite.lb.client-java/src/org/glite/lb/Sources.java
org.glite.lb.server/src/stored_master.c

diff --git a/org.glite.jobid.api-java/src/org/glite/jobid/CheckedString.java b/org.glite.jobid.api-java/src/org/glite/jobid/CheckedString.java
deleted file mode 100644 (file)
index da513c5..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.glite.jobid;
-
-/**
- * Class which escapes \ and new line signs in string which is set as parameter
- * in constructor
- * 
- * @author Pavel Piskac (173297@mail.muni.cz)
- * @version 15. 3. 2008
- */
-public class CheckedString {
-    
-    String checkedString;
-    
-    /**
-     * Creates new instance of CheckedString.
-     * 
-     * @param checkedString string which will be converted
-     * @throws java.lang.IllegalArgumentException if checkedString is null
-     */
-    public CheckedString(String checkedString) {
-        if (checkedString == null) {
-           this.checkedString = "";
-        }
-        
-        setCheckedString(checkedString);
-    }
-
-    /**
-     * Gets converted string.
-     * 
-     * @return converted string
-     */
-    public String getCheckedString() {
-        return checkedString;
-    }
-
-    /**
-     * Sets string which will be converted.
-     * 
-     * @param checkedString string which will be converted.
-     */
-    public void setCheckedString(String checkedString) {
-        checkedString = checkedString.replaceAll("[\\\"]", "\\\\\"");
-        checkedString = checkedString.replaceAll("[\n]", "\\\\\\\\n");
-        checkedString = checkedString.replaceAll("[/]", "_");
-        checkedString = checkedString.replaceAll("[\\+]", "-");
-        this.checkedString = checkedString;
-    }
-    
-    /**
-     * Returns converted string.
-     * 
-     * @return converted string
-     */
-    public String toString() {
-        return checkedString;
-    }
-
-}
index 9343068..e6ddbf4 100644 (file)
@@ -47,11 +47,10 @@ public class Jobid {
             throw new IllegalArgumentException("Jobid port");
         }
         
-        if (bkserver.indexOf("https://") == -1) {
-            throw new IllegalArgumentException("wrong jobid https");
-        }
-        
-        this.bkserver = bkserver;
+        if (bkserver.indexOf("https://") == -1)
+               this.bkserver = "https://" + bkserver;
+        else this.bkserver = bkserver;
+
         this.port = port;
         
         MessageDigest digest = null;
@@ -71,8 +70,9 @@ public class Jobid {
             digest.update(unique.getBytes(),0,unique.length());
             Base64 base64 = new Base64();
             byte[] tmp = base64.encode(digest.digest());
-            unique = new CheckedString(new String(tmp, 0, tmp.length-2)).toString();
-            
+            unique = new String(tmp, 0, tmp.length-2);
+           unique = unique.replaceAll("/", "_");
+           unique = unique.replaceAll("\\+", "-");
         } catch (NoSuchAlgorithmException ex) {
             System.err.println(ex);
             System.exit(-1);
@@ -106,7 +106,7 @@ public class Jobid {
         
         this.bkserver = bkserver;
         this.port = port;
-        this.unique = (new CheckedString(unique)).toString();
+        this.unique = unique;
     }
     
     /**
@@ -138,7 +138,7 @@ public class Jobid {
         
         this.bkserver = bkserverS;
         this.port = portS.intValue();
-        this.unique = (new CheckedString(uniqueS)).toString();
+        this.unique = uniqueS;
     }
 
     /**
@@ -186,7 +186,7 @@ public class Jobid {
             throw new IllegalArgumentException("Jobid unique");
         }
         
-        this.unique = (new CheckedString(unique)).toString();
+        this.unique = unique;
     }
 
     /**
index f8c960c..c04b328 100644 (file)
@@ -1,6 +1,6 @@
 -include Makefile.inc
 
-EXAMPLES := SimpleLLTest.class SSLClient.class SSLServer.class QueryDemo.class ProducerTestIL.class ProducerTestLL.class NotificationExample.class
+EXAMPLES := SimpleLLTest.class SSLClient.class SSLServer.class QueryDemo.class ProducerTestIL.class ProducerTestLL.class NotificationExample.class CreamTest.class
 
 VPATH := examples
 
diff --git a/org.glite.lb.client-java/examples/CreamTest.java b/org.glite.lb.client-java/examples/CreamTest.java
new file mode 100644 (file)
index 0000000..e4148a3
--- /dev/null
@@ -0,0 +1,51 @@
+import org.glite.lb.*;
+import org.glite.jobid.Jobid;
+
+public class CreamTest {
+
+public static void main(String[] args)
+{
+
+   try {
+       String[] srvpart = args[0].split(":");
+       int srvport = Integer.parseInt(srvpart[1]);
+       Jobid   job = new Jobid(srvpart[0],srvport);
+
+       LBCredentials   cred = new LBCredentials(System.getenv("X509_USER_PROXY"),"/etc/grid-security/certificates");
+
+
+       ContextDirect   ctxd = new ContextDirect(srvpart[0],srvport);
+       ctxd.setCredentials(cred);
+       ctxd.setSource(Sources.EDG_WLL_SOURCE_CREAM_CORE);
+       ctxd.setJobid(job);
+       ctxd.setSeqCode(new SeqCode(SeqCode.CREAM,"no_seqcodes_with_cream"));
+
+       EventRegJob     reg = new EventRegJob();
+       reg.setNs("https://where.is.cream:1234");
+       reg.setJobtype(EventRegJob.Jobtype.JOBTYPE_CREAM);
+
+       ctxd.log(reg);
+
+       System.out.println("JOBID="+job);
+
+
+
+/*
+       reg.setJdl
+
+
+       ContextIL       ctx = new ContextIL();
+*/
+       
+
+   } catch (Exception e)
+   {
+       System.err.println("Oops");
+       e.printStackTrace();
+   }
+
+}
+
+
+
+}
index e772057..822743b 100644 (file)
@@ -52,7 +52,23 @@ qq{          ${fnuu}_${cu},
 };
                                }
                                print E
-qq{\}
+qq{    \}
+       public static String ${fnu}ToString($fnu e) \{
+               String out = "UNDEF";
+               switch (e) \{
+};
+                               for (@{$f->{codes}}) {
+                                       my $cu = uc $_->{name};
+                                       print E
+qq{
+                       case ${fnuu}_${cu}: out = "$cu";
+};
+                               }
+                               print E
+qq{
+               \}
+               return out;
+       \}
 };
                        }
                        else {
@@ -74,7 +90,6 @@ qq{   private $t $fn;
                }
 
                print E
-
 qq{    public String ulm() \{
                return (" " +
 };
@@ -85,12 +100,18 @@ qq{        public String ulm() \{
                        my $fn = $f->{name};
                        my $t = getType $f;
                        my $fnu = ucfirst $fn;
+                       while ($fnu =~ /_([a-z])/) {
+                               my $u = uc $1;
+                               $fnu =~ s/_$1/$u/;
+                       }
                        my $fnuu = uc $fn;
                        my $val = $t eq 'String' ? 
-                               "new CheckedString($fn).toString()" : $fn;
+                               "($fn == null ? \"\" : Escape.ulm($fn))" :
+                               $f->{codes} ? "Escape.ulm(${fnu}ToString($fn))" :
+                               $fn;
 
                        print E
-qq{            "DG.$uuc.$fnuu=\\"" + $val + "\\"" +
+qq{            " DG.$uuc.$fnuu=\\"" + $val + "\\"" +
 };
                }
 
index dbb531d..8449a66 100644 (file)
@@ -4,7 +4,6 @@ import java.net.UnknownHostException;
 import java.util.Calendar;
 import java.util.Random;
 import org.glite.jobid.Jobid;
-import org.glite.jobid.CheckedString;
 
 /**
  * Class representing a context for some job
@@ -92,10 +91,10 @@ public abstract class Context {
         this.id = id;
         this.source = source;
         this.flag = flag;
-        this.host = new CheckedString(host).toString();
-        this.user = new CheckedString(user).toString();
-        this.prog = new CheckedString(prog).toString();
-        this.srcInstance = new CheckedString(srcInstance).toString();
+        this.host = host;
+        this.user = user;
+        this.prog = prog;
+        this.srcInstance = srcInstance;
         this.jobid = jobid;
     }
 
@@ -117,6 +116,8 @@ public abstract class Context {
             case Sources.EDG_WLL_SOURCE_LRMS: return "LRMS";
             case Sources.EDG_WLL_SOURCE_APPLICATION: return "Application";
             case Sources.EDG_WLL_SOURCE_LB_SERVER: return "LBServer";
+            case Sources.EDG_WLL_SOURCE_CREAM_CORE: return "CreamCore";
+            case Sources.EDG_WLL_SOURCE_BLAH: return "BLAH";
             default: throw new IllegalArgumentException("wrong source type");
         }
     }
@@ -159,10 +160,12 @@ public abstract class Context {
             throw new IllegalArgumentException("Context event");
         }
 
-        if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
-            throw new IllegalArgumentException("Context source");
+        if (seqCode == null) {
+            throw new IllegalArgumentException("Context seqCode");
         }
 
+       Sources.check(source);
+
         if (flag < 0) {
             throw new IllegalArgumentException("Context flag");
         }
@@ -206,20 +209,20 @@ public abstract class Context {
         String tmp2 = "000".substring(0, 3 - tmp.length()) + tmp;
         date += tmp2 + "000000".substring(tmp.length(), 6);
 
-        seqCode.incrementSeqCode(source);
+        if (seqCode != null) seqCode.incrementSeqCode(source);
 
         output = ("DG.LLLID=" + id +
-                " DG.USER=\"" + user + "\"" +
+                " DG.USER=\"" + Escape.ulm(user) + "\"" +
                 " DATE=" + date +
-                " HOST=\"" + host + "\"" +
-                " PROG=" + prog +
+                " HOST=\"" + Escape.ulm(host) + "\"" +
+                " PROG=" + Escape.ulm(prog) +
                 " LVL=SYSTEM" +
                 " DG.PRIORITY=0" +
                 " DG.SOURCE=\"" + recognizeSource(source) + "\"" +
-                " DG.SRC_INSTANCE=\"" + srcInstance + "\"" +
+                " DG.SRC_INSTANCE=\"" + Escape.ulm(srcInstance) + "\"" +
                 " DG.EVNT=\"" + event.getEventType() + "\"" +
                 " DG.JOBID=\"" + jobid + "\"" +
-                " DG.SEQCODE=\"" + seqCode + "\"" +
+                " DG.SEQCODE=\"" + Escape.ulm(seqCode.toString()) + "\"" +
                 event.ulm());
 
         return output;
@@ -332,7 +335,7 @@ public abstract class Context {
             prog = new String("edg-wms");
         }
 
-        this.prog = (new CheckedString(prog)).toString();
+        this.prog = prog;
     }
 
     /**
@@ -371,10 +374,7 @@ public abstract class Context {
      * @throws java.lang.IllegalArgumentException if source is null
      */
     public void setSource(int source) {
-        if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
-            throw new IllegalArgumentException("Context source");
-        }
-
+       Sources.check(source);
         this.source = source;
     }
 
@@ -395,7 +395,7 @@ public abstract class Context {
             srcInstance = new String("");
         }
 
-        this.srcInstance = new CheckedString(srcInstance).toString();
+        this.srcInstance = srcInstance;
     }
 
     /**
@@ -416,6 +416,6 @@ public abstract class Context {
             throw new IllegalArgumentException("Context user");
         }
 
-        this.user = (new CheckedString(user)).toString();
+        this.user = user;
     }
 }
diff --git a/org.glite.lb.client-java/src/org/glite/lb/ContextDirect.java b/org.glite.lb.client-java/src/org/glite/lb/ContextDirect.java
new file mode 100644 (file)
index 0000000..eea8361
--- /dev/null
@@ -0,0 +1,63 @@
+
+package org.glite.lb;
+import java.net.Socket;
+
+public class ContextDirect extends Context
+{
+       String  server;
+       int     port;
+       LBCredentials   cred;
+       ILProto il = null;
+       int     timeout = 20000;
+
+       public ContextDirect()
+       {
+       }
+
+       public ContextDirect(String server,int port)
+       {
+               if (server == null) {
+                       throw new IllegalArgumentException("server is null");
+               }
+               if (port < 1 || port > 65535) {
+                       throw new IllegalArgumentException("port is not valid range");
+               }
+               this.server = server;
+               this.port = port;
+       }
+
+       public void setCredentials(LBCredentials cred)
+       {
+               this.cred = cred;
+               il = null;
+       }
+
+       @Override
+       public void log(Event event) throws LBException {
+               if (il == null) {
+                       SSL ssl = new SSL();
+                       ssl.setCredentials(cred);
+                       Socket sock = ssl.connect(server,port+1,timeout);
+                       setUser(ssl.myDN());
+System.out.println("setUser("+ssl.myDN()+")");
+                       try { il = new ILProto(sock); }
+                       catch (Throwable e) { throw new LBException(e); }
+               }
+
+               String msg = super.createMessage(event);
+               int     maj;
+
+               try {
+                       il.sendMessage(msg);
+                       maj = il.receiveReply();
+               }
+               catch (Throwable e) { throw new LBException(e); }
+
+               if (maj > 0) {
+                       int     min = il.errMin();
+                       String  err = il.errMsg();
+
+                       throw new LBException("IL proto: " + maj + " " + min + " " + err);
+               }
+       }
+}
diff --git a/org.glite.lb.client-java/src/org/glite/lb/Escape.java b/org.glite.lb.client-java/src/org/glite/lb/Escape.java
new file mode 100644 (file)
index 0000000..0846662
--- /dev/null
@@ -0,0 +1,9 @@
+package org.glite.lb;
+
+class Escape {
+       public static String ulm(String in) {
+               String out = in.replaceAll("\"", "\\\"");
+               out = out.replaceAll("\n", "\\\n");
+               return out;
+       }
+}
@@ -15,12 +15,17 @@ import java.net.Socket;
  *
  * @author Kopac
  */
-public class ILProtoReceiver {
+public class ILProto {
 
     private Socket socket = null;
     private InputStream inStream = null;
     private OutputStream outStream = null;
-    private static final String magicWord = "6 michal";
+    private static final String magicWordXXX = "6 michal";
+    private static final String magicWord = "michal";
+    private int min,maj;
+    private String err;
+    private byte[] buf;
+    private int bufptr,bufsiz;
 
     /**
      * construcor initializes the class' socket, inStream and outStream attributes
@@ -28,7 +33,7 @@ public class ILProtoReceiver {
      * @param socket an SSLSocket
      * @throws java.io.IOException
      */
-    public ILProtoReceiver(Socket socket) throws IOException {
+    public ILProto(Socket socket) throws IOException {
         this.socket = socket;
         inStream = this.socket.getInputStream();
         outStream = this.socket.getOutputStream();
@@ -42,6 +47,7 @@ public class ILProtoReceiver {
      * the info about its length
      * @throws IOException
      */
+    /* XXX: weird implementation, should follow C */
     public String receiveMessage() throws IOException{
         byte[] b = new byte[17];
         int i = 0;
@@ -56,7 +62,7 @@ public class ILProtoReceiver {
             //read in the rest of the message
             int j = 0;
             while(i != length || j == -1) {
-                j = inStream.read(notification, i, length);
+                j = inStream.read(notification, i, length-i);
                 i=i+j;
             }
             String retString = checkWord(notification);
@@ -67,6 +73,43 @@ public class ILProtoReceiver {
         }
     }
 
+    public void sendMessage(String msg) throws IOException
+    {
+           newbuf(magicWord.length() + msg.length() + 100);
+           put_string(magicWord);
+           put_string(msg);
+           String hdr = String.format("%16d\n",bufptr);
+           outStream.write(hdr.getBytes());
+
+           writebuf();
+           outStream.flush();
+    }
+
+    public int receiveReply() throws IOException,LBException
+    {
+           newbuf(17);
+
+           if (readbuf(17) != 17) {
+                   throw new LBException("reading IL proto header");
+           }
+           int         len = Integer.parseInt((new String(buf)).trim());
+
+           newbuf(len);
+           if (readbuf(len) < len) {
+                   throw new LBException("incomplete IL message");
+           }
+
+           rewind();
+           this.maj = get_int();
+           this.min = get_int();
+           this.err = get_string();
+
+           return this.maj;
+    }
+
+    public int errMin() { return min; }
+    public String errMsg() { return err; }
+
     /**
      * private method that checks, if the magic word is present in the notification
      *
@@ -81,7 +124,7 @@ public class ILProtoReceiver {
         }
         String word = new String(notification, 0, i+1);
         word.trim();
-        if(!word.equals(magicWord)) {
+        if(!word.equals(magicWordXXX)) {
             return null;
         } else {
             return new String(notification, i+1, notification.length - i + 1);
@@ -135,4 +178,61 @@ public class ILProtoReceiver {
         }
         return arrayToFill;
     }
+
+    private void newbuf(int size) {
+           buf = new byte[size];
+           bufptr = 0;
+           bufsiz = size;
+    }
+
+    private void rewind() { bufptr = 0; }
+
+    private int readbuf(int size) throws IOException {
+           int r,total = 0;
+          
+           while (size > 0 && (r = inStream.read(buf,bufptr,size)) > 0) {
+                   bufptr += r;
+                   size -= r;
+                   total += r;
+           }
+           return total;
+    }
+
+    private void writebuf() throws IOException {
+           outStream.write(buf,0,bufptr);
+    }
+
+    private void _put_int(int ii)
+    {
+       String s = new String() + ii;
+       byte[] b = s.getBytes();
+       int i;
+
+       for (i=0; i<b.length; i++) buf[bufptr++] = b[i];
+    }
+    private void put_int(int i) { _put_int(i); buf[bufptr++] = '\n'; }
+    private void put_string(String s) {
+          int  i;
+          byte b[] = s.getBytes();
+          _put_int(b.length);
+          buf[bufptr++] = ' ';
+          for (i=0; i<b.length; i++) buf[bufptr++] = b[i];
+          buf[bufptr++] = '\n';
+    }
+
+/* FIXME: sanity checks */
+    private int get_int() {
+           int i,o;
+
+           for (i=0; Character.isDigit(buf[bufptr+i]); i++);
+           o = Integer.parseInt(new String(buf,bufptr,i));
+           bufptr += i+1;
+           return o;
+    }
+    private String get_string() {
+           int len = get_int();
+           String out = new String(buf,bufptr,len);
+           bufptr += len+1;
+           return out;
+    }
 }
index 00ef3fb..7228622 100644 (file)
@@ -5,5 +5,9 @@ public class LBException extends Exception {
     public LBException(Throwable e) {
                super(e);
        }
+
+    public LBException(String s) { 
+               super(s);
+       }
     
 }
index 53af91e..846d3a7 100644 (file)
@@ -208,16 +208,16 @@ public class Notification {
     public JobStatus receive(int timeout) throws LBException {
         SSL ssl = new SSL();
         ssl.setCredentials(lbCredent);
-        ILProtoReceiver receiver = null;
+        ILProto receiver = null;
         String received = null;
         try {
             if(socket == null) {
                 socket = ssl.accept(port, timeout);
             }
-            receiver = new ILProtoReceiver(socket);
+            receiver = new ILProto(socket);
             if((received = receiver.receiveMessage()) == null) {
                 socket = ssl.accept(port, timeout);
-                receiver = new ILProtoReceiver(socket);
+                receiver = new ILProto(socket);
                 received = receiver.receiveMessage();
             }
             receiver.sendReply(0, 0, "success");
index 045c2c6..f561f33 100644 (file)
@@ -80,4 +80,26 @@ public class SSL {
        catch (IOException e) { throw new LBException(e); }
     }
 
+    private static String slashDN(String dn) {
+           String f[] = dn.split(",");
+           int i;
+           String out = new String();
+
+           /* XXX: proxy */
+           for (i=f.length-1; i>=0 && f[i].indexOf("=proxy") == -1; i--) 
+                   out += "/" + f[i];
+
+           return out;
+    }
+
+    public String myDN()
+    {
+           java.security.cert.Certificate[] cert = sess.getLocalCertificates();
+           java.security.cert.X509Certificate xcert =
+                   (java.security.cert.X509Certificate) cert[0];
+       
+           return slashDN(xcert.getSubjectX500Principal().getName());
+    }
+
+
 }
index 06b1920..079435f 100644 (file)
@@ -7,8 +7,15 @@ package org.glite.lb;
  * @version 9. 4. 2008
  */
 public class SeqCode {
+
+    public static final int NORMAL = 1;
+    public static final int DUPLICATE = 11;
+    public static final int PBS = 2;
+    public static final int CONDOR = 4;
+    public static final int CREAM = 4;
     
     private int[] seqCode = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+    private int type = 0;
     
     /**
      * Empty constructor which creates new instance of SeqCode with all values
@@ -23,8 +30,8 @@ public class SeqCode {
      * 
      * @param seqCodeString
      */
-    public SeqCode(String seqCodeString) {
-        getSeqCodeFromString(seqCodeString);
+    public SeqCode(int type,String seqCodeString) {
+       getSeqCodeFromString(type,seqCodeString);
     }
 
     /**
@@ -33,11 +40,15 @@ public class SeqCode {
      * @param part part of sequence number which will be increased
      */
     public void incrementSeqCode(int part) {
-        if (part <= -1 || part >= Sources.EDG_WLL_SOURCE_LB_SERVER) {
-            throw new IllegalArgumentException("SeqCode part");
-        }
-        
-        seqCode[part-1]++;
+       switch (type) {
+               case NORMAL:
+               case DUPLICATE:
+                       if (part <= -1 || part >= Sources.EDG_WLL_SOURCE_LB_SERVER)
+                               throw new IllegalArgumentException("SeqCode part");
+                               seqCode[part-1]++;
+                       break;
+               default: break;
+                }
     }
     
     /**
@@ -47,65 +58,79 @@ public class SeqCode {
      * UI=000000:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000:LBS=000000
      * @param seqCodeString
      */
-    public void getSeqCodeFromString(String seqCodeString) {
-        
-        if (!seqCodeString.matches("UI=\\d{1,}:NS=\\d{1,}:WM=\\d{1,}:BH=\\d{1,}:" +
-                "JSS=\\d{1,}:LM=\\d{1,}:LRMS=\\d{1,}:APP=\\d{1,}:LBS=\\d{1,}")) {
-            throw new IllegalArgumentException("this is not correct sequence code");
-        }
-        
-        int currentPosition = 0;
-        int equalsPosition = 0;
-        int colonPosition = 0;
-        for (int i = 0; i <= 8; i++) {
-            equalsPosition = seqCodeString.indexOf('=', currentPosition);
-            if (i == 8) {
-                colonPosition = seqCodeString.length();
-            } else {
-                colonPosition = seqCodeString.indexOf(':', currentPosition);
-            }
-            seqCode[i] = (new Integer(seqCodeString.substring(equalsPosition+1, colonPosition))).intValue();
-            currentPosition = colonPosition + 1;
-        }
-        
+    public void getSeqCodeFromString(int type,String seqCodeString) {
+       switch (type) {
+               case NORMAL:
+               case DUPLICATE:
+                       if (!seqCodeString.matches("UI=\\d{1,}:NS=\\d{1,}:WM=\\d{1,}:BH=\\d{1,}:" +
+                       "JSS=\\d{1,}:LM=\\d{1,}:LRMS=\\d{1,}:APP=\\d{1,}:LBS=\\d{1,}")) {
+                       throw new IllegalArgumentException("this is not correct sequence code");
+                       }
+                       
+                       int currentPosition = 0;
+                       int equalsPosition = 0;
+                       int colonPosition = 0;
+                       for (int i = 0; i <= 8; i++) {
+                               equalsPosition = seqCodeString.indexOf('=', currentPosition);
+                               if (i == 8) {
+                               colonPosition = seqCodeString.length();
+                               } else {
+                               colonPosition = seqCodeString.indexOf(':', currentPosition);
+                               }
+                               seqCode[i] = (new Integer(seqCodeString.substring(equalsPosition+1, colonPosition))).intValue();
+                               currentPosition = colonPosition + 1;
+                       }
+                       break;
+               case CREAM: break;
+               default: throw new IllegalArgumentException("unsupported seqcode type " + type);
+       }
+       this.type = type;
     }
     
     public String toString() {        
-        String tmp = Integer.toString(seqCode[0]);    
-        String output = "UI=";
-        output += "000000".substring(0, 6 - tmp.length ()) + tmp;
-        output += ":";
-        output += "NS=";
-        tmp = Integer.toString(seqCode[1]);
-        output += "0000000000".substring(0, 10 - tmp.length ()) + tmp;
-        output += ":";
-        output += "WM=";
-        tmp = Integer.toString(seqCode[2]);
-        output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
-        output += ":";
-        output += "BH=";
-        tmp = Integer.toString(seqCode[3]);
-        output += "0000000000".substring(0, 10 - tmp.length ()) + tmp;
-        output += ":";
-        output += "JSS=";
-        tmp = Integer.toString(seqCode[4]);
-        output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
-        output += ":";
-        output += "LM=";
-        tmp = Integer.toString(seqCode[5]);
-        output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
-        output += ":";
-        output += "LMRS=";
-        tmp = Integer.toString(seqCode[6]);
-        output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
-        output += ":";
-        output += "APP=";
-        tmp = Integer.toString(seqCode[7]);
-        output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
-        output += ":";
-        output += "LBS=";
-        tmp = Integer.toString(seqCode[8]);
-        output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
-        return output;
+       switch (type) {
+               case NORMAL:
+               case DUPLICATE:
+                       String tmp = Integer.toString(seqCode[0]);    
+                       String output = "UI=";
+                       output += "000000".substring(0, 6 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "NS=";
+                       tmp = Integer.toString(seqCode[1]);
+                       output += "0000000000".substring(0, 10 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "WM=";
+                       tmp = Integer.toString(seqCode[2]);
+                       output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "BH=";
+                       tmp = Integer.toString(seqCode[3]);
+                       output += "0000000000".substring(0, 10 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "JSS=";
+                       tmp = Integer.toString(seqCode[4]);
+                       output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "LM=";
+                       tmp = Integer.toString(seqCode[5]);
+                       output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "LMRS=";
+                       tmp = Integer.toString(seqCode[6]);
+                       output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "APP=";
+                       tmp = Integer.toString(seqCode[7]);
+                       output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
+                       output += ":";
+                       output += "LBS=";
+                       tmp = Integer.toString(seqCode[8]);
+                       output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
+                       return output;
+               case CREAM: 
+                       return "no_seqcodes_with_cream";
+               default:
+                       throw new IllegalArgumentException("unitialized seqcode");
+       }
     }
 }
index c4e7ba0..bcac17d 100644 (file)
@@ -1,5 +1,7 @@
 package org.glite.lb;
 
+/* FIXME: cleanup required */
+
 /**
  * Enum which represents type if sources.
  * 
@@ -16,14 +18,22 @@ public class Sources {
     public static final int EDG_WLL_SOURCE_LRMS = 7;
     public static final int EDG_WLL_SOURCE_APPLICATION = 8;
     public static final int EDG_WLL_SOURCE_LB_SERVER = 9;
+    public static final int EDG_WLL_SOURCE_CREAM_CORE = 10;
+    public static final int EDG_WLL_SOURCE_BLAH = 11;
     
     public int source;
     
     public Sources() {
        this.source = 0;
     }
+
+    public static void check(int source) {
+       if (source < 1 || source > 11) 
+               throw new IllegalArgumentException("lb.Source");
+    }
     
     public Sources(int source) {
+       check(source);
        this.source = source;
     }
 }
index f039a5e..71e7a58 100644 (file)
@@ -12,6 +12,7 @@
 #include "glite/lb/il_msg.h"
 #include "glite/lb/lb_plain_io.h"
 #include "glite/lb/context-int.h"
+#include "glite/lbu/log.h"
 
 #include "store.h"
 
@@ -92,6 +93,7 @@ int edg_wll_StoreProtoServer(edg_wll_Context ctx)
        else
 #endif
 
+       glite_common_log(LOG_CATEGORY_LB_SERVER_ACCESS, LOG_PRIORITY_DEBUG,buf);
        handle_il_message(ctx,buf);
        free(buf);