Skip to content

Commit

Permalink
HPCC-30809 Add ESP WsSasha service and implement 3 methods
Browse files Browse the repository at this point in the history
1. Add ws_sasha framework
2. Add GetVersion/Archive/Restore

Revise based on review:
1. Remove 2 constructors.
2. Merge BackupWU into ArchiveWU with an optional 'deleteOnSuccess' option.
3. Store the sasha server response into the lastServerMessage and allow a caller to query it.
4. Store the ISashaCmdExecutors as members to avoid recreating.
5. Roll back the changes in esp_service_WsSMC.xsl.
6. Change the getLastServerMessage() to match with the pattern of the getVersion().
7. Remove extra ().
8. Divide the setResults() to setSuccess and setFailure.

Signed-off-by: wangkx <[email protected]>
  • Loading branch information
wangkx committed Dec 18, 2023
1 parent 7552030 commit 27f36d9
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 2 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
)

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

class CSashaCmdExecutor : public CInterfaceOf<ISashaCmdExecutor>
{
Owned<INode> node;
unsigned defaultTimeoutMs = 60;
StringBuffer nodeText;
mutable StringBuffer lastServerMessage;
bool restoreWorkunit(const char *wuid, bool dfu) const
{
lastServerMessage.clear();
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", nodeText.str());
if (cmd->numIds()==0)
{
// nothing restored
return false;
}
cmd->getId(0, lastServerMessage);
return true;
}
bool archiveWorkunit(const char *wuid, bool dfu, bool deleteAfterArchiving) const
{
lastServerMessage.clear();
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", nodeText.str());
if (cmd->numIds()==0)
{
// nothing archived
return false;
}
cmd->getId(0, lastServerMessage);
return true;
}

public:
CSashaCmdExecutor(const SocketEndpoint &ep, unsigned _defaultTimeoutSecs = 60)
{
ep.getEndpointHostText(nodeText);
node.setown(createINode(ep));
defaultTimeoutMs = _defaultTimeoutSecs * 1000;
}
virtual StringBuffer &getVersion(StringBuffer &version) const override
{
Owned<ISashaCommand> cmd = createSashaCommand();
cmd->setAction(SCA_GETVERSION);
if (!cmd->send(node, defaultTimeoutMs))
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", nodeText.str());
return version;
}
virtual StringBuffer &getLastServerMessage(StringBuffer &message) const override
{
message.append(lastServerMessage);
return message;
}
virtual bool restoreECLWorkUnit(const char *wuid) const override
{
return restoreWorkunit(wuid, false);
}
virtual bool restoreDFUWorkUnit(const char *wuid) const override
{
return restoreWorkunit(wuid, true);
}
virtual bool archiveECLWorkUnit(const char *wuid) const override
{
return archiveWorkunit(wuid, false, true);
}
virtual bool archiveDFUWorkUnit(const char *wuid) const override
{
return archiveWorkunit(wuid, true, true);
}
virtual bool backupECLWorkUnit(const char *wuid) const override
{
return archiveWorkunit(wuid, false, false);
}
virtual bool backupDFUWorkUnit(const char *wuid) const override
{
return archiveWorkunit(wuid, true, false);
}
};

ISashaCmdExecutor *createSashaCmdExecutor(const SocketEndpoint &ep, unsigned defaultTimeoutSecs)
{
return new CSashaCmdExecutor(ep, defaultTimeoutSecs);
}
24 changes: 24 additions & 0 deletions dali/sasha/saruncmd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#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) const = 0;
virtual StringBuffer &getLastServerMessage(StringBuffer &lastServeressage) 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(const SocketEndpoint &ep, unsigned defaultTimeoutSecs=60);

#endif
1 change: 1 addition & 0 deletions esp/applications/eclwatch/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ application:
- ws_codesign
- ws_resources
- WSDali
- WSSasha
- ws_logaccess
- WsCloud
5 changes: 5 additions & 0 deletions esp/applications/eclwatch/ldap_authorization_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,8 @@ ldap:
- path: WsLogAccess
resource: WsLogAccess
description: Access to HPCC component log
WSSasha:
Feature:
- path: SashaAccess
resource: SashaAccess
description: Access to HPCC Archive
2 changes: 2 additions & 0 deletions esp/applications/eclwatch/plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ service_plugins:
ws_codesign: ws_codesign
ws_resources: ws_resources
WSDali: ws_dali
WSSasha: ws_sasha
WsCloud: ws_cloud
ws_logaccess: ws_logaccess

Expand All @@ -43,5 +44,6 @@ binding_plugins:
ws_codesign: ws_codesign
ws_resources: ws_resources
WSDali: ws_dali
WSSasha: ws_sasha
WsCloud: ws_cloud
ws_logaccess: ws_logaccess
1 change: 1 addition & 0 deletions esp/scm/espscm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set ( ESPSCM_SRCS
ws_codesign.ecm
ws_decoupledlogging.ecm
ws_dali.ecm
ws_sasha.ecm
ws_resources.ecm
ws_logaccess.ecm
)
Expand Down
57 changes: 57 additions & 0 deletions esp/scm/ws_sasha.ecm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*##############################################################################

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] ArchiveWURequest
{
string Wuid;
ESPenum WUTypes WUType;
bool DeleteOnSuccess(true);
};

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

SCMexportdef(WSSasha);
SCMapi(WSSasha) IClientWSSasha *createWSSashaClient();
1 change: 1 addition & 0 deletions esp/services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ HPCC_ADD_SUBDIRECTORY (ws_store "PLATFORM")
HPCC_ADD_SUBDIRECTORY (ws_codesign "PLATFORM")
HPCC_ADD_SUBDIRECTORY (ws_resources "PLATFORM")
HPCC_ADD_SUBDIRECTORY (ws_dali "PLATFORM")
HPCC_ADD_SUBDIRECTORY (ws_sasha "PLATFORM")
if (CONTAINERIZED)
HPCC_ADD_SUBDIRECTORY (ws_cloud "PLATFORM")
else ()
Expand Down
71 changes: 71 additions & 0 deletions esp/services/ws_sasha/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
################################################################################
# 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: ws_sasha
#####################################################
# Description:
# ------------
# Cmake Input File for ws_sasha
#####################################################

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
)

include_directories (
${HPCC_SOURCE_DIR}/esp/platform
${HPCC_SOURCE_DIR}/esp/bindings
${HPCC_SOURCE_DIR}/esp/bindings/SOAP/xpp
${HPCC_SOURCE_DIR}/esp/clients
${HPCC_SOURCE_DIR}/esp/smc/SMCLib
${HPCC_SOURCE_DIR}/system/include
${HPCC_SOURCE_DIR}/system/jlib
${HPCC_SOURCE_DIR}/system/xmllib
${HPCC_SOURCE_DIR}/system/security/securesocket
${HPCC_SOURCE_DIR}/system/security/LdapSecurity
${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
)

ADD_DEFINITIONS( -D_USRDLL -DWSSasha_API_LOCAL -DESP_SERVICE_WSSasha)

HPCC_ADD_LIBRARY( ws_sasha SHARED ${SRCS} )
install ( TARGETS ws_sasha RUNTIME DESTINATION ${EXEC_DIR} LIBRARY DESTINATION ${LIB_DIR} )
target_link_libraries ( ws_sasha
jlib
xmllib
esphttp
SMCLib
saruncmdlib
${COMMON_ESP_SERVICE_LIBS}
)

IF (USE_OPENSSL)
target_link_libraries ( ws_sasha
securesocket
)
ENDIF()
Loading

0 comments on commit 27f36d9

Please sign in to comment.