bool JobServerJobLogConsumer::NewClassAd(const char *_key, const char */*type*/, const char */*target*/) { dprintf(D_FULLDEBUG, "JobServerJobLogConsumer::NewClassAd processing _key='%s'\n", _key); // ignore the marker if (strcmp(_key,"0.0") == 0) { return true; } const char* key_dup = strdup(_key); if ('0' == _key[0]) { // Cluster ad if (g_jobs.end() == g_jobs.find(_key)) { Job* new_cluster_job = new Job(key_dup); new_cluster_job->SetImpl(new ClusterJobImpl(key_dup)); g_jobs[key_dup] = new_cluster_job; } } else { // Proc ad // first see if some other proc job is here // ie history if (g_jobs.end() != g_jobs.find(_key)) { return true; } PROC_ID proc = getProcByString(_key); MyString cluster_key; cluster_key.sprintf("0%d.-1", proc.cluster); const char *cluster_dup = cluster_key.StrDup(); JobCollectionType::const_iterator element = g_jobs.find(cluster_dup); ClusterJobImpl* cluster_impl = NULL; // either find an existing cluster parent or create a new one if (g_jobs.end() == element) { // didn't find an existing job so create a new one Job* new_cluster_job = new Job(cluster_dup); cluster_impl = new ClusterJobImpl(cluster_dup); new_cluster_job->SetImpl(cluster_impl); g_jobs[cluster_dup] = new_cluster_job; } else { // found an existing job - we'll assume it is the cluster parent cluster_impl = static_cast<ClusterJobImpl*>((*element).second->GetImpl()); } Job* new_proc_job = new Job(key_dup); new_proc_job->SetImpl(new LiveJobImpl(key_dup, cluster_impl)); g_jobs[key_dup] = new_proc_job; } return true; }
bool NewClassAdJobLogConsumer::NewClassAd(const char *key, const char * /*type*/, const char * /*target*/) { classad::ClassAd* ad; bool using_existing_ad = false; ad = m_collection.GetClassAd(key); if (ad && ad->size() == 0) { // This is a cluster ad created in advance so that // children could be chained from it. using_existing_ad = true; } else { ad = new classad::ClassAd(); } // Chain this ad to its parent, if any. PROC_ID proc = getProcByString(key); if(proc.proc >= 0) { char cluster_key[PROC_ID_STR_BUFLEN]; // NOTE: cluster keys start with a 0: e.g. 021.-1 sprintf(cluster_key,"0%d.-1", proc.cluster); classad::ClassAd* cluster_ad = m_collection.GetClassAd(cluster_key); if (!cluster_ad) { // The cluster ad doesn't exist yet. This is expected. // For example, once the job queue is rewritten (i.e. // truncated), the order of entries in it is arbitrary. cluster_ad = new classad::ClassAd(); if (!m_collection.AddClassAd(cluster_key, cluster_ad)) { dprintf(D_ALWAYS, "error processing %s: failed to add '%s' to " "ClassAd collection.\n", m_reader ? m_reader->GetClassAdLogFileName() : "(null)", cluster_key); delete ad; return true; // XXX: why is this ok? } } ad->ChainToAd(cluster_ad); } if (!using_existing_ad) { if (!m_collection.AddClassAd(key, ad)) { dprintf(D_ALWAYS, "error processing %s: failed to add '%s' to " "ClassAd collection.\n", m_reader ? m_reader->GetClassAdLogFileName() : "(null)", key); // XXX: why is this ok? } } return true; }
void printNewMessages( ClassAd* result_ad, StringList* ids ) { char* tmp; char* msg; PROC_ID job_id; bool rval; JobActionResults results; results.readResults( result_ad ); ids->rewind(); while( (tmp = ids->next()) ) { job_id = getProcByString( tmp ); rval = results.getResultString( job_id, &msg ); if( rval ) { fprintf( stdout, "%s\n", msg ); } else { fprintf( stderr, "%s\n", msg ); } free( msg ); } }
bool HTCondorPeek::parse_args(int argc, char *argv[]) { std::string job_id; myDistro->Init( argc, argv ); config(); for (int i=1; i<argc; i++) { if (!strcmp(argv[i],"-help")) { usage(argv[0]); exit(0); } else if (!strcmp(argv[i],"-pool")) { i++; if(i==argc || !argv[i]) { fprintf(stderr,"-pool requires an argument.\n\n"); usage(argv[0]); exit(1); } m_pool = argv[i]; } else if (!strcmp(argv[i],"-name")) { i++; if (i==argc || !argv[i]) { fprintf(stderr,"-name requires an argument.\n\n"); usage(argv[0]); exit(1); } m_name = argv[i]; } else if (!strcmp(argv[i],"-maxbytes")) { i++; if(i==argc || !argv[i] || *argv[i] == '-') { fprintf(stderr,"-maxbytes requires an argument.\n\n"); usage(argv[0]); exit(1); } if ( ! parse_integer<size_t>(argv[i], m_max_bytes)) { fprintf(stderr, "Error: maxbytes (%s) is not valid\n\n", argv[i]); usage(argv[0]); exit(1); } } else if(!strcmp(argv[i],"-version")) { version(); exit(0); } else if(!strcmp(argv[i],"-debug")) { dprintf_set_tool_debug("TOOL", 0); } else if(!strcmp(argv[i],"-no-stdout")) { m_transfer_stdout = false; } else if(!strcmp(argv[i],"-stderr")) { m_transfer_stderr = true; } else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "-follow")) { m_follow = true; } else if (!strcmp(argv[i], "-auto-retry")) { m_auto_retry = true; } else if(!job_id.size()) { job_id = argv[i]; } else { m_filenames.push_back(argv[i]); m_offsets.push_back(-1); } } if( !m_transfer_stdout && !m_transfer_stderr && !m_filenames.size() ) { fprintf(stderr,"No file transfer specified.\n\n"); usage(argv[0]); exit(1); } if (!job_id.size()) { std::cerr << "Job ID not specified." << std::endl; usage(argv[0]); exit(1); } m_id = getProcByString(job_id.c_str()); if (m_id.cluster == -1) { std::cerr << "Invalid Job ID: " << job_id << std::endl; usage(argv[0]); exit(1); } return true; }
void LiveJobImpl::Set ( const char *_name, const char *_value ) { if ( strcasecmp ( _name, ATTR_JOB_SUBMISSION ) == 0 ) { std::string val = TrimQuotes( _value ); // TODO: grab the cluster from our key PROC_ID id = getProcByString(m_job->GetKey()); if (m_job) { m_job->SetSubmission ( val.c_str(), id.cluster ); } } // our status is changing...decrement for old one if ( strcasecmp ( _name, ATTR_JOB_STATUS ) == 0 ) { if ( m_job ) { m_job->SetStatus(this->GetStatus()); m_job->DecrementSubmission (); } } if ( strcasecmp ( _name, ATTR_OWNER ) == 0 ) { // need to leave an owner for this job // to be picked up soon // if we are in here, we don't have m_submission PROC_ID id = getProcByString(m_job->GetKey()); std::string val = TrimQuotes( _value ); g_ownerless_clusters[id.cluster] = val; m_job->UpdateSubmission(id.cluster,val.c_str()); } // parse the type ExprTree *expr; if ( ParseClassAdRvalExpr ( _value, expr ) ) { dprintf ( D_ALWAYS, "error: parsing %s[%s] = %s, skipping\n", m_job->GetKey(), _name, _value ); return; } // add this value to the classad classad::Value value; expr->Evaluate(value); switch ( value.GetType() ) { case classad::Value::INTEGER_VALUE: int i; from_string<int> ( i, std::string ( _value ), std::dec ); m_full_ad->Assign ( _name, i ); break; case classad::Value::REAL_VALUE: float f; from_string<float> ( f, std::string ( _value ), std::dec ); m_full_ad->Assign ( _name, f ); break; case classad::Value::STRING_VALUE: m_full_ad->Assign ( _name, _value ); break; default: m_full_ad->AssignExpr ( _name, _value ); break; } delete expr; expr = NULL; // our status has changed...increment for new one if ( strcasecmp ( _name, ATTR_JOB_STATUS ) == 0 ) { if ( m_job ) { m_job->SetStatus(this->GetStatus()); m_job->IncrementSubmission (); } } }