/**
@details
-# Find target job.  Return error if target job not found.
-# Find depends job.  Return error if depends job not found.
-# Return an error if both jobs are on the same thread.
-# The depend passed all checks, add the depends job to the target job dependency list
*/
int Trick::Executive::add_depends_on_job( std::string target_job_string , unsigned int t_instance , 
                                          std::string depend_job_string , unsigned int d_instance ) {

    Trick::JobData * target_job ;
    Trick::JobData * depend_job ;
    
    /* Find target job.  Return error if target job not found. */
    target_job = get_job(target_job_string, t_instance) ;
    if ( target_job == NULL ) {
        message_publish(MSG_ERROR, "add_depends_on_job: Could not find target job %s instance %d\n",
         target_job_string.c_str(), t_instance) ; 
        return(-1) ;
    }

    /* Find depends job.  Return error if depends job not found. */
    depend_job = get_job(depend_job_string, d_instance) ;
    if ( depend_job == NULL ) {
        message_publish(MSG_ERROR, "add_depends_on_job: Could not find depend job %s instance %d\n",
         depend_job_string.c_str(), d_instance) ; 
        return(-2) ;
    }

    /* Return an error if both jobs are on the same thread */
    if( target_job->thread == depend_job->thread) {
        message_publish(MSG_ERROR, "add_depends_on_job: target job %s and depend job %s on the same thread", 
         target_job_string.c_str() , depend_job_string.c_str()) ;  ; 
        return(-3) ;
    }

    /* Passed all checks, add the depends job to the target job dependency list */
    target_job->add_depend(depend_job) ;
    
    return(0) ;

}
Exemple #2
0
int main() {
    LIST *jlist = init_list();

    assert(gen_job_id(jlist) == 1);
    assert(get_fg(jlist) == (job *)NULL);
    assert(jlist->size == 0);

    //print_bg(jlist);
    
    job *jb1 = tstjob(1);
    push(jlist, JOB, jb1);
    assert(gen_job_id(jlist) == 2);
    assert(get_fg(jlist) == jb1);

    //print_bg(jlist);

    job *jb2 = tstjob(3);
    push(jlist, JOB, jb2);
    assert(gen_job_id(jlist) == 2);

    job *jb3 = tstjob(2);
    push(jlist, JOB, jb3);
    assert(gen_job_id(jlist) == 4);

    push(jlist, JOB, tstjob(7));
    assert(gen_job_id(jlist) == 4);

    print_bg(jlist);

    pop(jlist);
    assert(gen_job_id(jlist) == 4);

    assert(get_job_pgid(jlist, 11) == (job *)NULL);
    assert(get_job_pgid(jlist, 7) == jb2);
    assert(get_job_pgid(jlist, 3) == jb3);
    assert(get_job(jlist, 3) == jb2);
    assert(del_job(jlist, 7) == jb2);
    assert(get_job(jlist, 3) == (job *)NULL);
    assert(get_job(jlist, 55) == jb3);
    assert(get_job(jlist, 10) == (job *)NULL);
    assert(set_complete(jb2, 3) == 0);
    assert(set_complete(jb2, 4) == -1);
    assert(set_complete(jb3, 55) == 0);
    assert(((process *)jb2->pid_list->head->node_ptr)->complete == 0);
    assert(jb2->complete == 0);
    assert(jb3->complete == 1);
    assert(jlist->size == 2);
    assert(get_job_jid(jlist, 1) == jb1);
    assert(get_job_jid(jlist, 11) == (job *)NULL);

    printf("[job_handler_tst] All tests pass!\n");
    return 0;
}
Exemple #3
0
static void
assign_job(struct scan_peer *peer)
{
	size_t job_len;
	uint16_t net_job_len;

	peer->job = clients_started ? get_job() : NULL;
	if (peer->job == NULL) {
		LIST_INSERT_HEAD(&inactive_peers, peer, peer_link);
		if (LIST_EMPTY(&active_peers) && clients_started)
			shutdown_master();
		return;
	}

	LIST_INSERT_HEAD(&active_peers, peer, peer_link);

	peer->job->scan_output = NULL;

	job_len = strlen(peer->job->pkg_location);
	if (job_len > 0xffff)
		errx(1, "Location inside pkgsrc tree too long");
	net_job_len = htons(job_len);
	(void)memcpy(peer->tmp_buf, &net_job_len, 2);

	deferred_write(peer->fd, peer->tmp_buf, 2, peer, send_job_path,
	    kill_peer);
}
Exemple #4
0
int builtin_fg(cmd_t* cmd, job_list_t* jobs) {
  int index = -1;
  job_t* curr_job;
  if (cmd->args[1]) {
    // Get job specified.
    index = (int) strtol(cmd->args[1], NULL, 10);
    curr_job = get_job_by_index(jobs, index);
  } else {
    // Otherwise get latest job.
    curr_job = get_latest_job(jobs);
  }

  if (curr_job) {
    // Wait for process to complete synchronously.
    int exit_code = waitfor(curr_job->pid, jobs, 0);

    // Extract completed job from job list.
    get_job(jobs, curr_job->pid);

    return exit_code;
  } else {
    if (index > 0) {
      fprintf(stderr, "fg: job not found: %d\n", index);
    } else {
      fprintf(stderr, "fg: no current job\n");
    }
    return 1;
  }
}
Exemple #5
0
/**
 * gstreamill_get_job:
 * @uri: (in): access uri, e.g. /live/test/encoder/0
 *
 * Get the Job by access uri.
 *
 * Returns: job
 */
