GenEnvRules.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "jiface.hpp"
  14. #include "jliball.hpp"
  15. #include "GenEnvRules.hpp"
  16. namespace ech
  17. {
  18. void GenEnvRules::loadFile(const char* filename)
  19. {
  20. rules.setown(createProperties(filename));
  21. if (rules == NULL)
  22. MakeStringException(-1, "Cannot load file %s", filename);
  23. const char* roxieRedTypes[] = {"Full", "Circular", "None", "Overloaded"};
  24. roxieAgentRedType.clear().append("Circular");
  25. roxieAgentRedChannels = 2;
  26. roxieAgentRedOffset = 1;
  27. //To do CConfigHelper::getInstance()->addPluginsToGenEnvRules(m_algProp.get());
  28. Owned<IPropertyIterator> iter = rules->getIterator();
  29. StringBuffer prop;
  30. ForEach(*iter)
  31. {
  32. rules->getProp(iter->getPropKey(), prop.clear());
  33. if (prop.length() && prop.charAt(prop.length()-1) == ',')
  34. prop.setCharAt((prop.length()-1),' ');
  35. if (!strcmp(iter->getPropKey(), "roxie_agent_redundancy"))
  36. {
  37. StringArray sbarr;
  38. sbarr.appendList(prop.str(), ",");
  39. if (sbarr.length() > 1)
  40. {
  41. int type = atoi(sbarr.item(0));
  42. if (type == 0)
  43. continue;
  44. if (type > 0 && type < 5)
  45. roxieAgentRedType.clear().append(roxieRedTypes[type-1]);
  46. else
  47. continue;
  48. roxieAgentRedChannels = atoi(sbarr.item(1));
  49. if (roxieAgentRedChannels <= 0)
  50. roxieAgentRedChannels = 1;
  51. if (sbarr.length() > 2)
  52. {
  53. roxieAgentRedOffset = atoi(sbarr.item(2));
  54. if (roxieAgentRedOffset <= 0)
  55. roxieAgentRedOffset = 1;
  56. }
  57. else
  58. roxieAgentRedOffset = 0;
  59. }
  60. }
  61. }
  62. }
  63. int GenEnvRules::getPropInt(const char* propname, int dft) const
  64. {
  65. StringBuffer prop;
  66. rules->getProp(propname, prop.clear());
  67. if (prop.length() > 0)
  68. return atoi(prop.str());
  69. return dft;
  70. }
  71. const char* GenEnvRules::getProp(const char* propname) const
  72. {
  73. return rules->queryProp(propname);
  74. }
  75. bool GenEnvRules::doNotGenTheCompOptional(const char* compname) const
  76. {
  77. if (foundInProp("do_not_gen_optional", compname) &&
  78. foundInProp("do_not_gen_optional", "all"))
  79. return true;
  80. return false;
  81. }
  82. bool GenEnvRules::foundInProp(const char* propname, const char* item, const char* sep) const
  83. {
  84. StringBuffer prop;
  85. rules->getProp(propname, prop.clear());
  86. if (prop.length() == 0)
  87. return false;
  88. StringArray propvalue;
  89. propvalue.appendList(prop.str(), sep);
  90. if (propvalue.find(item) != NotFound) return true;
  91. return false;
  92. }
  93. bool GenEnvRules::isValidServerCombo(const char* server1, const char* server2) const
  94. {
  95. StringBuffer s1, s2;
  96. s1.clear().appendf("%s-%s",server1, server2);
  97. s2.clear().appendf("%s-%s",server2, server1);
  98. const char * propname = "avoid_combo";
  99. if (!foundInProp(propname, s1.str()) && !foundInProp(propname, s2.str()))
  100. return true;
  101. return false;;
  102. }
  103. }