Pārlūkot izejas kodu

HPCC-2197 Ecl package command line parameters need to be more consistent

The same parameters for different actions should be spelled
the same and should be consistent with ecl command line parameters
when applicable.  Required parameters should not be listed as optional
(i.e. target has replaced queryset and is required)

Signed-off-by: Stuart Ort <stuart.ort@lexisnexis.com>
Stuart Ort 13 gadi atpakaļ
vecāks
revīzija
df85531f27

+ 156 - 149
ecl/ecl-package/ecl-package.cpp

@@ -28,11 +28,10 @@
 #include "eclcmd_common.hpp"
 #include "eclcmd_core.hpp"
 
-#define ECLOPT_PACKAGEMAP "--packagemap"
 #define ECLOPT_OVERWRITE "--overwrite"
+#define ECLOPT_OVERWRITE_S "-O"
 #define ECLOPT_PACKAGE "--packagename"
-#define ECLOPT_PACKAGESET "--packageset"
-#define ECLOPT_PACKAGESET_S "-ps"
+#define ECLOPT_PACKAGESETID "--packagesetid"
 
 //=========================================================================================
 
@@ -70,17 +69,17 @@ public:
             const char *arg = iter.query();
             if (*arg!='-')
             {
-                if (optQuerySetName.isEmpty())
-                    optQuerySetName.set(arg);
+                if (!optTarget.length())
+                    optTarget.set(arg);
+                else if (!optPackageMap.length())
+                    optPackageMap.set(arg);
                 else
                 {
-                    fprintf(stderr, "\nargument is already defined %s\n", arg);
-                    return false;
+                    fprintf(stderr, "\nunrecognized argument %s\n", arg);
+                    return EclCmdOptionCompletion;
                 }
                 continue;
             }
-            if (iter.matchOption(optPackageMap, ECLOPT_PACKAGEMAP))
-                continue;
             if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
                 return false;
         }
@@ -90,13 +89,18 @@ public:
     {
         if (!EclCmdCommon::finalizeOptions(globals))
             return false;
-        if (optQuerySetName.isEmpty())
+        if (optTarget.isEmpty())
         {
-            fprintf(stdout, "\n ... Missing query set name\n\n");
+            fprintf(stdout, "\n ... Missing target name\n\n");
+            usage();
+            return false;
+        }
+        if (optPackageMap.isEmpty())
+        {
+            fprintf(stdout, "\n ... Missing package map name\n\n");
             usage();
             return false;
         }
-
         return true;
     }
     virtual int processCMD()
@@ -104,7 +108,7 @@ public:
         Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
 
         Owned<IClientActivatePackageRequest> request = packageProcessClient->createActivatePackageRequest();
-        request->setPackageName(optQuerySetName);
+        request->setTarget(optTarget);
         request->setPackageMapName(optPackageMap);
 
         Owned<IClientActivatePackageResponse> resp = packageProcessClient->ActivatePackage(request);
@@ -115,16 +119,21 @@ public:
     }
     virtual void usage()
     {
-        fprintf(stdout,"\nUsage:\n\n"
-            "ecl package activate [options] [<querySetName>]\n\n"
-            "   Options:\n"
-            "      --packagemap=<packagemap>        name of packagemap to update\n"
-        );
+        fputs("\nUsage:\n"
+                    "\n"
+                    "The 'activate' command will deactivate the currently activate packagmap \n"
+                    "and make the specified package the one that is used.\n"
+                    "\n"
+                    "ecl package activate <target> <packagemap>\n"
+                    " Options:\n"
+                    "   <target>               name of target containing package map to activate\n"
+                    "   <packagemap>           packagemap to activate\n",
+                    stdout);
         EclCmdCommon::usage();
     }
 private:
 
-    StringAttr optQuerySetName;
+    StringAttr optTarget;
     StringAttr optPackageMap;
 };
 
@@ -147,27 +156,19 @@ public:
             const char *arg = iter.query();
             if (*arg!='-')
             {
-                if (optQuerySetName.isEmpty())
-                    optQuerySetName.set(arg);
+                if (!optTarget.length())
+                    optTarget.set(arg);
+                else if (!optPackageMap.length())
+                    optPackageMap.set(arg);
                 else
                 {
-                    fprintf(stderr, "\nargument is already defined %s\n", arg);
-                    return false;
+                    fprintf(stderr, "\nunrecognized argument %s\n", arg);
+                    return EclCmdOptionCompletion;
                 }
                 continue;
             }
-            if (iter.matchOption(optPackageMap, ECLOPT_PACKAGEMAP))
-                continue;
-            switch (EclCmdCommon::matchCommandLineOption(iter))
-            {
-                case EclCmdOptionNoMatch:
-                    fprintf(stderr, "\n%s option not recognized\n", arg);
-                    return false;
-                case EclCmdOptionCompletion:
-                    return false;
-                case EclCmdOptionMatch:
-                    break;
-            }
+            if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
+                return false;
         }
         return true;
     }