Job *gstreamill_get_job (Gstreamill *gstreamill, gchar *uri)
{
        Job *job = NULL;
        GRegex *regex;
        GMatchInfo *match_info;
        gchar *name = NULL;

        regex = g_regex_new ("^/(live|dvr)/(?<name>[^/]*)/.*", G_REGEX_OPTIMIZE, 0, NULL);
        match_info = NULL;
        g_regex_match (regex, uri, 0, &match_info);
        g_regex_unref (regex);
        if (g_match_info_matches (match_info)) {
                name = g_match_info_fetch_named (match_info, "name");
        }

        if (name != NULL) {
                job = get_job (gstreamill, name);
                g_free (name);
        }
        if (match_info != NULL) {
                g_match_info_free (match_info);
        }

        return job;
}
Exemple #6
0
int Trick::SimObject::add_tag_to_job( std::string job_tag , std::string job_name ) {
    Trick::JobData * jd ;
    if ( (jd = get_job(name + "." + job_name)) != NULL ) {
        return jd->add_tag(job_tag) ;
    }
    return -1 ;

}
Exemple #7
0
int Trick::Executive::get_freeze_job(std::string sim_object_name) {
    freeze_job = get_job(sim_object_name + ".sched_freeze_to_exec_command") ;
    if ( freeze_job == NULL ) {
        exec_terminate_with_return(-1 , __FILE__ , __LINE__ , "Executive could not find freeze job" ) ;
    } else {
        freeze_job->next_tics = TRICK_MAX_LONG_LONG ;
    }

    return 0 ;
}
Exemple #8
0
static void
standalone_mode(void)
{
	struct scan_job *job;

	while ((job = get_job()) != NULL) {
		job->scan_output = scan_pkglocation(job->pkg_location);
		process_job(job, JOB_DONE);
	}
}
static unsigned int
is_job_done (pid_t pid, unsigned int print, unsigned int details)
{
    int status;
    int idx = index_of (pid);
    job *j = get_job (idx);
    const char l = (j == list->tail) ? '+' : '-';
    pid_t p = waitpid (pid, &status, WNOHANG|WUNTRACED);
    if (p == -1)
    {
        warn ("jobs [%d] %d (%s)", j->content->job,
                                   j->content->pid,
                                   j->content->cmd);
        remove_job (idx);
        return TRUE;
    }
    if (j == NULL)
    {
        fprintf (stderr, "'%d': no such job\n", pid);
        return TRUE;
    }
    if (j->content->stopped && print)
    {
        if (details)
        {
            int i;
            fprintf (stdout, "[%d]  %c %d suspended: %s",
                             j->content->job,
                             l,
                             pid,
                             j->content->cmd);
            for (i = 0; i < j->content->argc; i++)
            {
                char q;
                switch (j->content->protected[i])
                {
                    case NONE: q = '\0'; break;
                    case DOUBLE_QUOTE: q = '"'; break;
                    case SINGLE_QUOTE: q = '\'';
                }
                fprintf (stdout, " %c%s%c", q, j->content->argv[i], q);
            }
            fprintf (stdout, "\n");
        }
        else
        {
            fprintf (stdout, "[%d]  %c %d (%s) suspended\n",
                             j->content->job,
                             l,
                             pid,
                             j->content->cmd);
        }
        /* well, it's a lie but we don't want to print it twice */
        return TRUE;
    }
Exemple #10
0
/**
 * gstreamill_job_stop:
 * @name: (in): job name to be stoped
 *
 * Returns: plain text.
 */
gchar * gstreamill_job_stop (Gstreamill *gstreamill, gchar *name)
{
        Job *job;

        job = get_job (gstreamill, name);
        if (job != NULL) {
                stop_job (job, SIGUSR2);
                return g_strdup ("ok");

        } else {
                return g_strdup ("job not found");
        }
}
Exemple #11
0
/**
 * gstreamill_job_stop:
 * @name: (in): job name to be stoped
 *
 * Returns: plain text.
 */
gchar * gstreamill_job_stop (Gstreamill *gstreamill, gchar *name)
{
        Job *job;

        job = get_job (gstreamill, name);
        if (job != NULL) {
                stop_job (job, SIGTERM);
                return g_strdup_printf ("{\n    \"name\": \"%s\",\n    \"result\": \"success\"\n}", name);

        } else {
                return g_strdup ("{\n    \"result\": \"failure\",\n    \"reason\": \"job not found\"\n}");
        }
}
double Trick::Executive::get_job_cycle(std::string job_name) {

    Trick::JobData * job = NULL ;

    if ( job_name.empty() ) {
        return(get_curr_job()->cycle) ;
    } else {
        if ( (job = get_job(job_name)) != NULL ) {
            return(job->cycle) ;
        }
    }

    return(0.0) ;

}
Exemple #13
0
void* vina_worker(void* arg)
{
    struct para* work_para = (struct para*)arg;
    char work_path[MAX_PATH];
    int my_job;
    while ((my_job = get_job(work_para->jp, work_para->t)) != NO_JOB) {
        get_workpath(work_para->home_path, my_job, work_path);
        setup(work_para->cf, work_para->home_path, my_job, work_para->t);
        do_job(my_job, work_para->t, work_path);
        cleanup(work_path, work_para->cf->gather_loc, work_para->t, work_para->cf->outfile, my_job);
    }
    printf("Done!");
    free(work_para);
    return NULL;
}
Exemple #14
0
void *main_tsp(void *arg){
    unsigned long long perf;
    struct timespec t1, t2;
    uint64_t vpres=0;
	long long int myCuts = 0;

    clock_gettime (CLOCK_REALTIME, &t1);

    /* calculer chacun des travaux */
    tsp_path_t solution;
    memset (solution, -1, MAX_TOWNS * sizeof (int));
    solution[0] = 0;
	pthread_mutex_lock(&q_mutex);
    while (!empty_queue (&q, &q_mutex)) {
        int hops = 0, len = 0;
        get_job (&q, solution, &hops, &len, &vpres, &q_mutex);
		pthread_mutex_unlock(&q_mutex);

		//printf("Thread %ld\n", syscall(SYS_gettid));
	
	// le noeud est moins bon que la solution courante
	if (minimum < INT_MAX
	    && (nb_towns - hops) > 10
	    && ( (lower_bound_using_hk(solution, hops, len, vpres)) >= minimum 
		|| (lower_bound_using_lp(solution, hops, len, vpres)) >= minimum)){

		pthread_mutex_lock(&q_mutex);
		continue;
	}

	tsp (hops, len, vpres, solution, &myCuts, sol, &sol_len);
	pthread_mutex_lock(&q_mutex);
    }
	pthread_mutex_unlock(&q_mutex);

	/* update cuts */
	pthread_mutex_lock(&cuts_mutex);
	cuts += myCuts;
	pthread_mutex_unlock(&cuts_mutex);

    clock_gettime (CLOCK_REALTIME, &t2);
    perf = TIME_DIFF (t1,t2);
	printf("Son thread %ld finished after %lld.%03lld ms\n\n", syscall(SYS_gettid), perf/1000000ll, perf%1000000ll);
    
    return 0 ;

}
void* dispatch_job () {

	struct job *job;

	while(1) {
		pthread_mutex_lock(&mutex);
		job = get_job();
		pthread_mutex_unlock(&mutex);

		if (job) {
			do_job(job);
			free(job);
		}
		else {
			pthread_exit(NULL);
		}
	}
}
void * tsp_worker(void * args) {
    WorkerArgs * a = (WorkerArgs*) args;
    long long int cuts;
    while (!empty_queue(a->q)) {
        int hops = 0, len = 0;
        cuts = 0;
        pthread_mutex_lock(&mutex_queue);
        get_job(a->q, a->solution, &hops, &len); 
        pthread_mutex_unlock(&mutex_queue);
        
        tsp(hops, len, a->solution, &cuts, a->sol, a->sol_len);
       
        pthread_mutex_lock(&mutex_cuts);
        *(a->cuts) += cuts; 
        pthread_mutex_unlock(&mutex_cuts);
    }
    free(args);
    return (void*)42;
}
Exemple #17
0
static void
assign_job(void *arg)
{
	struct build_peer *peer = arg;
	size_t build_info_len;
	uint32_t net_build_info_len;

	if (peer->tmp_buf[0] == 'S') {
		send_build_stats(peer);
		return;
	}

	if (peer->tmp_buf[0] != 'G') {
		kill_peer(peer);
		return;
	}

	LIST_REMOVE(peer, peer_link);

	peer->job = get_job();
	if (peer->job == NULL) {
		LIST_INSERT_HEAD(&unassigned_peers, peer, peer_link);
		if (LIST_EMPTY(&active_peers))
			event_loopexit(NULL);
		return;
	}

	LIST_INSERT_HEAD(&active_peers, peer, peer_link);

	build_info_len = peer->job->end - peer->job->begin;
	if (build_info_len > 0xffffff)
		errx(1, "Build info too long");

	net_build_info_len = htonl(build_info_len);
	(void)memcpy(peer->tmp_buf, &net_build_info_len, 4);

	deferred_write(peer->fd, peer->tmp_buf, 4, peer, send_build_info,
	    kill_peer);

	peer = LIST_FIRST(&unassigned_peers);
	if (peer != NULL)
		assign_job(peer);
}
Exemple #18
0
void * tfn7(void * arg)
{
    int count;
    Job task = (struct job *)malloc(sizeof(struct job));
    task->next = NULL;
    task->val = 0;
    task->tid = -1;
    pthread_t tid = pthread_self();
    count = 0;
    while (count < MAX_ITEM) {
        if (pthread_mutex_trylock(&q_lock) == 0) {
            get_job(arg, task, &count, tid);
            pthread_mutex_unlock(&q_lock);
        }
    }
    print(task);
    if (free_job(task) == -1) {
        exit(1);
    }
    return (void *)0;
}
void * tfn7(void * arg)
{
    int count; /* 每次取得链表结点数 */
    struct job * task = NULL; /* 属于当前线程的任务结点的队列头 */
    pthread_t tid;

    tid = pthread_self(); /* 得到当前线程ID,根据此线程ID判断任务是否归属于当前线程 */

    count = 0;
    while(count < MAX_ITEM)
        if(pthread_mutex_trylock(&q_lock) == 0) { /* 将队列加锁 */
            get_job((Job) arg, task, &count);
            pthread_mutex_unlock(&q_lock); /* 遍历链表结束,释放锁 */
        }

    print((Job) arg);

    if(free_job(task) == -1)
        exit(1);

    return (void *)0;
}
Exemple #20
0
int main(int argc, char *argv[])
{
	log_options_t opts = LOG_OPTS_STDERR_ONLY;
	node_info_msg_t *node_info_ptr = NULL;
	node_info_msg_t *new_node_ptr = NULL;
	int error_code;
	int height = 40;
	int width = 100;
	int startx = 0;
	int starty = 0;
	int end = 0;
	int i;
	int rc;
	int mapset = 0;

	log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL);
	parse_command_line(argc, argv);
	if (params.verbose) {
		opts.stderr_level += params.verbose;
		log_alter(opts, SYSLOG_FACILITY_USER, NULL);
	}

	if (params.cluster_dims == 4) {
		min_screen_width = 92;
	} else if (params.cluster_dims == 3)
		min_screen_width = 92;

	while (slurm_load_node((time_t) NULL, &new_node_ptr, SHOW_ALL)) {
		error_code = slurm_get_errno();
		printf("slurm_load_node: %s\n", slurm_strerror(error_code));
		if (params.display == COMMANDS) {
			new_node_ptr = NULL;
			break;		/* just continue */
		}
		if (params.iterate == 0)
			_smap_exit(1);	/* Calls exit(), no return */
		sleep(10);	/* keep trying to reconnect */
	}

	_init_colors();
	select_g_ba_init(new_node_ptr, 0);
	init_grid(new_node_ptr);

	if (params.resolve) {
#if defined HAVE_BG_FILES && defined HAVE_BG_L_P
#if 1
		error("this doesn't work in the current 2.3 code. FIXME");
#else
		if (!have_db2) {
			printf("Required libraries can not be found "
			       "to access the Bluegene system.\nPlease "
			       "set your LD_LIBRARY_PATH correctly to "
			       "point to them.\n");
			goto part_fini;
		}

		if (!mapset)
			mapset = 1;
		if (params.resolve[0] != 'R') {
			i = strlen(params.resolve);
			i -= 3;
			if (i < 0) {
				printf("No real block was entered\n");
				goto part_fini;
			}
			char *rack_mid = find_bp_rack_mid(params.resolve+i);
			if (rack_mid) {
				printf("X=%c Y=%c Z=%c resolves to %s\n",
				       params.resolve[0+i],
				       params.resolve[1+i],
				       params.resolve[2+i],
				       rack_mid);
			} else {
				printf("X=%c Y=%c Z=%c has no resolve\n",
				       params.resolve[0+i],
				       params.resolve[1+i],
				       params.resolve[2+i]);
			}
		} else {
			uint16_t *coord = find_bp_loc(params.resolve);
			if (coord) {
				printf("%s resolves to X=%d Y=%d Z=%d\n",
				       params.resolve,
				       coord[0], coord[1], coord[2]);
			} else {
				printf("%s has no resolve.\n",
				       params.resolve);
			}
		}
part_fini:
#endif
#else
		printf("Must be physically on a BlueGene system for support "
		       "of resolve option.\n");
#endif
		_smap_exit(0);	/* Calls exit(), no return */
	}
	if (!params.commandline) {
		int check_width = min_screen_width;
		signal(SIGWINCH, (void (*)(int))_resize_handler);
		initscr();

		if (params.cluster_dims == 4) {
			height = dim_size[2] * dim_size[3] + dim_size[2] + 3;
			width = (dim_size[1] + dim_size[3] + 1) * dim_size[0]
				 + 2;
			check_width += width;
		} else if (params.cluster_dims == 3) {
			height = dim_size[1] * dim_size[2] + dim_size[1] + 3;
			width = dim_size[0] + dim_size[2] + 3;
			check_width += width;
		} else {
			height = 10;
			width = COLS;
		}

	        if ((COLS < check_width) || (LINES < height)) {
			endwin();
			error("Screen is too small make sure the screen "
			      "is at least %dx%d\n"
			      "Right now it is %dx%d\n",
			      check_width,
			      height,
			      COLS,
			      LINES);
			_smap_exit(1);	/* Calls exit(), no return */
		}

		raw();
		keypad(stdscr, TRUE);
		noecho();
		cbreak();
		curs_set(0);
		nodelay(stdscr, TRUE);
		start_color();
		_set_pairs();

		grid_win = newwin(height, width, starty, startx);
		max_display = grid_win->_maxy * grid_win->_maxx;

		if (params.cluster_dims == 4) {
			startx = width;
			COLS -= 2;
			width = COLS - width;
			height = LINES;
		} else if (params.cluster_dims == 3) {
			startx = width;
			COLS -= 2;
			width = COLS - width;
			height = LINES;
		} else {
			startx = 0;
			starty = height;
			height = LINES - height;
		}

		text_win = newwin(height, width, starty, startx);
        }
	while (!end) {
		if (!params.commandline) {
			_get_option();
redraw:
			clear_window(text_win);
			clear_window(grid_win);
			move(0, 0);

			main_xcord = 1;
			main_ycord = 1;
		}

		if (!params.no_header)
			print_date();

		clear_grid();
		switch (params.display) {
		case JOBS:
			get_job();
			break;
		case RESERVATIONS:
			get_reservation();
			break;
		case SLURMPART:
			get_slurm_part();
			break;
		case COMMANDS:
			if (params.cluster_flags & CLUSTER_FLAG_BG) {
				if (!mapset) {
					mapset = 1;
					wclear(text_win);
				}
				get_command();
			} else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		case BGPART:
			if (params.cluster_flags & CLUSTER_FLAG_BG)
				get_bg_part();
			else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		}

		if (!params.commandline) {
			box(text_win, 0, 0);
			wnoutrefresh(text_win);

			print_grid();
			box(grid_win, 0, 0);
			wnoutrefresh(grid_win);

			doupdate();

			node_info_ptr = new_node_ptr;
			if (node_info_ptr) {
				error_code = slurm_load_node(
					node_info_ptr->last_update,
					&new_node_ptr, SHOW_ALL);
				if (error_code == SLURM_SUCCESS)
					slurm_free_node_info_msg(
						node_info_ptr);
				else if (slurm_get_errno()
					 == SLURM_NO_CHANGE_IN_DATA) {
					error_code = SLURM_SUCCESS;
					new_node_ptr = node_info_ptr;
				}
			} else {
				error_code = slurm_load_node(
					(time_t) NULL,
					&new_node_ptr, SHOW_ALL);
			}
			if (error_code && (quiet_flag != 1)) {
				if (!params.commandline) {
					mvwprintw(
						text_win,
						main_ycord,
						1,
						"slurm_load_node: %s",
						slurm_strerror(
							slurm_get_errno()));
					main_ycord++;
				} else {
					printf("slurm_load_node: %s",
					       slurm_strerror(
						       slurm_get_errno()));
				}
			}
		}

		if (params.iterate) {
			for (i = 0; i < params.iterate; i++) {
				sleep(1);
				if (!params.commandline) {
					if ((rc = _get_option()) == 1)
						goto redraw;
					else if (resize_screen) {
						resize_screen = 0;
						goto redraw;
					}
				}
			}
		} else
			break;

	}

	if (!params.commandline) {
		nodelay(stdscr, FALSE);
		getch();
		endwin();
	}

	_smap_exit(0);	/* Calls exit(), no return */
	exit(0);	/* Redundant, but eliminates compiler warning */
}
Exemple #21
0
int main (int argc, char **argv)
{
   unsigned long temps;
   int i;
   struct timeval t1, t2;

   int *cuts = NULL; /* Juste à des fins de statistiques pour savoir combien de fois on a pu optimiser */

   if (argc != 3)
     {
	fprintf (stderr, "Usage: %s  <ncities> <seed> \n",argv[0]) ;
	exit (1) ;
     }
   
   Argc = argc ;
   Argv = argv ;
   minimum = INT_MAX ;
      
   printf ("ncities = %3d\n", atoi(argv[1])) ;
   
   init_queue (&q);
   genmap () ; 

   gettimeofday(&t1,NULL);

   {
      Path_t path;
      int i;

      for(i=0;i<MAXE;i++)
        path[i] = -1 ;
      path [0] = 0;
      
      tsp_partiel (1, 0, path, cuts);

      no_more_jobs (&q);
   }
    
   gettimeofday(&t2,NULL);

   temps = TIME_DIFF(t1,t2);
  
   printf("time = %ld.%03ldms\n", temps/1000, temps%1000);
   {
      Path_t path;
      int hops, len, n = 0;

      cuts = calloc(NrTowns+1,sizeof(*cuts));

      while (!empty_queue(&q))
	 {
	    n++;
	    get_job(&q, path, &hops, &len);
	    tsp(hops, len, path, cuts);
	 }
      printf("%d jobs", n);
   }
    
   gettimeofday(&t2,NULL);

   temps = TIME_DIFF(t1,t2);
   printf("time = %ld.%03ldms (cuts :", temps/1000, temps%1000);
   for (i=0; i<NrTowns; i++)
     printf(" %d",cuts[i]);
   printf(")\n");

   return 0 ;
}
Exemple #22
0
/**
 * gstreamill_job_start:
 * @job: (in): json type of job description.
 *
 * Returns: json type of job execution result. 
 */
