Index: trunk/slurm_drmaa/job.c
===================================================================
--- trunk/slurm_drmaa/job.c	(revision 35)
+++ trunk/slurm_drmaa/job.c	(revision 1)
@@ -1,6 +1,6 @@
-/* $Id$ */
+/* $Id: job.c 351 2010-10-01 13:14:55Z mamonski $ */
 /*
  * PSNC DRMAA for SLURM
- * Copyright (C) 2011 Poznan Supercomputing and Networking Center
+ * Copyright (C) 2010 Poznan Supercomputing and Networking Center
  *
  *  This program is free software: you can redistribute it and/or modify
@@ -54,5 +54,4 @@
 					fsd_exc_raise_fmt(	FSD_ERRNO_INTERNAL_ERROR,"slurm_suspend error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id);
 				}
-				slurm_self->user_suspended = true;
 				break;
 			case DRMAA_CONTROL_HOLD:
@@ -62,5 +61,4 @@
 				job_desc.job_id = atoi(self->job_id);
 				job_desc.priority = 0;
-				job_desc.alloc_sid = 0;
 				if(slurm_update_job(&job_desc) == -1) {
 					fsd_exc_raise_fmt(	FSD_ERRNO_INTERNAL_ERROR,"slurm_update_job error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id);
@@ -71,5 +69,4 @@
 					fsd_exc_raise_fmt(	FSD_ERRNO_INTERNAL_ERROR,"slurm_resume error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id);
 				}
-				slurm_self->user_suspended = false;
 				break;
 			case DRMAA_CONTROL_RELEASE:
@@ -109,5 +106,4 @@
 {
 	job_info_msg_t *job_info = NULL;
-	slurmdrmaa_job_t * slurm_self = (slurmdrmaa_job_t *) self;
 	fsd_log_enter(( "({job_id=%s})", self->job_id ));
 
@@ -116,92 +112,93 @@
 	{
 		if ( slurm_load_job( &job_info, fsd_atoi(self->job_id), SHOW_ALL) ) {
-			int _slurm_errno = slurm_get_errno();
-
-			if (_slurm_errno == ESLURM_INVALID_JOB_ID) {
-				self->on_missing(self);
-			} else {
-				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"slurm_load_jobs error: %s,job_id: %s", slurm_strerror(slurm_get_errno()), self->job_id);
-			}
-		}
-		if (job_info) {
-			fsd_log_debug(("state = %d, state_reason = %d", job_info->job_array[0].job_state, job_info->job_array[0].state_reason));
-			
-			switch(job_info->job_array[0].job_state & JOB_STATE_BASE)
-			{
-
-				case JOB_PENDING:
-					switch(job_info->job_array[0].state_reason)
-					{
-						#if SLURM_VERSION_NUMBER >= SLURM_VERSION_NUM(2,2,0)
-						case WAIT_HELD_USER:   /* job is held by user */
-							fsd_log_debug(("interpreting as DRMAA_PS_USER_ON_HOLD"));
-							self->state = DRMAA_PS_USER_ON_HOLD;
-							break;
-						#endif
-						case WAIT_HELD:  /* job is held by administrator */
-							fsd_log_debug(("interpreting as DRMAA_PS_SYSTEM_ON_HOLD"));
-							self->state = DRMAA_PS_SYSTEM_ON_HOLD;
-							break;
-						default:
-							fsd_log_debug(("interpreting as DRMAA_PS_QUEUED_ACTIVE"));
-							self->state = DRMAA_PS_QUEUED_ACTIVE;
-					}
-					break;
-				case JOB_RUNNING:
-					fsd_log_debug(("interpreting as DRMAA_PS_RUNNING"));
-					self->state = DRMAA_PS_RUNNING;
-					break;
-				case JOB_SUSPENDED:
-					if(slurm_self->user_suspended == true) {
-						fsd_log_debug(("interpreting as DRMAA_PS_USER_SUSPENDED"));
-						self->state = DRMAA_PS_USER_SUSPENDED;
-					} else {
-						fsd_log_debug(("interpreting as DRMAA_PS_SYSTEM_SUSPENDED"));
-						self->state = DRMAA_PS_SYSTEM_SUSPENDED;
-					}
-					break;
-				case JOB_COMPLETE:
-					fsd_log_debug(("interpreting as DRMAA_PS_DONE"));
-					self->state = DRMAA_PS_DONE;
-					self->exit_status = job_info->job_array[0].exit_code;
-					fsd_log_debug(("exit_status = %d -> %d",self->exit_status, WEXITSTATUS(self->exit_status)));
-					break;
-				case JOB_CANCELLED:
-					fsd_log_debug(("interpreting as DRMAA_PS_FAILED (aborted)"));
-					self->state = DRMAA_PS_FAILED;
-					self->exit_status = -1;
-				case JOB_FAILED:
-				case JOB_TIMEOUT:
-				case JOB_NODE_FAIL:
-				#if SLURM_VERSION_NUMBER >= SLURM_VERSION_NUM(2,3,0)
-				case JOB_PREEMPTED:
-				#endif
-					fsd_log_debug(("interpreting as DRMAA_PS_FAILED"));
-					self->state = DRMAA_PS_FAILED;
-					self->exit_status = job_info->job_array[0].exit_code;
-					fsd_log_debug(("exit_status = %d -> %d",self->exit_status, WEXITSTATUS(self->exit_status)));
-					break;
-				default: /*unknown state */
-					fsd_log_error(("Unknown job state: %d. Please send bug report: http://apps.man.poznan.pl/trac/slurm-drmaa", job_info->job_array[0].job_state));
-			}
-
-			if (job_info->job_array[0].job_state & JOB_STATE_FLAGS & JOB_COMPLETING) {
-				fsd_log_debug(("Epilog completing"));
-			}
-
-			if (job_info->job_array[0].job_state & JOB_STATE_FLAGS & JOB_CONFIGURING) {
-				fsd_log_debug(("Nodes booting"));
-			}
-
-			if (self->exit_status == -1) /* input,output,error path failure etc*/
+			fsd_exc_raise_fmt(	FSD_ERRNO_INTERNAL_ERROR,"slurm_load_jobs error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id);
+        }
+		
+		self->exit_status = job_info->job_array[0].exit_code;
+		fsd_log_debug(("exit_status = %d -> %d",self->exit_status, WEXITSTATUS(self->exit_status)));
+
+		switch(job_info->job_array[0].job_state)
+		{
+			case JOB_PENDING:
+				switch(job_info->job_array[0].state_reason)
+				{
+					case WAIT_NO_REASON:
+					case WAIT_PRIORITY:
+					case WAIT_DEPENDENCY:
+					case WAIT_RESOURCES:
+					case WAIT_PART_NODE_LIMIT: 
+					case WAIT_PART_TIME_LIMIT: 
+					case WAIT_PART_STATE: 
+						self->state = DRMAA_PS_QUEUED_ACTIVE;
+						break;
+					case WAIT_HELD:
+						self->state = DRMAA_PS_USER_ON_HOLD;
+						break;
+					case WAIT_TIME:
+					case WAIT_LICENSES:
+					case WAIT_ASSOC_JOB_LIMIT:
+					case WAIT_ASSOC_RESOURCE_LIMIT: 
+					case WAIT_ASSOC_TIME_LIMIT:
+					case WAIT_RESERVATION: 
+					case WAIT_NODE_NOT_AVAIL:
+					case WAIT_TBD1:
+					case WAIT_TBD2:
+						self->state = DRMAA_PS_QUEUED_ACTIVE;
+						break;
+					case FAIL_DOWN_PARTITION:
+					case FAIL_DOWN_NODE:
+					case FAIL_BAD_CONSTRAINTS:
+					case FAIL_SYSTEM:
+					case FAIL_LAUNCH:
+					case FAIL_EXIT_CODE:
+					case FAIL_TIMEOUT:
+					case FAIL_INACTIVE_LIMIT:
+					case FAIL_BANK_ACCOUNT:
+						self->state = DRMAA_PS_FAILED;
+						break;
+					default:
+						fsd_log_error(("job_state_reason = %d, assert(0)",job_info->job_array[0].state_reason));
+						fsd_assert(false);
+	
+				}
+				break;
+			case JOB_RUNNING:
+				self->state = DRMAA_PS_RUNNING;
+				break;
+			case JOB_SUSPENDED:
+				self->state = DRMAA_PS_SYSTEM_SUSPENDED; /* assume SYSTEM - suspendig jobs is administrator only */
+				break;
+			case JOB_COMPLETE:
+				self->state = DRMAA_PS_DONE;
+				break;
+			case JOB_CANCELLED:
+				self->exit_status = -1;
+			case JOB_FAILED:
+			case JOB_TIMEOUT:
+			case JOB_NODE_FAIL:
 				self->state = DRMAA_PS_FAILED;
-
-			self->last_update_time = time(NULL);
-		
-			if( self->state >= DRMAA_PS_DONE ) {
-				fsd_log_debug(("exit_status = %d, WEXITSTATUS(exit_status) = %d", self->exit_status, WEXITSTATUS(self->exit_status)));
-				fsd_cond_broadcast( &self->status_cond );
-			}
-		}
+				break;
+			default: /*transient states */
+				if(job_info->job_array[0].job_state >= 0x8000) {
+					fsd_log_debug(("state COMPLETING"));
+				}
+				else if (job_info->job_array[0].job_state >= 0x4000) {
+					fsd_log_debug(("state Allocated nodes booting"));
+				}
+				else {
+					fsd_log_error(("job_state = %d, assert(0)",job_info->job_array[0].job_state));
+					fsd_assert(false);
+				}
+		}
+
+		if(self->exit_status == -1) /* input,output,error path failure etc*/
+			self->state = DRMAA_PS_FAILED;
+
+		fsd_log_debug(("state: %d ,state_reason: %d-> %s", job_info->job_array[0].job_state, job_info->job_array[0].state_reason, drmaa_job_ps_to_str(self->state)));
+
+		self->last_update_time = time(NULL);
+	
+		if( self->state >= DRMAA_PS_DONE )
+			fsd_cond_broadcast( &self->status_cond );
 	}
 	FINALLY
