This repository was archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathLicensePool.cs
196 lines (178 loc) · 5.85 KB
/
LicensePool.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
* Copyright 2012 Splunk, Inc.
*
* 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.
*/
namespace Splunk
{
using System.Collections.Generic;
/// <summary>
/// The LicensePool class represents the License Pool Entity.
/// </summary>
public class LicensePool : Entity
{
/// <summary>
/// Initializes a new instance of the <see cref="LicensePool"/>
/// class.
/// </summary>
/// <param name="service">The service</param>
/// <param name="path">The path</param>
public LicensePool(Service service, string path)
: base(service, path)
{
}
/// <summary>
/// Sets a value indicating whether to append or overwrite slaves to
/// this license pool.
/// </summary>
public bool AppendSlaves
{
set
{
this.SetCacheValue("append_slaves", value);
}
}
/// <summary>
/// Gets or sets the description of this license pool.
/// </summary>
public string Description
{
get
{
return this.GetString("description", null);
}
set
{
this.SetCacheValue("description", value);
}
}
/// <summary>
/// Gets or sets the indexing quota for this license pool. Note: While
/// this value is normally an integer byyte count, use "MAX" to
/// indicate the maximum amount that is allowed.
/// </summary>
public string Quota
{
get
{
return this.GetString("quota", null);
}
set
{
this.SetCacheValue("quota", value);
}
}
/// <summary>
/// Gets or sets the slaves of this license pool.
/// </summary>
public string[] Slaves
{
get
{
// Return either the string array, OR if we have a temporary
// concatenation (as per the setter), rebuild the array.
string[] temp = this.GetStringArray("slaves", null);
if ((temp != null) && (temp.Length == 1))
{
return temp[0].Split(',');
}
return temp;
}
set
{
// Take string array and build into a single string separating
// the terms with a , symbol (expected by the endpoint) for
// updating.
string composite = string.Empty;
for (int i = 0; i < value.Length; i++)
{
if (i != 0)
{
composite = composite + ",";
}
composite = composite + value[i];
}
this.SetCacheValue("slaves", new string[] { composite });
}
}
/// <summary>
/// Gets the slaves usage in bytes.
/// </summary>
public Dictionary<string, int> SlavesUsageBytes
{
get
{
Dictionary<string, object> value =
(Dictionary<string, object>)this.Get("slaves_usage_bytes");
if (value == null)
{
value = new Dictionary<string, object>();
}
Dictionary<string, int> usageBytes =
new Dictionary<string, int>();
foreach (string key in value.Keys)
{
usageBytes[key] = int.Parse((string)value[key]);
}
return usageBytes;
}
}
/// <summary>
/// Gets the stack ID of this license message.
/// </summary>
public string StackId
{
get
{
return this.GetString("stack_id", null);
}
}
/// <summary>
/// Gets the index usage, in bytes, against this license pool.
/// </summary>
public int UsedBytes
{
get
{
return this.GetInteger("used_bytes", 0);
}
}
/// <summary>
/// Updates the entity with the arguments. We need to override
/// update only because of the asymmetric getter/setter slaves.
/// </summary>
/// <param name="args">The arguments to update.</param>
public override void Update(Dictionary<string, object> args)
{
// force canonicalization
if (this.Slaves != null)
{
this.Slaves = this.Slaves;
}
base.Update(args);
}
/// <summary>
/// Updates the entity with the arguments. We need to override
/// update only because of the asymmetric getter/setter "Slaves".
/// </summary>
public override void Update()
{
// force canonicalization
if (this.Slaves != null)
{
this.Slaves = this.Slaves;
}
base.Update();
}
}
}