@@ -175,9 +176,15 @@ public:
     {
         if (!EclCmdCommon::finalizeOptions(globals))
             return false;
-        if (optQuerySetName.isEmpty())
+        if (optTarget.isEmpty())
         {
-            fprintf(stdout, "\n ... Missing query set name\n\n");
+            fprintf(stdout, "\n ... Missing target name\n\n");
+            usage();
+            return false;
+        }
+        if (optPackageMap.isEmpty())
+        {
+            fprintf(stdout, "\n ... Missing package map name\n\n");
             usage();
             return false;
         }
@@ -188,7 +195,7 @@ public:
         Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
 
         Owned<IClientDeActivatePackageRequest> request = packageProcessClient->createDeActivatePackageRequest();
-        request->setPackageName(optQuerySetName);
+        request->setTarget(optTarget);
         request->setPackageMapName(optPackageMap);
 
         Owned<IClientDeActivatePackageResponse> resp = packageProcessClient->DeActivatePackage(request);
@@ -199,16 +206,20 @@ public:
     }
     virtual void usage()
     {
-        fprintf(stdout,"\nUsage:\n\n"
-            "ecl package deactivate [options] [<querySetName>]\n\n"
-            "   Options:\n"
-            "      --packagemap=<packagemap>        name of packagemap to update\n"
-        );
+        fputs("\nUsage:\n"
+                    "\n"
+                    "The 'deactivate' command will deactivate the currently activate packagmap \n"
+                    "\n"
+                    "ecl package deactivate <target> <packagemap>\n"
+                    " Options:\n"
+                    "   <target>               name of target containing package map to activate\n"
+                    "   <packagemap>           packagemap to activate\n",
+                    stdout);
         EclCmdCommon::usage();
     }
 private:
 
-    StringAttr optQuerySetName;
+    StringAttr optTarget;
     StringAttr optPackageMap;
 };
 
@@ -231,21 +242,15 @@ public:
             const char *arg = iter.query();
             if (*arg!='-')
             {
-                if (optProcess.isEmpty())
-                    optProcess.set(arg);
+                if (optTarget.isEmpty())
+                    optTarget.set(arg);
                 else
                 {
-                    fprintf(stderr, "\nargument is already defined %s\n", arg);
-                    return false;
+                    fprintf(stderr, "\nunrecognized argument %s\n", arg);
+                    return EclCmdOptionCompletion;
                 }
                 continue;
             }
-            if (iter.matchOption(optProcess, ECLOPT_CLUSTER_DEPRECATED)||iter.matchOption(optProcess, ECLOPT_CLUSTER_DEPRECATED_S))
-                continue;
-            if (iter.matchOption(optProcess, ECLOPT_PROCESS)||iter.matchOption(optProcess, ECLOPT_PROCESS_S))
-                continue;
-            if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
-                return false;
         }
         return true;
     }
@@ -253,9 +258,9 @@ public:
     {
         if (!EclCmdCommon::finalizeOptions(globals))
             return false;
-        if (optProcess.isEmpty())
+        if (optTarget.isEmpty())
         {
-            fprintf(stderr, "\nProcess cluster must be specified\n");
+            fprintf(stderr, "\nTarget cluster must be specified\n");
             usage();
             return false;
         }
@@ -266,7 +271,7 @@ public:
         Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
 
         Owned<IClientListPackageRequest> request = packageProcessClient->createListPackageRequest();
-        request->setCluster(optProcess);
+        request->setTarget(optTarget);
 
         Owned<IClientListPackageResponse> resp = packageProcessClient->ListPackage(request);
         if (resp->getExceptions().ordinality())
@@ -300,16 +305,19 @@ public:
     }
     virtual void usage()
     {
-        fprintf(stdout,"\nUsage:\n\n"
-            "ecl package list [options] \n\n"
-            "   Options:\n"
-            "      -p, --process=<process> name of process cluster for which to retrieve package information.  Defaults to all package information stored in dali\n"
-        );
+        fputs("\nUsage:\n"
+                    "\n"
+                    "The 'list' command will list package information for the target cluster \n"
+                    "\n"
+                    "ecl package list <target> \n"
+                    " Options:\n"
+                    "   <target>               name of target containing package map to use when retrieve list of package maps\n",
+                    stdout);
         EclCmdCommon::usage();
     }
 private:
 
-    StringAttr optProcess;
+    StringAttr optTarget;
 };
 
 class EclCmdPackageInfo: public EclCmdCommon
@@ -331,42 +339,25 @@ public:
             const char *arg = iter.query();
             if (*arg!='-')
             {
-                if (optPkgName.isEmpty())
-                    optPkgName.set(arg);
+                if (optTarget.isEmpty())
+                    optTarget.set(arg);
                 else
                 {
-                    fprintf(stderr, "\nargument is already defined %s\n", arg);
-                    return false;
+                    fprintf(stderr, "\nunrecognized argument %s\n", arg);
+                    return EclCmdOptionCompletion;
                 }
                 continue;
             }