@@ -215,30 +212,4 @@
 	
 	fsd_log_return(( "" ));
-}
-
-static void
-slurmdrmaa_job_on_missing( fsd_job_t *self )
-{
-
-	fsd_log_enter(( "({job_id=%s})", self->job_id ));
-	fsd_log_warning(( "Job %s missing from DRM queue", self->job_id ));
-
-	fsd_log_info(( "job_on_missing: last job_ps: %s (0x%02x)", drmaa_job_ps_to_str(self->state), self->state));
-
-	if( self->state >= DRMAA_PS_RUNNING ) { /*if the job ever entered running state assume finished */
-		self->state = DRMAA_PS_DONE;
-		self->exit_status = 0;
-	}
-	else {
-		self->state = DRMAA_PS_FAILED; /* otherwise failed */
-		self->exit_status = -1;
-	}
-
-	fsd_log_info(("job_on_missing evaluation result: state=%d exit_status=%d", self->state, self->exit_status));
-
-	fsd_cond_broadcast( &self->status_cond);
-	fsd_cond_broadcast( &self->session->wait_condition );
-
-	fsd_log_return(( "; job_ps=%s, exit_status=%d", drmaa_job_ps_to_str(self->state), self->exit_status ));
 }
 
@@ -253,7 +224,6 @@
 	self->super.control = slurmdrmaa_job_control;
 	self->super.update_status = slurmdrmaa_job_update_status;
-	self->super.on_missing = slurmdrmaa_job_on_missing;
 	self->old_priority = UINT32_MAX;
-	self->user_suspended = true;
+
 	return (fsd_job_t*)self;
 }
@@ -422,24 +392,5 @@
 	}
 
-	/*  propagate all environment variables from submission host */
-	{
-		extern char **environ;
-		char **i;
-		unsigned j = 0;
-
-		for ( i = environ; *i; i++) {
-			job_desc->env_size++;
-		}
-		
-		fsd_log_debug(("environ env_size = %d",job_desc->env_size));
-		fsd_calloc(job_desc->environment, job_desc->env_size+1, char *);
-		
-		for ( i = environ; *i; i++,j++ ) {
-			job_desc->environment[j] = fsd_strdup(*i);
-		}
-	}
-
 	/* environment */
-	
 	vector = jt->get_v_attr( jt, DRMAA_V_ENV );
 	if( vector )
@@ -447,5 +398,4 @@
 		const char *const *i;
 		unsigned j = 0;
-		unsigned env_offset = job_desc->env_size;
 
 		for( i = vector;  *i;  i++ )
@@ -453,13 +403,13 @@
 			job_desc->env_size++;
 		}
-		fsd_log_debug(("jt env_size = %d",job_desc->env_size));
+		fsd_log_debug(("env_size = %d",job_desc->env_size));
 
 		fsd_log_debug(("# environment ="));
