void test_user_policy_on_exit_remove_yes(void) { int val; int action; char buf[4096]; ClassAd *result; ClassAd *jad = new ClassAd; if (jad == NULL) { printf("Out of memory!\n"); exit(EXIT_FAILURE); } printf("==========================================\n"); printf("Testing User Policy on On Exit Remove: YES\n"); /* set up the classad */ sprintf(buf, "%s = %d", ATTR_ON_EXIT_CODE, 0); jad->Insert(buf); sprintf(buf, "%s = 42", ATTR_TOTAL_SUSPENSIONS); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_PERIODIC_HOLD_CHECK); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_PERIODIC_REMOVE_CHECK); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_ON_EXIT_HOLD_CHECK); jad->Insert(buf); sprintf(buf, "%s = TotalSuspensions == 42", ATTR_ON_EXIT_REMOVE_CHECK); jad->Insert(buf); result = user_job_policy(jad); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if(val == true) { printf("An error happened\n"); delete result; return; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == true) { printf("%s was true.\n", ATTR_TAKE_ACTION); result->LookupInteger(ATTR_USER_POLICY_ACTION, action); printf("Action is: %s\n", action==REMOVE_JOB?"REMOVE_JOB":action==HOLD_JOB?"HOLD_JOB": "UNKNOWN"); result->LookupString(ATTR_USER_POLICY_FIRING_EXPR, buf); printf("Reason for action: %s\n", buf); } else { printf("Something went wrong. I should have had an action to take.\n"); } }
void test_user_policy_on_exit_remove_no(void) { int val; char buf[4096]; ClassAd *result; ClassAd *jad = new ClassAd; if (jad == NULL) { printf("Out of memory!\n"); exit(EXIT_FAILURE); } printf("========================================\n"); printf("Testing User Policy on On Exit Remove: NO\n"); /* set up the classad */ sprintf(buf, "%s = %d", ATTR_ON_EXIT_CODE, 0); jad->Insert(buf); sprintf(buf, "%s = 40", ATTR_TOTAL_SUSPENSIONS); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_PERIODIC_HOLD_CHECK); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_PERIODIC_REMOVE_CHECK); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_ON_EXIT_HOLD_CHECK); jad->Insert(buf); sprintf(buf, "%s = TotalSuspensions == 42", ATTR_ON_EXIT_REMOVE_CHECK); jad->Insert(buf); result = user_job_policy(jad); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if(val == true) { printf("An error happened\n"); delete result; return; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == true) { printf("Something went wrong. I should not have had an action.\n"); } else { printf("Ignoring correctly.\n"); } }
bool mayUserForceRm( ) { const char * PARAM_ALLOW_FORCE_RM = "ALLOW_FORCE_RM"; char* tmp = param( PARAM_ALLOW_FORCE_RM ); if( tmp == NULL) { // Not present. Assume TRUE (old behavior). return true; } ClassAd tmpAd; const char * TESTNAME = "test"; if(tmpAd.AssignExpr(TESTNAME, tmp) == FALSE) { // Error parsing, most likely. Warn and assume TRUE. fprintf(stderr, "The configuration setting %s may be invalid. Treating as TRUE.\n", PARAM_ALLOW_FORCE_RM); free(tmp); return true; } free(tmp); int is_okay = 0; if(tmpAd.EvalBool(TESTNAME, 0, is_okay)) { return is_okay; } else { // Something went wrong. May be undefined because // we need a job classad. Assume TRUE. return true; } }
void test_oldstyle_with_exit(void) { int val; int action; char buf[4096]; ClassAd *result; ClassAd *jad = new ClassAd; if (jad == NULL) { printf("Out of memory!\n"); exit(EXIT_FAILURE); } printf("==================================================\n"); printf("Testing OldStyle job where it is marked as exited.\n"); /* An oldstyle classad would have this */ sprintf(buf, "%s = %d", ATTR_COMPLETION_DATE, 10); /* non zero */ jad->Insert(buf); result = user_job_policy(jad); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if(val == true) { printf("An error happened\n"); delete result; return; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == true) { printf("%s was true.\n", ATTR_TAKE_ACTION); result->LookupInteger(ATTR_USER_POLICY_ACTION, action); printf("Action is: %s\n", action==REMOVE_JOB?"REMOVE_JOB":action==HOLD_JOB?"HOLD_JOB": "UNKNOWN"); result->LookupString(ATTR_USER_POLICY_FIRING_EXPR, buf); printf("Reason for action: %s\n", buf); } else { printf("Something went wrong. I should have had an action to take.\n"); } }
void test_oldstyle_with_no_exit(void) { int val; char buf[4096]; ClassAd *result; ClassAd *jad = new ClassAd; if (jad == NULL) { printf("Out of memory!\n"); exit(EXIT_FAILURE); } printf("======================================================\n"); printf("Testing OldStyle job where it is NOT marked as exited.\n"); /* An oldstyle classad would have this */ sprintf(buf, "%s = %d", ATTR_COMPLETION_DATE, 0); jad->Insert(buf); result = user_job_policy(jad); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if(val == true) { printf("An error happened\n"); delete result; return; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == true) { printf("Something went wrong. I should not have had an action.\n"); } else { printf("Ignoring correctly.\n"); } delete result; }
void MachAttributes::start_benchmarks( Resource* rip, int &count ) { count = 0; ClassAd* cp = rip->r_classad; if( rip->isSuspendedForCOD() ) { // if there's a COD job, we definitely don't want to run // benchmarks return; } // This should be a bool, but EvalBool() expects an int int run_benchmarks = 0; if ( cp->EvalBool( ATTR_RUN_BENCHMARKS, cp, run_benchmarks ) == 0 ) { run_benchmarks = 0; } if ( !run_benchmarks ) { return; } dprintf( D_ALWAYS, "State change: %s is TRUE\n", ATTR_RUN_BENCHMARKS ); if( (rip->state() != unclaimed_state) && (rip->activity() != idle_act) ) { dprintf( D_ALWAYS, "Tried to run benchmarks when not idle, aborting.\n" ); return; } ASSERT( bench_job_mgr != NULL ); // Enter benchmarking activity BEFORE invoking StartBenchmarks(). // If StartBenchmarks() will return to idle activity upon failure // to launch benchmarks, or upon completion of benchmarks // (in the reaper). rip->change_state( benchmarking_act ); bench_job_mgr->StartBenchmarks( rip, count ); // However, if StartBenchmarks set count to zero, that means // there are no benchmarks configured to run now. So set the activity // back to idle. if ( count == 0 ) { rip->change_state( idle_act ); } }
/* After the job exits, look into the classad to see if certain things are true or not */ void static_policy(void) { ClassAd *result; int val; int action; char buf[4096]; char buf2[4096]; /* See what the user job policy has in store for me. */ result = user_job_policy(JobAd); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if (val == 1) { dprintf(D_ALWAYS, "There was an error in the static policy\n"); delete result; return; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == 1) { result->LookupString(ATTR_USER_POLICY_FIRING_EXPR, buf, sizeof(buf)); result->LookupInteger(ATTR_USER_POLICY_ACTION, action); switch(action) { case REMOVE_JOB: dprintf(D_ALWAYS, "Static Policy: removing job because %s has " "become true\n", buf); /* do nothing, the nasty old shadow logic takes it from here. */ delete result; return; break; case HOLD_JOB: dprintf(D_ALWAYS, "Static Policy: holding job because %s has " "become true\n", buf); delete result; sprintf(buf, "Your job has been held because %s has become " "true\n", ATTR_PERIODIC_HOLD_CHECK); sprintf(buf2, "Your job has been held because %s has become " "true", ATTR_PERIODIC_HOLD_CHECK); /* This exits */ HoldJob(buf, buf2, CONDOR_HOLD_CODE_JobPolicy, 0); return; break; default: dprintf(D_ALWAYS, "WARNING! Ignoring unknown action type in " "periodic_policy()\n"); delete result; return; break; } } delete result; dprintf( D_ALWAYS, "Static policy: don't remove on exit\n" ); EXCEPT( "Job didn't exit under conditions specifed in %s", ATTR_ON_EXIT_REMOVE_CHECK ); }
/* evaluate various periodic checks during the running of the shadow and perform actions based upon what special attributes evaluate to. */ bool periodic_policy(void) { ClassAd *result; int val; int action; char buf[4096]; char buf2[4096]; /* See what the user job policy has in store for me. */ result = user_job_policy(JobAd); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if (val == 1) { dprintf(D_ALWAYS, "There was an error in the periodic policy\n"); delete result; return false; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == 1) { result->LookupString(ATTR_USER_POLICY_FIRING_EXPR, buf, sizeof(buf)); result->LookupInteger(ATTR_USER_POLICY_ACTION, action); switch(action) { case REMOVE_JOB: dprintf(D_ALWAYS, "Periodic Policy: removing job because %s " "has become true\n", buf); /* set some yucky global variables */ JobStatus = 0; JobExitStatus = 0; delete result; return true; break; case HOLD_JOB: sprintf(buf, "Periodic Policy: holding job because %s has " "become true\n", buf); sprintf(buf, "Your job has been held because %s has become " "true\n", ATTR_PERIODIC_HOLD_CHECK); sprintf(buf2, "Your job has been held because %s has become " "true", ATTR_PERIODIC_HOLD_CHECK); delete result; /* This exits */ HoldJob(buf, buf2, CONDOR_HOLD_CODE_JobPolicy, 0); break; default: dprintf(D_ALWAYS, "WARNING! Ignoring unknown action type in " "periodic_policy()\n"); delete result; return false; break; } } delete result; return false; }
void OfflineCollectorPlugin::update ( int command, ClassAd &ad ) { dprintf ( D_FULLDEBUG, "In OfflineCollectorPlugin::update ( %d )\n", command ); /* bail out if the plug-in is not enabled */ if ( !enabled () ) { return; } /* make sure the command is relevant to us */ if ( UPDATE_STARTD_AD_WITH_ACK != command && UPDATE_STARTD_AD != command && MERGE_STARTD_AD != command ) { return; } MyString s; const char *key = makeOfflineKey(ad,s); if (!key) return; /* report whether this ad is "off-line" or not and update the ad accordingly. */ int offline = FALSE, lifetime = 0; bool offline_explicit = false; if( ad.EvalBool( ATTR_OFFLINE, NULL, offline ) ) { offline_explicit = true; } if ( MERGE_STARTD_AD == command ) { mergeClassAd( ad, key ); return; } // Rewrite the ad if it is going offline if ( UPDATE_STARTD_AD_WITH_ACK == command && !offline_explicit ) { /* set the off-line state of the machine */ offline = TRUE; /* get the off-line expiry time (default to INT_MAX) */ lifetime = param_integer ( "OFFLINE_EXPIRE_ADS_AFTER", INT_MAX ); /* reset any values in the ad that may interfere with a match in the future */ /* Reset Condor state */ ad.Assign ( ATTR_STATE, state_to_string ( unclaimed_state ) ); ad.Assign ( ATTR_ACTIVITY, activity_to_string ( idle_act ) ); ad.Assign ( ATTR_ENTERED_CURRENT_STATE, 0 ); ad.Assign ( ATTR_ENTERED_CURRENT_ACTIVITY, 0 ); /* Set the heart-beat time */ int now = static_cast<int> ( time ( NULL ) ); ad.Assign ( ATTR_MY_CURRENT_TIME, now ); ad.Assign ( ATTR_LAST_HEARD_FROM, now ); /* Reset machine load */ ad.Assign ( ATTR_LOAD_AVG, 0.0 ); ad.Assign ( ATTR_CONDOR_LOAD_AVG, 0.0 ); ad.Assign ( ATTR_TOTAL_LOAD_AVG, 0.0 ); ad.Assign ( ATTR_TOTAL_CONDOR_LOAD_AVG, 0.0 ); /* Reset CPU load */ ad.Assign ( ATTR_CPU_IS_BUSY, false ); ad.Assign ( ATTR_CPU_BUSY_TIME, 0 ); /* Reset keyboard and mouse times */ ad.Assign ( ATTR_KEYBOARD_IDLE, INT_MAX ); ad.Assign ( ATTR_CONSOLE_IDLE, INT_MAX ); /* any others? */ dprintf ( D_FULLDEBUG, "Machine ad lifetime: %d\n", lifetime ); /* record the new values as specified above */ ad.Assign ( ATTR_OFFLINE, (bool)offline ); if ( lifetime > 0 ) { ad.Assign ( ATTR_CLASSAD_LIFETIME, lifetime ); } } /* if it is off-line then add it to the list; otherwise, remove it. */ if ( offline > 0 ) { persistentStoreAd(key,ad); } else { persistentRemoveAd(key); } }
void test_user_policy_on_exit_hold_no(void) { int val; int action; char buf[4096]; ClassAd *result; ClassAd *jad = new ClassAd; if (jad == NULL) { printf("Out of memory!\n"); exit(EXIT_FAILURE); } printf("=======================================\n"); printf("Testing User Policy on On Exit Hold: NO\n"); /* set up the classad */ sprintf(buf, "%s = %d", ATTR_ON_EXIT_CODE, 0); jad->Insert(buf); sprintf(buf, "%s = 40", ATTR_TOTAL_SUSPENSIONS); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_PERIODIC_HOLD_CHECK); jad->Insert(buf); sprintf(buf, "%s = FALSE", ATTR_PERIODIC_REMOVE_CHECK); jad->Insert(buf); sprintf(buf, "%s = TotalSuspensions == 42", ATTR_ON_EXIT_HOLD_CHECK); jad->Insert(buf); sprintf(buf, "%s = TRUE", ATTR_ON_EXIT_REMOVE_CHECK); jad->Insert(buf); result = user_job_policy(jad); result->EvalBool(ATTR_USER_POLICY_ERROR, result, val); if(val == true) { printf("An error happened\n"); delete result; return; } result->EvalBool(ATTR_TAKE_ACTION, result, val); if (val == true) { printf("%s was true.\n", ATTR_TAKE_ACTION); result->LookupInteger(ATTR_USER_POLICY_ACTION, action); printf("Action is: %s\n", action==REMOVE_JOB?"REMOVE_JOB":action==HOLD_JOB?"HOLD_JOB": "UNKNOWN"); result->LookupString(ATTR_USER_POLICY_FIRING_EXPR, buf); printf("Reason for action: %s\n", buf); if (strcmp(ATTR_USER_POLICY_FIRING_EXPR, ATTR_ON_EXIT_HOLD_CHECK) == 0) { printf("Failed. I got removed because exit_hold was true.\n"); } else { printf("Success. I was removed because of %s, not because of %s\n", ATTR_ON_EXIT_REMOVE_CHECK, ATTR_ON_EXIT_HOLD_CHECK); } } else { printf("Ignoring correctly.\n"); } }