-            if (iter.matchOption(optProcess, ECLOPT_CLUSTER_DEPRECATED)||iter.matchOption(optProcess, ECLOPT_CLUSTER_DEPRECATED_S))
-                continue;
-            if (iter.matchOption(optProcess, ECLOPT_PROCESS)||iter.matchOption(optProcess, ECLOPT_PROCESS_S))
-                continue;
-            else if (iter.matchOption(optPkgName, ECLOPT_PACKAGE))
-                continue;
-            if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
-                return false;
         }
         return true;
     }
     virtual bool finalizeOptions(IProperties *globals)
     {
         if (!EclCmdCommon::finalizeOptions(globals))
-        {
-            usage();
             return false;
-        }
-        StringBuffer err;
-        if (!optPkgName.isEmpty() && !optProcess.isEmpty())
-            err.append("\n ... Specify either a process cluster name or a package name, but NOT both\n\n");
-        else if (optPkgName.isEmpty() && optProcess.isEmpty())
-            err.append("\n ... Specify either a process cluster name or a package name\n\n");
-
-        if (err.length())
+        if (optTarget.isEmpty())
         {
-            fprintf(stdout, "%s", err.str());
+            fprintf(stderr, "\nTarget cluster must be specified\n");
             usage();
             return false;
         }
@@ -377,8 +368,7 @@ public:
         Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
 
         Owned<IClientGetPackageRequest> request = packageProcessClient->createGetPackageRequest();
-        request->setPackageName(optPkgName);
-        request->setCluster(optProcess);
+        request->setTarget(optTarget);
 
         Owned<IClientGetPackageResponse> resp = packageProcessClient->GetPackage(request);
         if (resp->getExceptions().ordinality())
@@ -389,17 +379,19 @@ public:
     }
     virtual void usage()
     {
-        fprintf(stdout,"\nUsage:\n\n"
-            "ecl package info [options] [<packageName>]\n\n"
-            "   Options:\n"
-            "      [-p,--process=<process> | --packageName=<packageName>]  specify either a process cluster name or a package name to retrieve information\n"
-        );
+        fputs("\nUsage:\n"
+                    "\n"
+                    "The 'info' command will return the contents of the active package information for the target cluster \n"
+                    "\n"
+                    "ecl package list <target> \n"
+                    " Options:\n"
+                    "   <target>               name of the target to use when retrieving active package information\n",
+                    stdout);
         EclCmdCommon::usage();
     }
 private:
 
-    StringAttr optPkgName;
-    StringAttr optProcess;
+    StringAttr optTarget;
 };
 
 class EclCmdPackageDelete : public EclCmdCommon
@@ -421,17 +413,17 @@ public:
             const char *arg = iter.query();
             if (*arg!='-')
             {
-                if (optFileName.isEmpty())
-                    optFileName.set(arg);
+                if (!optTarget.length())
+                    optTarget.set(arg);
+                else if (!optPackageMap.length())
+                    optPackageMap.set(arg);
                 else
                 {
-                    fprintf(stderr, "\nargument is already defined %s\n", arg);
-                    return false;
+                    fprintf(stderr, "\nunrecognized argument %s\n", arg);
+                    return EclCmdOptionCompletion;
                 }
                 continue;
             }
-            if (iter.matchOption(optQuerySet, ECLOPT_QUERYSET))
-                continue;
             if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
                 return false;
         }
@@ -445,10 +437,10 @@ public:
             return false;
         }
         StringBuffer err;
-        if (optFileName.isEmpty())
-            err.append("\n ... Missing package file name\n\n");
-        else if (optQuerySet.isEmpty())
-            err.append("\n ... Specify either a cluster name of a package name\n\n");
+        if (optPackageMap.isEmpty())
+            err.append("\n ... Missing package map name\n\n");
+        else if (optTarget.isEmpty())
+            err.append("\n ... Specify a target cluster name\n\n");
 
         if (err.length())
         {
@@ -462,11 +454,11 @@ public:
     {
         Owned<IClientWsPackageProcess> packageProcessClient = getWsPackageSoapService(optServer, optPort, optUsername, optPassword);
 
-        fprintf(stdout, "\n ... deleting package %s now\n\n", optFileName.sget());
+        fprintf(stdout, "\n ... deleting package %s now\n\n", optPackageMap.sget());
 
         Owned<IClientDeletePackageRequest> request = packageProcessClient->createDeletePackageRequest();
-        request->setQuerySet(optQuerySet);
-        request->setPackageName(optFileName);
+        request->setTarget(optTarget);
+        request->setPackageMap(optPackageMap);
 
         Owned<IClientDeletePackageResponse> resp = packageProcessClient->DeletePackage(request);
         if (resp->getExceptions().ordinality())
@@ -485,8 +477,8 @@ public:
         EclCmdCommon::usage();
     }
 private:
-    StringAttr optFileName;
-    StringAttr optQuerySet;
+    StringAttr optPackageMap;
+    StringAttr optTarget;
 };
 
 class EclCmdPackageAdd : public EclCmdCommon
@@ -508,22 +500,22 @@ public:
             const char *arg = iter.query();
             if (*arg!='-')
             {
-                if (optFileName.isEmpty())
+                if (optTarget.isEmpty())
+                    optTarget.set(arg);
+                else if (optFileName.isEmpty())
                     optFileName.set(arg);
                 else
                 {
-                    fprintf(stderr, "\nargument is already defined %s\n", arg);
-                    return false;
+                    fprintf(stderr, "\nunrecognized argument %s\n", arg);
+                    return EclCmdOptionCompletion;
                 }
                 continue;
             }
-            if (iter.matchOption(optQuerySet, ECLOPT_QUERYSET)||iter.matchOption(optQuerySet, ECLOPT_QUERYSET_S))
-                continue;
-            if (iter.matchOption(optPackageSet, ECLOPT_PACKAGESET))
-                continue;
             if (iter.matchFlag(optActivate, ECLOPT_ACTIVATE)||iter.matchFlag(optActivate, ECLOPT_ACTIVATE_S))
                 continue;
-            if (iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE))
+            if (iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE)||iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE_S))
+                continue;
+            if (iter.matchOption(optPackageSetId, ECLOPT_PACKAGESETID))
                 continue;
             if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
                 return false;
