-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconfigure_expiration_operation.go
89 lines (74 loc) · 2.68 KB
/
configure_expiration_operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package ravendb
import (
"encoding/json"
"net/http"
)
var _ IVoidMaintenanceOperation = &ConfigureExpirationOperation{}
type ConfigureExpirationOperation struct {
parameters *ExpirationConfiguration
Command *ConfigureExpirationCommand
}
func NewConfigureExpirationOperationWithConfiguration(expirationConfiguration *ExpirationConfiguration) (*ConfigureExpirationOperation, error) {
return &ConfigureExpirationOperation{
parameters: expirationConfiguration,
}, nil
}
func NewConfigureExpirationOperation(disabled bool, deleteFrequencyInSec *int64, maxItemsToProcess *int64) (*ConfigureExpirationOperation, error) {
p := &ExpirationConfiguration{
Disabled: disabled,
DeleteFrequencyInSec: deleteFrequencyInSec,
MaxItemsToProcess: maxItemsToProcess,
}
return &ConfigureExpirationOperation{
parameters: p,
}, nil
}
type ConfigureExpirationCommand struct {
RavenCommandBase
_parameters []byte
Result *ExpirationConfigurationResult
}
// GetCommand returns a command
func (o *ConfigureExpirationOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) {
var err error
o.Command, err = newConfigureExpirationCommand(conventions, o.parameters)
if err != nil {
return nil, err
}
return o.Command, nil
}
func newConfigureExpirationCommand(conventions *DocumentConventions, parameters *ExpirationConfiguration) (*ConfigureExpirationCommand, error) {
if conventions == nil {
return nil, newIllegalArgumentError("conventions cannot be null")
}
if parameters == nil {
return nil, newIllegalArgumentError("parameters cannot be null")
}
// Note: compared to Java, we shortcut things by serializing to JSON
// here as it's simpler and faster than two-step serialization,
// first to map[string]interface{} and then to JSON
d, err := jsonMarshal(parameters)
panicIf(err != nil, "jsonMarshal failed with %s", err)
cmd := &ConfigureExpirationCommand{
RavenCommandBase: NewRavenCommandBase(),
_parameters: d,
}
cmd.ResponseType = RavenCommandResponseTypeObject
return cmd, nil
}
func (c *ConfigureExpirationCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases/" + node.Database + "/admin/expiration/config"
return NewHttpPost(url, c._parameters)
}
func (c *ConfigureExpirationCommand) SetResponse(response []byte, fromCache bool) error {
return json.Unmarshal(response, &c.Result)
}
// ExpirationConfiguration
type ExpirationConfiguration struct {
Disabled bool `json:"Disabled"`
DeleteFrequencyInSec *int64 `json:"DeleteFrequencyInSec"`
MaxItemsToProcess *int64 `json:"MaxItemsToProcess"`
}
type ExpirationConfigurationResult struct {
RaftCommandIndex *int64 `json:"RaftCommandIndex"`
}