<commit_before>/***************************Copyright-DO-NOT-REMOVE-THIS-LINE**
 * CONDOR Copyright Notice
 *
 * See LICENSE.TXT for additional notices and disclaimers.
 *
 * Copyright (c)1990-1998 CONDOR Team, Computer Sciences Department, 
 * University of Wisconsin-Madison, Madison, WI.  All Rights Reserved.  
 * No use of the CONDOR Software Program Source Code is authorized 
 * without the express consent of the CONDOR Team.  For more information 
 * contact: CONDOR Team, Attention: Prof<NAME>, 
 * 7367 Computer Sciences, 1210 W. Dayton St., Madison, WI 53706-1685, 
 * (608) 262-0856 or <EMAIL>.
 *
 * U.S. Government Rights Restrictions: Use, duplication, or disclosure 
 * by the U.S. Government is subject to restrictions as set forth in 
 * subparagraph (c)(1)(ii) of The Rights in Technical Data and Computer 
 * Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) and 
 * (2) of Commercial Computer Software-Restricted Rights at 48 CFR 
 * 52.227-19, as applicable, CONDOR Team, Attention: Prof<NAME> 
 * Livny, 7367 Computer Sciences, 1210 W. Dayton St., Madison, 
 * WI 53706-1685, (608) 262-0856 or <EMAIL>.
****************************Copyright-DO-NOT-REMOVE-THIS-LINE**/
#include "condor_common.h"
#include <iostream.h>
#include "condor_config.h"
#include "condor_accountant.h"
#include "condor_classad.h"
#include "condor_debug.h"
#include "condor_query.h"
#include "condor_q.h"
#include "condor_io.h"
#include "condor_attributes.h"
#include "match_prefix.h"
#include "my_hostname.h"
#include "get_daemon_addr.h"
#include "get_full_hostname.h"
#include "MyString.h"
#include "extArray.h"
#include "files.h"

extern 	"C" int SetSyscalls(int val){return val;}
extern  void short_print(int,int,const char*,int,int,int,int,int,const char *);
static  void processCommandLineArguments(int, char *[]);
extern 	"C" void set_debug_flags( char * );

static 	void short_header (void);
static 	void usage (char *);
static 	void displayJobShort (ClassAd *);
static 	void shorten (char *, int);
static	bool show_queue (char*, char*, char*);

static 	int verbose = 0, summarize = 1, global = 0;
static 	int malformed, unexpanded, running, idle;

static	CondorQ 	Q;
static	QueryResult result;
static	CondorQuery	scheddQuery(SCHEDD_AD);
static	CondorQuery submittorQuery(SUBMITTOR_AD);
static	ClassAdList	scheddList;

static	bool		querySchedds 	= false;
static	bool		querySubmittors = false;
static	char		constraint[4096];
static	char		*pool = NULL;

// for run failure analysis
static  int			findSubmittor( char * );
static	void 		setupAnalysis();
static 	void		fetchSubmittorPrios();
static	void		doRunAnalysis( ClassAd* );
struct 	PrioEntry { MyString name; float prio; };
static 	bool		analyze	= false;
static	char		*fixSubmittorName( char*, int );
static	ClassAdList startdAds;
static	ExprTree	*stdRankCondition;
static	ExprTree	*preemptRankCondition;
static	ExprTree	*preemptPrioCondition;
static	ExprTree	*preemptionHold;
static  ExtArray<PrioEntry> prioTable;
template class ExtArray<PrioEntry>;

extern 	"C"	int		Termlog;