@@ -540,11 +532,8 @@ public:
         StringBuffer err;
         if (optFileName.isEmpty())
             err.append("\n ... Missing package file name\n\n");
-        else if (optQuerySet.isEmpty())
-            err.append("\n ... Specify either a cluster name of a package name\n\n");
-
-        if (optPackageSet.isEmpty())
-            optPackageSet.set(optFileName);
+        else if (optTarget.isEmpty())
+            err.append("\n ... Specify a cluster name\n\n");
 
         if (err.length())
         {
@@ -552,6 +541,13 @@ public:
             usage();
             return false;
         }
+
+        if (optPackageSetId.isEmpty())
+            optPackageSetId.set("*");
+
+        if (optPackageProcessName.isEmpty())
+            optPackageProcessName.set(optFileName);
+
         return true;
     }
     virtual int processCMD()
@@ -565,10 +561,10 @@ public:
         Owned<IClientAddPackageRequest> request = packageProcessClient->createAddPackageRequest();
         request->setActivate(optActivate);
         request->setInfo(pkgInfo);
-        request->setQuerySet(optQuerySet);
-        request->setPackageSet(optPackageSet);
-        request->setPackageName(optFileName);
-        request->setOverWrite(optOverWrite);
+        request->setTarget(optTarget);
+        request->setPackageMap(optFileName);
+        request->setPackageProcessName(optPackageProcessName);
+        request->setPackageSetId(optPackageSetId);
 
         Owned<IClientAddPackageResponse> resp = packageProcessClient->AddPackage(request);
         if (resp->getExceptions().ordinality())
@@ -579,20 +575,27 @@ public:
 
     virtual void usage()
     {
-        fprintf(stdout,"\nUsage:\n\n"
-            "ecl package add [options] [<filename>]\n\n"
-            "   Options:\n"
-            "      -qs, --queryset=<queryset>        name of queryset to associate the information\n"
-            "      -ps, --packageset=<packageset>    will default to filename if omitted\n"
-            "      --overwrite=<true/false>          overwrite existing information - defaults to false\n"
-            "      -A, --activate                    activate the package information\n"
-        );
+        fputs("\nUsage:\n"
+                    "\n"
+                    "The 'add' command will add the package information to dali \n"
+                    "\n"
+                    "ecl package add [options] <target> <filename>\n"
+                    " Options:\n"
+                    "   -O, --overwrite             overwrite existing information\n"
+                    "   -A, --activate              activate the package information\n"
+                    "  --packagesetid               if not set use <filename>"
+// NOT-YET          "  --packageprocessname         if not set use this package process name for all clusters"
+                    "   <target>                    name of target to use when adding package information\n"
+                    "   <filename>                  name of file containing package information\n",
+                    stdout);
+
         EclCmdCommon::usage();
     }
 private:
     StringAttr optFileName;
-    StringAttr optQuerySet;
-    StringAttr optPackageSet;
+    StringAttr optTarget;
+    StringAttr optPackageProcessName;
+    StringAttr optPackageSetId;
     bool optActivate;
     bool optOverWrite;
     StringBuffer pkgInfo;
@@ -629,8 +632,6 @@ public:
                 }
                 continue;
             }
-            if (iter.matchOption(optProcess, ECLOPT_PROCESS)||iter.matchOption(optProcess, ECLOPT_PROCESS_S))
-                continue;
             if (iter.matchOption(optDaliIp, ECLOPT_DALIIP))
                 continue;
             if (iter.matchFlag(optOverWrite, ECLOPT_OVERWRITE))
@@ -650,7 +651,7 @@ public:
         StringBuffer err;
         if (optFileName.isEmpty())
             err.append("\n ... Missing package file name\n\n");
-        else if (optProcess.isEmpty())
+        else if (optTarget.isEmpty())
             err.append("\n ... Specify a process name\n\n");
 
         if (err.length())
@@ -671,7 +672,7 @@ public:
 
         Owned<IClientCopyFilesRequest> request = packageProcessClient->createCopyFilesRequest();
         request->setInfo(pkgInfo);
-        request->setProcess(optProcess);
+        request->setTarget(optTarget);
         request->setPackageName(optFileName);
         request->setOverWrite(optOverWrite);
         if (!optDaliIp.isEmpty())
@@ -686,18 +687,24 @@ public:
 
     virtual void usage()
     {
-        fprintf(stdout,"\nUsage:\n\n"
-            "ecl package copyFiles [options] [<filename>]\n\n"
-            "   Options:\n"
-            "      -p, --process=<process>      name of the process cluster to copy files\n"
-            "      --overwrite=<true/false>     overwrite data file if it already exists on the process cluster. defaults to false\n"
-            "      --daliip=<daliip>            ip of the source dali to use for file lookups\n"
-        );
+        fputs("\nUsage:\n"
+                    "\n"
+                    "The 'copyFiles' command will copy any file listed in the package that is not currently \n"
+                    "known on the cluster.  This will NOT load the package information \n"
+                    "\n"
+                    "ecl package copyFiles [options] <target> <filename>\n"
+                    " Options:\n"
+                    "   -O, --overwrite             overwrite existing information\n"
+                    "  --daliip=<daliip>            ip of the source dali to use for file lookups\n"
+                    "   <target>                    name of target to use when adding package information\n"
+                    "   <filename>                  name of file containing package information\n",
+                    stdout);
+
         EclCmdCommon::usage();
     }
 private:
     StringAttr optFileName;
