瀏覽代碼

Merge pull request #4981 from garonsky/HPCC-10124_config_buildset_update

HPCC-10124 ConfigMgr - Add new components and services from buildset

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 年之前
父節點
當前提交
f04b2e7276

+ 1 - 0
deployment/deployutils/CMakeLists.txt

@@ -30,6 +30,7 @@ set (    SRCS
          configenvhelper.cpp
          wizardInputs.cpp 
          deployutils.cpp 
+         confighelper.cpp
     )
 
 include_directories ( 

+ 3 - 2
deployment/deployutils/configenvhelper.cpp

@@ -20,6 +20,7 @@
 #include "configenvhelper.hpp"
 #include "deployutils.hpp"
 #include "build-config.h"
+#include "confighelper.hpp"
 
 bool CConfigEnvHelper::handleRoxieOperation(const char* cmd, const char* xmlStr)
 {
@@ -708,12 +709,12 @@ void CConfigEnvHelper::addComponent(const char* pszBuildSet, StringBuffer& sbNew
     // NOTE - we are assuming buildSet is unique in a build.
     StringBuffer xPath, value;
     xPath.appendf("./Programs/Build/BuildSet[@name=\"%s\"]", pszBuildSet);
-    Owned<IPropertyTreeIterator> buildSet = m_pRoot->getElements(xPath.str());
+    Owned<IPropertyTreeIterator> buildSet = CConfigHelper::getInstance()->getBuildSetTree()->getElements(xPath.str());
     buildSet->first();
     IPropertyTree* pBuildSet = &buildSet->query();
     const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
     const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
-    const char* buildName = m_pRoot->queryPropTree("./Programs/Build[1]")->queryProp(XML_ATTR_NAME);
+    const char* buildName = CConfigHelper::getInstance()->getBuildSetTree()->queryPropTree("./Programs/Build[1]")->queryProp(XML_ATTR_NAME);
     if (!processName) //support non-generic components as well
       processName = buildSetName;
 

+ 127 - 0
deployment/deployutils/confighelper.cpp

@@ -0,0 +1,127 @@
+#include "confighelper.hpp"
+#include "XMLTags.h"
+#include "jlib.hpp"
+#include "jprop.hpp"
+#include "jptree.hpp"
+#include "build-config.h"
+
+#define STANDARD_CONFIG_BUILDSETFILE "buildset.xml"
+#define STANDARD_CONFIG_CONFIGXML_DIR "/componentfiles/configxml/"
+
+CConfigHelper::CConfigHelper() : m_pDefBldSet(NULL)
+{
+}
+
+CConfigHelper::~CConfigHelper()
+{
+}
+
+CConfigHelper* CConfigHelper::getInstance(const IPropertyTree *cfg, const char* esp_name)
+{
+  static CConfigHelper *pConfigHelper = NULL;
+
+  if (pConfigHelper != NULL)
+  {
+      return pConfigHelper;
+  }
+
+  if (cfg == NULL || esp_name == NULL)
+  {
+      return NULL;
+  }
+
+  pConfigHelper = new CConfigHelper();
+
+  StringBuffer xpath;
+
+  xpath.setf("%s/%s/%s[%s='%s']/%s",XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, esp_name, XML_TAG_LOCALCONFFILE);
+  pConfigHelper->m_strConfFile = cfg->queryProp(xpath.str());
+
+  xpath.clear().appendf("%s/%s/%s[%s='%s']/%s",XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, esp_name, XML_TAG_LOCALENVCONFFILE);
+  pConfigHelper->m_strEnvConfFile = cfg->queryProp(xpath.str());
+
+  if (pConfigHelper->m_strConfFile.length() > 0 && pConfigHelper->m_strEnvConfFile.length() > 0)
+  {
+    Owned<IProperties> pParams = createProperties(pConfigHelper->m_strConfFile);
+    Owned<IProperties> pEnvParams = createProperties(pConfigHelper->m_strEnvConfFile);
+
+    pConfigHelper->m_strConfigXMLDir = pEnvParams->queryProp(TAG_PATH);
+
+    if ( pConfigHelper->m_strConfigXMLDir.length() == 0)
+    {
+      pConfigHelper->m_strConfigXMLDir = INSTALL_DIR;
+    }
+
+    pConfigHelper->m_strBuildSetFileName = pParams->queryProp(TAG_BUILDSET);
+
+    pConfigHelper->m_strBuildSetFilePath.append(pConfigHelper->m_strConfigXMLDir).append(STANDARD_CONFIG_CONFIGXML_DIR).append( pConfigHelper->m_strBuildSetFileName.length() > 0 ? pConfigHelper->m_strBuildSetFileName : STANDARD_CONFIG_BUILDSETFILE);
+    pConfigHelper->m_pDefBldSet.set(createPTreeFromXMLFile(pConfigHelper->m_strBuildSetFilePath.str()));
+  }
+
+  return pConfigHelper;
+}
+
+bool CConfigHelper::isInBuildSet(const char* comp_process_name, const char* comp_name) const
+{
+  StringBuffer xpath;
+
+  xpath.appendf("./%s/%s/%s[%s=\"%s\"][%s=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_ATTR_PROCESS_NAME, comp_process_name, XML_ATTR_NAME, comp_name);
+
+  if (strcmp(XML_TAG_DIRECTORIES,comp_name) != 0 && m_pDefBldSet->hasProp(xpath.str()) == false)
+  {
+     return false;
+  }
+  else
+  {
+     return true;
+  }
+}
+
+void CConfigHelper::getNewComponentListFromBuildSet(const IPropertyTree *pEnvTree, StringArray &sCompArray) const
+{
+    if (pEnvTree == NULL || m_pDefBldSet == NULL)
+        return;
+
+    StringBuffer xpathBuildSetFile;
+    xpathBuildSetFile.appendf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
+
+    Owned<IPropertyTreeIterator> iter = m_pDefBldSet->getElements(xpathBuildSetFile.str());
+
+    ForEach(*iter)
+    {
+        StringBuffer xpath;
+        IPropertyTree* pSetting = &iter->query();
+        StringBuffer strBuildSetName(pSetting->queryProp(XML_ATTR_NAME));
+
+        xpath.appendf("%s/%s/%s[%s=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_ATTR_NAME, strBuildSetName.str());
+
+        if (pEnvTree->hasProp(xpath.str()) == false)
+        {
+            sCompArray.append(strBuildSetName.str());
+        }
+    }
+}
+
+void CConfigHelper::addNewComponentsFromBuildSetToEnv(IPropertyTree *pEnvTree)
+{
+    if (pEnvTree == NULL)
+        return;
+
+    StringArray sCompArray;
+
+    getNewComponentListFromBuildSet(pEnvTree, sCompArray);
+
+    if (sCompArray.length() == 0)
+        return;
+
+    for (int idx = 0; idx < sCompArray.length(); idx++)
+    {
+        StringBuffer xpath;
+        xpath.appendf("%s/%s/%s[%s=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_ATTR_NAME, (sCompArray.item(idx)));
+
+        if (pEnvTree->hasProp(xpath.str()) == true)
+            continue;
+
+        pEnvTree->queryPropTree(XML_TAG_PROGRAMS"/"XML_TAG_BUILD)->addPropTree(XML_TAG_BUILDSET, createPTreeFromIPT(m_pDefBldSet->queryPropTree(xpath.str())));
+    }
+}

+ 52 - 0
deployment/deployutils/confighelper.hpp

@@ -0,0 +1,52 @@
+#include "deployutils.hpp"
+
+class CConfigHelper
+{
+public:
+
+  virtual ~CConfigHelper();
+
+  static CConfigHelper* getInstance(const IPropertyTree *cfg = NULL, const char* esp_name = NULL);
+
+  bool isInBuildSet(const char* comp_process_name, const char* comp_name) const;
+
+  const char* getConfigXMLDir() const
+  {
+    return m_strConfigXMLDir.toCharArray();
+  }
+  const char* getBuildSetFileName() const
+  {
+    return m_strBuildSetFileName.toCharArray();
+  }
+  const char* getEnvConfFile() const
+  {
+    return m_strEnvConfFile.toCharArray();
+  }
+  const char* getConfFile() const
+  {
+    return m_strConfFile.toCharArray();
+  }
+  const char* getBuildSetFilePath() const
+  {
+    return m_strBuildSetFilePath.toCharArray();
+  }
+
+  const IPropertyTree* getBuildSetTree() const
+  {
+      return m_pDefBldSet;
+  }
+
+  void getNewComponentListFromBuildSet(const IPropertyTree *pEnvTree, StringArray &sCompArray) const;
+  void addNewComponentsFromBuildSetToEnv(IPropertyTree *pEnvTree);
+
+protected:
+
+  CConfigHelper();
+
+  Owned<IPropertyTree> m_pDefBldSet;
+  StringBuffer  m_strConfigXMLDir;
+  StringBuffer  m_strBuildSetFileName;
+  StringBuffer  m_strEnvConfFile;
+  StringBuffer  m_strConfFile;
+  StringBuffer  m_strBuildSetFilePath;
+};

+ 4 - 2
deployment/deployutils/deployutils.cpp

@@ -27,6 +27,7 @@
 #include "jwrapper.hpp"
 #include "wizardInputs.hpp"
 #include "build-config.h"
+#include "confighelper.hpp"
 
 #define TRACE_SCHEMA_NODE(msg, schemaNode)
 
@@ -218,7 +219,8 @@ void getInstalledComponents(const char* pszInstallDir, StringBuffer& sbOutComps,
   }
   else
   {
-    Owned<IPropertyTreeIterator> iter = pEnv->getElements("Programs/Build[1]/*");
+    Owned<IPropertyTreeIterator> iter = CConfigHelper::getInstance() != NULL ? CConfigHelper::getInstance()->getBuildSetTree()->getElements("Programs/Build[1]/*") : pEnv->getElements("Programs/Build[1]/*");
+
     ForEach(*iter)
     {
       IPropertyTree* pBuildSet = &iter->query();
@@ -239,7 +241,7 @@ void getInstalledComponents(const char* pszInstallDir, StringBuffer& sbOutComps,
       }
       else 
       { 
-        if (!szName && !*szName)
+        if (!szName || !*szName)
           continue;
 
         const char* szOveride = pBuildSet->queryProp("@overide");

+ 11 - 74
esp/services/WsDeploy/WsDeployService.cpp

@@ -23,6 +23,7 @@
 #include "daclient.hpp"
 #include "dadfs.hpp"
 #include "jencrypt.hpp"
+#include "confighelper.hpp"
 
 #ifdef _WINDOWS
 #include <winsock2.h>
@@ -31,8 +32,6 @@
 
 #define STANDARD_CONFIG_BACKUPDIR CONFIG_DIR"/backup"
 #define STANDARD_CONFIG_SOURCEDIR CONFIG_DIR
-#define STANDARD_CONFIG_BUILDSETFILE "buildset.xml"
-#define STANDARD_CONFIG_CONFIGXML_DIR "/componentfiles/configxml/"
 #define STANDARD_CONFIG_STAGED_PATH "/etc/HPCCSystems/environment.xml"
 
 #define DEFAULT_DIRECTORIES "<Directories name=\""DIR_NAME"\">\
@@ -196,58 +195,6 @@ void expandRange(IPropertyTree* pComputers)
   }
 }
 
-CConfigHelper::CConfigHelper()
-{
-}
-
-CConfigHelper::~CConfigHelper()
-{
-}
-
-void CConfigHelper::init(const IPropertyTree *cfg, const char* esp_name)
-{
-  StringBuffer xpath;
-
-  xpath.clear().appendf("%s/%s/%s[%s='%s']/%s",XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, esp_name, XML_TAG_LOCALCONFFILE);
-  m_strConfFile = cfg->queryProp(xpath.str());
-
-  xpath.clear().appendf("%s/%s/%s[%s='%s']/%s",XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, esp_name, XML_TAG_LOCALENVCONFFILE);
-  m_strEnvConfFile = cfg->queryProp(xpath.str());
-
-  if (m_strConfFile.length() > 0 && m_strEnvConfFile.length() > 0)
-  {
-    Owned<IProperties> pParams = createProperties(m_strConfFile);
-    Owned<IProperties> pEnvParams = createProperties(m_strEnvConfFile);
-
-    m_strConfigXMLDir = pEnvParams->queryProp(TAG_PATH);
-
-    if ( m_strConfigXMLDir.length() == 0)
-    {
-      m_strConfigXMLDir = INSTALL_DIR;
-    }
-
-    m_strBuildSetFileName = pParams->queryProp(TAG_BUILDSET);
-
-    m_strBuildSetFilePath.append(m_strConfigXMLDir).append(STANDARD_CONFIG_CONFIGXML_DIR).append( m_strBuildSetFileName.length() > 0 ? m_strBuildSetFileName : STANDARD_CONFIG_BUILDSETFILE);
-    m_pDefBldSet.set(createPTreeFromXMLFile(m_strBuildSetFilePath.str()));
-  }
-}
-
-bool CConfigHelper::isInBuildSet(const char* comp_process_name, const char* comp_name) const
-{
-  StringBuffer xpath;
-
-  xpath.appendf("./%s/%s/%s[%s=\"%s\"][%s=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_ATTR_PROCESS_NAME, comp_process_name, XML_ATTR_NAME, comp_name);
-
-  if (strcmp(XML_TAG_DIRECTORIES,comp_name) != 0 && m_pDefBldSet->queryPropTree(xpath.str()) == NULL)
-  {
-     return false;
-  }
-  else
-  {
-     return true;
-  }
-}
 
 CWsDeployExCE::~CWsDeployExCE()
 {
@@ -298,12 +245,12 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
   if (m_service.length() == 0)
     m_service.append(service);
 
+  CConfigHelper::getInstance(cfg, service);
+
   m_bCloud = false;
   StringBuffer xpath;
   m_envFile.clear();
 
-  m_configHelper.init(cfg,service);
-
   xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalEnvConfFile", service);
   const char* tmp = cfg->queryProp(xpath.str());
   if (tmp && *tmp)
@@ -2989,11 +2936,14 @@ bool CWsDeployFileInfo::displaySettings(IEspContext &context, IEspDisplaySetting
       const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
       const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
 
-      if ( m_pService->m_configHelper.isInBuildSet(pszCompType,buildSetName) == false )
+      if ( CConfigHelper::getInstance()->isInBuildSet(pszCompType,buildSetName) == false )
       {
         throw MakeStringException(-1, "Component '%s' named '%s' not in build set. Component may be incompatible with the current version.", pszCompType, pszCompName);
       }
 
+      StringArray sNewCompArray;
+      CConfigHelper::getInstance()->getNewComponentListFromBuildSet(pEnvRoot, sNewCompArray);
+
       StringBuffer buildSetPath;
       Owned<IPropertyTree> pSchema = loadSchema(pEnvRoot->queryPropTree("./Programs/Build[1]"), pBuildSet, buildSetPath, m_Environment);
 
@@ -4100,16 +4050,16 @@ bool CWsDeployFileInfo::handleComponent(IEspContext &context, IEspHandleComponen
 
       StringBuffer xpath;
       xpath.appendf("./Programs/Build/BuildSet[@name=\"%s\"]", buildSet);
-      Owned<IPropertyTreeIterator> buildSetIter = pEnvRoot->getElements(xpath.str());
+      Owned<IPropertyTreeIterator> buildSetIter = CConfigHelper::getInstance()->getBuildSetTree()->getElements(xpath.str());
       buildSetIter->first();
       IPropertyTree* pBuildSet = &buildSetIter->query();
       const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
       const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
 
       StringBuffer buildSetPath;
-      Owned<IPropertyTree> pSchema = loadSchema(pEnvRoot->queryPropTree("./Programs/Build[1]"), pBuildSet, buildSetPath, m_Environment);
+      Owned<IPropertyTree> pSchema = loadSchema(CConfigHelper::getInstance()->getBuildSetTree()->queryPropTree("./Programs/Build[1]"), pBuildSet, buildSetPath, m_Environment);
       xpath.clear().appendf("./Software/%s[@name='%s']", processName, buildSetName);
-      IPropertyTree* pCompTree = generateTreeFromXsd(pEnvRoot, pSchema, processName, buildSetName, m_pService->getCfg(), m_pService->getName(), false);
+      IPropertyTree* pCompTree = generateTreeFromXsd(CConfigHelper::getInstance()->getBuildSetTree(), pSchema, processName, buildSetName, m_pService->getCfg(), m_pService->getName(), false);
 
       if (processName != NULL && strcmp(processName, XML_TAG_ROXIECLUSTER) == 0 && pCompTree->queryPropTree(XML_TAG_ROXIE_SERVER) != NULL)
         pCompTree->removeTree(pCompTree->queryPropTree(XML_TAG_ROXIE_SERVER));
@@ -4120,6 +4070,7 @@ bool CWsDeployFileInfo::handleComponent(IEspContext &context, IEspHandleComponen
         pCompTree->removeTree(pInstTree);
 
       addComponentToEnv(pEnvRoot, buildSet, sbNewName, pCompTree);
+      CConfigHelper::getInstance()->addNewComponentsFromBuildSetToEnv(pEnvRoot);
     }
 
     resp.setCompName(sbNewName.str());
@@ -6321,20 +6272,6 @@ void CWsDeployFileInfo::initFileInfo(bool createOrOverwrite, bool bClearEnv)
     StringBuffer s("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Environment></Environment>");
     Owned<IPropertyTree> pNewTree = createPTreeFromXMLString(s);
 
-    if ( strlen(m_pService->m_configHelper.getBuildSetFilePath()) > 0 )
-    {
-        try
-        {
-          Owned<IPropertyTree> pDefBldSet = createPTreeFromXMLFile( m_pService->m_configHelper.getBuildSetFilePath() );
-          pNewTree->addPropTree(XML_TAG_PROGRAMS, createPTreeFromIPT(pDefBldSet->queryPropTree("./Programs")));
-          pNewTree->addPropTree(XML_TAG_SOFTWARE, createPTreeFromIPT(pDefBldSet->queryPropTree("./Software")));
-        }
-        catch(IException* e)
-        {
-          e->Release();
-        }
-    }
-
     if(!pNewTree->queryPropTree(XML_TAG_SOFTWARE))
     {
       pNewTree->addPropTree(XML_TAG_SOFTWARE, createPTree());

+ 0 - 43
esp/services/WsDeploy/WsDeployService.hpp

@@ -892,48 +892,6 @@ private:
     StringBuffer m_ip;
 };
 
-
-class CConfigHelper
-{
-public:
-
-  CConfigHelper();
-  virtual ~CConfigHelper();
-
-  void init(const IPropertyTree *cfg, const char* esp_name);
-
-  bool isInBuildSet(const char* comp_process_name, const char* comp_name) const;
-
-  const char* getConfigXMLDir() const
-  {
-    return m_strConfigXMLDir.toCharArray();
-  };
-  const char* getBuildSetFileName() const
-  {
-    return m_strBuildSetFileName.toCharArray();
-  };
-  const char* getEnvConfFile() const
-  {
-    return m_strEnvConfFile.toCharArray();
-  };
-  const char* getConfFile() const
-  {
-    return m_strConfFile.toCharArray();
-  };
-  const char* getBuildSetFilePath() const
-  {
-    return m_strBuildSetFilePath.toCharArray();
-  };
-
-protected:
-  Owned<IPropertyTree> m_pDefBldSet;
-  StringBuffer  m_strConfigXMLDir;
-  StringBuffer  m_strBuildSetFileName;
-  StringBuffer  m_strEnvConfFile;
-  StringBuffer  m_strConfFile;
-  StringBuffer  m_strBuildSetFilePath;
-};
-
 class CWsDeployExCE : public CWsDeploy
 {
 public:
@@ -991,7 +949,6 @@ public:
     const char* getBackupDir() { return m_backupDir.str(); }
     const char* getProcessName() { return m_process.str(); }
     const char* getSourceDir() { return m_sourceDir.str(); }
-    CConfigHelper m_configHelper;
 
 private:
   virtual void getWizOptions(StringBuffer& sb);