12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #include "ws_machineService.hpp"
- #include "jarray.hpp"
- #include "dadfs.hpp"
- #include "exception_util.hpp"
- #include "workunit.hpp"
- #include "roxiecommlib.hpp"
- #include "componentstatus.hpp"
- #include "rmtssh.hpp"
- #include "platform.h"
- #include "TpWrapper.hpp"
- static const int THREAD_POOL_SIZE = 40;
- static const int THREAD_POOL_STACK_SIZE = 64000;
- static const char* FEATURE_URL = "MachineInfoAccess";
- const unsigned ROXIECONTROLSTATETIMEOUT = 5000; //5 second
- class CMachineInfoThreadParam : public CWsMachineThreadParam
- {
- public:
- IMPLEMENT_IINTERFACE;
- IEspContext& m_context;
- CGetMachineInfoUserOptions& m_options; //From request
- CMachineData& m_machineData; //From request
- IArrayOf<IEspMachineInfoEx>& m_machineInfoTable; //For response
- StringArray& m_machineInfoColumns; //For response
- MapStringTo<int>& channelsMap; //For response
- CMachineInfoThreadParam(Cws_machineEx* pService, IEspContext& context, CGetMachineInfoUserOptions& options,
- CMachineData& machineData, IArrayOf<IEspMachineInfoEx>& machineInfoTable, StringArray& machineInfoColumns,
- MapStringTo<int>& _channelsMap)
- : CWsMachineThreadParam(NULL, NULL, NULL, pService),
- m_context(context),
- m_options(options),
- m_machineData(machineData),
- m_machineInfoTable(machineInfoTable),
- m_machineInfoColumns(machineInfoColumns),
- channelsMap(_channelsMap)
- {
- }
- virtual void doWork()
- {
- m_pService->doGetMachineInfo(m_context, this);
- }
- void addColumn(const char* columnName)
- {
- synchronized block(s_mutex);
- if (m_machineInfoColumns.find(columnName) == NotFound)
- m_machineInfoColumns.append(columnName);
- }
- int* getChannels(const char* key) { return channelsMap.getValue(key); };
- private:
- static Mutex s_mutex;
- };
- Mutex CMachineInfoThreadParam::s_mutex;
- class CRoxieStateInfoThreadParam : public CWsMachineThreadParam
- {
- public:
- StringAttr clusterName;
- IArrayOf<IEspMachineInfoEx>& machineInfoTable; //For response
- MapStringTo<int>& channelsMap; //For response
- CRoxieStateInfoThreadParam(Cws_machineEx* pService, const char* _clusterName,
- IArrayOf<IEspMachineInfoEx>& _machineInfoTable, MapStringTo<int>& _channelsMap)
- : CWsMachineThreadParam(pService), clusterName(_clusterName), machineInfoTable(_machineInfoTable),
- channelsMap(_channelsMap)
- {
- }
- virtual void doWork()
- {
- m_pService->getRoxieStateInfo(this);
- }
- int* getChannels(const char* key) { return channelsMap.getValue(key); };
- };
- class CGetMachineUsageThreadParam : public CWsMachineThreadParam
- {
- public:
- IEspContext& espContext;
- IPropertyTree* request;
- CGetMachineUsageThreadParam(Cws_machineEx* pService, IEspContext& _espContext, IPropertyTree* _request)
- : CWsMachineThreadParam(pService), espContext(_espContext), request(_request) {}
- virtual void doWork()
- {
- m_pService->getMachineUsage(espContext, this);
- }
- };
- const char* findComponentTypeFromProcessType(const char* ProcessType)
- {
- if (strieq(ProcessType, eqDali))
- return "dali";
- if (strieq(ProcessType, eqEclAgent))
- return "eclagent";
- if (strieq(ProcessType, eqDfu))
- return "dfuserver";
- if (strieq(ProcessType, eqEsp))
- return "esp";
- if (strieq(ProcessType, eqEclCCServer) || strieq(ProcessType, eqEclServer))
- return "eclserver";
- if (strieq(ProcessType, eqEclScheduler))
- return "eclscheduler";
- if (strieq(ProcessType, eqSashaServer))
- return "sasha";
- return nullptr;
- }
- void Cws_machineEx::init(IPropertyTree *cfg, const char *process, const char *service)
- {
- //Read settings from esp.xml
- StringBuffer xpath;
- xpath.appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]", process, service);
- Owned<IPropertyTree> pServiceNode = cfg->getPropTree(xpath.str());
- m_bMonitorDaliFileServer = pServiceNode->getPropBool("@monitorDaliFileServer", false);
- m_processFilters.setown( pServiceNode->getPropTree("ProcessFilters") );
- const char* pchExcludePartitions = pServiceNode->queryProp("@excludePartitions");
- if (pchExcludePartitions && *pchExcludePartitions)
- {
- StringArray sPartitions;
- sPartitions.appendList(pchExcludePartitions, ", ;");
- unsigned int numOfPartitions = sPartitions.ordinality();
- for (unsigned int i=0; i<numOfPartitions; i++)
- {
- const char* partition = sPartitions.item(i);
- if (!partition || !*partition)
- continue;
- if (strchr(partition, '*'))
- m_excludePartitionPatterns.insert( partition );
- else
- m_excludePartitions.insert( partition );
- }
- }
- m_useDefaultHPCCInit = pServiceNode->getPropBool("UseDefaultHPCCInit", true);//Still used by Rexec for now
- m_SSHConnectTimeoutSeconds = pServiceNode->getPropInt("SSHConnectTimeoutSeconds", 5);
- const char* machineInfoScript = pServiceNode->queryProp("MachineInfoFile");
- if (machineInfoScript && *machineInfoScript)
- m_machineInfoFile.append(machineInfoScript);
- else
- m_machineInfoFile.append("preflight");
- //Read settings from environment.xml
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> pEnvironmentRoot = &constEnv->getPTree();
- Owned<IPropertyTree> pEnvSettings = pEnvironmentRoot->getPropTree("EnvSettings");
- if (pEnvSettings)
- {
- pEnvSettings->getProp("configs", environmentConfData.m_configsPath.clear());
- pEnvSettings->getProp("path", environmentConfData.m_executionPath.clear());
- pEnvSettings->getProp("runtime", environmentConfData.m_runtimePath.clear());
- pEnvSettings->getProp("lock", environmentConfData.m_lockPath.clear());
- pEnvSettings->getProp("pid", environmentConfData.m_pidPath.clear());
- pEnvSettings->getProp("user", environmentConfData.m_user.clear());
- }
- m_threadPoolSize = pServiceNode->getPropInt("ThreadPoolSize", THREAD_POOL_SIZE);
- m_threadPoolStackSize = pServiceNode->getPropInt("ThreadPoolStackSize", THREAD_POOL_STACK_SIZE);
- //Start thread pool
- Owned<IThreadFactory> pThreadFactory = new CWsMachineThreadFactory();
- m_threadPool.setown(createThreadPool("WsMachine Thread Pool", pThreadFactory,
- NULL, m_threadPoolSize, 10000, m_threadPoolStackSize)); //10 sec timeout for available thread; use stack size of 2MB
- setupLegacyFilters();
- Owned<IComponentStatusFactory> factory = getComponentStatusFactory();
- factory->init(pServiceNode);
- unsigned machineUsageCacheForceRebuildMinutes = pServiceNode->getPropInt("MachineUsageCacheMinutes", machineUsageCacheMinutes);
- unsigned machineUsageCacheAutoRebuildMinutes = pServiceNode->getPropInt("MachineUsageCacheAutoRebuildMinutes", defaultMachineUsageCacheAutoBuildMinutes);
- usageCacheReader.setown(new CUsageCacheReader(this, "Usage Reader", machineUsageCacheAutoRebuildMinutes*60, machineUsageCacheForceRebuildMinutes*60));
- }
- StringBuffer& Cws_machineEx::getAcceptLanguage(IEspContext& context, StringBuffer& acceptLanguage)
- {
- context.getAcceptLanguage(acceptLanguage);
- if (!acceptLanguage.length())
- {
- acceptLanguage.set("en");
- return acceptLanguage;
- }
- acceptLanguage.setLength(2);
- VStringBuffer languageFile("%ssmc_xslt/nls/%s/hpcc.xml", getCFD(), acceptLanguage.str());
- if (!checkFileExists(languageFile.str()))
- acceptLanguage.set("en");
- return acceptLanguage;
- }
- bool Cws_machineEx::onGetMachineInfo(IEspContext &context, IEspGetMachineInfoRequest & req,
- IEspGetMachineInfoResponse & resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Machine Information. Permission denied.");
- StringArray& addresses = req.getAddresses();
- if (addresses.empty())
- throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "No network address specified.");
- CGetMachineInfoData machineInfoData;
- readMachineInfoRequest(context, req.getGetProcessorInfo(), req.getGetStorageInfo(), req.getLocalFileSystemsOnly(), req.getGetSoftwareInfo(),
- req.getApplyProcessFilter(), addresses, req.getAddProcessesToFilter(), machineInfoData);
- getMachineInfo(context, machineInfoData);
- setMachineInfoResponse(context, req, machineInfoData, resp);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool Cws_machineEx::onGetMachineInfoEx(IEspContext &context, IEspGetMachineInfoRequestEx & req, IEspGetMachineInfoResponseEx & resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Machine Information. Permission denied.");
- StringArray& addresses = req.getAddresses();
- if (addresses.empty())
- throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "No network address specified.");
- double version = context.getClientVersion();
- CGetMachineInfoData machineInfoData;
- readMachineInfoRequest(context, true, true, true, true, true, addresses, NULL, machineInfoData);
- getMachineInfo(context, machineInfoData);
- if (machineInfoData.getMachineInfoTable().ordinality())
- resp.setMachines(machineInfoData.getMachineInfoTable());
- if (version >= 1.12)
- {
- StringBuffer acceptLanguage;
- resp.setAcceptLanguage(getAcceptLanguage(context, acceptLanguage).str());
- }
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool Cws_machineEx::onGetTargetClusterInfo(IEspContext &context, IEspGetTargetClusterInfoRequest & req,
- IEspGetTargetClusterInfoResponse & resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Target Cluster Information. Permission denied.");
- StringArray& targetClusters = req.getTargetClusters();
- if (targetClusters.empty())
- throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "No target cluster specified.");
- CGetMachineInfoData machineInfoData;
- Owned<IPropertyTree> targetClustersOut = createPTreeFromXMLString("<Root/>");
- readMachineInfoRequest(context, req.getGetProcessorInfo(), req.getGetStorageInfo(), req.getLocalFileSystemsOnly(), req.getGetSoftwareInfo(),
- req.getApplyProcessFilter(), req.getAddProcessesToFilter(), targetClusters, machineInfoData, targetClustersOut);
- getMachineInfo(context, machineInfoData);
- setTargetClusterInfoResponse(context, req, machineInfoData, targetClustersOut, resp);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- void Cws_machineEx::addChannels(CGetMachineInfoData& machineInfoData, IPropertyTree* envRoot,
- const char* componentType, const char* componentName)
- {
- VStringBuffer key("%s|%s", componentType, componentName);
- int* channels = machineInfoData.getChannels(key);
- if (channels)
- return;
- StringBuffer path("Software/");
- if (strieq(componentType, eqThorSlaveProcess))
- path.append(eqThorCluster);
- else if (strieq(componentType, eqRoxieServerProcess))
- path.append(eqRoxieCluster);
- else
- throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "Invalid %s in Cws_machineEx::addChannels().", componentType);
- path.appendf("[@name=\"%s\"]", componentName);
- Owned<IPropertyTree> component;
- if (envRoot)
- {
- component.setown(envRoot->getPropTree(path));
- }
- else
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- component.setown(root->getPropTree(path));
- }
- if (!component)
- throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "%s not found.", componentName);
- StringAttr attr;
- if (strieq(componentType, eqThorSlaveProcess))
- attr.set("@channelsPerSlave");
- else
- attr.set("@channelsPerNode");
- if (component->hasProp(attr.get()))
- machineInfoData.addToChannelsMap(key, component->getPropInt(attr.get()));
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- // Read Machine Infomation request and collect related settings from environment.xml //
- ////////////////////////////////////////////////////////////////////////////////////////
- void Cws_machineEx::readMachineInfoRequest(IEspContext& context, bool getProcessorInfo, bool getStorageInfo, bool localFileSystemsOnly, bool getSoftwareInfo, bool applyProcessFilter,
- StringArray& processes, const char* addProcessesToFilters, CGetMachineInfoData& machineInfoData)
- {
- double version = context.getClientVersion();
- StringBuffer userID, password;
- context.getUserID(userID);
- context.getPassword(password);
- machineInfoData.getOptions().setUserName(userID.str());
- machineInfoData.getOptions().setPassword(password.str());
- machineInfoData.getOptions().setGetProcessorInfo(getProcessorInfo);
- machineInfoData.getOptions().setGetStorageInfo(getStorageInfo);
- machineInfoData.getOptions().setLocalFileSystemsOnly(localFileSystemsOnly);
- machineInfoData.getOptions().setGetSoftwareInfo(getSoftwareInfo);
- machineInfoData.getOptions().setApplyProcessFilter(applyProcessFilter);
- machineInfoData.getOptions().getAdditionalProcessFilters().appendList(addProcessesToFilters, " ,\t");
- BoolHash uniqueProcesses;
- for (unsigned i=0; i<processes.ordinality(); i++)
- {
- StringArray address;
- address.appendList(processes.item(i), ":");
- StringBuffer address1, address2, processType, compName, path;
- unsigned processNumber = 0;
- if (!machineInfoData.getOptions().getGetSoftwareInfo())
- {
- parseAddresses(address.item(0), address1, address2);
- }
- else
- {
- if (address.ordinality() < 5)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Invalid address format in '%s'.", processes.item(i));
- parseProcessString(address, address1, address2, processType, compName, path, processNumber);
- }
- setProcessRequest(machineInfoData, uniqueProcesses, address1.str(), address2.str(), processType.str(), compName.str(), path.str(), processNumber);
- if (strieq(processType.str(), eqRoxieServerProcess))
- machineInfoData.appendRoxieClusters(compName.str());
- if ((version >= 1.16) && (strieq(processType, eqThorSlaveProcess) || strieq(processType, eqRoxieServerProcess)))
- addChannels(machineInfoData, nullptr, processType, compName);
- }
- }
- void Cws_machineEx::readMachineInfoRequest(IEspContext& context, bool getProcessorInfo, bool getStorageInfo, bool localFileSystemsOnly, bool getSoftwareInfo, bool applyProcessFilter,
- const char* addProcessesToFilters, StringArray& targetClustersIn, CGetMachineInfoData& machineInfoData, IPropertyTree* targetClusterTreeOut)
- {
- StringBuffer userID, password;
- context.getUserID(userID);
- context.getPassword(password);
- machineInfoData.getOptions().setUserName(userID.str());
- machineInfoData.getOptions().setPassword(password.str());
- machineInfoData.getOptions().setGetProcessorInfo(getProcessorInfo);
- machineInfoData.getOptions().setGetStorageInfo(getStorageInfo);
- machineInfoData.getOptions().setLocalFileSystemsOnly(localFileSystemsOnly);
- machineInfoData.getOptions().setGetSoftwareInfo(getSoftwareInfo);
- machineInfoData.getOptions().setApplyProcessFilter(applyProcessFilter);
- machineInfoData.getOptions().getAdditionalProcessFilters().appendList(addProcessesToFilters, " ,\t");
- readSettingsForTargetClusters(context, targetClustersIn, machineInfoData, targetClusterTreeOut);
- }
- //Parses address request from machine information request in the form "192.168.1.4-6|."
- //The second address is the address retrieved from environment setting (could be a '.').
- void Cws_machineEx::parseAddresses(const char *address, StringBuffer& address1, StringBuffer& address2)
- {
- address1 = address;
- address2.clear();
- const char* props1 = strchr(address, '|');
- if (props1)
- {
- address2 = props1+1;
- address1.setLength(props1 - address);
- }
- address1.trim();
- address2.trim();
- }
- //Parses machine information request for each process in the form "192.168.1.4-6|.:ThorSlaveProcess:thor1:2:/var/lib/..."
- void Cws_machineEx::parseProcessString(StringArray& process, StringBuffer& address1, StringBuffer& address2,
- StringBuffer& processType, StringBuffer& compName, StringBuffer& path, unsigned& processNumber)
- {
- parseAddresses(process.item(0), address1, address2);
- processType.clear().append( process.item(1) ).trim();
- compName.clear().append( process.item(2) ).trim();
- EnvMachineOS os = (EnvMachineOS) atoi( process.item(3) );
- path.clear().append( process.item(4) ).trim();
- if (path.length())
- {
- char pat1, pat2;
- char rep1, rep2;
- if (os == MachineOsLinux)
- {
- pat1 = ':'; rep1 = '$';
- pat2 = '\\';rep2 = '/';
- }
- else
- {
- pat1 = '$'; rep1 = ':';
- pat2 = '/';rep2 = '\\';
- }
- path.replace( pat1, rep1 );
- path.replace( pat2, rep2 );
- if ((os == MachineOsLinux) && (path.charAt(0) != '/'))
- path.insert(0, '/');
- }
- if (process.ordinality() < 6)
- return;
- processNumber = atoi( process.item(5) );
- }
- void Cws_machineEx::setProcessRequest(CGetMachineInfoData& machineInfoData, BoolHash& uniqueProcesses, const char* address1, const char* address2,
- const char* processType, const char* compName, const char* path, unsigned processNumber)
- {
- IpAddress ipAddr;
- unsigned numIps = ipAddr.ipsetrange(address1);
- //address is like 192.168.1.4-6
- //so process each address in the range
- if (!ipAddr.isIp4())
- IPV6_NOT_IMPLEMENTED();
- //Always use "EclAgentProcess" to retrieve machine info for "AgentExecProcess"
- StringBuffer processTypeStr;
- if (processType && *processType)
- {
- if (strieq(processType, eqAgentExec))
- processTypeStr.append(eqEclAgent);
- else
- processTypeStr = processType;
- }
- while (numIps--)
- {
- unsigned numAddr;
- if (ipAddr.getNetAddress(sizeof(numAddr),&numAddr)!=sizeof(numAddr))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Invalid network address.");
- ipAddr.ipincrement(1);
- //Clean possible duplication
- StringBuffer valuesToBeChecked;
- valuesToBeChecked.append(numAddr);
- if (machineInfoData.getOptions().getGetSoftwareInfo())
- valuesToBeChecked.appendf(":%s:%s:%d", processTypeStr.str(), compName, processNumber);
- bool* found = uniqueProcesses.getValue(valuesToBeChecked.str());
- if (found && *found)
- continue;
- uniqueProcesses.setValue(valuesToBeChecked.str(), true);
- addProcessRequestToMachineInfoData(machineInfoData, address1, address2, processTypeStr.str(), compName, path, processNumber);
- }
- }
- void Cws_machineEx::addProcessRequestToMachineInfoData(CGetMachineInfoData& machineInfoData, const char* address1, const char* address2,
- const char* processType, const char* compName, const char* path, unsigned processNumber)
- {
- CIArrayOf<CMachineData>& machines = machineInfoData.getMachineData();
- ForEachItemIn(idx, machines)
- {
- CMachineData& machine = machines.item(idx);
- if (streq(address1, machine.getNetworkAddress()))
- {
- addProcessData(&machine, processType, compName, path, processNumber);
- return;
- }
- }
- char pathSep;
- EnvMachineOS os;
- Owned<IConstEnvironment> constEnv = getConstEnvironment();
- Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachineByAddress(address1);
- if (pMachineInfo.get())
- os = pMachineInfo->getOS();
- else
- os = MachineOsUnknown;
- if (os == MachineOsW2K)
- pathSep = '\\';
- else
- pathSep = '/';
- if (!m_processFilters)
- return;
- Owned<CMachineData> machineNew = new CMachineData(address1, address2, os, pathSep);
- //Read possible dependencies for all processes
- set<string>& dependenciesForAllProcesses = machineNew->getDependencies();
- StringBuffer xPath;
- xPath.appendf("Platform[@name='%s']/ProcessFilter[@name='any']/Process", machineNew->getOS() == MachineOsW2K ? "Windows" : "Linux");
- Owned<IPropertyTreeIterator> processes = m_processFilters->getElements(xPath.str());
- ForEach (*processes)
- {
- StringBuffer processName;
- processes->query().getProp("@name", processName);
- processName.toLowerCase().replaceString(".exe", "");
- if ((processName.length() > 0) && (!streq(processName.str(), "hoagentd"))) //hoagentd is not needed anymore
- dependenciesForAllProcesses.insert(processName.str());
- }
- if (m_bMonitorDaliFileServer && (dependenciesForAllProcesses.find("dafilesrv") == dependenciesForAllProcesses.end()))
- dependenciesForAllProcesses.insert("dafilesrv");
- addProcessData(machineNew, processType, compName, path, processNumber);
- machines.append(*machineNew.getClear());
- }
- //Create a CProcessData object and add it to CMachineData
- void Cws_machineEx::addProcessData(CMachineData* machine, const char* processType, const char* compName,
- const char* path, unsigned processNumber)
- {
- if (!machine)
- return;
- StringBuffer pathStr(path);
- if (pathStr.length() > 0)
- {
- char pathSep = machine->getPathSep();
- if (pathStr.charAt(pathStr.length() - 1) != pathSep)
- pathStr.append(pathSep);
- }
- Owned<CProcessData> process = new CProcessData(compName, processType, pathStr.str(), processNumber);
- //Copy dependencies for all processes
- set<string>& dependenciesForThisProcess = process->getDependencies();
- set<string>& dependenciesForAllProcesses = machine->getDependencies();
- set<string>::const_iterator it = dependenciesForAllProcesses.begin();
- set<string>::const_iterator iEnd = dependenciesForAllProcesses.end();
- for (; it != iEnd; it++) //add in sorted order simply by traversing the map
- dependenciesForThisProcess.insert((*it).c_str());
- //now collect "process-specific" dependencies
- IPropertyTree* processFilterNode = nullptr;
- if (m_processFilters)
- {
- VStringBuffer xPath("Platform[@name='%s']/ProcessFilter[@name='%s']", machine->getOS() == MachineOsW2K ? "Windows" : "Linux", processType);
- processFilterNode = m_processFilters->queryPropTree( xPath.str() );
- }
- if (!processFilterNode)
- {
- machine->getProcesses().append(*process.getClear());
- return;
- }
- Owned<IPropertyTreeIterator> processes = processFilterNode->getElements("Process");
- ForEach (*processes)
- {
- IPropertyTree* pProcess = &processes->query();
- const char* name = pProcess->queryProp("@name");
- if (!name || streq(name, "."))
- continue;
- StringBuffer processName(name);
- processName.toLowerCase().replaceString(".exe", "");
- if (processName.length() < 1)
- continue;
- //Environment.xml may contain old filter settings.
- if (isLegacyFilter(processType, processName.str()))
- continue;
- if (pProcess->getPropBool("@remove", false))
- dependenciesForThisProcess.erase(processName.str());
- else
- dependenciesForThisProcess.insert(processName.str());
- }
- process->setMultipleInstances(machine->getOS() == MachineOsLinux && processFilterNode->getPropBool("@multipleInstances", false));
- machine->getProcesses().append(*process.getClear());
- }
- //Collect process settings for the requested target clusters
- void Cws_machineEx::readSettingsForTargetClusters(IEspContext& context, StringArray& targetClusters, CGetMachineInfoData& machineInfoData, IPropertyTree* targetClustersOut)
- {
- unsigned ordinality= targetClusters.ordinality();
- if (ordinality < 1)
- return;
- Owned<IConstEnvironment> constEnv = getConstEnvironment();
- Owned<IPropertyTree> pEnvironmentRoot = &constEnv->getPTree();
- if (!pEnvironmentRoot)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get environment information.");
- BoolHash uniqueProcesses;
- for (unsigned index=0; index<ordinality; index++)
- {
- StringBuffer clusterType;
- const char* clusterName = targetClusters.item(index);
- const char* pClusterName = strchr(clusterName, ':');
- if (pClusterName)
- {
- clusterType.append(clusterName, 0, pClusterName - clusterName);
- pClusterName++;
- }
- if (!pClusterName || !*pClusterName)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Cluster name not specified.");
- if (clusterType.length() < 1)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Cluster type not specified.");
- StringBuffer path;
- path.appendf("Software/Topology/Cluster[@name='%s']", pClusterName);
- IPropertyTree* pCluster = pEnvironmentRoot->queryPropTree(path.str());
- if (!pCluster)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Cluster %s not found in environment setting.", pClusterName);
- Owned<IPropertyTreeIterator> clusterProcesses;
- if (strieq(clusterType.str(), eqThorCluster) || strieq(clusterType.str(), eqRoxieCluster))
- {
- clusterProcesses.setown(pCluster->getElements(clusterType.str()));
- if (!clusterProcesses->first())
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Cluster %s not found in environment setting.", clusterType.str());
- }
- Owned<IPropertyTreeIterator> eclCCServerProcesses= pCluster->getElements(eqEclCCServer);
- Owned<IPropertyTreeIterator> eclServerProcesses= pCluster->getElements(eqEclServer);
- Owned<IPropertyTreeIterator> eclAgentProcesses= pCluster->getElements(eqEclAgent);
- Owned<IPropertyTreeIterator> eclSchedulerProcesses= pCluster->getElements(eqEclScheduler);
- IPropertyTree *targetClusterOut = targetClustersOut->addPropTree("TargetCluster", createPTree("TargetCluster"));
- targetClusterOut->setProp("@Name", pClusterName);
- targetClusterOut->setProp("@Type", clusterType.str());
- //Read Cluster processes
- if (clusterProcesses && clusterProcesses->first())
- ForEach(*clusterProcesses)
- readTargetClusterProcesses(context, clusterProcesses->query(), clusterType.str(), uniqueProcesses, machineInfoData, targetClusterOut);
- //Read eclCCServer process
- if (eclCCServerProcesses->first())
- readTargetClusterProcesses(context, eclCCServerProcesses->query(), eqEclCCServer, uniqueProcesses, machineInfoData, targetClusterOut);
- //Read eclServer process
- if (eclServerProcesses->first())
- readTargetClusterProcesses(context, eclServerProcesses->query(), eqEclServer, uniqueProcesses, machineInfoData, targetClusterOut);
- //Read eclAgent process
- if (eclAgentProcesses->first())
- readTargetClusterProcesses(context, eclAgentProcesses->query(), eqEclAgent, uniqueProcesses, machineInfoData, targetClusterOut);
- //Read eclScheduler process
- if (eclSchedulerProcesses->first())
- readTargetClusterProcesses(context, eclSchedulerProcesses->query(), eqEclScheduler, uniqueProcesses, machineInfoData, targetClusterOut);
- }
- }
- //Collect settings for one group of target cluster processes
- void Cws_machineEx::readTargetClusterProcesses(IEspContext& context, IPropertyTree &processNode, const char* nodeType, BoolHash& uniqueProcesses, CGetMachineInfoData& machineInfoData,
- IPropertyTree* targetClustersOut)
- {
- const char* process = processNode.queryProp("@process");
- if (!process || !*process)
- throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Process attribute not set for ECLCCServer in environment setting.");
- Owned<IConstEnvironment> constEnv = getConstEnvironment();
- Owned<IPropertyTree> pEnvironmentRoot = &constEnv->getPTree();
- if (!pEnvironmentRoot)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get environment information.");
- IPropertyTree* pEnvironmentSoftware = pEnvironmentRoot->queryPropTree("Software");
- if (!pEnvironmentSoftware)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get environment information.");
- double version = context.getClientVersion();
- IPropertyTree* pClusterProcess = NULL;
- if (strieq(nodeType, eqThorCluster) || strieq(nodeType, eqRoxieCluster))
- {
- StringBuffer path;
- path.appendf("Software/%s[@name='%s']", nodeType, process);
- pClusterProcess = pEnvironmentRoot->queryPropTree(path.str());
- if (!pClusterProcess)
- throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Process not set for %s in environment setting.", path.str());
- if (strieq(nodeType, eqRoxieCluster))
- machineInfoData.appendRoxieClusters(process);
- }
- IPropertyTree *pInfo = targetClustersOut->addPropTree("Process", createPTree("Process"));
- pInfo->setProp("@Name", process);
- pInfo->setProp("@Type", nodeType);
- StringBuffer dirStr;
- IPropertyTree* pEnvironmentDirectories = pEnvironmentSoftware->queryPropTree("Directories");
- if (!pClusterProcess)
- {
- if (!pEnvironmentDirectories || !getConfigurationDirectory(pEnvironmentDirectories, "run", nodeType, process, dirStr))
- dirStr.clear().append(processNode.queryProp("@directory"));
- getProcesses(constEnv, pEnvironmentSoftware, process, nodeType, dirStr.str(), machineInfoData, false, uniqueProcesses);
- return;
- }
- if (!pEnvironmentDirectories || !getConfigurationDirectory(pEnvironmentDirectories, "run", nodeType, process, dirStr))
- dirStr.clear().append(pClusterProcess->queryProp("@directory"));
- if (strieq(nodeType, eqThorCluster))
- {
- getProcesses(constEnv, pClusterProcess, process, eqThorMasterProcess, dirStr.str(), machineInfoData, true, uniqueProcesses);
- getThorProcesses(constEnv, pClusterProcess, process, eqThorSlaveProcess, dirStr.str(), machineInfoData, uniqueProcesses);
- getThorProcesses(constEnv, pClusterProcess, process, eqThorSpareProcess, dirStr.str(), machineInfoData, uniqueProcesses);
- if (version >= 1.16)
- addChannels(machineInfoData, pEnvironmentRoot, eqThorSlaveProcess, process);
- }
- else if (strieq(nodeType, eqRoxieCluster))
- {
- BoolHash uniqueRoxieProcesses;
- getProcesses(constEnv, pClusterProcess, process, eqRoxieServerProcess, dirStr.str(), machineInfoData, true, uniqueProcesses, &uniqueRoxieProcesses);
- if (version >= 1.16)
- addChannels(machineInfoData, pEnvironmentRoot, eqRoxieServerProcess, process);
- }
- }
- void Cws_machineEx::getThorProcesses(IConstEnvironment* constEnv, IPropertyTree* cluster, const char* processName,
- const char* processType, const char* directory, CGetMachineInfoData& machineInfoData, BoolHash& uniqueProcesses)
- {
- if (!constEnv || !cluster)
- return;
- Owned<IGroup> nodeGroup;
- StringBuffer groupName;
- if (strieq(processType, eqThorSlaveProcess))
- {
- getClusterGroupName(*cluster, groupName);
- if (groupName.length() < 1)
- {
- OWARNLOG("Cannot find group name for %s", processName);
- return;
- }
- nodeGroup.setown(getClusterProcessNodeGroup(processName, eqThorCluster));
- }
- else
- {
- getClusterSpareGroupName(*cluster, groupName);
- if (groupName.length() < 1)
- {
- OWARNLOG("Cannot find group name for %s", processName);
- return;
- }
- nodeGroup.setown(queryNamedGroupStore().lookup(groupName.str()));
- }
- if (!nodeGroup || (nodeGroup->ordinality() == 0))
- {
- OWARNLOG("Cannot find node group for %s", processName);
- return;
- }
- int slavesPerNode = cluster->getPropInt("@slavesPerNode");
- Owned<INodeIterator> gi = nodeGroup->getIterator();
- ForEach(*gi)
- {
- StringBuffer addressRead;
- gi->query().endpoint().getIpText(addressRead);
- if (addressRead.length() == 0)
- {
- OWARNLOG("Network address not found for a node in node group %s", groupName.str());
- continue;
- }
- StringBuffer netAddress;
- const char* ip = addressRead.str();
- if (!streq(ip, "."))
- {
- netAddress.append(ip);
- }
- else
- {
- IpAddress ipaddr = queryHostIP();
- ipaddr.getIpText(netAddress);
- }
- if (netAddress.length() == 0)
- {
- OWARNLOG("Network address not found for a node in node group %s", groupName.str());
- continue;
- }
- Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachineByAddress(addressRead.str());
- if (!pMachineInfo.get())
- {
- OWARNLOG("Machine not found at network address %s", addressRead.str());
- continue;
- }
- //Each thor slave is a process. The i is used to check whether the process is running or not.
- for (unsigned i = 1; i <= slavesPerNode; i++)
- setProcessRequest(machineInfoData, uniqueProcesses, netAddress.str(), addressRead.str(),
- processType, processName, directory, i);
- }
- return;
- }
- void Cws_machineEx::getProcesses(IConstEnvironment* constEnv, IPropertyTree* environment, const char* processName,
- const char* processType, const char* directory, CGetMachineInfoData& machineInfoData,
- bool isThorOrRoxieProcess, BoolHash& uniqueProcesses, BoolHash* uniqueRoxieProcesses)
- {
- Owned<IPropertyTreeIterator> processes= environment->getElements(processType);
- ForEach(*processes)
- {
- StringArray processInstances, directories;
- IPropertyTree &process = processes->query();
- //Thor master and roxie server has been checked before this call.
- if (!isThorOrRoxieProcess)
- {
- const char* name = process.queryProp("@name");
- if (!name || !*name || !streq(name, processName))
- continue;
- }
- const char* computerName = process.queryProp("@computer");
- if (computerName && *computerName)
- appendProcessInstance(computerName, directory, NULL, processInstances, directories);
- else
- {
- Owned<IPropertyTreeIterator> instances= process.getElements("Instance");
- ForEach(*instances)
- {
- IPropertyTree &instance = instances->query();
- appendProcessInstance(instance.queryProp("@computer"), directory, instance.queryProp("@directory"), processInstances, directories);
- }
- }
- if (processInstances.length() < 1)
- continue;
- for (unsigned i = 0; i < processInstances.length(); i++)
- {
- const char* name0 = processInstances.item(i);
- const char* directory0 = directories.item(i);
- if (uniqueRoxieProcesses)//to avoid duplicate entries for roxie (one machine has only one roxie process).
- {
- bool* found = uniqueRoxieProcesses->getValue(name0);
- if (found && *found)
- continue;
- uniqueRoxieProcesses->setValue(name0, true);
- }
- Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachine(name0);
- if (!pMachineInfo.get())
- {
- OWARNLOG("Machine %s not found in environment setting", name0);
- continue;
- }
- SCMStringBuffer ep;
- pMachineInfo->getNetAddress(ep);
- const char* ip = ep.str();
- if (!ip)
- {
- OWARNLOG("Network address not found for machine %s", name0);
- continue;
- }
- StringBuffer netAddress;
- StringBuffer configNetAddress(ip);
- if (!streq(ip, "."))
- {
- netAddress.set(ip);
- }
- else
- {
- IpAddress ipaddr = queryHostIP();
- ipaddr.getIpText(netAddress);
- }
- setProcessRequest(machineInfoData, uniqueProcesses, netAddress.str(), configNetAddress.str(), processType, processName, directory0);
- }
- }
- return;
- }
- void Cws_machineEx::setupLegacyFilters()
- {
- unsigned idx = 0;
- while (legacyFilterStrings[idx])
- {
- m_legacyFilters.setValue(legacyFilterStrings[idx], true);
- idx++;
- }
- return;
- }
- bool Cws_machineEx::isLegacyFilter(const char* processType, const char* dependency)
- {
- if (!processType || !*processType || !dependency || !*dependency)
- return false;
- StringBuffer filterString;
- filterString.appendf("%s:%s", processType, dependency);
- bool* found = m_legacyFilters.getValue(filterString.str());
- if (found && *found)
- return true;
- return false;
- }
- //The stateHashes stores different state hashes in one roxie cluster.
- //It also stores how many roxie nodes have the same state hashes.
- unsigned Cws_machineEx::addRoxieStateHash(const char* hash, StateHashes& stateHashes, unsigned& totalUniqueHashes)
- {
- if (!hash || !*hash)
- return -1;
- unsigned hashID = 0;
- IStateHash* stateHash = stateHashes.getValue(hash);
- if (stateHash)
- {
- //if the stateHashes already has the same 'hash', increases the count for the 'stateHash'.
- //The 'StateHash' with the highest count will be the 'Major StateHash'.
- //If a roxie node does not contain the 'Major StateHash', it has a 'mismatch' state hash.
- hashID = stateHash->queryID();
- stateHash->incrementCount();
- }
- else
- {
- //Add a new 'StateHash'. Set its hashID to totalUniqueHashes and set its count to 1.
- hashID = totalUniqueHashes;
- Owned<IStateHash> newStateHash = new CStateHash(hashID, 1);
- stateHashes.setValue(hash, newStateHash);
- totalUniqueHashes++;
- }
- return hashID;
- }
- void Cws_machineEx::updateMajorRoxieStateHash(StateHashes& stateHashes, CIArrayOf<CRoxieStateData>& roxieStates)
- {
- //Find out which state hash is for the most of the roxie nodes inside this roxie cluster.
- unsigned majorHashID = 0;
- unsigned majorHashCount = 0;
- HashIterator hashes(stateHashes);
- ForEach(hashes)
- {
- IStateHash *hash = stateHashes.mapToValue(&hashes.query());
- unsigned hashCount = hash->queryCount();
- if (majorHashCount >= hashCount)
- continue;
- majorHashCount = hashCount;
- majorHashID = hash->queryID();
- }
- //Set the MajorHash to false if the roxie node's HashID() != majorHashID.
- ForEachItemIn(ii, roxieStates)
- {
- CRoxieStateData& roxieState = roxieStates.item(ii);
- if (roxieState.getHashID() != majorHashID)
- roxieState.setMajorHash(false);
- }
- }
- void Cws_machineEx::readRoxieStatus(const Owned<IPropertyTree> controlResp, CIArrayOf<CRoxieStateData>& roxieStates)
- {
- StateHashes stateHashes;
- unsigned totalUniqueHashes = 0;
- Owned<IPropertyTreeIterator> roxieEndpoints = controlResp->getElements("Endpoint");
- ForEach(*roxieEndpoints)
- {
- IPropertyTree& roxieEndpoint = roxieEndpoints->query();
- const char *ep = roxieEndpoint.queryProp("@ep");
- if (!ep || !*ep)
- continue;
- bool ok = false, attached = false, detached = false;
- const char *status = roxieEndpoint.queryProp("Status");
- if (status && strieq(status, "ok"))
- ok = true;
- const char *stateHash = roxieEndpoint.queryProp("State/@hash");
- if (roxieEndpoint.hasProp("Dali/@connected"))
- {
- if (roxieEndpoint.getPropBool("Dali/@connected"))
- attached = true;
- else
- detached = true;
- }
- StringArray locations;
- locations.appendListUniq(ep, ":");
- Owned<CRoxieStateData> roxieState = new CRoxieStateData(locations.item(0), addRoxieStateHash(stateHash, stateHashes, totalUniqueHashes));
- roxieState->setState(ok, attached, detached, stateHash);
- roxieStates.append(*roxieState.getClear());
- }
- if (totalUniqueHashes > 1)
- updateMajorRoxieStateHash(stateHashes, roxieStates);
- }
- void Cws_machineEx::getRoxieStateInfo(CRoxieStateInfoThreadParam* param)
- {
- const char* clusterName = param->clusterName.get();
- if (!clusterName || !*clusterName)
- throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Roxie cluster not specified.");
- SocketEndpointArray servers;
- getRoxieProcessServers(clusterName, servers);
- if (!servers.length())
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Roxie Process server not found.");
- Owned<IRoxieCommunicationClient> roxieClient = createRoxieCommunicationClient(servers.item(0), ROXIECONTROLSTATETIMEOUT);
- Owned<IPropertyTree> controlResp = roxieClient->sendRoxieControlAllNodes("<control:state/>", true);
- if (!controlResp)
- throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to get control response from roxie %s.", clusterName);
- CIArrayOf<CRoxieStateData> roxieStates;
- readRoxieStatus(controlResp, roxieStates);
- ForEachItemIn(i, param->machineInfoTable)
- {
- IEspMachineInfoEx& machineInfo = param->machineInfoTable.item(i);
- if (!streq(machineInfo.getProcessType(), eqRoxieServerProcess) || !streq(machineInfo.getComponentName(), clusterName))
- continue;
- //This method is thread safe because each machineInfo (for one roxie node) belongs to only one Roxie cluster.
- //It is impossible for different threads to update the same machineInfo.
- bool foundRoxieState = false;
- ForEachItemIn(ii, roxieStates)
- {
- CRoxieStateData& roxieState = roxieStates.item(ii);
- if (!roxieState.matchIPAddress(machineInfo.getAddress()))
- continue;
- StringBuffer state, stateDetails;
- roxieState.reportState(state, stateDetails);
- machineInfo.setRoxieState(state.str());
- machineInfo.setRoxieStateDetails(stateDetails.str());
- foundRoxieState = true;
- }
- if (!foundRoxieState)
- {
- machineInfo.setRoxieState("??");
- machineInfo.setRoxieStateDetails("Roxie state not found");
- }
- }
- }
- void Cws_machineEx::getMachineInfo(IEspContext& context, bool getRoxieState, CGetMachineInfoData& machineInfoData)
- {
- UnsignedArray threadHandles;
- if (!getRoxieState)
- {
- CIArrayOf<CMachineData>& machines = machineInfoData.getMachineData();
- ForEachItemIn(idx, machines)
- {
- Owned<CMachineInfoThreadParam> pThreadReq = new CMachineInfoThreadParam(this, context, machineInfoData.getOptions(),
- machines.item(idx), machineInfoData.getMachineInfoTable(), machineInfoData.getMachineInfoColumns(),
- machineInfoData.getChannelsMap());
- PooledThreadHandle handle = m_threadPool->start( pThreadReq.getClear());
- threadHandles.append(handle);
- }
- }
- else
- {
- StringArray& roxieClusters = machineInfoData.getRoxieClusters();
- ForEachItemIn(i, roxieClusters)
- {
- Owned<CRoxieStateInfoThreadParam> pThreadReq = new CRoxieStateInfoThreadParam(this, roxieClusters.item(i),
- machineInfoData.getMachineInfoTable(), machineInfoData.getChannelsMap());
- PooledThreadHandle handle = m_threadPool->start( pThreadReq.getClear());
- threadHandles.append(handle);
- }
- machineInfoData.getMachineInfoColumns().append("Roxie State");
- }
- //Block for worker threads to finish, if necessary and then collect results
- //Not use joinAll() because multiple threads may call this method. Each call uses the pool to create
- //its own threads of checking query state. Each call should only join the ones created by that call.
- ForEachItemIn(i, threadHandles)
- m_threadPool->join(threadHandles.item(i));
- }
- ////////////////////////////////////////////////////////////////////
- // Get Machine Information based on Machine Information request //
- ////////////////////////////////////////////////////////////////////
- void Cws_machineEx::getMachineInfo(IEspContext& context, CGetMachineInfoData& machineInfoData)
- {
- double version = context.getClientVersion();
- getMachineInfo(context, false, machineInfoData);
- if ((version >= 1.13) && !machineInfoData.getRoxieClusters().empty())
- getMachineInfo(context, true, machineInfoData);
- }
- // the following method is invoked on worker threads of CMachineInfoThreadParam
- void Cws_machineEx::doGetMachineInfo(IEspContext& context, CMachineInfoThreadParam* pParam)
- {
- #ifdef DETECT_WS_MC_MEM_LEAKS
- static bool firstTime = true;
- if (firstTime)
- {
- firstTime = false;
- unsigned t = setAllocHook(true);
- }
- #endif //DETECT_WS_MC_MEM_LEAKS
- int error = 0;
- StringBuffer preflightCommand, response;
- buildPreflightCommand(context, pParam, preflightCommand);
- if (preflightCommand.length() < 1)
- {
- response.append("Failed in creating Machine Information command.\n");
- error = -1;
- }
- else
- {
- error = runCommand(context, pParam->m_machineData.getNetworkAddress(), pParam->m_machineData.getNetworkAddressInEnvSetting(), pParam->m_machineData.getOS(), preflightCommand.str(), pParam->m_options.getUserName(), pParam->m_options.getPassword(), response);
- if ((error == 0) && (response.length() > 0))
- readPreflightResponse(context, pParam, response.str(), error);
- }
- //Set IArrayOf<IEspMachineInfoEx> based on Preflight Response
- setMachineInfo(context, pParam, response.str(), error);
- #ifdef DETECT_WS_MC_MEM_LEAKS
- DBGLOG("Allocated=%d", setAllocHook(false));
- #endif //DETECT_WS_MC_MEM_LEAKS
- }
- void Cws_machineEx::buildPreflightCommand(IEspContext& context, CMachineInfoThreadParam* pParam, StringBuffer& preflightCommand)
- {
- preflightCommand.clear().appendf("/%s/sbin/%s -p=%s", environmentConfData.m_executionPath.str(),
- m_machineInfoFile.str(), environmentConfData.m_pidPath.str());
- if (preflightCommand.charAt(preflightCommand.length() - 1) == pParam->m_machineData.getPathSep())
- preflightCommand.remove(preflightCommand.length()-1, 1);
- bool checkDependency = false;
- CIArrayOf<CProcessData>& processes = pParam->m_machineData.getProcesses();
- ForEachItemIn(idx, processes)
- {
- CProcessData& process = processes.item(idx);
- if (!process.getName() || !*process.getName())
- continue;
- StringBuffer procName;
- if (streq(process.getType(), eqThorSlaveProcess))
- procName.appendf("thorslave_%s_%d,%s_slave_%d", process.getName(), process.getProcessNumber(), process.getName(), process.getProcessNumber());
- else if (streq(process.getType(), eqThorMasterProcess))
- procName.appendf("%s,%s_master", process.getName(), process.getName());
- else
- procName.append(process.getName());
- if (idx < 1)
- preflightCommand.appendf(" -n=%s", procName.str());
- else
- preflightCommand.appendf(",%s", procName.str());
- if (!process.getDependencies().empty())
- checkDependency = true;
- }
- if (checkDependency || !pParam->m_options.getApplyProcessFilter())
- preflightCommand.append(" -d=ALL");
- if (pParam->m_options.getGetStorageInfo() && !pParam->m_options.getLocalFileSystemsOnly())
- preflightCommand.append(" -m=YES");
- }
- int Cws_machineEx::runCommand(IEspContext& context, const char* sAddress, const char* sConfigAddress, EnvMachineOS os,
- const char* sCommand, const char* sUserId, const char* sPassword, StringBuffer& response)
- {
- int exitCode = -1;
- try
- {
- StringBuffer command(sCommand);
- StringBuffer userId;
- StringBuffer password;
- bool bLinux;
- if (sConfigAddress && *sConfigAddress)
- getAccountAndPlatformInfo(sConfigAddress, userId, password, bLinux);
- else
- getAccountAndPlatformInfo(sAddress, userId, password, bLinux);
- if (!sUserId || !*sUserId || !sPassword ||!*sPassword)
- {
- //BUG: 9825 - remote execution on linux needs to use individual accounts
- //use userid/password in ESP context for remote execution...
- if (bLinux)
- {
- userId.clear();
- password.clear();
- context.getUserID(userId);
- context.getPassword(password);
- }
- }
- else
- {
- userId.clear().append(sUserId);
- password.clear().append(sPassword);
- }
- // make sure there actually is something in command before we run a remote connection
- if (command.length() < 1)
- return exitCode;
- Owned<IFRunSSH> connection = createFRunSSH();
- connection->init(command.str(),NULL,NULL,NULL,m_SSHConnectTimeoutSeconds,0);
- // executed as single connection
- connection->exec(IpAddress(sAddress),NULL,false);
- response.append(connection->getReplyText()[0]);
- exitCode = connection->getReply()[0];
- int len = response.length();
- if (len > 0 && response.charAt(--len) == '\n') // strip newline
- response.setLength(len);
- if (response.length() && !exitCode)
- response.insert(0, "Response: ");
- else if (!exitCode)
- response.insert(0, "No response recieved.\n");
- }
- // CFRunSSH uses a MakeStringExceptionDirect throw to pass code and result string
- catch(IException* e)
- {
- exitCode = e->errorCode();
- // errorCode == -1 on successful CFRunSSH execution
- if(exitCode == -1)
- exitCode = 0;
- StringBuffer buf;
- e->errorMessage(buf);
- response.append(buf.str());
- int len = response.length();
- if (len > 0 && response.charAt(--len) == '\n') // strip newline
- response.setLength(len);
- // on successful connection
- if (response.length() && !exitCode)
- response.insert(0,"Response: ");
- else if (!exitCode)
- response.insert(0, "No response recieved.\n");
- e->Release();
- }
- #ifndef NO_CATCHALL
- catch(...)
- {
- response.append("An unknown exception occurred!");
- exitCode = -1;
- }
- #endif
- return exitCode;
- }
- int Cws_machineEx::invokeProgram(const char *command_line, StringBuffer& response)
- {
- char buffer[128];
- FILE *fp;
- // Run the command so that it writes its output to a pipe. Open this
- // pipe with read text attribute so that we can read it
- // like a text file.
- if (getEspLogLevel()>LogNormal)
- {
- DBGLOG("command_line=<%s>", command_line);
- }
- #ifndef NO_CONNECTION_DEBUG
- if( (fp = popen( command_line, "r" )) == NULL )
- return -1;
- #else
- if( (fp = fopen( "c:\\temp\\preflight_result.txt", "r" )) == NULL )
- return -1;
- #endif
- // Read pipe until end of file. End of file indicates that
- //the stream closed its standard out (probably meaning it
- //terminated).
- while ( !feof(fp) )
- if ( fgets( buffer, 128, fp) )
- response.append( buffer );
- if (getEspLogLevel()>LogNormal)
- {
- DBGLOG("response=<%s>", response.str());
- }
- // Close pipe and print return value of CHKDSK.
- #ifndef NO_CONNECTION_DEBUG
- return pclose( fp );
- #else
- return fclose( fp );
- #endif
- }
- void Cws_machineEx::readPreflightResponse(IEspContext& context, CMachineInfoThreadParam* pParam, const char* response, int error)
- {
- if (!response || !*response)
- return;
- StringBuffer computerUpTime;
- readALineFromResult(response, "ComputerUpTime:", computerUpTime, true);
- if (computerUpTime.length() < 1)
- computerUpTime.append("-");
- else
- {
- const char* pStr = strchr(computerUpTime.str(), ' ');
- if (pStr)
- {
- pStr++;
- pStr = strchr(pStr, ' ');
- if (pStr)
- {
- pStr++;
- if (pStr)
- pParam->m_machineData.setComputerUpTime(pStr);
- }
- }
- if (!pStr)
- pParam->m_machineData.setComputerUpTime(computerUpTime);
- }
- if (pParam->m_options.getGetProcessorInfo())
- {
- StringBuffer CPUIdle;
- readALineFromResult(response, "CPU-Idle:", CPUIdle, true);
- if (CPUIdle.length() < 1)
- pParam->m_machineData.setCPULoad(0);
- else
- {
- if (CPUIdle.charAt(CPUIdle.length() - 1) == '%')
- CPUIdle.setLength(CPUIdle.length() - 1);
- pParam->m_machineData.setCPULoad(100-atoi(CPUIdle.str()));
- }
- }
- if (pParam->m_options.getGetStorageInfo())
- readStorageData(response, pParam);
- if (pParam->m_options.getGetSoftwareInfo())
- readProcessData(response, pParam);
- }
- void Cws_machineEx::readALineFromResult(const char *result, const char *start, StringBuffer& value, bool trim)
- {
- if (!result || !*result)
- return;
- const char* pStr = strstr(result, start);
- if (!pStr)
- return;
- pStr += strlen(start);
- if (!pStr)
- return;
- const char* pStr1 = strchr(pStr, 0x0a);
- if (pStr1)
- value.append(pStr, 0, pStr1 - pStr);
- else
- value.append(pStr);
- if (trim)
- value.trim();
- }
- void Cws_machineEx::readStorageData(const char* response, CMachineInfoThreadParam* pParam)
- {
- if (!response || !*response)
- return;
- const char* pStr = strstr(response, "---SpaceUsedAndFree---");
- if (!pStr)
- DBGLOG("Storage information not found on %s", pParam->m_machineData.getNetworkAddress());
- bool isTitleLine = true;
- CIArrayOf<CStorageData>& storage = pParam->m_machineData.getStorage();
- while (pStr)
- {
- StringBuffer buf;
- const char* pStr1 = strchr(pStr, 0x0a);
- if (pStr1)
- {
- buf.append(pStr, 0, pStr1 - pStr);
- pStr = pStr1+1;
- }
- else
- {
- buf.append(pStr);
- pStr = NULL;
- }
- if (isTitleLine)
- {
- isTitleLine = false;
- continue;
- }
- if (buf.length() > 0)
- {
- StringBuffer diskSpaceTitle;
- int diskSpacePercentAvail = 0;
- __int64 diskSpaceAvailable = 0, diskSpaceTotal = 0;
- if (!readStorageSpace(buf.str(), diskSpaceTitle, diskSpaceAvailable, diskSpaceTotal, diskSpacePercentAvail))
- DBGLOG("Invalid storage information on %s: %s", pParam->m_machineData.getNetworkAddress(), buf.str());
- else if ((diskSpaceTitle.length() > 0) && !excludePartition(diskSpaceTitle.str()))
- {
- Owned<CStorageData> diskData = new CStorageData(diskSpaceTitle, diskSpaceAvailable, diskSpaceTotal, diskSpacePercentAvail);
- storage.append(*diskData.getClear());
- }
- }
- if (!pStr || (strnicmp(pStr, "---ProcessList1---", 18)==0))
- break;
- }
- }
- bool Cws_machineEx::readStorageSpace(const char *line, StringBuffer& title, __int64& free, __int64& total, int& percentAvail)
- {
- if (!line || !*line)
- return false;
- StringBuffer freeStr, usedStr;
- const char* pStr = line;
- const char* pStr1 = strchr(pStr, ':');
- if (!pStr1)
- return false;
- title.clear().append(pStr, 0, pStr1 - pStr);
- pStr = pStr1 + 2;
- pStr1 = (char*) strchr(pStr, ' ');
- if (!pStr1)
- return false;
- usedStr.append(pStr, 0, pStr1 - pStr);
- pStr = pStr1 + 1;
- if (!pStr)
- return false;
- freeStr.append(pStr);
- __int64 factor1 = 1;
- if (freeStr.length() > 9)
- {
- freeStr.setLength(freeStr.length()-6);
- factor1 = 1000000;
- }
- free = atol(freeStr.str())*factor1;
- __int64 factor2 = 1;
- if (usedStr.length() > 9)
- {
- usedStr.setLength(usedStr.length()-6);
- factor2 = 1000000;
- }
- __int64 used = atol(usedStr.str())*factor2;
- total = free + used;
- if (total > 0)
- percentAvail = (int) ((free*100)/total);
- free = (__int64) free /1000; //MByte
- total = (__int64) total /1000; //MByte
- return true;
- }
- void Cws_machineEx::buildProcessPath(StringBuffer &processPath, const char * processName, CMachineInfoThreadParam * pParam)
- {
- if (environmentConfData.m_pidPath.charAt(environmentConfData.m_pidPath.length() - 1) != pParam->m_machineData.getPathSep())
- processPath.setf("%s%c%s:", environmentConfData.m_pidPath.str(), pParam->m_machineData.getPathSep(), processName);
- else
- processPath.setf("%s%s:", environmentConfData.m_pidPath.str(), processName);
- }
- void Cws_machineEx::readProcessData(const char* response, CMachineInfoThreadParam* pParam)
- {
- if (!response || !*response)
- return;
- CIArrayOf<CProcessData>& processes = pParam->m_machineData.getProcesses();
- ForEachItemIn(idx, processes)
- {
- CProcessData& process = processes.item(idx);
- if (!process.getName() || !*process.getName())
- continue;
- StringBuffer procName, catError, processPath, processData;
- if (streq(process.getType(), eqThorSlaveProcess))
- {
- procName.appendf("thorslave_%s_%d", process.getName(), process.getProcessNumber());
- buildProcessPath(processPath,procName.str(),pParam);
- catError.setf("cat: %s",processPath.str());
- catError.insert(catError.length()-1,".pid");
- if (!strstr(response,catError.str()))
- readALineFromResult(response, processPath.str(), processData, true);
- else
- {
- procName.setf("%s_slave_%d", process.getName(), process.getProcessNumber());
- buildProcessPath(processPath,procName.str(),pParam);
- readALineFromResult(response, processPath.str(), processData, true);
- }
- }
- else if (streq(process.getType(), eqThorMasterProcess))
- {
- procName.appendf("%s", process.getName());
- buildProcessPath(processPath,procName.str(),pParam);
- catError.setf("cat: %s",processPath.str());
- catError.insert(catError.length()-1,".pid");
- if (!strstr(response,catError.str()))
- readALineFromResult(response, processPath.str(), processData, true);
- else
- {
- procName.setf("%s_master", process.getName());
- buildProcessPath(processPath,procName.str(),pParam);
- readALineFromResult(response, processPath.str(), processData, true);
- }
- }
- else
- {
- procName.append(process.getName());
- buildProcessPath(processPath,procName.str(),pParam);
- readALineFromResult(response, processPath.str(), processData, true);
- }
- if (processData.length() < 1)
- {
- DBGLOG("Information for process %s not found", processPath.str());
- continue;
- }
- const char* pStr = strchr(processData.str(), ' ');
- if (!pStr)
- {
- DBGLOG("incorrect data for process %s: %s", processPath.str(), processData.str());
- continue;
- }
- unsigned len = pStr - processData.str();
- StringBuffer pid, upTime;
- pid.append(processData.str(), 0, len);
- len++;
- upTime.append(processData.str(), len, processData.length() - len);
- upTime.replaceString("-", " day(s) ");
- process.setPID(pid.str());
- process.setUpTime(upTime.str());
- }
- readRunningProcesses(response, pParam);
- }
- void Cws_machineEx::readRunningProcesses(const char* response, CMachineInfoThreadParam* pParam)
- {
- if (!response || !*response)
- return;
- const char* pStr = strstr(response, "---ProcessList2---");
- if (!pStr)
- DBGLOG("Running process not found on %s", pParam->m_machineData.getNetworkAddress());
- IArrayOf<IEspProcessInfo>& runningProcesses = pParam->m_machineData.getRunningProcesses();
- while (pStr)
- {
- //read a line
- StringBuffer lineStr;
- const char* pStr1 = strchr(pStr, 0x0a);
- if (!pStr1)
- {
- lineStr.append(pStr);
- pStr = NULL;
- }
- else
- {
- lineStr.append(pStr, 0, pStr1 - pStr);
- pStr = pStr1+1;
- }
- if (lineStr.length() < 1)
- continue;
- StringBuffer pidStr, desc, param;
- pStr1 = lineStr.str();
- const char* pStr2 = strchr(pStr1, ' ');
- if (!pStr2)
- continue;
- pidStr.append(pStr1, 0, pStr2 - pStr1);
- param.append(pStr2+1);
- if (param.length() < 1)
- continue;
- if (streq(param.str(), "ps"))
- continue;
- bool isNumber = true;
- for (unsigned i = 0; i < pidStr.length(); i++)
- {
- if (!isdigit(pidStr.charAt(i)))
- {
- isNumber = false;
- break;
- }
- }
- if (!isNumber)
- continue;
- int pid = atoi(pidStr.str());
- desc = param;
- if ((desc.charAt(0) == '.') && (param.charAt(1) == '/'))
- desc.remove(0, 2);
- if (desc.charAt(desc.length() - 1) == '/')
- desc.remove(desc.length() - 1, 1);
- if (desc.charAt(0) == '[')
- {
- desc.remove(0, 1);
- if (desc.charAt(desc.length() - 1) == ']')
- desc.remove(desc.length() - 1, 1);
- }
- Owned<IEspProcessInfo> info = createProcessInfo("","");
- info->setPID(pid);
- info->setParameter(param.str());
- info->setDescription(desc.str());
- runningProcesses.append(*info.getClear());
- }
- }
- void Cws_machineEx::setMachineInfo(IEspContext& context, CMachineInfoThreadParam* pParam, const char* response, int error)
- {
- //Read additionalProcessFilters which will be used in setProcessInfo()/setProcessComponent()
- set<string>& additionalProcesses = pParam->m_machineData.getAdditinalProcessFilters();
- StringArray& additionalProcessFilters = pParam->m_options.getAdditionalProcessFilters();
- if (pParam->m_options.getApplyProcessFilter() && !additionalProcessFilters.empty())
- {
- int len = additionalProcessFilters.length();
- for (int i=0; i<len; i++)
- {
- StringBuffer processName(additionalProcessFilters.item(i));
- processName.toLowerCase().replaceString(".exe", "");
- if (processName.length() > 0)
- additionalProcesses.insert(processName.str());
- }
- }
- CIArrayOf<CProcessData>& processes = pParam->m_machineData.getProcesses();
- ForEachItemIn(idx, processes)
- {
- CProcessData& process = processes.item(idx);
- Owned<IEspMachineInfoEx> pMachineInfo = static_cast<IEspMachineInfoEx*>(new CMachineInfoEx(""));
- setProcessInfo(context, pParam, response, error, process, idx<1, pMachineInfo);
- synchronized block(mutex_machine_info_table);
- pParam->m_machineInfoTable.append(*pMachineInfo.getLink());
- }
- }
- void Cws_machineEx::setProcessInfo(IEspContext& context, CMachineInfoThreadParam* pParam, const char* response,
- int error, CProcessData& process, bool firstProcess, IEspMachineInfoEx* pMachineInfo)
- {
- double version = context.getClientVersion();
- bool isEclAgentProcess = process.getType() && strieq(process.getType(), eqEclAgent);
- pMachineInfo->setAddress(pParam->m_machineData.getNetworkAddress());
- pMachineInfo->setConfigAddress(pParam->m_machineData.getNetworkAddressInEnvSetting());
- pMachineInfo->setOS(pParam->m_machineData.getOS());
- if (process.getName() && *process.getName())
- pMachineInfo->setComponentName(process.getName());
- if (process.getPath() && *process.getPath())
- pMachineInfo->setComponentPath(process.getPath());
- //set DisplayType
- if (process.getType() && *process.getType())
- {
- if (isEclAgentProcess)
- {
- pMachineInfo->setProcessType(eqAgentExec);
- pMachineInfo->setDisplayType("Agent Exec");
- }
- else
- {
- pMachineInfo->setProcessType(process.getType());
- StringBuffer displayName;
- getProcessDisplayName(process.getType(), displayName);
- pMachineInfo->setDisplayType(displayName.str());
- }
- }
- else if (process.getName() && *process.getName())
- {
- pMachineInfo->setDisplayType(process.getName());
- }
- if ((version > 1.09) && process.getType() && strieq(process.getType(), eqThorSlaveProcess))
- {
- pMachineInfo->setProcessNumber(process.getProcessNumber());
- }
- if ((version >= 1.16) && (strieq(process.getType(), eqThorSlaveProcess) || strieq(process.getType(), eqRoxieServerProcess)))
- {
- VStringBuffer key("%s|%s", process.getType(), process.getName());
- int* channels = pParam->getChannels(key);
- if (channels)
- pMachineInfo->setChannels(*channels);
- }
- if (error != 0 || !response || !*response)
- {
- StringBuffer description;
- if (!response || !*response)
- description.append("Failed in getting Machine Information");
- else
- description = response;
- if (version < 1.17)
- pMachineInfo->setDescription(description.str());
- else
- pMachineInfo->setException(description.str());
- }
- else
- {
- //Now, add more columns based on 'response'
- pMachineInfo->setUpTime(pParam->m_machineData.getComputerUpTime());
- pParam->addColumn("Up Time");
- if (pParam->m_options.getGetStorageInfo())
- {
- IArrayOf<IEspStorageInfo> storageArray;
- CIArrayOf<CStorageData>& storage = pParam->m_machineData.getStorage();
- ForEachItemIn(idx, storage)
- {
- CStorageData& diskData = storage.item(idx);
- Owned<IEspStorageInfo> info = static_cast<IEspStorageInfo*>(new CStorageInfo(""));
- info->setDescription(diskData.getDiskSpaceTitle());
- info->setTotal(diskData.getDiskSpaceTotal());
- info->setAvailable(diskData.getDiskSpaceAvailable());
- info->setPercentAvail(diskData.getDiskSpacePercentAvail());
- storageArray.append(*info.getLink());
- pParam->addColumn(diskData.getDiskSpaceTitle());
- }
- pMachineInfo->setStorage(storageArray);
- storageArray.kill();
- }
- if (pParam->m_options.getGetProcessorInfo())
- {
- IArrayOf<IEspProcessorInfo> processorArray;
- Owned<IEspProcessorInfo> info = static_cast<IEspProcessorInfo*>(new CProcessorInfo(""));
- info->setLoad(pParam->m_machineData.getCPULoad());
- processorArray.append(*info.getLink());
- pMachineInfo->setProcessors(processorArray);
- processorArray.kill();
- pParam->addColumn("CPU Load");
- }
- if (pParam->m_options.getGetSoftwareInfo())
- {
- IArrayOf<IEspSWRunInfo> processArray;
- IEspComponentInfo* pComponentInfo = &pMachineInfo->updateComponentInfo();
- setProcessComponent(context, pParam, process, firstProcess, processArray, pComponentInfo);
- if (processArray.ordinality())
- {
- //Set running processes if ApplyProcessFilter is set to false
- //Set processes not running if ApplyProcessFilter is set to true
- pMachineInfo->setRunning(processArray);
- }
- pParam->addColumn("Processes");
- pParam->addColumn("Condition");
- pParam->addColumn("State");
- pParam->addColumn("UpTime");
- }
- }
- }
- void Cws_machineEx::setProcessComponent(IEspContext& context, CMachineInfoThreadParam* pParam, CProcessData& process,
- bool firstProcess, IArrayOf<IEspSWRunInfo>& processArray, IEspComponentInfo* pComponentInfo)
- {
- const char* procType = process.getType();
- const char* procPID = process.getPID();
- //If a component (ex. dropzone) has no process type, it is not a process and does not have a PID.
- //FTSlaveProcess may not have a PID since it is launched dynamically during a spray.
- if (pParam->m_options.getApplyProcessFilter() && (isEmptyString(procPID) &&
- !isEmptyString(procType) && !strieq(procType, "FTSlaveProcess")))
- {
- Owned<IEspSWRunInfo> info = static_cast<IEspSWRunInfo*>(new CSWRunInfo(""));
- info->setName(process.getName());
- info->setInstances(0);
- processArray.append( *info.getLink() );
- }
- set<string>& additionalProcesses = pParam->m_machineData.getAdditinalProcessFilters();
- map<string, Linked<IEspSWRunInfo> > runningProcessMap; //save only one description of each process
- set<string>& dependencies = process.getDependencies();
- IArrayOf<IEspProcessInfo>& runningProcesses = pParam->m_machineData.getRunningProcesses();
- if (runningProcesses.length() > 0)
- {
- if (!pParam->m_options.getApplyProcessFilter()) //need to display all of the running processes
- enumerateRunningProcesses( pParam, process, &runningProcessMap, firstProcess);
- else if (!dependencies.empty() || !additionalProcesses.empty())
- enumerateRunningProcesses(pParam, process, NULL, firstProcess);
- }
- map<string, Linked<IEspSWRunInfo> >::const_iterator it = runningProcessMap.begin();
- map<string, Linked<IEspSWRunInfo> >::const_iterator iEnd = runningProcessMap.end();
- for (; it != iEnd; it++) //add in sorted order simply by traversing the map
- {
- Linked<IEspSWRunInfo> info( (*it).second );
- processArray.append( *info.getLink() );
- }
- bool dependencyDown = false;
- if (!dependencies.empty())
- {
- dependencyDown = true;
- if (pParam->m_options.getApplyProcessFilter())
- {
- set<string>::const_iterator it = dependencies.begin();
- set<string>::const_iterator iEnd = dependencies.end();
- for (; it != iEnd; it++)
- {
- Owned<IEspSWRunInfo> info = static_cast<IEspSWRunInfo*>(new CSWRunInfo(""));
- info->setName(it->c_str());
- info->setInstances(0);
- processArray.append( *info.getLink() );
- }
- }
- }
- if (pParam->m_options.getApplyProcessFilter() && !additionalProcesses.empty())
- {
- set<string>::const_iterator it = additionalProcesses.begin();
- set<string>::const_iterator iEnd = additionalProcesses.end();
- for (; it != iEnd; it++)
- {
- Owned<IEspSWRunInfo> info = static_cast<IEspSWRunInfo*>(new CSWRunInfo(""));
- info->setName(it->c_str());
- info->setInstances(0);
- processArray.append( *info.getLink() );
- }
- }
- if (!dependencyDown && (!isEmptyString(procPID) || isEmptyString(procType) || strieq(procType, "FTSlaveProcess")))
- {
- //conditions: unknown, normal, warning, minor, major, critical, fatal
- pComponentInfo->setCondition( 1 );
- pComponentInfo->setState(5);
- if (process.getUpTime() && *process.getUpTime())
- pComponentInfo->setUpTime( process.getUpTime() );
- }
- else
- {
- pComponentInfo->setCondition(2); //Warnning
- pComponentInfo->setState(0);
- }
- }
- //Erase this process from dependencies and, if firstProcess, additionalProcesses;
- //If processMap is not NULL, add this process to processMap
- void Cws_machineEx::enumerateRunningProcesses(CMachineInfoThreadParam* pParam, CProcessData& process, map<string, Linked<IEspSWRunInfo> >* runningProcessMap, bool firstProcess)
- {
- set<string>& dependencies = process.getDependencies();
- set<string>& additionalProcesses = pParam->m_machineData.getAdditinalProcessFilters();
- IArrayOf<IEspProcessInfo>& runningProcesses = pParam->m_machineData.getRunningProcesses();
- ForEachItemIn(k, runningProcesses)
- {
- IEspProcessInfo& processInfo = runningProcesses.item(k);
- //Erase this process from dependencies and, if firstProcess, additionalProcesses
- const char* pName = processInfo.getDescription();
- if (pParam->m_machineData.getOS() == MachineOsW2K)
- {
- StringBuffer sName(pName);
- pName = sName.toLowerCase().replaceString(".exe", "").str();
- if (!dependencies.empty())
- dependencies.erase(pName);
- if (pParam->m_options.getApplyProcessFilter() && firstProcess && !additionalProcesses.empty())
- additionalProcesses.erase(pName);
- }
- else
- {
- //dafilesrv would probably be running from a global directory
- //and not component's installation directory so ignore their paths
- const char* pPath = pName;
- if ( !strieq(pName, "dafilesrv"))
- {
- const char* param = processInfo.getParameter();
- if (param && *param)
- {
- if (strncmp(param, "bash ", 5))
- pPath = param;
- else
- pPath = param + 5;
- if (!pPath || !*pPath)
- continue;
- //params typically is like "/c$/esp_dir/esp [parameters...]"
- //so just pick the full path
- const char* pch = strchr(pPath, ' ');
- if (pch)
- {
- StringBuffer sPath(pPath);
- sPath.setLength( pch - pPath );
- pPath = sPath.str();
- }
- }
- }
- if (!dependencies.empty())
- {
- const char* pProcessName;
- if (process.getType() && !strncmp(process.getType(), "Thor", 4) && !strnicmp(pName, "thor", 4))
- {
- const char* pch = strrchr(pPath, pParam->m_machineData.getPathSep());
- pProcessName = pch ? pch+1 : pName;
- }
- else
- {
- const char* pName0 = process.getMultipleInstances() ? pPath : pName;
- const char* pch = strrchr(pName0, pParam->m_machineData.getPathSep());
- pProcessName = pch ? pch+1 : pName0;
- }
- dependencies.erase(pProcessName);
- if (pParam->m_options.getApplyProcessFilter() && firstProcess && !additionalProcesses.empty())
- additionalProcesses.erase(pProcessName);
- }
- pName = pPath;
- }
- if (!runningProcessMap)
- continue;
- //Add this process to runningProcessMap
- map<string, Linked<IEspSWRunInfo> >::iterator it = runningProcessMap->find(pName);
- if ( it != runningProcessMap->end()) //not in the set
- {
- Linked<IEspSWRunInfo>& linkedPtr = (*it).second;
- linkedPtr->setInstances( linkedPtr->getInstances() + 1);
- }
- else
- {
- Owned<IEspSWRunInfo> info = static_cast<IEspSWRunInfo*>(new CSWRunInfo(""));
- info->setName(pName);
- info->setInstances(1);
- runningProcessMap->insert(pair<string, Linked<IEspSWRunInfo> >(pName, info));
- }
- }
- }
- void Cws_machineEx::getProcessDisplayName(const char* processName, StringBuffer& displayName)
- {
- //produces "LDAPServerProcess" as "LDAP Server" and "EspService" as "Esp Service", etc.
- const char* end = strstr(processName, "Process");
- if (!end)
- end = processName + strlen(processName);
- displayName.append(*processName);
- processName++;
- bool bLower = false;
- while (processName < end)
- {
- char ch = *processName;
- if (!isupper(ch))
- bLower = true;
- else
- {
- if (bLower || //last char was uppercase or the following character is lowercase?
- ((processName+1 < end) && islower(*(processName+1))))
- {
- displayName.append(' ');
- }
- bLower = false;
- }
- displayName.append(*processName);
- processName++;
- }
- displayName.append('\0');
- return;
- }
- bool Cws_machineEx::excludePartition(const char* partition) const
- {
- //first see if this partition is meant to be excluded as is - for instance
- //if partition is /dev and /dev is one of the predefined partitions to be excluded
- set<string>::const_iterator it = m_excludePartitions.find( partition );
- set<string>::const_iterator itEnd = m_excludePartitions.end();
- bool found = false;
- if (it != itEnd)
- found = true;
- else
- {
- //now check if /dev* is one of the partitions to be excluded
- set<string>::const_iterator itBegin = m_excludePartitionPatterns.begin();
- itEnd = m_excludePartitionPatterns.end();
- unsigned int partitionLen = strlen(partition);
- for (it=itBegin; it != itEnd; it++)
- {
- const string& pattern = *it;
- if ((found = ::WildMatch(partition, partitionLen, pattern.c_str(), pattern.length(), false)))
- break;
- }
- }
- return found;
- }
- void Cws_machineEx::appendProcessInstance(const char* name, const char* directory1, const char* directory2, StringArray& processInstances, StringArray& directories)
- {
- if (!name || !*name)
- return;
- processInstances.append(name);
- if (directory1 && *directory1)
- directories.append(directory1);
- else if (directory2 && *directory2)
- directories.append(directory2);
- else
- directories.append("Setting not found");
- }
- //////////////////////////////////////////////////////////////////
- // Set Machine Infomation for response //
- //////////////////////////////////////////////////////////////////
- void Cws_machineEx::setMachineInfoResponse(IEspContext& context, IEspGetMachineInfoRequest& req,
- CGetMachineInfoData& machineInfoData, IEspGetMachineInfoResponse& resp)
- {
- IEspRequestInfoStruct& reqInfo = resp.updateRequestInfo();
- #if 0
- StringBuffer user;
- StringBuffer pw;
- context.getUserID(user);
- context.getPassword(pw);
- reqInfo.setUserName(user.str());
- reqInfo.setPassword(pw.str());
- #endif
- reqInfo.setSecurityString(req.getSecurityString());
- reqInfo.setGetProcessorInfo(req.getGetProcessorInfo());
- reqInfo.setGetStorageInfo(req.getGetStorageInfo());
- double version = context.getClientVersion();
- if (version > 1.10)
- reqInfo.setLocalFileSystemsOnly(req.getLocalFileSystemsOnly());
- reqInfo.setGetSoftwareInfo(req.getGetSoftwareInfo());
- reqInfo.setAutoRefresh( req.getAutoRefresh() );
- reqInfo.setMemThreshold(req.getMemThreshold());
- reqInfo.setDiskThreshold(req.getDiskThreshold());
- reqInfo.setCpuThreshold(req.getCpuThreshold());
- reqInfo.setMemThresholdType(req.getMemThresholdType());
- reqInfo.setDiskThresholdType(req.getDiskThresholdType());
- reqInfo.setApplyProcessFilter( req.getApplyProcessFilter() );
- reqInfo.setClusterType( req.getClusterType() );
- reqInfo.setCluster( req.getCluster() );
- reqInfo.setAddProcessesToFilter( req.getAddProcessesToFilter() );
- reqInfo.setOldIP( req.getOldIP() );
- reqInfo.setPath( req.getPath() );
- reqInfo.setSortBy("Address");
- if (machineInfoData.getMachineInfoColumns().ordinality())
- resp.setColumns(machineInfoData.getMachineInfoColumns());
- if (machineInfoData.getMachineInfoTable().ordinality())
- resp.setMachines(machineInfoData.getMachineInfoTable());
- char timeStamp[32];
- getTimeStamp(timeStamp);
- resp.setTimeStamp( timeStamp );
- if (version >= 1.12)
- {
- StringBuffer acceptLanguage;
- resp.setAcceptLanguage(getAcceptLanguage(context, acceptLanguage).str());
- }
- }
- void Cws_machineEx::getTimeStamp(char* timeStamp)
- {
- //set time stamp in the result for this machine
- time_t tNow;
- time(&tNow);
- #ifdef _WIN32
- struct tm *ltNow;
- ltNow = localtime(&tNow);
- strftime(timeStamp, 32, "%m/%d/%y %H:%M:%S", ltNow);
- #else
- struct tm ltNow;
- localtime_r(&tNow, <Now);
- strftime(timeStamp, 32, "%m/%d/%y %H:%M:%S", <Now);
- #endif
- }
- void Cws_machineEx::setTargetClusterInfoResponse(IEspContext& context, IEspGetTargetClusterInfoRequest& req,
- CGetMachineInfoData& machineInfoData, IPropertyTree* targetClusterTree, IEspGetTargetClusterInfoResponse& resp)
- {
- IEspRequestInfoStruct& reqInfo = resp.updateRequestInfo();
- #if 0
- StringBuffer user;
- StringBuffer pw;
- context.getUserID(user);
- context.getPassword(pw);
- reqInfo.setUserName(user.str());
- reqInfo.setPassword(pw.str());
- #endif
- reqInfo.setGetProcessorInfo(req.getGetProcessorInfo());
- reqInfo.setGetStorageInfo(req.getGetStorageInfo());
- double version = context.getClientVersion();
- if (version > 1.10)
- reqInfo.setLocalFileSystemsOnly(req.getLocalFileSystemsOnly());
- reqInfo.setGetSoftwareInfo(req.getGetSoftwareInfo());
- reqInfo.setAutoRefresh( req.getAutoRefresh() );
- reqInfo.setMemThreshold(req.getMemThreshold());
- reqInfo.setDiskThreshold(req.getDiskThreshold());
- reqInfo.setCpuThreshold(req.getCpuThreshold());
- reqInfo.setMemThresholdType(req.getMemThresholdType());
- reqInfo.setDiskThresholdType(req.getDiskThresholdType());
- reqInfo.setApplyProcessFilter( req.getApplyProcessFilter() );
- reqInfo.setAddProcessesToFilter( req.getAddProcessesToFilter() );
- reqInfo.setSortBy("Address");
- if (machineInfoData.getMachineInfoColumns().ordinality())
- resp.setColumns(machineInfoData.getMachineInfoColumns());
- if (machineInfoData.getMachineInfoTable().ordinality())
- {
- IArrayOf<IEspTargetClusterInfo> targetClusterInfoList;
- setTargetClusterInfo(targetClusterTree, machineInfoData.getMachineInfoTable(), targetClusterInfoList);
- if (targetClusterInfoList.ordinality())
- resp.setTargetClusterInfoList(targetClusterInfoList);
- }
- char timeStamp[32];
- getTimeStamp(timeStamp);
- resp.setTimeStamp( timeStamp );
- if (version >= 1.12)
- {
- StringBuffer acceptLanguage;
- resp.setAcceptLanguage(getAcceptLanguage(context, acceptLanguage).str());
- }
- }
- void Cws_machineEx::setTargetClusterInfo(IPropertyTree* pTargetClusterTree, IArrayOf<IEspMachineInfoEx>& machineArray, IArrayOf<IEspTargetClusterInfo>& targetClusterInfoList)
- {
- if (!pTargetClusterTree)
- return;
- unsigned machineCount = machineArray.ordinality();
- if (machineCount < 1)
- return;
- Owned<IPropertyTreeIterator> targetClusters = pTargetClusterTree->getElements("TargetCluster");
- ForEach(*targetClusters)
- {
- IPropertyTree& targetCluster = targetClusters->query();
- StringBuffer targetName, targetType;
- targetCluster.getProp("@Name", targetName);
- targetCluster.getProp("@Type", targetType);
- Owned<IEspTargetClusterInfo> targetClusterInfo = static_cast<IEspTargetClusterInfo*>(new CTargetClusterInfo(""));
- targetClusterInfo->setName( targetName.str() );
- targetClusterInfo->setType( targetType.str() );
- IArrayOf<IEspMachineInfoEx> machineArrayNew;
- Owned<IPropertyTreeIterator> processes = targetCluster.getElements("Process");
- ForEach(*processes)
- {
- IPropertyTree& process = processes->query();
- StringBuffer processName, processType;
- process.getProp("@Name", processName);
- process.getProp("@Type", processType);
- for (unsigned i = 0; i < machineCount; i++)
- {
- IEspMachineInfoEx& machineInfoEx = machineArray.item(i);
- const char* name = machineInfoEx.getComponentName();
- const char* type = machineInfoEx.getProcessType();
- if (!name || !type || !strieq(name, processName.str()) || !strieq(getProcessTypeFromMachineType(type), processType.str()))
- continue;
- Owned<IEspMachineInfoEx> pMachineInfo = static_cast<IEspMachineInfoEx*>(new CMachineInfoEx(""));
- pMachineInfo->copy(machineInfoEx);
- machineArrayNew.append(*pMachineInfo.getLink());
- //Cannot break here because more than one processes match (ex. EclAgent/AgentExec)
- }
- }
- if (machineArrayNew.ordinality())
- targetClusterInfo->setProcesses(machineArrayNew);
- targetClusterInfoList.append(*targetClusterInfo.getLink());
- }
- }
- const char* Cws_machineEx::getProcessTypeFromMachineType(const char* machineType)
- {
- const char* processType ="Unknown";
- if (!machineType || !*machineType)
- return processType;
- if (strieq(machineType, eqThorMasterProcess) || strieq(machineType, eqThorSlaveProcess) || strieq(machineType, eqThorSpareProcess))
- {
- processType = eqThorCluster;
- }
- else if (strieq(machineType, eqRoxieServerProcess))
- {
- processType = eqRoxieCluster;
- }
- else if (strieq(machineType, eqAgentExec))
- {
- processType = eqEclAgent;
- }
- else
- {
- processType = machineType;
- }
- return processType;
- }
- IConstEnvironment* Cws_machineEx::getConstEnvironment()
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- if (!constEnv)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get environment information.");
- return constEnv.getLink();
- }
- //Used in Rexec
- IPropertyTree* Cws_machineEx::getComponent(const char* compType, const char* compName)
- {
- StringBuffer xpath;
- xpath.append("Software/").append(compType).append("[@name='").append(compName).append("']");
- Owned<IConstEnvironment> constEnv = getConstEnvironment();
- Owned<IPropertyTree> pEnvRoot = &constEnv->getPTree();
- return pEnvRoot->getPropTree( xpath.str() );
- }
- void Cws_machineEx::getAccountAndPlatformInfo(const char* address, StringBuffer& userId, StringBuffer& password, bool& bLinux)
- {
- Owned<IConstEnvironment> constEnv = getConstEnvironment();
- Owned<IConstMachineInfo> machine = constEnv->getMachineByAddress(address);
- if (!machine && strieq(address, "."))
- {
- machine.setown(constEnv->getMachineByAddress("127.0.0.1"));
- }
- if (!machine)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Machine %s is not defined in environment!", address);
- Owned<IConstDomainInfo> domain = machine->getDomain();
- if (!domain)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Machine %s does not have any domain information!", address);
- userId.clear();
- password.clear();
- StringBufferAdaptor strval1(userId);
- StringBufferAdaptor strval2(password);
- domain->getAccountInfo(strval1, strval2);
- StringBuffer domainName;
- StringBufferAdaptor strval3(domainName);
- domain->getName(strval3);
- if ((machine->getOS() == MachineOsW2K) && domainName.length())
- {
- domainName.append('\\');
- userId.insert(0, domainName);
- }
- bLinux = machine->getOS() == MachineOsLinux;
- }
- IPropertyTree* Cws_machineEx::createDiskUsageReq(IPropertyTree* envDirectories, const char* pathName,
- const char* componentType, const char* componentName)
- {
- StringBuffer path;
- if (!getConfigurationDirectory(envDirectories, pathName, componentType, componentName, path))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get %s Disk Path for component %s", pathName, componentName);
- Owned<IPropertyTree> diskReq = createPTree("Folder");
- diskReq->addProp("@name", pathName);
- diskReq->addProp("@path", path);
- return diskReq.getClear();
- }
- IPropertyTree* Cws_machineEx::createMachineUsageReq(IConstEnvironment* constEnv, const char* computer)
- {
- Owned<IConstMachineInfo> machine = constEnv->getMachine(computer);
- if (!machine)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get machine %s", computer);
- Owned<IPropertyTree> machineReq = createPTree("Machine");
- machineReq->addProp("@name", computer);
- SCMStringBuffer netAddress;
- machine->getNetAddress(netAddress);
- machineReq->addProp("@netAddress", netAddress.str());
- machineReq->addPropInt("@OS", machine->getOS());
- return machineReq.getClear();
- }
- void Cws_machineEx::readThorUsageReq(const char* name, IConstEnvironment* constEnv, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Thor name");
- Owned<IPropertyTree> componentReq = createPTree("Component");
- componentReq->addProp("@name", name);
- componentReq->addProp("@type", eqThorCluster);
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- IPropertyTree* envDirectories = envRoot->queryPropTree("Software/Directories");
- Owned<IPropertyTree> logFolder = createDiskUsageReq(envDirectories, "log", "thor", name);
- Owned<IPropertyTree> dataFolder = createDiskUsageReq(envDirectories, "data", "thor", name);
- Owned<IPropertyTree> repFolder = createDiskUsageReq(envDirectories, "mirror", "thor", name);
- VStringBuffer xpath("Software/ThorCluster[@name='%s']/ThorSlaveProcess", name);
- Owned<IPropertyTreeIterator> slaveProcesses= envRoot->getElements(xpath);
- ForEach(*slaveProcesses)
- {
- IPropertyTree& slaveProcess = slaveProcesses->query();
- const char* computer = slaveProcess.queryProp("@computer");
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get @computer for %s", xpath.str());
- Owned<IPropertyTree> newMachineReq = createMachineUsageReq(constEnv, computer);
- //Not sure we need those folders here. Add them just in case.
- if (logFolder)
- newMachineReq->addPropTree(logFolder->queryName(), LINK(logFolder));
- if (dataFolder)
- newMachineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
- if (repFolder)
- newMachineReq->addPropTree(repFolder->queryName(), LINK(repFolder));
- componentReq->addPropTree(newMachineReq->queryName(), LINK(newMachineReq));
- }
- //Read ThorMasterProcess in case it is on a different machine
- xpath.setf("Software/ThorCluster[@name='%s']/ThorMasterProcess/@computer", name);
- const char* computer = envRoot->queryProp(xpath);
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get %s", xpath.str());
- Owned<IPropertyTree> machineReq = createMachineUsageReq(constEnv, computer);
- xpath.setf("Machine[@netAddress='%s']", machineReq->queryProp("@netAddress"));
- if (componentReq->queryPropTree(xpath))
- { //ThorMasterProcess is running on one of the ThorSlaveProcess machines.
- //So, we do not add this machine again.
- usageReq->addPropTree(componentReq->queryName(), LINK(componentReq));
- return;
- }
- //Not sure we need those folders here. Add them just in case.
- if (logFolder)
- machineReq->addPropTree(logFolder->queryName(), LINK(logFolder));
- if (dataFolder)
- machineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
- if (repFolder)
- machineReq->addPropTree(repFolder->queryName(), LINK(repFolder));
- componentReq->addPropTree(machineReq->queryName(), LINK(machineReq));
- usageReq->addPropTree(componentReq->queryName(), LINK(componentReq));
- }
- void Cws_machineEx::readRoxieUsageReq(const char* name, IConstEnvironment* constEnv, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Roxie name");
- Owned<IPropertyTree> componentReq = createPTree("Component");
- componentReq->addProp("@name", name);
- componentReq->addProp("@type", eqRoxieCluster);
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- IPropertyTree* envDirectories = envRoot->queryPropTree("Software/Directories");
- Owned<IPropertyTree> logFolder = createDiskUsageReq(envDirectories, "log", "roxie", name);
- Owned<IPropertyTree> dataFolder = createDiskUsageReq(envDirectories, "data", "roxie", name);
- VStringBuffer xpath("Software/RoxieCluster[@name='%s']/RoxieServerProcess", name);
- Owned<IPropertyTreeIterator> slaveProcesses= envRoot->getElements(xpath);
- ForEach(*slaveProcesses)
- {
- IPropertyTree& slaveProcess = slaveProcesses->query();
- const char* computer = slaveProcess.queryProp("@computer");
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get @computer for %s", xpath.str());
- Owned<IPropertyTree> newMachineReq = createMachineUsageReq(constEnv, computer);
- //Not sure we need those folders here. Add them just in case.
- if (logFolder)
- newMachineReq->addPropTree(logFolder->queryName(), LINK(logFolder));
- if (dataFolder)
- newMachineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
- componentReq->addPropTree(newMachineReq->queryName(), LINK(newMachineReq));
- }
- usageReq->addPropTree(componentReq->queryName(), LINK(componentReq));
- }
- void Cws_machineEx::readDropZoneUsageReq(const char* name, IConstEnvironment* constEnv, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty DropZone name");
- Owned<IConstDropZoneInfo> envDropZone = constEnv->getDropZone(name);
- if (!envDropZone || !envDropZone->isECLWatchVisible())
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Dropzone %s not found", name);
- SCMStringBuffer directory;
- envDropZone->getDirectory(directory);
- if (directory.length() == 0)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get directory for DropZone %s", name);
- Owned<IPropertyTree> dataFolder = createPTree("Folder");
- dataFolder->addProp("@name", "data");
- dataFolder->addProp("@path", directory.str());
- Owned<IPropertyTree> componentReq = createPTree("Component");
- componentReq->addProp("@name", name);
- componentReq->addProp("@type", eqDropZone);
- SCMStringBuffer computerName;
- envDropZone->getComputerName(computerName);
- if (computerName.length() == 0)
- {
- OS_TYPE os = (getPathSepChar(directory.str()) == '/') ? OS_LINUX : OS_WINDOWS;
- Owned<IConstDropZoneServerInfoIterator> servers = envDropZone->getServers();
- ForEach(*servers)
- {
- IConstDropZoneServerInfo &server = servers->query();
- StringBuffer serverNetAddress;
- server.getServer(serverNetAddress.clear());
- Owned<IPropertyTree> machineReq = createPTree("Machine");
- machineReq->addProp("@name", serverNetAddress.str());
- machineReq->addProp("@netAddress", serverNetAddress.str());
- machineReq->addPropInt("@OS", os);
- machineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
- componentReq->addPropTree(machineReq->queryName(), LINK(machineReq));
- }
- }
- else
- { //legacy dropzone settings
- Owned<IPropertyTree> machineReq = createMachineUsageReq(constEnv, computerName.str());
- machineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
- componentReq->addPropTree(machineReq->queryName(), LINK(machineReq));
- }
- usageReq->addPropTree(componentReq->queryName(), LINK(componentReq));
- }
- void Cws_machineEx::readOtherComponentUsageReq(const char* name, const char* type, IConstEnvironment* constEnv, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Component name");
- const char* componentType = findComponentTypeFromProcessType(type);
- if (!componentType)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Component usage function is not supported for %s", type);
- Owned<IPropertyTree> componentReq = createPTree("Component");
- componentReq->addProp("@name", name);
- componentReq->addProp("@type", type);
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- VStringBuffer xpath("Software/%s[@name='%s']/Instance", type, name);
- Owned<IPropertyTreeIterator> it = envRoot->getElements(xpath);
- ForEach(*it)
- {
- IPropertyTree& instance = it->query();
- const char* computer = instance.queryProp("@computer");
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get %s", xpath.str());
-
- Owned<IPropertyTree> machineReq = createMachineUsageReq(constEnv, computer);
-
- IPropertyTree* envDirectories = envRoot->queryPropTree("Software/Directories");
- Owned<IPropertyTree> logFolder = createDiskUsageReq(envDirectories, "log", type, name);
- if (logFolder)
- machineReq->addPropTree(logFolder->queryName(), LINK(logFolder));
- Owned<IPropertyTree> dataFolder = createDiskUsageReq(envDirectories, "data", componentType, name);
- if (dataFolder)
- machineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
-
- if (strieq(type, eqDali))
- {
- Owned<IPropertyTree> repFolder = createDiskUsageReq(envDirectories, "mirror", "dali", name);
- if (repFolder)
- machineReq->addPropTree(repFolder->queryName(), LINK(repFolder));
- }
- componentReq->addPropTree(machineReq->queryName(), LINK(machineReq));
- }
- usageReq->addPropTree(componentReq->queryName(), LINK(componentReq));
- }
- void Cws_machineEx::setUniqueMachineUsageReq(IPropertyTree* usageReq, IPropertyTree* uniqueUsages)
- {
- Owned<IPropertyTreeIterator> components= usageReq->getElements("Component");
- ForEach(*components)
- {
- IPropertyTree& component = components->query();
- Owned<IPropertyTreeIterator> machines= component.getElements("Machine");
- ForEach(*machines)
- {
- IPropertyTree& machine = machines->query();
- const char* netAddress = machine.queryProp("@netAddress");
-
- VStringBuffer xpath("Machine[@netAddress='%s']", netAddress);
- IPropertyTree* uniqueMachineReqTree = uniqueUsages->queryPropTree(xpath);
- if (!uniqueMachineReqTree)
- {
- uniqueUsages->addPropTree(machine.queryName(), LINK(&machine));
- continue;
- }
- //Add unique disk folders from the usageReq.
- Owned<IPropertyTreeIterator> folders = machine.getElements("Folder");
- ForEach(*folders)
- {
- IPropertyTree& folder = folders->query();
- const char* aDiskPath = folder.queryProp("@path");
- xpath.setf("Folder[@path='%s']", aDiskPath);
- IPropertyTree* uniqueFolderReqTree = uniqueMachineReqTree->queryPropTree(xpath);
- if (!uniqueFolderReqTree)
- {
- Owned<IPropertyTree> folderReq = createPTree("Folder");
- folderReq->addProp("@name", folder.queryProp("@name"));
- folderReq->addProp("@path", aDiskPath);
- uniqueMachineReqTree->addPropTree(folderReq->queryName(), LINK(folderReq));
- }
- }
- }
- }
- }
- IArrayOf<IConstComponent>& Cws_machineEx::listComponentsByType(IPropertyTree* envRoot,
- const char* componentType, IArrayOf<IConstComponent>& componentList)
- {
- VStringBuffer xpath("Software/%s", componentType);
- Owned<IPropertyTreeIterator> components= envRoot->getElements(xpath);
- ForEach(*components)
- {
- Owned<IEspComponent> component = createComponent();
- component->setName(components->query().queryProp("@name"));
- component->setType(componentType);
- componentList.append(*component.getClear());
- }
- return componentList;
- }
- IArrayOf<IConstComponent>& Cws_machineEx::listComponentsForCheckingUsage(IConstEnvironment* constEnv,
- IArrayOf<IConstComponent>& componentList)
- {
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- listComponentsByType(envRoot, eqThorCluster, componentList);
- listComponentsByType(envRoot, eqRoxieCluster, componentList);
- listComponentsByType(envRoot, eqDali, componentList);
- listComponentsByType(envRoot, eqEclAgent, componentList);
- listComponentsByType(envRoot, eqSashaServer, componentList);
- listComponentsByType(envRoot, eqDropZone, componentList);
- listComponentsByType(envRoot, eqDfu, componentList);
- listComponentsByType(envRoot, eqEclCCServer, componentList);
- listComponentsByType(envRoot, eqEclServer, componentList);
- listComponentsByType(envRoot, eqEclScheduler, componentList);
- listComponentsByType(envRoot, eqEsp, componentList);
- return componentList;
- }
- IPropertyTree* Cws_machineEx::getComponentUsageReq(IEspGetComponentUsageRequest& req, IConstEnvironment* constEnv)
- {
- IArrayOf<IConstComponent>& componentList = req.getComponents();
- if (!componentList.length())
- listComponentsForCheckingUsage(constEnv, componentList);
- Owned<IPropertyTree> usageReq = createPTree("Req");
- ForEachItemIn(i, componentList)
- {
- IConstComponent& component = componentList.item(i);
- const char* type = component.getType();
- if (isEmptyString(type))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Component Type");
- if (strieq(type, eqThorCluster))
- readThorUsageReq(component.getName(), constEnv, usageReq);
- else if (strieq(type, eqRoxieCluster))
- readRoxieUsageReq(component.getName(), constEnv, usageReq);
- else if (strieq(type, eqDropZone))
- readDropZoneUsageReq(component.getName(), constEnv, usageReq);
- else
- readOtherComponentUsageReq(component.getName(), type, constEnv, usageReq);
- }
- return usageReq.getClear();
- }
- void Cws_machineEx::getMachineUsages(IEspContext& context, IPropertyTree* uniqueUsages)
- {
- UnsignedArray threadHandles;
- Owned<IPropertyTreeIterator> requests= uniqueUsages->getElements("Machine");
- ForEach(*requests)
- {
- Owned<CGetMachineUsageThreadParam> threadParam = new CGetMachineUsageThreadParam(this, context, &requests->query());
- PooledThreadHandle handle = m_threadPool->start(threadParam.getClear());
- threadHandles.append(handle);
- }
- ForEachItemIn(i, threadHandles)
- m_threadPool->join(threadHandles.item(i));
- }
- bool Cws_machineEx::readDiskSpaceResponse(const char* response, __int64& free, __int64& used, int& percentAvail, StringBuffer& pathUsed)
- {
- if (isEmptyString(response))
- return false;
- StringArray data;
- data.appendList(response, " ");
- if (data.length() < 2)
- return false;
- used = atol(data.item(0));
- free = atol(data.item(1));
- __int64 total = free + used;
- if (total > 0)
- percentAvail = (int) ((free*100)/total);
- //The given path (ex. /var/lib/HPCCSystems/hpcc-mirror/thor) in the usage request does not exist.
- //The data.item(2) is the path (ex. /var/lib/HPCCSystems/hpcc-mirror/) the usage script is used
- //to read the DiskSpace.
- if (data.length() > 2)
- pathUsed.set(data.item(2));
- return true;
- }
- void Cws_machineEx::getMachineUsage(IEspContext& context, CGetMachineUsageThreadParam* param)
- {
- VStringBuffer command("/%s/sbin/usage -d=", environmentConfData.m_executionPath.str());
- unsigned pathCount = 0;
- Owned<IPropertyTreeIterator> diskPathList = param->request->getElements("Folder");
- ForEach(*diskPathList)
- {
- IPropertyTree& t = diskPathList->query();
- if (pathCount > 0)
- command.append(",");
- command.appendf("%s", t.queryProp("@path"));
- pathCount++;
- }
- ESPLOG(LogMax, "command(%s)", command.str());
- StringBuffer response;
- int error = runCommand(context, param->request->queryProp("@netAddress"), nullptr,
- (EnvMachineOS) param->request->getPropInt("@OS", MachineOsLinux), command.str(), nullptr, nullptr, response);
- if (error != 0 || isEmptyString(response))
- {
- if (isEmptyString(response))
- param->request->addProp("@error", "Failed in getting component usage.");
- else
- param->request->addProp("@error", response);
- return;
- }
- ESPLOG(LogMax, "response(%s)", response.str());
- ForEach(*diskPathList)
- {
- IPropertyTree& diskPathTree = diskPathList->query();
- StringBuffer aDiskPathResp, pathUsed;
- VStringBuffer diskPath("%s:", diskPathTree.queryProp("@path"));
- readALineFromResult(response, diskPath, aDiskPathResp, true);
- int percentAvail = 0;
- __int64 diskSpaceAvailable = 0, diskSpaceUsed = 0;
- if (!readDiskSpaceResponse(aDiskPathResp.str(), diskSpaceAvailable, diskSpaceUsed, percentAvail, pathUsed))
- {
- DBGLOG("Failed to read disc space on %s: %s", param->request->queryProp("@netAddress"), aDiskPathResp.str());
- diskPathTree.addProp("@error", "Failed to read disc space.");
- continue;
- }
- diskPathTree.addPropInt64("@used", diskSpaceUsed);
- diskPathTree.addPropInt64("@available", diskSpaceAvailable);
- diskPathTree.addPropInt("@percentAvail", percentAvail);
- if (!pathUsed.isEmpty())
- diskPathTree.addProp("@pathUsed", pathUsed);
- }
- }
- void Cws_machineEx::readComponentUsageResult(IEspContext& context, IPropertyTree* usageReq,
- const IPropertyTree* uniqueUsages, IArrayOf<IEspComponentUsage>& componentUsages)
- {
- double version = context.getClientVersion();
- Owned<IPropertyTreeIterator> components= usageReq->getElements("Component");
- ForEach(*components)
- {
- IPropertyTree& component = components->query();
- Owned<IEspComponentUsage> componentUsage = createComponentUsage();
- componentUsage->setName(component.queryProp("@name"));
- componentUsage->setType(component.queryProp("@type"));
- IArrayOf<IEspMachineUsage> machineUsages;
- Owned<IPropertyTreeIterator> machines= component.getElements("Machine");
- ForEach(*machines)
- {
- IPropertyTree& machine = machines->query();
- const char* netAddress = machine.queryProp("@netAddress");
- Owned<IEspMachineUsage> machineUsage = createMachineUsage();
- machineUsage->setName(machine.queryProp("@name"));
- machineUsage->setNetAddress(netAddress);
- VStringBuffer xpath("Machine[@netAddress='%s']", netAddress);
- IPropertyTree* uniqueMachineReqTree = uniqueUsages->queryPropTree(xpath);
- if (!uniqueMachineReqTree)
- {
- if (version < 1.17)
- machineUsage->setDescription("No data returns.");
- else
- machineUsage->setException("No data returns.");
- machineUsages.append(*machineUsage.getClear());
- continue;
- }
- const char* error = uniqueMachineReqTree->queryProp("@error");
- if (!isEmptyString(error))
- {
- if (version < 1.17)
- machineUsage->setDescription(error);
- else
- machineUsage->setException(error);
- machineUsages.append(*machineUsage.getClear());
- continue;
- }
- IArrayOf<IEspDiskUsage> diskUsages;
- Owned<IPropertyTreeIterator> folders = machine.getElements("Folder");
- ForEach(*folders)
- {
- IPropertyTree& folder = folders->query();
- const char* aDiskPath = folder.queryProp("@path");
- Owned<IEspDiskUsage> diskUsage = createDiskUsage();
- diskUsage->setName(folder.queryProp("@name"));
- diskUsage->setPath(aDiskPath);
- xpath.setf("Folder[@path='%s']", aDiskPath);
- IPropertyTree* folderTree = uniqueMachineReqTree->queryPropTree(xpath);
- if (!folderTree)
- {
- if (version < 1.17)
- diskUsage->setDescription("No data returns.");
- else
- diskUsage->setException("No data returns.");
- }
- else
- {
- const char* error = folderTree->queryProp("@error");
- if (!isEmptyString(error))
- {
- if (version < 1.17)
- diskUsage->setDescription(error);
- else
- diskUsage->setException(error);
- }
- else
- {
- diskUsage->setAvailable(folderTree->getPropInt64("@available"));
- diskUsage->setInUse(folderTree->getPropInt64("@used"));
- diskUsage->setPercentAvailable(folderTree->getPropInt("@percentAvail"));
- const char* pathUsed = folderTree->queryProp("@pathUsed");
- if (!isEmptyString(pathUsed))
- {
- VStringBuffer desc("%s not found. Read disk usage from %s", aDiskPath, pathUsed);
- diskUsage->setDescription(desc);
- }
- }
- }
- diskUsages.append(*diskUsage.getClear());
- }
- machineUsage->setDiskUsages(diskUsages);
- machineUsages.append(*machineUsage.getClear());
- }
- componentUsage->setMachineUsages(machineUsages);
- componentUsages.append(*componentUsage.getClear());
- }
- }
- StringBuffer& Cws_machineEx::setUsageTimeStr(CUsageCache* usageCache, StringBuffer& timeStr)
- {
- if (usageCache)
- usageCache->queryTimeCached(timeStr);
- else
- {
- CDateTime timeNow;
- timeNow.setNow();
- timeNow.getString(timeStr, true);
- }
- return timeStr;
- }
- bool Cws_machineEx::onGetComponentUsage(IEspContext& context, IEspGetComponentUsageRequest& req,
- IEspGetComponentUsageResponse& resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Machine Information. Permission denied.");
- double version = context.getClientVersion();
- StringBuffer timeStr;
- IArrayOf<IEspComponentUsage> componentUsages;
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> usageReq = getComponentUsageReq(req, constEnv);
- Owned<CUsageCache> usage;
- Owned<const IPropertyTree> uniqueUsages;
- if (req.getBypassCachedResult())
- {
- Owned<IPropertyTree> tmpUniqueUsages = createPTree("Usage");
- //Add unique machines from the usageReq to uniqueUsages.
- setUniqueMachineUsageReq(usageReq, tmpUniqueUsages);
- getMachineUsages(context, tmpUniqueUsages);
- uniqueUsages.setown(tmpUniqueUsages.getClear());
- }
- else
- {
- usage.setown((CUsageCache*) usageCacheReader->getCachedInfo());
- if (!usage)
- throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to get usage. Please try later.");
- ESPLOG(LogMax, "GetComponentUsage: found UsageCache.");
- uniqueUsages.set(usage->queryUsages());
- }
- readComponentUsageResult(context, usageReq, uniqueUsages, componentUsages);
- if (version >= 1.17)
- resp.setUsageTime(setUsageTimeStr(usage, timeStr));
- resp.setComponentUsages(componentUsages);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- StringArray& Cws_machineEx::listTargetClusterNames(IConstEnvironment* constEnv, StringArray& targetClusters)
- {
- Owned<IStringIterator> targets = getTargetClusters(nullptr, nullptr);
- ForEach(*targets)
- {
- SCMStringBuffer target;
- targetClusters.append(targets->str(target).str());
- }
- return targetClusters;
- }
- IPropertyTree* Cws_machineEx::getTargetClusterUsageReq(IEspGetTargetClusterUsageRequest& req, IConstEnvironment* constEnv)
- {
- StringArray& targetClusters = req.getTargetClusters();
- if (targetClusters.empty())
- listTargetClusterNames(constEnv, targetClusters);
- Owned<IPropertyTree> usageReq = createPTree("Req");
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- ForEachItemIn(i, targetClusters)
- {
- const char* targetClusterName = targetClusters.item(i);
- if (isEmptyString(targetClusterName))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Target Cluster specified.");
- Owned<IConstWUClusterInfo> targetClusterInfo = getTargetClusterInfo(targetClusterName);
- if (!targetClusterInfo)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Could not find information about target cluster %s ", targetClusterName);
- Owned<IPropertyTree> targetClusterTree = createPTree("TargetCluster");
- targetClusterTree->addProp("@name", targetClusterName);
- const StringArray& thors = targetClusterInfo->getThorProcesses();
- ForEachItemIn(i, thors)
- {
- const char* thor = thors.item(i);
- if (!isEmptyString(thor))
- readThorUsageReq(thor, constEnv, targetClusterTree);
- }
- SCMStringBuffer roxie;
- targetClusterInfo->getRoxieProcess(roxie);
- if (roxie.length())
- readRoxieUsageReq(roxie.str(), constEnv, targetClusterTree);
- SCMStringBuffer eclAgent, eclScheduler;
- targetClusterInfo->getAgentName(eclAgent);
- if (eclAgent.length())
- readOtherComponentUsageReq(eclAgent.str(), eqEclAgent, constEnv, targetClusterTree);
- targetClusterInfo->getECLSchedulerName(eclScheduler);
- if (eclScheduler.length())
- readOtherComponentUsageReq(eclScheduler.str(), eqEclScheduler, constEnv, targetClusterTree);
- const StringArray& eclServers = targetClusterInfo->getECLServerNames();
- ForEachItemIn(j, eclServers)
- readOtherComponentUsageReq(eclServers.item(j), targetClusterInfo->isLegacyEclServer() ? eqEclServer : eqEclCCServer, constEnv, targetClusterTree);
- usageReq->addPropTree(targetClusterTree->queryName(), LINK(targetClusterTree));
- }
- return usageReq.getClear();
- }
- void Cws_machineEx::readTargetClusterUsageResult(IEspContext& context, IPropertyTree* usageReq,
- const IPropertyTree* uniqueUsages, IArrayOf<IEspTargetClusterUsage>& targetClusterUsages)
- {
- Owned<IPropertyTreeIterator> targetClusters= usageReq->getElements("TargetCluster");
- ForEach(*targetClusters)
- {
- IPropertyTree& targetCluster = targetClusters->query();
- Owned<IEspTargetClusterUsage> targetClusterUsage = createTargetClusterUsage();
- targetClusterUsage->setName(targetCluster.queryProp("@name"));
- IArrayOf<IEspComponentUsage> componentUsages;
- readComponentUsageResult(context, &targetCluster, uniqueUsages, componentUsages);
- targetClusterUsage->setComponentUsages(componentUsages);
- targetClusterUsages.append(*targetClusterUsage.getClear());
- }
- }
- bool Cws_machineEx::onGetTargetClusterUsage(IEspContext& context, IEspGetTargetClusterUsageRequest& req,
- IEspGetTargetClusterUsageResponse& resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Machine Information. Permission denied.");
- double version = context.getClientVersion();
- StringBuffer timeStr;
- IArrayOf<IEspTargetClusterUsage> targetClusterUsages;
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> usageReq = getTargetClusterUsageReq(req, constEnv);
- Owned<CUsageCache> usage;
- Owned<const IPropertyTree> uniqueUsages;
- if (req.getBypassCachedResult())
- {
- Owned<IPropertyTree> tmpUniqueUsages = createPTree("Usage");
- Owned<IPropertyTreeIterator> targetClusterItr= usageReq->getElements("TargetCluster");
- ForEach(*targetClusterItr)
- {
- IPropertyTree& targetCluster = targetClusterItr->query();
- setUniqueMachineUsageReq(&targetCluster, tmpUniqueUsages);
- }
- getMachineUsages(context, tmpUniqueUsages);
- uniqueUsages.setown(tmpUniqueUsages.getClear());
- }
- else
- {
- usage.setown((CUsageCache*) usageCacheReader->getCachedInfo());
- if (!usage)
- throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to get usage. Please try later.");
- ESPLOG(LogMax, "GetTargetClusterUsage: found UsageCache.");
- uniqueUsages.set(usage->queryUsages());
- }
- readTargetClusterUsageResult(context, usageReq, uniqueUsages, targetClusterUsages);
- if (version >= 1.17)
- resp.setUsageTime(setUsageTimeStr(usage, timeStr));
- resp.setTargetClusterUsages(targetClusterUsages);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool Cws_machineEx::getEclAgentNameFromNodeGroupName(const char* nodeGroupName, StringBuffer& agentName)
- {
- //Node group name for an eclagent should be: 'hthor__' + ECLAgentName[ + '_' + a number]
- if ((strlen(nodeGroupName) <= 7) || strnicmp(nodeGroupName, "hthor__", 7))
- return false;
- agentName.set(nodeGroupName + 7);
- const char* ptr = strrchr(agentName.str(), '_');
- if (isEmptyString(ptr) || isEmptyString(++ptr))
- return true;
- const char* ptrSuffix = ptr - 1;
- do
- {
- if (!isdigit(ptr[0]))
- return true;
- ptr++;
- } while(!isEmptyString(ptr));
- agentName.setLength(agentName.length() - (ptr - ptrSuffix));
- return true;
- }
- void Cws_machineEx::getThorClusterNamesByGroupName(IPropertyTree* envRoot, const char* group, StringArray& thorClusterNames)
- {
- Owned<IPropertyTreeIterator> thorClusters= envRoot->getElements("Software/ThorCluster");
- ForEach(*thorClusters)
- {
- IPropertyTree& thorCluster = thorClusters->query();
- const char *nodeGroupName = thorCluster.queryProp("@nodeGroup");
- if (!isEmptyString(nodeGroupName) && !strieq(nodeGroupName, group))
- continue;
- if (!isEmptyString(nodeGroupName))
- thorClusterNames.append(nodeGroupName);
- else
- {
- const char *name = thorCluster.queryProp("@name");
- if (strieq(name, group))
- thorClusterNames.append(name);
- }
- }
- }
- StringArray& Cws_machineEx::listThorHThorNodeGroups(IConstEnvironment* constEnv, StringArray& nodeGroups)
- {
- BoolHash uniqueThorClusterGroupNames;
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- Owned<IPropertyTreeIterator> it =envRoot->getElements("Software/ThorCluster");
- ForEach(*it)
- {
- IPropertyTree& cluster = it->query();
- StringBuffer thorClusterGroupName;
- getClusterGroupName(cluster, thorClusterGroupName);
- if (!thorClusterGroupName.length())
- continue;
- bool* found = uniqueThorClusterGroupNames.getValue(thorClusterGroupName);
- if (found && *found)
- continue;
- nodeGroups.append(thorClusterGroupName);
- uniqueThorClusterGroupNames.setValue(thorClusterGroupName, true);
- }
- it.setown(envRoot->getElements("Software/EclAgentProcess"));
- ForEach(*it)
- {
- IPropertyTree &cluster = it->query();
- const char* name = cluster.queryProp("@name");
- if (!name||!*name)
- continue;
- unsigned ins = 0;
- Owned<IPropertyTreeIterator> insts = cluster.getElements("Instance");
- ForEach(*insts)
- {
- ins++;
- StringBuffer gname("hthor__");
- gname.append(name);
- if (ins>1)
- gname.append('_').append(ins);
- nodeGroups.append(gname);
- }
- }
- return nodeGroups;
- }
- IPropertyTree* Cws_machineEx::getNodeGroupUsageReq(IEspGetNodeGroupUsageRequest& req, IConstEnvironment* constEnv)
- {
- StringArray& nodeGroups = req.getNodeGroups();
- if (nodeGroups.empty())
- listThorHThorNodeGroups(constEnv, nodeGroups);
- if (nodeGroups.empty())
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "No node group found.");
- Owned<IPropertyTree> usageReq = createPTree("Req");
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- ForEachItemIn(i, nodeGroups)
- {
- const char* nodeGroupName = nodeGroups.item(i);
- if (isEmptyString(nodeGroupName))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty node group specified.");
- Owned<IPropertyTree> nodeGroupTree = createPTree("NodeGroup");
- nodeGroupTree->addProp("@name", nodeGroupName);
- StringBuffer agentName;
- if (getEclAgentNameFromNodeGroupName(nodeGroupName, agentName))
- readOtherComponentUsageReq(agentName.str(), eqEclAgent, constEnv, nodeGroupTree);
- else
- {
- StringArray thorNames;
- getThorClusterNamesByGroupName(envRoot, nodeGroupName, thorNames);
- if (thorNames.length() == 0)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "No thor/hthor can be found for node group name %s.", nodeGroupName);
- ForEachItemIn(ii, thorNames)
- readThorUsageReq(thorNames.item(ii), constEnv, nodeGroupTree);
- }
- usageReq->addPropTree(nodeGroupTree->queryName(), LINK(nodeGroupTree));
- }
- return usageReq.getClear();
- }
- void Cws_machineEx::readNodeGroupUsageResult(IEspContext& context, IPropertyTree* usageReq,
- const IPropertyTree* uniqueUsages, IArrayOf<IEspNodeGroupUsage>& nodeGroupUsages)
- {
- Owned<IPropertyTreeIterator> nodeGroups= usageReq->getElements("NodeGroup");
- ForEach(*nodeGroups)
- {
- IPropertyTree& nodeGroup = nodeGroups->query();
- Owned<IEspNodeGroupUsage> nodeGroupUsage = createNodeGroupUsage();
- nodeGroupUsage->setName(nodeGroup.queryProp("@name"));
- IArrayOf<IEspComponentUsage> componentUsages;
- readComponentUsageResult(context, &nodeGroup, uniqueUsages, componentUsages);
- nodeGroupUsage->setComponentUsages(componentUsages);
- nodeGroupUsages.append(*nodeGroupUsage.getClear());
- }
- }
- bool Cws_machineEx::onGetNodeGroupUsage(IEspContext& context, IEspGetNodeGroupUsageRequest& req,
- IEspGetNodeGroupUsageResponse& resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Machine Information. Permission denied.");
- double version = context.getClientVersion();
- StringBuffer timeStr;
- IArrayOf<IEspNodeGroupUsage> nodeGroupUsages;
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> usageReq = getNodeGroupUsageReq(req, constEnv);
- Owned<CUsageCache> usage;
- Owned<const IPropertyTree> uniqueUsages;
- if (req.getBypassCachedResult())
- {
- Owned<IPropertyTree> tmpUniqueUsages = createPTree("Usage");
- Owned<IPropertyTreeIterator> nodeGroupItr= usageReq->getElements("NodeGroup");
- ForEach(*nodeGroupItr)
- {
- IPropertyTree& nodeGroup = nodeGroupItr->query();
- setUniqueMachineUsageReq(&nodeGroup, tmpUniqueUsages);
- }
- getMachineUsages(context, tmpUniqueUsages);
- uniqueUsages.setown(tmpUniqueUsages.getClear());
- }
- else
- {
- usage.setown((CUsageCache*) usageCacheReader->getCachedInfo());
- if (!usage)
- throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to get usage. Please try later.");
- ESPLOG(LogMax, "GetNodeGroupUsage: found UsageCache.");
- uniqueUsages.set(usage->queryUsages());
- }
- readNodeGroupUsageResult(context, usageReq, uniqueUsages, nodeGroupUsages);
- if (version >= 1.17)
- resp.setUsageTime(setUsageTimeStr(usage, timeStr));
- resp.setNodeGroupUsages(nodeGroupUsages);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool Cws_machineEx::onGetComponentStatus(IEspContext &context, IEspGetComponentStatusRequest &req, IEspGetComponentStatusResponse &resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Get Component Status. Permission denied.");
- Owned<IComponentStatusFactory> factory = getComponentStatusFactory();
- Owned<IESPComponentStatusInfo> status = factory->getComponentStatus();
- if (!status) //Should never happen
- return false;
- int statusID = status->getComponentStatusID();
- if (statusID < 0)
- {
- resp.setStatus("Not reported");
- }
- else
- {
- resp.setComponentType(status->getComponentType());
- resp.setEndPoint(status->getEndPoint());
- resp.setReporter(status->getReporter());
- resp.setComponentStatus(status->getComponentStatus());
- resp.setTimeReportedStr(status->getTimeReportedStr());
- IConstStatusReport* componentStatus = status->getStatusReport();
- if (componentStatus)
- resp.setStatusReport(*componentStatus);
- resp.setComponentStatusList(status->getComponentStatusList());
- }
- resp.setComponentStatusID(statusID);
- resp.setStatusCode(0);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- bool Cws_machineEx::onUpdateComponentStatus(IEspContext &context, IEspUpdateComponentStatusRequest &req, IEspUpdateComponentStatusResponse &resp)
- {
- try
- {
- context.ensureFeatureAccess(FEATURE_URL, SecAccess_Write, ECLWATCH_MACHINE_INFO_ACCESS_DENIED, "Failed to Update Component Status. Permission denied.");
- const char* reporter = req.getReporter();
- if (!reporter || !*reporter)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Report not specified.");
-
- Owned<IComponentStatusFactory> factory = getComponentStatusFactory();
- factory->updateComponentStatus(reporter, req.getComponentStatusList());
- resp.setStatusCode(0);
- }
- catch(IException* e)
- {
- FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
- }
- return true;
- }
- CInfoCache* CUsageCacheReader::read()
- {
- Owned<IPropertyTree> uniqueUsages = getUsageReqAllMachines();
- //Send usage command to each machine
- Owned<IEspContext> espContext = createEspContext();
- servicePtr->getMachineUsages(*espContext, uniqueUsages);
- Owned<CUsageCache> usageCache = new CUsageCache();
- usageCache->setUsages(uniqueUsages.getClear());
- return usageCache.getClear();
- }
- IPropertyTree* CUsageCacheReader::getUsageReqAllMachines()
- {
- //Collect network addresses and HPCC folders for all HPCC machines.
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- IArrayOf<IConstComponent> componentList;
- servicePtr->listComponentsForCheckingUsage(constEnv, componentList);
- //Create a PTree which will be used to store the usages of all HPCC machines.
- Owned<IPropertyTree> uniqueUsages = createPTree("Usage");
- //Store the network addresses and HPCC folders into the PTree.
- //Their usages may be added by calling servicePtr->getMachineUsages().
- ForEachItemIn(i, componentList)
- {
- IConstComponent& component = componentList.item(i);
- const char* type = component.getType();
- if (isEmptyString(type))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Component Type");
- if (strieq(type, eqThorCluster))
- addClusterUsageReq(constEnv, component.getName(), true, uniqueUsages);
- else if (strieq(type, eqRoxieCluster))
- addClusterUsageReq(constEnv, component.getName(), false, uniqueUsages);
- else if (strieq(type, eqDropZone))
- addDropZoneUsageReq(constEnv, component.getName(), uniqueUsages);
- else
- addOtherComponentUsageReq(constEnv, component.getName(), type, uniqueUsages);
- }
- return uniqueUsages.getClear();
- }
- void CUsageCacheReader::addClusterUsageReq(IConstEnvironment* constEnv, const char* name, bool thorCluster, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty cluster name");
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- IPropertyTree* envDirectories = envRoot->queryPropTree("Software/Directories");
- Owned<IPropertyTree> logFolderReq = servicePtr->createDiskUsageReq(envDirectories, "log", thorCluster ? "thor" : "roxie", name);
- Owned<IPropertyTree> dataFolderReq = servicePtr->createDiskUsageReq(envDirectories, "data", thorCluster ? "thor" : "roxie", name);
- Owned<IPropertyTree> repFolderReq;
- if (thorCluster)
- repFolderReq.setown(servicePtr->createDiskUsageReq(envDirectories, "mirror", "thor", name));
- StringBuffer xpath;
- if (thorCluster)
- xpath.setf("Software/ThorCluster[@name='%s']/ThorSlaveProcess", name);
- else
- xpath.setf("Software/RoxieCluster[@name='%s']/RoxieServerProcess", name);
- Owned<IPropertyTreeIterator> processes= envRoot->getElements(xpath);
- ForEach(*processes)
- {
- IPropertyTree& process = processes->query();
- const char* computer = process.queryProp("@computer");
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get @computer for %s", xpath.str());
- checkAndAddMachineUsageReq(constEnv, computer, logFolderReq, dataFolderReq, repFolderReq, usageReq);
- }
- if (!thorCluster)
- return;
- //Read ThorMasterProcess in case it is on a different machine
- xpath.setf("Software/ThorCluster[@name='%s']/ThorMasterProcess/@computer", name);
- const char* computer = envRoot->queryProp(xpath);
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get %s", xpath.str());
- checkAndAddMachineUsageReq(constEnv, computer, logFolderReq, dataFolderReq, repFolderReq, usageReq);
- }
- void CUsageCacheReader::checkAndAddMachineUsageReq(IConstEnvironment* constEnv, const char* computer, IPropertyTree* logFolderReq,
- IPropertyTree* dataFolderReq, IPropertyTree* repFolderReq, IPropertyTree* usageReq)
- {
- Owned<IPropertyTree> machineReq = servicePtr->createMachineUsageReq(constEnv, computer);
- VStringBuffer xpath("Machine[@netAddress='%s']", machineReq->queryProp("@netAddress"));
- IPropertyTree* foundMachineReqTree = usageReq->queryPropTree(xpath);
- if (!foundMachineReqTree)
- {
- //Not sure we need those folders here. Add them just in case.
- if (logFolderReq)
- machineReq->addPropTree(logFolderReq->queryName(), LINK(logFolderReq));
- if (dataFolderReq)
- machineReq->addPropTree(dataFolderReq->queryName(), LINK(dataFolderReq));
- if (repFolderReq)
- machineReq->addPropTree(repFolderReq->queryName(), LINK(repFolderReq));
- usageReq->addPropTree(machineReq->queryName(), LINK(machineReq));
- return;
- }
- //Add unique disk folders
- checkAndAddFolderReq(logFolderReq, foundMachineReqTree);
- checkAndAddFolderReq(dataFolderReq, foundMachineReqTree);
- checkAndAddFolderReq(repFolderReq, foundMachineReqTree);
- }
- void CUsageCacheReader::checkAndAddFolderReq(IPropertyTree* folderReq, IPropertyTree* machineReqTree)
- {
- if (!folderReq)
- return;
- //Add unique disk folders
- VStringBuffer xpath("Folder[@path='%s']", folderReq->queryProp("@path"));
- if (!machineReqTree->queryPropTree(xpath))
- machineReqTree->addPropTree(folderReq->queryName(), LINK(folderReq));
- }
- void CUsageCacheReader::addDropZoneUsageReq(IConstEnvironment* constEnv, const char* name, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty DropZone name");
- Owned<IConstDropZoneInfo> envDropZone = constEnv->getDropZone(name);
- if (!envDropZone)
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Dropzone %s not found", name);
- if (!envDropZone->isECLWatchVisible())
- return;
- SCMStringBuffer directory;
- envDropZone->getDirectory(directory);
- if (directory.length() == 0)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get directory for DropZone %s", name);
- Owned<IPropertyTree> dataFolder = createPTree("Folder");
- dataFolder->addProp("@name", "data");
- dataFolder->addProp("@path", directory.str());
- SCMStringBuffer computerName;
- envDropZone->getComputerName(computerName);
- if (computerName.length() == 0)
- {
- OS_TYPE os = (getPathSepChar(directory.str()) == '/') ? OS_LINUX : OS_WINDOWS;
- Owned<IConstDropZoneServerInfoIterator> servers = envDropZone->getServers();
- ForEach(*servers)
- {
- IConstDropZoneServerInfo& server = servers->query();
- StringBuffer serverNetAddress;
- server.getServer(serverNetAddress.clear());
- VStringBuffer xpath("Machine[@netAddress='%s']", serverNetAddress.str());
- IPropertyTree* foundMachineReqTree = usageReq->queryPropTree(xpath);
- if (foundMachineReqTree)
- {
- checkAndAddFolderReq(dataFolder, foundMachineReqTree);
- continue;
- }
- Owned<IPropertyTree> machineReq = createPTree("Machine");
- machineReq->addProp("@name", serverNetAddress.str());
- machineReq->addProp("@netAddress", serverNetAddress.str());
- machineReq->addPropInt("@OS", os);
- machineReq->addPropTree(dataFolder->queryName(), LINK(dataFolder));
- usageReq->addPropTree(machineReq->queryName(), LINK(machineReq));
- }
- }
- else
- { //legacy dropzone settings
- checkAndAddMachineUsageReq(constEnv, computerName.str(), nullptr, dataFolder, nullptr, usageReq);
- }
- }
- void CUsageCacheReader::addOtherComponentUsageReq(IConstEnvironment* constEnv, const char* name, const char* type, IPropertyTree* usageReq)
- {
- if (isEmptyString(name))
- throw MakeStringException(ECLWATCH_INVALID_INPUT, "Empty Component name");
- const char* componentType = findComponentTypeFromProcessType(type);
- if (!componentType)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Component usage function is not supported for %s", type);
- //Find disk folders for log, data, etc.
- Owned<IPropertyTree> envRoot = &constEnv->getPTree();
- IPropertyTree* envDirectories = envRoot->queryPropTree("Software/Directories");
- Owned<IPropertyTree> dataFolder = servicePtr->createDiskUsageReq(envDirectories, "data", componentType, name);
- Owned<IPropertyTree> logFolder = servicePtr->createDiskUsageReq(envDirectories, "log", componentType, name);
- Owned<IPropertyTree> repFolder;
- if (strieq(type, eqDali))
- repFolder.setown(servicePtr->createDiskUsageReq(envDirectories, "mirror", "dali", name));
- VStringBuffer xpath("Software/%s[@name='%s']/Instance", type, name);
- Owned<IPropertyTreeIterator> it = envRoot->getElements(xpath);
- ForEach(*it)
- {
- IPropertyTree& instance = it->query();
- const char* computer = instance.queryProp("@computer");
- if (isEmptyString(computer))
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get @computer for %s", xpath.str());
- checkAndAddMachineUsageReq(constEnv, computer, logFolder, dataFolder, repFolder, usageReq);
- }
- }
|