@@ -25,11 +25,11 @@ package client
2525import (
2626 "context"
2727 "encoding/json"
28- "fmt"
2928 "io/ioutil"
3029 "net/http"
3130 "net/url"
3231
32+ driver "github.com/arangodb/go-driver"
3333 "github.com/pkg/errors"
3434)
3535
@@ -101,6 +101,30 @@ func (c *client) Version(ctx context.Context) (VersionInfo, error) {
101101 return result , nil
102102}
103103
104+ // DatabaseVersion returns the version of the `arangod` binary that is being
105+ // used by this starter.
106+ func (c * client ) DatabaseVersion (ctx context.Context ) (driver.Version , error ) {
107+ url := c .createURL ("/database-version" , nil )
108+
109+ var result DatabaseVersionResponse
110+ req , err := http .NewRequest ("GET" , url , nil )
111+ if err != nil {
112+ return "" , maskAny (err )
113+ }
114+ if ctx != nil {
115+ req = req .WithContext (ctx )
116+ }
117+ resp , err := c .client .Do (req )
118+ if err != nil {
119+ return "" , maskAny (err )
120+ }
121+ if err := c .handleResponse (resp , "GET" , url , & result ); err != nil {
122+ return "" , maskAny (err )
123+ }
124+
125+ return result .Version , nil
126+ }
127+
104128// Processes loads information of all the server processes launched by a specific arangodb.
105129func (c * client ) Processes (ctx context.Context ) (ProcessList , error ) {
106130 url := c .createURL ("/process" , nil )
@@ -174,6 +198,99 @@ func (c *client) Shutdown(ctx context.Context, goodbye bool) error {
174198 return nil
175199}
176200
201+ // StartDatabaseUpgrade is called to start the upgrade process
202+ func (c * client ) StartDatabaseUpgrade (ctx context.Context ) error {
203+ url := c .createURL ("/database-auto-upgrade" , nil )
204+
205+ req , err := http .NewRequest ("POST" , url , nil )
206+ if err != nil {
207+ return maskAny (err )
208+ }
209+ if ctx != nil {
210+ req = req .WithContext (ctx )
211+ }
212+ resp , err := c .client .Do (req )
213+ if err != nil {
214+ return maskAny (err )
215+ }
216+ if err := c .handleResponse (resp , "POST" , url , nil ); err != nil {
217+ return maskAny (err )
218+ }
219+
220+ return nil
221+ }
222+
223+ // RetryDatabaseUpgrade resets a failure mark in the existing upgrade plan
224+ // such that the starters will retry the upgrade once more.
225+ func (c * client ) RetryDatabaseUpgrade (ctx context.Context ) error {
226+ url := c .createURL ("/database-auto-upgrade" , nil )
227+
228+ req , err := http .NewRequest ("PUT" , url , nil )
229+ if err != nil {
230+ return maskAny (err )
231+ }
232+ if ctx != nil {
233+ req = req .WithContext (ctx )
234+ }
235+ resp , err := c .client .Do (req )
236+ if err != nil {
237+ return maskAny (err )
238+ }
239+ if err := c .handleResponse (resp , "PUT" , url , nil ); err != nil {
240+ return maskAny (err )
241+ }
242+
243+ return nil
244+ }
245+
246+ // AbortDatabaseUpgrade removes the existing upgrade plan.
247+ // Note that Starters working on an entry of the upgrade
248+ // will finish that entry.
249+ // If there is no plan, a NotFoundError will be returned.
250+ func (c * client ) AbortDatabaseUpgrade (ctx context.Context ) error {
251+ url := c .createURL ("/database-auto-upgrade" , nil )
252+
253+ req , err := http .NewRequest ("DELETE" , url , nil )
254+ if err != nil {
255+ return maskAny (err )
256+ }
257+ if ctx != nil {
258+ req = req .WithContext (ctx )
259+ }
260+ resp , err := c .client .Do (req )
261+ if err != nil {
262+ return maskAny (err )
263+ }
264+ if err := c .handleResponse (resp , "DELETE" , url , nil ); err != nil {
265+ return maskAny (err )
266+ }
267+
268+ return nil
269+ }
270+
271+ // Status returns the status of any upgrade plan
272+ func (c * client ) UpgradeStatus (ctx context.Context ) (UpgradeStatus , error ) {
273+ url := c .createURL ("/database-auto-upgrade" , nil )
274+
275+ var result UpgradeStatus
276+ req , err := http .NewRequest ("GET" , url , nil )
277+ if err != nil {
278+ return UpgradeStatus {}, maskAny (err )
279+ }
280+ if ctx != nil {
281+ req = req .WithContext (ctx )
282+ }
283+ resp , err := c .client .Do (req )
284+ if err != nil {
285+ return UpgradeStatus {}, maskAny (err )
286+ }
287+ if err := c .handleResponse (resp , "GET" , url , & result ); err != nil {
288+ return UpgradeStatus {}, maskAny (err )
289+ }
290+
291+ return result , nil
292+ }
293+
177294// handleResponse checks the given response status and decodes any JSON result.
178295func (c * client ) handleResponse (resp * http.Response , method , url string , result interface {}) error {
179296 // Read response body into memory
@@ -184,11 +301,16 @@ func (c *client) handleResponse(resp *http.Response, method, url string, result
184301 }
185302
186303 if resp .StatusCode != http .StatusOK {
187- /* var er ErrorResponse
304+ var er ErrorResponse
188305 if err := json .Unmarshal (body , & er ); err == nil {
189- return &er
190- }*/
191- return maskAny (fmt .Errorf ("Invalid status %d" , resp .StatusCode ))
306+ return maskAny (StatusError {
307+ StatusCode : resp .StatusCode ,
308+ message : er .Error ,
309+ })
310+ }
311+ return maskAny (StatusError {
312+ StatusCode : resp .StatusCode ,
313+ })
192314 }
193315
194316 // Got a success status
0 commit comments