buildset.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 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. //disable the harmless warning about very long symbol names > 255 chars in debug mode
  14. //this is typical with STL
  15. #pragma warning( disable : 4786 )
  16. #include "jliball.hpp"
  17. #include "environment.hpp"
  18. #include "XMLTags.h"
  19. #include "buildset.hpp"
  20. #include "Constants.h"
  21. #include <set>
  22. #include <string>
  23. using std::set;
  24. using std::string;
  25. static set<string> s_failedConnections;
  26. //for getcwd
  27. #ifdef _WINDOWS
  28. #else
  29. #include <dirent.h>
  30. #include <unistd.h>
  31. #endif
  32. //---------------------------------------------------------------------------
  33. // getAccountInfo
  34. //---------------------------------------------------------------------------
  35. void getAccountInfo(const char* computer, StringAttr& user, StringAttr& pwd, IConstEnvironment* pConstEnv)
  36. {
  37. if (!pConstEnv)
  38. throw MakeStringException(-1, "No environment is available!");
  39. Owned<IConstMachineInfo> machine = pConstEnv->getMachine(computer);
  40. if (!machine)
  41. {
  42. StringBuffer sComputer(computer);
  43. StringBuffer sExtra;
  44. if (sExtra.length() == 0)
  45. machine.setown( pConstEnv->getMachineByAddress(computer) );
  46. if (!machine)
  47. throw MakeStringException(-1, "The computer '%s' is undefined!", computer);
  48. }
  49. Owned<IConstDomainInfo> domain = machine->getDomain();
  50. if (!domain)
  51. throw MakeStringException(-1, "The computer '%s' does not have any domain information!", computer);
  52. StringBuffer x;
  53. domain->getName(StringBufferAdaptor(x));
  54. if (x.length())
  55. x.append(PATHSEPCHAR);
  56. domain->getAccountInfo(StringBufferAdaptor(x), StringAttrAdaptor(pwd));
  57. user.set(x.str());
  58. }
  59. bool connectionRemoteMachine(const StringBuffer& sPath, IConstEnvironment* pConstEnv)
  60. {
  61. bool rc = true;
  62. if (sPath.length() > 2 && sPath[0] == '\\' && sPath[1] == '\\')
  63. {
  64. const char* spath = sPath.str();
  65. const char* cpos = strchr(spath + 2, '\\');
  66. int pos = cpos? cpos - spath : -1;
  67. if (pos != -1)
  68. {
  69. char szComp[128];
  70. strncpy(szComp, spath + 2, pos);
  71. StringBuffer computer(szComp);
  72. StringAttr userid;
  73. StringAttr pswd;
  74. try {
  75. //if computer is defined in hardware section then use its associated
  76. //login information, if any
  77. getAccountInfo(computer, userid, pswd, pConstEnv);
  78. } catch (...)
  79. {
  80. userid.clear();
  81. pswd.clear();
  82. }
  83. }
  84. }
  85. return rc;
  86. }
  87. // Various helper functions for managing build sets
  88. bool connectBuildSet(IPropertyTree* pBuild, IPropertyTree* pBuildSet, StringBuffer& buildSetPath, IConstEnvironment* pConstEnv)
  89. {
  90. bool rc = true;
  91. buildSetPath.clear();
  92. // Get InstallSet file name from BuildSet node
  93. const char* szVal = pBuild->queryProp(XML_ATTR_URL);
  94. if (szVal && *szVal)
  95. {
  96. buildSetPath = szVal;
  97. rc = connectionRemoteMachine(buildSetPath, pConstEnv);
  98. buildSetPath.append(PATHSEPCHAR);
  99. }
  100. //szVal = pBuildSet->queryProp(XML_ATTR_PATH);
  101. //if (szVal && *szVal)
  102. //buildSetPath.append(szVal).append(PATHSEPCHAR);
  103. buildSetPath.append("componentfiles").append(PATHSEPCHAR).append("configxml").append(PATHSEPCHAR);
  104. buildSetPath.replace('\\', PATHSEPCHAR);
  105. return rc;
  106. }
  107. IPropertyTree *loadInstallSet(IPropertyTree *pBuild, IPropertyTree *pBuildSet, IConstEnvironment* pConstEnv)
  108. {
  109. // Create fully qualified path to InstallSet file
  110. IPropertyTree* pInstallSet = NULL;
  111. StringBuffer sFilename;
  112. if (connectBuildSet(pBuild, pBuildSet, sFilename, pConstEnv))
  113. {
  114. // Get InstallSet file name from BuildSet node
  115. const char* szVal = pBuildSet->queryProp(XML_ATTR_INSTALLSET);
  116. if (szVal && *szVal)
  117. sFilename.append(szVal);
  118. else
  119. sFilename.append(DEFAULT_INSTALLSET);
  120. pInstallSet = createPTreeFromXMLFile(sFilename);
  121. }
  122. return pInstallSet;
  123. }
  124. IPropertyTree *loadSchema(IPropertyTree *pBuild, IPropertyTree *pBuildSet, StringBuffer& sSchemaPath, IConstEnvironment* pConstEnv)
  125. {
  126. IPropertyTree* pSchema = NULL;
  127. sSchemaPath.clear();
  128. try
  129. {
  130. if (pBuild && pBuildSet && connectBuildSet(pBuild, pBuildSet, sSchemaPath, pConstEnv))
  131. {
  132. const char *schemaName = pBuildSet->queryProp("@schema");
  133. if (schemaName && *schemaName)
  134. {
  135. sSchemaPath.append(schemaName);
  136. pSchema = createPTreeFromXMLFile(sSchemaPath);
  137. }
  138. else
  139. {
  140. const char *processName = pBuildSet->queryProp("@processName");
  141. if (processName && *processName)
  142. {
  143. char szXsdPath[_MAX_PATH+1];
  144. #ifdef _WINDOWS
  145. if (GetModuleFileName(NULL, szXsdPath, _MAX_PATH))
  146. {
  147. char* pchSlash = strrchr(szXsdPath, PATHSEPCHAR);
  148. #else
  149. if (getcwd(szXsdPath,_MAX_PATH))
  150. {
  151. char* pchSlash = szXsdPath + strlen(szXsdPath);
  152. strcat(pchSlash, PATHSEPSTR);
  153. #endif
  154. strcpy(pchSlash+1, "generic.xsd");
  155. sSchemaPath = szXsdPath;
  156. }
  157. pSchema = createPTreeFromXMLFile(sSchemaPath);
  158. if (pSchema)
  159. {
  160. IPropertyTree* pNode = pSchema->queryPropTree("xs:element");
  161. pNode->setProp("@name", processName);
  162. pNode = pNode->queryPropTree("xs:complexType/xs:sequence/xs:element/xs:complexType/xs:attribute[@name=\"directory\"]");
  163. if (pNode)
  164. {
  165. const char *name = pBuildSet->queryProp("@name");
  166. StringBuffer sPath("c$\\");
  167. if (name)
  168. sPath.append(name);
  169. pNode->setProp("@default", sPath);
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. catch(IException *E)
  177. {
  178. StringBuffer buf;
  179. (E->errorMessage(buf).str());
  180. E->Release();
  181. }
  182. catch(...)
  183. {
  184. }
  185. return pSchema;
  186. }
  187. IPropertyTree *loadDefaultSchema()
  188. {
  189. return createPTreeFromXMLString(
  190. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  191. "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">"
  192. " <xs:element name=\"ThorCluster\">"
  193. " <xs:complexType>"
  194. " <xs:attribute name=\"build\" type=\"xs:string\" use=\"required\">"
  195. " <xs:annotation><xs:appinfo>"
  196. " <tooltip>The build name to be deployed</tooltip>"
  197. " </xs:appinfo></xs:annotation>"
  198. " </xs:attribute>"
  199. " <xs:attribute name=\"buildSet\" type=\"seisint:buildSet\" use=\"required\">"
  200. " <xs:annotation><xs:appinfo>"
  201. " <viewType>hidden</viewType>"
  202. " </xs:appinfo></xs:annotation>"
  203. " </xs:attribute>"
  204. " <xs:attribute name=\"name\" type=\"xs:string\" use=\"required\">"
  205. " <xs:annotation><xs:appinfo>"
  206. " <tooltip>Name for this process</tooltip>"
  207. " </xs:appinfo></xs:annotation>"
  208. " </xs:attribute>"
  209. " <xs:attribute name=\"description\" type=\"xs:string\" use=\"optional\">"
  210. " <xs:annotation><xs:appinfo>"
  211. " <tooltip>Description for this process</tooltip>"
  212. " </xs:appinfo></xs:annotation>"
  213. " </xs:attribute>"
  214. " <xs:attribute name=\"daliServers\" type=\"seisint:daliServers\" use=\"optional\">"
  215. " <xs:annotation><xs:appinfo>"
  216. " <tooltip>Select the dali process to be used</tooltip>"
  217. " </xs:appinfo></xs:annotation>"
  218. " </xs:attribute>"
  219. " </xs:complexType>"
  220. " </xs:element>"
  221. "</xs:schema>"
  222. );
  223. }