IConstDomainInfo * getDomainFromIp(const char * ip) { Owned<IEnvironmentFactory> ef = getEnvironmentFactory(true); Owned<IConstEnvironment> env = ef->openEnvironment(); Owned<IConstMachineInfo> curMachine = env->getMachineByAddress(ip); if (!curMachine) return NULL; return curMachine->getDomain(); }
int main(int argc, char** argv) { InitModuleObjects(); const char* out_envname = NULL; const char* in_ipfilename; StringBuffer ipAddrs; int roxieNodes=0, thorNodes=0, slavesPerNode=1; MapStringTo<StringBuffer> dirMap; int i = 1; bool writeToFiles = false; int port = 80; while(i<argc) { if(stricmp(argv[i], "-help") == 0 || stricmp(argv[i], "-?") == 0) { usage(); releaseAtoms(); return 0; } else if (stricmp(argv[i], "-env") == 0) { i++; out_envname = argv[i++]; } else if (stricmp(argv[i], "-roxienodes") == 0) { i++; roxieNodes = atoi(argv[i++]); } else if (stricmp(argv[i], "-thornodes") == 0) { i++; thorNodes = atoi(argv[i++]); } else if (stricmp(argv[i], "-slavespernode") == 0) { i++; slavesPerNode = atoi(argv[i++]); } else if (stricmp(argv[i], "-ip") == 0) { i++; ipAddrs.append(argv[i++]); } else if(stricmp(argv[i], "-ipfile") == 0) { i++; in_ipfilename = argv[i++]; ipAddrs.loadFile(in_ipfilename); } else if(stricmp(argv[i], "-o") == 0) { i++; StringArray sbarr; DelimToStringArray(argv[i++], sbarr, "="); if (sbarr.length() != 2) continue; if (strstr(sbarr.item(1), "[NAME]") && (strstr(sbarr.item(1), "[INST]") || strstr(sbarr.item(1), "[COMPONENT]"))) dirMap.setValue(sbarr.item(0), sbarr.item(1)); else { fprintf(stderr, "Error: Directory Override must contain [NAME] and either [INST] or [COMPONENT]\n"); releaseAtoms(); return 1; } } else { fprintf(stderr, "Error: unknown command line parameter: %s\n", argv[i]); usage(); releaseAtoms(); return 1; } } if (!out_envname) { fprintf(stderr, "Error: Output environment xml file is required. Please specify.\n"); usage(); releaseAtoms(); return 1; } if (ipAddrs.length() == 0) { fprintf(stderr, "Error: Ip addresses are required. Please specify.\n"); usage(); releaseAtoms(); return 1; } try { validateIPS(ipAddrs.str()); StringBuffer optionsXml, envXml; const char* pServiceName = "WsDeploy_wsdeploy_esp"; Owned<IPropertyTree> pCfg = createPTreeFromXMLFile(ENVGEN_PATH_TO_ESP_CONFIG); optionsXml.appendf("<XmlArgs roxieNodes=\"%d\" thorNodes=\"%d\" slavesPerNode=\"%d\" ipList=\"%s\"/>", roxieNodes, thorNodes, slavesPerNode, ipAddrs.str()); buildEnvFromWizard(optionsXml, pServiceName, pCfg, envXml, &dirMap); if(envXml.length()) { StringBuffer env; StringBuffer thisip; queryHostIP().getIpText(thisip); env.appendf("<"XML_HEADER">\n<!-- Generated with envgen on ip %s -->\n", thisip.str()); env.append(envXml); Owned<IEnvironmentFactory> factory = getEnvironmentFactory(); Owned<IConstEnvironment> constEnv = factory->loadLocalEnvironment(env); validateEnv(constEnv); Owned<IFile> pFile; pFile.setown(createIFile(out_envname)); Owned<IFileIO> pFileIO; pFileIO.setown(pFile->open(IFOcreaterw)); pFileIO->write(0, env.length(), env.str()); } } catch(IException *excpt) { StringBuffer errMsg; fprintf(stderr, "Exception: %d:\n%s\n", excpt->errorCode(), excpt->errorMessage(errMsg).str()); releaseAtoms(); excpt->Release(); return 1; } catch(...) { fprintf(stderr, "Unknown exception\n"); releaseAtoms(); return 1; } releaseAtoms(); return 0; }
IPropertyTree* CFileSpraySoapBindingEx::createPTreeForXslt(const char* method, const char* dfuwuid) { Owned<IEnvironmentFactory> factory = getEnvironmentFactory(); Owned<IConstEnvironment> m_constEnv = factory->openEnvironment(); Owned<IPropertyTree> pEnvRoot = &m_constEnv->getPTree(); IPropertyTree* pEnvSoftware = pEnvRoot->queryPropTree("Software"); Owned<IPropertyTree> pRoot = createPTreeFromXMLString("<Environment/>"); IPropertyTree* pSoftware = pRoot->addPropTree("Software", createPTree("Software")); if (pEnvSoftware) { StringBuffer dfuwuidSourcePartIP, wuxml; if(dfuwuid && *dfuwuid) { Owned<IDFUWorkUnitFactory> dfuwu_factory = getDFUWorkUnitFactory(); Owned<IConstDFUWorkUnit> dfuwu = dfuwu_factory->openWorkUnit(dfuwuid, false); if(dfuwu) { dfuwu->toXML(wuxml); Owned<IPropertyTree> wu = createPTreeFromXMLString(wuxml.str()); if (wu) { const char* ip = wu->queryProp("Source/Part/@node"); if (ip && *ip) dfuwuidSourcePartIP.append(ip); } } } Owned<IPropertyTreeIterator> it = pEnvSoftware->getElements("DropZone"); ForEach(*it) { IPropertyTree* pDropZone = pSoftware->addPropTree("DropZone", &it->get()); //get IP Address of the computer associated with this drop zone const char* pszComputer = it->query().queryProp("@computer"); if (!strcmp(pszComputer, ".")) pszComputer = "localhost"; StringBuffer xpath; xpath.appendf("Hardware/Computer[@name='%s']/@netAddress", pszComputer); StringBuffer sNetAddr; const char* pszNetAddr = pEnvRoot->queryProp(xpath.str()); if (strcmp(pszNetAddr, ".")) { sNetAddr.append(pszNetAddr); } else { StringBuffer ipStr; IpAddress ipaddr = queryHostIP(); ipaddr.getIpText(ipStr); if (ipStr.length() > 0) { #ifdef MACHINE_IP sNetAddr.append(MACHINE_IP); #else sNetAddr.append(ipStr.str()); #endif } } pDropZone->addProp("@netAddress", sNetAddr.str()); if ((dfuwuidSourcePartIP.length() > 0) && (sNetAddr.length() > 0)) { IpAddress ip1(dfuwuidSourcePartIP.str()), ip2(sNetAddr.str()); if (ip1.ipequals(ip2)) pDropZone->addProp("@sourceNode", "1"); } Owned<IConstMachineInfo> machine; if (strcmp(pszNetAddr, ".")) machine.setown(m_constEnv->getMachineByAddress(sNetAddr.str())); else { machine.setown(m_constEnv->getMachineByAddress(pszNetAddr)); if (!machine) machine.setown(m_constEnv->getMachineByAddress(sNetAddr.str())); } if (machine) { //int os = machine->getOS(); StringBuffer dir; pDropZone->getProp("@directory", dir); if (machine->getOS() == MachineOsLinux || machine->getOS() == MachineOsSolaris) { dir.replace('\\', '/');//replace all '\\' by '/' pDropZone->setProp("@linux", "true"); } else { dir.replace('/', '\\'); dir.replace('$', ':'); } pDropZone->setProp("@directory", dir); } } //For Spray files on Thor Cluster, fetch all the group names for all the thor instances (and dedup them) BoolHash uniqueThorClusterGroupNames; it.setown(pEnvSoftware->getElements("ThorCluster")); ForEach(*it) { StringBuffer thorClusterGroupName; IPropertyTree& cluster = it->query(); getClusterGroupName(cluster, thorClusterGroupName); if (!thorClusterGroupName.length()) continue; bool* found = uniqueThorClusterGroupNames.getValue(thorClusterGroupName.str()); if (found && *found) continue; uniqueThorClusterGroupNames.setValue(thorClusterGroupName.str(), true); IPropertyTree* newClusterTree = pSoftware->addPropTree("ThorCluster", &it->get()); newClusterTree->setProp("@name", thorClusterGroupName.str()); //set group name into @name for spray target } it.setown(pEnvSoftware->getElements("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) { const char *na = insts->query().queryProp("@netAddress"); if (!na || !*na) { insts->query().setProp("@gname", name); continue; } SocketEndpoint ep(na); if (ep.isNull()) continue; ins++; StringBuffer gname("hthor__"); //StringBuffer gname; gname.append(name); if (ins>1) gname.append('_').append(ins); insts->query().setProp("@gname", gname.str()); } pSoftware->addPropTree("EclAgentProcess", &it->get()); } if (stricmp(method, "CopyInput") == 0) //Limit for this method only { it.setown(pEnvSoftware->getElements("RoxieCluster")); ForEach(*it) pSoftware->addPropTree("RoxieCluster", &it->get()); } if (wuxml.length() > 0) pSoftware->addPropTree("DfuWorkunit", createPTreeFromXMLString(wuxml.str())); } return pRoot.getClear(); }
CEspConfig::CEspConfig(IProperties* inputs, IPropertyTree* envpt, IPropertyTree* procpt, bool isDali) { hsami_=0; serverstatus=NULL; useDali=false; if(inputs) m_inputs.setown(inputs); if(!envpt || !procpt) return; m_envpt.setown(envpt); m_cfg.setown(procpt); loadBuiltIns(); // load options const char* level = m_cfg->queryProp("@logLevel"); m_options.logLevel = level ? atoi(level) : LogMin; m_options.logReq = m_cfg->getPropBool("@logRequests", false); m_options.logResp = m_cfg->getPropBool("@logResponses", false); m_options.frameTitle.set(m_cfg->queryProp("@name")); m_options.slowProcessingTime = m_cfg->getPropInt("@slowProcessingTime", 30) * 1000; //in msec #ifdef USE_ENV_CONF_FILE // load environment parameters StringBuffer envConfFile, envXMLFile; const char* configFile = m_cfg->queryProp("EnvironmentConfFile"); if (configFile && *configFile) { envConfFile.append(configFile); } else { envConfFile.append("/etc/LexisNexis/environment.conf"); } const char* envFromDali = m_cfg->queryProp("@environmentNotFromDali"); if (envFromDali && !stricmp(envFromDali, "true")) { const char* envXML = m_cfg->queryProp("EnvironmentXMLFile"); if (envXML && *envXML) { envXMLFile.append(envXML); } else { envXMLFile.append("environment.xml"); } } Owned<IEnvironmentFactory> factory = getEnvironmentFactory(); factory->createEnvironmentByFile(envConfFile.str(), envXMLFile.str()); #endif if (!m_cfg->getProp("@name", m_process)) { ERRLOG("EspProcess name not found"); } else { DBGLOG("ESP process name [%s]", m_process.str()); IPropertyTreeIterator *pt_iter = NULL; StringBuffer daliservers; if (m_cfg->getProp("@daliServers", daliservers)) initDali(daliservers.str()); #ifndef _DEBUG startPerformanceMonitor(m_cfg->getPropInt("@perfReportDelay", 60)*1000); #endif //get the local computer name: m_cfg->getProp("@computer", m_computer); //get the local computer information: StringBuffer xpath; xpath.appendf("Hardware/Computer[@name=\"%s\"]", m_computer.str()); IPropertyTree *computer = m_envpt->queryPropTree(xpath.str()); if (computer) { StringBuffer address; computer->getProp("@netAddress", address); int port = m_cfg->getPropInt("@port", 1500); if(strcmp(address.str(), ".") == 0) { GetHostName(address.clear()); } m_address.set(address.str(), (unsigned short) port); } xpath.clear(); xpath.append("EspService"); pt_iter = m_cfg->getElements(xpath.str()); if (pt_iter!=NULL) { IPropertyTree *ptree = NULL; pt_iter->first(); while(pt_iter->isValid()) { ptree = &pt_iter->query(); if (ptree) { srv_cfg *svcfg = new srv_cfg; ptree->getProp("@name", svcfg->name); ptree->getProp("@type", svcfg->type); ptree->getProp("@plugin", svcfg->plugin); fixPlugin(svcfg->plugin); map<string, srv_cfg*>::value_type en(svcfg->name.str(), svcfg); m_services.insert(en); } pt_iter->next(); } pt_iter->Release(); pt_iter=NULL; } xpath.clear(); xpath.append("EspProtocol"); pt_iter = m_cfg->getElements(xpath.str()); if (pt_iter!=NULL) { IPropertyTree *ptree = NULL; pt_iter->first(); while(pt_iter->isValid()) { ptree = &pt_iter->query(); if (ptree) { protocol_cfg *pcfg = new protocol_cfg; ptree->getProp("@name", pcfg->name); ptree->getProp("@plugin", pcfg->plugin); fixPlugin(pcfg->plugin); ptree->getProp("@type", pcfg->type); map<string, protocol_cfg*>::value_type en(pcfg->name.str(), pcfg); m_protocols.insert(en); } pt_iter->next(); } pt_iter->Release(); pt_iter=NULL; } xpath.clear(); xpath.append("EspBinding"); pt_iter = m_cfg->getElements(xpath.str()); if (pt_iter!=NULL) { IPropertyTree *ptree = NULL; pt_iter->first(); while(pt_iter->isValid()) { ptree = &pt_iter->query(); if (ptree) { binding_cfg *bcfg = new binding_cfg; ptree->getProp("@name", bcfg->name); ptree->getProp("@type", bcfg->type); ptree->getProp("@plugin", bcfg->plugin); fixPlugin(bcfg->plugin); bcfg->isDefault = ptree->getPropBool("@defaultBinding", false); StringBuffer addr; ptree->getProp("@netAddress", addr); if(strcmp(addr.str(), ".") == 0) { bcfg->address.append("0.0.0.0"); } else { bcfg->address.append(addr.str()); } StringBuffer portstr; ptree->getProp("@port", portstr); bcfg->port = atoi(portstr.str()); ptree->getProp("@service", bcfg->service_name); ptree->getProp("@protocol", bcfg->protocol_name); m_bindings.push_back(bcfg); } pt_iter->next(); } pt_iter->Release(); pt_iter=NULL; } } }
IPropertyTree* CFileSpraySoapBindingEx::createPTreeForXslt(double clientVersion, const char* method, const char* dfuwuid) { Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true); Owned<IConstEnvironment> constEnv = factory->openEnvironment(); Owned<IPropertyTree> pEnvRoot = &constEnv->getPTree(); IPropertyTree* pEnvSoftware = pEnvRoot->queryPropTree("Software"); Owned<IPropertyTree> pRoot = createPTreeFromXMLString("<Environment/>"); IPropertyTree* pSoftware = pRoot->addPropTree("Software", createPTree("Software")); if (pEnvSoftware) { StringBuffer dfuwuidSourcePartIP, wuxml; if(dfuwuid && *dfuwuid) { Owned<IDFUWorkUnitFactory> dfuwu_factory = getDFUWorkUnitFactory(); Owned<IConstDFUWorkUnit> dfuwu = dfuwu_factory->openWorkUnit(dfuwuid, false); if(dfuwu) { dfuwu->toXML(wuxml); Owned<IPropertyTree> wu = createPTreeFromXMLString(wuxml.str()); if (wu) { const char* ip = wu->queryProp("Source/Part/@node"); if (ip && *ip) dfuwuidSourcePartIP.append(ip); } } } appendDropZones(clientVersion, constEnv, dfuwuidSourcePartIP.str(), pSoftware); //For Spray files on Thor Cluster, fetch all the group names for all the thor instances (and dedup them) BoolHash uniqueThorClusterGroupNames; Owned<IPropertyTreeIterator> it =pEnvSoftware->getElements("ThorCluster"); ForEach(*it) { StringBuffer thorClusterGroupName; IPropertyTree& cluster = it->query(); getClusterGroupName(cluster, thorClusterGroupName); if (!thorClusterGroupName.length()) continue; bool* found = uniqueThorClusterGroupNames.getValue(thorClusterGroupName.str()); if (found && *found) continue; uniqueThorClusterGroupNames.setValue(thorClusterGroupName.str(), true); IPropertyTree* newClusterTree = pSoftware->addPropTree("ThorCluster", &it->get()); newClusterTree->setProp("@name", thorClusterGroupName.str()); //set group name into @name for spray target } it.setown(pEnvSoftware->getElements("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) { const char *na = insts->query().queryProp("@netAddress"); if (!na || !*na) { insts->query().setProp("@gname", name); continue; } SocketEndpoint ep(na); if (ep.isNull()) continue; ins++; StringBuffer gname("hthor__"); //StringBuffer gname; gname.append(name); if (ins>1) gname.append('_').append(ins); insts->query().setProp("@gname", gname.str()); } pSoftware->addPropTree("EclAgentProcess", &it->get()); } if (stricmp(method, "CopyInput") == 0) //Limit for this method only { it.setown(pEnvSoftware->getElements("RoxieCluster")); ForEach(*it) pSoftware->addPropTree("RoxieCluster", &it->get()); } if (wuxml.length() > 0) pSoftware->addPropTree("DfuWorkunit", createPTreeFromXMLString(wuxml.str())); } return pRoot.getClear(); }