BuildSet.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jptree.hpp"
  14. #include "XMLTags.h"
  15. #include "BuildSet.hpp"
  16. #include "SchemaCommon.hpp"
  17. using namespace CONFIGURATOR;
  18. #define LOOP_THRU_BUILD_SET int len = m_buildSetArray.length(); for (int idx = 0; idx < len; idx++)
  19. static CBuildSetManager *s_pBuildSetManager = nullptr;
  20. CBuildSetManager* CBuildSetManager::getInstance(const char* pBuildSetFile, const char* pBuildSetDirectory)
  21. {
  22. if (s_pBuildSetManager == nullptr)
  23. {
  24. s_pBuildSetManager = new CBuildSetManager();
  25. s_pBuildSetManager->m_buildSetFile.set(pBuildSetFile != nullptr ? pBuildSetFile : DEFAULT_BUILD_SET_XML_FILE);
  26. s_pBuildSetManager->m_buildSetDir.set(pBuildSetDirectory != nullptr ? pBuildSetDirectory : DEFAULT_BUILD_SET_DIRECTORY);
  27. pBuildSetFile = s_pBuildSetManager->m_buildSetFile;
  28. pBuildSetDirectory = s_pBuildSetManager->m_buildSetDir;
  29. s_pBuildSetManager->m_buildSetPath.setf("%s%s%s", pBuildSetDirectory, pBuildSetDirectory[strlen(pBuildSetDirectory)-1] == '/' ? "" : "/", pBuildSetFile);
  30. if (s_pBuildSetManager->populateBuildSet() == false)
  31. {
  32. delete s_pBuildSetManager;
  33. s_pBuildSetManager = nullptr;
  34. }
  35. }
  36. return s_pBuildSetManager;
  37. }
  38. CBuildSetManager::CBuildSetManager(const char* pBuildSetFile, const char* pBuildSetDir) : m_buildSetFile(pBuildSetFile), m_buildSetDir(pBuildSetDir)
  39. {
  40. if (pBuildSetFile != nullptr && pBuildSetDir != nullptr)
  41. m_buildSetPath.clear().appendf("%s%s%s", pBuildSetDir, pBuildSetDir[strlen(pBuildSetDir)-1] == '/' ? "" : "/", pBuildSetFile);
  42. }
  43. CBuildSetManager::CBuildSetManager()
  44. {
  45. }
  46. CBuildSetManager::~CBuildSetManager()
  47. {
  48. m_buildSetArray.kill();
  49. }
  50. void CBuildSetManager::getBuildSetComponents(StringArray& buildSetArray) const
  51. {
  52. int nLength = this->getBuildSetComponentCount();
  53. for (int idx = 0; idx < nLength; idx++)
  54. {
  55. buildSetArray.append(this->getBuildSetComponentTypeName(idx));
  56. }
  57. }
  58. void CBuildSetManager::getBuildSetServices(StringArray& buildSetArray) const
  59. {
  60. int nLength = this->getBuildSetServiceCount();
  61. for (int idx = 0; idx < nLength; idx++)
  62. {
  63. buildSetArray.append(this->getBuildSetServiceName(idx));
  64. }
  65. }
  66. const char* CBuildSetManager::getBuildSetServiceName(int index) const
  67. {
  68. if (index >= getBuildSetServiceCount())
  69. return nullptr;
  70. return this->getBuildSetService(index)->getName();
  71. }
  72. const char* CBuildSetManager::getBuildSetServiceFileName(int index) const
  73. {
  74. if (index >= getBuildSetServiceCount())
  75. return nullptr;
  76. return this->getBuildSetService(index)->getSchema();
  77. }
  78. const char* CBuildSetManager::getBuildSetComponentTypeName(int index) const
  79. {
  80. if (index >= this->getBuildSetComponentCount())
  81. return nullptr;
  82. return this->getBuildSetComponent(index)->getName();
  83. }
  84. const char* CBuildSetManager::getBuildSetComponentFileName(int index) const
  85. {
  86. if (index >= this->getBuildSetComponentCount())
  87. return nullptr;
  88. return this->getBuildSetComponent(index)->getSchema();
  89. }
  90. const char* CBuildSetManager::getBuildSetProcessName(int index) const
  91. {
  92. if (index >= this->getBuildSetComponentCount())
  93. return nullptr;
  94. return this->getBuildSetComponent(index)->getProcessName();
  95. }
  96. bool CBuildSetManager::populateBuildSet()
  97. {
  98. StringBuffer xpath;
  99. if (m_buildSetTree.get() != nullptr)
  100. return false;
  101. try
  102. {
  103. m_buildSetTree.set(createPTreeFromXMLFile(m_buildSetPath.str()));
  104. }
  105. catch(...)
  106. {
  107. return false;
  108. }
  109. xpath.setf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
  110. Owned<IPropertyTreeIterator> iter = m_buildSetTree->getElements(xpath.str());
  111. ForEach(*iter)
  112. {
  113. IPropertyTree* pTree = &iter->query();
  114. if ( pTree->queryProp(XML_ATTR_PROCESS_NAME) == nullptr || pTree->queryProp(XML_ATTR_OVERRIDE) != nullptr || ( (pTree->queryProp(XML_ATTR_DEPLOYABLE) != nullptr && \
  115. stricmp(pTree->queryProp(XML_ATTR_DEPLOYABLE), "no") == 0 && stricmp(pTree->queryProp(XML_ATTR_PROCESS_NAME), XML_TAG_ESPSERVICE) != 0) ) )
  116. continue;
  117. Owned<CBuildSet> pBuildSet = new CBuildSet(pTree->queryProp(XML_ATTR_INSTALLSET), pTree->queryProp(XML_ATTR_NAME), pTree->queryProp(XML_ATTR_PROCESS_NAME),\
  118. pTree->queryProp(XML_ATTR_SCHEMA), pTree->queryProp(XML_ATTR_DEPLOYABLE), pTree->queryProp(XML_ATTR_OVERRIDE));
  119. m_buildSetArray.append(*pBuildSet.getLink());
  120. }
  121. return true;
  122. }
  123. void CBuildSetManager::setBuildSetArray(const StringArray &strArray)
  124. {
  125. m_buildSetArray.kill();
  126. for (int idx = 0; idx < strArray.length(); idx++)
  127. {
  128. Owned<CBuildSet> pBSet = new CBuildSet(nullptr, strArray.item(idx), nullptr, strArray.item(idx));
  129. assert (pBSet != nullptr);
  130. m_buildSetArray.append(*pBSet.getClear());
  131. }
  132. }
  133. const char* CBuildSetManager::getBuildSetSchema(int index) const
  134. {
  135. assert(index < m_buildSetArray.length());
  136. if (index < m_buildSetArray.length())
  137. return m_buildSetArray.item(index).getSchema();
  138. else
  139. return nullptr;
  140. }
  141. const int CBuildSetManager::getBuildSetSchemaCount() const
  142. {
  143. return m_buildSetArray.length();
  144. }
  145. const int CBuildSetManager::getBuildSetServiceCount() const
  146. {
  147. int nCount = 0;
  148. LOOP_THRU_BUILD_SET
  149. {
  150. if (m_buildSetArray.item(idx).getProcessName() != nullptr && strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) == 0 && \
  151. (m_buildSetArray.item(idx).getDeployable() != nullptr && stricmp(m_buildSetArray.item(idx).getDeployable(), "no") == 0))
  152. nCount++;
  153. }
  154. return nCount;
  155. }
  156. const int CBuildSetManager::getBuildSetComponentCount() const
  157. {
  158. int nCount = 0;
  159. LOOP_THRU_BUILD_SET
  160. {
  161. if ( ((m_buildSetArray.item(idx).getProcessName() == nullptr) || (strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) != 0)) && \
  162. ( (m_buildSetArray.item(idx).getDeployable() == nullptr) || (stricmp(m_buildSetArray.item(idx).getDeployable(), "no") != 0) ) && \
  163. ( (m_buildSetArray.item(idx).getOverride() == nullptr) || (stricmp(m_buildSetArray.item(idx).getOverride(), "no") != 0) ) )
  164. nCount++;
  165. }
  166. return nCount;
  167. }
  168. const CBuildSet* CBuildSetManager::getBuildSetComponent(int index) const
  169. {
  170. LOOP_THRU_BUILD_SET
  171. {
  172. if (index == 0)
  173. {
  174. if ( ((m_buildSetArray.item(idx).getProcessName() == nullptr) || (strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) != 0)) && \
  175. ( (m_buildSetArray.item(idx).getDeployable() == nullptr) || (stricmp(m_buildSetArray.item(idx).getDeployable(), "no") != 0) ) && \
  176. ( (m_buildSetArray.item(idx).getOverride() == nullptr) || (stricmp(m_buildSetArray.item(idx).getOverride(), "no") != 0) ) )
  177. return &(m_buildSetArray.item(idx));
  178. else
  179. continue;
  180. }
  181. if ( ((m_buildSetArray.item(idx).getProcessName() == nullptr) || (strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) != 0)) && \
  182. ( (m_buildSetArray.item(idx).getDeployable() == nullptr)|| (stricmp(m_buildSetArray.item(idx).getDeployable(), "no") != 0) ) && \
  183. ( (m_buildSetArray.item(idx).getOverride() == nullptr) || (stricmp(m_buildSetArray.item(idx).getOverride(), "no") != 0) ) )
  184. index--;
  185. }
  186. assert(!"index invalid");
  187. return nullptr;
  188. }
  189. const CBuildSet* CBuildSetManager::getBuildSetService(int index) const
  190. {
  191. LOOP_THRU_BUILD_SET
  192. {
  193. if (index == 0)
  194. {
  195. if (m_buildSetArray.item(idx).getProcessName() != nullptr && strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) == 0 && \
  196. (m_buildSetArray.item(idx).getDeployable() != nullptr && stricmp(m_buildSetArray.item(idx).getDeployable(), "no") == 0))
  197. return &(m_buildSetArray.item(idx));
  198. else
  199. continue;
  200. }
  201. if (m_buildSetArray.item(idx).getProcessName() != nullptr && strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) == 0 && \
  202. (m_buildSetArray.item(idx).getDeployable() != nullptr && stricmp(m_buildSetArray.item(idx).getDeployable(), "no") == 0))
  203. index--;
  204. }
  205. assert(!"index invalid");
  206. return nullptr;
  207. }