SWEspProcess.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 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 "SWEspProcess.hpp"
  14. #include "SWEspService.hpp"
  15. #include "deployutils.hpp"
  16. namespace ech
  17. {
  18. SWEspProcess::SWEspProcess(const char* name, EnvHelper * envHelper):SWProcess(name, envHelper)
  19. {
  20. }
  21. IPropertyTree * SWEspProcess::addComponent(IPropertyTree *params)
  22. {
  23. IPropertyTree * pCompTree;
  24. IPropertyTree * envTree = m_envHelper->getEnvTree();
  25. const char* clone = params->queryProp("@clone");
  26. if (clone)
  27. {
  28. pCompTree = SWComponentBase::cloneComponent(params);
  29. }
  30. else
  31. {
  32. pCompTree = SWComponentBase::addComponent(params);
  33. if (pCompTree->hasProp("@daliServers") && !strcmp(pCompTree->queryProp("@daliServers"), ""))
  34. {
  35. StringBuffer xpath;
  36. xpath.clear().appendf(XML_TAG_SOFTWARE "/DaliServerProcess/@name");
  37. const char *daliName = envTree->queryProp(xpath.str());
  38. if (daliName)
  39. {
  40. pCompTree->setProp("@daliServers", daliName);
  41. }
  42. }
  43. }
  44. removeInstancesFromComponent(pCompTree);
  45. IPropertyTree* pAttrs = params->queryPropTree("Attributes");
  46. if (pAttrs)
  47. {
  48. // The default is to bind all Esp Services
  49. // If "bindings" attribute set to "skip" user need to use "EspBinding" selector
  50. // to add bindings
  51. const char * bindings = pAttrs->queryProp("Attribute[@name='bindings']/@value");
  52. if (bindings && !stricmp(bindings, "skip"))
  53. {
  54. return pCompTree;
  55. }
  56. }
  57. StringBuffer xpath;
  58. xpath.clear().appendf(XML_TAG_SOFTWARE "/" XML_TAG_ESPSERVICE);
  59. Owned<IPropertyTreeIterator> espServiceIter = envTree->getElements(xpath.str());
  60. ForEach (*espServiceIter)
  61. {
  62. IPropertyTree* pEspService = &espServiceIter->query();
  63. if(pEspService)
  64. {
  65. const char* serviceName = pEspService->queryProp("@name");
  66. xpath.clear().appendf("<Attributes><Attribute name=\"name\" value=\"my%s\"/>", serviceName);
  67. xpath.appendf("<Attribute name=\"service\" value=\"%s\"/></Attributes>", serviceName);
  68. Owned<IPropertyTree> pBindingAttrs = createPTreeFromXMLString(xpath.str());
  69. addBinding(pCompTree, pBindingAttrs);
  70. }
  71. }
  72. return pCompTree;
  73. }
  74. void SWEspProcess::addOtherSelector(IPropertyTree *compTree, IPropertyTree *params)
  75. {
  76. const char* selector = params->queryProp("@selector");
  77. if (selector && !stricmp(selector, "EspBinding"))
  78. {
  79. IPropertyTree* pAttrs = params->queryPropTree("Attributes");
  80. if (!pAttrs)
  81. throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Miss binding attributes input");
  82. addBinding(compTree, pAttrs);
  83. }
  84. }
  85. void SWEspProcess::addBinding(IPropertyTree *parent, IPropertyTree * attrs)
  86. {
  87. StringBuffer xpath;
  88. xpath.clear().append("Attribute[@name='name']/@value");
  89. const char * bindingName = attrs->queryProp(xpath);
  90. if (!bindingName || !(*bindingName))
  91. throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Miss esp binding name in adding binding");
  92. xpath.clear().append("Attribute[@name='service']/@value");
  93. const char * serviceName = attrs->queryProp(xpath);
  94. if (!serviceName || !(*serviceName))
  95. throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Miss esp service name in adding binding");
  96. IPropertyTree * envTree = m_envHelper->getEnvTree();
  97. xpath.clear().appendf(XML_TAG_SOFTWARE "/" XML_TAG_ESPSERVICE "[@name=\"%s\"]", serviceName);
  98. IPropertyTree * pEspService = envTree->queryPropTree(xpath.str());
  99. if (!pEspService)
  100. {
  101. throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Can't find EspService with name %s.", serviceName);
  102. }
  103. IPropertyTree *pBinding = createPTree(XML_TAG_ESPBINDING);
  104. if (attrs)
  105. updateNode(pBinding, attrs, NULL);
  106. // check attributes
  107. if (!(pBinding->queryProp(XML_ATTR_PROTOCOL)))
  108. pBinding->addProp(XML_ATTR_PROTOCOL, "http");
  109. const char* protocol = pBinding->queryProp(XML_ATTR_PROTOCOL);
  110. if (!stricmp(protocol, "https"))
  111. xpath.clear().append("Properties/@defaultSecurePort");
  112. else
  113. xpath.clear().append("Properties/@defaultPort");
  114. const char* defaultPort = pEspService->queryProp(xpath.str());
  115. const char* port = pBinding->queryProp(XML_ATTR_PORT);
  116. if (!port || !(*port))
  117. {
  118. pBinding->addProp(XML_ATTR_PORT, defaultPort);
  119. }
  120. const char* defaultForPort = pBinding->queryProp("@defaultForPort");
  121. if (!stricmp(defaultPort, pBinding->queryProp(XML_ATTR_PORT)))
  122. {
  123. if (!defaultForPort || !(*defaultForPort) || !defaultForPort)
  124. pBinding->setProp("@defaultForPort", "true");
  125. }
  126. else
  127. {
  128. if (!defaultForPort || !(*defaultForPort) || defaultForPort)
  129. pBinding->setProp("@defaultForPort", "true");
  130. }
  131. if (!(pBinding->queryProp("@defaultServiceVersion")))
  132. pBinding->addProp("@defaultServiceVersion", "");
  133. if (!(pBinding->queryProp("@resourcesBasedn")))
  134. pBinding->addProp("@resourcesBasedn", pEspService->queryProp("Properties/@defaultResourcesBasedn"));
  135. if (!(pBinding->queryProp(XML_ATTR_TYPE)))
  136. pBinding->addProp(XML_ATTR_TYPE, "");
  137. if (!(pBinding->queryProp("@workunitsBasedn")))
  138. pBinding->addProp("@workunitsBasedn", "ou=workunits,ou=ecl");
  139. if (!(pBinding->queryProp("@wsdlServiceAddress")))
  140. pBinding->addProp("@wsdlServiceAddress", "");
  141. // Add AuthenticateFeature
  142. Owned<IPropertyTreeIterator> afIter = pEspService->getElements("Properties/AuthenticateFeature");
  143. ForEach (*afIter)
  144. {
  145. pBinding->addPropTree("AuthenticateFeature", m_envHelper->clonePTree(&afIter->query()));
  146. }
  147. // Add Authenticate
  148. Owned<IPropertyTreeIterator> authIter = pEspService->getElements("Properties/Authenticate");
  149. ForEach (*authIter)
  150. {
  151. pBinding->addPropTree("Authenticate", m_envHelper->clonePTree(&authIter->query()));
  152. }
  153. parent->addPropTree(XML_TAG_ESPBINDING, pBinding);
  154. }
  155. }