int main (int argc, char **argv)
{
	ClassAd		*ad;
	bool		first = true;
	char		scheddAddr[64];
	char		scheddName[64];
	char		scheddMachine[64];
	
	// load up configuration file
	config( 0 );

#if !defined(WIN32)
	install_sig_handler(SIGPIPE, SIG_IGN );
#endif

	// process arguments
	processCommandLineArguments (argc, argv);

	// check if analysis is required
	if( analyze ) {
		setupAnalysis();
	}
	// if we haven't figured out what to do yet, just display the
	// local queue 
	if (!global && !querySchedds && !querySubmittors) {
		char *tmp = get_schedd_addr(0);
		if( !tmp ) {
			fprintf( stderr, "Can't find address of local schedd\n" );
			exit( 1 );
		}
		sprintf( scheddAddr, "%s", tmp );
		sprintf( scheddName, "%s", my_daemon_name("SCHEDD") );		
		sprintf( scheddMachine, "%s", my_full_hostname() );
		if( show_queue(scheddAddr, scheddName, scheddMachine) ) {
			exit( 0 );
		} else {
			fprintf( stderr, "Can't display queue of local schedd\n" );
			exit( 1 );
		}
	}
	
	// if a global queue is required, query the schedds instead of submittors
	if (global) {
		querySchedds = true;
		sprintf( constraint, "%s > 0 || %s > 0", ATTR_TOTAL_RUNNING_JOBS,
				ATTR_TOTAL_IDLE_JOBS );
		result = scheddQuery.addConstraint( constraint );
		if( result != Q_OK ) {
			fprintf( stderr, "Error: Couldn't add constraint %s\n", constraint);
			exit( 1 );
		}		
	}

	// get the list of ads from the collector
	if( pool ) {
		result = querySchedds ? scheddQuery.fetchAds(scheddList, pool) : 
			submittorQuery.fetchAds(scheddList, pool);
	} else {
		result = querySchedds ? scheddQuery.fetchAds(scheddList) : 
			submittorQuery.fetchAds(scheddList);
	}

	if (result != Q_OK) {
		fprintf (stderr, "Error %d: %s\n", result, getStrQueryResult(result));
		exit(1);
	}
	

	// get queue from each ScheddIpAddr in ad
	scheddList.Open();
	while ((ad = scheddList.Next()))
	{
		// get the address of the schedd
		if (!ad->LookupString(ATTR_SCHEDD_IP_ADDR, scheddAddr)	||
			!ad->LookupString(ATTR_NAME, scheddName)			||
			!ad->LookupString(ATTR_MACHINE, scheddMachine))
				continue;
	
		show_queue( scheddAddr, scheddName, scheddMachine );
		first = false;
	}

	// close list
	scheddList.Close();

	if (first)
	{
		fprintf (stderr,"Error: Collector has no record of schedd/submitter\n");
		exit(1);
	}

	return 0;
}

static void 
processCommandLineArguments (int argc, char *argv[])
{
	int i, cluster, proc;
	char *arg, *at, *daemonname;
	<commit_msg>If all queues are empty on a -global, don't print out an error.  Print a helpful "All queues are empty" message instead.<commit_after>/***************************Copyright-DO-NOT-REMOVE-THIS-LINE**
 * CONDOR Copyright Notice
 *
 * See LICENSE.TXT for additional notices and disclaimers.
 *
 * Copyright (c)1990-1998 CONDOR Team, Computer Sciences Department, 
 * University of Wisconsin-Madison, Madison, WI.  All Rights Reserved.  
 * No use of the CONDOR Software Program Source Code is authorized 
 * without the express consent of the CONDOR Team.  For more information 
 * contact: CONDOR Team, Attention: Prof<NAME>, 
 * 7367 Computer Sciences, 1210 W. Dayton St., Madison, WI 53706-1685, 
 * (608) 262-0856 or <EMAIL>.
 *
 * U.S. Government Rights Restrictions: Use, duplication, or disclosure 
 * by the U.S. Government is subject to restrictions as set forth in 
 * subparagraph (c)(1)(ii) of The Rights in Technical Data and Computer 
 * Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) and 
 * (2) of Commercial Computer Software-Restricted Rights at 48 CFR 
 * 52.227-19, as applicable, CONDOR Team, Attention: <NAME> 
 * Livny, 7367 Computer Sciences, 1210 W. Dayton St., Madison, 
 * WI 53706-1685, (608) 262-0856 or <EMAIL>.
****************************Copyright-DO-NOT-REMOVE-THIS-LINE**/
#include "condor_common.h"
#include <iostream.h>
#include "condor_config.h"
#include "condor_accountant.h"
#include "condor_classad.h"
#include "condor_debug.h"
#include "condor_query.h"
#include "condor_q.h"
#include "condor_io.h"
#include "condor_attributes.h"
#include "match_prefix.h"
#include "my_hostname.h"
#include "get_daemon_addr.h"
#include "get_full_hostname.h"
#include "MyString.h"
#include "extArray.h"
#include "files.h"

extern 	"C" int SetSyscalls(int val){return val;}
extern  void short_print(int,int,const char*,int,int,int,int,int,const char *);
static  void processCommandLineArguments(int, char *[]);
extern 	"C" void set_debug_flags( char * );

static 	void short_header (void);
static 	void usage (char *);
static 	void displayJobShort (ClassAd *);
static 	void shorten (char *, int);
static	bool show_queue (char*, char*, char*);

static 	int verbose = 0, summarize = 1, global = 0;
static 	int malformed, unexpanded, running, idle;

