diff --git a/dali/sasha/saruncmd.cpp b/dali/sasha/saruncmd.cpp index 864a44515b6..b6f0f670a36 100644 --- a/dali/sasha/saruncmd.cpp +++ b/dali/sasha/saruncmd.cpp @@ -4,116 +4,97 @@ #include "sacmd.hpp" #include "saruncmd.hpp" -class CSashaCmdExecutor : implements ISashaCmdExecutor, public CInterface +class CSashaCmdExecutor : public CInterfaceOf { - Linked node; + Owned node; unsigned defaultTimeoutMs = 60; StringBuffer nodeText; - const char *getNodeText() - { - if (0==nodeText.length()) - node->endpoint().getEndpointHostText(nodeText); - return nodeText; - } - bool restoreWorkunit(const char *wuid, bool dfu, StringBuffer &serverResponse) + mutable StringBuffer lastServerMessage; + bool restoreWorkunit(const char *wuid, bool dfu) const { + lastServerMessage.clear(); Owned cmd = createSashaCommand(); cmd->setAction(SCA_RESTORE); if (dfu) cmd->setDFU(true); cmd->addId(wuid); if (!cmd->send(node, defaultTimeoutMs)) - throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText()); + throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", nodeText.str()); if (cmd->numIds()==0) { // nothing restored return false; } - cmd->getId(0, serverResponse); + cmd->getId(0, lastServerMessage); return true; } - bool archiveWorkunit(const char *wuid, bool dfu, bool deleteAfterArchiving, StringBuffer &serverResponse) + bool archiveWorkunit(const char *wuid, bool dfu, bool deleteAfterArchiving) const { + lastServerMessage.clear(); Owned cmd = createSashaCommand(); cmd->setAction(SCA_ARCHIVE); if (dfu) cmd->setDFU(true); cmd->addId(wuid); if (!cmd->send(node, defaultTimeoutMs)) - throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText()); + throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", nodeText.str()); if (cmd->numIds()==0) { // nothing archived return false; } - cmd->getId(0, serverResponse); + cmd->getId(0, lastServerMessage); return true; } public: - IMPLEMENT_IINTERFACE; - CSashaCmdExecutor(INode *_node, unsigned _defaultTimeoutSecs=60) : node(_node) - { - defaultTimeoutMs = _defaultTimeoutSecs * 1000; - } CSashaCmdExecutor(const SocketEndpoint &ep, unsigned _defaultTimeoutSecs = 60) { + ep.getEndpointHostText(nodeText); node.setown(createINode(ep)); defaultTimeoutMs = _defaultTimeoutSecs * 1000; } - CSashaCmdExecutor(const char *server, unsigned port=0, unsigned _defaultTimeoutSecs = 60) - { - SocketEndpoint ep(server, port); - node.setown(createINode(ep)); - defaultTimeoutMs = _defaultTimeoutSecs * 1000; - } - StringBuffer &getVersion(StringBuffer &version) + virtual StringBuffer &getVersion(StringBuffer &version) const override { Owned cmd = createSashaCommand(); cmd->setAction(SCA_GETVERSION); if (!cmd->send(node, defaultTimeoutMs)) - throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText()); + throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", nodeText.str()); if (!cmd->getId(0, version)) - throw makeStringExceptionV(-1, "Sasha server[%s]: Protocol error", getNodeText()); + throw makeStringExceptionV(-1, "Sasha server[%s]: Protocol error", nodeText.str()); return version; } - bool restoreECLWorkUnit(const char *wuid, StringBuffer &serverResponse) + virtual StringBuffer &getLastServerMessage() const override + { + return lastServerMessage; + } + virtual bool restoreECLWorkUnit(const char *wuid) const override { - return restoreWorkunit(wuid, false, serverResponse); + return restoreWorkunit(wuid, false); } - bool restoreDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) + virtual bool restoreDFUWorkUnit(const char *wuid) const override { - return restoreWorkunit(wuid, true, serverResponse); + return restoreWorkunit(wuid, true); } - bool archiveECLWorkUnit(const char *wuid, StringBuffer &serverResponse) + virtual bool archiveECLWorkUnit(const char *wuid) const override { - return archiveWorkunit(wuid, false, true, serverResponse); + return archiveWorkunit(wuid, false, true); } - bool archiveDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) + virtual bool archiveDFUWorkUnit(const char *wuid) const override { - return archiveWorkunit(wuid, true, true, serverResponse); + return archiveWorkunit(wuid, true, true); } - bool backupECLWorkUnit(const char *wuid, StringBuffer &serverResponse) + virtual bool backupECLWorkUnit(const char *wuid) const override { - return archiveWorkunit(wuid, true, false, serverResponse); + return archiveWorkunit(wuid, false, false); } - bool backupDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) + virtual bool backupDFUWorkUnit(const char *wuid) const override { - return archiveWorkunit(wuid, true, false, serverResponse); + return archiveWorkunit(wuid, true, false); } }; -ISashaCmdExecutor *createSashaCmdExecutor(INode *node, unsigned defaultTimeoutSecs) -{ - return new CSashaCmdExecutor(node, defaultTimeoutSecs); -} - ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs) { return new CSashaCmdExecutor(ep, defaultTimeoutSecs); } - -ISashaCmdExecutor *createSashaCmdExecutor(const char *server, unsigned port, unsigned defaultTimeoutSecs) -{ - return new CSashaCmdExecutor(server, port, defaultTimeoutSecs); -} \ No newline at end of file diff --git a/dali/sasha/saruncmd.hpp b/dali/sasha/saruncmd.hpp index 6b6bf3643de..d588c130332 100644 --- a/dali/sasha/saruncmd.hpp +++ b/dali/sasha/saruncmd.hpp @@ -9,17 +9,16 @@ interface ISashaCmdExecutor : extends IInterface { - virtual StringBuffer &getVersion(StringBuffer &version) = 0; - virtual bool restoreECLWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; - virtual bool restoreDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; - virtual bool archiveECLWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; - virtual bool archiveDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; - virtual bool backupECLWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; - virtual bool backupDFUWorkUnit(const char *wuid, StringBuffer &serverResponse) = 0; + virtual StringBuffer &getVersion(StringBuffer &version) const = 0; + virtual StringBuffer &getLastServerMessage() const = 0; + virtual bool restoreECLWorkUnit(const char *wuid) const = 0; + virtual bool restoreDFUWorkUnit(const char *wuid) const = 0; + virtual bool archiveECLWorkUnit(const char *wuid) const = 0; + virtual bool archiveDFUWorkUnit(const char *wuid) const = 0; + virtual bool backupECLWorkUnit(const char *wuid) const = 0; + virtual bool backupDFUWorkUnit(const char *wuid) const = 0; }; -extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(INode *node, unsigned defaultTimeoutSecs=60); extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs=60); -extern SARUNCMD_API ISashaCmdExecutor *createSashaCmdExecutor(const char *server, unsigned port=0, unsigned defaultTimeoutSecs=60); #endif \ No newline at end of file diff --git a/esp/scm/ws_sasha.ecm b/esp/scm/ws_sasha.ecm index f7bce9f9afb..75db41f7146 100644 --- a/esp/scm/ws_sasha.ecm +++ b/esp/scm/ws_sasha.ecm @@ -32,16 +32,11 @@ ESPresponse [exceptions_inline, nil_remove] ResultResponse string Result; }; -ESPrequest [nil_remove] BackupWURequest -{ - string Wuid; - ESPenum WUTypes WUType; -}; - ESPrequest [nil_remove] ArchiveWURequest { string Wuid; ESPenum WUTypes WUType; + bool DeleteOnSuccess(true); }; ESPrequest [nil_remove] RestoreWURequest @@ -56,8 +51,6 @@ ESPservice [auth_feature("DEFERRED"), //This declares that the method logic hand ESPmethod [auth_feature("SashaAccess:Access")] GetVersion(GetVersionRequest, ResultResponse); ESPmethod [auth_feature("SashaAccess:FULL")] ArchiveWU(ArchiveWURequest, ResultResponse); //archive ECL WUs or DFU WUs ESPmethod [auth_feature("SashaAccess:FULL")] RestoreWU(RestoreWURequest, ResultResponse); //restore ECL WUs or DFU WUs - //The ArchiveWU deletes the workunit from Dali whereas BackupWU leave it in place. - ESPmethod [auth_feature("SashaAccess:FULL")] BackupWU(BackupWURequest, ResultResponse); }; SCMexportdef(WSSasha); diff --git a/esp/services/ws_sasha/ws_sashaservice.cpp b/esp/services/ws_sasha/ws_sashaservice.cpp index 21cb3e900d9..30a8344bc7d 100644 --- a/esp/services/ws_sasha/ws_sashaservice.cpp +++ b/esp/services/ws_sasha/ws_sashaservice.cpp @@ -32,6 +32,21 @@ ISashaCmdExecutor* CWSSashaEx::createSashaCommandExecutor(const char* archiverTy return createSashaCmdExecutor(ep); } +ISashaCmdExecutor* CWSSashaEx::querySashaCommandExecutor(CWUTypes wuType) +{ + CriticalBlock block(sect); + if (wuType == CWUTypes_ECL) + { + if (!eclWUSashaCommandExecutor) + eclWUSashaCommandExecutor.setown(createSashaCommandExecutor(wuArchiverType)); + return eclWUSashaCommandExecutor.get(); + } + + if (!dfuWUSashaCommandExecutor) + dfuWUSashaCommandExecutor.setown(createSashaCommandExecutor(dfuwuArchiverType)); + return dfuWUSashaCommandExecutor.get(); +} + void CWSSashaEx::init(IPropertyTree* cfg, const char* process, const char* service) { } @@ -43,8 +58,7 @@ bool CWSSashaEx::onGetVersion(IEspContext& context, IEspGetVersionRequest& req, context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_SASHA_ACCESS_DENIED, "WSSashaEx.GetVersion: Permission denied."); StringBuffer results; - Owned executor = createSashaCommandExecutor(wuArchiverType); - executor->getVersion(results); + querySashaCommandExecutor(CWUTypes_ECL)->getVersion(results); resp.setResult(results); } catch(IException* e) @@ -55,39 +69,20 @@ bool CWSSashaEx::onGetVersion(IEspContext& context, IEspGetVersionRequest& req, return true; } -void CWSSashaEx::setResults(const char* wuid, const char* action, StringBuffer& results) +void CWSSashaEx::setResults(const char* lastServerMessage, const char* wuid, const char* action, IEspResultResponse& resp) { + if (lastServerMessage) + { + resp.setResult(lastServerMessage); + return; + } + + StringBuffer results; if (isEmptyString(wuid)) results.appendf("No workunits %s.", action); else results.appendf("Workunit %s not %s", wuid, action); -} - -bool CWSSashaEx::onBackupWU(IEspContext& context, IEspBackupWURequest& req, IEspResultResponse& resp) -{ - try - { - context.ensureFeatureAccess(FEATURE_URL, SecAccess_Full, ECLWATCH_SASHA_ACCESS_DENIED, "WSSashaEx.BackupWU: Permission denied."); - - const char* wuid = req.getWuid(); - CWUTypes wuType = req.getWUType(); - Owned executor = createSashaCommandExecutor(wuType == CWUTypes_ECL ? wuArchiverType : dfuwuArchiverType); - - StringBuffer results; - bool sashaCmdReturn = false; - if (wuType == CWUTypes_ECL) - sashaCmdReturn = executor->backupECLWorkUnit(isEmptyString(wuid) ? "*" : wuid, results); - else - sashaCmdReturn = executor->backupDFUWorkUnit(isEmptyString(wuid) ? "*" : wuid, results); - if (!sashaCmdReturn) - setResults(wuid, "backed up", results); - resp.setResult(results); - } - catch(IException* e) - { - FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); - } - return true; + resp.setResult(results); } bool CWSSashaEx::onArchiveWU(IEspContext& context, IEspArchiveWURequest& req, IEspResultResponse& resp) @@ -97,18 +92,25 @@ bool CWSSashaEx::onArchiveWU(IEspContext& context, IEspArchiveWURequest& req, IE context.ensureFeatureAccess(FEATURE_URL, SecAccess_Full, ECLWATCH_SASHA_ACCESS_DENIED, "WSSashaEx.ArchiveWU: Permission denied."); const char* wuid = req.getWuid(); - CWUTypes wuType= req.getWUType(); - Owned executor = createSashaCommandExecutor(wuType == CWUTypes_ECL ? wuArchiverType : dfuwuArchiverType); + CWUTypes wuType = req.getWUType(); - StringBuffer results; - bool sashaCmdReturn = false; - if (wuType == CWUTypes_ECL) - sashaCmdReturn = executor->archiveECLWorkUnit(isEmptyString(wuid) ? "*" : wuid, results); + ISashaCmdExecutor* executor = querySashaCommandExecutor(wuType); + bool sashaCmdSuccess = false; + if (req.getDeleteOnSuccess()) + { + if ((wuType == CWUTypes_ECL)) + sashaCmdSuccess = executor->archiveECLWorkUnit(isEmptyString(wuid) ? "*" : wuid); + else + sashaCmdSuccess = executor->archiveDFUWorkUnit(isEmptyString(wuid) ? "*" : wuid); + } else - sashaCmdReturn = executor->archiveDFUWorkUnit(isEmptyString(wuid) ? "*" : wuid, results); - if (!sashaCmdReturn) - setResults(wuid, "archived", results); - resp.setResult(results); + { + if ((wuType == CWUTypes_ECL)) + sashaCmdSuccess = executor->backupECLWorkUnit(isEmptyString(wuid) ? "*" : wuid); + else + sashaCmdSuccess = executor->backupDFUWorkUnit(isEmptyString(wuid) ? "*" : wuid); + } + setResults(sashaCmdSuccess ? executor->getLastServerMessage().str() : nullptr, wuid, "archived", resp); } catch(IException* e) { @@ -125,17 +127,14 @@ bool CWSSashaEx::onRestoreWU(IEspContext& context, IEspRestoreWURequest& req, IE const char* wuid = req.getWuid(); CWUTypes wuType = req.getWUType(); - Owned executor = createSashaCommandExecutor(wuType == CWUTypes_ECL ? wuArchiverType : dfuwuArchiverType); - StringBuffer results; - bool sashaCmdReturn = false; - if (wuType == CWUTypes_ECL) - sashaCmdReturn = executor->restoreECLWorkUnit(isEmptyString(wuid) ? "*" : wuid, results); + ISashaCmdExecutor* executor = querySashaCommandExecutor(wuType); + bool sashaCmdSuccess = false; + if ((wuType == CWUTypes_ECL)) + sashaCmdSuccess = executor->restoreECLWorkUnit(isEmptyString(wuid) ? "*" : wuid); else - sashaCmdReturn = executor->restoreDFUWorkUnit(isEmptyString(wuid) ? "*" : wuid, results); - if (!sashaCmdReturn) - setResults(wuid, "restored", results); - resp.setResult(results); + sashaCmdSuccess = executor->restoreDFUWorkUnit(isEmptyString(wuid) ? "*" : wuid); + setResults(sashaCmdSuccess ? executor->getLastServerMessage().str() : nullptr, wuid, "restored", resp); } catch(IException* e) { diff --git a/esp/services/ws_sasha/ws_sashaservice.hpp b/esp/services/ws_sasha/ws_sashaservice.hpp index 0c14bb83320..0167d453d51 100644 --- a/esp/services/ws_sasha/ws_sashaservice.hpp +++ b/esp/services/ws_sasha/ws_sashaservice.hpp @@ -25,15 +25,16 @@ class CWSSashaEx : public CWSSasha { + CriticalSection sect; + Owned eclWUSashaCommandExecutor, dfuWUSashaCommandExecutor; + ISashaCmdExecutor* createSashaCommandExecutor(const char* archiverType); - void setResults(const char* wuid, const char* action, StringBuffer& results); + ISashaCmdExecutor* querySashaCommandExecutor(CWUTypes wuType); + void setResults(const char* lastServerMessage, const char* wuid, const char* action, IEspResultResponse& resp); public: - IMPLEMENT_IINTERFACE; - virtual void init(IPropertyTree* cfg, const char* process, const char* service) override; virtual bool onGetVersion(IEspContext& context, IEspGetVersionRequest& req, IEspResultResponse& resp) override; - virtual bool onBackupWU(IEspContext& context, IEspBackupWURequest& req, IEspResultResponse& resp) override; virtual bool onArchiveWU(IEspContext& context, IEspArchiveWURequest& req, IEspResultResponse& resp) override; virtual bool onRestoreWU(IEspContext& context, IEspRestoreWURequest& req, IEspResultResponse& resp) override; }; diff --git a/initfiles/componentfiles/configxml/@temp/esp_service_WsSMC.xsl b/initfiles/componentfiles/configxml/@temp/esp_service_WsSMC.xsl index 28093ef6946..0269f62a35b 100755 --- a/initfiles/componentfiles/configxml/@temp/esp_service_WsSMC.xsl +++ b/initfiles/componentfiles/configxml/@temp/esp_service_WsSMC.xsl @@ -137,10 +137,6 @@ This is required by its binding with ESP service ' - - - - @@ -780,37 +776,6 @@ This is required by its binding with ESP service ' - - - - - - - - - - - - - - - - - - - - - - - - - - - -