-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Divide agent command into multiple ones by role
- Loading branch information
Showing
10 changed files
with
274 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/bbva/qed/gossip" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type agentContext struct { | ||
config *gossip.Config | ||
} | ||
|
||
func newAgentCommand() *cobra.Command { | ||
var ( | ||
nodeName, bindAddr, advertiseAddr string | ||
startJoin []string | ||
) | ||
|
||
ctx := &agentContext{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "agent", | ||
Short: "Start a gossip agent for the verifiable log QED", | ||
Long: ``, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
config := gossip.DefaultConfig() | ||
config.NodeName = nodeName | ||
config.BindAddr = bindAddr | ||
config.AdvertiseAddr = advertiseAddr | ||
config.EnableCompression = true | ||
ctx.config = config | ||
}, | ||
TraverseChildren: true, | ||
} | ||
|
||
cmd.Flags().StringVarP(&nodeName, "node", "", "", "Unique name for node. If not set, fallback to hostname") | ||
cmd.Flags().StringVarP(&bindAddr, "bind", "", "", "Bind address for TCP/UDP gossip on (host:port)") | ||
cmd.Flags().StringVarP(&advertiseAddr, "advertise", "", "", "Address to advertise to cluster") | ||
cmd.Flags().StringSliceVarP(&startJoin, "join", "", []string{}, "Comma-delimited list of nodes ([host]:port), through which a cluster can be joined") | ||
|
||
cmd.MarkPersistentFlagRequired("node") | ||
cmd.MarkPersistentFlagRequired("bind") | ||
cmd.MarkPersistentFlagRequired("join") | ||
|
||
cmd.AddCommand(newAgentMonitorCommand(ctx)) | ||
cmd.AddCommand(newAgentAuditorCommand(ctx)) | ||
|
||
return cmd | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/bbva/qed/gossip" | ||
"github.com/bbva/qed/log" | ||
"github.com/bbva/qed/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newAgentAuditorCommand(ctx *agentContext) *cobra.Command { | ||
|
||
var qedEndpoints []string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "monitor", | ||
Short: "Start a QED auditor", | ||
Long: `Start a QED auditor that reacts to snapshot batches | ||
propagated by QED servers and periodically executes membership | ||
queries to verify the inclusion of events`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
log.SetLogger("QedAuditor", logLevel) | ||
|
||
config := ctx.config | ||
//auditorConfig := auditor.DefaultConfig() | ||
|
||
agent, err := gossip.NewAgent(config, []gossip.Processor{gossip.DummyProcessor{}}) | ||
if err != nil { | ||
log.Fatalf("Failed to start the QED auditor: %v", err) | ||
} | ||
|
||
contacted, err := agent.Join(config.StartJoin) | ||
if err != nil { | ||
log.Fatalf("Failed to join the cluster: %v", err) | ||
} | ||
log.Debugf("Number of nodes contacted: %d", contacted) | ||
|
||
agent.Start() | ||
defer agent.Shutdown() | ||
util.AwaitTermSignal(agent.Leave) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringSliceVarP(&qedEndpoints, "endpoints", "", []string{}, "Comma-delimited list of QED servers ([host]:port), through which an auditor can make queries") | ||
cmd.MarkPersistentFlagRequired("endpoints") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/bbva/qed/gossip" | ||
"github.com/bbva/qed/log" | ||
"github.com/bbva/qed/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newAgentMonitorCommand(ctx *agentContext) *cobra.Command { | ||
|
||
var qedEndpoints []string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "monitor", | ||
Short: "Start a QED monitor", | ||
Long: `Start a QED monitor that reacts to snapshot batches | ||
propagated by QED servers and periodically executes incremental | ||
queries to verify the consistency between commitments`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
log.SetLogger("QedMonitor", logLevel) | ||
|
||
config := ctx.config | ||
//monitorConfig := monitor.DefaultConfig() | ||
|
||
agent, err := gossip.NewAgent(config, []gossip.Processor{gossip.DummyProcessor{}}) | ||
if err != nil { | ||
log.Fatalf("Failed to start the QED monitor: %v", err) | ||
} | ||
|
||
contacted, err := agent.Join(config.StartJoin) | ||
if err != nil { | ||
log.Fatalf("Failed to join the cluster: %v", err) | ||
} | ||
log.Debugf("Number of nodes contacted: %d", contacted) | ||
|
||
agent.Start() | ||
defer agent.Shutdown() | ||
util.AwaitTermSignal(agent.Leave) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringSliceVarP(&qedEndpoints, "endpoints", "", []string{}, "Comma-delimited list of QED servers ([host]:port), through which a monitor can make queries") | ||
cmd.MarkPersistentFlagRequired("endpoints") | ||
|
||
return cmd | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package auditor | ||
|
||
type Config struct { | ||
} | ||
|
||
func DefaultConfig() *Config { | ||
return nil | ||
} | ||
|
||
type Auditor struct { | ||
} | ||
|
||
func NewAuditor(conf *Config) *Auditor { | ||
return &Auditor{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package monitor | ||
|
||
type Config struct { | ||
} | ||
|
||
func DefaultConfig() *Config { | ||
return nil | ||
} | ||
|
||
type Monitor struct { | ||
} | ||
|
||
func NewMonitor(conf *Config) *Monitor { | ||
return &Monitor{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.