Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ziti agent snapshot-db match ziti fabric db snapshot. Fixes #2333 #2358

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
$(go env GOPATH)/bin/ziti-ci configure-git
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
go test ./...
pushd zititest && go install ./... && popd
pushd zititest && go mod tidy && go install ./... && popd
go install -tags=all,tests ./...

- name: Create Test Environment
Expand Down Expand Up @@ -313,7 +313,7 @@ jobs:
run: |
$(go env GOPATH)/bin/ziti-ci configure-git
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version ${ZITI_BASE_VERSION:+--base-version $ZITI_BASE_VERSION}
pushd zititest && go install ./... && popd
pushd zititest && go mod tidy && go install ./... && popd
go install -tags=all,tests ./...

- name: Create Test Environment
Expand Down
13 changes: 8 additions & 5 deletions controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
const (
AgentAppId byte = 1

AgentIdHeader = 10
AgentAddrHeader = 11
AgentIsVoterHeader = 12
AgentIdHeader = 10
AgentAddrHeader = 11
AgentIsVoterHeader = 12
AgentSnapshotFileName = 13
)

func (self *Controller) RegisterAgentBindHandler(bindHandler channel.BindHandler) {
Expand Down Expand Up @@ -67,12 +68,14 @@ func (self *Controller) HandleCustomAgentAsyncOp(conn net.Conn) error {
}

func (self *Controller) agentOpSnapshotDb(m *channel.Message, ch channel.Channel) {
fileName, _ := m.GetStringHeader(AgentSnapshotFileName)

log := pfxlog.Logger()
if err := self.network.SnapshotDatabase(); err != nil {
if path, err := self.network.SnapshotDatabaseToFile(fileName); err != nil {
log.WithError(err).Error("failed to snapshot db")
handler_common.SendOpResult(m, ch, "db.snapshot", err.Error(), false)
} else {
handler_common.SendOpResult(m, ch, "db.snapshot", "", true)
handler_common.SendOpResult(m, ch, "db.snapshot", path, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/agentcli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewAgentCmd(p common.OptionsProvider) *cobra.Command {
}

agentCmd.AddCommand(ctrlCmd)
ctrlCmd.AddCommand(NewSimpleChAgentCustomCmd("snapshot-db", AgentAppController, int32(mgmt_pb.ContentType_SnapshotDbRequestType), p))
ctrlCmd.AddCommand(NewAgentSnapshotDb(p))
ctrlCmd.AddCommand(NewAgentCtrlInit(p))
ctrlCmd.AddCommand(NewAgentCtrlInitFromDb(p))

Expand Down
71 changes: 71 additions & 0 deletions ziti/cmd/agentcli/agent_snapshot_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright NetFoundry Inc.

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

https://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 agentcli

import (
"fmt"
"github.com/openziti/channel/v2"
"github.com/openziti/ziti/common/pb/mgmt_pb"
"github.com/openziti/ziti/controller"
"github.com/openziti/ziti/ziti/cmd/common"
"github.com/spf13/cobra"
)

type AgentSnapshoptDbAction struct {
AgentOptions
}

func NewAgentSnapshotDb(p common.OptionsProvider) *cobra.Command {
action := &AgentSnapshoptDbAction{
AgentOptions: AgentOptions{
CommonOptions: p(),
},
}

cmd := &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "snapshot-db <snapshot path>",
RunE: func(cmd *cobra.Command, args []string) error {
action.Cmd = cmd
action.Args = args
return action.MakeChannelRequest(byte(AgentAppController), action.makeRequest)
},
}
cmd.Args = cobra.MaximumNArgs(1)
action.AddAgentOptions(cmd)

return cmd
}

func (self *AgentSnapshoptDbAction) makeRequest(ch channel.Channel) error {
msg := channel.NewMessage(int32(mgmt_pb.ContentType_SnapshotDbRequestType), nil)
if len(self.Args) > 0 {
msg.PutStringHeader(controller.AgentSnapshotFileName, self.Args[0])
}

reply, err := msg.WithTimeout(self.timeout).SendForReply(ch)
if err != nil {
return err
}
result := channel.UnmarshalResult(reply)
if result.Success {
fmt.Println(result.Message)
} else {
fmt.Printf("error: %v\n", result.Message)
}
return nil
}
5 changes: 5 additions & 0 deletions zititest/models/dtls/configs/router.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ metrics:
reportInterval: 15s
messageQueueSize: 10

transport:
westworld3:
profile_version: 1
#max_segment_sz: 3000

link:
listeners:
- binding: transport
Expand Down
Loading