void SWProcess::computerUpdated(IPropertyTree *computerNode, const char* oldName, const char* oldIp, const char* instanceXMLTagName) { IPropertyTree *software = m_envHelper->getEnvTree()->queryPropTree("Software"); Owned<IPropertyTreeIterator> compIter = software->getElements(m_processName); const char *instance = (instanceXMLTagName)? instanceXMLTagName: m_instanceElemName.str(); synchronized block(mutex); ForEach (*compIter) { IPropertyTree *comp = &compIter->query(); Owned<IPropertyTreeIterator> instanceIter = comp->getElements(instance); ForEach (*instanceIter) { IPropertyTree *instance = &instanceIter->query(); if (instance->hasProp(XML_ATTR_NAME) && !stricmp(instance->queryProp(XML_ATTR_NAME), oldName)) { if (stricmp(computerNode->queryProp(XML_ATTR_NAME), instance->queryProp(XML_ATTR_NAME))) instance->setProp(XML_ATTR_NAME, computerNode->queryProp(XML_ATTR_NAME)); if (instance->hasProp(m_ipAttribute.str()) && stricmp(computerNode->queryProp(XML_ATTR_NETADDRESS), instance->queryProp(m_ipAttribute.str()))) instance->setProp(m_ipAttribute.str(), computerNode->queryProp(XML_ATTR_NETADDRESS)); if (instance->hasProp("@computer") && stricmp(computerNode->queryProp(XML_ATTR_NAME), instance->queryProp("@computer"))) instance->setProp("@computer", computerNode->queryProp(XML_ATTR_NAME)); } else if (instance->hasProp(m_ipAttribute.str()) && !stricmp(instance->queryProp(m_ipAttribute.str()), oldIp)) { instance->setProp(m_ipAttribute.str(), computerNode->queryProp(XML_ATTR_NETADDRESS)); } } } }
void CLogContentFilter::readAllLogFilters(IPropertyTree* cfg) { bool groupFilterRead = false; VStringBuffer xpath("Filters/Filter[@type='%s']", espLogContentGroupNames[ESPLCGBackEndResp]); IPropertyTree* filter = cfg->queryBranch(xpath.str()); if (filter && filter->hasProp("@value")) { logBackEndResp = filter->getPropBool("@value"); groupFilterRead = true; } xpath.setf("Filters/Filter[@type='%s']", espLogContentGroupNames[ESPLCGBackEndReq]); filter = cfg->queryBranch(xpath.str()); if (filter && filter->hasProp("@value")) { logBackEndReq = filter->getPropBool("@value"); groupFilterRead = true; } for (unsigned i = 0; i < ESPLCGBackEndReq; i++) { if (readLogFilters(cfg, i)) groupFilterRead = true; } if (!groupFilterRead) { groupFilters.clear(); readLogFilters(cfg, ESPLCGAll); } }
void appendSchemaResource(IPropertyTree &res, ILoadedDllEntry *dll) { if (!dll || (flags & WWV_OMIT_SCHEMAS)) return; if (res.getPropInt("@seq", -1)>=0 && res.hasProp("@id")) { int id = res.getPropInt("@id"); size32_t len = 0; const void *data = NULL; if (dll->getResource(len, data, "RESULT_XSD", (unsigned) id) && len>0) { buffer.append("<XmlSchema name=\"").append(res.queryProp("@name")).append("\">"); if (res.getPropBool("@compressed")) { StringBuffer decompressed; decompressResource(len, data, decompressed); if (flags & WWV_CDATA_SCHEMAS) buffer.append("<![CDATA["); buffer.append(decompressed.str()); if (flags & WWV_CDATA_SCHEMAS) buffer.append("]]>"); } else buffer.append(len, (const char *)data); buffer.append("</XmlSchema>"); } } }
unsigned SWBackupNode::add(IPropertyTree *params) { unsigned rc = SWProcess::add(params); IPropertyTree * envTree = m_envHelper->getEnvTree(); const char* key = params->queryProp("@key"); StringBuffer xpath; xpath.clear().appendf(XML_TAG_SOFTWARE "/%s[@name=\"%s\"]", m_processName.str(), key); IPropertyTree * compTree = envTree->queryPropTree(xpath.str()); assert(compTree); const char* selector = params->queryProp("@selector"); if (selector && !stricmp("NodeGroup", selector)) { IPropertyTree *nodeGroup = createPTree(selector); IPropertyTree* pAttrs = params->queryPropTree("Attributes"); updateNode(nodeGroup, pAttrs, NULL); if (!nodeGroup->hasProp("@interval")) { xpath.clear().appendf("xs:element/xs:complexType/xs:sequence/xs:element[@name=\"NodeGroup\"]/xs:complexType/xs:attribute[@name=\"interval\"]/@default"); const char *interval = m_pSchema->queryProp(xpath.str()); if ( interval && *interval ) { nodeGroup->addProp("@interval", interval); } else { throw MakeStringException(CfgEnvErrorCode::MissingRequiredParam, "Missing required paramter \"interval\" and there is no default value."); } } compTree->addPropTree(selector, nodeGroup); } return rc; }
static bool ensureThorIsDown(const char *cluster, bool nofail, bool wait) { bool retry = false; do { Owned<IRemoteConnection> pStatus = querySDS().connect("/Status/Servers", myProcessSession(), RTM_NONE, SDS_LOCK_TIMEOUT); Owned<IPropertyTreeIterator> it = pStatus->queryRoot()->getElements("Server[@name='ThorMaster']"); retry = false; ForEach(*it) { IPropertyTree* pServer = &it->query(); if (pServer->hasProp("@cluster") && !strcmp(pServer->queryProp("@cluster"), cluster)) { if (nofail) { WARNLOG("A Thor on cluster %s is still active", cluster); if (!wait) return false; Sleep(1000*10); PROGLOG("Retrying..."); retry = true; break; } throw MakeStringException(-1, "A Thor cluster node swap requires the cluster to be offline. Please stop the Thor cluster '%s' and try again.", cluster); } } } while (retry); return true; }
void SWBackupNode::addOtherSelector(IPropertyTree *compTree, IPropertyTree *params) { StringBuffer xpath; assert(compTree); const char* selector = params->queryProp("@selector"); if (selector && !stricmp("NodeGroup", selector)) { IPropertyTree *nodeGroup = createPTree(selector); IPropertyTree* pAttrs = params->queryPropTree("Attributes"); updateNode(nodeGroup, pAttrs, NULL); if (!nodeGroup->hasProp("@interval")) { xpath.clear().appendf("xs:element/xs:complexType/xs:sequence/xs:element[@name=\"NodeGroup\"]/xs:complexType/xs:attribute[@name=\"interval\"]/@default"); const char *interval = m_pSchema->queryProp(xpath.str()); if ( interval && *interval ) { nodeGroup->addProp("@interval", interval); } else { throw MakeStringException(CfgEnvErrorCode::MissingRequiredParam, "Missing required paramter \"interval\" and there is no default value."); } } compTree->addPropTree(selector, nodeGroup); } }
bool getIsOpt(const IPropertyTree &graphNode) { if (graphNode.hasProp("att[@name='_isOpt']")) return graphNode.getPropBool("att[@name='_isOpt']/@value", false); else return graphNode.getPropBool("att[@name='_isIndexOpt']/@value", false); }
bool deletePkgInfo(const char *name, const char *target, const char *process, bool globalScope) { Owned<IRemoteConnection> pkgSetsConn = querySDS().connect("/PackageSets/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT); if (!pkgSetsConn) throw MakeStringException(PKG_NONE_DEFINED, "No package sets defined"); IPropertyTree* packageSets = pkgSetsConn->queryRoot(); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, process); VStringBuffer pkgSet_xpath("PackageSet[@id='%s']", pkgSetId.str()); IPropertyTree *pkgSetRegistry = packageSets->queryPropTree(pkgSet_xpath.str()); if (!pkgSetRegistry) throw MakeStringException(PKG_TARGET_NOT_DEFINED, "No package sets defined for %s", process); StringBuffer lcTarget(target); target = lcTarget.toLowerCase().str(); StringBuffer lcName(name); name = lcName.toLowerCase().str(); Owned<IPropertyTree> mapEntry; StringBuffer xpath; if (!globalScope) { xpath.appendf("PackageMap[@id='%s::%s'][@querySet='%s']", target, name, target); mapEntry.setown(pkgSetRegistry->getPropTree(xpath.str())); } if (!mapEntry) { xpath.clear().appendf("PackageMap[@id='%s'][@querySet='%s']", name, target); mapEntry.setown(pkgSetRegistry->getPropTree(xpath.str())); if (!mapEntry) throw MakeStringException(PKG_DELETE_NOT_FOUND, "Unable to delete %s - information not found", lcName.str()); } StringAttr pmid(mapEntry->queryProp("@id")); pkgSetRegistry->removeTree(mapEntry); xpath.clear().appendf("PackageSet/PackageMap[@id='%s']", pmid.get()); if (!packageSets->hasProp(xpath)) { Owned<IRemoteConnection> pkgMapsConn = querySDS().connect("/PackageMaps/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT); if (!pkgMapsConn) throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageMaps information from dali [/PackageMaps]"); IPropertyTree *pkgMaps = pkgMapsConn->queryRoot(); if (!pkgMaps) throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageMaps information from dali [/PackageMaps]"); IPropertyTree *mapTree = pkgMaps->queryPropTree(xpath.clear().appendf("PackageMap[@id='%s']", pmid.get()).str()); if (mapTree) pkgMaps->removeTree(mapTree); } return true; }
void SWProcess::computerDeleted(const char* ipAddress, const char* computerName, const char *instanceXMLTagName) { IPropertyTree * software = m_envHelper->getEnvTree()->queryPropTree(XML_TAG_SOFTWARE); Owned<IPropertyTreeIterator> compIter = software->getElements(m_processName); const char *instance = (instanceXMLTagName)? instanceXMLTagName: m_instanceElemName.str(); synchronized block(mutex); ForEach (*compIter) { IPropertyTree * comp = &compIter->query(); Owned<IPropertyTreeIterator> instanceIter = comp->getElements(instance); ForEach (*instanceIter) { IPropertyTree * instance = &instanceIter->query(); if ((instance->hasProp(m_ipAttribute.str()) && stricmp(instance->queryProp(m_ipAttribute.str()), ipAddress)) || (instance->hasProp("@computer") && stricmp(instance->queryProp("@computer"), computerName))) comp->removeTree(instance); } } }
void ResourceManifest::addToArchive(IPropertyTree *archive) { IPropertyTree *additionalFiles = ensurePTree(archive, "AdditionalFiles"); //xsi namespace required for proper representaion after PTree::setPropBin() if (!additionalFiles->hasProp("@xmlns:xsi")) additionalFiles->setProp("@xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); Owned<IPropertyTreeIterator> resources = manifest->getElements("Resource[@resourcePath]"); ForEach(*resources) { IPropertyTree &item = resources->query(); const char *respath = item.queryProp("@resourcePath"); VStringBuffer xpath("Resource[@resourcePath='%s']", respath); if (!additionalFiles->hasProp(xpath.str())) { IPropertyTree *resTree = additionalFiles->addPropTree("Resource", createPTree("Resource")); const char *filepath = item.queryProp("@originalFilename"); resTree->setProp("@originalFilename", filepath); resTree->setProp("@resourcePath", respath); MemoryBuffer content; loadResource(filepath, content); resTree->setPropBin(NULL, content.length(), content.toByteArray()); } } StringBuffer xml; toXML(manifest, xml); IPropertyTree *manifest = additionalFiles->addPropTree("Manifest", createPTree("Manifest", ipt_none)); manifest->setProp("@originalFilename", absFilename.str()); manifest->setProp(NULL, xml.str()); }
bool CLogThread::FlattenTree(IArrayOf<IEspLogInfo>& valueArray,IPropertyTree& tree,StringBuffer& RootName) { StringBuffer Value,Name; if (tree.hasChildren() == true) { Owned<IPropertyTreeIterator> itr = tree.getElements("*"); itr->first(); while(itr->isValid()) { IPropertyTree &node = itr->query(); if(RootName.length() > 0) Name.appendf("%s_",RootName.str()); Name.appendf("%s",node.queryName()); if (node.hasChildren() == true) { if(IsArray(node)==true) FlattenArray(valueArray,node,Name); else FlattenTree(valueArray,node,Name); } else { const char* _value = tree.queryProp(node.queryName()); if(tree.hasProp(node.queryName())==true && _value!=0 && _value!='\0') { Value.appendf("%s",tree.queryProp(node.queryName())); IClientLogInfo& logElement = addLogInfoElement(valueArray); logElement.setName(Name.str()); logElement.setValue(Value.str()); //DBGLOG("Add log element: %s, %s", Name.str(), Value.str()); Value.clear(); } } Name.clear(); itr->next(); } } else { return false; } return true; }
CEclDirectSoapBindingEx::CEclDirectSoapBindingEx(IPropertyTree* cfg, const char *binding, const char *process):CEclDirectSoapBinding(cfg, binding, process) { StringBuffer xpath; xpath.appendf("Software/EspProcess[@name='%s']", process); IPropertyTree *procTree = cfg->queryPropTree(xpath.str()); if (!procTree) throw MakeStringException(-1, "EclDirect Configuration Error: unable to find process"); xpath.set("EspBinding[@name='").append(binding).append("']/@port"); int port = procTree->getPropInt(xpath.str()); if (port) { xpath.set("EspBinding[@type='ws_workunitsSoapBinding'][@port='").append(port).append("']"); redirect = procTree->hasProp(xpath.str()); } SCMStringBuffer s; Owned<IStringIterator> it = getTargetClusters(NULL, NULL); ForEach(*it) clusters.append(it->str(s).str()); supportRepository = false; }
IPropertyTree * SWProcess::addComponent(IPropertyTree *params) { const char* clone = params->queryProp("@clone"); if (clone) { return SWComponentBase::cloneComponent(params); } IPropertyTree * pCompTree = SWComponentBase::addComponent(params); if (pCompTree->hasProp("@daliServers") && !strcmp(pCompTree->queryProp("@daliServers"), "")) { IPropertyTree * envTree = m_envHelper->getEnvTree(); StringBuffer xpath; xpath.clear().appendf(XML_TAG_SOFTWARE "/DaliServerProcess/@name"); const char *daliName = envTree->queryProp(xpath.str()); if (daliName) { pCompTree->setProp("@daliServers", daliName); } } removeInstancesFromComponent(pCompTree); return pCompTree; }
bool CEnvGen::parseArgs(int argc, char** argv) { int i = 1; //m_params = createPTree("Env"); m_params.setown(createPTree("Env")); IPropertyTree * config = createPTree("Config"); m_params->addPropTree("Config", config); while (i < argc) { if (stricmp(argv[i], "-help") == 0 || stricmp(argv[i], "-?") == 0) { usage(); return false; } else if (stricmp(argv[i], "-mode") == 0) { i++; config->setProp("@mode", argv[i++]); } else if ((stricmp(argv[i], "-env") == 0) || (stricmp(argv[i], "-env-out") == 0)) { i++; config->addProp("@env-out", argv[i++]); } else if (stricmp(argv[i], "-env-in") == 0) { i++; config->addProp("@env-in", argv[i++]); } else if (stricmp(argv[i], "-ip") == 0) { i++; config->addProp("@ip-list", argv[i++]); } else if (stricmp(argv[i], "-ipfile") == 0) { i++; config->addProp("@ip-file", argv[i++]); } else if (stricmp(argv[i], "-supportnodes") == 0) { i++; config->addProp("@support-nodes", argv[i++]); } else if (stricmp(argv[i], "-espnodes") == 0) { i++; config->addProp("@esp-nodes", argv[i++]); } else if (stricmp(argv[i], "-roxienodes") == 0) { i++; config->addProp("@roxie-nodes", argv[i++]); } else if (stricmp(argv[i], "-thornodes") == 0) { i++; config->addProp("@thor-nodes", argv[i++]); } else if (stricmp(argv[i], "-slavespernode") == 0) { i++; config->addProp("@slaves-per-node", argv[i++]); } else if (stricmp(argv[i], "-thorchannelsperslave") == 0) { i++; config->addProp("@thor-channels-per-slave", argv[i++]); } else if (stricmp(argv[i], "-roxiechannelsperslave") == 0) { i++; config->addProp("@roxie-channels-per-slave", argv[i++]); } else if (stricmp(argv[i], "-roxieondemand") == 0) { i++; if (!strcmp(argv[i++], "0")) config->addProp("@roxie-on-demand", "false"); } else if (stricmp(argv[i], "-o") == 0) { i++; StringArray sbarr; sbarr.appendList(argv[i++], "="); if (sbarr.length() != 2) continue; if (strstr(sbarr.item(1), "[NAME]") && (strstr(sbarr.item(1), "[INST]") || strstr(sbarr.item(1), "[COMPONENT]"))) { StringBuffer sb; sb.clear().appendf("sw:dirs:category@%s=%s",sbarr.item(0), sbarr.item(1)); createUpdateTask("modify", config, sb.str()); } else { fprintf(stderr, "Error: Directory Override must contain [NAME] and either [INST] or [COMPONENT]\n"); return false; } } else if (stricmp(argv[i], "-override") == 0) { i++; if (!convertOverrideTask(config, argv[i++])) return false; } else if (stricmp(argv[i], "-set-xpath-attrib-value")== 0) { i++; m_arrXPaths.append(*new StringBufferItem (argv[i++])); m_arrAttrib.append(*new StringBufferItem (argv[i++])); m_arrValues.append(*new StringBufferItem (argv[i++])); } // new parameters else if (stricmp(argv[i], "-env-options") == 0) { i++; config->addProp("@options", argv[i++]); } else if (stricmp(argv[i], "-env-rules") == 0) { i++; config->addProp("@rules", argv[i++]); } else if (stricmp(argv[i], "-buildset") == 0) { i++; config->addProp("@buildset", argv[i++]); } else if (stricmp(argv[i], "-add") == 0) { i++; createUpdateTask("add", config, argv[i++]); } else if (stricmp(argv[i], "-mod") == 0) { i++; createUpdateTask("modify", config, argv[i++]); } else if (stricmp(argv[i], "-rmv") == 0) { i++; createUpdateTask("remove", config, argv[i++]); } else if (stricmp(argv[i], "-add-node") == 0) { i++; createUpdateNodeTask("add", config, argv[i++]); } else if (stricmp(argv[i], "-mod-node") == 0) { i++; createUpdateNodeTask("modify", config, argv[i++]); } else if (stricmp(argv[i], "-rmv-node") == 0) { i++; createUpdateNodeTask("remove", config, argv[i++]); } else if (stricmp(argv[i], "-add-binding") == 0) { i++; createUpdateBindingTask("add", config, argv[i++]); } else if (stricmp(argv[i], "-mod-binding") == 0) { i++; createUpdateBindingTask("modify", config, argv[i++]); } else if (stricmp(argv[i], "-rmv-binding") == 0) { i++; createUpdateBindingTask("remove", config, argv[i++]); } else if (stricmp(argv[i], "-add-service") == 0) { i++; createUpdateServiceTask("add", config, argv[i++]); } else if (stricmp(argv[i], "-mod-service") == 0) { i++; createUpdateServiceTask("modify", config, argv[i++]); } else if (stricmp(argv[i], "-rmv-service") == 0) { i++; createUpdateServiceTask("remove", config, argv[i++]); } else if (stricmp(argv[i], "-add-topology") == 0) { i++; createUpdateTopologyTask("add", config, argv[i++]); } else if (stricmp(argv[i], "-mod-topology") == 0) { i++; createUpdateTopologyTask("modify", config, argv[i++]); } else if (stricmp(argv[i], "-rmv-topology") == 0) { i++; createUpdateTopologyTask("remove", config, argv[i++]); } else if (stricmp(argv[i], "-in-file") == 0) { i++; addUpdateTaskFromFile(argv[i++]); } else if (stricmp(argv[i], "-add-content")== 0) { i++; m_arrContentXPaths.append(*new StringBufferItem (argv[i++])); const char* fileName = argv[i++]; StringBufferItem * sbi = new StringBufferItem() ; sbi->loadFile(fileName); m_arrContents.append(*sbi); if ((String(fileName).toLowerCase())->endsWith(".json")) m_arrContentFormats.append(*new StringBufferItem("json")); else m_arrContentFormats.append(*new StringBufferItem("xml")); } else if (stricmp(argv[i], "-show-input-only") == 0) { i++; m_showInputOnly = true; m_displayFormat = XML_Format; } else if (stricmp(argv[i], "-show-input-json-only") == 0) { i++; m_showInputOnly = true; m_displayFormat = JSON_Format; } else if (stricmp(argv[i], "-help-update-1") == 0) { usage_update_input_format_1(); return false; } else if (stricmp(argv[i], "-help-update-2") == 0) { usage_update_input_format_2(); return false; } else if (stricmp(argv[i], "-help-update-3") == 0) { usage_update_input_format_3(); return false; } else if (stricmp(argv[i], "-help-update-3-json") == 0) { usage_update_input_format_3_json(); return false; } else if (stricmp(argv[i], "-cloud") == 0) { i++; cloudConfiguration(config, argv[i++]); } else { fprintf(stderr, "\nUnknown option %s\n", argv[i]); usage(); return false; } } // Check input parameters if (!config->queryProp("@env-out")) { fprintf(stderr, "\nMissing -env-out\n"); usage(); return false; } if (!config->queryProp("@mode")) { if (config->queryProp("@env-in")) config->addProp("@mode", "update"); else config->addProp("@mode", "create"); } if (!stricmp(config->queryProp("@mode"), "update") && !config->queryProp("@env-in")) { fprintf(stderr, "\nMissing input enviroment.xml (-env-in) in update mode\n"); return false; } if (!stricmp(config->queryProp("@mode"), "create") && !config->hasProp("@ip-list") && !config->hasProp("@ip-file")) { config->setProp("@support-nodes", "0"); config->setProp("@roxie-nodes", "0"); config->setProp("@thor-nodes", "0"); config->setProp("@esp-nodes", "0"); } m_iConfigEnv = ConfigEnvFactory::getIConfigEnv(config); return true; }