basic state machine for VM
authorJiří Filipovič <fila@ics.muni.cz>
Mon, 2 Jul 2012 14:13:20 +0000 (14:13 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Mon, 2 Jul 2012 14:13:20 +0000 (14:13 +0000)
org.glite.lb.client/examples/job_status.c
org.glite.lb.client/src/EventAttrNames.pl
org.glite.lb.client/src/StatusAttrNames.pl
org.glite.lb.common/interface/jobstat.h.T
org.glite.lb.common/src/status.c.T
org.glite.lb.state-machine/src/intjobstat_supp.c
org.glite.lb.state-machine/src/process_event_virtual_machine.c
org.glite.lb.types/events.T
org.glite.lb.types/status.T

index 8a9f526..59f8413 100644 (file)
@@ -246,6 +246,9 @@ static void printstat(edg_wll_JobStat stat, int level)
                case EDG_WLL_STAT_FILE_TRANSFER_COLLECTION:
                        printf("%sjobtype : FILE_TRANSFER_COLLECTION\n", ind);
                         break;
+               case EDG_WLL_STAT_VIRTUAL_MACHINE:
+                       printf("%sjobtype : VIRTUAL_MACHINE\n", ind);
+                        break;
                default:
                        printf("%sjobtype : UNKNOWN\n", ind);
                        break;
@@ -377,7 +380,15 @@ static void printstat(edg_wll_JobStat stat, int level)
                printf("%sft_sandbox_type : UNKNOWN\n", ind);
        printf("%sft_src : %s\n", ind, stat.ft_src);
        printf("%sft_dest : %s\n", ind, stat.ft_dest);
-       
+
+       char *vm_stat_name = edg_wll_VMStatToString(stat.vm_state);
+       if (stat.jobtype == EDG_WLL_STAT_VIRTUAL_MACHINE){
+               printf("%svm_state : %s\n", ind, vm_stat_name);
+               printf("%svm_hostname : %s\n", ind, stat.vm_hostname);
+               printf("%svm_image : %s\n", ind, stat.vm_image);
+               printf("%svm_require : %s\n", ind, stat.vm_require);
+               printf("%svm_usage : %s\n", ind, stat.vm_usage);
+       }       
 
        printf("\n");   
        
index 9b24a03..7f5d7d4 100644 (file)
        NEWSTATE
        NEWSUBSTATE
        RESOURCES
+       IMAGE
+       REQUIRE
+       HOSTVM
 /;
index 413aefd..82c89e2 100644 (file)
        PAYLOAD_OWNER
        ACCESS_RIGHTS
        HISTORY
+       VM_HOSTNAME
+       VM_IMAGE
+       VM_MACHINE
+       VM_REQUIRE
+       VM_STATE
+       VM_USAGE
 /;
index 9220f75..dc4201e 100644 (file)
@@ -221,6 +221,12 @@ extern enum edg_wll_StatCream_state edg_wll_StringToCreamStat(const char *name);
  */
 extern char *edg_wll_CreamStatToString(enum edg_wll_StatCream_state);
 
+/**
+ * Convert numeric VM status code to string representation
+ */
+extern char *edg_wll_VMStatToString(enum edg_wll_StatVm_state);
+
+
 /** 
  * Extract a variable from the JDL attribute 
  */
index 3a59a82..82e1296 100644 (file)
@@ -259,6 +259,27 @@ char *edg_wll_CreamStatToString(enum edg_wll_StatCream_state statCode)
         return strdup(cream_statNames[statCode]);
 }
 
+static const char * const vm_statNames[] = {
+@@@{
+                my $f = selectField $status vm_state;
+                if ($f->{codes}) {
+                        for (@{$f->{codes}}) {
+                                my $lc = lc $_->{name};
+                                my $uc = ucfirst $lc;
+                                gen qq{
+!       "$uc",
+};
+                        }
+                }
+@@@}
+};
+
+
+char *edg_wll_VMStatToString(enum edg_wll_StatVm_state statCode)
+{
+        if ((int)statCode < 0 || statCode >= sizeof(vm_statNames)/sizeof(vm_statNames[0])) return (char *) NULL;
+        return strdup(vm_statNames[statCode]);
+}
 
 
 char *edg_wll_JDLField(edg_wll_JobStat *stat, const char *field_name)
index ff4fe62..6f01118 100644 (file)
@@ -575,6 +575,12 @@ char *enc_JobStat(char *old, edg_wll_JobStat* stat)
        if (ret) ret = enc_int(ret, stat->ft_sandbox_type);
        if (ret) ret = enc_string(ret, stat->ft_src);
        if (ret) ret = enc_string(ret, stat->ft_dest);
+       if (ret) ret = enc_int(ret, stat->vm_state);
+       if (ret) ret = enc_string(ret, stat->vm_image);
+       if (ret) ret = enc_string(ret, stat->vm_require);
+       if (ret) ret = enc_string(ret, stat->vm_usage);
+       if (ret) ret = enc_string(ret, stat->vm_hostname);
+       if (ret) ret = enc_string(ret, stat->vm_machine);
 
        return ret;
 }
@@ -682,7 +688,12 @@ edg_wll_JobStat* dec_JobStat(char *in, char **rest)
        if (tmp_in != NULL) stat->ft_sandbox_type = dec_int(tmp_in, &tmp_in);
        if (tmp_in != NULL) stat->ft_src = dec_string(tmp_in, &tmp_in);
        if (tmp_in != NULL) stat->ft_dest = dec_string(tmp_in, &tmp_in);
-       
+       if (tmp_in != NULL) stat->vm_state = dec_int(tmp_in, &tmp_in);
+       if (tmp_in != NULL) stat->vm_image = dec_string(tmp_in, &tmp_in);
+       if (tmp_in != NULL) stat->vm_require = dec_string(tmp_in, &tmp_in);
+       if (tmp_in != NULL) stat->vm_usage = dec_string(tmp_in, &tmp_in);
+       if (tmp_in != NULL) stat->vm_hostname = dec_string(tmp_in, &tmp_in);
+       if (tmp_in != NULL) stat->vm_machine = dec_string(tmp_in, &tmp_in);
 
        *rest = tmp_in;
 
index 02193c2..ced31f1 100644 (file)
@@ -64,19 +64,65 @@ int processEvent_VirtualMachine(intJobStat *js, edg_wll_Event *e, int ev_seq, in
        switch (e->any.type) {
                case EDG_WLL_EVENT_REGJOB:
                        if (USABLE(res)) {
-                               js->pub.state = EDG_WLL_JOB_SUBMITTED;
+                               js->pub.vm_state = EDG_WLL_STAT_VM_PENDING;
                        }
-                       /*if (USABLE_DATA(res)) {
-                               edg_wlc_JobIdFree(js->pub.parent_job);
-                               edg_wlc_JobIdDup(e->regJob.parent, &js->pub.parent_job);
-                       }*/
                        break;
+               case EDG_WLL_EVENT_VMCREATE:
+                       if (USABLE_DATA(res)) {
+                               rep_cond(js->pub.vm_require, e->vMCreate.require);
+                               rep_cond(js->pub.vm_image, e->vMCreate.image);
+                       }
+                       break;
+               case EDG_WLL_EVENT_VMHOST:
+                       if (USABLE_DATA(res)) {
+                               rep_cond(js->pub.vm_hostname, e->vMHost.hostvm);
+                               //XXX transfer to prolog/boot state?
+                       }
+                       break;
+               case EDG_WLL_EVENT_VMRUNNING:
+                       if (USABLE(res)) {
+                               js->pub.vm_state = EDG_WLL_STAT_VM_RUNNING;
+                       }
+                       break;
+               case EDG_WLL_EVENT_VMSHUTDOWN:
+                        if (USABLE(res)) {
+                                js->pub.vm_state = EDG_WLL_STAT_VM_SHUTDOWN;
+                        }
+                        break;
+               case EDG_WLL_EVENT_VMSTOP:
+                        if (USABLE(res)) {
+                                js->pub.vm_state = EDG_WLL_STAT_VM_STOPPED;
+                        }
+                        break;
+               case EDG_WLL_EVENT_VMRESUME:
+                        if (USABLE(res)) {
+                                js->pub.vm_state = EDG_WLL_STAT_VM_PENDING;
+                               //XXX clear hostname here?
+                        }
+                        break;
+               case EDG_WLL_EVENT_VMDONE:
+                        if (USABLE(res)) {
+                               switch (e->vMDone.status_code){
+                                       case EDG_WLL_VMDONE_OK:
+                                       case EDG_WLL_VMDONE_DELETE:
+                                               js->pub.vm_state = EDG_WLL_STAT_VM_DONE;
+                                               break;
+                                       case EDG_WLL_VMDONE_FAILURE:
+                                               js->pub.vm_state = EDG_WLL_STAT_VM_FAILURE;
+                                               break;
+                                       case EDG_WLL_VMDONE_STATUS_CODE_UNDEFINED:
+                                               break;
+                               }
+                               if (USABLE_DATA(res))
+                                       rep_cond(js->pub.vm_usage, e->vMDone.usage);
+                        }
+                        break;
                default:
                        break;
        }
 
        if (USABLE(res)) {
-               rep(js->last_seqcode, e->any.seqcode);
+               //rep(js->last_seqcode, e->any.seqcode);
 
                js->pub.lastUpdateTime = e->any.timestamp;
                if (old_state != js->pub.state) {
@@ -85,8 +131,7 @@ int processEvent_VirtualMachine(intJobStat *js, edg_wll_Event *e, int ev_seq, in
                                = (int)js->pub.lastUpdateTime.tv_sec;
                }
        }
-       if (! js->pub.location) js->pub.location = strdup("this is FILE TRANSFER");
-
+       if (! js->pub.location) js->pub.location = strdup("this is VIRTUAL MACHINE");
 
        return RET_OK;
 }
index 2c99a09..abad712 100644 (file)
 @flesh VirtualMachine
 
 @type VMCreate                 create (register) virtual machine
-       string name             machine name
+       string image            machine image
+       string require          machine requirements
+
+@type VMHost
+       string hostvm           hostname of VM
+
+@type VMRunning                        VM is running
+
+@type VMShutdown
+
+@type VMStop
+
+@type VMResume
+
+@type VMDone
+       int     status_code
+       _code_  OK
+       _code_  DELETE
+       _code_  FAILURE
+       string  usage   
+       _optional_
 
-@type VMRunning                        machine running
index cc01f60..e93b31a 100644 (file)
@@ -183,6 +183,23 @@ string     ft_dest                 File transfer destination
 
 _pad_  20
 
+int    vm_state                VM job state
+       _null_  -1
+       _code_  VM_PENDING      pending
+       _code_  VM_BOOT         boot
+       _code_  VM_RUNNING      running
+       _code_  VM_SHUTDOWN     shutdown
+       _code_  VM_STOPPED      stopped
+       _code_  VM_DONE         done
+       _code_  VM_FAILURE      failure
+string vm_image                VM image
+string vm_require              VM requirement on physical machine
+string vm_usage                VM usage
+string vm_hostname             VM hostname
+string vm_machine              physical machine on which VM runs
+
+_pad_  20
+
 @type Submitted                Entered by the user to the User Interface or registered by Job Partitioner.
 @type Waiting          Accepted by WMS, waiting for resource allocation.
 @type Ready            Matching resources found.