-    StringAttr optProcess;
+    StringAttr optTarget;
     StringAttr optDaliIp;
     StringBuffer pkgInfo;
     bool optOverWrite;

+ 11 - 11
esp/scm/ws_packageprocess.ecm

@@ -24,9 +24,10 @@ ESPrequest AddPackageRequest
     string Info;
     boolean Activate;
     boolean OverWrite;
-    string QuerySet;
-    strint PackageSet;
-    string PackageName;
+    string Target;
+    string PackageMap;
+    string PackageProcessName;
+    string PackageSetId;
 };
 
 
@@ -37,8 +38,8 @@ ESPresponse [exceptions_inline] AddPackageResponse
 
 ESPrequest DeletePackageRequest
 {
-    string QuerySet;
-    string PackageName;
+    string Target;
+    string PackageMap;
 };
 
 ESPresponse [exceptions_inline] DeletePackageResponse
@@ -48,7 +49,7 @@ ESPresponse [exceptions_inline] DeletePackageResponse
 
 ESPrequest ActivatePackageRequest
 {
-    string PackageName;
+    string Target;
     string PackageMapName;
 };
 
@@ -59,7 +60,7 @@ ESPresponse [exceptions_inline] ActivatePackageResponse
 
 ESPrequest DeActivatePackageRequest
 {
-    string PackageName;
+    string Target;
     string PackageMapName;
 };
 
@@ -70,8 +71,7 @@ ESPresponse [exceptions_inline] DeActivatePackageResponse
 
 ESPrequest GetPackageRequest
 {
-    string Cluster;
-    string PackageName;
+    string Target;
 };
 
 ESPresponse [exceptions_inline] GetPackageResponse
@@ -82,7 +82,7 @@ ESPresponse [exceptions_inline] GetPackageResponse
 
 ESPrequest ListPackageRequest
 {
-    string Cluster;
+    string Target;
 };
 
 ESPstruct PackageListData
