2017-02-08 18:52:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2017-12-05 20:44:22 +00:00
|
|
|
"errors"
|
2017-02-08 18:52:34 +00:00
|
|
|
"fmt"
|
2017-07-03 18:15:59 +00:00
|
|
|
"sort"
|
2017-02-08 18:52:34 +00:00
|
|
|
"strings"
|
2018-10-23 18:21:27 +00:00
|
|
|
"time"
|
2017-02-08 18:52:34 +00:00
|
|
|
|
2019-01-05 09:10:54 +00:00
|
|
|
"github.com/ipfs/ipfs-cluster/api"
|
2019-06-14 10:41:11 +00:00
|
|
|
|
|
|
|
peer "github.com/libp2p/go-libp2p-core/peer"
|
2017-02-08 18:52:34 +00:00
|
|
|
)
|
|
|
|
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
type addedOutputQuiet struct {
|
2019-03-23 16:31:05 +00:00
|
|
|
*api.AddedOutput
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
quiet bool
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:44:22 +00:00
|
|
|
func jsonFormatObject(resp interface{}) {
|
|
|
|
switch resp.(type) {
|
|
|
|
case nil:
|
|
|
|
return
|
2019-02-27 17:04:35 +00:00
|
|
|
case []*addedOutputQuiet:
|
2019-01-10 10:13:21 +00:00
|
|
|
// print original objects as in JSON it makes
|
|
|
|
// no sense to have a human "quiet" output
|
2019-02-27 17:04:35 +00:00
|
|
|
serials := resp.([]*addedOutputQuiet)
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
var actual []*api.AddedOutput
|
|
|
|
for _, s := range serials {
|
2019-03-23 16:31:05 +00:00
|
|
|
actual = append(actual, s.AddedOutput)
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
}
|
|
|
|
jsonFormatPrint(actual)
|
2017-02-08 18:52:34 +00:00
|
|
|
default:
|
2019-02-27 17:04:35 +00:00
|
|
|
jsonFormatPrint(resp)
|
2017-02-08 18:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:44:22 +00:00
|
|
|
func jsonFormatPrint(obj interface{}) {
|
|
|
|
j, err := json.MarshalIndent(obj, "", " ")
|
|
|
|
checkErr("generating json output", err)
|
|
|
|
fmt.Printf("%s\n", j)
|
2017-02-08 18:52:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:44:22 +00:00
|
|
|
func textFormatObject(resp interface{}) {
|
|
|
|
switch resp.(type) {
|
|
|
|
case nil:
|
|
|
|
return
|
2019-02-27 17:04:35 +00:00
|
|
|
case *api.ID:
|
|
|
|
textFormatPrintID(resp.(*api.ID))
|
|
|
|
case *api.GlobalPinInfo:
|
|
|
|
textFormatPrintGPInfo(resp.(*api.GlobalPinInfo))
|
|
|
|
case *api.Pin:
|
|
|
|
textFormatPrintPin(resp.(*api.Pin))
|
|
|
|
case *api.AddedOutput:
|
|
|
|
textFormatPrintAddedOutput(resp.(*api.AddedOutput))
|
|
|
|
case *addedOutputQuiet:
|
|
|
|
textFormatPrintAddedOutputQuiet(resp.(*addedOutputQuiet))
|
|
|
|
case *api.Version:
|
|
|
|
textFormatPrintVersion(resp.(*api.Version))
|
|
|
|
case *api.Error:
|
|
|
|
textFormatPrintError(resp.(*api.Error))
|
|
|
|
case *api.Metric:
|
|
|
|
textFormatPrintMetric(resp.(*api.Metric))
|
|
|
|
case []*api.ID:
|
|
|
|
for _, item := range resp.([]*api.ID) {
|
2017-12-05 20:44:22 +00:00
|
|
|
textFormatObject(item)
|
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
case []*api.GlobalPinInfo:
|
|
|
|
for _, item := range resp.([]*api.GlobalPinInfo) {
|
2017-12-05 20:44:22 +00:00
|
|
|
textFormatObject(item)
|
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
case []*api.Pin:
|
|
|
|
for _, item := range resp.([]*api.Pin) {
|
2017-12-05 20:44:22 +00:00
|
|
|
textFormatObject(item)
|
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
case []*api.AddedOutput:
|
|
|
|
for _, item := range resp.([]*api.AddedOutput) {
|
2018-03-05 20:20:33 +00:00
|
|
|
textFormatObject(item)
|
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
case []*addedOutputQuiet:
|
|
|
|
for _, item := range resp.([]*addedOutputQuiet) {
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
textFormatObject(item)
|
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
case []*api.Metric:
|
|
|
|
for _, item := range resp.([]*api.Metric) {
|
2018-10-07 16:32:46 +00:00
|
|
|
textFormatObject(item)
|
|
|
|
}
|
2017-12-05 20:44:22 +00:00
|
|
|
default:
|
|
|
|
checkErr("", errors.New("unsupported type returned"))
|
|
|
|
}
|
2017-02-08 18:52:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
func textFormatPrintID(obj *api.ID) {
|
2017-02-08 18:52:34 +00:00
|
|
|
if obj.Error != "" {
|
2019-03-14 12:58:36 +00:00
|
|
|
fmt.Printf("%s | ERROR: %s\n", obj.ID.Pretty(), obj.Error)
|
2017-02-08 18:52:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
fmt.Printf(
|
|
|
|
"%s | %s | Sees %d other peers\n",
|
|
|
|
obj.ID.Pretty(),
|
|
|
|
obj.Peername,
|
|
|
|
len(obj.ClusterPeers)-1,
|
|
|
|
)
|
|
|
|
|
2017-07-14 19:22:52 +00:00
|
|
|
addrs := make(sort.StringSlice, 0, len(obj.Addresses))
|
2017-02-08 18:52:34 +00:00
|
|
|
for _, a := range obj.Addresses {
|
2019-02-27 17:04:35 +00:00
|
|
|
addrs = append(addrs, a.String())
|
2017-07-03 18:15:59 +00:00
|
|
|
}
|
|
|
|
addrs.Sort()
|
|
|
|
fmt.Println(" > Addresses:")
|
|
|
|
for _, a := range addrs {
|
2017-02-08 18:52:34 +00:00
|
|
|
fmt.Printf(" - %s\n", a)
|
|
|
|
}
|
|
|
|
if obj.IPFS.Error != "" {
|
|
|
|
fmt.Printf(" > IPFS ERROR: %s\n", obj.IPFS.Error)
|
|
|
|
return
|
|
|
|
}
|
2017-07-03 18:15:59 +00:00
|
|
|
|
2017-07-14 19:22:52 +00:00
|
|
|
ipfsAddrs := make(sort.StringSlice, 0, len(obj.Addresses))
|
2017-02-08 18:52:34 +00:00
|
|
|
for _, a := range obj.IPFS.Addresses {
|
2019-02-27 17:04:35 +00:00
|
|
|
ipfsAddrs = append(ipfsAddrs, a.String())
|
2017-07-03 18:15:59 +00:00
|
|
|
}
|
|
|
|
ipfsAddrs.Sort()
|
2019-03-11 23:08:51 +00:00
|
|
|
fmt.Printf(" > IPFS: %s\n", obj.IPFS.ID.Pretty())
|
2017-07-03 18:15:59 +00:00
|
|
|
for _, a := range ipfsAddrs {
|
2017-02-08 18:52:34 +00:00
|
|
|
fmt.Printf(" - %s\n", a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
func textFormatPrintGPInfo(obj *api.GlobalPinInfo) {
|
2017-05-18 11:16:27 +00:00
|
|
|
fmt.Printf("%s :\n", obj.Cid)
|
2019-02-27 17:04:35 +00:00
|
|
|
peers := make([]string, 0, len(obj.PeerMap))
|
Issue #162: Rework configuration format
The following commit reimplements ipfs-cluster configuration under
the following premises:
* Each component is initialized with a configuration object
defined by its module
* Each component decides how the JSON representation of its
configuration looks like
* Each component parses and validates its own configuration
* Each component exposes its own defaults
* Component configurations are make the sections of a
central JSON configuration file (which replaces the current
JSON format)
* Component configurations implement a common interface
(config.ComponentConfig) with a set of common operations
* The central configuration file is managed by a
config.ConfigManager which:
* Registers ComponentConfigs
* Assigns the correspondent sections from the JSON file to each
component and delegates the parsing
* Delegates the JSON generation for each section
* Can be notified when the configuration is updated and must be
saved to disk
The new service.json would then look as follows:
```json
{
"cluster": {
"id": "QmTVW8NoRxC5wBhV7WtAYtRn7itipEESfozWN5KmXUQnk2",
"private_key": "<...>",
"secret": "00224102ae6aaf94f2606abf69a0e278251ecc1d64815b617ff19d6d2841f786",
"peers": [],
"bootstrap": [],
"leave_on_shutdown": false,
"listen_multiaddress": "/ip4/0.0.0.0/tcp/9096",
"state_sync_interval": "1m0s",
"ipfs_sync_interval": "2m10s",
"replication_factor": -1,
"monitor_ping_interval": "15s"
},
"consensus": {
"raft": {
"heartbeat_timeout": "1s",
"election_timeout": "1s",
"commit_timeout": "50ms",
"max_append_entries": 64,
"trailing_logs": 10240,
"snapshot_interval": "2m0s",
"snapshot_threshold": 8192,
"leader_lease_timeout": "500ms"
}
},
"api": {
"restapi": {
"listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
"read_timeout": "30s",
"read_header_timeout": "5s",
"write_timeout": "1m0s",
"idle_timeout": "2m0s"
}
},
"ipfs_connector": {
"ipfshttp": {
"proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
"node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
"connect_swarms_delay": "7s",
"proxy_read_timeout": "10m0s",
"proxy_read_header_timeout": "5s",
"proxy_write_timeout": "10m0s",
"proxy_idle_timeout": "1m0s"
}
},
"monitor": {
"monbasic": {
"check_interval": "15s"
}
},
"informer": {
"disk": {
"metric_ttl": "30s",
"metric_type": "freespace"
},
"numpin": {
"metric_ttl": "10s"
}
}
}
```
This new format aims to be easily extensible per component. As such,
it already surfaces quite a few new options which were hardcoded
before.
Additionally, since Go API have changed, some redundant methods have been
removed and small refactoring has happened to take advantage of the new
way.
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-10-11 18:23:03 +00:00
|
|
|
for k := range obj.PeerMap {
|
2017-07-03 18:15:59 +00:00
|
|
|
peers = append(peers, k)
|
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
sort.Strings(peers)
|
2017-07-03 18:15:59 +00:00
|
|
|
|
|
|
|
for _, k := range peers {
|
|
|
|
v := obj.PeerMap[k]
|
2018-09-21 17:28:55 +00:00
|
|
|
if len(v.PeerName) > 0 {
|
2019-08-14 12:10:11 +00:00
|
|
|
fmt.Printf(" > %-20s : %s", v.PeerName, strings.ToUpper(v.Status.String()))
|
2018-09-21 17:28:55 +00:00
|
|
|
} else {
|
2019-08-14 12:10:11 +00:00
|
|
|
fmt.Printf(" > %-20s : %s", k, strings.ToUpper(v.Status.String()))
|
2018-09-21 17:28:55 +00:00
|
|
|
}
|
2017-02-08 18:52:34 +00:00
|
|
|
if v.Error != "" {
|
2018-08-22 11:06:10 +00:00
|
|
|
fmt.Printf(": %s", v.Error)
|
2017-02-08 18:52:34 +00:00
|
|
|
}
|
2019-02-27 17:04:35 +00:00
|
|
|
txt, _ := v.TS.MarshalText()
|
|
|
|
fmt.Printf(" | %s\n", txt)
|
2017-02-08 18:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
func textFormatPrintPInfo(obj *api.PinInfo) {
|
|
|
|
gpinfo := api.GlobalPinInfo{
|
2017-11-30 00:53:31 +00:00
|
|
|
Cid: obj.Cid,
|
2019-02-27 17:04:35 +00:00
|
|
|
PeerMap: map[string]*api.PinInfo{
|
|
|
|
peer.IDB58Encode(obj.Peer): obj,
|
2017-11-30 00:53:31 +00:00
|
|
|
},
|
|
|
|
}
|
2017-12-05 20:44:22 +00:00
|
|
|
textFormatPrintGPInfo(&gpinfo)
|
2017-11-30 00:53:31 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 18:52:34 +00:00
|
|
|
func textFormatPrintVersion(obj *api.Version) {
|
|
|
|
fmt.Println(obj.Version)
|
|
|
|
}
|
2017-02-13 15:46:53 +00:00
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
func textFormatPrintPin(obj *api.Pin) {
|
|
|
|
fmt.Printf("%s | %s | %s | ", obj.Cid, obj.Name, strings.ToUpper(obj.Type.String()))
|
2018-01-15 18:32:54 +00:00
|
|
|
|
|
|
|
if obj.ReplicationFactorMin < 0 {
|
2018-04-20 15:41:15 +00:00
|
|
|
fmt.Printf("Repl. Factor: -1 | Allocations: [everywhere]")
|
2017-02-13 15:46:53 +00:00
|
|
|
} else {
|
2019-02-27 17:04:35 +00:00
|
|
|
sortAlloc := api.PeersToStrings(obj.Allocations)
|
|
|
|
sort.Strings(sortAlloc)
|
2018-04-20 15:41:15 +00:00
|
|
|
fmt.Printf("Repl. Factor: %d--%d | Allocations: %s",
|
2018-01-16 10:19:39 +00:00
|
|
|
obj.ReplicationFactorMin, obj.ReplicationFactorMax,
|
|
|
|
sortAlloc)
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
2018-03-18 19:29:02 +00:00
|
|
|
var recStr string
|
2018-07-04 16:30:24 +00:00
|
|
|
switch obj.MaxDepth {
|
|
|
|
case 0:
|
|
|
|
recStr = "Direct"
|
|
|
|
case -1:
|
2018-03-18 19:29:02 +00:00
|
|
|
recStr = "Recursive"
|
2018-07-04 16:30:24 +00:00
|
|
|
default:
|
|
|
|
recStr = fmt.Sprintf("Recursive-%d", obj.MaxDepth)
|
2018-03-18 19:29:02 +00:00
|
|
|
}
|
2018-07-04 16:30:24 +00:00
|
|
|
|
2019-08-19 04:52:50 +00:00
|
|
|
fmt.Printf(" | %s", recStr)
|
|
|
|
|
|
|
|
fmt.Printf(" | Metadata:")
|
2019-08-27 04:02:34 +00:00
|
|
|
if len(obj.Metadata) == 0 {
|
|
|
|
fmt.Printf(" no\n")
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" yes\n")
|
2019-08-19 04:52:50 +00:00
|
|
|
}
|
2017-02-13 15:46:53 +00:00
|
|
|
}
|
2017-03-28 15:48:26 +00:00
|
|
|
|
2018-03-05 20:20:33 +00:00
|
|
|
func textFormatPrintAddedOutput(obj *api.AddedOutput) {
|
2018-10-03 21:03:30 +00:00
|
|
|
fmt.Printf("added %s %s\n", obj.Cid, obj.Name)
|
2018-03-05 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
func textFormatPrintAddedOutputQuiet(obj *addedOutputQuiet) {
|
|
|
|
if obj.quiet {
|
2019-03-23 16:31:05 +00:00
|
|
|
fmt.Printf("%s\n", obj.AddedOutput.Cid)
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
} else {
|
2019-03-23 16:31:05 +00:00
|
|
|
textFormatPrintAddedOutput(obj.AddedOutput)
|
Fix #632: Add --no-stream to ipfs-cluster-ctl
tl;dr: this solves the user's immediate need and, even if not tne strictest
solution, it is the simplest one.
I think we should not have the server buffer output when we can do it rather
easily client side and have the clients use their own memory for the task even
if `stream-channels=false` would do this.
We can always change the approach, but this is the minimal solution to
json array with all the AddedOutput things.
We might not buffer at all and hack a `[`, `,` separating elements and `]`
at the end, when json encoding is enabled, etc. But that would not be clean,
specially if we mean to support more output formats at some point.
Enabling supporting stream-channels=false in the api/rest/client means adding
new methods, with tests, modifying the interface etc etc. for what is
essentially a presentation issue in "ctl" in the end. Similarly we could
buffer inside the client, but it is so trivial that I don't see advatange.
We should also start thinking about moving to streaming API endpoints and
when that moment arrives we shall revisit this discussion.
I have removed the hacky manual output parts by declaring a custom
addedOutputQuiet type which wraps added output and is understood by
the formatters.go helpers.
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-01-09 17:53:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 16:32:46 +00:00
|
|
|
func textFormatPrintMetric(obj *api.Metric) {
|
2018-10-23 18:21:27 +00:00
|
|
|
date := time.Unix(0, obj.Expire).UTC().Format(time.RFC3339)
|
|
|
|
fmt.Printf("%s: %s | Expire: %s\n", peer.IDB58Encode(obj.Peer), obj.Value, date)
|
2018-10-07 16:32:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 15:48:26 +00:00
|
|
|
func textFormatPrintError(obj *api.Error) {
|
2017-12-06 14:00:01 +00:00
|
|
|
fmt.Printf("An error occurred:\n")
|
2017-03-28 15:48:26 +00:00
|
|
|
fmt.Printf(" Code: %d\n", obj.Code)
|
|
|
|
fmt.Printf(" Message: %s\n", obj.Message)
|
|
|
|
}
|
2019-01-05 09:10:54 +00:00
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
func trackerStatusAllString() string {
|
|
|
|
var strs []string
|
|
|
|
for _, st := range api.TrackerStatusAll() {
|
|
|
|
strs = append(strs, " - "+st.String())
|
2019-01-05 09:10:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 18:45:07 +00:00
|
|
|
sort.Strings(strs)
|
|
|
|
return strings.Join(strs, "\n")
|
2019-01-05 09:10:54 +00:00
|
|
|
}
|