ContextDirect ctxd = new ContextDirect(srvpart[0],srvport);
ctxd.setCredentials(cred);
- ctxd.setSource(Sources.EDG_WLL_SOURCE_CREAM_CORE);
+ ctxd.setSource(new Sources(Sources.CREAM_CORE));
ctxd.setJobid(job);
ctxd.setSeqCode(new SeqCode(SeqCode.CREAM,"no_seqcodes_with_cream"));
System.out.println("JOBID="+job);
ContextIL ctx = new ContextIL(prefix,socket,lib);
- ctx.setSource(Sources.EDG_WLL_SOURCE_CREAM_CORE);
+ ctx.setSource(new Sources(Sources.CREAM_CORE));
ctx.setJobid(job);
- ctx.setSeqCode(new SeqCode(SeqCode.CREAM,"no_seqcodes_with_cream"));
+ ctx.setSeqCode(new SeqCode(SeqCode.CREAM,"no_seqcodes_with_cream_cheat_duplicate"));
ctx.setUser(ctxd.getUser());
/* 2nd registration with JDL, via IL */
Event e = new EventCREAMStart();
ctx.log(e);
+
+ EventCREAMStore store = new EventCREAMStore();
+ store.setResult(EventCREAMStore.Result.RESULT_START);
+ store.setCommand(EventCREAMStore.Command.COMMAND_CMDSTART);
+ ctx.log(store);
+
+ EventCREAMCall call = new EventCREAMCall();
+ call.setCallee(new Sources(Sources.LRMS));
+ call.setDestid("fake_Torque_ID");
+ call.setResult(EventCREAMCall.Result.RESULT_OK);
+ call.setCommand(EventCREAMCall.Command.COMMAND_CMDSTART);
+ ctx.log(call);
} catch (Exception e)
{
* SeqCode seqCode = new SeqCode();
* seqCode.getSeqCodeFromString("UI=000001:NS=0000000002:WM=000003:BH=0000000004:" +
* "JSS=000005:LM=000006:LRMS=000007:APP=000008:LBS=000009");
- * seqCode.incrementSeqCode(Sources.EDG_WLL_SOURCE_USER_INTERFACE);
+ * seqCode.incrementSeqCode(Sources.USER_INTERFACE);
* resulting sequence code will be
* UI=000002:NS=0000000002:WM=000003:BH=0000000004:JSS=000005:LM=000006:LRMS=000007:APP=000008:LBS=000009
*/
/* Source indicates source of the message, it is constant from org.glite.lb.client_java.Sources class
* and determines which part of sequence number will be increased.
- * Example: ctx.setSource(Sources.EDG_WLL_SOURCE_LRMS);
+ * Example: ctx.setSource(Sources.LRMS);
* In this case we have to use method which converts args[2] to Sources. In real environment it will
* not be used.
*/
/* Source indicates source of the message, it is constant from org.glite.lb.client_java.Sources class
* and determines which part of sequence number will be increased.
- * Example: ctx.setSource(Sources.EDG_WLL_SOURCE_LRMS);
+ * Example: ctx.setSource(Sources.LRMS);
* In this case we have to use method which converts args[2] to Sources. In real environment it will
* not be used.
*/
print E
qq{
package org.glite.lb;
-import org.glite.jobid.CheckedString;
import org.glite.jobid.Jobid;
public class Event$uc extends Event \{
my $cu = uc $_->{name};
print E
qq{
- case ${fnuu}_${cu}: out = "$cu";
+ case ${fnuu}_${cu}: out = "$cu"; break;
};
}
print E
*/
public abstract class Context {
- private int source;
+ private Sources source;
private int flag;
private String host;
private String user;
* or flag < 0 or source <=0 || >= 9
*
*/
- public Context(int source,
+ public Context(Sources src,
int flag,
String host,
String user,
String srcInstance,
Jobid jobid) {
- if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
+ if (src == null) {
throw new IllegalArgumentException("Context source");
}
throw new IllegalArgumentException("Context jobid");
}
- this.source = source;
+ this.source = src;
this.flag = flag;
this.host = host;
this.user = user;
}
/**
- * Converts Sources enum constants to defined string
- * @param sourceEnum Sources enum constant
- * @return String representation of Sources enum constants
- * @throws IllegalArgumentException if wrong source type is set
- */
- private String recognizeSource(int sourceEnum) {
- switch (sourceEnum) {
- case Sources.EDG_WLL_SOURCE_NONE: return "Undefined";
- case Sources.EDG_WLL_SOURCE_USER_INTERFACE: return "UserInterface";
- case Sources.EDG_WLL_SOURCE_NETWORK_SERVER: return "NetworkServer";
- case Sources.EDG_WLL_SOURCE_WORKLOAD_MANAGER: return "WorkloadManager";
- case Sources.EDG_WLL_SOURCE_BIG_HELPER: return "BigHelper";
- case Sources.EDG_WLL_SOURCE_JOB_SUBMISSION: return "JobController";
- case Sources.EDG_WLL_SOURCE_LOG_MONITOR: return "LogMonitor";
- 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");
- }
- }
-
- /**
* Abstract method which will serve as method for sending messages with events.
* @param event event for which will be created and send message
*/
throw new IllegalArgumentException("Context seqCode");
}
- Sources.check(source);
-
if (flag < 0) {
throw new IllegalArgumentException("Context flag");
}
" PROG=" + Escape.ulm(prog) +
" LVL=SYSTEM" +
" DG.PRIORITY=0" +
- " DG.SOURCE=\"" + recognizeSource(source) + "\"" +
+ " DG.SOURCE=\"" + source + "\"" +
" DG.SRC_INSTANCE=\"" + Escape.ulm(srcInstance) + "\"" +
" DG.EVNT=\"" + event.getEventType() + "\"" +
" DG.JOBID=\"" + jobid + "\"" +
* Gets source which represents which part of sequence code will be changed
* @return source
*/
- public int getSource() {
+ public Sources getSource() {
return source;
}
* @param source source
* @throws java.lang.IllegalArgumentException if source is null
*/
- public void setSource(int source) {
- Sources.check(source);
- this.source = source;
+ public void setSource(Sources src) {
+ this.source = src;
}
/**
* Creates new instance of ContextIL.
*/
public ContextIL() {
+ this.prefix = "/var/glite/log/dglogd.log";
}
public ContextIL(String prefix) {
* @param event event
* @throws java.lang.IllegalArgumentException if event, prefix or path
*/
- public void log(Event event) {
+ public void log(Event event) throws LBException {
if (event == null) {
throw new IllegalArgumentException("ContextIL event");
}
private Sources getSourceFromString(String from) {
if (from == null) throw new IllegalArgumentException("from cannot be null");
- Sources source = new Sources(Sources.EDG_WLL_SOURCE_NONE);
-
- if (from.equals(EventSource._UserInterface)) source = new Sources(Sources.EDG_WLL_SOURCE_USER_INTERFACE);
- else if (from.equals(EventSource._NetworkServer)) source = new Sources(Sources.EDG_WLL_SOURCE_NETWORK_SERVER);
- else if (from.equals(EventSource._WorkloadManager)) source = new Sources(Sources.EDG_WLL_SOURCE_WORKLOAD_MANAGER);
- else if (from.equals(EventSource._BigHelper)) source = new Sources(Sources.EDG_WLL_SOURCE_BIG_HELPER);
- else if (from.equals(EventSource._JobSubmission)) source = new Sources(Sources.EDG_WLL_SOURCE_JOB_SUBMISSION);
- else if (from.equals(EventSource._LogMonitor)) source = new Sources(Sources.EDG_WLL_SOURCE_LOG_MONITOR);
- else if (from.equals(EventSource._LRMS)) source = new Sources(Sources.EDG_WLL_SOURCE_LRMS);
- else if (from.equals(EventSource._Application)) source = new Sources(Sources.EDG_WLL_SOURCE_APPLICATION);
- else if (from.equals(EventSource._LBServer)) source = new Sources(Sources.EDG_WLL_SOURCE_LB_SERVER);
+ Sources source = new Sources(Sources.NONE);
+
+ if (from.equals(EventSource._UserInterface)) source = new Sources(Sources.USER_INTERFACE);
+ else if (from.equals(EventSource._NetworkServer)) source = new Sources(Sources.NETWORK_SERVER);
+ else if (from.equals(EventSource._WorkloadManager)) source = new Sources(Sources.WORKLOAD_MANAGER);
+ else if (from.equals(EventSource._BigHelper)) source = new Sources(Sources.BIG_HELPER);
+ else if (from.equals(EventSource._JobSubmission)) source = new Sources(Sources.JOB_SUBMISSION);
+ else if (from.equals(EventSource._LogMonitor)) source = new Sources(Sources.LOG_MONITOR);
+ else if (from.equals(EventSource._LRMS)) source = new Sources(Sources.LRMS);
+ else if (from.equals(EventSource._Application)) source = new Sources(Sources.APPLICATION);
+ else if (from.equals(EventSource._LBServer)) source = new Sources(Sources.LB_SERVER);
return source;
}
org.glite.wsdl.types.lb.EventAccepted wsdlEvent = event.getAccepted();
EventAccepted ev = new EventAccepted();
- Sources source = new Sources(Sources.EDG_WLL_SOURCE_NONE);
+ Sources source = new Sources(Sources.NONE);
if (wsdlEvent.getFrom() != null) {
source = getSourceFromString(wsdlEvent.getFrom().getValue());
}
if (wsdlEvent.getFrom() != null) {
ev.setFrom(getSourceFromString(wsdlEvent.getFrom().getValue()));
- } else ev.setFrom(new Sources(Sources.EDG_WLL_SOURCE_NONE));
+ } else ev.setFrom(new Sources(Sources.NONE));
if (wsdlEvent.getFromHost() != null) ev.setFromHost(wsdlEvent.getFromHost());
if (wsdlEvent.getFromInstance() != null) ev.setFromInstance(wsdlEvent.getFromInstance());
if (wsdlEvent.getReason() != null) ev.setReason(wsdlEvent.getReason());
if (wsdlEvent.getDestination() != null) {
ev.setDestination(getSourceFromString(wsdlEvent.getDestination().getValue()));
- } else ev.setDestination(new Sources(Sources.EDG_WLL_SOURCE_NONE));
+ } else ev.setDestination(new Sources(Sources.NONE));
if (wsdlEvent.getJob() != null) ev.setJob(wsdlEvent.getJob());
if (wsdlEvent.getReason() != null) ev.setReason(wsdlEvent.getReason());
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
* @param message message which will be written
* @param repeatWriteToFile count of attempts to write to file in case of failure
*/
- public static Long write(String prefix, String message, int repeatWriteToFile) {
+ public static Long write(String prefix, String message, int repeatWriteToFile) throws LBException {
FileWriter fileWriter = null;
- Long fileLength = null;
- RandomAccessFile raf = null;
+ long fileLength = 0;
FileLock fileLock = null;
File file;
for (int i = 0; i < repeatWriteToFile; i++) {
try {
file = new File(prefix);
- raf = new RandomAccessFile(file, "rw");
- FileChannel fileChannel = raf.getChannel();
+ FileOutputStream out = new FileOutputStream(file,true);
+ FileChannel fileChannel = out.getChannel();
fileLock = fileChannel.tryLock();
if (fileLock != null) {
if (!file.exists()) {
continue;
}
- fileLength = new Long(raf.length());
- fileWriter = new FileWriter(file, true);
- //true means append data at the end of file
-
- BufferedWriter bufferedFileWriter = new BufferedWriter(fileWriter);
-
- bufferedFileWriter.write(message);
- bufferedFileWriter.flush();
+ fileLength = file.length();
+ out.write(message.getBytes());
+ fileLock.release();
+ out.close();
if (file.exists()) {
break;
}
}
- } catch (FileNotFoundException ex) {
- System.err.println(ex);
- } catch (IOException ex) {
- System.err.println(ex);
- } catch (Exception ex) {
- System.err.println(ex);
- } finally {
+ } catch (Throwable ex) {
if (fileLock != null) {
try {
fileLock.release();
- } catch (IOException ex) {
- System.err.println(ex);
- }
- }
-
- try {
- raf.close();
- } catch (IOException ex) {
- System.err.println(ex);
- } catch (NullPointerException ex) {
- System.err.println(ex);
+ } catch (IOException ex2) { }
}
+ throw new LBException(ex);
}
}
- return fileLength;
+ return new Long(fileLength);
}
}
private int[] seqCode = {0, 0, 0, 0, 0, 0, 0, 0, 0};
private int type = 0;
+ private String cream_code;
/**
* Empty constructor which creates new instance of SeqCode with all values
*
* @param part part of sequence number which will be increased
*/
- public void incrementSeqCode(int part) {
+ public void incrementSeqCode(Sources src) {
+ int part = src.source;
switch (type) {
case NORMAL:
case DUPLICATE:
- if (part <= -1 || part >= Sources.EDG_WLL_SOURCE_LB_SERVER)
+ if (src == null)
throw new IllegalArgumentException("SeqCode part");
seqCode[part-1]++;
break;
currentPosition = colonPosition + 1;
}
break;
- case CREAM: break;
+ case CREAM:
+ cream_code = seqCodeString;
+ break;
default: throw new IllegalArgumentException("unsupported seqcode type " + type);
}
this.type = type;
output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
return output;
case CREAM:
- return "no_seqcodes_with_cream";
+ return cream_code;
default:
throw new IllegalArgumentException("unitialized seqcode");
}
* @author Pavel Piskac (173297@mail.muni.cz)
*/
public class Sources {
- public static final int EDG_WLL_SOURCE_NONE = 0; /* uninitialized value */
- public static final int EDG_WLL_SOURCE_USER_INTERFACE = 1;
- public static final int EDG_WLL_SOURCE_NETWORK_SERVER = 2;
- public static final int EDG_WLL_SOURCE_WORKLOAD_MANAGER = 3;
- public static final int EDG_WLL_SOURCE_BIG_HELPER = 4;
- public static final int EDG_WLL_SOURCE_JOB_SUBMISSION = 5;
- public static final int EDG_WLL_SOURCE_LOG_MONITOR = 6;
- 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 static final int NONE = 0; /* uninitialized value */
+ public static final int USER_INTERFACE = 1;
+ public static final int NETWORK_SERVER = 2;
+ public static final int WORKLOAD_MANAGER = 3;
+ public static final int BIG_HELPER = 4;
+ public static final int JOB_SUBMISSION = 5;
+ public static final int LOG_MONITOR = 6;
+ public static final int LRMS = 7;
+ public static final int APPLICATION = 8;
+ public static final int LB_SERVER = 9;
+ public static final int CREAM_CORE = 10;
+ public static final int BLAH = 11;
+
public int source;
+ private String[] names = {
+ "None",
+ "UserInterface",
+ "NetworkServer",
+ "WorkloadManager",
+ "BigHelper",
+ "JobSubmission",
+ "LogMonitor",
+ "LRMS",
+ "Application",
+ "LBServer",
+ "CREAMCore",
+ "BLAH",
+ };
public Sources() {
this.source = 0;
check(source);
this.source = source;
}
+
+ public String toString() {
+ return names[source];
+ }
}