bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { resp.updateStatus().setCode(0); StringAttr target(req.getTarget()); StringAttr name(req.getPackageMap()); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); if (name.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); DBGLOG("%s adding packagemap %s to target %s", context.queryUserId(), name.str(), target.str()); StringBuffer pmid; if (!req.getGlobalScope()) pmid.append(target).append("::"); pmid.append(name.get()); bool activate = req.getActivate(); unsigned updateFlags = 0; if (req.getOverWrite()) updateFlags |= (DALI_UPDATEF_PACKAGEMAP | DALI_UPDATEF_REPLACE_FILE | DALI_UPDATEF_CLONE_FROM | DALI_UPDATEF_SUPERFILES); if (req.getReplacePackageMap()) updateFlags |= DALI_UPDATEF_PACKAGEMAP; if (req.getUpdateCloneFrom()) updateFlags |= DALI_UPDATEF_CLONE_FROM; if (req.getUpdateSuperFiles()) updateFlags |= DALI_UPDATEF_SUPERFILES; if (req.getAppendCluster()) updateFlags |= DALI_UPDATEF_APPEND_CLUSTER; StringAttr processName(req.getProcess()); Owned<IUserDescriptor> userdesc; const char *user = context.queryUserId(); const char *password = context.queryPassword(); if (user && *user && *password && *password) { userdesc.setown(createUserDescriptor()); userdesc->set(user, password); } StringBuffer srcCluster; StringBuffer daliip; StringBuffer prefix; splitDerivedDfsLocation(req.getDaliIp(), srcCluster, daliip, prefix, req.getSourceProcess(), req.getSourceProcess(), NULL, NULL); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, processName.get()); StringArray filesNotFound; addPackageMapInfo(updateFlags, req.getInfo(), filesNotFound, processName, target, pmid, pkgSetId, daliip, srcCluster, prefix, activate, userdesc, req.getAllowForeignFiles(), req.getPreloadAllPackages()); resp.setFilesNotFound(filesNotFound); StringBuffer msg; msg.append("Successfully loaded ").append(name.get()); resp.updateStatus().setDescription(msg.str()); return true; }
bool CWsDfuXRefEx::onDFUXRefUnusedFiles(IEspContext &context, IEspDFUXRefUnusedFilesRequest &req, IEspDFUXRefUnusedFilesResponse &resp) { const char *process = req.getProcessCluster(); if (!process || !*process) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "process cluster, not specified."); SocketEndpointArray servers; getRoxieProcessServers(process, servers); if (!servers.length()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_CLUSTER_INFO, "process cluster, not found."); Owned<ISocket> sock = ISocket::connect_timeout(servers.item(0), 5000); Owned<IPropertyTree> controlXrefInfo = sendRoxieControlQuery(sock, "<control:getQueryXrefInfo/>", 5000); if (!controlXrefInfo) throw MakeStringExceptionDirect(ECLWATCH_INTERNAL_ERROR, "roxie cluster, not responding."); MapStringTo<bool> usedFileMap; Owned<IPropertyTreeIterator> roxieFiles = controlXrefInfo->getElements("//File"); ForEach(*roxieFiles) addLfnToUsedFileMap(usedFileMap, roxieFiles->query().queryProp("@name")); if (req.getCheckPackageMaps()) addUsedFilesFromActivePackageMaps(usedFileMap, process); StringArray unusedFiles; findUnusedFilesInDFS(unusedFiles, process, usedFileMap); resp.setUnusedFileCount(unusedFiles.length()); resp.setUnusedFiles(unusedFiles); return true; }
void setPMID(const char *_target, const char *name, bool globalScope) { if (!name || !*name) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); if (!globalScope) { target.set(_target); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); ensureClusterInfo(); pmid.append(target).append("::"); } pmid.append(name); pmid.toLowerCase(); }
static ISecManager* loadSecManager(const char* model_name, const char* servicename, IPropertyTree* cfg) { if (!model_name || !*model_name) throw MakeStringExceptionDirect(-1, "Security model not specified"); StringBuffer realName; if(stricmp(model_name, "LdapSecurity") == 0) { realName.append(SharedObjectPrefix).append(LDAPSECLIB).append(SharedObjectExtension); HINSTANCE ldapseclib = LoadSharedObject(realName.str(), true, false); if(ldapseclib == NULL) throw MakeStringException(-1, "can't load library %s", realName.str()); newSecManager_t_ xproc = NULL; xproc = (newSecManager_t_)GetSharedProcedure(ldapseclib, "newLdapSecManager"); if (xproc) return xproc(servicename, *cfg); else throw MakeStringException(-1, "procedure newLdapSecManager of %s can't be loaded", realName.str()); } else throw MakeStringException(-1, "Security model %s not supported", model_name); }
bool CWsDfuXRefEx::onDFUXRefMessages(IEspContext &context, IEspDFUXRefMessagesQueryRequest &req, IEspDFUXRefMessagesQueryResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to get Xref Messages. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefMessages User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) return false; StringBuffer buf; xRefNode->serializeMessages(buf); resp.setDFUXRefMessagesQueryResult(buf.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWsDfuXRefEx::onDFUXRefCleanDirectories(IEspContext &context, IEspDFUXRefCleanDirectoriesRequest &req, IEspDFUXRefCleanDirectoriesResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Write, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to clean Xref Directories. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefDirectories User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) return false; StringBuffer buf; xRefNode->removeEmptyDirectories(buf); DBGLOG("xRefNode->removeEmptyDirectories result=%s",buf.str()); resp.setRedirectUrl(StringBuffer("/WsDFUXRef/DFUXRefDirectories?Cluster=").append(req.getCluster())); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
//--------------------------------------------------------------------------- // getPluginDirectory // // returns absolute path where plugins are to be deployed //--------------------------------------------------------------------------- void CPluginDeploymentEngine::getPluginDirectory(const char* destPath, StringBuffer& sPluginDest) const { sPluginDest.clear().append(destPath); sPluginDest.replace('\\', '/'); StringBuffer sPluginsDir; //relative path (from ECL server installation directory) for plugins m_process.getProp("@pluginsPath", sPluginsDir); if (sPluginsDir.length()) { sPluginsDir.replace('\\', '/'); sPluginsDir.replace('$', ':'); if (! ::PathIsRelative(sPluginsDir.str())) throw MakeStringExceptionDirect(-1, "Plugins path for ECL server must be relative to its installation directory!"); if (!strncmp(sPluginsDir.str(), "./", 2)) sPluginsDir.remove(0, 2); sPluginDest.append(sPluginsDir); } const char* pchLast = sPluginDest.str() + sPluginDest.length() - 1; if (*pchLast != '/') sPluginDest.append('/'); }
bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { resp.updateStatus().setCode(0); StringAttr target(req.getTarget()); StringAttr name(req.getPackageMap()); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); if (name.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); StringBuffer pmid; if (!req.getGlobalScope()) pmid.append(target).append("::"); pmid.append(name.get()); bool activate = req.getActivate(); bool overWrite = req.getOverWrite(); StringAttr processName(req.getProcess()); Owned<IUserDescriptor> userdesc; const char *user = context.queryUserId(); const char *password = context.queryPassword(); if (user && *user && *password && *password) { userdesc.setown(createUserDescriptor()); userdesc->set(user, password); } StringBuffer srcCluster; StringBuffer daliip; StringBuffer prefix; splitDerivedDfsLocation(req.getDaliIp(), srcCluster, daliip, prefix, req.getSourceProcess(), req.getSourceProcess(), NULL, NULL); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, processName.get()); StringArray filesNotFound; addPackageMapInfo(req.getInfo(), filesNotFound, processName, target, pmid, pkgSetId, daliip, srcCluster, prefix, activate, overWrite, userdesc, req.getAllowForeignFiles(), req.getPreloadAllPackages()); resp.setFilesNotFound(filesNotFound); StringBuffer msg; msg.append("Successfully loaded ").append(name.get()); resp.updateStatus().setDescription(msg.str()); return true; }
void createPart(const char *partname, const char *xml) { if (!partname || !*partname) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap Part name provided"); if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap content provided"); pmPart.setown(createPTreeFromXMLString(xml)); if (!pmPart) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap content"); pmPart->addProp("@id", partname); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); fixPackageMapFileIds(pmPart, checkFlag(PKGADD_PRELOAD_ALL)); }
void createPart(const char *partname, const char *xml) { if (!partname || !*partname) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap Part name provided"); if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap content provided"); pmPart.setown(createPTreeFromXMLString(xml)); if (!pmPart) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap content"); pmPart->addProp("@id", partname); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); Owned<IPropertyTreeIterator> iter = pmPart->getElements("Package"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (checkFlag(PKGADD_PRELOAD_ALL)) item.setPropBool("@preload", true); Owned<IPropertyTreeIterator> superFiles = item.getElements("SuperFile"); ForEach(*superFiles) { IPropertyTree &superFile = superFiles->query(); StringBuffer lc(superFile.queryProp("@id")); const char *id = lc.toLowerCase().str(); if (*id == '~') id++; superFile.setProp("@id", id); Owned<IPropertyTreeIterator> subFiles = superFile.getElements("SubFile"); ForEach(*subFiles) { IPropertyTree &subFile = subFiles->query(); id = subFile.queryProp("@value"); if (id && *id == '~') { StringAttr value(id+1); subFile.setProp("@value", value.get()); } } } } }
void activatePackageMapInfo(const char *target, const char *name, const char *process, bool globalScope, bool activate) { if (!target || !*target) throw MakeStringExceptionDirect(PKG_TARGET_NOT_DEFINED, "No target defined"); if (!name || !*name) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "No pmid specified"); Owned<IRemoteConnection> globalLock = querySDS().connect("PackageSets", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT); if (!globalLock) throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageSets information from dali /PackageSets"); StringBuffer lcTarget(target); target = lcTarget.toLowerCase().str(); StringBuffer lcName(name); name = lcName.toLowerCase().str(); IPropertyTree *root = globalLock->queryRoot(); if (!root) throw MakeStringException(PKG_ACTIVATE_NOT_FOUND, "Unable to retrieve PackageSet information"); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, process); VStringBuffer xpath("PackageSet[@id='%s']", pkgSetId.str()); IPropertyTree *pkgSetTree = root->queryPropTree(xpath); if (pkgSetTree) { IPropertyTree *mapTree = NULL; if (!globalScope) { xpath.clear().appendf("PackageMap[@querySet='%s'][@id='%s::%s']", target, target, name); mapTree = pkgSetTree->queryPropTree(xpath); } if (!mapTree) { xpath.clear().appendf("PackageMap[@querySet='%s'][@id='%s']", target, name); mapTree = pkgSetTree->queryPropTree(xpath); } if (!mapTree) throw MakeStringException(PKG_ACTIVATE_NOT_FOUND, "PackageMap %s not found on target %s", name, target); makePackageActive(pkgSetTree, mapTree, target, activate); } }
virtual void append(IMultiException& me) { synchronized block(m_mutex); IArrayOf<IException>& exceptions = me.getArray(); const char* source = me.source(); ForEachItemIn(i, exceptions) { IException& e = exceptions.item(i); if (source && *source) { StringBuffer msg; msg.appendf("[%s] ",source); e.errorMessage(msg); array_.append(*MakeStringExceptionDirect(e.errorAudience(), e.errorCode(), msg)); } else array_.append(*LINK(&e)); }
bool CWsDfuXRefEx::onDFUXRefBuild(IEspContext &context, IEspDFUXRefBuildRequest &req, IEspDFUXRefBuildResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to build Xref. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefBuild User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); //create the node if it doesn;t exist Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) { xRefNode.setown( XRefNodeManager->CreateXRefNode(req.getCluster())); } StringBuffer returnStr; if (m_XRefbuilder->IsQueued(req.getCluster()) ) appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","An XRef build for cluster %s is in process. Click here to return to the main XRef List.",req.getCluster()); else if (!m_XRefbuilder->IsRunning()) appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","Running XRef Process. Click here to return to the main XRef List."); else appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","someone is currently running a Xref build. Your request will be added to the queue. Please click here to return to the main page."); m_XRefbuilder->QueueRequest(xRefNode,req.getCluster()); resp.setDFUXRefActionResult(returnStr.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool invoke_program(const char *command_line, DWORD &runcode, bool wait, const char *outfile, HANDLE *rethandle, bool throwException, bool newProcessGroup) { runcode = 0; if (rethandle) *rethandle = 0; if(!command_line || !*command_line) return false; pid_t pid = fork(); if (pid == 0) { //Force the child process into its own process group, so we can terminate it and its children. if (newProcessGroup) setpgid(0,0); if (outfile&&*outfile) { int outh = open(outfile, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); if(outh >= 0) { dup2(outh, STDOUT_FILENO); dup2(outh, STDERR_FILENO); close(outh); } else { ERRLOG("invoke_program: could not open %s",outfile); return false; } } int size = 10; char **args; char **argptr = args = (char **) malloc(sizeof(args) * size); char **over = argptr+size; char *cl = strdup(command_line); char *curptr = cl; *argptr = readarg(curptr); while (*argptr != NULL) { argptr++; if (argptr==over) { args = (char **) realloc(args, sizeof(args) * size * 2); argptr = args+size; size *= 2; over = args+size; } *argptr = readarg(curptr); } // JCSMORE - do I not need to free args, if successful exec? if (execvp(*args, args)) { //print out why create process failed int err = errno; ERRLOG("invoke_program(%s) failed with error(%d): %s",command_line,err,strerror(err)); } assertex(0); // don't expect to get here! _exit(0); } else if (pid < 0) { StringBuffer s("fork of \""); s.append(command_line).append("\" failed. fork() returned:"); if (errno == EAGAIN) s.append("EAGAIN"); else if (errno == ENOMEM) s.append("ENOMEM"); else s.append(errno); ERRLOG("%s",s.toCharArray()); if(throwException) throw MakeStringExceptionDirect(-1, s.str()); return false; } if (rethandle) *rethandle = (HANDLE)pid; if (wait) { int retv; if (waitpid(pid, &retv, 0) != pid) { ERRLOG("invoke_program(%s): wait failed (%d)",command_line,(int)pid); return false; } if (!WIFEXITED(retv)) //did not exit normally { int err = errno; ERRLOG("invoke_program(%s): failed.",command_line); ERRLOG("The process was killed by signal %d%s.",(int)WTERMSIG(retv),WCOREDUMP(retv)?" - core dumped":""); ERRLOG("Last system error is %s",strerror(err)); } runcode = WEXITSTATUS(retv); } return true; // it did run even if signalled }
void addPackageMapInfo(const char *xml, StringArray &filesNotFound, const char *process, const char *target, const char *pmid, const char *packageSetName, const char *lookupDaliIp, const char *srcCluster, const char *prefix, bool activate, bool overWrite, IUserDescriptor* userdesc, bool allowForeignFiles, bool preloadAll) { if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "PackageMap info not provided"); if (srcCluster && *srcCluster) { if (!isProcessCluster(lookupDaliIp, srcCluster)) throw MakeStringException(PKG_INVALID_CLUSTER_TYPE, "Process cluster %s not found on %s DALI", srcCluster, lookupDaliIp ? lookupDaliIp : "local"); } Owned<IConstWUClusterInfo> clusterInfo = getTargetClusterInfo(target); if (!clusterInfo) throw MakeStringException(PKG_TARGET_NOT_DEFINED, "Could not find information about target cluster %s ", target); Owned<IPropertyTree> pmTree = createPTreeFromXMLString(xml); if (!pmTree) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap info"); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); pmTree->setProp("@id", pmid); Owned<IPropertyTreeIterator> iter = pmTree->getElements("Package"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (preloadAll) item.setPropBool("@preload", true); Owned<IPropertyTreeIterator> superFiles = item.getElements("SuperFile"); ForEach(*superFiles) { IPropertyTree &superFile = superFiles->query(); StringBuffer lc(superFile.queryProp("@id")); const char *id = lc.toLowerCase().str(); if (*id == '~') id++; superFile.setProp("@id", id); Owned<IPropertyTreeIterator> subFiles = superFile.getElements("SubFile"); ForEach(*subFiles) { IPropertyTree &subFile = subFiles->query(); id = subFile.queryProp("@value"); if (id && *id == '~') { StringAttr value(id+1); subFile.setProp("@value", value.get()); } } } } VStringBuffer xpath("PackageMap[@id='%s']", pmid); Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageMaps", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT); IPropertyTree *packageMaps = globalLock->queryRoot(); IPropertyTree *pmExisting = packageMaps->queryPropTree(xpath); xpath.appendf("[@querySet='%s']", target); Owned<IPropertyTree> pkgSet = getPkgSetRegistry(process, false); IPropertyTree *psEntry = pkgSet->queryPropTree(xpath); if (!overWrite && (psEntry || pmExisting)) throw MakeStringException(PKG_NAME_EXISTS, "Package name %s already exists, either delete it or specify overwrite", pmid); cloneFileInfoToDali(filesNotFound, pmTree, lookupDaliIp, clusterInfo, srcCluster, prefix, overWrite, userdesc, allowForeignFiles); if (pmExisting) packageMaps->removeTree(pmExisting); packageMaps->addPropTree("PackageMap", pmTree.getClear()); if (!psEntry) { psEntry = pkgSet->addPropTree("PackageMap", createPTree("PackageMap")); psEntry->setProp("@id", pmid); psEntry->setProp("@querySet", target); } makePackageActive(pkgSet, psEntry, target, activate); }
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; sArray.appendList(addresses.item(index), ":"); 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_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, 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; }
bool CWsDfuXRefEx::onDFUXRefDirectories(IEspContext &context, IEspDFUXRefDirectoriesQueryRequest &req, IEspDFUXRefDirectoriesQueryResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to get Xref Directories. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefDirectories User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) return false; StringBuffer buf0; xRefNode->serializeDirectories(buf0); Owned <IPropertyTree> dirs = createPTreeFromXMLString(buf0.str()); // Why are we doing this? Owned<IPropertyTreeIterator> iter = dirs->getElements("Directory"); ForEach(*iter) { IPropertyTree &node = iter->query(); StringBuffer positive, negative; char* skew = (char*) node.queryProp("Skew"); if (!skew || !*skew) continue; char* skewPtr = strchr(skew, '/'); if (skewPtr) { if (skew[0] == '+' && (strlen(skew) > 1)) positive.append(skewPtr - skew - 1, skew+1); else positive.append(skewPtr - skew, skew); skewPtr++; if (skewPtr) { if (skewPtr[0] == '-') negative.append(skewPtr+1); else negative.append(skewPtr); } } else { if (skew[0] == '+' && (strlen(skew) > 1)) positive.append(skew+1); else positive.append(skew); } node.removeProp("Skew"); node.addProp("PositiveSkew", positive); node.addProp("NegativeSkew", negative); } StringBuffer buf; toXML(dirs, buf); resp.setDFUXRefDirectoriesQueryResult(buf.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
bool CWsDfuXRefEx::onDFUXRefArrayAction(IEspContext &context, IEspDFUXRefArrayActionRequest &req, IEspDFUXRefArrayActionResponse &resp) { try { StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefArrayAction User=%s",username.str()); Owned<IUserDescriptor> userdesc; if(username.length() > 0) { const char* passwd = context.queryPassword(); userdesc.setown(createUserDescriptor()); userdesc->set(username.str(), passwd); } if(*req.getAction() == 0 || *req.getType() == 0 || *req.getCluster() == 0) { ERRLOG("Invalid Parameters into CWsDfuXRefEx::onDFUXRefArrayAction"); throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Action, cluster, or type not defined."); } Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) { ERRLOG("Unable to resolve XRef cluster name %s",req.getCluster()); throw MakeStringException(ECLWATCH_CANNOT_RESOLVE_CLUSTER_NAME, "Unable to resolve cluster name %s",req.getCluster()); } Owned<IXRefFilesNode> _fileNode = getFileNodeInterface(*xRefNode.get(),req.getType()); if (_fileNode.get() == 0) { ERRLOG("Unable to find a suitable IXRefFilesNode interface for %s",req.getType()); throw MakeStringException(ECLWATCH_CANNOT_FIND_IXREFFILESNODE, "Unable to find a suitable IXRefFilesNode interface for %s",req.getType()); } if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to run Xref command. Permission denied."); StringBuffer returnStr,UserName; const char* ActionType = req.getAction(); DBGLOG("Running Xref Command %s for user %s",ActionType,context.getUserID(UserName).str()); for(unsigned i = 0; i < req.getXRefFiles().length();i++) { DBGLOG("CWsDfuXRefEx::onDFUXRefArrayAction %s file %s for User=%s", ActionType, req.getXRefFiles().item(i), username.str()); StringBuffer errstr; if (strcmp("Delete" ,ActionType) == 0) { if (_fileNode->RemovePhysical(req.getXRefFiles().item(i),userdesc,req.getCluster(),errstr)) appendReplyMessage(returnStr,NULL,"Removed Physical part %s",req.getXRefFiles().item(i)); else appendReplyMessage(returnStr,NULL,"Error(s) removing physical part %s\n%s",req.getXRefFiles().item(i),errstr.str()); } else if (strcmp("Attach" ,ActionType) == 0) { if(_fileNode->AttachPhysical(req.getXRefFiles().item(i),userdesc,req.getCluster(),errstr) ) appendReplyMessage(returnStr,NULL,"Reattached Physical part %s",req.getXRefFiles().item(i)); else appendReplyMessage(returnStr,NULL,"Error(s) attaching physical part %s\n%s",req.getXRefFiles().item(i),errstr.str()); } if (strcmp("DeleteLogical" ,ActionType) == 0) { // Note we don't want to physically delete 'lost' files - this will end up with orphans on next time round but that is safer if (_fileNode->RemoveLogical(req.getXRefFiles().item(i),userdesc,req.getCluster(),errstr)) { appendReplyMessage(returnStr,NULL,"Removed Logical File %s",req.getXRefFiles().item(i)); } else appendReplyMessage(returnStr,NULL,"Error(s) removing File %s\n%s",req.getXRefFiles().item(i),errstr.str()); } } xRefNode->commit(); resp.setDFUXRefArrayActionResult(returnStr.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }