void CWizardInputs::setWizardRules() { const char* roxieRedTypes[] = {"Full", "Circular", "None", "Overloaded"}; m_roxieAgentRedType.clear().append("Circular"); m_roxieAgentRedChannels = 2; m_roxieAgentRedOffset = 1; m_genOptForAllComps = GENOPTIONAL_ALL; if(m_algProp) { Owned<IPropertyIterator> iter = m_algProp->getIterator(); StringBuffer prop; ForEach(*iter) { m_algProp->getProp(iter->getPropKey(), prop.clear()); if(prop.length() && prop.charAt(prop.length()-1) == ',') prop.setCharAt((prop.length()-1),' '); if(!strcmp(iter->getPropKey(), "max_comps_per_node")) { m_maxCompOnNode = atoi(prop.str()); } else if(!strcmp(iter->getPropKey(), "avoid_combo")) { StringArray pairValue; DelimToStringArray(prop.str(), pairValue, ","); if( pairValue.ordinality() > 0) { for( unsigned i = 0; i < pairValue.ordinality() ; i++) { StringArray eachpair; DelimToStringArray(pairValue.item(i), eachpair, "-"); if(eachpair.ordinality() == 2 ) { StringArray* serverCompArr = 0; ForEachItemIn(x, eachpair) { StringArrayPtr* pairServerArr = m_invalidServerCombo.getValue(eachpair.item(x)); if(pairServerArr) { serverCompArr = (*pairServerArr); serverCompArr->append(x == 0 ? eachpair.item(1): eachpair.item(0)); } else { serverCompArr = new StringArray(); serverCompArr->append(x == 0 ? eachpair.item(1): eachpair.item(0)); m_invalidServerCombo.setValue(eachpair.item(x),serverCompArr); } } } } } }
void CDfuPlusHelper::info(const char *fmt, ...) { va_list args; va_start(args, fmt); StringBuffer buf; buf.valist_appendf(fmt,args); va_end(args); if (msgintercept) { StringArray strs; DelimToStringArray(buf.str(), strs, "\n"); ForEachItemIn(i,strs) { const char *s = strs.item(i); if (*s) msgintercept->info(s); } } else
void Cws_machineEx::updatePathInAddress(const char* address, StringBuffer& addrStr) { addrStr.append(address); StringArray sArray; DelimToStringArray(address, sArray, ":"); const char* OS = sArray.item(3); const char* Dir = sArray.item(4); if (OS && *OS && Dir && *Dir) { char oldC1 = '/'; char oldC2 = '$'; char newC1 = '\\'; char newC2 = ':'; int os = atoi(OS); if (os == 2) //2: linux { oldC1 = '\\'; oldC2 = ':'; newC1 = '/'; newC2 = '$'; } StringBuffer dirStr(Dir); dirStr.replace(oldC1, newC1); dirStr.replace(oldC2, newC2); if ((os == 2) && (dirStr.charAt(0) != '/')) dirStr.insert(0, '/'); addrStr.clear(); for (unsigned i = 0; i < sArray.length(); i++) { const char* item = sArray.item(i); if (i == 4) addrStr.appendf(":%s", dirStr.str()); else if (item && *item) { if (i == 0) addrStr.append(item); else addrStr.appendf(":%s", item); } } } return; }
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; }
bool Cws_machineEx::doStartStop(IEspContext &context, StringArray& addresses, char* userName, char* password, bool bStop, IEspStartStopResponse &resp) { bool containCluster = false; double version = context.getClientVersion(); const int ordinality= addresses.ordinality(); UnsignedArray threadHandles; IArrayOf<IEspStartStopResult> resultsArray; for (int index=0; index<ordinality; index++) { const char* address0 = addresses.item(index); //address passed in is of the form "192.168.1.4:EspProcess:2:path1" StringArray sArray; DelimToStringArray(addresses.item(index), sArray, ":"); if (sArray.ordinality() < 4) throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Incomplete arguments"); Owned<IEspStartStopResult> pResult = static_cast<IEspStartStopResult*>(new CStartStopResult("")); const char* address = sArray.item(0); const char* compType= sArray.item(1); const char* OS = sArray.item(3);//index 2 is component name const char* path = sArray.item(4); if (!(address && *address && compType && *compType && OS && *OS && path && *path)) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Invalid input"); if (!stricmp(compType, "ThorCluster") || !stricmp(compType, "RoxieCluster")) containCluster = true; #ifndef OLD_START_STOP { char* configAddress = NULL; char* props1 = (char*) strchr(address, '|'); if (props1) { configAddress = props1+1; *props1 = '\0'; } else { configAddress = (char*) address; } StringBuffer newAddress; ConvertAddress(address0, newAddress); pResult->setAddressOrig ( newAddress.str() );//can be either IP or name of component pResult->setAddress ( address );//can be either IP or name of component pResult->setCompType( compType ); if (version > 1.04) { pResult->setName( path ); const char* pStr2 = strstr(path, "LexisNexis"); if (pStr2) { char name[256]; const char* pStr1 = strchr(pStr2, '|'); if (!pStr1) { strcpy(name, pStr2+11); } else { strncpy(name, pStr2+11, pStr1 - pStr2 -11); name[pStr1 - pStr2 -11] = 0; } pResult->setName( name ); } } pResult->setOS( atoi(OS) ); pResult->setPath( path ); resultsArray.append(*pResult.getLink()); CStartStopThreadParam* pThreadReq; pThreadReq = new CStartStopThreadParam(address, configAddress, bStop, m_useDefaultSSHUserID, m_useDefaultHPCCInit, this, context); pThreadReq->setResultObject( pResult ); if (userName && *userName) pThreadReq->setUserID( userName ); if (password && *password) pThreadReq->setPassword( password ); PooledThreadHandle handle = m_threadPool->start( pThreadReq ); threadHandles.append(handle); } #else { StringBuffer newAddress; ConvertAddress(address0, newAddress); char* pStr = (char*) strchr(address, '|');; if (pStr) pStr[0] = 0; pResult->setAddressOrig ( newAddress.str() );//can be either IP or name of component pResult->setAddress ( address );//can be either IP or name of component pResult->setCompType( compType ); pResult->setOS( atoi(OS) ); pResult->setPath( path ); resultsArray.append(*pResult.getLink()); CStartStopThreadParam* pThreadReq; pThreadReq = new CStartStopThreadParam(address, bStop, m_useDefaultSSHUserID, this, context); pThreadReq->setResultObject( pResult ); if (userName && *userName) pThreadReq->setUserID( userName ); if (password && *password) pThreadReq->setPassword( password ); PooledThreadHandle handle = m_threadPool->start( pThreadReq ); threadHandles.append(handle); } #endif } //block for worker theads to finish, if necessary, and then collect results // PooledThreadHandle* pThreadHandle = threadHandles.getArray(); unsigned i=threadHandles.ordinality(); while (i--) { m_threadPool->join(*pThreadHandle, 30000);//abort after 30 secs in remote possibility that the command blocks pThreadHandle++; } resp.setStartStopResults(resultsArray); resp.setStop(bStop); if (version > 1.08) { resp.setContainCluster(containCluster); } return true; }
void Cws_machineEx::ConvertAddress( const char* originalAddress, StringBuffer& newAddress) { if (!originalAddress || !*originalAddress) throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "No network address or computer name specified!"); StringArray sArray; DelimToStringArray(originalAddress, sArray, ":"); if (sArray.ordinality() < 4) throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Incomplete arguments"); const char* address = sArray.item(0); const char* compType= sArray.item(1); const char* compName= sArray.item(2); const char* OS = sArray.item(3); const char* path = sArray.item(4); StringBuffer process; if (sArray.ordinality() > 5) { const char* ClusterType = sArray.item(5); if (ClusterType && *ClusterType) { if (strcmp("THORMACHINES",ClusterType) == 0) { process.append("ThorMasterProcess"); } else if (strcmp("ROXIEMACHINES",ClusterType) == 0) { process.append("RoxieServerProcess"); } } } if (strchr(address, '.')) //have an IP address { newAddress.clear().append(originalAddress); return; } StringBuffer xpath; if (!strcmp(compType, "RoxieCluster")) { xpath.append("RoxieServer"); } else if (!strcmp(compType, "ThorCluster")) { xpath.append("ThorMaster"); } else if (!strcmp(compType, "HoleCluster")) { xpath.append("HoleControl"); } else throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "Failed to resolve address for component type '%s'", compType); Owned<IPropertyTree> pComponent = getComponent(compType, address); xpath.append("Process[1]/@computer"); const char* computer = pComponent->queryProp(xpath.str()); if (!computer || !*computer) throw MakeStringException(ECLWATCH_INVALID_COMPONENT_INFO, "Failed to resolve computer for %s '%s'!", compType, address); Owned<IConstEnvironment> pConstEnv = getConstEnvironment(); Owned<IConstMachineInfo> pConstMc = pConstEnv->getMachine(computer); SCMStringBuffer sAddress; pConstMc->getNetAddress(sAddress); #ifndef OLD_START_STOP { StringBuffer sConfigAddress; sConfigAddress.append(sAddress.str()); if (!strcmp(sAddress.str(), ".")) { StringBuffer ipStr; IpAddress ipaddr = queryHostIP(); ipaddr.getIpText(ipStr); if (ipStr.length() > 0) { #ifdef MACHINE_IP sAddress.set(MACHINE_IP); #else sAddress.set(ipStr.str()); #endif } } if (process.length() > 0) newAddress.clear().appendf("%s|%s:%s:%s:%s:%s", sAddress.str(), sConfigAddress.str(), process.str(), compName, OS, path); else newAddress.clear().appendf("%s|%s:%s:%s:%s:%s", sAddress.str(), sConfigAddress.str(), compType, compName, OS, path); } #else if (process.length() > 0) newAddress.clear().appendf("%s:%s:%s:%s:%s", sAddress.str(), process.str(), compName, OS, path); else newAddress.clear().appendf("%s:%s:%s:%s:%s", sAddress.str(), compType, compName, OS, path); //newAddress.clear().appendf("%s:ThorMasterProcess:%s:%s:%s", sAddress.str(), compName, OS, path); #endif return; }