+++ /dev/null
-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;
- }
-
-}
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;
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);
this.bkserver = bkserver;
this.port = port;
- this.unique = (new CheckedString(unique)).toString();
+ this.unique = unique;
}
/**
this.bkserver = bkserverS;
this.port = portS.intValue();
- this.unique = (new CheckedString(uniqueS)).toString();
+ this.unique = uniqueS;
}
/**
throw new IllegalArgumentException("Jobid unique");
}
- this.unique = (new CheckedString(unique)).toString();
+ this.unique = unique;
}
/**
-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
--- /dev/null
+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();
+ }
+
+}
+
+
+
+}
};
}
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 {
}
print E
-
qq{ public String ulm() \{
return (" " +
};
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 + "\\"" +
};
}
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
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;
}
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");
}
}
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");
}
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;
prog = new String("edg-wms");
}
- this.prog = (new CheckedString(prog)).toString();
+ this.prog = prog;
}
/**
* @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;
}
srcInstance = new String("");
}
- this.srcInstance = new CheckedString(srcInstance).toString();
+ this.srcInstance = srcInstance;
}
/**
throw new IllegalArgumentException("Context user");
}
- this.user = (new CheckedString(user)).toString();
+ this.user = user;
}
}
--- /dev/null
+
+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);
+ }
+ }
+}
--- /dev/null
+package org.glite.lb;
+
+class Escape {
+ public static String ulm(String in) {
+ String out = in.replaceAll("\"", "\\\"");
+ out = out.replaceAll("\n", "\\\n");
+ return out;
+ }
+}
*
* @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
* @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();
* 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;
//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);
}
}
+ 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
*
}
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);
}
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;
+ }
}
public LBException(Throwable e) {
super(e);
}
+
+ public LBException(String s) {
+ super(s);
+ }
}
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");
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());
+ }
+
+
}
* @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
*
* @param seqCodeString
*/
- public SeqCode(String seqCodeString) {
- getSeqCodeFromString(seqCodeString);
+ public SeqCode(int type,String seqCodeString) {
+ getSeqCodeFromString(type,seqCodeString);
}
/**
* @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;
+ }
}
/**
* 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");
+ }
}
}
package org.glite.lb;
+/* FIXME: cleanup required */
+
/**
* Enum which represents type if 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;
}
}
#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"
else
#endif
+ glite_common_log(LOG_CATEGORY_LB_SERVER_ACCESS, LOG_PRIORITY_DEBUG,buf);
handle_il_message(ctx,buf);
free(buf);