فهرست منبع

Merge pull request #686 from richardkchapman/eclagent-group-gh685

Fix gh-685 thorlib.group() gives internal error in eclagent
Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 13 سال پیش
والد
کامیت
65d5d40910
3فایلهای تغییر یافته به همراه67 افزوده شده و 28 حذف شده
  1. 23 25
      common/workunit/workunit.cpp
  2. 1 1
      common/workunit/workunit.hpp
  3. 43 2
      ecl/eclagent/eclagent.cpp

+ 23 - 25
common/workunit/workunit.cpp

@@ -4063,39 +4063,37 @@ const char *getTargetClusterComponentName(const char *clustname, const char *pro
     return name.str();
 }
 
-unsigned getEnvironmentThorClusterNames(StringArray &clusternames, StringArray &groupnames, StringArray &qnames)
+unsigned getEnvironmentThorClusterNames(StringArray &thorNames, StringArray &groupNames, StringArray &targetNames)
 {
     Owned<IRemoteConnection> conn = querySDS().connect("Environment", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
     if (!conn)
         return 0;
-    Owned<IPropertyTreeIterator> iter = conn->queryRoot()->getElements("Software/Topology/EclServerProcess/Cluster");
-    ForEach(*iter) {
-        IPropertyTree &tc = iter->query();
-        // I think we want the name here but it isn't exactly clear
-        const char *cname = tc.queryProp("@name");
-        if (cname&&*cname) {
-            Owned<IPropertyTreeIterator> iter2 = tc.getElements("ThorCluster");
-            ForEach(*iter2) {
-                IPropertyTree &tc2 = iter2->query();
-                StringBuffer query;
-                const char *pname = tc2.queryProp("@process");
-                query.appendf("Software/ThorCluster[@name=\"%s\"]",pname);
-                IPropertyTree *t = conn->queryRoot()->queryPropTree(query.str());
-                if (t) {
-                    const char *qname = t->queryProp("@queueName");
-                    if (!qname||!*qname)
-                        qname = pname;
-                    const char *gname = t->queryProp("@nodeGroup");
-                    if (!gname||!*gname)
-                        gname = pname;
-                    clusternames.append(cname);
-                    groupnames.append(gname);
-                    qnames.append(qname);
+    Owned<IPropertyTreeIterator> allTargets = conn->queryRoot()->getElements("Software/Topology/Cluster");
+    ForEach(*allTargets)
+    {
+        IPropertyTree &target = allTargets->query();
+        const char *targetName = target.queryProp("@name");
+        if (targetName && *targetName)
+        {
+            Owned<IPropertyTreeIterator> thorClusters = target.getElements("ThorCluster");
+            ForEach(*thorClusters)
+            {
+                const char *thorName = thorClusters->query().queryProp("@process");
+                VStringBuffer query("Software/ThorCluster[@name=\"%s\"]",thorName);
+                IPropertyTree *thorCluster = conn->queryRoot()->queryPropTree(query.str());
+                if (thorCluster)
+                {
+                    const char *groupName = thorCluster->queryProp("@nodeGroup");
+                    if (!groupName||!*groupName)
+                        groupName = thorName;
+                    thorNames.append(thorName);
+                    groupNames.append(groupName);
+                    targetNames.append(targetName);
                 }
             }
         }
     }
-    return clusternames.ordinality();
+    return thorNames.ordinality();
 }
 
 

+ 1 - 1
common/workunit/workunit.hpp

@@ -1132,7 +1132,7 @@ extern WORKUNIT_API bool getWorkUnitCreateTime(const char *wuid,CDateTime &time)
 extern WORKUNIT_API bool restoreWorkUnit(const char *base,const char *wuid);
 extern WORKUNIT_API void clientShutdownWorkUnit();
 extern WORKUNIT_API IExtendedWUInterface * queryExtendedWU(IWorkUnit * wu);
-extern WORKUNIT_API unsigned getEnvironmentThorClusterNames(StringArray &clusternames, StringArray &groupnames, StringArray &qnames);
+extern WORKUNIT_API unsigned getEnvironmentThorClusterNames(StringArray &thorNames, StringArray &groupNames, StringArray &targetNames);
 extern WORKUNIT_API StringBuffer &formatGraphTimerLabel(StringBuffer &str, const char *graphName, unsigned subGraphNum=0, unsigned __int64 subId=0);
 extern WORKUNIT_API bool parseGraphTimerLabel(const char *label, StringBuffer &graphName, unsigned &subGraphNum, unsigned __int64  &subId);
 extern WORKUNIT_API void addExceptionToWorkunit(IWorkUnit * wu, WUExceptionSeverity severity, const char * source, unsigned code, const char * text, const char * filename, unsigned lineno, unsigned column);

+ 43 - 2
ecl/eclagent/eclagent.cpp

@@ -2707,8 +2707,49 @@ char * EclAgent::getClusterName()
 
 char * EclAgent::getGroupName()
 {
-    // We don't know the name of the thor we will run on - can only tell the queue.
-    throwUnexpected();
+    StringBuffer groupName;
+    if (!isStandAloneExe)
+    {
+        const char * cluster = clusterNames.tos();
+        Owned<IConstWUClusterInfo> clusterInfo = getTargetClusterInfo(cluster);
+        if (!clusterInfo)
+            throw MakeStringException(-1, "Unknown cluster '%s'", cluster);
+        const StringArray &thors = clusterInfo->getThorProcesses();
+        if (thors.length())
+        {
+            StringArray envClusters, envGroups, envQueues;
+            getEnvironmentThorClusterNames(envClusters, envGroups, envQueues);
+            ForEachItemIn(i, thors)
+            {
+                const char *thorName = thors.item(i);
+                ForEachItemIn(j, envClusters)
+                {
+                    if (strieq(thorName, envClusters.item(j)))
+                    {
+                        const char *envGroup = envGroups.item(j);
+                        if (groupName.length())
+                        {
+                            if (!strieq(groupName, envGroup))
+                                throw MakeStringException(-1, "getGroupName(): ambiguous groups %s, %s", groupName.str(), envGroup);
+                        }
+                        else
+                            groupName.append(envGroup);
+                        break;
+                    }
+                }
+            }
+
+        }
+        else
+        {
+            // eclagent group name not stored in cluster info so reverse lookup in dali (bit of kludge)
+            SocketEndpoint ep = queryMyNode()->endpoint();
+            ep.port = 0;
+            Owned<IGroup> grp = createIGroup(1,&ep);
+            queryNamedGroupStore().find(grp, groupName);
+        }
+    }
+    return groupName.detach();
 }
 
 char * EclAgent::queryIndexMetaData(char const * lfn, char const * xpath)