gchar * gstreamill_job_start (Gstreamill *gstreamill, gchar *job_desc)
{
        gchar *p, *name;
        Job *job;

        if (!jobdesc_is_valid (job_desc)) {
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"invalid job\"\n}");
                return p;
        }

        if (jobdesc_is_live (job_desc)) {
                GST_ERROR ("live job arrived:\n%s", job_desc);

        } else {
                GST_ERROR ("transcode job arrived:\n%s", job_desc);
        }

        /* create job object */
        name = jobdesc_get_name (job_desc);
        if (get_job (gstreamill, name) != NULL) {
                GST_ERROR ("start job failure, duplicated name %s.", name);
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"duplicated name\"\n}");
                g_free (name);
                return p;
        }
        job = job_new ("job", job_desc, "name", name, "exe_path", gstreamill->exe_path, NULL);
        g_free (name);

        /* job initialize */
        job->log_dir = gstreamill->log_dir;
        g_mutex_init (&(job->access_mutex));
        job->is_live = jobdesc_is_live (job_desc);
        job->eos = FALSE;
        job->current_access = 0;
        job->age = 0;
        job->last_start_time = NULL;
        if (job_initialize (job, gstreamill->daemon) != 0) {
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"initialize job failure\"\n}");
                g_object_unref (job);
                return p;
        }

        if (job->is_live && (job_output_initialize (job) != 0)) {
                p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"initialize job output failure\"\n}");
                g_object_unref (job);
                return p;
        }

        /* reset and start job */
        job_reset (job);
        if (gstreamill->daemon) {
                guint64 stat;

                stat = create_job_process (job);
                if (stat == JOB_STATE_PLAYING) {
                        GST_ERROR ("Start job %s success", job->name);
                        g_mutex_lock (&(gstreamill->job_list_mutex));
                        gstreamill->job_list = g_slist_append (gstreamill->job_list, job);
                        g_mutex_unlock (&(gstreamill->job_list_mutex));
                        p = g_strdup_printf ("{\n    \"name\": \"%s\",\n\"result\": \"success\"\n}", job->name);

                } else {
                        GST_ERROR ("Start job %s failure, return stat: %s", job->name, job_state_get_name (stat));
                        g_object_unref (job);
                        p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"create process failure\"\n}");
                }

        } else {
                job_encoders_output_initialize (job);
                if (job_start (job) == 0) {
                        g_mutex_lock (&(gstreamill->job_list_mutex));
                        gstreamill->job_list = g_slist_append (gstreamill->job_list, job);
                        g_mutex_unlock (&(gstreamill->job_list_mutex));
                        p = g_strdup ("{\n    \"result\": \"success\"\n}");

                } else {
                        p = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"unknown\"\n}");
                }
        }

        return p;
}
Exemple #23
0
static int handle_worker_result(int sd, int events, void *arg)
{
	wproc_object_job *oj = NULL;
	char *buf, *error_reason = NULL;
	unsigned long size;
	int ret;
	static struct kvvec kvv = KVVEC_INITIALIZER;
	struct wproc_worker *wp = (struct wproc_worker *)arg;

	if(iocache_capacity(wp->ioc) == 0) {
		logit(NSLOG_RUNTIME_WARNING, TRUE, "wproc: iocache_capacity() is 0 for worker %s.\n", wp->name);
	}

	ret = iocache_read(wp->ioc, wp->sd);

	if (ret < 0) {
		logit(NSLOG_RUNTIME_WARNING, TRUE, "wproc: iocache_read() from %s returned %d: %s\n",
			  wp->name, ret, strerror(errno));
		return 0;
	} else if (ret == 0) {
		logit(NSLOG_INFO_MESSAGE, TRUE, "wproc: Socket to worker %s broken, removing", wp->name);
		wproc_num_workers_online--;
		iobroker_unregister(nagios_iobs, sd);
		if (workers.len <= 0) {
			/* there aren't global workers left, we can't run any more checks
			 * we should try respawning a few of the standard ones
			 */
			logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc: All our workers are dead, we can't do anything!");
		}
		remove_worker(wp);
		fanout_destroy(wp->jobs, fo_reassign_wproc_job);
		wp->jobs = NULL;
		wproc_destroy(wp, 0);
		return 0;
	}
	while ((buf = worker_ioc2msg(wp->ioc, &size, 0))) {
		struct wproc_job *job;
		wproc_result wpres;

		/* log messages are handled first */
		if (size > 5 && !memcmp(buf, "log=", 4)) {
			logit(NSLOG_INFO_MESSAGE, TRUE, "wproc: %s: %s\n", wp->name, buf + 4);
			continue;
		}

		/* for everything else we need to actually parse */
		if (buf2kvvec_prealloc(&kvv, buf, size, '=', '\0', KVVEC_ASSIGN) <= 0) {
			logit(NSLOG_RUNTIME_ERROR, TRUE,
				  "wproc: Failed to parse key/value vector from worker response with len %lu. First kv=%s",
				  size, buf ? buf : "(NULL)");
			continue;
		}

		memset(&wpres, 0, sizeof(wpres));
		wpres.job_id = -1;
		wpres.type = -1;
		wpres.response = &kvv;
		parse_worker_result(&wpres, &kvv);

		job = get_job(wp, wpres.job_id);
		if (!job) {
			logit(NSLOG_RUNTIME_WARNING, TRUE, "wproc: Job with id '%d' doesn't exist on %s.\n",
				  wpres.job_id, wp->name);
			continue;
		}
		if (wpres.type != job->type) {
			logit(NSLOG_RUNTIME_WARNING, TRUE, "wproc: %s claims job %d is type %d, but we think it's type %d\n",
				  wp->name, job->id, wpres.type, job->type);
			break;
		}
		oj = (wproc_object_job *)job->arg;

		/*
		 * ETIME ("Timer expired") doesn't really happen
		 * on any modern systems, so we reuse it to mean
		 * "program timed out"
		 */
		if (wpres.error_code == ETIME) {
			wpres.early_timeout = TRUE;
		}
		if (wpres.early_timeout) {
			asprintf(&error_reason, "timed out after %.2fs", tv_delta_f(&wpres.start, &wpres.stop));
		}
		else if (WIFSIGNALED(wpres.wait_status)) {
			asprintf(&error_reason, "died by signal %d%s after %.2f seconds",
			         WTERMSIG(wpres.wait_status),
			         WCOREDUMP(wpres.wait_status) ? " (core dumped)" : "",
			         tv_delta_f(&wpres.start, &wpres.stop));
		}
		else if (job->type != WPJOB_CHECK && WEXITSTATUS(wpres.wait_status) != 0) {
			asprintf(&error_reason, "is a non-check helper but exited with return code %d",
			         WEXITSTATUS(wpres.wait_status));
		}
		if (error_reason) {
			logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc: %s job %d from worker %s %s",
			      wpjob_type_name(job->type), job->id, wp->name, error_reason);
			logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc:   command: %s\n", job->command);
			if (job->type != WPJOB_CHECK && oj) {
				logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc:   host=%s; service=%s; contact=%s\n",
				      oj->host_name ? oj->host_name : "(none)",
				      oj->service_description ? oj->service_description : "(none)",
				      oj->contact_name ? oj->contact_name : "(none)");
			} else if (oj) {
				struct check_result *cr = (struct check_result *)job->arg;
				logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc:   host=%s; service=%s;\n",
				      cr->host_name, cr->service_description);
			}
			logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc:   early_timeout=%d; exited_ok=%d; wait_status=%d; error_code=%d;\n",
			      wpres.early_timeout, wpres.exited_ok, wpres.wait_status, wpres.error_code);
			wproc_logdump_buffer(NSLOG_RUNTIME_ERROR, TRUE, "wproc:   stderr", wpres.outerr);
			wproc_logdump_buffer(NSLOG_RUNTIME_ERROR, TRUE, "wproc:   stdout", wpres.outstd);
		}
		my_free(error_reason);

		switch (job->type) {
		case WPJOB_CHECK:
			ret = handle_worker_check(&wpres, wp, job);
			break;
		case WPJOB_NOTIFY:
			if (wpres.early_timeout) {
				if (oj->service_description) {
					logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Notifying contact '%s' of service '%s' on host '%s' by command '%s' timed out after %.2f seconds\n",
						  oj->contact_name, oj->service_description,
						  oj->host_name, job->command,
						  tv2float(&wpres.runtime));
				} else {
					logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Notifying contact '%s' of host '%s' by command '%s' timed out after %.2f seconds\n",
						  oj->contact_name, oj->host_name,
						  job->command, tv2float(&wpres.runtime));
				}
			}
			break;
		case WPJOB_OCSP:
			if (wpres.early_timeout) {
				logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCSP command '%s' for service '%s' on host '%s' timed out after %.2f seconds\n",
					  job->command, oj->service_description, oj->host_name,
					  tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_OCHP:
			if (wpres.early_timeout) {
				logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCHP command '%s' for host '%s' timed out after %.2f seconds\n",
					  job->command, oj->host_name, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_GLOBAL_SVC_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Global service event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_SVC_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Service event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_GLOBAL_HOST_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Global host event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_HOST_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Host event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;

		case WPJOB_CALLBACK:
			run_job_callback(job, &wpres, 0);
			break;

		default:
			logit(NSLOG_RUNTIME_WARNING, TRUE, "Worker %d: Unknown jobtype: %d\n", wp->pid, job->type);
			break;
		}
		destroy_job(job);
	}

	return 0;
}
int main (int argc, char **argv)
{
    unsigned long long perf;
    tsp_path_t path;
    struct tsp_queue q;
    struct timespec t1, t2;
	

    /* lire les arguments */
    int opt;
    while ((opt = getopt(argc, argv, "s")) != -1) {
      switch (opt) {
      case 's':
	affiche_sol = true;
	break;
      default:
	usage(argv[0]);
	break;
      }
    }

    if (optind != argc-3)
      usage(argv[0]);

    nb_towns = atoi(argv[optind]);
    myseed = atol(argv[optind+1]);
    nb_threads = atoi(argv[optind+2]);
    assert(nb_towns > 0);
    assert(nb_threads > 0);
   
    minimum = INT_MAX;
      
    /* generer la carte et la matrice de distance */
    fprintf (stderr, "ncities = %3d\n", nb_towns);
    genmap ();

    init_queue (&q);

    clock_gettime (CLOCK_REALTIME, &t1);
	
	/* on vide le chemin 'path' : on met des -1 dans toutes les cases */
    memset (path, -1, MAX_TOWNS * sizeof (int));
	/* on définit la première ville comme étant 0 */
    path[0] = 0;

    /* On met des travaux dans la file d'attente q */
    generate_tsp_jobs (&q, 1, 0, path, &cuts, sol, & sol_len, 3);
    no_more_jobs (&q);
   
	/* on vide le chemin 'solution' : on met des -1 dans toutes les cases */
	/* puis on définit la première ville comme étant 0 */
    tsp_path_t solution;
    memset (solution, -1, MAX_TOWNS * sizeof (int));
    solution[0] = 0;

	/* allocation du tableau d'informations sur les threads */
    tab_threads = malloc(nb_threads*sizeof(Cell));
	memset(tab_threads, 0, nb_threads*sizeof(int));

	/* initialisation du mutex*/
	pthread_mutex_init(&mutex, NULL);

	int i;

	/* on place tous les threads dans l'état 'non-occupé' */
	for(i=0; i<nb_threads; i++){
		tab_threads[i].occupe = 0;
    }

	/* Tant que la file de jobs n'est pas vide on sort un job et on l'execute avec tsp */
    while (!empty_queue (&q)) {
        int hops = 0, len = 0;
		/* on récupère un job dans la file d'atente des jobs */
        get_job (&q, solution, &hops, &len);
        
        i = 0;
		/* on boucle tant qu'on n'a pas trouvé de thread pour effectuer le job */
        while (1){
			/* si le thread i n'est pas occupé alors on va l'utiliser pour effectuer le job */
            if(!tab_threads[i].occupe){
                
				/* on place le thread i en statut 'occupé' */
                tab_threads[i].occupe = 1;

				/* on crée une structure arguments qui va recevoir les arguments de tsp */
                struct arg_struct arguments;

				arguments.hops = hops;
				arguments.len = len;
				memcpy(arguments.path, solution, nb_towns * sizeof (int));

				/* tsp est récursive et on a besoin de savoir quand le thread a terminé le job afin de le mettre en 'non-occupé' */
				/* On introduit donc un entier qui est 1 si le tsp appelé est celui du père et 0 si c'est dans les fils */
                arguments.pere = 1; 

				/* lancement du thread sur tsp avec les bons arguments*/
                pthread_create (&tab_threads[i].thread, NULL, tsp, (void*)&arguments);
                break;
            }
			/* sinon on va regarder si le suivant%nb_threads est occupé */
            i = (i+1)%nb_threads;
        }
    }

    i = 0;
	/* on attend la fin de tous les threads avant de continuer */
    while(1){
        pthread_join(tab_threads[i].thread, NULL);
        i++;
        if (i == nb_threads) break;
    }
    
    clock_gettime (CLOCK_REALTIME, &t2);

    if (affiche_sol)
      print_solution_svg (sol, sol_len);

    perf = TIME_DIFF (t1,t2);
    printf("<!-- # = %d seed = %ld len = %d threads = %d time = %lld.%03lld ms ( %lld coupures ) -->\n",
	   nb_towns, myseed, sol_len, nb_threads,
	   perf/1000000ll, perf%1000000ll, cuts);

    return 0 ;
}
void get_command(void)
{
	char com[255];

	int text_width, text_startx;
	allocated_block_t *allocated_block = NULL;
	int i = 0;
	int count = 0;

	WINDOW *command_win = NULL;
        List allocated_blocks = NULL;
	ListIterator results_i;

	if (params.commandline && !params.command) {
		printf("Configure won't work with commandline mode.\n");
		printf("Please remove the -c from the commandline.\n");
		bg_configure_ba_fini();
		exit(0);
	}

	if (working_cluster_rec) {
		char *cluster_name = slurm_get_cluster_name();
		if (strcmp(working_cluster_rec->name, cluster_name)) {
			xfree(cluster_name);
			endwin();
			printf("To use the configure option you must be on the "
			       "cluster the configure is for.\nCross cluster "
			       "support doesn't exist today.\nSorry for the "
			       "inconvenince.\n");
			bg_configure_ba_fini();
			exit(0);
		}
		xfree(cluster_name);
	}

	/* make sure we don't get any noisy debug */
	ba_configure_set_ba_debug_flags(0);

	bg_configure_ba_setup_wires();

	color_count = 0;

	allocated_blocks = list_create(_destroy_allocated_block);

	if (params.commandline) {
		snprintf(com, sizeof(com), "%s", params.command);
		goto run_command;
	} else {
		text_width = text_win->_maxx;
		text_startx = text_win->_begx;
		command_win = newwin(3, text_width - 1, LINES - 4,
				     text_startx + 1);
		curs_set(1);
		echo();
	}

	while (strcmp(com, "quit")) {
		clear_window(grid_win);
		print_grid();
		clear_window(text_win);
		box(text_win, 0, 0);
		box(grid_win, 0, 0);

		if (!params.no_header)
			_print_header_command();

		if (error_string != NULL) {
			i = 0;
			while (error_string[i] != '\0') {
				if (error_string[i] == '\n') {
					main_ycord++;
					main_xcord=1;
					i++;
				}
				mvwprintw(text_win,
					  main_ycord,
					  main_xcord,
					  "%c",
					  error_string[i++]);
				main_xcord++;
			}
			main_ycord++;
			main_xcord = 1;
			memset(error_string, 0, 255);
		}
		results_i = list_iterator_create(allocated_blocks);

		count = list_count(allocated_blocks)
			- (LINES-(main_ycord+5));

		if (count<0)
			count=0;
		i=0;
		while ((allocated_block = list_next(results_i)) != NULL) {
			if (i >= count)
				_print_text_command(allocated_block);
			i++;
		}
		list_iterator_destroy(results_i);

		wnoutrefresh(text_win);
		wnoutrefresh(grid_win);
		doupdate();
		clear_window(command_win);

		box(command_win, 0, 0);
		mvwprintw(command_win, 0, 3,
			  "Input Command: (type quit to change view, "
			  "exit to exit)");
		wmove(command_win, 1, 1);
		wgetstr(command_win, com);

		if (!strcmp(com, "exit")) {
			endwin();
			if (allocated_blocks)
				list_destroy(allocated_blocks);
			bg_configure_ba_fini();
			exit(0);
		}
	run_command:

		if (!strcmp(com, "quit") || !strcmp(com, "\\q")) {
			break;
		} else if (!strncasecmp(com, "layout", 6)) {
			_set_layout(com);
		} else if (!strncasecmp(com, "basepartition", 13)) {
			_set_base_part_cnt(com);
		} else if (!strncasecmp(com, "nodecard", 8)) {
			_set_nodecard_cnt(com);
		} else if (!strncasecmp(com, "resolve", 7) ||
			   !strncasecmp(com, "r ", 2)) {
			_resolve(com);
		} else if (!strncasecmp(com, "resume", 6)) {
			mvwprintw(text_win,
				main_ycord,
				main_xcord, "%s", com);
		} else if (!strncasecmp(com, "drain", 5)) {
			mvwprintw(text_win,
				main_ycord,
				main_xcord, "%s", com);
		} else if (!strncasecmp(com, "alldown", 7)) {
			_change_state_all_bps(com, NODE_STATE_DOWN);
		} else if (!strncasecmp(com, "down", 4)) {
			_change_state_bps(com, NODE_STATE_DOWN);
		} else if (!strncasecmp(com, "allup", 5)) {
			_change_state_all_bps(com, NODE_STATE_IDLE);
		} else if (!strncasecmp(com, "up", 2)) {
			_change_state_bps(com, NODE_STATE_IDLE);
		} else if (!strncasecmp(com, "remove", 6)
			|| !strncasecmp(com, "delete", 6)
			|| !strncasecmp(com, "drop", 4)) {
			_remove_allocation(com, allocated_blocks);
		} else if (!strncasecmp(com, "create", 6)) {
			_create_allocation(com, allocated_blocks);
		} else if (!strncasecmp(com, "copy", 4)
			|| !strncasecmp(com, "c ", 2)
			|| !strncasecmp(com, "c\0", 2)) {
			_copy_allocation(com, allocated_blocks);
		} else if (!strncasecmp(com, "save", 4)) {
			_save_allocation(com, allocated_blocks);
		} else if (!strncasecmp(com, "load", 4)) {
			_load_configuration(com, allocated_blocks);
		} else if (!strncasecmp(com, "clear all", 9)
			|| !strncasecmp(com, "clear", 5)) {
			list_flush(allocated_blocks);
		} else {
			memset(error_string, 0, 255);
			sprintf(error_string, "Unknown command '%s'",com);
		}

		if (params.commandline) {
			bg_configure_ba_fini();
			exit(1);
		}
	}
	if (allocated_blocks)
		list_destroy(allocated_blocks);
	params.display = 0;
	noecho();

	clear_window(text_win);
	main_xcord = 1;
	main_ycord = 1;
	curs_set(0);
	print_date();
	get_job();
	return;
}
Exemple #26
0
int mpi_main(int argc, char **argv,
             job_t (send_jobs)(filter_t *, unsigned char **, int, int),
             job_t (get_job)(filter_t *)) {
    int rank, image_width, image_height;
    filter_t filter;
    job_t job;
    double starttime;
    unsigned char ** result;

    MPI_Init(&argc, &argv);

    starttime = MPI_Wtime();
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    // Init
    if (rank == 0) {
        // Read in image and filter and send to workers
        if (argc < 3 || argc > 4) {
            fprintf(stderr, "USAGE: %s filter.txt input.pnm [output.pnm]\n",
                    argv[1]);
            return 1;
        }

        const char * filter_path = argv[1];
        const char * image_path  = argv[2];
        const char * output_path = argv[argc == 3 ? 2 : 3];

        unsigned char ** image;

        filter.filter = read_filter(filter_path, &filter.width, &filter.height);
        image = read_image(image_path, &image_width, &image_height);

        send_filter(&filter);
        job = send_jobs(&filter, image, image_width, image_height);

        result = do_job(&job, &filter);

        LOG("Fetching results.");
        fetch_results(result, image_width);

        LOG("Writing output");
        write_image(output_path, result, job.width, job.height);
    } else {
        // Receive filter and job
        filter = get_filter();
        job = get_job(&filter);

        result = do_job(&job, &filter);

        LOG("Sending results");
        send_result(&job, result);
    }

    // Cleanup
    /* free_filter(filter.filter, filter.height); */
    /* free_image(job.image); */
    /* free_image(result); */

    starttime = MPI_Wtime() - starttime;
    if (rank == 0)
        printf("%f\n", starttime);

    MPI_Finalize();

    return 0;
}
Exemple #27
0
static int handle_worker_result(int sd, int events, void *arg)
{
	worker_process *wp = (worker_process *)arg;
	wproc_object_job *oj;
	char *buf;
	unsigned long size;
	int ret;
	static struct kvvec kvv = KVVEC_INITIALIZER;

	ret = iocache_read(wp->ioc, wp->sd);

	if (ret < 0) {
		logit(NSLOG_RUNTIME_WARNING, TRUE, "iocache_read() from worker %d returned %d: %s\n",
			  wp->pid, ret, strerror(errno));
		return 0;
	} else if (ret == 0) {
		/*
		 * XXX FIXME worker exited. spawn a new on to replace it
		 * and distribute all unfinished jobs from this one to others
		 */
		return 0;
	}

	while ((buf = iocache_use_delim(wp->ioc, MSG_DELIM, MSG_DELIM_LEN, &size))) {
		int job_id = -1;
		worker_job *job;
		wproc_result wpres;

		/* log messages are handled first */
		if (size > 5 && !memcmp(buf, "log=", 4)) {
			logit(NSLOG_INFO_MESSAGE, TRUE, "worker %d: %s\n", wp->pid, buf + 4);
			continue;
		}

		/* for everything else we need to actually parse */
		if (buf2kvvec_prealloc(&kvv, buf, size, '=', '\0', KVVEC_ASSIGN) <= 0) {
			/* XXX FIXME log an error */
			continue;
		}

		memset(&wpres, 0, sizeof(wpres));
		wpres.job_id = -1;
		wpres.type = -1;
		wpres.response = &kvv;
		parse_worker_result(&wpres, &kvv);

		job = get_job(wp, wpres.job_id);
		if (!job) {
			logit(NSLOG_RUNTIME_WARNING, TRUE, "Worker job with id '%d' doesn't exist on worker %d.\n",
				  job_id, wp->pid);
			continue;
		}
		if (wpres.type != job->type) {
			logit(NSLOG_RUNTIME_WARNING, TRUE, "Worker %d claims job %d is type %d, but we think it's type %d\n",
				  wp->pid, job->id, wpres.type, job->type);
			break;
		}
		oj = (wproc_object_job *)job->arg;

		/*
		 * ETIME ("Timer expired") doesn't really happen
		 * on any modern systems, so we reuse it to mean
		 * "program timed out"
		 */
		if (wpres.error_code == ETIME) {
			wpres.early_timeout = TRUE;
		}
		switch (job->type) {
		case WPJOB_CHECK:
			ret = handle_worker_check(&wpres, wp, job);
			break;
		case WPJOB_NOTIFY:
			if (wpres.early_timeout) {
				if (oj->service_description) {
					logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Notifying contact '%s' of service '%s' on host '%s' by command '%s' timed out after %.2f seconds\n",
						  oj->contact_name, oj->service_description,
						  oj->host_name, job->command,
						  tv2float(&wpres.runtime));
				} else {
					logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Notifying contact '%s' of host '%s' by command '%s' timed out after %.2f seconds\n",
						  oj->contact_name, oj->host_name,
						  job->command, tv2float(&wpres.runtime));
				}
			}
			break;
		case WPJOB_OCSP:
			if (wpres.early_timeout) {
				logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCSP command '%s' for service '%s' on host '%s' timed out after %.2f seconds\n",
					  job->command, oj->service_description, oj->host_name,
					  tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_OCHP:
			if (wpres.early_timeout) {
				logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCHP command '%s' for host '%s' timed out after %.2f seconds\n",
					  job->command, oj->host_name, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_GLOBAL_SVC_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Global service event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_SVC_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Service event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_GLOBAL_HOST_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Global host event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;
		case WPJOB_HOST_EVTHANDLER:
			if (wpres.early_timeout) {
				logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE,
					  "Warning: Host event handler command '%s' timed out after %.2f seconds\n",
					  job->command, tv2float(&wpres.runtime));
			}
			break;

		default:
			logit(NSLOG_RUNTIME_WARNING, TRUE, "Worker %d: Unknown jobtype: %d\n", wp->pid, job->type);
			break;
		}
		destroy_job(wp, job);
	}

	return 0;
}
Exemple #28
0
/** SIGCHLD handler **/
void handler(int signum, siginfo_t *info, void *context) {
    int cpid, status;

    cpid = info->si_pid; // sending pid
    //printf("Got a SIGCHLD from %d!\n", cpid);

    // loop to catch simultaneous SIGCHLDs
    while( (cpid = waitpid(-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) > 0 ) {

        //printf("HANDLER Got %d from waitpid\n", cpid);
        job *j = get_job(job_list, cpid);
        if(j == NULL) {
            printf("Error: get_job returned null\n");
            _exit(EXIT_FAILURE);
        }

        if(WIFEXITED(status)) { // completed
            if( set_complete(j, cpid) == -1 ) {
                printf("HANDLER set_complete went awry!\n");
                _exit(EXIT_FAILURE);
            }
        }
        else if(WIFSIGNALED(status)) { // terminated
            set_complete(j, cpid);
            printf("\n");
            //printf("TERMINATED: %d\n", WTERMSIG(status));
        }
        else if(WIFSTOPPED(status)) { // stopped
            j->running = 0;

            if(j->fg) {
                send_back(job_list, j->pgid);
                printf("\nStopped: %s\n", j->rawcmd);
            } else {

                // queue stopped message
                message *m = malloc(sizeof(message));
                copy_to_buf(j->rawcmd, m->msg);
                m->status = 0;
                push(msg_q, PROCESS, (void *)m);
            }
        }
        else if(WIFCONTINUED(status)) { // continued
            j->running = 1;
            //printf("CONTINUED\n");
        }

        if(j->complete) {
            j->running = 0;
            if(!j->fg) {
                // queue finished message
                message *m = malloc(sizeof(message));
                copy_to_buf(j->rawcmd, m->msg);
                m->status = 1;
                push(msg_q, PROCESS, (void *)m);

                free_job(del_job(job_list, j->pgid));
            }
        }
    }

    //printf("HANDLER Done with waitpid loop\n");
}
Exemple #29
0
static void *_resize_handler(int sig)
{
	int startx = 0, starty = 0;
	int height = 40, width = 100;
	int check_width = min_screen_width;
	main_ycord = 1;

	/* clear existing data and update to avoid ghost during resize */
	clear_window(text_win);
	clear_window(grid_win);
	doupdate();
	delwin(grid_win);
	delwin(text_win);

	endwin();
	initscr();
	doupdate();	/* update now to make sure we get the new size */

	if (params.cluster_dims == 4) {
		height = dim_size[2] * dim_size[3] + dim_size[2] + 3;
		width = (dim_size[1] + dim_size[3] + 1) * dim_size[0];
		check_width += width;
	} else if (params.cluster_dims == 3) {
		height = dim_size[1] * dim_size[2] + dim_size[1] + 3;
		width = dim_size[0] + dim_size[2] + 3;
		check_width += width;
	} else {
		height = 10;
		width = COLS;
	}

	if (COLS < check_width || LINES < height) {
		endwin();
		error("Screen is too small make sure "
		      "the screen is at least %dx%d\n"
		      "Right now it is %dx%d\n", width, height, COLS, LINES);
		_smap_exit(0);	/* Calls exit(), no return */
	}

	grid_win = newwin(height, width, starty, startx);
	max_display = (getmaxy(grid_win) - 1) * (getmaxx(grid_win) - 1);

	if (params.cluster_dims == 4) {
		startx = width;
		width = COLS - width - 2;
		height = LINES;
	} else if (params.cluster_dims == 3) {
		startx = width;
		width = COLS - width - 2;
		height = LINES;
	} else {
		startx = 0;
		starty = height;
		height = LINES - height;
	}

	text_win = newwin(height, width, starty, startx);

	print_date();
	switch (params.display) {
	case JOBS:
		get_job();
		break;
	case RESERVATIONS:
		get_reservation();
		break;
	case SLURMPART:
		get_slurm_part();
		break;
	case COMMANDS:
#ifdef HAVE_BG
		get_command();
#endif
		break;
	case BGPART:
		if (params.cluster_flags & CLUSTER_FLAG_BG)
			get_bg_part();
		break;
	}

	print_grid();
	box(text_win, 0, 0);
	box(grid_win, 0, 0);
	wnoutrefresh(text_win);
	wnoutrefresh(grid_win);
	doupdate();
	resize_screen = 1;
	return NULL;
}
Exemple #30
0
int main(int argc, char **argv)
{
	log_options_t opts = LOG_OPTS_STDERR_ONLY;
	node_info_msg_t *node_info_ptr = NULL;
	node_info_msg_t *new_node_ptr = NULL;
	int error_code;
	int height = 40;
	int width = 100;
	int startx = 0;
	int starty = 0;
	int end = 0;
	int i;
	int rc;

	slurm_conf_init(NULL);
	log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL);
	parse_command_line(argc, argv);
	if (params.verbose) {
		opts.stderr_level += params.verbose;
		log_alter(opts, SYSLOG_FACILITY_USER, NULL);
	}

	if (params.cluster_dims == 4) {
		min_screen_width = 92;
	} else if (params.cluster_dims == 3)
		min_screen_width = 92;

	/* no need for this if you are resolving */
	while (slurm_load_node((time_t) NULL,
			       &new_node_ptr, SHOW_ALL)) {
		if (params.resolve || (params.display == COMMANDS)) {
			new_node_ptr = NULL;
			break;		/* just continue */
		}
		error_code = slurm_get_errno();
		printf("slurm_load_node: %s\n",
		       slurm_strerror(error_code));
		if (params.iterate == 0)
			exit(1);
		sleep(10);	/* keep trying to reconnect */
	}

	select_g_ba_init(new_node_ptr, 0);

	if (dim_size == NULL) {
		dim_size = get_cluster_dims(new_node_ptr);
		if ((dim_size == NULL) || (dim_size[0] < 1))
			fatal("Invalid system dimensions");
	}
	_init_colors();

	if (params.resolve) {
		char *ret_str = resolve_mp(params.resolve, new_node_ptr);
		if (ret_str) {
			printf("%s", ret_str);
			xfree(ret_str);
		}
		_smap_exit(0);	/* Calls exit(), no return */
	}
	if (!params.commandline) {
		int check_width = min_screen_width;

		initscr();
		init_grid(new_node_ptr, COLS);
		signal(SIGWINCH, (void (*)(int))_resize_handler);

		if (params.cluster_dims == 4) {
			height = dim_size[2] * dim_size[3] + dim_size[2] + 3;
			width = (dim_size[1] + dim_size[3] + 1) * dim_size[0]
				 + 2;
			check_width += width;
		} else if (params.cluster_dims == 3) {
			height = dim_size[1] * dim_size[2] + dim_size[1] + 3;
			width = dim_size[0] + dim_size[2] + 3;
			check_width += width;
		} else {
			height = 10;
			width = COLS;
		}

	        if ((COLS < check_width) || (LINES < height)) {
			endwin();
			error("Screen is too small make sure the screen "
			      "is at least %dx%d\n"
			      "Right now it is %dx%d\n",
			      check_width,
			      height,
			      COLS,
			      LINES);
			_smap_exit(1);	/* Calls exit(), no return */
		}

		raw();
		keypad(stdscr, true);
		noecho();
		cbreak();
		curs_set(0);
		nodelay(stdscr, true);
		start_color();
		_set_pairs();

		grid_win = newwin(height, width, starty, startx);
		max_display = (getmaxy(grid_win) - 1) * (getmaxx(grid_win) - 1);

		if (params.cluster_dims == 4) {
			startx = width;
			width = COLS - width - 2;
			height = LINES;
		} else if (params.cluster_dims == 3) {
			startx = width;
			width = COLS - width - 2;
			height = LINES;
		} else {
			startx = 0;
			starty = height;
			height = LINES - height;
		}

		text_win = newwin(height, width, starty, startx);
        }
	while (!end) {
		if (!params.commandline) {
			_get_option();
redraw:
			clear_window(text_win);
			clear_window(grid_win);
			move(0, 0);

			update_grid(new_node_ptr);
			main_xcord = 1;
			main_ycord = 1;
		}

		if (!params.no_header)
			print_date();

		clear_grid();
		switch (params.display) {
		case JOBS:
			get_job();
			break;
		case RESERVATIONS:
			get_reservation();
			break;
		case SLURMPART:
			get_slurm_part();
			break;
		case COMMANDS:
#ifdef HAVE_BG
			wclear(text_win);
			get_command();
#else
			error("Must be on a real BG SYSTEM to "
			      "run this command");
			if (!params.commandline)
				endwin();
			_smap_exit(1);	/* Calls exit(), no return */
#endif
			break;
		case BGPART:
			if (params.cluster_flags & CLUSTER_FLAG_BG)
				get_bg_part();
			else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		}

		if (!params.commandline) {
			box(text_win, 0, 0);
			wnoutrefresh(text_win);

			print_grid();
			box(grid_win, 0, 0);
			wnoutrefresh(grid_win);

			doupdate();

			node_info_ptr = new_node_ptr;
			if (node_info_ptr) {
				error_code = slurm_load_node(
					node_info_ptr->last_update,
					&new_node_ptr, SHOW_ALL);
				if (error_code == SLURM_SUCCESS)
					slurm_free_node_info_msg(
						node_info_ptr);
				else if (slurm_get_errno()
					 == SLURM_NO_CHANGE_IN_DATA) {
					error_code = SLURM_SUCCESS;
					new_node_ptr = node_info_ptr;
				}
			} else {
				error_code = slurm_load_node(
					(time_t) NULL,
					&new_node_ptr, SHOW_ALL);
			}
			if (error_code && (quiet_flag != 1)) {
				if (!params.commandline) {
					mvwprintw(
						text_win,
						main_ycord,
						1,
						"slurm_load_node: %s",
						slurm_strerror(
							slurm_get_errno()));
					main_ycord++;
				} else {
					printf("slurm_load_node: %s",
					       slurm_strerror(
						       slurm_get_errno()));
				}
			}
		}

		if (params.iterate) {
			for (i = 0; i < params.iterate; i++) {
				sleep(1);
				if (!params.commandline) {
					if ((rc = _get_option()) == 1)
						goto redraw;
					else if (resize_screen) {
						resize_screen = 0;
						goto redraw;
					}
				}
			}
		} else
			break;

	}

	if (!params.commandline) {
		nodelay(stdscr, false);
		getch();
		endwin();
	}

	_smap_exit(0);	/* Calls exit(), no return */
	exit(0);	/* Redundant, but eliminates compiler warning */
}