Skip to content

Commit

Permalink
add delete_multiple methods and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tanguyvda committed Jun 13, 2024
1 parent bd22d7e commit 39649a4
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,36 @@ function ScCacheSqlite:delete(object_id, property)
return true
end

--- sc_cache_sqlite:delete_multiple: delete a multiple properties of an object
-- @param object_id (string) the object identifier.
-- @param properties (table) a table of properties to retreive
-- @return (boolean) false if we couldn't delete the information from the cache, true otherwise
function ScCacheSqlite:delete_multiple(object_id, properties)
local sql_properties_value = ""

for _, property in ipairs(properties) do
if counter == 0 then
sql_properties_value = "'" .. property .. "'"
counter = counter + 1
else
sql_properties_value = sql_properties_value .. ", '" .. property .. "'"
end
end

local query = "DELETE FROM sc_cache WHERE property IN (" .. sql_properties_value .. ") AND object_id = '" .. object_id .. "';"

if not self:run_query(query) then
self.sc_logger:error("[sc_cache_sqlite:delete_multiple]: couldn't delete property in cache. Object id: " .. tostring(object_id)
.. ", properties: " .. self.sc_common:dumper(properties))
return false
end

self.sc_logger:debug("[sc_cache_sqlite:delete_multiple]: successfully deleted property in cache for object id: " .. tostring(object_id)
.. ", properties: " .. self.sc_common:dumper(properties))

return true
end

--- sc_cache_sqlite:show: display all property values of a given object in the stream connector log file.
-- @param object_id (string) the object identifier.
-- @return (boolean) false if we couldn't display the information from the cache, true otherwise
Expand Down
20 changes: 20 additions & 0 deletions modules/centreon-stream-connectors-lib/sc_cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ function ScCache:delete(object_id, property)
return self.cache_backend:delete(object_id, property)
end

--- delete_multiple: delete an object properties in the cache
-- @param object_id (string) the object with the property that must be deleted
-- @param properties (table) a list of properties
-- @return (boolean) true if values properly deleted in cache, false otherwise
function ScCache:delete_multiple(object_id, properties)
if not self:is_valid_cache_object(object_id) then
self.sc_logger:error("[sc_cache:delete]: Object is invalid")
return false
end

if type(properties) ~= "table" then
self.sc_logger:error("[sc_cache:delete_multiple]: properties parameter is not a table"
.. ". Received properties: " .. self.sc_common:dumper(properties))
return false
end


return self.cache_backend:delete_multiple(object_id, property)
end

--- show: show (in the log file) all stored properties of an object
-- @param object_id (string) the object with the property that must be shown
-- @return (boolean) true if object properties are retrieved, false otherwise
Expand Down
6 changes: 4 additions & 2 deletions modules/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@
| get | gets an object property in the cache | [Documentation](sc_cache.md#get-method) |
| get_multiple | retrieves a list of properties for an object | [Documentation](sc_cache.md#get_multiple-method) |
| delete | deletes an object property in the cache | [Documentation](sc_cache.md#delete-method) |
| delete_multiple | deletes an object properties in the cache | [Documentation](sc_cache.md#delete_multiple-method) |
| show | shows (in the log file) all stored properties of an object | [Documentation](sc_cache.md#show-method) |
| deletes | deletes all stored information in cache | [Documentation](sc_cache.md#is_valid_perfdata-method) |
| clear | deletes all stored information in cache | [Documentation](sc_cache.md#is_valid_perfdata-method) |

## sc_cache_sqlite methods

Expand All @@ -211,8 +212,9 @@
| get | retrieves a single property value of an object | [Documentation](cache_backends/sc_cache_sqlite.md#get-method) |
| get_multiple | retrieves a list of properties for an object | [Documentation](cache_backends/sc_cache_sqlite.md#get_multiple-method) |
| delete | deletes an object property in the cache | [Documentation](cache_backends/sc_cache_sqlite.md#delete-method) |
| delete_multiple | deletes an object properties in the cache | [Documentation](cache_backends/sc_cache_sqlite.md#delete_multiple-method) |
| show | shows (in the log file) all stored properties of an object | [Documentation](cache_backends/sc_cache_sqlite.md#show-method) |
| deletes | deletes all stored information in cache | [Documentation](cache_backends/sc_cache_sqlite.md#is_valid_perfdata-method) |
| clear | deletes all stored information in cache | [Documentation](cache_backends/sc_cache_sqlite.md#is_valid_perfdata-method) |

## google.bigquery.bigquery methods

Expand Down
31 changes: 31 additions & 0 deletions modules/docs/cache_backends/sc_cache_sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
- [delete: parameters](#delete-parameters)
- [delete: returns](#delete-returns)
- [delete: example](#delete-example)
- [delete\_multiple method](#delete_multiple-method)
- [delete\_multiple: parameters](#delete_multiple-parameters)
- [delete\_multiple: returns](#delete_multiple-returns)
- [delete\_multiple: example](#delete_multiple-example)
- [show method](#show-method)
- [show: parameters](#show-parameters)
- [show: returns](#show-returns)
Expand Down Expand Up @@ -341,6 +345,33 @@ local status, value = test_cache_sqlite:delete(object_id, property)
--> status is true
```

## delete_multiple method

The **delete_multiple** method deletes an object properties in the cache

### delete_multiple: parameters

| parameter | type | optional | default value |
| ------------------------------------------------- | ------ | -------- | ------------- |
| the object with the property that must be deleted | string | no | |
| list of properties | table | no | |

### delete_multiple: returns

| return | type | always | condition |
| ------------- | ------- | ------ | -------------------------------------------------------- |
| true or false | boolean | yes | true if value properly deleted in cache, false otherwise |

### delete_multiple: example

```lua
local object_id = "host_2712"
local properties = {"city", "country"}

local status= test_cache_sqlite:delete_multiple(object_id, properties)
--> status is true
```

## show method

The **show** method shows (in the log file) all stored properties of an object
Expand Down
33 changes: 32 additions & 1 deletion modules/docs/sc_cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
- [delete: parameters](#delete-parameters)
- [delete: returns](#delete-returns)
- [delete: example](#delete-example)
- [delete\_multiple method](#delete_multiple-method)
- [delete\_multiple: parameters](#delete_multiple-parameters)
- [delete\_multiple: returns](#delete_multiple-returns)
- [delete\_multiple: example](#delete_multiple-example)
- [show method](#show-method)
- [show: parameters](#show-parameters)
- [show: returns](#show-returns)
Expand Down Expand Up @@ -256,7 +260,34 @@ The **delete** method deletes an object property in the cache
local object_id = "host_2712"
local property = "city"

local status, value = test_cache:delete(object_id, property)
local status = test_cache:delete(object_id, property)
--> status is true
```

## delete_multiple method

The **delete_multiple** method deletes an object properties in the cache

### delete_multiple: parameters

| parameter | type | optional | default value |
| ------------------------------------------------- | ------ | -------- | ------------- |
| the object with the property that must be deleted | string | no | |
| a list of properties | table | no | |

### delete_multiple: returns

| return | type | always | condition |
| ------------- | ------- | ------ | --------------------------------------------------------- |
| true or false | boolean | yes | true if values properly deleted in cache, false otherwise |

### delete_multiple: example

```lua
local object_id = "host_2712"
local properties = {"city", "country"}

local status = test_cache:delete_multiple(object_id, properties)
--> status is true
```

Expand Down

0 comments on commit 39649a4

Please sign in to comment.