[mapguide-commits] r9200 - in sandbox/jng/cmdline: Common/Foundation/System Server/src/Core

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Jun 5 08:10:47 PDT 2017


Author: jng
Date: 2017-06-05 08:10:47 -0700 (Mon, 05 Jun 2017)
New Revision: 9200

Modified:
   sandbox/jng/cmdline/Common/Foundation/System/Resources.cpp
   sandbox/jng/cmdline/Common/Foundation/System/Resources.h
   sandbox/jng/cmdline/Server/src/Core/Server.cpp
   sandbox/jng/cmdline/Server/src/Core/Server.h
   sandbox/jng/cmdline/Server/src/Core/main.cpp
Log:
Add support for a "loadpackage" command-line operation. The use case for this feature is to allow for loading data packages in a headless fashion before starting up the mgserver service/daemon proper. This is important when MapGuide is used within a container (eg. Docker) or an automated environment provisioning context where currently MapGuide has no means to automatically load resources as part of building a MapGuide environment through automated means.

Modified: sandbox/jng/cmdline/Common/Foundation/System/Resources.cpp
===================================================================
--- sandbox/jng/cmdline/Common/Foundation/System/Resources.cpp	2017-06-05 11:54:32 UTC (rev 9199)
+++ sandbox/jng/cmdline/Common/Foundation/System/Resources.cpp	2017-06-05 15:10:47 UTC (rev 9200)
@@ -125,6 +125,11 @@
 const STRING MgResources::ServerCmdStopDescription      = L"  stop\n"\
                                                           L"      Stops the server service. Note: The service must be installed.\n\n";
 
+const STRING MgResources::ServerCmdLoadPackage          = L"loadpackage"; // Do not translate
+const STRING MgResources::ServerCmdLoadPackageInfo      = L"Loading the specified package.\n\n";
+const STRING MgResources::ServerCmdLoadPackageDescription = L"  loadpackage <package file path>\n"\
+                                                            L"      Loads the package at the given path.\n\n";
+
 const STRING MgResources::ServerCmdUnrecognizedInfo     = L"Unrecognized option: \"%s\".\n";
 
 const STRING MgResources::ServerCmdInstallFailed        = L"Failed to install the server service: \"%s\".\nError: %s";

Modified: sandbox/jng/cmdline/Common/Foundation/System/Resources.h
===================================================================
--- sandbox/jng/cmdline/Common/Foundation/System/Resources.h	2017-06-05 11:54:32 UTC (rev 9199)
+++ sandbox/jng/cmdline/Common/Foundation/System/Resources.h	2017-06-05 15:10:47 UTC (rev 9200)
@@ -216,6 +216,9 @@
     static const STRING ServerCmdTestDefaultTests;
     static const STRING ServerCmdTestListTests;
     static const STRING ServerCmdTestMode; // Backwards compatibility
+    static const STRING ServerCmdLoadPackage;
+    static const STRING ServerCmdLoadPackageInfo;
+    static const STRING ServerCmdLoadPackageDescription;
     static const STRING ServerCmdUninstall;
     static const STRING ServerCmdUninstallInfo;
     static const STRING ServerCmdUninstallDescription;

Modified: sandbox/jng/cmdline/Server/src/Core/Server.cpp
===================================================================
--- sandbox/jng/cmdline/Server/src/Core/Server.cpp	2017-06-05 11:54:32 UTC (rev 9199)
+++ sandbox/jng/cmdline/Server/src/Core/Server.cpp	2017-06-05 15:10:47 UTC (rev 9200)
@@ -79,6 +79,7 @@
 
     m_bTestMode = false;
     m_bTestFdo = false;
+    m_bLoadPackage = false;
 
 #ifdef _DEBUG
     m_nClientRequestLimit = -1;   // -1 = No limit. DEBUG ONLY
@@ -253,7 +254,22 @@
                 m_strTestFileName = L"";
             }
         }
+        else if (ACE_OS::strcasecmp(parameter, MG_WCHAR_TO_TCHAR(MgResources::ServerCmdLoadPackage)) == 0)
+        {
+            // Package loading mode
+            m_bLoadPackage = true;
 
+            // If there is a 2nd parameter it is the package filename
+            if (argc > 2)
+            {
+                m_strPackageFilePath = MG_TCHAR_TO_WCHAR(argv[2]);
+            }
+            else
+            {
+                m_strPackageFilePath = L"";
+            }
+        }
+
         delete[] parameter;
     }
 }
@@ -485,6 +501,59 @@
             nResult = -1;
         }
     }
