Masking: Add possibility to reload rules

This commit is contained in:
Johan Wikman
2017-01-02 15:20:35 +02:00
parent ad4cc7bbac
commit 8127454f24
3 changed files with 85 additions and 0 deletions

View File

@ -241,3 +241,19 @@ string should be a MariaDB account string, that is, `%` is a wildcard.
] ]
} }
``` ```
## Module commands
Read [Module Commands](../Reference/Module-Commands.md) documentation for details about module commands.
The masking filter supports the following module commands.
### `reload`
Reload the rules from the rules file. The new rules are taken into use
only if the loading succeeds without any errors.
```
MaxScale> call command masking reload MyMaskingFilter
```
`MyMaskingFilter` refers to a particular filter section in the
MariaDB MaxScale configuration file.

View File

@ -14,17 +14,67 @@
#define MXS_MODULE_NAME "masking" #define MXS_MODULE_NAME "masking"
#include "maskingfilter.hh" #include "maskingfilter.hh"
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include <maxscale/modulecmd.h>
#include "maskingrules.hh" #include "maskingrules.hh"
using std::auto_ptr; using std::auto_ptr;
using std::string; using std::string;
namespace
{
char VERSION_STRING[] = "V1.0.0";
/**
* Implement "call command masking reload ..."
*
* @param pArgs The arguments of the command.
*
* @return True, if the command was handled.
*/
bool masking_command_reload(const MODULECMD_ARG* pArgs)
{
ss_dassert(pArgs->argc == 2);
ss_dassert(MODULECMD_GET_TYPE(&pArgs->argv[0].type) == MODULECMD_ARG_OUTPUT);
ss_dassert(MODULECMD_GET_TYPE(&pArgs->argv[1].type) == MODULECMD_ARG_FILTER);
DCB* pDcb = pArgs->argv[0].value.dcb;
ss_dassert(pDcb);
const FILTER_DEF* pFilterDef = pArgs->argv[1].value.filter;
ss_dassert(pFilterDef);
if (strcmp(pFilterDef->module, "masking") == 0)
{
MaskingFilter* pFilter = reinterpret_cast<MaskingFilter*>(pFilterDef->filter);
MXS_EXCEPTION_GUARD(pFilter->reload(pDcb));
}
else
{
dcb_printf(pDcb, "Filter %s exists, but it is not a masking filter.", pFilterDef->name);
}
return true;
}
}
// //
// Global symbols of the Module // Global symbols of the Module
// //
extern "C" MXS_MODULE* MXS_CREATE_MODULE() extern "C" MXS_MODULE* MXS_CREATE_MODULE()
{ {
static modulecmd_arg_type_t reload_argv[] =
{
{ MODULECMD_ARG_OUTPUT, "The output dcb" },
{ MODULECMD_ARG_FILTER, "Masking name" }
};
modulecmd_register_command("masking", "reload", masking_command_reload,
MXS_ARRAY_NELEMS(reload_argv), reload_argv);
MXS_NOTICE("Masking module %s initialized.", VERSION_STRING); MXS_NOTICE("Masking module %s initialized.", VERSION_STRING);
static MXS_MODULE info = static MXS_MODULE info =
@ -104,6 +154,23 @@ std::tr1::shared_ptr<MaskingRules> MaskingFilter::rules() const
return m_sRules; return m_sRules;
} }
void MaskingFilter::reload(DCB* pOut)
{
auto_ptr<MaskingRules> sRules = MaskingRules::load(m_config.rules_file().c_str());
if (sRules.get())
{
m_sRules = sRules;
dcb_printf(pOut, "Rules reloaded.\n");
}
else
{
dcb_printf(pOut, "Could not reload the rules. Check the log file for more "
"detailed information.\n");
}
}
// static // static
bool MaskingFilter::process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, Config& config) bool MaskingFilter::process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, Config& config)
{ {

View File

@ -37,6 +37,8 @@ public:
static uint64_t getCapabilities(); static uint64_t getCapabilities();
void reload(DCB* pOut);
SMaskingRules rules() const; SMaskingRules rules() const;
private: private: