Просмотр исходного кода

HPCC-9898 ConfigMgr - Fix thor topology cluster add / del

Signed-off-by: Gleb Aronsky <gleb.aronsky@lexisnexis.com>
Gleb Aronsky 11 лет назад
Родитель
Сommit
758bd16d8e

+ 43 - 0
deployment/deployutils/deployutils.cpp

@@ -2811,6 +2811,49 @@ const char* getUniqueName(const IPropertyTree* pEnv, StringBuffer& sName, const
   return sName.str();
 }
 
+
+const char* getUniqueName2(const IPropertyTree* pEnv, StringBuffer& sName, const char* processName, const char* keyAttrib)
+{
+  //if the name ends in _N (where N is a number) then ignore _N to avoid duplicating
+  //number suffix as in _N_M
+  //
+  StringBuffer sPrefix = sName;
+  const char* pdx = strrchr(sName.str(), '_');
+  if (pdx)
+  {
+    StringBuffer num(sName);
+    char* pszNum = num.detach();
+
+    char *token;
+    j_strtok_r(pszNum, "_", &token);
+
+    if (strspn(token, "0123456789") == strlen(token))
+    {
+      sName.remove(pdx - sName.str(), sName.length() - (pdx - sName.str()));
+      sPrefix.clear().append(sName);
+    }
+    else
+    {
+      int len = sPrefix.length();
+      if (len > 0 && endsWith(sPrefix.str(), "_")) //ends with '_'
+        sPrefix = sPrefix.remove(sPrefix.length() - 1, 1); //lose it
+    }
+  }
+
+  StringBuffer xpath;
+  xpath.appendf("./%s[%s='%s']", processName, keyAttrib, sName.str());
+  int iIdx = 2;
+
+  while (pEnv->queryPropTree(xpath))
+  {
+    sName.clear().appendf("%s_", sPrefix.str()).append(iIdx);
+    xpath.clear().appendf("./%s[%s='%s']", processName, keyAttrib, sName.str());
+    iIdx++;
+  }
+
+  return sName.str();
+}
+
 void getCommonDir(const IPropertyTree* pEnv, const char* catType, const char* buildSetName, const char* compName, StringBuffer& sbVal)
 {
   const IPropertyTree* pEnvDirs = pEnv->queryPropTree("Software/Directories");

+ 1 - 0
deployment/deployutils/deployutils.hpp

@@ -60,6 +60,7 @@ extern DEPLOYUTILS_API IPropertyTree* generateTreeFromXsd(const IPropertyTree* p
 extern DEPLOYUTILS_API bool checkComponentReferences(const IPropertyTree* pEnv, IPropertyTree* pCompNode, const char* compName, StringBuffer& sMsg, const char* szNewName=NULL);
 extern DEPLOYUTILS_API bool generateHeaderForComponent(const IPropertyTree* pEnv, IPropertyTree* pSchema, const char* compName);
 extern DEPLOYUTILS_API const char* getUniqueName(const IPropertyTree* pEnv, StringBuffer& sName, const char* xpath, const char* category);
+extern DEPLOYUTILS_API const char* getUniqueName2(const IPropertyTree* pEnv, StringBuffer& sName, const char* processName, const char* keyAttrib);
 extern DEPLOYUTILS_API void getTabNameArray(const IPropertyTree* pEnv, IPropertyTree* pSchema, const char* compName, StringArray& strArray);
 extern DEPLOYUTILS_API void getDefnPropTree(const IPropertyTree* pEnv, IPropertyTree* pSchema, const char* compName, IPropertyTree* pDefTree, StringBuffer xpath);
 extern DEPLOYUTILS_API void getDefnString(const IPropertyTree* pEnv, IPropertyTree* pSchema, const char* compName, StringBuffer& compDefn, StringBuffer& viewChildNodes, StringBuffer& multiRowNodes);

+ 42 - 14
esp/services/WsDeploy/WsDeployService.cpp

@@ -4950,6 +4950,7 @@ bool CWsDeployFileInfo::handleTopology(IEspContext &context, IEspHandleTopologyR
   pTopParams->loadProps(decodedParams.str());
 
   StringBuffer buf("Software/Topology");
+  StringBuffer subPath;
 
   for (int i = 3; i >= 0; i--)
   {
@@ -4981,7 +4982,10 @@ bool CWsDeployFileInfo::handleTopology(IEspContext &context, IEspHandleTopologyR
         buf.append("/").append(sbCl);
       }
       else if (strstr(sbName, XML_TAG_THORCLUSTER) == sbName)
+      {
+        subPath.set(buf);
         buf.append("/ThorCluster");
+      }
       else if (strstr(sbName, XML_TAG_ROXIECLUSTER) == sbName)
         buf.append("/RoxieCluster");
       else if (buf.str()[buf.length() - 1] != ']')
@@ -5014,9 +5018,15 @@ bool CWsDeployFileInfo::handleTopology(IEspContext &context, IEspHandleTopologyR
       !strcmp(sbNewType.str(), XML_TAG_ECLSERVERPROCESS) ||
       !strcmp(sbNewType.str(), XML_TAG_ECLAGENTPROCESS) ||
       !strcmp(sbNewType.str(), XML_TAG_ECLSCHEDULERPROCESS) ||
-      !strcmp(sbNewType.str(), XML_TAG_THORCLUSTER) ||
       !strcmp(sbNewType.str(), XML_TAG_ROXIECLUSTER))
       pNode->addProp(XML_ATTR_PROCESS, "");
+    else if (!strcmp(sbNewType.str(), XML_TAG_THORCLUSTER))
+    {
+      StringBuffer strName("thor");
+      strName.set(getUniqueName2(pEnvRoot->queryPropTree(buf.str()), strName, "ThorCluster", XML_ATTR_PROCESS));
+
+      pNode->addProp(XML_ATTR_PROCESS, strName.str());
+    }
     else if (!strcmp(sbNewType.str(), XML_TAG_CLUSTER))
     {
       pNode->addProp(XML_ATTR_NAME, "");
@@ -5031,22 +5041,40 @@ bool CWsDeployFileInfo::handleTopology(IEspContext &context, IEspHandleTopologyR
   }
   else if (!strcmp(operation, "Delete"))
   {
-    String sParent(buf.str());
-    StringBuffer sbParent(XML_TAG_SOFTWARE"/"XML_TAG_TOPOLOGY);
-    int idx = sParent.lastIndexOf('/');
-
-    if (idx > 0)
+    if (!strcmp(compType, XML_TAG_THORCLUSTER))
     {
-      String* tmpstr = sParent.substring(0, idx);
-      sbParent.clear().append(*tmpstr);
-      delete tmpstr;
+        StringBuffer xpath("./"XML_TAG_THORCLUSTER);
+        xpath.appendf("[%s=\"%s\"]", XML_ATTR_PROCESS, name);
+
+        IPropertyTree *pParent = pEnvRoot->queryPropTree(subPath.str());
+
+        if (pParent)
+        {
+            IPropertyTree* pDel = pParent->queryPropTree(xpath.str());
+
+            if (pDel)
+              pParent->removeTree(pDel);
+        }
     }
+    else
+    {
+        String sParent(buf.str());
+        StringBuffer sbParent(XML_TAG_SOFTWARE"/"XML_TAG_TOPOLOGY);
+        int idx = sParent.lastIndexOf('/');
 
-    IPropertyTree* pTopology = pEnvRoot->queryPropTree(sbParent);
-    IPropertyTree* pDel = pEnvRoot->queryPropTree(buf.str());
-    
-    if (pTopology && pDel)
-      pTopology->removeTree(pDel);
+        if (idx > 0)
+        {
+          String* tmpstr = sParent.substring(0, idx);
+          sbParent.clear().append(*tmpstr);
+          delete tmpstr;
+        }
+
+        IPropertyTree* pTopology = pEnvRoot->queryPropTree(sbParent);
+        IPropertyTree* pDel = pEnvRoot->queryPropTree(buf.str());
+
+        if (pTopology && pDel)
+          pTopology->removeTree(pDel);
+    }
     resp.setStatus("true");
   }