Esempio n. 1
0
char * normal_execution_bulk()
{
	char *reason;
	int  *job_ids;
	int  *ot_ids;
	int              deps[GW_JT_DEPS];
	int              rc;
	int              *exit_codes;
	gw_msg_job_t     job_status;
	int              array_id;
	int              i;
	int              num_of_tasks = 5;
	signed long      timeout = -1;
	    
	reason = malloc(sizeof(char)*200);
        
	if ( gw_session == NULL )
	{
		sprintf(reason,"Could not connect to gwd");
		return reason;	
	}
	
	deps[0]=-1;
	
	// Submit jobs
	if((rc = gw_client_array_submit("normal_execution.jt",num_of_tasks,GW_JOB_STATE_PENDING,&array_id,&job_ids,deps,0,1,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS)
	{
	     sprintf(reason,"[gw_client_array_submit] %s",gw_ret_code_string(rc));
	     return reason; 
	}   
	

	/*realloc(job_ids,sizeof(int)*num_of_tasks+1);
	job_ids[num_of_tasks] = -1;*/
	ot_ids=malloc(sizeof(int)*num_of_tasks+1);
	for(i=0;i<num_of_tasks;i++)
	    *(ot_ids+i)=*(job_ids+i);
	 ot_ids[num_of_tasks] = -1; 
		
	if((rc = gw_client_wait_set(ot_ids,&exit_codes,GW_FALSE,timeout)!=GW_RC_SUCCESS))
    {
	        sprintf(reason,"[gw_client_wait_set] %s",gw_ret_code_string(rc));
	        fflush(NULL); 
	        return reason; 	
	 }    	
	
	 for(i=0;i<num_of_tasks;i++)
	 {
	 	if(exit_codes[i]!=0)
	 	{
	      sprintf(reason,"Wrong exit code %d in task number %i",exit_codes[i],i);
	      return reason; 		
		}

		if((rc = gw_client_job_status(ot_ids[i], &job_status))!=GW_RC_SUCCESS)
		{
		     sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc));
		     return reason; 		
		}
		else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0)
			 {
		   	  	sprintf(reason,"Wrong job state %s for job %d",gw_job_state_string(job_status.job_state),i);
		     	return reason; 			
			 }
			 
		printf(" Task %d finished with code %d and state \"done\"\n",ot_ids[i],exit_codes[i]);

	 }
	
	sprintf(reason,"OK");

	return reason;	
	
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    int                job_id[MAX_JOBS_WAIT];
    int                i;
    int                number_of_jobs;
    int                array_id = -1;
    int                error = 0;
    char               opt;
    int                exit_code;
    int *              exit_codes;
    int                a = 0, A = 0, v = 0, k = 0;
    signed long        timeout = -1;
    gw_client_t *      gw_session;
    gw_boolean_t       any = GW_FALSE;

    struct sigaction   act;
    gw_return_code_t   rc;

    /* ---------------------------------------------------------------- */
    /* Parse arguments                                                  */
    /* ---------------------------------------------------------------- */

    opterr = 0;
    optind = 1;

    while((opt = getopt(argc,argv,":hkavt:A:"))!= -1)
        switch(opt)
        {
        case 'h':
            printf("%s", usage);
            exit(0);
            break;
        case 'v':
            v = 1;
            break;
        case 'a':
            a = 1;
            any = GW_TRUE;
            break;
        case 'A':
            A = 1;
            array_id = atoi(optarg);
            break;
        case 't':
            timeout = atoi(optarg);
            break;
        case 'k':
            k = 1;
            break;
        case '?':
            fprintf(stderr,"error: invalid option \'%c\'\n",optopt);
            printf("%s", susage);
            exit(1);
            break;
        case ':':
            fprintf(stderr,"error: must provide an argument for option \'%c\'\n",
                    optopt);
            printf("%s", susage);
            exit(1);
            break;
        }

    /* ---------------------------------------------------------------- */
    /* Connect to GWD                                                   */
    /* ---------------------------------------------------------------- */

    gw_session = gw_client_init();

    if ( gw_session == NULL )
    {
        fprintf(stderr,"Could not connect to gwd\n");
        return (-1);
    }

    act.sa_handler = signal_handler;
    act.sa_flags   = SA_RESTART;
    sigemptyset(&act.sa_mask);

    sigaction(SIGTERM||SIGINT,&act,NULL);

    /* ---------------------------------------------------------------- */
    /* Set job id array                                                 */
    /* ---------------------------------------------------------------- */

    if (!A)
    {
        if (optind < argc)
        {
            number_of_jobs = 0;
            while ( optind < argc )
            {
                job_id[number_of_jobs++] = atoi(argv[optind++]);

                if (number_of_jobs >= (MAX_JOBS_WAIT - 1) )
                {
                    fprintf(stderr,"FAILED: Max number of jobs reached\n");
                    error = 1;
                }
            }
            job_id[number_of_jobs] = -1;
        }
        else
        {
            printf("%s",susage);
            error = 1;
        }
    }
    else
    {
        rc = gw_client_job_status_all( );

        if (rc == GW_RC_SUCCESS)
        {
            number_of_jobs = 0;

            for (i=0; i<gw_client.number_of_jobs; i++)
                if (gw_client.job_pool[i] != NULL)
                    if (gw_client.job_pool[i]->array_id == array_id)
                    {
                        job_id[number_of_jobs++] = gw_client.job_pool[i]->id;
                        if (number_of_jobs>=(MAX_JOBS_WAIT - 1))
                        {
                            fprintf(stderr,"FAILED: Max number of jobs reached\n");
                            error = 1;
                        }
                    }

            job_id[number_of_jobs] = -1;

            if (number_of_jobs == 0)
            {
                fprintf(stderr,"FAILED: failed bad array id\n");
                error = 1;
            }
        }
        else
        {
            fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc));
            error = 1;
        }
    }

    if (error)
    {
        gw_client_finalize();
        return -1;
    }

    /* ---------------------------------------------------------------- */
    /* Wait for the jobs                                                */
    /* ---------------------------------------------------------------- */

    if ( number_of_jobs == 1 )
    {
        rc = gw_client_wait(job_id[0], &exit_code, timeout);

        if ( rc == GW_RC_SUCCESS )
        {
            if (v)
            {
                printf("%i\n",exit_code);
            }

            if (!k)
            {
                gw_client_job_signal(job_id[0],GW_CLIENT_SIGNAL_KILL,GW_FALSE);
            }
        }
    }
    else
    {
        rc = gw_client_wait_set(job_id,&exit_codes,any,timeout);

        if (rc == GW_RC_SUCCESS)
        {
            if (any)
            {
                if (v)
                {
                    printf("%i: %i\n",job_id[0],exit_codes[0]);
                }

                if (!k)
                {
                    gw_client_job_signal(job_id[0],GW_CLIENT_SIGNAL_KILL,GW_FALSE);
                }
            }
            else
            {
                for (i=0; i<number_of_jobs; i++)
                {
                    if (v)
                    {
                        printf("%-4i: %i\n",job_id[i],exit_codes[i]);
                    }

                    if (!k)
                    {
                        gw_client_job_signal(job_id[i],GW_CLIENT_SIGNAL_KILL,GW_FALSE);
                    }
                }
            }
        }

        free(exit_codes);
    }

    gw_client_finalize();

    if ( rc != GW_RC_SUCCESS)
    {
        fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc));
        return -1;
    }
    else
        return 0;
}
Esempio n. 3
0
char * epilog_fail_bulk()
{
	char *reason;
	int  *job_ids;
	int  *ot_ids;
	int              deps[GW_JT_DEPS];
	int              rc;
	int              *exit_codes;
	gw_msg_job_t     job_status;
	int              array_id;
	int              i;
	int              num_of_tasks = 5;
	signed long      timeout = -1;
	
	reason = malloc(sizeof(char)*200);
        
	if ( gw_session == NULL )
	{
		sprintf(reason,"Could not connect to gwd");
		return reason;	
	}
	
	deps[0]=-1;	
	
	// Submit jobs
	if((rc = gw_client_array_submit("epilog_output_nr.jt",num_of_tasks,GW_JOB_STATE_PENDING,&array_id,&job_ids,deps,0,1,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS)
	{
	     sprintf(reason,"[gw_client_array_submit] %s",gw_ret_code_string(rc));
	     return reason; 
	}   
	
	/*realloc(job_ids,sizeof(int)*num_of_tasks+1);
	job_ids[num_of_tasks] = -1;*/
	ot_ids=malloc(sizeof(int)*num_of_tasks+1);
	for(i=0;i<num_of_tasks;i++)
	    *(ot_ids+i)=*(job_ids+i);
	 ot_ids[num_of_tasks] = -1; 
	
		
	// Wait for the array (all of them)
	if((rc = gw_client_wait_set(ot_ids,&exit_codes,GW_FALSE,timeout))!=GW_RC_FAILED_JOB_FAIL)
	{
	     sprintf(reason,"[gw_client_wait_set] %s",gw_ret_code_string(rc));
	     fflush(NULL);
	     return reason; 	
	}
    	
	
	 for(i=0;i<num_of_tasks;i++)
	 {

		if((rc = gw_client_job_status(ot_ids[i], &job_status))!=GW_RC_SUCCESS)
		{
		     sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc));
		     return reason; 		
		}
	 
	    if(job_status.job_state==GW_JOB_STATE_FAILED)
			printf(" Task %d finished with state failed.\n",ot_ids[i]);
		else
		{
		     sprintf(reason,"Wrong job state for task %d (job state = %s)",ot_ids[i],gw_job_state_string(job_status.job_state));
		     return reason; 		
		}
	 }
	 
	unlink("doesnt_exist.txt");
	
	sprintf(reason,"OK");
	
	return reason;	
	
}