Skip to content

Commit

Permalink
Merge pull request #354 from mutagen-io/json-restructure
Browse files Browse the repository at this point in the history
cli: restructure JSON output
  • Loading branch information
xenoscopic authored Jun 28, 2022
2 parents 38475f9 + 8086ea1 commit e7d3581
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 388 deletions.
10 changes: 5 additions & 5 deletions cmd/mutagen/sync/list_monitor_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func printEndpoint(name string, url *url.URL, configuration *synchronization.Con
// Print content information, if available.
if state.Scanned {
fmt.Printf("\tSynchronizable contents:\n\t\t%s\n\t\t%s\n\t\t%s\n",
formatDirectoryCount(state.DirectoryCount),
formatFileCountAndSize(state.FileCount, state.TotalFileSize),
formatSymbolicLinkCount(state.SymbolicLinkCount),
formatDirectoryCount(state.Directories),
formatFileCountAndSize(state.Files, state.TotalFileSize),
formatSymbolicLinkCount(state.SymbolicLinks),
)
}

Expand Down Expand Up @@ -429,12 +429,12 @@ func printSession(state *synchronization.State, mode common.SessionDisplayMode)
var totalExpectedSize uint64
if state.Status == synchronization.Status_StagingAlpha {
stagingProgress = state.AlphaState.StagingProgress
if stagingProgress != nil && stagingProgress.ExpectedFiles == state.BetaState.FileCount {
if stagingProgress != nil && stagingProgress.ExpectedFiles == state.BetaState.Files {
totalExpectedSize = state.BetaState.TotalFileSize
}
} else if state.Status == synchronization.Status_StagingBeta {
stagingProgress = state.BetaState.StagingProgress
if stagingProgress != nil && stagingProgress.ExpectedFiles == state.AlphaState.FileCount {
if stagingProgress != nil && stagingProgress.ExpectedFiles == state.AlphaState.Files {
totalExpectedSize = state.AlphaState.TotalFileSize
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/mutagen/sync/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func computeMonitorStatusLine(state *synchronization.State) string {
stagingProgress = state.AlphaState.StagingProgress
if stagingProgress == nil {
status += "Preparing to stage files on alpha"
} else if stagingProgress.ExpectedFiles == state.BetaState.FileCount {
} else if stagingProgress.ExpectedFiles == state.BetaState.Files {
totalExpectedSize = state.BetaState.TotalFileSize
}
} else if state.Status == synchronization.Status_StagingBeta {
status += "[→] "
stagingProgress = state.BetaState.StagingProgress
if stagingProgress == nil {
status += "Preparing to stage files on beta"
} else if stagingProgress.ExpectedFiles == state.AlphaState.FileCount {
} else if stagingProgress.ExpectedFiles == state.AlphaState.Files {
totalExpectedSize = state.AlphaState.TotalFileSize
}
} else {
Expand Down
61 changes: 61 additions & 0 deletions pkg/api/models/forwarding/endpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package forwarding

import (
"github.com/mutagen-io/mutagen/pkg/forwarding"
"github.com/mutagen-io/mutagen/pkg/url"
)

// Endpoint represents a forwarding endpoint.
type Endpoint struct {
// Protocol endpoint transport protocol.
Protocol url.Protocol `json:"protocol"`
// User is the endpoint user.
User string `json:"user,omitempty"`
// Host is the endpoint host.
Host string `json:"host,omitempty"`
// Port is the endpoint port.
Port uint16 `json:"port,omitempty"`
// Endpoint is the listening or dialing address on the endpoint.
Endpoint string `json:"endpoint,omitempty"`
// Environment is the environment variable map to use for the transport.
Environment map[string]string `json:"environment,omitempty"`
// Parameters is the parameter map to use for the transport.
Parameters map[string]string `json:"parameters,omitempty"`
// Configuration is the endpoint-specific configuration.
Configuration
// Connected indicates whether or not the controller is currently connected
// to the endpoint.
Connected bool `json:"connected"`
// EndpointState stores state fields relevant to connected endpoints. It is
// non-nil if and only if the endpoint is connected.
*EndpointState
}

// EndpointState encodes the current state of a forwarding endpoint.
type EndpointState struct{}

// loadFromInternal sets an Endpoint to match internal Protocol Buffers
// representations. All parameters must be valid.
func (e *Endpoint) loadFromInternal(url *url.URL, configuration *forwarding.Configuration, state *forwarding.EndpointState) {
// Propagate URL parameters.
e.Protocol = url.Protocol
e.User = url.User
e.Host = url.Host
e.Port = uint16(url.Port)
e.Endpoint = url.Path
e.Environment = url.Environment
e.Parameters = url.Parameters

// Propagate configuration.
e.Configuration.loadFromInternal(configuration)

// Propagate connectivity.
e.Connected = state.Connected

// Propagate other state fields.
if !e.Connected {
e.EndpointState = nil
} else {
e.EndpointState = &EndpointState{}
}
}
File renamed without changes.
57 changes: 21 additions & 36 deletions pkg/api/models/forwarding/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,25 @@ type Session struct {
CreationTime string `json:"creationTime"`
// CreatingVersion is the version of Mutagen that created the session.
CreatingVersion string `json:"creatingVersion"`
// Source is the source endpoint URL.
Source URL `json:"source"`
// Destination is the destination endpoint URL.
Destination URL `json:"destination"`
// Source stores the source endpoint's configuration and state.
Source Endpoint `json:"source"`
// Destination stores the destination endpoint's configuration and state.
Destination Endpoint `json:"destination"`
// Configuration is the session configuration.
Configuration
// ConfigurationSource is the source endpoint configuration.
ConfigurationSource Configuration `json:"configurationSource"`
// ConfigurationDestination is the destination endpoint configuration.
ConfigurationDestination Configuration `json:"configurationDestination"`
// Name is the session name.
Name string `json:"name,omitempty"`
// Label are the session labels.
Labels map[string]string `json:"labels,omitempty"`
// Paused indicates whether or not the session is paused.
Paused bool `json:"paused"`
// State stores state fields relevant to running sessions. It is non-nil if
// and only if the session is unpaused.
*State
// SessionState stores state fields relevant to running sessions. It is
// non-nil if and only if the session is unpaused.
*SessionState
}

// EndpointState encodes the current state of a forwarding endpoint.
type EndpointState struct {
// Connected indicates whether or not the controller is currently connected
// to the endpoint.
Connected bool `json:"connected"`
}

// State encodes fields relevant to unpaused sessions.
type State struct {
// SessionState encodes fields relevant to unpaused sessions.
type SessionState struct {
// Status is the session status.
Status forwarding.Status `json:"status"`
// LastError is the last forwarding error to occur.
Expand All @@ -63,10 +52,6 @@ type State struct {
// TotalInboundData is the total amount of data (in bytes) that has been
// transmitted from destination to source across all forwarded connections.
TotalInboundData uint64 `json:"totalInboundData"`
// SourceState encodes the state of the source endpoint.
SourceState EndpointState `json:"sourceState"`
// DestinationState encodes the state of the destination endpoint.
DestinationState EndpointState `json:"destinationState"`
}

// loadFromInternal sets a session to match an internal Protocol Buffers session
Expand All @@ -86,31 +71,31 @@ func (s *Session) loadFromInternal(state *forwarding.State) {
s.Paused = state.Session.Paused

// Propagate endpoint information.
s.Source.loadFromInternal(state.Session.Source)
s.Destination.loadFromInternal(state.Session.Destination)
s.Source.loadFromInternal(
state.Session.Source,
state.Session.ConfigurationSource,
state.SourceState,
)
s.Destination.loadFromInternal(
state.Session.Destination,
state.Session.ConfigurationDestination,
state.DestinationState,
)

// Propagate configuration information.
s.Configuration.loadFromInternal(state.Session.Configuration)
s.ConfigurationSource.loadFromInternal(state.Session.ConfigurationSource)
s.ConfigurationDestination.loadFromInternal(state.Session.ConfigurationDestination)

// Propagate state information if the session isn't paused.
if state.Session.Paused {
s.State = nil
s.SessionState = nil
} else {
s.State = &State{
s.SessionState = &SessionState{
Status: state.Status,
LastError: state.LastError,
OpenConnections: state.OpenConnections,
TotalConnections: state.TotalConnections,
TotalOutboundData: state.TotalOutboundData,
TotalInboundData: state.TotalInboundData,
SourceState: EndpointState{
Connected: state.SourceState.Connected,
},
DestinationState: EndpointState{
Connected: state.DestinationState.Connected,
},
}
}
}
Expand Down
35 changes: 0 additions & 35 deletions pkg/api/models/forwarding/url.go

This file was deleted.

110 changes: 110 additions & 0 deletions pkg/api/models/synchronization/endpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package synchronization

import (
"github.com/mutagen-io/mutagen/pkg/synchronization"
"github.com/mutagen-io/mutagen/pkg/url"
)

// Endpoint represents a synchronization endpoint.
type Endpoint struct {
// Protocol endpoint transport protocol.
Protocol url.Protocol `json:"protocol"`
// User is the endpoint user.
User string `json:"user,omitempty"`
// Host is the endpoint host.
Host string `json:"host,omitempty"`
// Port is the endpoint port.
Port uint16 `json:"port,omitempty"`
// Path is the synchronization root on the endpoint.
Path string `json:"path,omitempty"`
// Environment is the environment variable map to use for the transport.
Environment map[string]string `json:"environment,omitempty"`
// Parameters is the parameter map to use for the transport.
Parameters map[string]string `json:"parameters,omitempty"`
// Configuration is the endpoint-specific configuration.
Configuration
// Connected indicates whether or not the controller is currently connected
// to the endpoint.
Connected bool `json:"connected"`
// EndpointState stores state fields relevant to connected endpoints. It is
// non-nil if and only if the endpoint is connected.
*EndpointState
}

// EndpointState encodes the current state of a synchronization endpoint.
type EndpointState struct {
// Scanned indicates whether or not at least one scan has been performed on
// the endpoint.
Scanned bool `json:"scanned"`
// Directories is the number of synchronizable directory entries contained
// in the last snapshot from the endpoint.
Directories uint64 `json:"directories,omitempty"`
// Files is the number of synchronizable file entries contained in the last
// snapshot from the endpoint.
Files uint64 `json:"files,omitempty"`
// SymbolicLinks is the number of synchronizable symbolic link entries
// contained in the last snapshot from the endpoint.
SymbolicLinks uint64 `json:"symbolicLinks,omitempty"`
// TotalFileSize is the total size of all synchronizable files referenced by
// the last snapshot from the endpoint.
TotalFileSize uint64 `json:"totalFileSize,omitempty"`
// ScanProblems is the list of non-terminal problems encountered during the
// last scanning operation on the endpoint. This list may be a truncated
// version of the full list if too many problems are encountered to report
// via the API, in which case ExcludedScanProblems will be non-zero.
ScanProblems []Problem `json:"scanProblems,omitempty"`
// ExcludedScanProblems is the number of problems that have been excluded
// from ScanProblems due to truncation. This value can be non-zero only if
// ScanProblems is non-empty.
ExcludedScanProblems uint64 `json:"excludedScanProblems,omitempty"`
// TransitionProblems is the list of non-terminal problems encountered
// during the last transition operation on the endpoint. This list may be a
// truncated version of the full list if too many problems are encountered
// to report via the API, in which case ExcludedTransitionProblems will be
// non-zero.
TransitionProblems []Problem `json:"transitionProblems,omitempty"`
// ExcludedTransitionProblems is the number of problems that have been
// excluded from TransitionProblems due to truncation. This value can be
// non-zero only if TransitionProblems is non-empty.
ExcludedTransitionProblems uint64 `json:"excludedTransitionProblems,omitempty"`
// StagingProgress is the rsync staging progress. It is non-nil if and only
// if the endpoint is currently staging files.
StagingProgress *ReceiverState `json:"stagingProgress,omitempty"`
}

// loadFromInternal sets an Endpoint to match internal Protocol Buffers
// representations. All parameters must be valid.
func (e *Endpoint) loadFromInternal(url *url.URL, configuration *synchronization.Configuration, state *synchronization.EndpointState) {
// Propagate URL parameters.
e.Protocol = url.Protocol
e.User = url.User
e.Host = url.Host
e.Port = uint16(url.Port)
e.Path = url.Path
e.Environment = url.Environment
e.Parameters = url.Parameters

// Propagate configuration.
e.Configuration.loadFromInternal(configuration)

// Propagate connectivity.
e.Connected = state.Connected

// Propagate other state fields.
if !e.Connected {
e.EndpointState = nil
} else {
e.EndpointState = &EndpointState{
Scanned: state.Scanned,
Directories: state.Directories,
Files: state.Files,
SymbolicLinks: state.SymbolicLinks,
TotalFileSize: state.TotalFileSize,
ScanProblems: exportProblems(state.ScanProblems),
ExcludedScanProblems: state.ExcludedScanProblems,
TransitionProblems: exportProblems(state.TransitionProblems),
ExcludedTransitionProblems: state.ExcludedTransitionProblems,
StagingProgress: newReceiverStateFromInternalReceiverState(state.StagingProgress),
}
}
}
File renamed without changes.
Loading

0 comments on commit e7d3581

Please sign in to comment.