1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197 |
- /*##############################################################################
- 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.
- ############################################################################## */
- #pragma warning (disable : 4786)
- // TpWrapper.cpp: implementation of the CTpWrapper class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "TpWrapper.hpp"
- #include <stdio.h>
- #include "workunit.hpp"
- #include "exception_util.hpp"
- #include "portlist.h"
- #include "daqueue.hpp"
- #include "dautils.hpp"
- #include "dameta.hpp"
- #ifdef _CONTAINERIZED
- #error "Should not be compiled in the container build"
- #endif
- const char* MSG_FAILED_GET_ENVIRONMENT_INFO = "Failed to get environment information.";
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- IPropertyTree* CTpWrapper::getEnvironment(const char* xpath)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- if (!xpath || !*xpath)
- return LINK(root);
- IPropertyTree* pSubTree = root->queryPropTree( xpath );
- if (pSubTree)
- return LINK(pSubTree);
- return NULL;
- }
- void CTpWrapper::getClusterMachineList(double clientVersion,
- const char* ClusterType,
- const char* ClusterPath,
- const char* ClusterDirectory,
- IArrayOf<IEspTpMachine> &MachineList,
- bool& hasThorSpareProcess,
- const char* ClusterName)
- {
- try
- {
- StringBuffer returnStr,path;
- getAttPath(ClusterPath,path);
- set<string> machineNames; //used for checking duplicates
- if (strcmp(eqTHORMACHINES,ClusterType) == 0)
- {
- bool multiSlaves = false;
- getMachineList(clientVersion, eqThorMasterProcess, path.str(), "", ClusterDirectory, MachineList);
- getThorSlaveMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
- unsigned count = MachineList.length();
- getThorSpareMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
- //The checkMultiSlavesFlag is for legacy multiSlaves environment, not for new environments.
- //count < MachineList.length(): There is some node for eqThorSpareProcess being added to the MachineList.
- if (!checkMultiSlavesFlag(ClusterName) &&(count < MachineList.length()))
- hasThorSpareProcess = true;
- }
- else if (strcmp(eqHOLEMACHINES,ClusterType) == 0)
- {
- getMachineList(clientVersion, eqHoleSocketProcess, path.str(), "", ClusterDirectory, MachineList);
- getMachineList(clientVersion, eqHoleProcessorProcess, path.str(), "", ClusterDirectory, MachineList);
- getMachineList(clientVersion, eqHoleControlProcess, path.str(), "", ClusterDirectory, MachineList);
- getMachineList(clientVersion, eqHoleCollatorProcess, path.str(), "", ClusterDirectory, MachineList);
- getMachineList(clientVersion, eqHoleStandbyProcess, path.str(), "", ClusterDirectory, MachineList);
- }
- else if (strcmp(eqROXIEMACHINES,ClusterType) == 0)
- {
- getMachineList(clientVersion, "RoxieServerProcess", path.str(), "", ClusterDirectory, MachineList, &machineNames);
- }
- else if (strcmp(eqMACHINES,ClusterType) == 0)
- {
- //load a list of available machines.......
- getMachineList(clientVersion, "Computer", "/Environment/Hardware", "", ClusterDirectory, MachineList);
- }
- else if (strcmp("AVAILABLEMACHINES",ClusterType) == 0)
- {
- getMachineList(clientVersion, "Computer", "/Environment/Hardware", eqMachineAvailablability, ClusterDirectory, MachineList);
- }
- else if (strcmp("DROPZONE",ClusterType) == 0)
- {
- getDropZoneMachineList(clientVersion, false, MachineList);
- }
- else if (strcmp("STANDBYNNODE",ClusterType) == 0)
- {
- getThorSpareMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
- getMachineList(clientVersion, eqHoleStandbyProcess, path.str(), "", ClusterDirectory, MachineList);
- }
- else if (strcmp("THORSPARENODES",ClusterType) == 0)
- {
- getThorSpareMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
- }
- else if (strcmp("HOLESTANDBYNODES",ClusterType) == 0)
- {
- getMachineList(clientVersion, eqHoleStandbyProcess, path.str(), "", ClusterDirectory, MachineList);
- }
- }
- catch(IException* e){
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...){
- IWARNLOG("Unknown Exception caught within CTpWrapper::getClusterMachineList");
- }
- }
- void CTpWrapper::fetchInstances(const char* ServiceType, IPropertyTree& service,
- IArrayOf<IEspTpMachine>& tpMachines)
- {
- Owned<IPropertyTreeIterator> instances = service.getElements("Instance");
- if (instances->first()) {
- do {
- IPropertyTree& instanceNode = instances->query();
- IEspTpMachine* machine = createTpMachine("", "");
- getMachineInfo(*machine, instanceNode, "/Environment/Software", ServiceType, "@computer");
- machine->setPort( instanceNode.getPropInt("@port") );
- const char* directory = instanceNode.queryProp("@directory");
- if (directory && *directory)
- machine->setDirectory( directory );
- tpMachines.append(*machine);
- } while (instances->next());
- }
- }
- void CTpWrapper::getTpDaliServers(double clientVersion, IArrayOf<IConstTpDali>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqDali);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpDali> pService = createTpDali("","");
- const char* name = serviceTree.queryProp("@name");
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBackupComputer(serviceTree.queryProp("@backupCoputer"));
- pService->setBackupDirectory(serviceTree.queryProp("@backupDirectory"));
- pService->setBuild(serviceTree.queryProp("@build"));
- pService->setType(eqDali);
- StringBuffer tmpDir, tmpAuditDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "dali", name, tmpDir))
- {
- const char* pStr = tmpDir.str();
- if (pStr)
- {
- if (strchr(pStr, '/'))
- tmpDir.append("/");
- else
- tmpDir.append("\\");
- tmpAuditDir.set(tmpDir.str());
- tmpDir.append("server");
- pService->setLogDirectory(tmpDir.str());
- if (clientVersion >= 1.27)
- {
- tmpAuditDir.append("audit");
- pService->setAuditLogDirectory(tmpAuditDir.str());
- }
- }
- }
- else
- {
- pService->setLogDirectory(serviceTree.queryProp("@LogDir")); // backward compatible
- }
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqDali, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpEclServers(IArrayOf<IConstTpEclServer>& list, const char* serverName)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqEclServer);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpEclServer> pService = createTpEclServer("","");
- const char* name = serviceTree.queryProp("@name");
- if (serverName && stricmp(name, serverName))
- continue;
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclserver", name, tmpDir))
- {
- pService->setLogDirectory( tmpDir.str() );
- }
- else
- {
- pService->setLogDirectory(serviceTree.queryProp("@eclLogDir"));
- }
- pService->setType(eqEclServer);
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqEclServer, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpEclCCServers(IArrayOf<IConstTpEclServer>& list, const char* serverName)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- getTpEclCCServers(root, list, serverName);
- return;
- }
- void CTpWrapper::getTpEclCCServers(IPropertyTree* environmentSoftware, IArrayOf<IConstTpEclServer>& list, const char* serverName)
- {
- if (!environmentSoftware)
- return;
- Owned<IPropertyTreeIterator> services= environmentSoftware->getElements(eqEclCCServer);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- const char* name = serviceTree.queryProp("@name");
- const char* logDir = serviceTree.queryProp("@logDir");
- if (serverName && stricmp(name, serverName))
- continue;
- Owned<IEspTpEclServer> pService = createTpEclServer("","");
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- StringBuffer tmpDir;
- if (getConfigurationDirectory(environmentSoftware->queryPropTree("Directories"), "log", "eclccserver", name, tmpDir))
- {
- pService->setLogDirectory( tmpDir.str() );
- }
- else
- {
- pService->setLogDirectory(logDir);
- }
- pService->setType(eqEclCCServer);
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqEclCCServer, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpEclAgents(IArrayOf<IConstTpEclAgent>& list, const char* agentName)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqEclAgent);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- const char* name = serviceTree.queryProp("@name");
- if (agentName && stricmp(name, agentName))
- continue;
- const char* daliServers = serviceTree.queryProp("@daliServers");
- const char* logDir = serviceTree.queryProp("@logDir");
- Owned<IEspTpEclAgent> pService = createTpEclAgent("","");
- pService->setDaliServer(daliServers);
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclagent", name, tmpDir))
- {
- pService->setLogDir( tmpDir.str() );
- }
- else
- {
- pService->setLogDir(logDir);
- }
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- pService->setType(eqEclAgent);
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqEclAgent, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpEclSchedulers(IArrayOf<IConstTpEclScheduler>& list, const char* serverName)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqEclScheduler);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- const char* name = serviceTree.queryProp("@name");
- const char* logDir = serviceTree.queryProp("@logDir");
- if (serverName && stricmp(name, serverName))
- continue;
- Owned<IEspTpEclScheduler> pService = createTpEclScheduler("","");
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclscheduler", name, tmpDir))
- {
- pService->setLogDirectory( tmpDir.str() );
- }
- else
- {
- pService->setLogDirectory(logDir);
- }
- pService->setType(eqEclScheduler);
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqEclScheduler, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpEspServers(IArrayOf<IConstTpEspServer>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqEsp);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpEspServer> pService = createTpEspServer("","");
- const char* name = serviceTree.queryProp("@name");
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- pService->setType(eqEsp);
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "esp", name, tmpDir))
- {
- pService->setLogDirectory( tmpDir.str() );
- }
- else
- {
- const char* logDir = serviceTree.queryProp("@logDir");
- if (logDir && *logDir)
- pService->setLogDirectory(logDir);
- }
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqEsp, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- Owned<IPropertyTreeIterator> iBinding = serviceTree.getElements("EspBinding");
- IArrayOf<IEspTpBinding> tpBindings;
- ForEach(*iBinding)
- {
- IPropertyTree& binding = iBinding->query();
- const char* service = binding.queryProp("@service");
- if (service && *service)
- {
- Owned<IEspTpBinding> pTpBinding = createTpBinding("", "");
- pTpBinding->setName (binding.queryProp("@name"));
- pTpBinding->setService(service);
- pTpBinding->setProtocol (binding.queryProp("@protocol"));
- pTpBinding->setPort (binding.queryProp("@port"));
- StringBuffer xpath;
- xpath.appendf("EspService[@name='%s']", service);
- IPropertyTree* pServiceNode = root->queryPropTree(xpath.str());
- if (pServiceNode)
- {
- const char* serviceType = pServiceNode->queryProp("Properties/@type");
- if (serviceType && *serviceType)
- pTpBinding->setServiceType(serviceType);
- const char* bindingType = pServiceNode->queryProp("Properties/@bindingType");
- if (bindingType && *bindingType)
- pTpBinding->setBindingType(bindingType);
- const char* buildSet = pServiceNode->queryProp("@buildSet");
- if (buildSet && *buildSet)
- pTpBinding->setServiceBuildSet(buildSet);
- }
- tpBindings.append(*pTpBinding.getLink());
- }
- }
- pService->setTpBindings( tpBindings);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpDfuServers(IArrayOf<IConstTpDfuServer>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqDfu);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpDfuServer> pService = createTpDfuServer("","");
- const char* name = serviceTree.queryProp("@name");
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- pService->setQueue(serviceTree.queryProp("@queue"));
- pService->setType(eqDfu);
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "dfuserver", name, tmpDir))
- {
- pService->setLogDirectory( tmpDir.str() );
- }
- else
- {
- pService->setLogDirectory(serviceTree.queryProp("@dfuLogDir"));
- }
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqDfu, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getClear());
- }
- }
- void CTpWrapper::getTpSashaServers(IArrayOf<IConstTpSashaServer>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqSashaServer);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpSashaServer> pService = createTpSashaServer("","");
- const char* name = serviceTree.queryProp("@name");
- pService->setName(name);
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "sasha", name, tmpDir))
- {
- pService->setLogDirectory( tmpDir.str() );
- }
- else
- {
- pService->setLogDirectory(serviceTree.queryProp("@logDir"));
- }
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqSashaServer, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpLdapServers(IArrayOf<IConstTpLdapServer>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqLdapServer);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpLdapServer> pService = createTpLdapServer("","");
- pService->setName(serviceTree.queryProp("@name"));
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqLdapServer, serviceTree, tpMachines);
- int port = serviceTree.getPropInt("@ldapPort", 0);
- if (tpMachines.length() == 0)
- {
- const char* computer = serviceTree.queryProp("@computer");
- if (computer && *computer)
- {
- Owned<IEspTpMachine> machine = createTpMachine("", "");
- setMachineInfo(computer, "LDAPServerProcess", *machine);
- StringBuffer tmpPath;
- StringBuffer ppath("/Environment/Software");
- setAttPath(ppath, "Instance", "name", computer, tmpPath);
- machine->setPath(tmpPath.str());
- if (port)
- machine->setPort( port );
- tpMachines.append(*machine.getLink());
- }
- }
- else
- {
- const int nMachines = tpMachines.length();
- for (int i=0; i<nMachines; i++)
- tpMachines.item(i).setPort(port);
- }
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpFTSlaves(IArrayOf<IConstTpFTSlave>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqFTSlave);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpFTSlave> pService = createTpFTSlave("","");
- pService->setName(serviceTree.queryProp("@name"));
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqFTSlave, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpDkcSlaves(IArrayOf<IConstTpDkcSlave>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqDkcSlave);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpDkcSlave> pService =createTpDkcSlave("","");
- pService->setName(serviceTree.queryProp("@name"));
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqDkcSlave, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTpGenesisServers(IArrayOf<IConstTpGenesisServer>& list)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> services= root->getElements(eqGenesisServer);
- ForEach(*services)
- {
- IPropertyTree& serviceTree = services->query();
- Owned<IEspTpGenesisServer> pService = createTpGenesisServer("","");
- pService->setName(serviceTree.queryProp("@name"));
- pService->setDescription(serviceTree.queryProp("@description"));
- pService->setBuild(serviceTree.queryProp("@build"));
- IArrayOf<IEspTpMachine> tpMachines;
- fetchInstances(eqGenesisServer, serviceTree, tpMachines);
- pService->setTpMachines(tpMachines);
- list.append(*pService.getLink());
- }
- }
- void CTpWrapper::getTargetClusterList(IArrayOf<IEspTpLogicalCluster>& clusters, const char* clusterType, const char* clusterName)
- {
- Owned<IPropertyTree> root = getEnvironment("Software");
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IPropertyTreeIterator> clusterIterator = root->getElements("Topology/Cluster");
- if (clusterIterator->first())
- {
- do {
- IPropertyTree &cluster0 = clusterIterator->query();
- StringBuffer processName;
- const char* clusterName0 = cluster0.queryProp("@name");
- if (!clusterName0 || !*clusterName0)
- continue;
- bool bAdd = false;
- if (!clusterType || !*clusterType)
- {
- bAdd = true;
- }
- else
- {
- Owned<IPropertyTreeIterator> clusters0= cluster0.getElements(clusterType);
- if (clusters0->first())
- {
- if (!clusterName || !*clusterName)
- {
- IPropertyTree &cluster = clusters0->query();
- const char* name = cluster.queryProp("@process");
- if (name && *name)
- processName.append(name);
- bAdd = true;
- }
- else
- {
- do {
- IPropertyTree &cluster = clusters0->query();
- const char* name = cluster.queryProp("@process");
- if (!name||!*name)
- continue;
- if (!stricmp(name, clusterName))
- {
- bAdd = true;
- break;
- }
- } while (clusters0->next());
- }
- }
- }
- if (!bAdd)
- continue;
- IEspTpLogicalCluster* pService = createTpLogicalCluster("","");
- pService->setName(clusterName0);
- if (processName.length() > 0)
- pService->setProcess(processName);
- pService->setLanguageVersion("3.0.0");
- clusters.append(*pService);
- } while (clusterIterator->next());
- }
- }
- void CTpWrapper::queryTargetClusterProcess(double version, const char* processName, const char* clusterType, IArrayOf<IConstTpCluster>& clusterList)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- StringBuffer xpath;
- xpath.appendf("Software/%s[@name='%s']", clusterType, processName);
- IPropertyTree* pClusterTree = root->queryPropTree(xpath.str());
- if (!pClusterTree)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- const char* queueName = NULL;
- if (processName&&(stricmp(clusterType,eqThorCluster)==0))
- {
- // only for multi-thor
- // only list first thor cluster on queue
- queueName = pClusterTree->queryProp("@queueName");
- if (!queueName||!*queueName)
- queueName = processName;
- }
- IEspTpCluster* clusterInfo = createTpCluster("","");
- clusterInfo->setName(processName);
- if (queueName && *queueName)
- clusterInfo->setQueueName(queueName);
- else
- clusterInfo->setQueueName(processName);
- clusterInfo->setDesc(processName);
- clusterInfo->setBuild( pClusterTree->queryProp("@build") );
- clusterInfo->setType(clusterType);
- StringBuffer tmpPath;
- StringBuffer path("/Environment/Software");
- setAttPath(path, clusterType, "name", processName, tmpPath);
- clusterInfo->setPath(tmpPath.str());
- StringBuffer dirStr;
- if (!getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", clusterType, processName, dirStr))
- {
- dirStr.clear().append(pClusterTree->queryProp("@directory"));
- }
- clusterInfo->setDirectory(dirStr.str());
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "log", clusterType, processName, tmpDir))
- {
- clusterInfo->setLogDirectory( tmpDir.str() );
- }
- else
- {
- const char* logDir = pClusterTree->queryProp("@logDir");
- if (logDir)
- clusterInfo->setLogDirectory( logDir );
- }
- clusterInfo->setPrefix("");
- if(pClusterTree->hasProp("@dataBuild"))
- clusterInfo->setDataModel(pClusterTree->queryProp("@dataBuild"));
- clusterList.append(*clusterInfo);
- //find out OS
- OS_TYPE os = OS_WINDOWS;
- unsigned int clusterTypeLen = strlen(clusterType);
- const char* childType = NULL;
- const char* clusterType0 = NULL;
- if (clusterTypeLen > 4)
- {
- if (!strnicmp(clusterType, "roxie", 4))
- {
- childType = "RoxieServerProcess[1]";
- clusterType0 = eqROXIEMACHINES;
- }
- else if (!strnicmp(clusterType, "thor", 4))
- {
- childType = "ThorMasterProcess";
- clusterType0 = eqTHORMACHINES;
- }
- else
- {
- childType = "HoleControlProcess";
- clusterType0 = eqHOLEMACHINES;
- }
- }
- if (childType)
- {
- IPropertyTree* pChild = pClusterTree->queryPropTree(childType);
- if (pChild)
- {
- const char* computer = pChild->queryProp("@computer");
- IPropertyTree* pHardware = root->queryPropTree("Hardware");
- if (computer && *computer && pHardware)
- {
- StringBuffer xpath;
- xpath.appendf("Computer[@name='%s']/@computerType", computer);
- const char* computerType = pHardware->queryProp( xpath.str() );
- if (computerType && *computerType)
- {
- xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
- const char* opSys = pHardware->queryProp( xpath.str() );
- if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
- os = OS_LINUX;
- }
- }
- }
- }
- clusterInfo->setOS(os);
- if (clusterType0 && *clusterType0)
- {
- bool hasThorSpareProcess = false;
- IArrayOf<IEspTpMachine> machineList;
- getClusterMachineList(version, clusterType0, tmpPath.str(), dirStr.str(), machineList, hasThorSpareProcess, processName);
- if (machineList.length() > 0)
- clusterInfo->setTpMachines(machineList);
- if (version > 1.14)
- clusterInfo->setHasThorSpareProcess(hasThorSpareProcess);
- }
- return;
- }
- void CTpWrapper::queryTargetClusters(double version, const char* clusterType, const char* clusterName, IArrayOf<IEspTpTargetCluster>& targetClusterList)
- {
- try
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- Owned<IPropertyTreeIterator> clusters= root->getElements("Software/Topology/Cluster");
- if (!clusters->first())
- return;
- do {
- IPropertyTree &cluster = clusters->query();
- const char* name = cluster.queryProp("@name");
- if (!name||!*name)
- continue;
- if (clusterName && *clusterName && strcmp(clusterName, name))
- continue;
- const char* prefix = cluster.queryProp("@prefix");
- Owned<IPropertyTreeIterator> thorClusters= cluster.getElements(eqThorCluster);
- Owned<IPropertyTreeIterator> roxieClusters= cluster.getElements(eqRoxieCluster);
- Owned<IPropertyTreeIterator> eclCCServerProcesses= cluster.getElements(eqEclCCServer);
- Owned<IPropertyTreeIterator> eclServerProcesses= cluster.getElements(eqEclServer);
- Owned<IPropertyTreeIterator> eclSchedulerProcesses= cluster.getElements(eqEclScheduler);
- Owned<IPropertyTreeIterator> eclAgentProcesses= cluster.getElements(eqEclAgent);
- if (clusterType && !stricmp(clusterType, eqThorCluster) && !thorClusters->first())
- continue;
- if (clusterType && !stricmp(clusterType, eqRoxieCluster) && !roxieClusters->first())
- continue;
- if (clusterType && !stricmp(clusterType, eqHoleCluster) && (roxieClusters->first() || thorClusters->first()))
- continue;
- IEspTpTargetCluster* clusterInfo = createTpTargetCluster("","");
- clusterInfo->setName(name);
- if (prefix && *prefix)
- clusterInfo->setPrefix(prefix);
- //Read Cluster process
- clusterInfo->setType(eqHoleCluster);
- IArrayOf<IConstTpCluster>& clusterList = clusterInfo->getTpClusters();
- if (thorClusters->first())
- {
- clusterInfo->setType(eqThorCluster);
- do {
- IPropertyTree &thorCluster = thorClusters->query();
- const char* process = thorCluster.queryProp("@process");
- if (process && *process)
- {
- queryTargetClusterProcess(version, process, eqThorCluster, clusterList);
- }
- } while (thorClusters->next());
- }
- if (roxieClusters->first())
- {
- clusterInfo->setType(eqRoxieCluster);
- do {
- IPropertyTree &roxieCluster = roxieClusters->query();
- const char* process = roxieCluster.queryProp("@process");
- if (process && *process)
- {
- queryTargetClusterProcess(version, process, eqRoxieCluster, clusterList);
- }
- } while (roxieClusters->next());
- }
- //Read eclCCServer process
- IArrayOf<IConstTpEclServer>& eclCCServerList = clusterInfo->getTpEclCCServers();
- if (eclCCServerProcesses->first())
- {
- IPropertyTree &eclCCServerProcess = eclCCServerProcesses->query();
- const char* process = eclCCServerProcess.queryProp("@process");
- if (process && *process)
- {
- getTpEclCCServers(eclCCServerList, process);
- }
- }
- //Read eclServer process
- if ((version >= 1.19) && eclServerProcesses->first())
- {
- IArrayOf<IConstTpEclServer>& eclServerList = clusterInfo->getTpEclServers();
- IPropertyTree &eclServerProcess = eclServerProcesses->query();
- const char* process = eclServerProcess.queryProp("@process");
- if (process && *process)
- {
- getTpEclServers(eclServerList, process);
- }
- }
- //Read eclAgent process
- IArrayOf<IConstTpEclAgent>& eclAgentList = clusterInfo->getTpEclAgents();
- if (eclAgentProcesses->first())
- {
- IPropertyTree &eclAgentProcess = eclAgentProcesses->query();
- const char* process = eclAgentProcess.queryProp("@process");
- if (process && *process)
- {
- getTpEclAgents(eclAgentList, process);
- }
- }
- //Read eclScheduler process
- IArrayOf<IConstTpEclScheduler>& eclSchedulerList = clusterInfo->getTpEclSchedulers();
- if (eclSchedulerProcesses->first())
- {
- IPropertyTree &eclSchedulerProcess = eclSchedulerProcesses->query();
- const char* process = eclSchedulerProcess.queryProp("@process");
- if (process && *process)
- {
- getTpEclSchedulers(eclSchedulerList, process);
- }
- }
- targetClusterList.append(*clusterInfo);
- } while (clusters->next());
- }
- catch(IException* e){
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...){
- IWARNLOG("Unknown Exception caught within CTpWrapper::getClusterList");
- }
- }
- void CTpWrapper::getClusterProcessList(const char* ClusterType, IArrayOf<IEspTpCluster>& clusterList, bool ignoreduplicatqueues, bool ignoreduplicategroups)
- {
- try
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- IPropertyTree* pSoftware = root->queryPropTree("Software");
- if (!pSoftware)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- StringArray queuesdone;
- StringArray groupsdone;
- Owned<IPropertyTreeIterator> clusters= pSoftware->getElements(ClusterType);
- if (clusters->first()) {
- do {
- IPropertyTree &cluster = clusters->query();
- const char* name = cluster.queryProp("@name");
- if (!name||!*name)
- continue;
- const char* queueName = NULL;
- const char* groupName = NULL;
- if (name&&(stricmp(ClusterType,eqThorCluster)==0))
- {
- // only for multi-thor
- // only list first thor cluster on queue
- queueName = cluster.queryProp("@queueName");
- if (!queueName||!*queueName)
- queueName = name;
- if (ignoreduplicatqueues)
- {
- bool done=false;
- ForEachItemIn(i,queuesdone)
- {
- if (strcmp(queuesdone.item(i),queueName)==0)
- {
- done = true;
- break;
- }
- }
- if (done)
- continue;
- queuesdone.append(queueName);
- }
- groupName = cluster.queryProp("@nodeGroup");
- if (!groupName||!*groupName)
- groupName = name;
- if (ignoreduplicategroups)
- {
- bool done=false;
- ForEachItemIn(i,groupsdone)
- {
- if (strcmp(groupsdone.item(i),groupName)==0)
- {
- done = true;
- break;
- }
- }
- if (done)
- continue;
- groupsdone.append(groupName);
- }
- }
- IEspTpCluster* clusterInfo = createTpCluster("","");
- clusterInfo->setName(name);
- if (queueName && *queueName)
- clusterInfo->setQueueName(queueName);
- else
- clusterInfo->setQueueName(name);
- clusterInfo->setDesc(name);
- clusterInfo->setBuild( cluster.queryProp("@build") );
- StringBuffer path("/Environment/Software");
- StringBuffer tmpPath;
- setAttPath(path, ClusterType, "name", name, tmpPath);
- clusterInfo->setType(ClusterType);
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", ClusterType, name, tmpDir))
- {
- clusterInfo->setDirectory(tmpDir.str());
- }
- else
- {
- clusterInfo->setDirectory(cluster.queryProp("@directory"));
- }
- tmpDir.clear();
- if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "log", ClusterType, name, tmpDir))
- {
- clusterInfo->setLogDirectory( tmpDir.str() );
- }
- else
- {
- const char* logDir = cluster.queryProp("@logDir");
- if (logDir)
- clusterInfo->setLogDirectory( logDir );
- }
- clusterInfo->setPath(tmpPath.str());
- clusterInfo->setPrefix("");
- if(cluster.hasProp("@dataBuild"))
- clusterInfo->setDataModel(cluster.queryProp("@dataBuild"));
- clusterList.append(*clusterInfo);
- //find out OS
- OS_TYPE os = OS_WINDOWS;
- unsigned int clusterTypeLen = strlen(ClusterType);
- const char* childType = NULL;
- if (clusterTypeLen > 4)
- {
- if (!strnicmp(ClusterType, "roxie", 4))
- childType = "RoxieServerProcess[1]";
- else if (!strnicmp(ClusterType, "thor", 4))
- childType = "ThorMasterProcess";
- else
- childType = "HoleControlProcess";
- }
- if (childType)
- {
- IPropertyTree* pChild = cluster.queryPropTree(childType);
- if (pChild)
- {
- const char* computer = pChild->queryProp("@computer");
- IPropertyTree* pHardware = root->queryPropTree("Hardware");
- if (computer && *computer && pHardware)
- {
- StringBuffer xpath;
- xpath.appendf("Computer[@name='%s']/@computerType", computer);
- const char* computerType = pHardware->queryProp( xpath.str() );
- if (computerType && *computerType)
- {
- xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
- const char* opSys = pHardware->queryProp( xpath.str() );
- if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
- os = OS_LINUX;
- }
- }
- }
- }
- clusterInfo->setOS(os);
- } while (clusters->next());
- }
- }
- catch(IException* e){
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...){
- IWARNLOG("Unknown Exception caught within CTpWrapper::getClusterList");
- }
- }
- void CTpWrapper::getHthorClusterList(IArrayOf<IEspTpCluster>& clusterList)
- {
- try
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- IPropertyTree* pSoftware = root->queryPropTree("Software");
- const char * ClusterType = "EclAgentProcess";
- Owned<IPropertyTreeIterator> clusters(pSoftware->getElements(ClusterType));
- ForEach(*clusters)
- {
- IPropertyTree &cluster = clusters->query();
- const char* name = cluster.queryProp("@name");
- if (!name||!*name)
- continue;
- unsigned ins = 0;
- Owned<IPropertyTreeIterator> insts = clusters->query().getElements("Instance");
- ForEach(*insts)
- {
- const char *na = insts->query().queryProp("@netAddress");
- if (na&&*na)
- {
- SocketEndpoint ep(na);
- if (!ep.isNull())
- {
- ins++;
- StringBuffer gname("hthor__");
- gname.append(name);
- if (ins>1)
- gname.append('_').append(ins);
- IEspTpCluster* clusterInfo = createTpCluster("","");
- clusterInfo->setName(gname.str());
- clusterInfo->setQueueName(name);
- clusterInfo->setDesc(cluster.queryProp("@build"));
- clusterInfo->setBuild( cluster.queryProp("@description") );
- StringBuffer path("/Environment/Software");
- StringBuffer tmpPath;
- setAttPath(path, ClusterType, "name", name, tmpPath);
- clusterInfo->setType(ClusterType);
- clusterInfo->setDirectory(insts->query().queryProp("@directory"));
- StringBuffer tmpDir;
- if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", ClusterType, name, tmpDir))
- {
- clusterInfo->setDirectory(tmpDir.str());
- }
- else
- {
- clusterInfo->setDirectory(insts->query().queryProp("@directory"));
- }
- clusterInfo->setPath(tmpPath.str());
- clusterList.append(*clusterInfo);
- //find out OS
- OS_TYPE os = OS_WINDOWS;
- const char* computer = insts->query().queryProp("@computer");
- IPropertyTree* pHardware = root->queryPropTree("Hardware");
- if (computer && *computer && pHardware)
- {
- StringBuffer xpath;
- xpath.appendf("Computer[@name='%s']/@computerType", computer);
- const char* computerType = pHardware->queryProp( xpath.str() );
- if (computerType && *computerType)
- {
- xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
- const char* opSys = pHardware->queryProp( xpath.str() );
- if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
- os = OS_LINUX;
- }
- }
- clusterInfo->setOS(os);
- }
- }
- }
- }
- }
- catch(IException* e){
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...){
- IWARNLOG("Unknown Exception caught within CTpWrapper::getHthorClusterList");
- }
- }
- void CTpWrapper::getGroupList(double espVersion, const char* kindReq, IArrayOf<IEspTpGroup> &GroupList)
- {
- try
- {
- Owned<IRemoteConnection> conn = querySDS().connect("/Groups", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
- Owned<IPropertyTreeIterator> groups= conn->queryRoot()->getElements("Group");
- if (groups->first())
- {
- do
- {
- IPropertyTree &group = groups->query();
- const char* kind = group.queryProp("@kind");
- if (kindReq && *kindReq && !strieq(kindReq, kind))
- continue;
- IEspTpGroup* pGroup = createTpGroup("","");
- const char* name = group.queryProp("@name");
- pGroup->setName(name);
- if (kind && *kind && (espVersion >= 1.21))
- {
- pGroup->setKind(kind);
- pGroup->setReplicateOutputs(checkGroupReplicateOutputs(name, kind));
- }
- GroupList.append(*pGroup);
- } while (groups->next());
- }
- }
- catch(IException* e)
- {
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...)
- {
- IWARNLOG("Unknown Exception caught within CTpWrapper::getGroupList");
- }
- }
- bool CTpWrapper::checkGroupReplicateOutputs(const char* groupName, const char* kind)
- {
- if (strieq(kind, "Roxie") || strieq(kind, "hthor"))
- return false;
- Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> environment = factory->openEnvironment();
- Owned<IPropertyTree> root = &environment->getPTree();
- Owned<IPropertyTreeIterator> it= root->getElements("Software/ThorCluster");
- ForEach(*it)
- {
- StringBuffer thorClusterGroupName;
- IPropertyTree& cluster = it->query();
- getClusterGroupName(cluster, thorClusterGroupName);
- if (thorClusterGroupName.length() && strieq(thorClusterGroupName.str(), groupName))
- return cluster.getPropBool("@replicateOutputs", false);
- }
- return false;
- }
- void CTpWrapper::getMachineInfo(double clientVersion, const char* name, const char* netAddress, IEspTpMachine& machineInfo)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IConstMachineInfo> pMachineInfo;
- if (name && *name)
- pMachineInfo.setown(constEnv->getMachine(name));
- else if (netAddress && *netAddress)
- pMachineInfo.setown(constEnv->getMachineByAddress(netAddress));
- else
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Machine not specified");
- if (!pMachineInfo)
- throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Machine Not Found for %s '%s'",
- (name && *name)? "Name" : "Net Address", (name && *name)? name : netAddress);
- setTpMachine(pMachineInfo, machineInfo);
- }
- void CTpWrapper::setTpMachine(IConstMachineInfo* machine, IEspTpMachine& tpMachine)
- {
- if (!machine)
- return;
- SCMStringBuffer machineName, netAddress;
- machine->getName(machineName);
- machine->getNetAddress(netAddress);
- tpMachine.setName(machineName.str());
- tpMachine.setNetaddress(netAddress.str());
- tpMachine.setOS(machine->getOS());
- switch(machine->getState())
- {
- case MachineStateAvailable:
- tpMachine.setAvailable("Available");
- break;
- case MachineStateUnavailable:
- tpMachine.setAvailable("Unavailable");
- break;
- case MachineStateUnknown:
- tpMachine.setAvailable("Unknown");
- break;
- }
- Owned<IConstDomainInfo> pDomain = machine->getDomain();
- if (pDomain != 0)
- {
- SCMStringBuffer sName;
- tpMachine.setDomain(pDomain->getName(sName).str());
- }
- }
- void CTpWrapper::getMachineInfo(IEspTpMachine& machineInfo,IPropertyTree& machine,const char* ParentPath,const char* MachineType,const char* nodenametag)
- {
- const char* name = machine.queryProp(nodenametag);
- setMachineInfo(name,MachineType,machineInfo);
- StringBuffer tmpPath;
- StringBuffer ppath(ParentPath);
- setAttPath(ppath,machine.queryName(),"name",name,tmpPath);
- machineInfo.setPath(tmpPath.str());
- }
- bool CTpWrapper::checkMultiSlavesFlag(const char* clusterName)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- VStringBuffer path("Software/ThorCluster[@name=\"%s\"]", clusterName);
- Owned<IPropertyTree> cluster= root->getPropTree(path.str());
- if (!cluster)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- //set this flag for legacy multi slave clusters because SwapNode made little sense in the old scheme
- //This is no longer an option in new environments, but is kept for backward compatibility with old
- //multi slave environments that used to list multiple slaves per node manually.
- return cluster->getPropBool("@multiSlaves");
- }
- void CTpWrapper::appendThorMachineList(double clientVersion, IConstEnvironment* constEnv, INode& node, const char* clusterName,
- const char* machineType, unsigned& processNumber, unsigned channels, const char* directory, IArrayOf<IEspTpMachine>& machineList)
- {
- StringBuffer netAddress;
- node.endpoint().getIpText(netAddress);
- if (netAddress.length() == 0)
- {
- OWARNLOG("Net address not found for a node of %s", clusterName);
- return;
- }
- processNumber++;
- Owned<IEspTpMachine> machineInfo = createTpMachine("","");
- machineInfo->setType(machineType);
- machineInfo->setNetaddress(netAddress.str());
- if (!isEmptyString(directory))
- machineInfo->setDirectory(directory);
- Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachineByAddress(netAddress.str());
- if (pMachineInfo.get())
- {
- setTpMachine(pMachineInfo, *machineInfo);
- if (clientVersion > 1.17)
- {
- machineInfo->setProcessNumber(processNumber);
- }
- }
- else
- {
- machineInfo->setName("external");
- machineInfo->setOS(MachineOsUnknown);
- }
- if (clientVersion >= 1.30)
- machineInfo->setChannels(channels);
- machineList.append(*machineInfo.getLink());
- }
- void CTpWrapper::getThorSlaveMachineList(double clientVersion, const char* clusterName, const char* directory, IArrayOf<IEspTpMachine>& machineList)
- {
- try
- {
- getThorMachineList(clientVersion, clusterName, directory, true, machineList);
- }
- catch(IException* e)
- {
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...)
- {
- IWARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
- }
- return;
- }
- void CTpWrapper::getThorSpareMachineList(double clientVersion, const char* clusterName, const char* directory, IArrayOf<IEspTpMachine>& machineList)
- {
- try
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- getThorMachineList(clientVersion, clusterName, directory, false, machineList);
- }
- catch(IException* e)
- {
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...)
- {
- IWARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
- }
- return;
- }
- void CTpWrapper::getThorMachineList(double clientVersion, const char* clusterName, const char* directory,
- bool slaveNode, IArrayOf<IEspTpMachine>& machineList)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root = &constEnv->getPTree();
- VStringBuffer path("Software/%s[@name=\"%s\"]", eqThorCluster, clusterName);
- Owned<IPropertyTree> cluster= root->getPropTree(path.str());
- if (!cluster)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- Owned<IGroup> nodeGroup;
- if (slaveNode)
- {
- nodeGroup.setown(getClusterProcessNodeGroup(clusterName, eqThorCluster));
- }
- else
- {
- StringBuffer groupName;
- getClusterSpareGroupName(*cluster, groupName);
- if (groupName.length() < 1)
- return;
- nodeGroup.setown(queryNamedGroupStore().lookup(groupName.str()));
- }
- if (!nodeGroup || (nodeGroup->ordinality() == 0))
- return;
- unsigned processNumber = 0;
- unsigned channels = cluster->getPropInt("@channelsPerSlave", 1);
- Owned<INodeIterator> gi = nodeGroup->getIterator();
- ForEach(*gi)
- appendThorMachineList(clientVersion, constEnv, gi->query(), clusterName,
- slaveNode? eqThorSlaveProcess : eqThorSpareProcess, processNumber, channels, directory, machineList);
- }
- void CTpWrapper::getMachineList(double clientVersion, const char* MachineType, const char* ParentPath,
- const char* Status, const char* Directory, IArrayOf<IEspTpMachine>& MachineList, set<string>* pMachineNames/*=NULL*/)
- {
- try
- {
- //ParentPath=Path to parent node... normally a cluster
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- Owned<IPropertyTree> root0 = &constEnv->getPTree();
-
- char* xpath = (char*)ParentPath;
- if (!strnicmp(xpath, "/Environment/", 13))
- xpath += 13;
- IPropertyTree* root = root0->queryPropTree( xpath );
- if (!root)
- throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
- bool hasPropChannelsPerNode = root->hasProp("@channelsPerNode");
- int channels = root->getPropInt("@channelsPerNode");
- Owned<IPropertyTreeIterator> machines= root->getElements(MachineType);
- const char* nodenametag = getNodeNameTag(MachineType);
- if (machines->first()) {
- do {
- IPropertyTree &machine = machines->query();
- if (pMachineNames)//caller wishes us to avoid inserting duplicate entries for machines
- {
- const char* machineName = machine.queryProp(nodenametag);
- if (pMachineNames->find(machineName) != pMachineNames->end())
- continue;
- pMachineNames->insert(machineName);
- }
- //load up the machines of which we do not care what status is set or we have a matching status
- const char* state = machine.queryProp("@state");
- if ((Status==NULL || *Status=='\0') ||
- (state && strcmp(Status, state)==0))
- {
- IEspTpMachine & machineInfo = *(createTpMachine("",""));
- getMachineInfo(machineInfo,machine,ParentPath,MachineType,nodenametag);
- if (Directory && *Directory)
- machineInfo.setDirectory(Directory);
- if (hasPropChannelsPerNode && (clientVersion >= 1.30))
- machineInfo.setChannels(channels);
- MachineList.append(machineInfo);
- }
- } while (machines->next());
- }
- }
- catch(IException* e){
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...){
- IWARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
- }
- }
- const char* CTpWrapper::getNodeNameTag(const char* MachineType)
- {
- if (strcmp(MachineType,"Computer")==0)
- return "@name";
- else
- return "@computer";
- }
- void CTpWrapper::getDropZoneMachineList(double clientVersion, bool ECLWatchVisibleOnly, IArrayOf<IEspTpMachine> &MachineList)
- {
- try
- {
- IArrayOf<IConstTpDropZone> list;
- getTpDropZones(clientVersion, nullptr, ECLWatchVisibleOnly, list);
- ForEachItemIn(i, list)
- {
- IConstTpDropZone& dropZone = list.item(i);
- IArrayOf<IConstTpMachine>& tpMachines = dropZone.getTpMachines();
- ForEachItemIn(ii, tpMachines)
- {
- IConstTpMachine& tpMachine = tpMachines.item(ii);
- Owned<IEspTpMachine> machine = createTpMachine();
- machine->copy(tpMachine);
- MachineList.append(*machine.getLink());
- }
- }
- }
- catch(IException* e)
- {
- EXCLOG(e);
- e->Release();
- }
- catch(...)
- {
- IWARNLOG("Unknown Exception caught within CTpWrapper::getDropZoneMachineList");
- }
- }
- //For a given dropzone or every dropzones (check ECLWatchVisible if needed), read: "@name",
- // "@description", "@build", "@directory", "@ECLWatchVisible" into an IEspTpDropZone object.
- //For each ServerList, read "@name" and "@server" (hostname or IP) into an IEspTpMachine object.
- //Add the IEspTpMachine object into the IEspTpDropZone.
- void CTpWrapper::getTpDropZones(double clientVersion, const char* name, bool ECLWatchVisibleOnly, IArrayOf<IConstTpDropZone>& list)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- if (!isEmptyString(name))
- {
- Owned<IConstDropZoneInfo> pDropZoneInfo = constEnv->getDropZone(name);
- if (pDropZoneInfo && (!ECLWatchVisibleOnly || pDropZoneInfo->isECLWatchVisible()))
- appendTpDropZone(clientVersion, constEnv, *pDropZoneInfo, list);
- }
- else
- {
- Owned<IConstDropZoneInfoIterator> it = constEnv->getDropZoneIterator();
- ForEach(*it)
- {
- IConstDropZoneInfo& dropZoneInfo = it->query();
- if (!ECLWatchVisibleOnly || dropZoneInfo.isECLWatchVisible())
- appendTpDropZone(clientVersion, constEnv, dropZoneInfo, list);
- }
- }
- }
- void CTpWrapper::appendTpDropZone(double clientVersion, IConstEnvironment* constEnv, IConstDropZoneInfo& dropZoneInfo, IArrayOf<IConstTpDropZone>& list)
- {
- SCMStringBuffer dropZoneName, description, directory, umask, build, computer;
- dropZoneInfo.getName(dropZoneName);
- dropZoneInfo.getDescription(description);
- dropZoneInfo.getDirectory(directory);
- dropZoneInfo.getUMask(umask);
- dropZoneInfo.getComputerName(computer);
- Owned<IEspTpDropZone> dropZone = createTpDropZone();
- if (dropZoneName.length() > 0)
- dropZone->setName(dropZoneName.str());
- if (description.length() > 0)
- dropZone->setDescription(description.str());
- if (directory.length() > 0)
- dropZone->setPath(directory.str());
- if (build.length() > 0)
- dropZone->setBuild(build.str());
- dropZone->setECLWatchVisible(dropZoneInfo.isECLWatchVisible());
- IArrayOf<IEspTpMachine> tpMachines;
- Owned<IConstDropZoneServerInfoIterator> itr = dropZoneInfo.getServers();
- ForEach(*itr)
- {
- IConstDropZoneServerInfo& dropZoneServer = itr->query();
- StringBuffer name, server, networkAddress;
- dropZoneServer.getName(name);
- dropZoneServer.getServer(server);
- if (name.isEmpty() && server.isEmpty())
- continue;
- Owned<IEspTpMachine> machine = createTpMachine();
- if (!name.isEmpty())
- machine->setName(name.str());
- if (!server.isEmpty())
- {
- IpAddress ipAddr;
- ipAddr.ipset(server.str());
- ipAddr.getIpText(networkAddress);
- machine->setNetaddress(networkAddress.str());
- machine->setConfigNetaddress(server.str());
- }
- if (directory.length() > 0)
- {
- machine->setDirectory(directory.str());
- machine->setOS(getPathSepChar(directory.str()) == '/' ? MachineOsLinux : MachineOsW2K);
- }
- tpMachines.append(*machine.getLink());
- }
- dropZone->setTpMachines(tpMachines);
- list.append(*dropZone.getLink());
- }
- void CTpWrapper::getTpSparkThors(double clientVersion, const char* name, IArrayOf<IConstTpSparkThor>& list)
- {
- Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
- if (!isEmptyString(name))
- {
- Owned<IConstSparkThorInfo> sparkThorInfo = constEnv->getSparkThor(name);
- if (sparkThorInfo)
- appendTpSparkThor(clientVersion, constEnv, *sparkThorInfo, list);
- }
- else
- {
- Owned<IConstSparkThorInfoIterator> it = constEnv->getSparkThorIterator();
- ForEach(*it)
- appendTpSparkThor(clientVersion, constEnv, it->query(), list);
- }
- }
- void CTpWrapper::appendTpSparkThor(double clientVersion, IConstEnvironment* constEnv, IConstSparkThorInfo& sparkThorInfo, IArrayOf<IConstTpSparkThor>& list)
- {
- SCMStringBuffer name, build, thorClusterName;
- sparkThorInfo.getName(name);
- sparkThorInfo.getBuild(build);
- sparkThorInfo.getThorClusterName(thorClusterName);
- Owned<IEspTpSparkThor> sparkThor = createTpSparkThor();
- if (name.length() > 0)
- sparkThor->setName(name.str());
- if (build.length() > 0)
- sparkThor->setBuild(build.str());
- if (thorClusterName.length() > 0)
- sparkThor->setThorClusterName(thorClusterName.str());
- sparkThor->setSparkExecutorCores(sparkThorInfo.getSparkExecutorCores());
- sparkThor->setSparkExecutorMemory(sparkThorInfo.getSparkExecutorMemory());
- sparkThor->setSparkMasterPort(sparkThorInfo.getSparkMasterPort());
- sparkThor->setSparkMasterWebUIPort(sparkThorInfo.getSparkMasterWebUIPort());
- sparkThor->setSparkWorkerCores(sparkThorInfo.getSparkWorkerCores());
- sparkThor->setSparkWorkerMemory(sparkThorInfo.getSparkWorkerMemory());
- sparkThor->setSparkWorkerPort(sparkThorInfo.getSparkWorkerPort());
- //Create the Path used by the thor cluster.
- StringBuffer tmpPath;
- StringBuffer path("/Environment/Software");
- setAttPath(path, eqThorCluster, "name", thorClusterName.str(), tmpPath);
- sparkThor->setThorPath(tmpPath.str());
- StringBuffer dirBuf;
- Owned<IPropertyTree> root = &constEnv->getPTree();
- if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "sparkthor", name.str(), dirBuf))
- sparkThor->setLogDirectory(dirBuf.str());
- IArrayOf<IConstTpMachine> machines;
- Owned<IConstInstanceInfoIterator> instanceInfoItr = sparkThorInfo.getInstanceIterator();
- ForEach(*instanceInfoItr)
- appendTpMachine(clientVersion, constEnv, instanceInfoItr->query(), machines);
- sparkThor->setTpMachines(machines);
- list.append(*sparkThor.getLink());
- }
- void CTpWrapper::appendTpMachine(double clientVersion, IConstEnvironment* constEnv, IConstInstanceInfo& instanceInfo, IArrayOf<IConstTpMachine>& machines)
- {
- SCMStringBuffer name, networkAddress, description, directory;
- Owned<IConstMachineInfo> machineInfo = instanceInfo.getMachine();
- machineInfo->getName(name);
- machineInfo->getNetAddress(networkAddress);
- instanceInfo.getDirectory(directory);
- Owned<IEspTpMachine> machine = createTpMachine();
- machine->setName(name.str());
- if (networkAddress.length() > 0)
- {
- IpAddress ipAddr;
- ipAddr.ipset(networkAddress.str());
- StringBuffer networkAddressStr;
- ipAddr.getIpText(networkAddressStr);
- machine->setNetaddress(networkAddressStr);
- }
- machine->setPort(instanceInfo.getPort());
- machine->setOS(machineInfo->getOS());
- machine->setDirectory(directory.str());
- machine->setType(eqSparkThorProcess);
- machines.append(*machine.getLink());
- }
- IEspTpMachine* CTpWrapper::createTpMachineEx(const char* name, const char* type, IConstMachineInfo* machineInfo)
- {
- if (!machineInfo)
- return nullptr;
- Owned<IEspTpMachine> machine = createTpMachine();
- machine->setName(name);
- machine->setType(type);
- machine->setOS(machineInfo->getOS());
- Owned<IConstDomainInfo> domain = machineInfo->getDomain();
- if (domain)
- {
- SCMStringBuffer sName;
- machine->setDomain(domain->getName(sName).str());
- }
- SCMStringBuffer netAddr;
- machineInfo->getNetAddress(netAddr);
- if (netAddr.length() > 0)
- {
- StringBuffer networkAddress;
- IpAddress ipAddr;
- ipAddr.ipset(netAddr.str());
- ipAddr.getIpText(networkAddress);
- machine->setNetaddress(networkAddress.str());
- }
- switch(machineInfo->getState())
- {
- case MachineStateAvailable:
- machine->setAvailable("Available");
- break;
- case MachineStateUnavailable:
- machine->setAvailable("Unavailable");
- break;
- default:
- machine->setAvailable("Unknown");
- break;
- }
- return machine.getClear();
- }
- void CTpWrapper::setMachineInfo(const char* name,const char* type,IEspTpMachine& machine)
- {
- try{
- Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
- Owned<IConstEnvironment> constEnv = factory->openEnvironment();
- Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachine(name);
- if (pMachineInfo.get())
- {
- SCMStringBuffer ep;
- pMachineInfo->getNetAddress(ep);
- const char* ip = ep.str();
- if (!ip || stricmp(ip, "."))
- {
- machine.setNetaddress(ep.str());
- machine.setConfigNetaddress(ep.str());
- }
- else
- {
- StringBuffer ipStr;
- IpAddress ipaddr = queryHostIP();
- ipaddr.getIpText(ipStr);
- if (ipStr.length() > 0)
- {
- #ifdef MACHINE_IP
- machine.setNetaddress(MACHINE_IP);
- #else
- machine.setNetaddress(ipStr.str());
- #endif
- machine.setConfigNetaddress(".");
- }
- }
- machine.setOS(pMachineInfo->getOS());
-
-
- switch(pMachineInfo->getState())
- {
- case MachineStateAvailable:
- machine.setAvailable("Available");
- break;
- case MachineStateUnavailable:
- machine.setAvailable("Unavailable");
- break;
- case MachineStateUnknown:
- machine.setAvailable("Unknown");
- break;
- }
- Owned<IConstDomainInfo> pDomain = pMachineInfo->getDomain();
- if (pDomain != 0)
- {
- SCMStringBuffer sName;
- machine.setDomain(pDomain->getName(sName).str());
- }
- }
- machine.setName(name);
- machine.setType(type);
- }
- catch(IException* e){
- StringBuffer msg;
- e->errorMessage(msg);
- IWARNLOG("%s", msg.str());
- e->Release();
- }
- catch(...){
- IWARNLOG("Unknown Exception caught within CTpWrapper::getDropZoneList");
- }
- }
- void CTpWrapper::setAttPath(StringBuffer& Path,const char* PathToAppend,const char* AttName,const char* AttValue,StringBuffer& returnStr)
- {
- Path.append("/");
- Path.append(PathToAppend);
- Path.append("[@");
- Path.append(AttName);
- Path.append("=\"");
- Path.append(AttValue);
- Path.append("\"]");
- StringBuffer rawPath;
- const void* buff = (void*)Path.str();
- JBASE64_Encode(buff,Path.length(),rawPath, false);
- returnStr.append(rawPath.str());
- }
- void CTpWrapper::getAttPath(const char* Path,StringBuffer& returnStr)
- {
- StringBuffer decodedStr;
- JBASE64_Decode(Path, returnStr);
- }
- void CTpWrapper::getServices(double version, const char* serviceType, const char* serviceName, IArrayOf<IConstHPCCService>& services)
- {
- Owned<IPropertyTreeIterator> itr = getComponentConfigSP()->getElements("services");
- ForEach(*itr)
- {
- IPropertyTree& service = itr->query();
- //Only show the public services for now
- if (!service.getPropBool("@public"))
- continue;
- const char* type = service.queryProp("@type");
- if (isEmptyString(type) || (!isEmptyString(serviceType) && !strieq(serviceType, type)))
- continue;
- const char* name = service.queryProp("@name");
- if (isEmptyString(name) || (!isEmptyString(serviceName) && !strieq(serviceName, name)))
- continue;
- Owned<IEspHPCCService> svc = createHPCCService();
- svc->setName(name);
- svc->setType(type);
- svc->setPort(service.getPropInt("@port"));
- if (service.getPropBool("@tls"))
- svc->setTLSSecure(true);
- services.append(*svc.getLink());
- if (!isEmptyString(serviceName))
- break;
- }
- }
- class CContainerWUClusterInfo : public CSimpleInterfaceOf<IConstWUClusterInfo>
- {
- StringAttr name;
- StringAttr serverQueue;
- StringAttr agentQueue;
- StringAttr thorQueue;
- ClusterType platform;
- unsigned clusterWidth;
- StringArray thorProcesses;
- public:
- CContainerWUClusterInfo(const char* _name, const char* type, unsigned _clusterWidth)
- : name(_name), clusterWidth(_clusterWidth)
- {
- StringBuffer queue;
- if (strieq(type, "thor"))
- {
- thorQueue.set(getClusterThorQueueName(queue.clear(), name));
- platform = ThorLCRCluster;
- thorProcesses.append(name);
- }
- else if (strieq(type, "roxie"))
- {
- agentQueue.set(getClusterEclAgentQueueName(queue.clear(), name));
- platform = RoxieCluster;
- }
- else
- {
- agentQueue.set(getClusterEclAgentQueueName(queue.clear(), name));
- platform = HThorCluster;
- }
- serverQueue.set(getClusterEclCCServerQueueName(queue.clear(), name));
- }
- virtual IStringVal& getName(IStringVal& str) const override
- {
- str.set(name.get());
- return str;
- }
- virtual IStringVal& getAgentQueue(IStringVal& str) const override
- {
- str.set(agentQueue);
- return str;
- }
- virtual IStringVal& getServerQueue(IStringVal& str) const override
- {
- str.set(serverQueue);
- return str;
- }
- virtual IStringVal& getThorQueue(IStringVal& str) const override
- {
- str.set(thorQueue);
- return str;
- }
- virtual ClusterType getPlatform() const override
- {
- return platform;
- }
- virtual unsigned getSize() const override
- {
- return clusterWidth;
- }
- virtual bool isLegacyEclServer() const override
- {
- return false;
- }
- virtual IStringVal& getScope(IStringVal& str) const override
- {
- UNIMPLEMENTED;
- }
- virtual unsigned getNumberOfSlaveLogs() const override
- {
- UNIMPLEMENTED;
- }
- virtual IStringVal & getAgentName(IStringVal & str) const override
- {
- UNIMPLEMENTED;
- }
- virtual IStringVal & getECLSchedulerName(IStringVal & str) const override
- {
- UNIMPLEMENTED;
- }
- virtual const StringArray & getECLServerNames() const override
- {
- UNIMPLEMENTED;
- }
- virtual IStringVal & getRoxieProcess(IStringVal & str) const override
- {
- str.set(name.get());
- return str;
- }
- virtual const StringArray & getThorProcesses() const override
- {
- return thorProcesses;
- }
- virtual const StringArray & getPrimaryThorProcesses() const override
- {
- UNIMPLEMENTED;
- }
- virtual const SocketEndpointArray & getRoxieServers() const override
- {
- UNIMPLEMENTED;
- }
- virtual const char *getLdapUser() const override
- {
- UNIMPLEMENTED;
- }
- virtual const char *getLdapPassword() const override
- {
- UNIMPLEMENTED;
- }
- virtual unsigned getRoxieRedundancy() const override
- {
- return 1;
- }
- virtual unsigned getChannelsPerNode() const override
- {
- return 1;
- }
- virtual int getRoxieReplicateOffset() const override
- {
- return 0;
- }
- virtual const char *getAlias() const override
- {
- UNIMPLEMENTED;
- }
- };
- extern TPWRAPPER_API unsigned getContainerWUClusterInfo(CConstWUClusterInfoArray& clusters)
- {
- Owned<IPropertyTreeIterator> queues = getComponentConfigSP()->getElements("queues");
- ForEach(*queues)
- {
- IPropertyTree& queue = queues->query();
- Owned<IConstWUClusterInfo> cluster = new CContainerWUClusterInfo(queue.queryProp("@name"),
- queue.queryProp("@type"), (unsigned) queue.getPropInt("@width", 1));
- clusters.append(*cluster.getClear());
- }
- return clusters.ordinality();
- }
- extern TPWRAPPER_API unsigned getWUClusterInfo(CConstWUClusterInfoArray& clusters)
- {
- return getEnvironmentClusterInfo(clusters);
- }
- static IPropertyTree * getContainerClusterConfig(const char * clusterName)
- {
- VStringBuffer xpath("queues[@name='%s']", clusterName);
- return getComponentConfigSP()->getPropTree(xpath);
- }
- extern TPWRAPPER_API IConstWUClusterInfo* getWUClusterInfoByName(const char* clusterName)
- {
- return getTargetClusterInfo(clusterName);
- }
- extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap)
- {
- Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
- ForEach(*services)
- {
- IPropertyTree& service = services->query();
- const char* name = service.queryProp("@name");
- const char* target = service.queryProp("@target");
- const char* port = service.queryProp("@port");
- if (isEmptyString(target) || isEmptyString(name)) //bad config?
- continue;
- StringBuffer s;
- s.append(name).append(':').append(port ? port : "9876");
- Owned<ISmartSocketFactory> sf = new CSmartSocketFactory(s.str(), false, 60, (unsigned) -1);
- connMap.setValue(target, sf.get());
- }
- }
- extern TPWRAPPER_API unsigned getThorClusterNames(StringArray& targetNames, StringArray& queueNames)
- {
- StringArray thorNames, groupNames;
- getEnvironmentThorClusterNames(thorNames, groupNames, targetNames, queueNames);
- return targetNames.ordinality();
- }
- static std::set<std::string> validTargets;
- static CriticalSection validTargetSect;
- // called within validTargetSect lock
- static void refreshValidTargets()
- {
- validTargets.clear();
- Owned<IStringIterator> it = getTargetClusters(nullptr, nullptr);
- ForEach(*it)
- {
- SCMStringBuffer s;
- IStringVal& val = it->str(s);
- if (validTargets.find(val.str()) == validTargets.end())
- {
- validTargets.insert(val.str());
- PROGLOG("adding valid target: %s", val.str());
- }
- }
- }
- extern TPWRAPPER_API void validateTargetName(const char* target)
- {
- if (isEmptyString(target))
- throw makeStringException(ECLWATCH_INVALID_CLUSTER_NAME, "Empty target name.");
- CriticalBlock block(validTargetSect);
- if (validTargets.find(target) == validTargets.end())
- {
- // bare metal rechecks in case env. changed since target list built
- if (!validateTargetClusterName(target))
- throw makeStringExceptionV(ECLWATCH_INVALID_CLUSTER_NAME, "Invalid target name: %s", target);
- refreshValidTargets();
- }
- }
- bool getSashaService(StringBuffer &serviceAddress, const char *serviceName, bool failIfNotFound)
- {
- if (!isEmptyString(serviceName))
- {
- // all services are on same sasha on bare-metal as far as esp services are concerned
- StringBuffer sashaAddress;
- IArrayOf<IConstTpSashaServer> sashaservers;
- CTpWrapper dummy;
- dummy.getTpSashaServers(sashaservers);
- if (0 != sashaservers.ordinality())
- {
- // NB: this code (in bare-matal) doesn't handle >1 Sasha.
- // Prior to this change, it would have failed to [try to] contact any Sasha.
- IConstTpSashaServer& sashaserver = sashaservers.item(0);
- IArrayOf<IConstTpMachine> &sashaservermachine = sashaserver.getTpMachines();
- sashaAddress.append(sashaservermachine.item(0).getNetaddress());
- if (!sashaAddress.isEmpty())
- {
- serviceAddress.append(sashaAddress).append(':').append(DEFAULT_SASHA_PORT);
- return true;
- }
- }
- }
- if (failIfNotFound)
- throw makeStringExceptionV(ECLWATCH_ARCHIVE_SERVER_NOT_FOUND, "Sasha '%s' server not found", serviceName);
- return false;
- }
- bool getSashaServiceEP(SocketEndpoint &serviceEndpoint, const char *service, bool failIfNotFound)
- {
- StringBuffer serviceAddress;
- if (!getSashaService(serviceAddress, service, failIfNotFound))
- return false;
- serviceEndpoint.set(serviceAddress);
- return true;
- }
- StringBuffer & getRoxieDefaultPlane(StringBuffer & plane, const char * roxieName)
- {
- Owned <IConstWUClusterInfo> clusterInfo(getTargetClusterInfo(roxieName));
- StringBufferAdaptor process(plane);
- if (clusterInfo && clusterInfo->getPlatform()==RoxieCluster)
- clusterInfo->getRoxieProcess(process);
- return plane;
- }
|