+    else if (m_bLoadPackage)
+    {
+        try 
+        {
+            if (MgFileUtil::IsFile(m_strPackageFilePath))
+            {
+                // Let the site manager know that the check servers background thread needs to stop
+                MgSiteManager* siteManager = MgSiteManager::GetInstance();
+                siteManager->StopCheckServersThread();
+
+                // Set the user information for the current thread to be administrator.
+                //
+                // This is server-local, so no authentication is done. The MgServiceManager just needs to know the user when
+                // services are requested.
+                Ptr<MgUserInformation> adminUserInfo = new MgUserInformation(MgUser::Administrator, L"");
+                MgUserInformation::SetCurrentUserInfo(adminUserInfo);
+
+                MgServiceManager* serviceManager = MgServiceManager::GetInstance();
+                Ptr<MgResourceService> resSvc = dynamic_cast<MgResourceService*>(serviceManager->RequestService(MgServiceType::ResourceService));
+                if (NULL == (MgResourceService*)resSvc)
+                {
+                    throw new MgServiceNotAvailableException(L"MgServer.svc", __LINE__, __WFILE__, NULL, L"", NULL);
+                }
+
+                Ptr<MgByteSource> bs = new MgByteSource(m_strPackageFilePath);
+                Ptr<MgByteReader> br = bs->GetReader();
+
+                ACE_DEBUG((LM_INFO, ACE_TEXT("Loading package file: %W...\n\n"), m_strPackageFilePath.c_str()));
+                resSvc->ApplyResourcePackage(br);
+                ACE_DEBUG((LM_INFO, ACE_TEXT("Package loaded.\n")));
+            }
+            else
+            {
+                ACE_DEBUG((LM_INFO, ACE_TEXT("Package file not found: %W\n\n"), m_strPackageFilePath.c_str()));
+
+                nResult = -1;
+            }
+        }
+        catch (MgException* e)
+        {
+            ACE_DEBUG((LM_ERROR, ACE_TEXT("Unable to load the specified package.\n")));
+            ACE_DEBUG((LM_ERROR, ACE_TEXT("%W\n"), e->GetStackTrace(pServerManager->GetDefaultMessageLocale()).c_str()));
+            SAFE_RELEASE(e);
+
+            nResult = -1;
+        }
+        catch (...)
+        {
+            ACE_DEBUG((LM_ERROR, ACE_TEXT("Unable to load the specified package.\n")));
+
+            nResult = -1;
+        }
+    }
     else
     {
         try

Modified: sandbox/jng/cmdline/Server/src/Core/Server.h
===================================================================
--- sandbox/jng/cmdline/Server/src/Core/Server.h	2017-06-05 11:54:32 UTC (rev 9199)
+++ sandbox/jng/cmdline/Server/src/Core/Server.h	2017-06-05 15:10:47 UTC (rev 9200)
@@ -121,6 +121,8 @@
     ///////////////////////////////////////////////////////
     /// Member data
 private:
+    bool m_bLoadPackage;
+    STRING m_strPackageFilePath;
     bool m_bTestMode;
     bool m_bTestFdo;
     STRING m_strTestFileName;

Modified: sandbox/jng/cmdline/Server/src/Core/main.cpp
===================================================================
--- sandbox/jng/cmdline/Server/src/Core/main.cpp	2017-06-05 11:54:32 UTC (rev 9199)
+++ sandbox/jng/cmdline/Server/src/Core/main.cpp	2017-06-05 15:10:47 UTC (rev 9200)
@@ -294,6 +294,21 @@
 
                 bRunServerService = false;
             }
+            else if (ACE_OS::strcasecmp(parameter, MG_WCHAR_TO_TCHAR(MgResources::ServerCmdLoadPackage)) == 0)
+            {
+                // Run the fdo unit tests
+                ACE_OS::printf(MG_WCHAR_TO_CHAR(MgResources::ServerCmdLoadPackageInfo));
+
+                // Run the server as a regular application
+                nResult = SERVER::instance()->init(argc, argv);
+                if (0 == nResult)
+                {
+                    nResult = SERVER::instance()->open();
+                    SERVER::instance()->fini();
+                }
+
+                bRunServerService = false;
+            }
             else
             {
                 // Unrecognized command line option
@@ -419,6 +434,7 @@
     // Add the supported commands
     ACE_OS::printf(MG_WCHAR_TO_CHAR(MgResources::ServerCmdTestFdoDescription));
     ACE_OS::printf(MG_WCHAR_TO_CHAR(MgResources::ServerCmdTestDescription));
+    ACE_OS::printf(MG_WCHAR_TO_CHAR(MgResources::ServerCmdLoadPackageDescription));
 
 #ifdef _WIN32
     // Windows only commands



More information about the mapguide-commits mailing list