static	CondorQ 	Q;
static	QueryResult result;
static	CondorQuery	scheddQuery(SCHEDD_AD);
static	CondorQuery submittorQuery(SUBMITTOR_AD);
static	ClassAdList	scheddList;

static	bool		querySchedds 	= false;
static	bool		querySubmittors = false;
static	char		constraint[4096];
static	char		*pool = NULL;

// for run failure analysis
static  int			findSubmittor( char * );
static	void 		setupAnalysis();
static 	void		fetchSubmittorPrios();
static	void		doRunAnalysis( ClassAd* );
struct 	PrioEntry { MyString name; float prio; };
static 	bool		analyze	= false;
static	char		*fixSubmittorName( char*, int );
static	ClassAdList startdAds;
static	ExprTree	*stdRankCondition;
static	ExprTree	*preemptRankCondition;
static	ExprTree	*preemptPrioCondition;
static	ExprTree	*preemptionHold;
static  ExtArray<PrioEntry> prioTable;
template class ExtArray<PrioEntry>;

extern 	"C"	int		Termlog;

int main (int argc, char **argv)
{
	ClassAd		*ad;
	bool		first = true;
	char		scheddAddr[64];
	char		scheddName[64];
	char		scheddMachine[64];
	
	// load up configuration file
	config( 0 );

#if !defined(WIN32)
	install_sig_handler(SIGPIPE, SIG_IGN );
#endif

	// process arguments
	processCommandLineArguments (argc, argv);

	// check if analysis is required
	if( analyze ) {
		setupAnalysis();
	}
	// if we haven't figured out what to do yet, just display the
	// local queue 
	if (!global && !querySchedds && !querySubmittors) {
		char *tmp = get_schedd_addr(0);
		if( !tmp ) {
			fprintf( stderr, "Can't find address of local schedd\n" );
			exit( 1 );
		}
		sprintf( scheddAddr, "%s", tmp );
		sprintf( scheddName, "%s", my_daemon_name("SCHEDD") );		
		sprintf( scheddMachine, "%s", my_full_hostname() );
		if( show_queue(scheddAddr, scheddName, scheddMachine) ) {
			exit( 0 );
		} else {
			fprintf( stderr, "Can't display queue of local schedd\n" );
			exit( 1 );
		}
	}
	
	// if a global queue is required, query the schedds instead of submittors
	if (global) {
		querySchedds = true;
		sprintf( constraint, "%s > 0 || %s > 0", ATTR_TOTAL_RUNNING_JOBS,
				ATTR_TOTAL_IDLE_JOBS );
		result = scheddQuery.addConstraint( constraint );
		if( result != Q_OK ) {
			fprintf( stderr, "Error: Couldn't add constraint %s\n", constraint);
			exit( 1 );
		}		
	}

	// get the list of ads from the collector
	if( pool ) {
		result = querySchedds ? scheddQuery.fetchAds(scheddList, pool) : 
			submittorQuery.fetchAds(scheddList, pool);
	} else {
		result = querySchedds ? scheddQuery.fetchAds(scheddList) : 
			submittorQuery.fetchAds(scheddList);
	}

	if (result != Q_OK) {
		fprintf (stderr, "Error %d: %s\n", result, getStrQueryResult(result));
		exit(1);
	}
	

	// get queue from each ScheddIpAddr in ad
	scheddList.Open();
	while ((ad = scheddList.Next()))
	{
		// get the address of the schedd
		if (!ad->LookupString(ATTR_SCHEDD_IP_ADDR, scheddAddr)	||
			!ad->LookupString(ATTR_NAME, scheddName)			||
			!ad->LookupString(ATTR_MACHINE, scheddMachine))
				continue;
	
		show_queue( scheddAddr, scheddName, scheddMachine );
		first = false;
	}

	// close list
	scheddList.Close();

	if( first ) {
		if( global ) {
			printf( "All queues are empty\n" );
		} else {
			fprintf(stderr,"Error: Collector has no record of "
							"schedd/submitter\n");
			exit(1);
		}
	}

	return 0;
}

static void 
processCommandLineArguments (int argc, char *argv[])
{
	int i, cluster, proc;
	char *arg, *at, *daemonname;
	
{'fraction_non_alphanumeric': 0.1276767314756742, 'fraction_numerical': 0.019711495385718127, 'mean_word_length': 4.394876752054133, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7624408', 'n_tokens_mistral': 4285, 'n_tokens_neox': 3891, 'n_words': 1136}