@@ -105,7 +105,7 @@ ESPresponse [exceptions_inline] ListPackageResponse
 
 ESPrequest CopyFilesRequest
 {
-    string Process;
+    string Target;
     string PackageName;
     string DaliIp;
     string Info;

+ 2 - 1
esp/services/ws_packageprocess/packageprocess_errors.h

@@ -24,9 +24,10 @@
 #define PKG_MISSING_PARAM   PKG_PROCESS_ERROR_START+1
 #define PKG_DALI_LOOKUP_ERROR    PKG_PROCESS_ERROR_START+2
 #define PKG_MISSING_DALI_LOOKUP_IP  PKG_PROCESS_ERROR_START+3
-#define PKG_SET_NOT_DEFINED   PKG_PROCESS_ERROR_START+4
+#define PKG_TARGET_NOT_DEFINED   PKG_PROCESS_ERROR_START+4
 #define PKG_ACTIVATE_NOT_FOUND   PKG_PROCESS_ERROR_START+5
 #define PKG_DEACTIVATE_NOT_FOUND   PKG_PROCESS_ERROR_START+6
 #define PKG_DELETE_NOT_FOUND   PKG_PROCESS_ERROR_START+7
+#define PKG_NONE_DEFINED   PKG_PROCESS_ERROR_START+8
 
 #endif

+ 60 - 63
esp/services/ws_packageprocess/ws_packageprocessService.cpp

@@ -53,20 +53,24 @@ bool CWsPackageProcessEx::onEcho(IEspContext &context, IEspEchoRequest &req, IEs
     return true;
 }
 
-IPropertyTree *getPkgSetRegistry(const char *setName, bool readonly)
+IPropertyTree *getPkgSetRegistry(const char *id, const char *process, bool readonly)
 {
     Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageSets/", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT);
 
     //Only lock the branch for the target we're interested in.
     StringBuffer xpath;
-    xpath.append("/PackageSets/PackageSet[@id=\"").append(setName).append("\"]");
+    xpath.append("/PackageSets/PackageSet[@id=\"").append(id).append("\"]");
     Owned<IRemoteConnection> conn = querySDS().connect(xpath.str(), myProcessSession(), readonly ? RTM_LOCK_READ : RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT);
     if (!conn)
     {
         if (readonly)
             return NULL;
         Owned<IPropertyTree> querySet = createPTree();
-        querySet->setProp("@id", setName);
+        querySet->setProp("@id", id);
+        if (!process || !*process)
+            querySet->setProp("@process", "*");
+        else
+            querySet->setProp("@process", process);
         globalLock->queryRoot()->addPropTree("PackageSet", querySet.getClear());
         globalLock->commit();
 
@@ -94,25 +98,25 @@ bool isRoxieProcess(const char *process)
     return conn->queryRoot()->hasProp(xpath.str());
 }
 
-bool isFileKnownOnCluster(const char *logicalname, const char *lookupDaliIp, const char *process, IUserDescriptor* userdesc)
+bool isFileKnownOnCluster(const char *logicalname, const char *lookupDaliIp, const char *target, IUserDescriptor* userdesc)
 {
     Owned<IDistributedFile> dst = queryDistributedFileDirectory().lookup(logicalname, userdesc, true);
     if (dst)
     {
-        if (dst->findCluster(process) != NotFound)
+        if (dst->findCluster(target) != NotFound)
             return true; // file already known for this cluster
     }
     return false;
 }
 
-bool addFileInfoToDali(const char *logicalname, const char *lookupDaliIp, const char *process, bool overwrite, IUserDescriptor* userdesc, StringBuffer &host, short port, StringBuffer &msg)
+bool addFileInfoToDali(const char *logicalname, const char *lookupDaliIp, const char *target, bool overwrite, IUserDescriptor* userdesc, StringBuffer &host, short port, StringBuffer &msg)
 {
     bool retval = true;
     try
     {
         if (!overwrite)
         {
-            if (isFileKnownOnCluster(logicalname, lookupDaliIp, process, userdesc))
+            if (isFileKnownOnCluster(logicalname, lookupDaliIp, target, userdesc))
                 return true;
         }
 
@@ -132,12 +136,12 @@ bool addFileInfoToDali(const char *logicalname, const char *lookupDaliIp, const
         VStringBuffer url("http://%s:%d/FileSpray", host.str(), port);
         fs->addServiceUrl(url.str());
 
-        bool isRoxie = isRoxieProcess(process);
+        bool isRoxie = isRoxieProcess(target);
 
         Owned<IClientCopy> req = fs->createCopyRequest();
         req->setSourceLogicalName(logicalname);
         req->setDestLogicalName(logicalname);
-        req->setDestGroup(process);
+        req->setDestGroup(target);
         req->setSuperCopy(false);
         if (isRoxie)
             req->setDestGroupRoxie("Yes");
@@ -178,11 +182,11 @@ void makePackageActive(IPropertyTree *pkgSetRegistry, IPropertyTree *pkgSetTree,
 
 //////////////////////////////////////////////////////////
 
-void addPackageMapInfo(IPropertyTree *pkgSetRegistry, const char *setName, const char *packageSetName, IPropertyTree *packageInfo, bool active, bool overWrite)
+void addPackageMapInfo(IPropertyTree *pkgSetRegistry, const char *target, const char *packageMapName, const char *packageSetName, IPropertyTree *packageInfo, bool active, bool overWrite)
 {
     Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageMaps/", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT);
 
-    StringBuffer lcName(packageSetName);
+    StringBuffer lcName(packageMapName);
     lcName.toLowerCase();
     StringBuffer xpath;
     xpath.append("PackageMap[@id='").append(lcName).append("']");
@@ -202,7 +206,7 @@ void addPackageMapInfo(IPropertyTree *pkgSetRegistry, const char *setName, const
 
 
     mapTree = root->addPropTree("PackageMap", createPTree());
-    mapTree->addProp("@id", packageSetName);
+    mapTree->addProp("@id", packageMapName);
 
     IPropertyTree *baseInfo = createPTree();
     Owned<IPropertyTreeIterator> iter = packageInfo->getElements("Package");
@@ -244,14 +248,14 @@ void addPackageMapInfo(IPropertyTree *pkgSetRegistry, const char *setName, const
 
     IPropertyTree *pkgSetTree = pkgSetRegistry->addPropTree("PackageMap", createPTree("PackageMap"));
     pkgSetTree->setProp("@id", lcName);
-    pkgSetTree->setProp("@querySet", setName);
+    pkgSetTree->setProp("@querySet", target);
     if (active)
-        makePackageActive(pkgSetRegistry, pkgSetTree, setName);
+        makePackageActive(pkgSetRegistry, pkgSetTree, target);
     else
         pkgSetTree->setPropBool("@active", false);
 }
 
-void copyPackageSubFiles(IPropertyTree *packageInfo, const char *process, const char *defaultLookupDaliIp, bool overwrite, IUserDescriptor* userdesc, StringBuffer &host, short port)
+void copyPackageSubFiles(IPropertyTree *packageInfo, const char *target, const char *defaultLookupDaliIp, bool overwrite, IUserDescriptor* userdesc, StringBuffer &host, short port)
 {
     Owned<IPropertyTreeIterator> iter = packageInfo->getElements("Package");
     ForEach(*iter)
@@ -278,7 +282,7 @@ void copyPackageSubFiles(IPropertyTree *packageInfo, const char *process, const
                 if (subid.length())
                 {
                     StringBuffer msg;
-                    addFileInfoToDali(subid.get(), lookupDaliIp, process, overwrite, userdesc, host, port, msg);
+                    addFileInfoToDali(subid.get(), lookupDaliIp, target, overwrite, userdesc, host, port, msg);
                 }
             }
         }
@@ -318,14 +322,14 @@ void getAllPackageListInfo(IPropertyTree *mapTree, StringBuffer &info)
     }
     info.append("</PackageMap>");
 }
-void listPkgInfo(const char *cluster, IArrayOf<IConstPackageListMapData>* results)
+void listPkgInfo(const char *target, IArrayOf<IConstPackageListMapData>* results)
 {
     StringBuffer info;
     Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageMaps/", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT);
     if (!globalLock)
         throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve package information from dali /PackageMaps");
     IPropertyTree *root = globalLock->queryRoot();
-    if (!cluster || !*cluster)
+    if (!target || !*target)
     {
         info.append("<PackageMaps>");
         Owned<IPropertyTreeIterator> iter = root->getElements("PackageMap");
@@ -340,9 +344,9 @@ void listPkgInfo(const char *cluster, IArrayOf<IConstPackageListMapData>* result
     }
     else
     {
-        Owned<IPropertyTree> pkgSetRegistry = getPkgSetRegistry(cluster, true);
+        Owned<IPropertyTree> pkgSetRegistry = getPkgSetRegistry(target, NULL, true);
         if (!pkgSetRegistry)
-            throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve package information from dali for cluster %s", cluster);
+            throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve package information from dali for target %s", target);
 
         Owned<IPropertyTreeIterator> iter = pkgSetRegistry->getElements("PackageMap");
         info.append("<PackageMaps>");
@@ -363,16 +367,16 @@ void listPkgInfo(const char *cluster, IArrayOf<IConstPackageListMapData>* result
         info.append("</PackageMaps>");
     }
 }
-void getPkgInfo(const char *cluster, const char *package, StringBuffer &info)
+void getPkgInfo(const char *target, StringBuffer &info)
 {
     Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageMaps/", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT);
     if (!globalLock)
         throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve package information from dali /PackageMaps");
     IPropertyTree *root = globalLock->queryRoot();
     Owned<IPropertyTree> tree = createPTree("PackageMaps");
-    if (cluster)
+    if (target)
     {
-        Owned<IPropertyTree> pkgSetRegistry = getPkgSetRegistry(cluster, true);
+        Owned<IPropertyTree> pkgSetRegistry = getPkgSetRegistry(target, NULL, true);
         Owned<IPropertyTreeIterator> iter = pkgSetRegistry->getElements("PackageMap[@active='1']");
         ForEach(*iter)
         {
@@ -389,35 +393,27 @@ void getPkgInfo(const char *cluster, const char *package, StringBuffer &info)
         }
     }
     else
-    {
-        StringBuffer xpath;
-        xpath.append("PackageMap[@id='").append(package).append("']");
-        Owned<IPropertyTreeIterator> iter = root->getElements(xpath.str());
-        ForEach(*iter)
-        {
-            IPropertyTree &item = iter->query();
-            mergePTree(tree, &item);
-        }
-    }
+        throw MakeStringException(PKG_TARGET_NOT_DEFINED, "No target defined");
+
     toXML(tree, info);
 }
 
-bool deletePkgInfo(const char *packageSetName, const char *queryset)
+bool deletePkgInfo(const char *packageMap, const char *target)
 {
     Owned<IRemoteConnection> pkgSet = querySDS().connect("/PackageSets/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT);
     if (!pkgSet)
-        throw MakeStringException(PKG_SET_NOT_DEFINED, "No package sets defined");
+        throw MakeStringException(PKG_NONE_DEFINED, "No package sets defined");
 
     IPropertyTree* packageSets = pkgSet->queryRoot();
 
-    VStringBuffer pkgSet_xpath("PackageSet[@id='%s']", queryset);
+    VStringBuffer pkgSet_xpath("PackageSet[@id='%s']", target);
     IPropertyTree *pkgSetRegistry = packageSets->queryPropTree(pkgSet_xpath.str());
     if (!pkgSetRegistry)
-        throw MakeStringException(PKG_SET_NOT_DEFINED, "No package sets defined for %s", queryset);
+        throw MakeStringException(PKG_TARGET_NOT_DEFINED, "No package sets defined for %s", target);
 
-    StringBuffer lcName(packageSetName);
+    StringBuffer lcName(packageMap);
     lcName.toLowerCase();
-    VStringBuffer xpath("PackageMap[@id='%s'][@querySet='%s']", lcName.str(), queryset);
+    VStringBuffer xpath("PackageMap[@id='%s'][@querySet='%s']", lcName.str(), target);
     IPropertyTree *pm = pkgSetRegistry->getPropTree(xpath.str());
     if (pm)
         pkgSetRegistry->removeTree(pm);
@@ -441,16 +437,16 @@ bool deletePkgInfo(const char *packageSetName, const char *queryset)
     return true;
 }
 
-void activatePackageMapInfo(const char *packageSetName, const char *packageMap, bool activate)
+void activatePackageMapInfo(const char *target, const char *packageMap, bool activate)
 {
-    if (!packageSetName || !*packageSetName)
-        throw MakeStringException(PKG_SET_NOT_DEFINED, "No package sets defined");
+    if (!target || !*target)
+        throw MakeStringException(PKG_TARGET_NOT_DEFINED, "No target defined");
 
     Owned<IRemoteConnection> globalLock = querySDS().connect("PackageSets", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT);
     if (!globalLock)
         throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageSets information from dali /PackageSets");
 
-    StringBuffer lcName(packageSetName);
+    StringBuffer lcName(target);
     lcName.toLowerCase();
     VStringBuffer xpath("PackageSet[@id=\"%s\"]", lcName.str());
 
@@ -470,7 +466,7 @@ void activatePackageMapInfo(const char *packageSetName, const char *packageMap,
             if (activate)
                 makePackageActive(pkgSetTree, mapTree, lcName.str());
             else
-                pkgSetTree->setPropBool("@active", false);
+                mapTree->setPropBool("@active", false);
         }
     }
 }
@@ -481,15 +477,17 @@ bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageReque
     StringBuffer info(req.getInfo());
     bool activate = req.getActivate();
     bool overWrite = req.getOverWrite();
-    StringAttr querySet(req.getQuerySet());
-    StringAttr pkgName(req.getPackageName());
+    StringAttr target(req.getTarget());
+    StringAttr pkgMapName(req.getPackageMap());
+    StringAttr pkgSetId(req.getPackageSetId());
+    StringAttr pkgProcessName(req.getPackageProcessName());
 
     Owned<IPropertyTree> packageTree = createPTreeFromXMLString(info.str());
-    Owned<IPropertyTree> pkgSetRegistry = getPkgSetRegistry(querySet.get(), false);
-    addPackageMapInfo(pkgSetRegistry, querySet.get(), pkgName.get(), LINK(packageTree), activate, overWrite);
+    Owned<IPropertyTree> pkgSetRegistry = getPkgSetRegistry(pkgSetId.get(), pkgProcessName.get(), false);
+    addPackageMapInfo(pkgSetRegistry, target.get(), pkgMapName.get(), pkgSetId.get(), LINK(packageTree), activate, overWrite);
 
     StringBuffer msg;
-    msg.append("Successfully loaded ").append(pkgName.get());
+    msg.append("Successfully loaded ").append(pkgMapName.get());
     resp.updateStatus().setDescription(msg.str());
     return true;
 }
@@ -497,11 +495,11 @@ bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageReque
 bool CWsPackageProcessEx::onDeletePackage(IEspContext &context, IEspDeletePackageRequest &req, IEspDeletePackageResponse &resp)
 {
     resp.updateStatus().setCode(0);
-    StringAttr pkgName(req.getPackageName());
-    bool ret = deletePkgInfo(pkgName.get(), req.getQuerySet());
+    StringAttr pkgMap(req.getPackageMap());
+    bool ret = deletePkgInfo(pkgMap.get(), req.getTarget());
     StringBuffer msg;
     (ret) ? msg.append("Successfully ") : msg.append("Unsuccessfully ");
-    msg.append("deleted").append(pkgName.get());
+    msg.append("deleted ").append(pkgMap.get()).append(" from ").append(req.getTarget());
 
     resp.updateStatus().setDescription(msg.str());
     return true;
@@ -510,20 +508,20 @@ bool CWsPackageProcessEx::onDeletePackage(IEspContext &context, IEspDeletePackag
 bool CWsPackageProcessEx::onActivatePackage(IEspContext &context, IEspActivatePackageRequest &req, IEspActivatePackageResponse &resp)
 {
     resp.updateStatus().setCode(0);
-    StringBuffer pkgName(req.getPackageName());
+    StringBuffer target(req.getTarget());
     StringBuffer pkgMapName(req.getPackageMapName());
 
-    activatePackageMapInfo(pkgName.str(), pkgMapName.str(), true);
+    activatePackageMapInfo(target.str(), pkgMapName.str(), true);
     return true;
 }
 
 bool CWsPackageProcessEx::onDeActivatePackage(IEspContext &context, IEspDeActivatePackageRequest &req, IEspDeActivatePackageResponse &resp)
 {
     resp.updateStatus().setCode(0);
-    StringBuffer pkgName(req.getPackageName());
+    StringBuffer target(req.getTarget());
     StringBuffer pkgMapName(req.getPackageMapName());
 
-    activatePackageMapInfo(pkgName.str(), pkgMapName.str(), false);
+    activatePackageMapInfo(target.str(), pkgMapName.str(), false);
     return true;
 }
 
@@ -531,7 +529,7 @@ bool CWsPackageProcessEx::onListPackage(IEspContext &context, IEspListPackageReq
 {
     resp.updateStatus().setCode(0);
     IArrayOf<IConstPackageListMapData> results;
-    listPkgInfo(req.getCluster(), &results);
+    listPkgInfo(req.getTarget(), &results);
     resp.setPkgListMapData(results);
     return true;
 }
@@ -539,10 +537,9 @@ bool CWsPackageProcessEx::onListPackage(IEspContext &context, IEspListPackageReq
 bool CWsPackageProcessEx::onGetPackage(IEspContext &context, IEspGetPackageRequest &req, IEspGetPackageResponse &resp)
 {
     resp.updateStatus().setCode(0);
-    StringAttr cluster(req.getCluster());
-    StringAttr pkgName(req.getPackageName());
+    StringAttr target(req.getTarget());
     StringBuffer info;
-    getPkgInfo(cluster.length() ? cluster.get() : NULL, pkgName.length() ? pkgName.get() : NULL, info);
+    getPkgInfo(target.length() ? target.get() : "*", info);
     resp.setInfo(info);
     return true;
 }
@@ -551,11 +548,11 @@ bool CWsPackageProcessEx::onCopyFiles(IEspContext &context, IEspCopyFilesRequest
 {
     resp.updateStatus().setCode(0);
     StringBuffer info(req.getInfo());
-    StringAttr process(req.getProcess());
+    StringAttr target(req.getTarget());
     StringAttr pkgName(req.getPackageName());
     StringAttr lookupDaliIp(req.getDaliIp());
 
-    if (process.length() == 0)
+    if (target.length() == 0)
         throw MakeStringException(PKG_MISSING_PARAM, "CWsPackageProcessEx::onCopyFiles process parameter not set.");
 
     Owned<IUserDescriptor> userdesc;
@@ -572,7 +569,7 @@ bool CWsPackageProcessEx::onCopyFiles(IEspContext &context, IEspCopyFilesRequest
     context.getServAddress(host, port);
 
     Owned<IPropertyTree> packageTree = createPTreeFromXMLString(info.str());
-    copyPackageSubFiles(LINK(packageTree), process, lookupDaliIp.get(), req.getOverWrite(), userdesc, host, port);
+    copyPackageSubFiles(LINK(packageTree), target, lookupDaliIp.get(), req.getOverWrite(), userdesc, host, port);
 
     StringBuffer msg;
     msg.append("Successfully loaded ").append(pkgName.get());