Skip to content

Commit

Permalink
HPCC-30809 Add GetVersion/Archive/Restore
Browse files Browse the repository at this point in the history
Signed-off-by: wangkx <[email protected]>
  • Loading branch information
wangkx committed Dec 7, 2023
1 parent c6bbbeb commit 9399d71
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 3 deletions.
5 changes: 4 additions & 1 deletion dali/sasha/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

project (sasha)

include (saruncmd.cmake)

INCLUDE(CheckLibraryExists)

if (NOT WIN32 AND NOT WIN64)
Expand Down Expand Up @@ -112,7 +114,8 @@ install ( TARGETS sasha RUNTIME DESTINATION ${EXEC_DIR})
target_link_libraries ( sasha
${XALAN_LIBRARIES} ${XERCES_LIBRARIES}
jlib
mp
mp
saruncmdlib
)


Expand Down
47 changes: 47 additions & 0 deletions dali/sasha/saruncmd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
################################################################################
# HPCC SYSTEMS software Copyright (C) 2023 HPCC Systems®.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################


# Component: saruncmdlib
#####################################################
# Description:
# ------------
# Cmake Input File for saruncmdlib
#####################################################

project( saruncmdlib )

set ( SRCS
sacmd.cpp
saruncmd.cpp
)

include_directories (
.
${HPCC_SOURCE_DIR}/system/mp
${HPCC_SOURCE_DIR}/system/include
${HPCC_SOURCE_DIR}/system/jlib
)

ADD_DEFINITIONS ( -D_USRDLL -DSASHACLI_API_EXPORTS )

HPCC_ADD_LIBRARY( saruncmdlib SHARED ${SRCS} )
install ( TARGETS saruncmdlib RUNTIME DESTINATION ${EXEC_DIR} LIBRARY DESTINATION ${LIB_DIR} )
target_link_libraries ( saruncmdlib
jlib
mp
)

119 changes: 119 additions & 0 deletions dali/sasha/saruncmd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include "platform.h"
#include "jlib.hpp"
#include "mpbase.hpp"
#include "sacmd.hpp"
#include "saruncmd.hpp"

class CSashaCmdExecutor : implements ISashaCmdExecutor, public CInterface
{
Linked<INode> 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)
{
Owned<ISashaCommand> 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());
if (cmd->numIds()==0)
{
// nothing restored
return false;
}
cmd->getId(0, serverResponse);
return true;
}
bool archiveWorkunit(const char *wuid, bool dfu, bool deleteAfterArchiving, StringBuffer &serverResponse)
{
Owned<ISashaCommand> 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());
if (cmd->numIds()==0)
{
// nothing archived
return false;
}
cmd->getId(0, serverResponse);
return true;
}

public:
IMPLEMENT_IINTERFACE;
CSashaCmdExecutor(INode *_node, unsigned _defaultTimeoutSecs=60) : node(_node)
{
defaultTimeoutMs = _defaultTimeoutSecs * 1000;
}
CSashaCmdExecutor(const SocketEndpoint &ep, unsigned _defaultTimeoutSecs = 60)
{
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)
{
Owned<ISashaCommand> cmd = createSashaCommand();
cmd->setAction(SCA_GETVERSION);
if (!cmd->send(node, defaultTimeoutMs))
throw makeStringExceptionV(-1, "Could not connect to Sasha server on %s", getNodeText());
if (!cmd->getId(0, version))
throw makeStringExceptionV(-1, "Sasha server[%s]: Protocol error", getNodeText());
return version;
}
bool restoreECLWorkUnit(const char *wuid, StringBuffer &serverResponse)
{
return restoreWorkunit(wuid, false, serverResponse);
}
bool restoreDFUWorkUnit(const char *wuid, StringBuffer &serverResponse)
{
return restoreWorkunit(wuid, true, serverResponse);
}
bool archiveECLWorkUnit(const char *wuid, StringBuffer &serverResponse)
{
return archiveWorkunit(wuid, false, true, serverResponse);
}
bool archiveDFUWorkUnit(const char *wuid, StringBuffer &serverResponse)
{
return archiveWorkunit(wuid, true, true, serverResponse);
}
bool backupECLWorkUnit(const char *wuid, StringBuffer &serverResponse)
{
return archiveWorkunit(wuid, true, false, serverResponse);
}
bool backupDFUWorkUnit(const char *wuid, StringBuffer &serverResponse)
{
return archiveWorkunit(wuid, true, false, serverResponse);
}
};

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);
}
25 changes: 25 additions & 0 deletions dali/sasha/saruncmd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef SARUNCMD_HPP
#define SARUNCMD_HPP

#ifdef SARUNCMD_API_EXPORTS
#define SARUNCMD_API DECL_EXPORT
#else
#define SARUNCMD_API DECL_IMPORT
#endif

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;
};

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
64 changes: 64 additions & 0 deletions esp/scm/ws_sasha.ecm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*##############################################################################

HPCC SYSTEMS software Copyright (C) 2023 HPCC Systems.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
############################################################################## */

EspInclude(common);

ESPenum WUTypes : string
{
ECL("ECL"),
DFU("DFU"),
};

ESPrequest [nil_remove] GetVersionRequest
{
};

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;
};

ESPrequest [nil_remove] RestoreWURequest
{
string Wuid;
ESPenum WUTypes WUType;
};

ESPservice [auth_feature("DEFERRED"), //This declares that the method logic handles feature level authorization
version("1.00"), default_client_version("1.00"), exceptions_inline("./smc_xslt/exceptions.xslt")] WSSasha
{
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);
SCMapi(WSSasha) IClientWSSasha *createWSSashaClient();
4 changes: 4 additions & 0 deletions esp/services/ws_sasha/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ project( ws_sasha )
include(${HPCC_SOURCE_DIR}/esp/scm/espscm.cmake)

set ( SRCS
${HPCC_SOURCE_DIR}/dali/sasha/sacmd.cpp
${ESPSCM_GENERATED_DIR}/ws_sasha_esp.cpp
ws_sashaplugin.cpp
ws_sashaservice.cpp
Expand All @@ -45,6 +46,7 @@ include_directories (
${HPCC_SOURCE_DIR}/system/security/shared
${HPCC_SOURCE_DIR}/system/mp
${HPCC_SOURCE_DIR}/common/thorhelper
${HPCC_SOURCE_DIR}/common/environment
${HPCC_SOURCE_DIR}/dali/base
${HPCC_SOURCE_DIR}/dali/sasha
)
Expand All @@ -57,6 +59,8 @@ target_link_libraries ( ws_sasha
jlib
xmllib
esphttp
SMCLib
saruncmdlib
${COMMON_ESP_SERVICE_LIBS}
)

Expand Down
Loading

0 comments on commit 9399d71

Please sign in to comment.