/* This function reads of a ClaimId string, optional classad, and eom from the given stream. It looks up that ClaimId in the resmgr to find the corresponding Resource*. If such a Resource is found, we return the pointer to it, otherwise, we return NULL. */ Resource* stream_to_rip( Stream* stream, ClassAd * pad ) { char* id = NULL; Resource* rip; stream->decode(); if( ! stream->get_secret(id) ) { dprintf( D_ALWAYS, "Can't read ClaimId\n" ); free( id ); return NULL; } // if we are not ad end of message, then there may be a classad payload containing argument options. if (pad && ! stream->peek_end_of_message()) { if ( ! getClassAd(stream, *pad)) { dprintf( D_ALWAYS, "Can't read options ClassAd after ClaimId\n"); } } if( ! stream->end_of_message() ) { dprintf( D_ALWAYS, "Can't read end_of_message\n" ); free( id ); return NULL; } rip = resmgr->get_by_cur_id( id ); if( !rip ) { ClaimIdParser idp( id ); dprintf( D_ALWAYS, "Error: can't find resource with ClaimId (%s) -- perhaps this claim was already removed?\n", idp.publicClaimId() ); free( id ); return NULL; } free( id ); return rip; }
/* Takes sinful address of startd and sends it the given cmd, along with the capability and an end_of_message. */ int send_cmd_to_startd(char *sin_host, char *capability, int cmd) { ReliSock* sock = NULL; Daemon startd (DT_STARTD, sin_host, NULL); if (!(sock = (ReliSock*)startd.startCommand(cmd, Stream::reli_sock, 20))) { dprintf( D_ALWAYS, "Can't connect to startd at %s\n", sin_host ); return -1; } // send the capability ClaimIdParser idp( capability ); dprintf(D_FULLDEBUG, "send capability %s\n", idp.publicClaimId() ); if(!sock->code(capability)){ dprintf( D_ALWAYS, "sock->code(%s) failed.\n", idp.publicClaimId() ); delete sock; return -3; } // send end of message if( !sock->end_of_message() ) { dprintf( D_ALWAYS, "end_of_message failed\n" ); delete sock; return -4; } dprintf( D_FULLDEBUG, "Sent command %d to startd at %s with cap %s\n", cmd, sin_host, idp.publicClaimId() ); delete sock; return 0; }
bool ScriptInterface::EnumeratePropertyNamesWithPrefix(JS::HandleValue objVal, const char* prefix, std::vector<std::string>& out) { JSAutoRequest rq(m->m_cx); if (!objVal.isObjectOrNull()) { LOGERROR("EnumeratePropertyNamesWithPrefix expected object type!"); return false; } if(objVal.isNull()) return true; // reached the end of the prototype chain JS::RootedObject obj(m->m_cx, &objVal.toObject()); JS::RootedObject it(m->m_cx, JS_NewPropertyIterator(m->m_cx, obj)); if (!it) return false; while (true) { JS::RootedId idp(m->m_cx); JS::RootedValue val(m->m_cx); if (! JS_NextProperty(m->m_cx, it, idp.address()) || ! JS_IdToValue(m->m_cx, idp, &val)) return false; if (val.isUndefined()) break; // end of iteration if (!val.isString()) continue; // ignore integer properties JS::RootedString name(m->m_cx, val.toString()); size_t len = strlen(prefix)+1; std::vector<char> buf(len); size_t prefixLen = strlen(prefix) * sizeof(char); JS_EncodeStringToBuffer(m->m_cx, name, &buf[0], prefixLen); buf[len-1]= '\0'; if(0 == strcmp(&buf[0], prefix)) { size_t len; const jschar* chars = JS_GetStringCharsAndLength(m->m_cx, name, &len); out.push_back(std::string(chars, chars+len)); } } // Recurse up the prototype chain JS::RootedObject prototype(m->m_cx); if (JS_GetPrototype(m->m_cx, obj, &prototype)) { JS::RootedValue prototypeVal(m->m_cx, JS::ObjectOrNullValue(prototype)); if (! EnumeratePropertyNamesWithPrefix(prototypeVal, prefix, out)) return false; } return true; }
static void op_idp(int byte, struct thread *thread) { obj_t *sp = thread->sp; obj_t x = sp[-2]; obj_t y = sp[-1]; if (x == y) sp[-2] = obj_True; else if (obj_is_fixnum(x) || obj_is_fixnum(y)) sp[-2] = obj_False; else if (idp(x, y)) sp[-2] = obj_True; else sp[-2] = obj_False; thread->sp = sp-1; }
static __inline__ bool singleton_instancep(obj_t thing, obj_t type) { return idp(thing, SING(type)->object); }
int part_send_job( int test_starter, char *host, int &reason, char *capability, char * /*schedd*/, PROC *proc, int &sd1, int &sd2, char **name) { int reply; ReliSock *sock = NULL; StartdRec stRec; PORTS ports; bool done = false; int retry_delay = 3; int num_retries = 0; // make sure we have the job classad InitJobAd(proc->id.cluster, proc->id.proc); while( !done ) { Daemon startd(DT_STARTD, host, NULL); if (!(sock = (ReliSock*)startd.startCommand ( ACTIVATE_CLAIM, Stream::reli_sock, 90))) { dprintf( D_ALWAYS, "startCommand(ACTIVATE_CLAIM) to startd failed\n"); goto returnfailure; } // Send the capability ClaimIdParser idp( capability ); dprintf(D_FULLDEBUG, "send capability %s\n", idp.publicClaimId() ); if( !sock->put_secret(capability) ) { dprintf( D_ALWAYS, "sock->put(\"%s\") failed\n",idp.publicClaimId()); goto returnfailure; } // Send the starter number if( test_starter ) { dprintf( D_ALWAYS, "Requesting Alternate Starter %d\n", test_starter ); } else { dprintf( D_ALWAYS, "Requesting Primary Starter\n" ); } if( !sock->code(test_starter) ) { dprintf( D_ALWAYS, "sock->code(%d) failed\n", test_starter ); goto returnfailure; } // Send the job info if( !JobAd->put(*sock) ) { dprintf( D_ALWAYS, "failed to send job ad\n" ); goto returnfailure; } if( !sock->end_of_message() ) { dprintf( D_ALWAYS, "failed to send message to startd\n" ); goto returnfailure; } // We're done sending. Now, get the reply. sock->decode(); if( !sock->code(reply) || !sock->end_of_message() ) { dprintf( D_ALWAYS, "failed to receive reply from startd\n" ); goto returnfailure; } switch( reply ) { case OK: dprintf( D_ALWAYS, "Shadow: Request to run a job was ACCEPTED\n" ); done = true; break; case NOT_OK: dprintf( D_ALWAYS, "Shadow: Request to run a job was REFUSED\n"); goto returnfailure; break; case CONDOR_TRY_AGAIN: num_retries++; dprintf( D_ALWAYS, "Shadow: Request to run a job was TEMPORARILY REFUSED\n" ); if( num_retries > 20 ) { dprintf( D_ALWAYS, "Shadow: Too many retries, giving up.\n" ); goto returnfailure; } delete sock; dprintf( D_ALWAYS, "Shadow: will try again in %d seconds\n", retry_delay ); sleep( retry_delay ); break; default: dprintf(D_ALWAYS,"Unknown reply from startd for command ACTIVATE_CLAIM\n"); dprintf(D_ALWAYS,"Shadow: Request to run a job was REFUSED\n"); goto returnfailure; break; } } /* start flock : dhruba */ sock->decode(); memset( &stRec, '\0', sizeof(stRec) ); if( !sock->code(stRec) || !sock->end_of_message() ) { dprintf(D_ALWAYS, "Can't read reply from startd.\n"); goto returnfailure; } ports = stRec.ports; if( stRec.ip_addr ) { host = stRec.server_name; if(name) { *name = strdup(stRec.server_name); } dprintf(D_FULLDEBUG, "host = %s inet_addr = 0x%x port1 = %d port2 = %d\n", host, stRec.ip_addr,ports.port1, ports.port2 ); } else { dprintf(D_FULLDEBUG, "host = %s port1 = %d port2 = %d\n", host, ports.port1, ports.port2 ); } if( ports.port1 == 0 ) { dprintf( D_ALWAYS, "Shadow: Request to run a job on %s was REFUSED\n", host ); goto returnfailure; } /* end flock ; dhruba */ // We don't use the server_name in the StartdRec, because our // DNS query may fail or may give us the wrong IP address // (either because it's stale or because we're talking to a // machine with multiple network interfaces). Sadly, we can't // use the ip_addr either, because the startd doesn't send it in // the correct byte ordering on little-endian machines. So, we // grab the IP address from the ReliSock, since we konw the // startd always uses the same IP address for all of its // communication. char sinfulstring[SINFUL_STRING_BUF_SIZE]; generate_sinful(sinfulstring, SINFUL_STRING_BUF_SIZE, sock->peer_ip_str(), ports.port1); if( (sd1 = do_connect(sinfulstring, (char *)0, (u_short)ports.port1)) < 0 ) { dprintf( D_ALWAYS, "failed to connect to scheduler on %s\n", sinfulstring ); goto returnfailure; } generate_sinful(sinfulstring, SINFUL_STRING_BUF_SIZE, sock->peer_ip_str(), ports.port2); if( (sd2 = do_connect(sinfulstring, (char *)0, (u_short)ports.port2)) < 0 ) { dprintf( D_ALWAYS, "failed to connect to scheduler on %s\n", sinfulstring ); close(sd1); goto returnfailure; } delete sock; sock = NULL; if ( stRec.server_name ) { free( stRec.server_name ); } return 0; returnfailure: reason = JOB_NOT_STARTED; delete sock; return -1; }
void USER_IMPL::AddTraffStatD(int dir, uint32_t ip, uint32_t len) #endif { STG_LOCKER lock(&mutex); if (!connected || tariff == NULL) return; double cost = 0; DIR_TRAFF dt(down); int64_t traff = tariff->GetTraffByType(up.ConstData()[dir], down.ConstData()[dir]); int64_t threshold = tariff->GetThreshold(dir) * 1024 * 1024; dt[dir] += len; int tt = tariff->GetTraffType(); if (tt == TARIFF::TRAFF_DOWN || tt == TARIFF::TRAFF_UP_DOWN || // Check NEW traff data (tt == TARIFF::TRAFF_MAX && up.ConstData()[dir] <= dt[dir])) { double dc = 0; if (traff < threshold && traff + len >= threshold) { // cash = partBeforeThreshold * priceBeforeThreshold + // partAfterThreshold * priceAfterThreshold int64_t before = threshold - traff; // Chunk part before threshold int64_t after = len - before; // Chunk part after threshold dc = tariff->GetPriceWithTraffType(up.ConstData()[dir], down.ConstData()[dir], // Traff before chunk dir, stgTime) * before + tariff->GetPriceWithTraffType(up.ConstData()[dir], dt[dir], // Traff after chunk dir, stgTime) * after; } else { dc = tariff->GetPriceWithTraffType(up.ConstData()[dir], down.ConstData()[dir], dir, stgTime) * len; } if (freeMb.ConstData() <= 0) // FreeMb is exhausted cost = dc; else if (freeMb.ConstData() < dc) // FreeMb is partially exhausted cost = dc - freeMb.ConstData(); property.Stat().freeMb -= dc; property.Stat().cash -= cost; cash.ModifyTime(); freeMb.ModifyTime(); } down = dt; sessionDownload[dir] += len; sessionDownloadModTime = stgTime; //Add detailed stat if (!settings->GetWriteFreeMbTraffCost() && freeMb.ConstData() >= 0) cost = 0; #ifdef TRAFF_STAT_WITH_PORTS IP_DIR_PAIR idp(ip, dir, port); #else IP_DIR_PAIR idp(ip, dir); #endif std::map<IP_DIR_PAIR, STAT_NODE>::iterator lb; lb = traffStat.lower_bound(idp); if (lb == traffStat.end() || lb->first != idp) { traffStat.insert(lb, std::make_pair(idp, STAT_NODE(0, len, cost))); } else { lb->second.cash += cost; lb->second.down += len; } }