int main(int argc, char* argv[]) { enableMemLeakChecking(true); InitModuleObjects(); EnableSEHtoExceptionMapping(); if (argc<2) { usage(argv[0]); return -1; } SocketEndpoint dalieps(argv[1],DALI_SERVER_PORT); // endpoint of dali server Owned<IGroup> group = createIGroup(1,&dalieps); try { initClientProcess(group, DCR_Other); // I will add a DCR_Orbit at some point try { doStuff(); } catch (IException *e) { pexception(argv[0],e); e->Release(); } closedownClientProcess(); } catch (IException *e) { pexception(argv[0],e); e->Release(); } releaseAtoms(); return 0; }
void enableThorSlaveAsDaliClient() { #ifdef ISDALICLIENT PROGLOG("Slave activated as a Dali client"); const char *daliServers = globals->queryProp("@DALISERVERS"); if (!daliServers) throw MakeStringException(0, "No Dali server list specified"); Owned<IGroup> serverGroup = createIGroup(daliServers, DALI_SERVER_PORT); unsigned retry = 0; loop { try { LOG(MCdebugProgress, thorJob, "calling initClientProcess"); initClientProcess(serverGroup,DCR_ThorSlave, getFixedPort(TPORT_mp)); break; } catch (IJSOCK_Exception *e) { if ((e->errorCode()!=JSOCKERR_port_in_use)) throw; FLLOG(MCexception(e), thorJob, e,"InitClientProcess"); if (retry++>10) throw; e->Release(); LOG(MCdebugProgress, thorJob, "Retrying"); Sleep(retry*2000); } } setPasswordsFromSDS(); #endif }
DaliClient(const char* daliserver): serverGroup(createIGroup(daliserver, DALI_SERVER_PORT)) { if (!serverGroup) throw MakeStringException(0, "Could not instantiate IGroup"); if (!initClientProcess(serverGroup,DCR_Util)) throw MakeStringException(0, "Could not initializing client process"); setPasswordsFromSDS(); }
bool updateDaliEnv(IPropertyTree *env, bool forceGroupUpdate, const char *daliIp) { Owned<IPropertyTreeIterator> dalis = env->getElements("Software/DaliServerProcess/Instance"); if (!dalis||!dalis->first()) { fprintf(stderr,"Could not find DaliServerProcess\n"); return false; } SocketEndpoint daliep; loop { const char *ps = dalis->get().queryProp("@port"); unsigned port = ps?atoi(ps):0; if (!port) port = DALI_SERVER_PORT; daliep.set(dalis->get().queryProp("@netAddress"),port); if (daliIp && *daliIp) { SocketEndpoint testep; testep.set(daliIp,DALI_SERVER_PORT); if (testep.equals(daliep)) break; daliep.set(NULL,0); } if (!dalis->next()) break; if (!daliep.isNull()) { fprintf(stderr,"Ambiguous DaliServerProcess instance\n"); return false; } } if (daliep.isNull()) { fprintf(stderr,"Could not find DaliServerProcess instance\n"); return false; } SocketEndpointArray epa; epa.append(daliep); Owned<IGroup> group = createIGroup(epa); bool ret = true; initClientProcess(group, DCR_Util); StringBuffer response; if (querySDS().updateEnvironment(env, forceGroupUpdate, response)) { StringBuffer tmp; PROGLOG("Environment and node groups updated in dali at %s",daliep.getUrlStr(tmp).str()); } else ret = false; if (response.length()) WARNLOG("%s", response.str()); closedownClientProcess(); return ret; }
void testMultiCluster() { Owned<IGroup> grp1 = createIGroup("192.168.51.1-5"); Owned<IGroup> grp2 = createIGroup("192.168.16.1-5"); Owned<IGroup> grp3 = createIGroup("192.168.53.1-5"); queryNamedGroupStore().add("testgrp1",grp1); queryNamedGroupStore().add("testgrp2",grp2); queryNamedGroupStore().add("testgrp3",grp3); Owned<IFileDescriptor> fdesc = createFileDescriptor(); fdesc->setDefaultDir("/c$/thordata/test"); fdesc->setPartMask("testfile1._$P$_of_$N$"); fdesc->setNumParts(5); ClusterPartDiskMapSpec mapping; fdesc->addCluster(grp1,mapping); fdesc->addCluster(grp2,mapping); fdesc->addCluster(grp3,mapping); queryDistributedFileDirectory().removeEntry("test::testfile1",UNKNOWN_USER); Owned<IDistributedFile> file = queryDistributedFileDirectory().createNew(fdesc); queryDistributedFileDirectory().removeEntry("test::testfile1",UNKNOWN_USER); file->attach("test::testfile1",UNKNOWN_USER); StringBuffer name; unsigned i; for (i=0;i<file->numClusters();i++) PROGLOG("cluster[%d] = %s",i,file->getClusterName(i,name.clear()).str()); file.clear(); file.setown(queryDistributedFileDirectory().lookup("test::testfile1",UNKNOWN_USER)); for (i=0;i<file->numClusters();i++) PROGLOG("cluster[%d] = %s",i,file->getClusterName(i,name.clear()).str()); file.clear(); file.setown(queryDistributedFileDirectory().lookup("test::testfile1@testgrp1",UNKNOWN_USER)); for (i=0;i<file->numClusters();i++) PROGLOG("cluster[%d] = %s",i,file->getClusterName(i,name.clear()).str()); file.clear(); queryDistributedFileDirectory().removePhysical("test::testfile1@testgrp2",UNKNOWN_USER); file.setown(queryDistributedFileDirectory().lookup("test::testfile1",UNKNOWN_USER)); for (i=0;i<file->numClusters();i++) PROGLOG("cluster[%d] = %s",i,file->getClusterName(i,name.clear()).str()); }
void CEspConfig::initDali(const char *servers) { if (servers!=NULL && *servers!=0 && !daliClientActive()) { DBGLOG("Initializing DALI client [servers = %s]", servers); useDali=true; // Create server group Owned<IGroup> serverGroup = createIGroup(servers, DALI_SERVER_PORT); if (!serverGroup) throw MakeStringException(0, "Could not instantiate dali IGroup"); // Initialize client process if (!initClientProcess(serverGroup, DCR_EspServer)) throw MakeStringException(0, "Could not initialize dali client"); setPasswordsFromSDS(); serverstatus = new CSDSServerStatus("ESPserver"); } }
void processMessage(CMessageBuffer &mb) { ICoven &coven=queryCoven(); SessionId id; int fn; mb.read(fn); switch (fn) { case MSR_REGISTER_PROCESS_SESSION: { acceptConnections.wait(); acceptConnections.signal(); Owned<INode> node(deserializeINode(mb)); Owned<INode> servernode(deserializeINode(mb)); // hopefully me, but not if forwarded int role=0; if (mb.length()-mb.getPos()>=sizeof(role)) { // a capability block present mb.read(role); if (!manager.authorizeConnection(role,false)) { SocketEndpoint sender = mb.getSender(); mb.clear(); coven.reply(mb); MilliSleep(100+getRandom()%1000); // Causes client to 'work' for a short time. Owned<INode> node = createINode(sender); coven.disconnect(node); break; } #ifdef _DEBUG StringBuffer eps; PROGLOG("Connection to %s authorized",mb.getSender().getUrlStr(eps).str()); #endif } IGroup *covengrp; id = manager.registerClientProcess(node.get(),covengrp,(DaliClientRole)role); mb.clear().append(id); if (covengrp->rank(servernode)==RANK_NULL) { // must have been redirected covengrp->Release(); // no good, so just use one we know about (may use something more sophisticated later) INode *na = servernode.get(); covengrp = createIGroup(1, &na); } covengrp->serialize(mb); covengrp->Release(); coven.reply(mb); } break; case MSR_SECONDARY_REGISTER_PROCESS_SESSION: { mb.read(id); Owned<INode> node (deserializeINode(mb)); int role; mb.read(role); manager.addProcessSession(id,node.get(),(DaliClientRole)role); mb.clear(); coven.reply(mb); } break; case MSR_REGISTER_SESSION: { SecurityToken tok; SessionId parentid; mb.read(tok).read(parentid); SessionId id = manager.registerSession(tok,parentid); mb.clear().append(id); coven.reply(mb); } break; case MSR_SECONDARY_REGISTER_SESSION: { mb.read(id); manager.addSession(id); mb.clear(); coven.reply(mb); } break; case MSR_LOOKUP_PROCESS_SESSION: { // looks up from node or from id Owned<INode> node (deserializeINode(mb)); if (node->endpoint().isNull()&&(mb.length()-mb.getPos()>=sizeof(id))) { mb.read(id); INode *n = manager.getProcessSessionNode(id); if (n) node.setown(n); node->serialize(mb.clear()); } else { id = manager.lookupProcessSession(node.get()); mb.clear().append(id); } coven.reply(mb); } break; case MSR_STOP_SESSION: { SessionId sessid; bool failed; mb.read(sessid).read(failed); manager.stopSession(sessid,failed); mb.clear(); coven.reply(mb); } break; case MSR_LOOKUP_LDAP_PERMISSIONS: { StringAttr key; StringAttr obj; Owned<IUserDescriptor> udesc=createUserDescriptor(); StringAttr username; StringAttr passwordenc; mb.read(key).read(obj); udesc->deserialize(mb); #ifndef _NO_DALIUSER_STACKTRACE //following debug code to be removed StringBuffer sb; udesc->getUserName(sb); if (0==sb.length()) { DBGLOG("UNEXPECTED USER (NULL) in dasess.cpp CSessionRequestServer::processMessage() line %d", __LINE__); } #endif unsigned auditflags = 0; if (mb.length()-mb.getPos()>=sizeof(auditflags)) mb.read(auditflags); int err = 0; int ret=manager.getPermissionsLDAP(key,obj,udesc,auditflags,&err); mb.clear().append(ret); if (err) mb.append(err); coven.reply(mb); } break; } }
int main(int argc, char* argv[]) { InitModuleObjects(); int exitCode = 1; try { if (argc<2) { printf("usage: dalistop <server_ip:port> [/nowait]\n"); printf("eg: dalistop . -- stop dali server running locally\n"); printf(" dalistop eq0001016 -- stop dali server running remotely\n"); } else { SocketEndpoint ep; ep.set(argv[1],DALI_SERVER_PORT); bool nowait = false; if (argc>=3) nowait = stricmp(argv[2],"/nowait")==0; printf("Stopping Dali Server on %s\n",argv[1]); startMPServer(0); Owned<IGroup> group = createIGroup(1,&ep); Owned<ICommunicator> comm = createCommunicator(group); CMessageBuffer mb; int fn=-1; mb.append(fn); if (comm->verifyConnection(0,2000)) { comm->send(mb,0,MPTAG_DALI_COVEN_REQUEST,MP_ASYNC_SEND); if (nowait) { Sleep(1000); exitCode = 0; } else { // verifyConnection() has a min conn timeout of 10s // use recv() instead to check for socket closed ... try { while (!comm->recv(mb,0,MPTAG_DALI_COVEN_REQUEST,nullptr,5000)) { printf("Waiting for Dali Server to stop....\n"); } exitCode = 0; } catch (IMP_Exception *e) { if (e->errorCode() == MPERR_link_closed) exitCode = 0; e->Release(); } } } else fprintf(stderr, "Dali not responding\n"); stopMPServer(); } } catch (IException *e) { pexception("Exception",e); stopMPServer(); } releaseAtoms(); return exitCode; }
int main(int argc, const char *argv[]) { InitModuleObjects(); EnableSEHtoExceptionMapping(); NoQuickEditSection xxx; Owned<IFile> file = createIFile("dfuserver.xml"); if (file->exists()) globals.setown(createPTreeFromXMLFile("dfuserver.xml", ipt_caseInsensitive)); else globals.setown(readOldIni()); for (unsigned i=1;i<(unsigned)argc;i++) { const char *arg = argv[i]; StringBuffer prop("@"); StringBuffer val; while (*arg && *arg != '=') prop.append(*arg++); if (*arg) { arg++; while (isspace(*arg)) arg++; val.append(arg); prop.clip(); val.clip(); if (prop.length()>1) globals->setProp(prop.str(), val.str()); } } StringBuffer daliServer; StringBuffer queue; if (!globals->getProp("@DALISERVERS", daliServer)||!globals->getProp("@QUEUE", queue)) { usage(); globals.clear(); releaseAtoms(); return 1; } Owned<IFile> sentinelFile; bool stop = globals->getPropInt("@STOP",0)!=0; if (!stop) { sentinelFile.setown(createSentinelTarget()); removeSentinelFile(sentinelFile); StringBuffer logname; StringBuffer logdir; if (!getConfigurationDirectory(globals->queryPropTree("Directories"),"log","dfuserver",globals->queryProp("@name"),logdir)) globals->getProp("@LOG_DIR", logdir); if (logdir.length() && recursiveCreateDirectory(logdir.str())) logname.append(logdir); else appendCurrentDirectory(logname, true); if (logname.length() && logname.charAt(logname.length()-1) != PATHSEPCHAR) logname.append(PATHSEPCHAR); logname.append("dfuserver"); StringBuffer aliasLogName(logname); aliasLogName.append(".log"); fileMsgHandler = getRollingFileLogMsgHandler(logname.str(), ".log", MSGFIELD_STANDARD, false, true, NULL, aliasLogName.str()); queryLogMsgManager()->addMonitorOwn(fileMsgHandler, getCategoryLogMsgFilter(MSGAUD_all, MSGCLS_all, 1000)); } StringBuffer ftslogdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"log","ftslave",globals->queryProp("@name"),ftslogdir)) // NB instance deliberately dfuserver's setFtSlaveLogDir(ftslogdir.str()); setRemoteSpawnSSH( globals->queryProp("SSH/@SSHidentityfile"), globals->queryProp("SSH/@SSHusername"), globals->queryProp("SSH/@SSHpassword"), globals->getPropInt("SSH/@SSHtimeout",0), globals->getPropInt("SSH/@SSHretries",3), "run_"); bool enableSNMP = globals->getPropInt("@enableSNMP")!=0; CSDSServerStatus *serverstatus=NULL; Owned<IReplicateServer> replserver; try { Owned<IGroup> serverGroup = createIGroup(daliServer.str(),DALI_SERVER_PORT); initClientProcess(serverGroup, DCR_DfuServer, 0, NULL, NULL, stop?(1000*30):MP_WAIT_FOREVER); setPasswordsFromSDS(); if(!stop) { if (globals->getPropBool("@enableSysLog",true)) UseSysLogForOperatorMessages(); serverstatus = new CSDSServerStatus("DFUserver"); setDaliServixSocketCaching(true); // speeds up lixux operations startLogMsgParentReceiver(); // for auditing connectLogMsgManagerToDali(); engine.setown(createDFUengine()); addAbortHandler(exitDFUserver); } const char *q = queue.str(); loop { StringBuffer subq; const char *comma = strchr(q,','); if (comma) subq.append(comma-q,q); else subq.append(q); if (stop) { stopDFUserver(subq.str()); } else { StringBuffer mask; mask.appendf("Queue[@name=\"%s\"][1]",subq.str()); IPropertyTree *t=serverstatus->queryProperties()->queryPropTree(mask.str()); if (t) t->setPropInt("@num",t->getPropInt("@num",0)+1); else { t = createPTree(); t->setProp("@name",subq.str()); t->setPropInt("@num",1); serverstatus->queryProperties()->addPropTree("Queue",t); } serverstatus->commitProperties(); engine->setDefaultTransferBufferSize((size32_t)globals->getPropInt("@transferBufferSize")); engine->startListener(subq.str(),serverstatus); } if (!comma) break; q = comma+1; if (!*q) break; } q = globals->queryProp("@MONITORQUEUE"); if (q&&*q) { if (stop) { stopDFUserver(q); } else { IPropertyTree *t=serverstatus->queryProperties()->addPropTree("MonitorQueue",createPTree()); t->setProp("@name",q); engine->startMonitor(q,serverstatus,globals->getPropInt("@MONITORINTERVAL",60)*1000); } } q = globals->queryProp("@REPLICATEQUEUE"); if (q&&*q) { if (stop) { // TBD? } else { replserver.setown(createReplicateServer(q)); replserver->runServer(); } } if (!stop) { serverstatus->commitProperties(); writeSentinelFile(sentinelFile); engine->joinListeners(); if (replserver.get()) replserver->stopServer(); LOG(MCprogress, unknownJob, "Exiting"); } } catch(IException *e){ EXCLOG(e, "DFU Server Exception: "); e->Release(); } catch (const char *s) { WARNLOG("DFU: %s",s); } delete serverstatus; if (stop) Sleep(2000); // give time to stop engine.clear(); globals.clear(); closeEnvironment(); closedownClientProcess(); UseSysLogForOperatorMessages(false); setDaliServixSocketCaching(false); releaseAtoms(); return 0; }
static void test2() { const size32_t recsize = 17; printf("Test DFS\n"); StringBuffer s; unsigned i; unsigned n; unsigned t; queryNamedGroupStore().remove("daregress_group"); queryDistributedFileDirectory().removeEntry("daregress::superfile1"); SocketEndpointArray epa; for (n=0;n<400;n++) { s.clear().append("192.168.").append(n/256).append('.').append(n%256); SocketEndpoint ep(s.str()); epa.append(ep); } Owned<IGroup> group = createIGroup(epa); queryNamedGroupStore().add("daregress_group",group,true); if (!queryNamedGroupStore().find(group,s.clear())) ERROR("Created logical group not found"); if (stricmp(s.str(),"daregress_group")!=0) ERROR("Created logical group found with wrong name"); group.setown(queryNamedGroupStore().lookup("daregress_group")); if (!group) ERROR("named group lookup failed"); printf("Named group created - 400 nodes\n"); for (i=0;i<100;i++) { Owned<IPropertyTree> pp = createPTree("Part"); Owned<IFileDescriptor>fdesc = createFileDescriptor(); fdesc->setDefaultDir("c:\\thordata\\regress"); n = 9; for (unsigned k=0;k<400;k++) { s.clear().append("192.168.").append(n/256).append('.').append(n%256); Owned<INode> node = createINode(s.str()); pp->setPropInt64("@size",(n*777+i)*recsize); s.clear().append("daregress_test").append(i).append("._").append(n+1).append("_of_400"); fdesc->setPart(n,node,s.str(),pp); n = (n+9)%400; } fdesc->queryProperties().setPropInt("@recordSize",17); s.clear().append("daregress::test").append(i); queryDistributedFileDirectory().removeEntry(s.str()); StringBuffer cname; Owned<IDistributedFile> dfile = queryDistributedFileDirectory().createNew(fdesc); if (stricmp(dfile->getClusterName(0,cname),"daregress_group")!=0) ERROR1("Cluster name wrong %d",i); s.clear().append("daregress::test").append(i); dfile->attach(s.str()); } printf("DFile create done - 100 files\n"); unsigned samples = 5; t = 33; for (i=0;i<100;i++) { s.clear().append("daregress::test").append(t); if (!queryDistributedFileDirectory().exists(s.str())) ERROR1("Could not find %s",s.str()); Owned<IDistributedFile> dfile = queryDistributedFileDirectory().lookup(s.str()); if (!dfile) { ERROR1("Could not find %s",s.str()); continue; } offset_t totsz = 0; n = 11; for (unsigned k=0;k<400;k++) { Owned<IDistributedFilePart> part = dfile->getPart(n); if (!part) { ERROR2("part not found %d %d",t,n); continue; } s.clear().append("192.168.").append(n/256).append('.').append(n%256); Owned<INode> node = createINode(s.str()); if (!node->equals(part->queryNode())) ERROR2("part node mismatch %d, %d",t,n); if (part->getFileSize(false,false)!=(n*777+t)*recsize) ERROR4("size node mismatch %d, %d, %d, %d",t,n,(unsigned)part->getFileSize(false,false),(n*777+t)*recsize); s.clear().append("daregress_test").append(t).append("._").append(n+1).append("_of_400"); /* ** TBD if (stricmp(s.str(),part->queryPartName())!=0) ERROR4("part name mismatch %d, %d '%s' '%s'",t,n,s.str(),part->queryPartName()); */ totsz += (n*777+t)*recsize; if ((samples>0)&&(i+n+t==k)) { samples--; RemoteFilename rfn; part->getFilename(rfn,samples%2); StringBuffer fn; rfn.getRemotePath(fn); printf("SAMPLE: %d,%d %s\n",t,n,fn.str()); } n = (n+11)%400; } if (totsz!=dfile->getFileSize(false,false)) ERROR1("total size mismatch %d",t); t = (t+33)%100; } printf("DFile lookup done - 100 files\n"); // check iteration __int64 crctot = 0; unsigned np = 0; unsigned totrows = 0; Owned<IDistributedFileIterator> fiter = queryDistributedFileDirectory().getIterator("daregress::*",false); Owned<IDistributedFilePartIterator> piter; ForEach(*fiter) { piter.setown(fiter->query().getIterator()); ForEach(*piter) { RemoteFilename rfn; StringBuffer s; piter->query().getFilename(rfn,0); rfn.getRemotePath(s); piter->query().getFilename(rfn,1); rfn.getRemotePath(s); crctot += crc32(s.str(),s.length(),0); np++; totrows += (unsigned)(piter->query().getFileSize(false,false)/fiter->query().queryProperties().getPropInt("@recordSize",-1)); } } piter.clear(); fiter.clear(); printf("DFile iterate done - %d parts, %d rows, CRC sum %"I64F"d\n",np,totrows,crctot); Owned<IDistributedSuperFile> sfile; sfile.setown(queryDistributedFileDirectory().createSuperFile("daregress::superfile1",true)); for (i = 0;i<100;i++) { s.clear().append("daregress::test").append(i); sfile->addSubFile(s.str()); } sfile.clear(); sfile.setown(queryDistributedFileDirectory().lookupSuperFile("daregress::superfile1")); if (!sfile) { ERROR("Could not find added superfile"); return; } __int64 savcrc = crctot; crctot = 0; np = 0; totrows = 0; size32_t srs = (size32_t)sfile->queryProperties().getPropInt("@recordSize",-1); if (srs!=17) ERROR1("Superfile does not match subfile row size %d",srs); piter.setown(sfile->getIterator()); ForEach(*piter) { RemoteFilename rfn; StringBuffer s; piter->query().getFilename(rfn,0); rfn.getRemotePath(s); piter->query().getFilename(rfn,1); rfn.getRemotePath(s); crctot += crc32(s.str(),s.length(),0); np++; totrows += (unsigned)(piter->query().getFileSize(false,false)/srs); } piter.clear(); printf("Superfile iterate done - %d parts, %d rows, CRC sum %"I64F"d\n",np,totrows,crctot); if (crctot!=savcrc) ERROR("SuperFile does not match sub files"); unsigned tr = (unsigned)(sfile->getFileSize(false,false)/srs); if (totrows!=tr) ERROR1("Superfile size does not match part sum %d",tr); sfile->detach(); sfile.clear(); sfile.setown(queryDistributedFileDirectory().lookupSuperFile("daregress::superfile1")); if (sfile) ERROR("Superfile deletion failed"); t = 37; for (i=0;i<100;i++) { s.clear().append("daregress::test").append(t); if (i%1) { Owned<IDistributedFile> dfile = queryDistributedFileDirectory().lookup(s.str()); if (!dfile) ERROR1("Could not find %s",s.str()); dfile->detach(); } else queryDistributedFileDirectory().removeEntry(s.str()); t = (t+37)%100; } printf("DFile removal complete\n"); t = 39; for (i=0;i<100;i++) { if (queryDistributedFileDirectory().exists(s.str())) ERROR1("Found %s after deletion",s.str()); Owned<IDistributedFile> dfile = queryDistributedFileDirectory().lookup(s.str()); if (dfile) ERROR1("Found %s after deletion",s.str()); t = (t+39)%100; } printf("DFile removal check complete\n"); queryNamedGroupStore().remove("daregress_group"); if (queryNamedGroupStore().lookup("daregress_group")) ERROR("Named group not removed"); }
int CEclAgentExecutionServer::run() { Owned<IFile> sentinelFile = createSentinelTarget(); removeSentinelFile(sentinelFile); try { Owned<IGroup> serverGroup = createIGroup(daliServers, DALI_SERVER_PORT); initClientProcess(serverGroup, DCR_EclServer); getAgentQueueNames(queueNames, agentName); queue.setown(createJobQueue(queueNames.str())); queue->connect(); } catch (IException *e) { EXCLOG(e, "Server queue create/connect: "); e->Release(); return -1; } catch(...) { ERRLOG("Terminating unexpectedly"); } writeSentinelFile(sentinelFile); try { while (started) { PROGLOG("AgentExec: Waiting on queue(s) '%s'", queueNames.str()); Owned<IJobQueueItem> item = queue->dequeue(WAIT_FOREVER); if (item.get()) { rebuildLogfileName();//rebuild in case date rollover StringAttr wuid; wuid.set(item->queryWUID()); PROGLOG("AgentExec: Dequeued workunit request '%s'", wuid.get()); try { executeWorkunit(wuid); } catch(IException *e) { EXCLOG(e, "CEclAgentExecutionServer::run: "); } catch(...) { ERRLOG("Unexpected exception in CEclAgentExecutionServer::run caught"); } } else { ERRLOG("Unexpected dequeue of bogus job queue item, exiting agentexec"); removeSentinelFile(sentinelFile);//no reason to restart assert(!started); break; } } } catch (IException *e) { EXCLOG(e, "Server Exception: "); e->Release(); PROGLOG("Exiting"); } try { queue->disconnect(); } catch (IException *e) { EXCLOG(e, "Server queue disconnect: "); e->Release(); } PROGLOG("Exiting agentexec\n"); return 1; }
int main( int argc, char *argv[] ) { #if defined(WIN32) && defined(_DEBUG) int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); tmpFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag( tmpFlag ); #endif InitModuleObjects(); addAbortHandler(ControlHandler); EnableSEHtoExceptionMapping(); dummyProc(); #ifndef __64BIT__ Thread::setDefaultStackSize(0x10000); // NB under windows requires linker setting (/stack:) #endif #ifdef _WIN32 Owned<CReleaseMutex> globalNamedMutex; #endif if (globals) globals->Release(); { Owned<IFile> iFile = createIFile("thor.xml"); globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive); } unsigned multiThorMemoryThreshold = 0; try { if (argc==1) { usage(); return 1; } cmdArgs = argv+1; mergeCmdParams(globals); cmdArgs = argv+1; const char *master = globals->queryProp("@MASTER"); if (!master) usage(); const char *slave = globals->queryProp("@SLAVE"); if (slave) { slfEp.set(slave); localHostToNIC(slfEp); } else slfEp.setLocalHost(0); if (globals->hasProp("@SLAVENUM")) mySlaveNum = atoi(globals->queryProp("@SLAVENUM")); else mySlaveNum = slfEp.port; // shouldn't happen, provided by script setMachinePortBase(slfEp.port); slfEp.port = getMachinePortBase(); startSlaveLog(); startMPServer(getFixedPort(TPORT_mp)); #ifdef USE_MP_LOG startLogMsgParentReceiver(); LOG(MCdebugProgress, thorJob, "MPServer started on port %d", getFixedPort(TPORT_mp)); #endif SocketEndpoint masterEp(master); localHostToNIC(masterEp); setMasterPortBase(masterEp.port); markNodeCentral(masterEp); if (RegisterSelf(masterEp)) { #define ISDALICLIENT // JCSMORE plugins *can* access dali - though I think we should probably prohibit somehow. #ifdef ISDALICLIENT const char *daliServers = globals->queryProp("@DALISERVERS"); if (!daliServers) { LOG(MCerror, thorJob, "No Dali server list specified\n"); return 1; } Owned<IGroup> serverGroup = createIGroup(daliServers, DALI_SERVER_PORT); unsigned retry = 0; loop { try { LOG(MCdebugProgress, thorJob, "calling initClientProcess"); initClientProcess(serverGroup,DCR_ThorSlave, getFixedPort(TPORT_mp)); break; } catch (IJSOCK_Exception *e) { if ((e->errorCode()!=JSOCKERR_port_in_use)) throw; FLLOG(MCexception(e), thorJob, e,"InitClientProcess"); if (retry++>10) throw; e->Release(); LOG(MCdebugProgress, thorJob, "Retrying"); Sleep(retry*2000); } } setPasswordsFromSDS(); #endif IDaFileSrvHook *daFileSrvHook = queryDaFileSrvHook(); if (daFileSrvHook) // probably always installed daFileSrvHook->addSubnetFilters(globals->queryPropTree("NAS"), NULL); StringBuffer thorPath; globals->getProp("@thorPath", thorPath); recursiveCreateDirectory(thorPath.str()); int err = _chdir(thorPath.str()); if (err) { IException *e = MakeErrnoException(-1, "Failed to change dir to '%s'",thorPath.str()); FLLOG(MCexception(e), thorJob, e); throw e; } // Initialization from globals setIORetryCount(globals->getPropInt("Debug/@ioRetries")); // default == 0 == off StringBuffer str; if (globals->getProp("@externalProgDir", str.clear())) _mkdir(str.str()); else globals->setProp("@externalProgDir", thorPath); const char * overrideBaseDirectory = globals->queryProp("@thorDataDirectory"); const char * overrideReplicateDirectory = globals->queryProp("@thorReplicateDirectory"); StringBuffer datadir; StringBuffer repdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"data","thor",globals->queryProp("@name"),datadir)) overrideBaseDirectory = datadir.str(); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"mirror","thor",globals->queryProp("@name"),repdir)) overrideReplicateDirectory = repdir.str(); if (overrideBaseDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideBaseDirectory, false); if (overrideReplicateDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideReplicateDirectory, true); StringBuffer tempdirstr; const char *tempdir = globals->queryProp("@thorTempDirectory"); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"temp","thor",globals->queryProp("@name"),tempdirstr)) tempdir = tempdirstr.str(); SetTempDir(tempdir,true); useMemoryMappedRead(globals->getPropBool("@useMemoryMappedRead")); LOG(MCdebugProgress, thorJob, "ThorSlave Version LCR - %d.%d started",THOR_VERSION_MAJOR,THOR_VERSION_MINOR); StringBuffer url; LOG(MCdebugProgress, thorJob, "Slave %s - temporary dir set to : %s", slfEp.getUrlStr(url).toCharArray(), queryTempDir()); #ifdef _WIN32 ULARGE_INTEGER userfree; ULARGE_INTEGER total; ULARGE_INTEGER free; if (GetDiskFreeSpaceEx("c:\\",&userfree,&total,&free)&&total.QuadPart) { unsigned pc = (unsigned)(free.QuadPart*100/total.QuadPart); LOG(MCdebugProgress, thorJob, "Total disk space = %"I64F"d k", total.QuadPart/1000); LOG(MCdebugProgress, thorJob, "Free disk space = %"I64F"d k", free.QuadPart/1000); LOG(MCdebugProgress, thorJob, "%d%% disk free\n",pc); } #endif if (getConfigurationDirectory(globals->queryPropTree("Directories"),"query","thor",globals->queryProp("@name"),str.clear())) globals->setProp("@query_so_dir", str.str()); else globals->getProp("@query_so_dir", str.clear()); if (str.length()) { if (globals->getPropBool("Debug/@dllsToSlaves", true)) { StringBuffer uniqSoPath; if (PATHSEPCHAR == str.charAt(str.length()-1)) uniqSoPath.append(str.length()-1, str.str()); else uniqSoPath.append(str); uniqSoPath.append("_").append(getMachinePortBase()); str.swapWith(uniqSoPath); globals->setProp("@query_so_dir", str.str()); } PROGLOG("Using querySo directory: %s", str.str()); recursiveCreateDirectory(str.str()); } multiThorMemoryThreshold = globals->getPropInt("@multiThorMemoryThreshold")*0x100000; if (multiThorMemoryThreshold) { StringBuffer lgname; if (!globals->getProp("@multiThorResourceGroup",lgname)) globals->getProp("@nodeGroup",lgname); if (lgname.length()) { Owned<ILargeMemLimitNotify> notify = createMultiThorResourceMutex(lgname.str()); setMultiThorMemoryNotify(multiThorMemoryThreshold,notify); PROGLOG("Multi-Thor resource limit for %s set to %"I64F"d",lgname.str(),(__int64)multiThorMemoryThreshold); } else multiThorMemoryThreshold = 0; } slaveMain(); } LOG(MCdebugProgress, thorJob, "ThorSlave terminated OK"); } catch (IException *e) { FLLOG(MCexception(e), thorJob, e,"ThorSlave"); e->Release(); } catch (CATCHALL) { FLLOG(MCerror, thorJob, "ThorSlave exiting because of uncaught exception"); } ClearTempDirs(); if (multiThorMemoryThreshold) setMultiThorMemoryNotify(0,NULL); roxiemem::releaseRoxieHeap(); #ifdef ISDALICLIENT closeEnvironment(); closedownClientProcess(); // dali client closedown #endif #ifdef USE_MP_LOG stopLogMsgReceivers(); #endif stopMPServer(); ::Release(globals); releaseAtoms(); // don't know why we can't use a module_exit to destruct these... return 0; }