-		fsd_realloc(job_desc->environment, job_desc->env_size+1, char *);
+		fsd_calloc(job_desc->environment, job_desc->env_size+1, char *);
 
 		for( i = vector;  *i;  i++,j++ )
  		{
-			job_desc->environment[j + env_offset] = fsd_strdup(*i);
-			fsd_log_debug((" %s", job_desc->environment[j+ env_offset]));
+			job_desc->environment[j] = fsd_strdup(*i);
+			fsd_log_debug((" %s", job_desc->environment[j]));
 		}
 	 }
@@ -470,5 +420,5 @@
 	{
 		job_desc->time_limit = slurmdrmaa_datetime_parse( value );
-		fsd_log_debug(("# wct_hlimit = %s -> %ld",value, (long int)slurmdrmaa_datetime_parse( value )));
+		fsd_log_debug(("# wct_hlimit = %s -> %ld",value,slurmdrmaa_datetime_parse( value )));
 	}
 
@@ -571,11 +521,9 @@
 			/* only to one email address message may be send */
 			job_desc->mail_user = fsd_strdup(vector[0]);
-			job_desc->mail_type = MAIL_JOB_BEGIN | MAIL_JOB_END |  MAIL_JOB_FAIL;
 			fsd_log_debug(("# mail_user = %s\n",vector[0]));
-			fsd_log_debug(("# mail_type = %o\n",job_desc->mail_type));
 			if( vector[1] != NULL )
 			{
-				fsd_log_error(( "SLURM only supports one e-mail notification address" ));
-				fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"SLURM only supports one e-mail notification address");
+				fsd_log_error(( "LL only supports one e-mail notification address" ));
+				fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"LL only supports one e-mail notification address");
 			}
 		}
@@ -635,5 +583,12 @@
 	END_TRY			
 	
-	
+	/* native specification */
+	value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION );
+	if( value )
+	{
+		fsd_log_debug(("# Native specification: %s\n", value));
+		slurmdrmaa_parse_native(job_desc, value);
+	}
+		
 	/* job category */
 	value = jt->get_attr( jt, DRMAA_JOB_CATEGORY );
@@ -665,21 +620,6 @@
 	 	}
  	}
-
-    /* set defaults for constraints - ref: slurm.h */
-    fsd_log_debug(("# Setting defaults for tasks and processors" ));
-    job_desc->num_tasks = 1;
-    job_desc->min_cpus = 0;
-    job_desc->cpus_per_task = 0;
-    job_desc->pn_min_cpus = 0;
-
-	/* native specification */
-	value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION );
-	if( value )
-	{
-		fsd_log_debug(("# Native specification: %s\n", value));
-		slurmdrmaa_parse_native(job_desc, value);
-	}
-	
-}
-
-
+	
+}		
+		
+
