-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathcluster.go
More file actions
773 lines (686 loc) · 20.3 KB
/
cluster.go
File metadata and controls
773 lines (686 loc) · 20.3 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/*
* SPDX-FileCopyrightText: © Hypermode Inc. <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/
package dgraphapi
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os/exec"
"strings"
"time"
"github.com/pkg/errors"
"github.com/dgraph-io/dgo/v250"
"github.com/dgraph-io/dgo/v250/protos/api"
"github.com/hypermodeinc/dgraph/v24/graphql/schema"
"github.com/hypermodeinc/dgraph/v24/x"
)
const (
localVersion = "local"
DefaultUser = "groot"
DefaultPassword = "password"
)
type Cluster interface {
Client() (*GrpcClient, func(), error)
HTTPClient() (*HTTPClient, error)
AlphasHealth() ([]string, error)
AlphasLogs() ([]string, error)
AssignUids(gc *dgo.Dgraph, num uint64) error
GetVersion() string
GetEncKeyPath() (string, error)
GetRepoDir() (string, error)
}
type GrpcClient struct {
*dgo.Dgraph
}
// HttpToken stores credentials for making HTTP request
type HttpToken struct {
UserId string
Password string
AccessJwt string
RefreshToken string
}
// HTTPClient allows doing operations on Dgraph over http
type HTTPClient struct {
*HttpToken
adminURL string
graphqlURL string
stateURL string
dqlURL string
dqlMutateUrl string
}
// GraphQLParams are used for making graphql requests to dgraph
type GraphQLParams struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
Extensions *schema.RequestExtensions `json:"extensions,omitempty"`
}
type GraphQLResponse struct {
Data json.RawMessage `json:"data,omitempty"`
Errors x.GqlErrorList `json:"errors,omitempty"`
Code string `json:"code"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
type LicenseResponse struct {
Data json.RawMessage `json:"data,omitempty"`
Errors x.GqlErrorList `json:"errors,omitempty"`
Code string `json:"code"`
Extensions map[string]interface{} `json:"license,omitempty"`
}
var client *http.Client = &http.Client{
Timeout: requestTimeout,
}
func DoReq(req *http.Request) ([]byte, error) {
resp, err := client.Do(req)
if err != nil {
return nil, errors.Wrap(err, "error performing HTTP request")
}
defer func() {
if err := resp.Body.Close(); err != nil {
log.Printf("[WARNING] error closing response body: %v", err)
}
}()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrapf(err, "error reading response body: url: [%v], err: [%v]", req.URL, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("got non 200 resp: %v", string(respBody))
}
return respBody, nil
}
func (hc *HTTPClient) LoginUsingToken(ns uint64) error {
q := `mutation login( $namespace: Int, $refreshToken:String) {
login(namespace: $namespace, refreshToken: $refreshToken) {
response {
accessJWT
refreshJWT
}
}
}`
params := GraphQLParams{
Query: q,
Variables: map[string]interface{}{
"namespace": ns,
"refreshToken": hc.RefreshToken,
},
}
return hc.doLogin(params, true)
}
func (hc *HTTPClient) LoginIntoNamespace(user, password string, ns uint64) error {
// This is useful for v20.11 which does not support multi-tenancy
if ns == 0 {
return hc.LoginIntoNamespaceV20(user, password)
}
q := `mutation login($userId: String, $password: String, $namespace: Int) {
login(userId: $userId, password: $password, namespace: $namespace) {
response {
accessJWT
refreshJWT
}
}
}`
params := GraphQLParams{
Query: q,
Variables: map[string]interface{}{
"userId": user,
"password": password,
"namespace": ns,
},
}
hc.HttpToken = &HttpToken{
UserId: user,
Password: password,
}
return hc.doLogin(params, true)
}
func (hc *HTTPClient) LoginIntoNamespaceV20(user, password string) error {
q := `mutation login($userId: String, $password: String) {
login(userId: $userId, password: $password) {
response {
accessJWT
refreshJWT
}
}
}`
params := GraphQLParams{
Query: q,
Variables: map[string]interface{}{
"userId": user,
"password": password,
},
}
hc.HttpToken = &HttpToken{
UserId: user,
Password: password,
}
return hc.doLogin(params, true)
}
func (hc *HTTPClient) doLogin(params GraphQLParams, isAdmin bool) error {
resp, err := hc.RunGraphqlQuery(params, isAdmin)
if err != nil {
return err
}
var r struct {
Login struct {
Response struct {
AccessJWT string
RefreshJwt string
}
}
}
if err := json.Unmarshal(resp, &r); err != nil {
return errors.Wrap(err, "error unmarshalling response into object")
}
if r.Login.Response.AccessJWT == "" {
return errors.Errorf("no access JWT found in the response")
}
hc.HttpToken.AccessJwt = r.Login.Response.AccessJWT
hc.HttpToken.RefreshToken = r.Login.Response.RefreshJwt
return nil
}
func (hc *HTTPClient) ResetPassword(userID, newPass string, nsID uint64) (string, error) {
const query = `mutation resetPassword($userID: String!, $newpass: String!, $namespaceId: Int!){
resetPassword(input: {userId: $userID, password: $newpass, namespace: $namespaceId}) {
userId
message
}
}`
params := GraphQLParams{
Query: query,
Variables: map[string]interface{}{
"namespaceId": nsID,
"userID": userID,
"newpass": newPass,
},
}
resp, err := hc.RunGraphqlQuery(params, true)
if err != nil {
return "", err
}
var result struct {
ResetPassword struct {
UserId string `json:"userId"`
Message string `json:"message"`
}
}
if err = json.Unmarshal(resp, &result); err != nil {
return "", errors.Wrap(err, "error unmarshalling response")
}
if userID != result.ResetPassword.UserId {
return "", fmt.Errorf("unexpected error while resetting password for user [%s]", userID)
}
if result.ResetPassword.Message == "Reset password is successful" {
return result.ResetPassword.UserId, nil
}
return "", errors.New(result.ResetPassword.Message)
}
// doPost makes a post request to the 'url' endpoint
func (hc *HTTPClient) doPost(body []byte, url string, contentType string) ([]byte, error) {
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body))
if err != nil {
return nil, errors.Wrapf(err, "error building req for endpoint [%v]", url)
}
req.Header.Add("Content-Type", contentType)
if hc.HttpToken != nil {
req.Header.Add("X-Dgraph-AccessToken", hc.AccessJwt)
}
return DoReq(req)
}
// RunGraphqlQuery makes a query to graphql (or admin) endpoint
func (hc *HTTPClient) RunGraphqlQuery(params GraphQLParams, admin bool) ([]byte, error) {
reqBody, err := json.Marshal(params)
if err != nil {
return nil, errors.Wrap(err, "error while marshalling params")
}
url := hc.graphqlURL
if admin {
url = hc.adminURL
}
respBody, err := hc.doPost(reqBody, url, "application/json")
if err != nil {
return nil, errors.Wrap(err, "error while running graphql query")
}
var gqlResp GraphQLResponse
if err := json.Unmarshal(respBody, &gqlResp); err != nil {
return nil, errors.Wrap(err, "error unmarshalling GQL response")
}
if len(gqlResp.Errors) > 0 {
return nil, errors.Wrapf(gqlResp.Errors, "error while running graphql query, resp: %v",
string(gqlResp.Data))
}
return gqlResp.Data, nil
}
func (hc *HTTPClient) HealthForInstance() ([]byte, error) {
const query = `query {
health {
instance
address
lastEcho
status
version
uptime
group
}
}`
params := GraphQLParams{Query: query}
return hc.RunGraphqlQuery(params, true)
}
// Backup creates a backup of dgraph at a given path
func (hc *HTTPClient) Backup(c Cluster, forceFull bool, backupPath string) error {
repoDir, err := c.GetRepoDir()
if err != nil {
return errors.Wrapf(err, "error getting repo directory")
}
// backup API was made async in the commit d3bf7b7b2786bcb99f02e1641f3b656d0a98f7f4
asyncAPI, err := IsHigherVersion(c.GetVersion(), "d3bf7b7b2786bcb99f02e1641f3b656d0a98f7f4", repoDir)
if err != nil {
return errors.Wrapf(err, "error checking incremental restore support")
}
var taskPart string
if asyncAPI {
taskPart = "taskId"
}
const queryFmt = `mutation backup($dest: String!, $ff: Boolean!) {
backup(input: {destination: $dest, forceFull: $ff}) {
response {
code
}
%v
}
}`
params := GraphQLParams{
Query: fmt.Sprintf(queryFmt, taskPart),
Variables: map[string]interface{}{"dest": backupPath, "ff": forceFull},
}
resp, err := hc.RunGraphqlQuery(params, true)
if err != nil {
return err
}
var backupResp struct {
Backup struct {
Response struct {
Code string `json:"code,omitempty"`
} `json:"response,omitempty"`
TaskID string `json:"taskId,omitempty"`
} `json:"backup,omitempty"`
}
if err := json.Unmarshal(resp, &backupResp); err != nil {
return errors.Wrap(err, "error unmarshalling backup response")
}
if backupResp.Backup.Response.Code != "Success" {
return fmt.Errorf("backup failed")
}
return hc.WaitForTask(backupResp.Backup.TaskID)
}
// WaitForTask waits for the task to finish
func (hc *HTTPClient) WaitForTask(taskId string) error {
// This can happen if the backup API is a sync API
if taskId == "" {
return nil
}
const query = `query task($id: String!) {
task(input: {id: $id}) {
status
}
}`
params := GraphQLParams{
Query: query,
Variables: map[string]interface{}{"id": taskId},
}
for {
time.Sleep(waitDurBeforeRetry)
resp, err := hc.RunGraphqlQuery(params, true)
if err != nil {
return err
}
var statusResp struct {
Task struct {
Status string `json:"status,omitempty"`
} `json:"task,omitempty"`
}
if err := json.Unmarshal(resp, &statusResp); err != nil {
return errors.Wrap(err, "error unmarshalling status response")
}
switch statusResp.Task.Status {
case "Success":
return nil
case "Failed", "Unknown":
return fmt.Errorf("task failed with status: %s", statusResp.Task.Status)
}
}
}
// Restore performs restore on Dgraph cluster from the given path to backup
func (hc *HTTPClient) Restore(c Cluster, backupPath string,
backupId string, incrFrom, backupNum int) error {
repoDir, err := c.GetRepoDir()
if err != nil {
return errors.Wrapf(err, "error getting repo directory")
}
// incremental restore was introduced in commit 8b3712e93ed2435bea52d957f7b69976c6cfc55b
incrRestoreSupported, err := IsHigherVersion(c.GetVersion(), "8b3712e93ed2435bea52d957f7b69976c6cfc55b", repoDir)
if err != nil {
return errors.Wrapf(err, "error checking incremental restore support")
}
if !incrRestoreSupported && incrFrom != 0 {
return errors.New("incremental restore is not supported by the cluster")
}
encKey, err := c.GetEncKeyPath()
if err != nil {
return errors.Wrapf(err, "error getting encryption key path")
}
var varPart, queryPart string
if incrRestoreSupported {
varPart = "$incrFrom: Int, "
queryPart = " incrementalFrom: $incrFrom,"
}
query := fmt.Sprintf(`mutation restore($location: String!, $backupId: String,
%v$backupNum: Int, $encKey: String) {
restore(input: {location: $location, backupId: $backupId,%v
backupNum: $backupNum, encryptionKeyFile: $encKey}) {
code
message
}
}`, varPart, queryPart)
vars := map[string]interface{}{"location": backupPath, "backupId": backupId,
"backupNum": backupNum, "encKey": encKey}
if incrRestoreSupported {
vars["incrFrom"] = incrFrom
}
params := GraphQLParams{
Query: query,
Variables: vars,
}
resp, err := hc.RunGraphqlQuery(params, true)
if err != nil {
return err
}
var restoreResp struct {
Restore struct {
Code string
Message string
}
}
if err := json.Unmarshal(resp, &restoreResp); err != nil {
return errors.Wrap(err, "error unmarshalling restore response")
}
if restoreResp.Restore.Code != "Success" {
return fmt.Errorf("restore failed, response: %+v", restoreResp.Restore)
}
return nil
}
// RestoreTenant restore specific namespace
func (hc *HTTPClient) RestoreTenant(c Cluster, backupPath string, backupId string,
incrFrom, backupNum int, fromNamespace uint64) error {
encKey, err := c.GetEncKeyPath()
if err != nil {
return errors.Wrapf(err, "error getting encryption key path")
}
query := `mutation restoreTenant( $location: String!, $backupId: String,
$incrFrom: Int, $backupNum: Int, $encKey: String,$fromNamespace: Int! ) {
restoreTenant(input: {restoreInput: { location: $location, backupId: $backupId,
incrementalFrom: $incrFrom, backupNum: $backupNum,
encryptionKeyFile: $encKey },fromNamespace:$fromNamespace}) {
code
message
}
}`
vars := map[string]interface{}{"location": backupPath, "backupId": backupId, "backupNum": backupNum,
"encKey": encKey, "fromNamespace": fromNamespace, "incrFrom": incrFrom}
params := GraphQLParams{
Query: query,
Variables: vars,
}
resp, err := hc.RunGraphqlQuery(params, true)
if err != nil {
return err
}
var restoreResp struct {
RestoreTenant struct {
Code string
Message string
}
}
if err := json.Unmarshal(resp, &restoreResp); err != nil {
return errors.Wrap(err, "error unmarshalling restore response")
}
if restoreResp.RestoreTenant.Code != "Success" {
return fmt.Errorf("restoreTenant failed, response: %+v", restoreResp.RestoreTenant)
}
return nil
}
// WaitForRestore waits for restore to complete on all alphas
func WaitForRestore(c Cluster) error {
loop:
for {
time.Sleep(waitDurBeforeRetry)
resp, err := c.AlphasHealth()
if err != nil && strings.Contains(err.Error(), "the server is in draining mode") {
continue loop
} else if err != nil {
return err
}
for _, hr := range resp {
if strings.Contains(hr, "opRestore") {
continue loop
}
}
break
}
// sometimes it is possible that one alpha hasn't even started the restore process.
// In this case, the alpha will not show "opRestore" in the response to health endpoint
// and the "loop" will not be able to detect this case. The "loop2" below ensures
// by looking into the logs that the restore process has in fact been started and completed.
loop2:
for range 60 {
time.Sleep(waitDurBeforeRetry)
alphasLogs, err := c.AlphasLogs()
if err != nil {
return err
}
for _, alphaLogs := range alphasLogs {
// It is possible that the alpha didn't do a restore but streamed snapshot from any other alpha
if !strings.Contains(alphaLogs, "Operation completed with id: opRestore") &&
!strings.Contains(alphaLogs, "Operation completed with id: opSnapshot") {
continue loop2
}
}
return nil
}
return errors.Errorf("restore wasn't started on at least 1 alpha")
}
func (hc *HTTPClient) Export(dest, format string, namespace int) error {
const exportRequest = `mutation export($dest: String!, $f: String!, $ns: Int) {
export(input: {destination: $dest, format: $f, namespace: $ns}) {
response {
message
}
}
}`
params := GraphQLParams{
Query: exportRequest,
Variables: map[string]interface{}{
"dest": dest,
"f": format,
"ns": namespace,
},
}
resp, err := hc.RunGraphqlQuery(params, true)
if err != nil {
return err
}
var r struct {
Export struct {
Response struct {
Message string
}
}
}
if err := json.Unmarshal(resp, &r); err != nil {
return errors.Wrap(err, "error unmarshalling export response")
}
return nil
}
// UpdateGQLSchema updates graphql schema for a given HTTP client
func (hc *HTTPClient) UpdateGQLSchema(sch string) error {
const query = `mutation updateGQLSchema($sch: String!) {
updateGQLSchema(input: { set: { schema: $sch }}) {
gqlSchema {
id
}
}
}`
params := GraphQLParams{
Query: query,
Variables: map[string]interface{}{
"sch": sch,
},
}
if _, err := hc.RunGraphqlQuery(params, true); err != nil {
return err
}
return nil
}
// PostPersistentQuery stores a persisted query
func (hc *HTTPClient) PostPersistentQuery(query, sha string) ([]byte, error) {
params := GraphQLParams{
Query: query,
Extensions: &schema.RequestExtensions{PersistedQuery: schema.PersistedQuery{
Sha256Hash: sha,
}},
}
return hc.RunGraphqlQuery(params, false)
}
func (hc *HTTPClient) GetZeroState() (*LicenseResponse, error) {
response, err := http.Get(hc.stateURL)
if err != nil {
return nil, errors.Wrap(err, "error getting zero state http response")
}
defer func() {
if err := response.Body.Close(); err != nil {
log.Printf("[WARNING] error closing body: %v", err)
}
}()
body, err := io.ReadAll(response.Body)
if err != nil {
return nil, errors.Wrapf(err, "error reading zero state response body")
}
var stateResponse LicenseResponse
if err := json.Unmarshal(body, &stateResponse); err != nil {
return nil, errors.Wrapf(err, "error unmarshaling zero state response")
}
return &stateResponse, nil
}
func (hc *HTTPClient) PostDqlQuery(query string) ([]byte, error) {
req, err := http.NewRequest(http.MethodPost, hc.dqlURL, bytes.NewBufferString(query))
if err != nil {
return nil, errors.Wrapf(err, "error building req for endpoint [%v]", hc.dqlURL)
}
req.Header.Add("Content-Type", "application/dql")
if hc.HttpToken != nil {
req.Header.Add("X-Dgraph-AccessToken", hc.AccessJwt)
}
return DoReq(req)
}
func (hc *HTTPClient) Mutate(mutation string, commitNow bool) ([]byte, error) {
url := hc.dqlMutateUrl
if commitNow {
url = hc.dqlMutateUrl + "?commitNow=true"
}
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBufferString(mutation))
if err != nil {
return nil, errors.Wrapf(err, "error building req for endpoint [%v]", url)
}
req.Header.Add("Content-Type", "application/rdf")
if hc.HttpToken != nil {
req.Header.Add("X-Dgraph-AccessToken", hc.AccessJwt)
}
return DoReq(req)
}
// SetupSchema sets up DQL schema
func (gc *GrpcClient) SetupSchema(dbSchema string) error {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
return gc.Alter(ctx, &api.Operation{Schema: dbSchema})
}
// DropAll drops all the data in the db
func (gc *GrpcClient) DropAll() error {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
return gc.Alter(ctx, &api.Operation{DropAll: true})
}
// DropPredicate drops the predicate from the data in the db
func (gc *GrpcClient) DropPredicate(pred string) error {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
return gc.Alter(ctx, &api.Operation{DropAttr: pred})
}
// Mutate performs a given mutation in a txn
func (gc *GrpcClient) Mutate(mu *api.Mutation) (*api.Response, error) {
txn := gc.NewTxn()
defer func() { _ = txn.Discard(context.Background()) }()
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
return txn.Mutate(ctx, mu)
}
func (gc *GrpcClient) Upsert(query string, mu *api.Mutation) (*api.Response, error) {
txn := gc.NewTxn()
defer func() { _ = txn.Discard(context.Background()) }()
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
req := &api.Request{
Query: query,
Mutations: []*api.Mutation{mu},
CommitNow: true,
}
return txn.Do(ctx, req)
}
// Query performa a given query in a new txn
func (gc *GrpcClient) Query(query string) (*api.Response, error) {
txn := gc.NewTxn()
defer func() { _ = txn.Discard(context.Background()) }()
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
return txn.Query(ctx, query)
}
// IsHigherVersion checks whether "higher" is the higher version compared to "lower"
func IsHigherVersion(higher, lower, repoDir string) (bool, error) {
// the order of if conditions matters here
if lower == localVersion {
return false, nil
}
if higher == localVersion {
return true, nil
}
// An older commit is usually the ancestor of a newer commit which is a descendant commit
cmd := exec.Command("git", "merge-base", "--is-ancestor", lower, higher)
cmd.Dir = repoDir
if out, err := cmd.CombinedOutput(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
return exitError.ExitCode() == 0, nil
}
return false, errors.Wrapf(err, "error checking if [%v] is ancestor of [%v]\noutput:%v",
higher, lower, string(out))
}
return true, nil
}
func GetHttpClient(alphaUrl, zeroUrl string) (*HTTPClient, error) {
adminUrl := "http://" + alphaUrl + "/admin"
graphQLUrl := "http://" + alphaUrl + "/graphql"
stateUrl := "http://" + zeroUrl + "/state"
dqlUrl := "http://" + alphaUrl + "/query"
dqlMutateUrl := "http://" + alphaUrl + "/mutate"
return &HTTPClient{
adminURL: adminUrl,
graphqlURL: graphQLUrl,
stateURL: stateUrl,
dqlURL: dqlUrl,
dqlMutateUrl: dqlMutateUrl,
HttpToken: &HttpToken{},
}, nil
}