Просмотр исходного кода

Merge pull request #6490 from RussWhitehead/configgen_504

HPCC-12327 Configgen should extract and write LDAPServer config

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 10 лет назад
Родитель
Сommit
d7f9895756
1 измененных файлов с 74 добавлено и 2 удалено
  1. 74 2
      deployment/configgen/main.cpp

+ 74 - 2
deployment/configgen/main.cpp

@@ -92,6 +92,7 @@ void usage()
   puts("          has more than one instance, it will be listed as two separate.");
   puts("          has more than one instance, it will be listed as two separate.");
   puts("          entries in the output");
   puts("          entries in the output");
   puts("          componentName,instanceip");
   puts("          componentName,instanceip");
+  puts("   -listldapservers: Lists out all LDAP Server components and associated tags");
   puts("   -machines: Lists out all names or ips of machines specified in the environment");
   puts("   -machines: Lists out all names or ips of machines specified in the environment");
   puts("          Output is written to stdout, one machine per line.");
   puts("          Output is written to stdout, one machine per line.");
   puts("   -validateonly: Validates the environment, without generating permanent ");
   puts("   -validateonly: Validates the environment, without generating permanent ");
@@ -251,7 +252,7 @@ int processRequest(const char* in_cfgname, const char* out_dirname, const char*
                    const char* out_filename, bool generateOutput, const char* ipAddr, 
                    const char* out_filename, bool generateOutput, const char* ipAddr, 
                    bool listComps, bool verbose, bool listallComps, bool listallCompsAllThors, bool listESPServices, bool listdirs,
                    bool listComps, bool verbose, bool listallComps, bool listallCompsAllThors, bool listESPServices, bool listdirs,
                    bool listdropzones, bool listcommondirs, bool listMachines, bool validateOnly,
                    bool listdropzones, bool listcommondirs, bool listMachines, bool validateOnly,
-                   bool listldaps, bool ldapconfig)
+                   bool listldaps, bool ldapconfig, bool ldapservers)
 {
 {
   Owned<IPropertyTree> pEnv = createPTreeFromXMLFile(in_cfgname);
   Owned<IPropertyTree> pEnv = createPTreeFromXMLFile(in_cfgname);
   short nodeIndex = 1;
   short nodeIndex = 1;
@@ -382,6 +383,71 @@ int processRequest(const char* in_cfgname, const char* out_dirname, const char*
       }
       }
     }
     }
   }
   }
+  else if (ldapservers)
+  {
+    //first, build a map of all ldapServer/IP
+    StringBuffer sb1,sb2;
+    typedef MapStringTo<StringBuffer> strMap;
+    strMap ldapServers;
+    {
+      xPath.appendf("Software/%s/", XML_TAG_LDAPSERVERPROCESS);
+      Owned<IPropertyTreeIterator> ldaps = pEnv->getElements(xPath.str());
+      ForEach(*ldaps)
+      {
+        IPropertyTree* ldap = &ldaps->query();
+        Owned<IPropertyTreeIterator> insts = ldap->getElements(XML_TAG_INSTANCE);
+        ForEach(*insts)
+        {
+          IPropertyTree* inst = &insts->query();
+          StringBuffer computerName(inst->queryProp(XML_ATTR_COMPUTER));
+          xPath.clear().appendf("Hardware/Computer[@name=\"%s\"]", computerName.str());
+          IPropertyTree* pComputer = pEnv->queryPropTree(xPath.str());
+          if (pComputer)
+          {
+            if (NULL == ldapServers.getValue(ldap->queryProp(XML_ATTR_NAME)))//only add once
+              ldapServers.setValue(ldap->queryProp(XML_ATTR_NAME), pComputer->queryProp("@netAddress"));
+          }
+        }
+      }
+    }
+
+    //Lookup and output all LDAPServer components
+    StringBuffer out;
+    xPath.clear().append(XML_TAG_SOFTWARE"/"XML_TAG_LDAPSERVERPROCESS);
+    Owned<IPropertyTreeIterator> ldaps = pEnv->getElements(xPath.str());
+
+    ForEach(*ldaps)
+    {
+      IPropertyTree* ldap = &ldaps->query();
+      out.appendf("%s\n",ldap->queryName());
+      Owned<IAttributeIterator> attrs = ldap->getAttributes();
+      ForEach(*attrs)
+      {
+        out.appendf("%s,%s\n", attrs->queryName(), attrs->queryValue());
+        //If this is ldap server name, lookup and add its IP address
+        if (0==strcmp(attrs->queryName(), "@name"))
+        {
+          StringBuffer sb(attrs->queryValue());
+          StringBuffer * ldapIP = ldapServers.getValue(sb);
+          if (ldapIP->str())
+          {
+            out.appendf("@ldapAddress,%s\n",ldapIP->str());
+            ldapServers.setValue(attrs->queryValue(), NULL);
+          }
+          else
+          {
+            out.clear();
+            break;
+          }
+        }
+      }
+      if (out.length())
+      {
+        fprintf(stdout, "%s", out.str());
+        out.clear();
+      }
+    }
+  }
   else if (!listComps && !listallComps && !listdirs && !listdropzones && !listcommondirs && !listMachines
   else if (!listComps && !listallComps && !listdirs && !listdropzones && !listcommondirs && !listMachines
            && !listldaps && !listESPServices)
            && !listldaps && !listESPServices)
   {
   {
@@ -666,6 +732,7 @@ int main(int argc, char** argv)
   bool ldapconfig = false;
   bool ldapconfig = false;
   bool listldaps = false;
   bool listldaps = false;
   bool listespservices = false;
   bool listespservices = false;
+  bool ldapservers = false;
 
 
   int i = 1;
   int i = 1;
   bool writeToFiles = false;
   bool writeToFiles = false;
@@ -764,6 +831,11 @@ int main(int argc, char** argv)
       i++;
       i++;
       listldaps = true;
       listldaps = true;
     }
     }
+    else if (stricmp(argv[i], "-listldapservers") == 0)
+    {
+      i++;
+      ldapservers = true;
+    }
     else if (stricmp(argv[i], "-machines") == 0)
     else if (stricmp(argv[i], "-machines") == 0)
     {
     {
       i++;
       i++;
@@ -804,7 +876,7 @@ int main(int argc, char** argv)
     processRequest(in_cfgname, out_dirname, in_dirname, compName, 
     processRequest(in_cfgname, out_dirname, in_dirname, compName, 
       compType,in_filename, out_filename, generateOutput, ipAddr.length() ? ipAddr.str(): NULL,
       compType,in_filename, out_filename, generateOutput, ipAddr.length() ? ipAddr.str(): NULL,
       listComps, verbose, listallComps, listallCompsAllThors, listespservices, listdirs, listdropzones, listcommondirs, listMachines,
       listComps, verbose, listallComps, listallCompsAllThors, listespservices, listdirs, listdropzones, listcommondirs, listMachines,
-      validateOnly, listldaps, ldapconfig);
+      validateOnly, listldaps, ldapconfig, ldapservers);
   }
   }
   catch(IException *excpt)
   catch(IException *excpt)
   {
   {