|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package agency |
| 22 | + |
| 23 | +import "encoding/json" |
| 24 | + |
| 25 | +var ( |
| 26 | + _ json.Unmarshaler = &ArangoSyncLazy{} |
| 27 | +) |
| 28 | + |
| 29 | +// ArangoSyncLazy allows failure during load of the Sync state |
| 30 | +type ArangoSyncLazy struct { |
| 31 | + Error error |
| 32 | + *ArangoSync |
| 33 | +} |
| 34 | + |
| 35 | +func (a *ArangoSyncLazy) UnmarshalJSON(bytes []byte) error { |
| 36 | + var s ArangoSync |
| 37 | + |
| 38 | + if err := json.Unmarshal(bytes, &s); err != nil { |
| 39 | + a.ArangoSync = nil |
| 40 | + a.Error = err |
| 41 | + } else { |
| 42 | + a.ArangoSync = &s |
| 43 | + a.Error = nil |
| 44 | + } |
| 45 | + |
| 46 | + return nil |
| 47 | +} |
| 48 | + |
| 49 | +type ArangoSync struct { |
| 50 | + State ArangoSyncState `json:"synchronizationState"` |
| 51 | +} |
| 52 | + |
| 53 | +func (a *ArangoSync) IsSyncInProgress() bool { |
| 54 | + if a == nil { |
| 55 | + return false |
| 56 | + } |
| 57 | + |
| 58 | + // Check Incoming |
| 59 | + if s := a.State.Incoming.State; s != nil && *s != "inactive" && *s != "" { |
| 60 | + return true |
| 61 | + } |
| 62 | + |
| 63 | + if a.State.Outgoing.Targets.Exists() { |
| 64 | + return true |
| 65 | + } |
| 66 | + |
| 67 | + return false |
| 68 | +} |
| 69 | + |
| 70 | +type ArangoSyncState struct { |
| 71 | + Incoming ArangoSyncIncomingState `json:"incoming"` |
| 72 | + Outgoing ArangoSyncOutgoingState `json:"outgoing"` |
| 73 | +} |
| 74 | + |
| 75 | +type ArangoSyncIncomingState struct { |
| 76 | + State *string `json:"state,omitempty"` |
| 77 | +} |
| 78 | + |
| 79 | +type ArangoSyncOutgoingState struct { |
| 80 | + Targets StateExists `json:"targets,omitempty"` |
| 81 | +} |
0 commit comments