/
objectstore.go
199 lines (175 loc) · 4.55 KB
/
objectstore.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
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
197
198
199
package server
import (
"encoding/json"
"net/http"
"strconv"
clustermanager "github.com/libopenstorage/openstorage/cluster/manager"
"github.com/libopenstorage/openstorage/objectstore"
)
// swagger:operation GET /cluster/objectstore objectstore objectStoreInspect
//
// Lists Objectstore
//
// This will list current objectstores
//
// ---
// produces:
// - application/json
// parameters:
// - name: ID
// in: query
// description: ID of objectstore to inspect
// type: string
// responses:
// '200':
// description: success
// schema:
// $ref: '#/definitions/ObjectstoreInfo'
func (c *clusterApi) objectStoreInspect(w http.ResponseWriter, r *http.Request) {
method := "objectStoreInspect"
var objstoreID string
params := r.URL.Query()
v := params[objectstore.ObjectStoreID]
if v != nil {
objstoreID = v[0]
}
inst, err := clustermanager.Inst()
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
objInfo, err := inst.ObjectStoreInspect(objstoreID)
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(objInfo)
}
// swagger:operation POST /cluster/objectstore objectstore objectStoreCreate
//
// Create an Object store
//
// This creates the volumes required to run the object store
//
// ---
// produces:
// - application/json
// parameters:
// - name: name
// in: query
// description: volume on which object store to run
// required: true
// type: string
// responses:
// '200':
// description: success
// schema:
// $ref: '#/definitions/ObjectstoreInfo'
func (c *clusterApi) objectStoreCreate(w http.ResponseWriter, r *http.Request) {
method := "objectStoreCreate"
params := r.URL.Query()
volumeName := params[objectstore.VolumeName]
if len(volumeName) == 0 || volumeName[0] == "" {
c.sendError(c.name, method, w, "Missing volume name", http.StatusBadRequest)
return
}
inst, err := clustermanager.Inst()
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
objInfo, err := inst.ObjectStoreCreate(volumeName[0])
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(objInfo)
}
// swagger:operation PUT /cluster/objectstore objectstore objectStoreUpdate
//
// Updates object store
//
// This will enable/disable object store functionality.
//
// ---
// produces:
// - application/json
// parameters:
// - name: enable
// in: query
// description: enable/disable flag for object store
// type: boolean
// - name: id
// in: query
// description: ID of objectstore to update
// type: string
// responses:
// '200':
// description: success
func (c *clusterApi) objectStoreUpdate(w http.ResponseWriter, r *http.Request) {
method := "objectStoreUpdate"
var objstoreID string
params := r.URL.Query()
strEnable := params[objectstore.Enable]
v := params[objectstore.ObjectStoreID]
if v != nil {
objstoreID = v[0]
}
if len(strEnable) == 0 && strEnable[0] == "" {
c.sendError(c.name, method, w, "enable parameter not set", http.StatusInternalServerError)
return
}
enable, err := strconv.ParseBool(strEnable[0])
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
inst, err := clustermanager.Inst()
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
err = inst.ObjectStoreUpdate(objstoreID, enable)
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
// swagger:operation DELETE /cluster/objectstore objectstore objectStoreDelete
//
// Delete object store
//
// This will delete object store on node
//
// ---
// produces:
// - application/json
// parameters:
// - name: id
// in: query
// description: ID of objectstore to delete
// type: string
// responses:
// '200':
// description: success
func (c *clusterApi) objectStoreDelete(w http.ResponseWriter, r *http.Request) {
method := "objectStoreDelete"
var objstoreID string
params := r.URL.Query()
v := params[objectstore.ObjectStoreID]
if v != nil {
objstoreID = v[0]
}
inst, err := clustermanager.Inst()
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
err = inst.ObjectStoreDelete(objstoreID)
if err != nil {
c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}