[GE dev] JGDI Events

andre Andre.Alefeld at sun.com
Wed Jun 17 14:29:12 BST 2009


Hi,

maybe this small example might be useful, I guess the problem is that 
the job is already gone in some cases but you should get the right job 
with the event already.

Andre

-------------------------------------------------
package com.sun.grid.jgdi.examples;

import com.sun.grid.jgdi.EventClient;
import com.sun.grid.jgdi.JGDI;
import com.sun.grid.jgdi.JGDIException;
import com.sun.grid.jgdi.JGDIFactory;
import com.sun.grid.jgdi.configuration.JobTask;
import com.sun.grid.jgdi.event.Event;
import com.sun.grid.jgdi.event.EventListener;
import com.sun.grid.jgdi.event.EventTypeEnum;
import com.sun.grid.jgdi.event.JobFinalUsageEvent;

import com.sun.grid.jgdi.EventClient;
import com.sun.grid.jgdi.JGDI;
import com.sun.grid.jgdi.JGDIException;
import com.sun.grid.jgdi.JGDIFactory;
import com.sun.grid.jgdi.configuration.JobTask;
import com.sun.grid.jgdi.event.Event;
import com.sun.grid.jgdi.event.EventListener;
import com.sun.grid.jgdi.event.EventTypeEnum;
import com.sun.grid.jgdi.event.JobFinalUsageEvent;
import com.sun.grid.jgdi.event.JobTaskAddEvent;
import com.sun.grid.jgdi.event.JobTaskDelEvent;
import com.sun.grid.jgdi.event.JobTaskModEvent;
import com.sun.grid.jgdi.event.JobUsageEvent;
import java.util.Map;

/**
 * Simple example which demonstrates how to receive events from the
 * Sun™ Grid Engine
 *
 */
public class JobEventExample {

    public static void main(String[] args) {

        try {

            String url = "bootstrap:///opt/sge@default:1026";

            if (args.length == 1) {
                url = args[0];
            }

            JGDI jgdi = JGDIFactory.newInstance(url);

            try {
                System.out.println("Successfully connected to " + url);

                EventClient evc = JGDIFactory.createEventClient(url, 0);

                evc.subscribe(EventTypeEnum.JobAdd);
                evc.subscribe(EventTypeEnum.JobMod);
                evc.subscribe(EventTypeEnum.JobDel);
                evc.subscribe(EventTypeEnum.JobTaskAdd);
                evc.subscribe(EventTypeEnum.JobTaskMod);
                evc.subscribe(EventTypeEnum.JobTaskDel);
                evc.subscribe(EventTypeEnum.JobFinalUsage);
                evc.subscribe(EventTypeEnum.JobUsage);

                evc.commit();

                evc.addEventListener(new EventListener() {

                    public void eventOccured(Event evt) {
                        System.out.println("got event " + evt);
                        if (evt instanceof JobUsageEvent) {
                            JobUsageEvent uevt = (JobUsageEvent) evt;
                            System.out.println("jobId.taskId: " + 
uevt.getJobId() + "." + uevt.getTaskId());
                            for (Map.Entry<String, Double> entry : 
uevt.getUsage().entrySet()) {
                                System.out.println(entry.getKey() + " : 
" + entry.getValue());
                            }
                        }
                        if (evt instanceof JobTaskAddEvent) {
                            System.out.println("JobTaskAdd");
                            JobTaskAddEvent jtm = (JobTaskAddEvent)evt;
                            JobTask jt = jtm.get();
                            System.out.println("getState(): " + 
jt.getState());
                            System.out.println("getStatus(): " + 
jt.getStatus());
                        }
                        if (evt instanceof JobTaskDelEvent) {
                            System.out.println("JobTaskDel");
                        }
                        if (evt instanceof JobTaskModEvent) {
                            System.out.println("JobTaskMod");
                            JobTaskModEvent jtm = (JobTaskModEvent)evt;
                            JobTask jt = jtm.get();
                            System.out.println("getState(): " + 
jt.getState());
                            System.out.println("getStatus(): " + 
jt.getStatus());
                        }
                        if (evt instanceof JobFinalUsageEvent) {
                            System.out.println("JobFinalUsageEvent");
                            JobFinalUsageEvent juevt = 
(JobFinalUsageEvent) evt;
                            System.out.println("jobId.taskId: " + 
juevt.getJobId() + "." + juevt.getTaskId());
                            for (Map.Entry<String, Double> entry : 
juevt.getUsage().entrySet()) {
                                System.out.println(entry.getKey() + " : 
" + entry.getValue());
                            }
                            System.out.println("exit status: " + 
juevt.getLoadValue("exit_status"));
                        }

                    }
                });


                try {
                    Thread.sleep(600000);
                } finally {
                    evc.close();
                }
            } finally {
                jgdi.close();
            }
        } catch (JGDIException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

ppetosy wrote:
> Hi 
>
> I am using JGDI API to get events from SGE about job status changes.I have successfully subscribed for EventTypeEnum.JobFinish and EventTypeEnum.JobMod events and I do get the events. When I get these events I have two problems
>  1. My JobModEvent listener gets the jobId of modified job, but I am not able to get the status of modified job ( is it running or queued or suspended, etc. ). 
>  2. With JobFinishLister I get the Id of the job. For this I need to get exit status of the executed job. I am doing following for getting the status
> a) I call getJob(jobId) method of class com.sun.grid.jgdi.JGDI
> b) I get first task of the job by calling com.sun.grid.jgdi.configuration.JobTask jt = job.getJaTasks(0);
> c) Then I call jt.getUsage("exit_status") method and successfully get the status
>
> BUT The problem is when I submit multiple jobs ( hundreds of jobs ), randomly I get NULL when calling getJob(jobId) ( see (a) ). 
>
> What can be possible reason of this problems and how can I get the info which I want ? 
>
>
> Thanks in advance.
>
> ------------------------------------------------------
> http://gridengine.sunsource.net/ds/viewMessage.do?dsForumId=39&dsMessageId=201453
>
> To unsubscribe from this discussion, e-mail: [dev-unsubscribe at gridengine.sunsource.net].
>   

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Andre Alefeld                Phone: ++49 (0)941 3075-255
Software Engineering         Fax:   ++49 (0)941 3075-222
Sun Microsystems GmbH
Dr.-Leo-Ritter-Str. 7	     mailto: andre.alefeld at sun.com
D-93049 Regensburg           http://www.sun.com/gridware

------------------------------------------------------
http://gridengine.sunsource.net/ds/viewMessage.do?dsForumId=39&dsMessageId=202105

To unsubscribe from this discussion, e-mail: [dev-unsubscribe at gridengine.sunsource.net].



More information about the gridengine-users mailing list