From 64710deb9f75411e70defff5962d3e2fb30f8ba6 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Sat, 13 Nov 2021 06:33:29 -0500 Subject: [PATCH] Delete `go/cmd/automation_{client,server}` Signed-off-by: Andrew Mason --- go/cmd/automation_client/automation_client.go | 138 ------------------ go/cmd/automation_server/automation_server.go | 62 -------- .../plugin_grpcvtctlclient.go | 23 --- .../plugin_grpcvtworkerclient.go | 23 --- 4 files changed, 246 deletions(-) delete mode 100644 go/cmd/automation_client/automation_client.go delete mode 100644 go/cmd/automation_server/automation_server.go delete mode 100644 go/cmd/automation_server/plugin_grpcvtctlclient.go delete mode 100644 go/cmd/automation_server/plugin_grpcvtworkerclient.go diff --git a/go/cmd/automation_client/automation_client.go b/go/cmd/automation_client/automation_client.go deleted file mode 100644 index ebc82a11048..00000000000 --- a/go/cmd/automation_client/automation_client.go +++ /dev/null @@ -1,138 +0,0 @@ -/* -Copyright 2019 The Vitess Authors. - -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 main - -import ( - "flag" - "fmt" - "os" - "strings" - "time" - - "google.golang.org/protobuf/encoding/prototext" - - "context" - - "google.golang.org/grpc" - - "vitess.io/vitess/go/vt/grpcclient" - automationpb "vitess.io/vitess/go/vt/proto/automation" - automationservicepb "vitess.io/vitess/go/vt/proto/automationservice" -) - -var ( - automationServer = flag.String("server", "", "Endpoint to Automation Server e.g. localhost:1234.") - task = flag.String("task", "", "Task which should be run.") -) - -// cmdParams implements flag.Value to store key=value pairs. -type cmdParams struct { - parameters map[string]string -} - -// String implements flag.Value to return the default value. -func (*cmdParams) String() string { return "\"key=value\"" } - -func (p *cmdParams) Get() interface{} { - return p -} - -func (p *cmdParams) Set(v string) error { - if v != "" { - keyAndValue := strings.SplitN(v, "=", 2) - if len(keyAndValue) < 2 { - return fmt.Errorf("no key specified: '%v' Expected format: key=value", v) - } - if p.parameters == nil { - p.parameters = make(map[string]string) - } - p.parameters[keyAndValue[0]] = keyAndValue[1] - } - return nil -} - -func main() { - var params cmdParams - flag.Var(¶ms, "param", "Task Parameter of the form key=value. May be repeated.") - flag.Parse() - - if *task == "" { - fmt.Println("Please specify a task using the --task parameter.") - os.Exit(1) - } - if *automationServer == "" { - fmt.Println("Please specify the automation server address using the --server parameter.") - os.Exit(2) - } - - fmt.Println("Connecting to Automation Server:", *automationServer) - - conn, err := grpcclient.Dial(*automationServer, grpcclient.FailFast(false), grpc.WithInsecure()) - if err != nil { - fmt.Println("Cannot create connection:", err) - os.Exit(3) - } - defer conn.Close() - client := automationservicepb.NewAutomationClient(conn) - - enqueueRequest := &automationpb.EnqueueClusterOperationRequest{ - Name: *task, - Parameters: params.parameters, - } - protoTextReq, _ := prototext.Marshal(enqueueRequest) - fmt.Printf("Sending request:\n%s", protoTextReq) - enqueueResponse, err := client.EnqueueClusterOperation(context.Background(), enqueueRequest, grpc.WaitForReady(true)) - if err != nil { - fmt.Println("Failed to enqueue ClusterOperation. Error:", err) - os.Exit(4) - } - fmt.Println("Operation was enqueued. Details:", enqueueResponse) - resp, errWait := waitForClusterOp(client, enqueueResponse.Id) - if errWait != nil { - fmt.Println("ERROR:", errWait) - os.Exit(5) - } - protoTextResp, _ := prototext.Marshal(resp) - fmt.Printf("SUCCESS: ClusterOperation finished.\n\nDetails:\n%s", protoTextResp) -} - -// waitForClusterOp polls and blocks until the ClusterOperation invocation specified by "id" has finished. If an error occurred, it will be returned. -func waitForClusterOp(client automationservicepb.AutomationClient, id string) (*automationpb.GetClusterOperationDetailsResponse, error) { - for { - req := &automationpb.GetClusterOperationDetailsRequest{ - Id: id, - } - - resp, err := client.GetClusterOperationDetails(context.Background(), req, grpc.WaitForReady(true)) - if err != nil { - return nil, fmt.Errorf("failed to get ClusterOperation Details. Request: %v Error: %v", req, err) - } - - switch resp.ClusterOp.State { - case automationpb.ClusterOperationState_UNKNOWN_CLUSTER_OPERATION_STATE: - return resp, fmt.Errorf("ClusterOperation is in an unknown state. Details: %v", resp) - case automationpb.ClusterOperationState_CLUSTER_OPERATION_DONE: - if resp.ClusterOp.Error != "" { - protoTextResp, _ := prototext.Marshal(resp) - return resp, fmt.Errorf("ClusterOperation failed. Details:\n%s", protoTextResp) - } - return resp, nil - } - - time.Sleep(50 * time.Millisecond) - } -} diff --git a/go/cmd/automation_server/automation_server.go b/go/cmd/automation_server/automation_server.go deleted file mode 100644 index 0d0e3aea84a..00000000000 --- a/go/cmd/automation_server/automation_server.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2019 The Vitess Authors. - -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 main - -import ( - "fmt" - "net" - "os" - - "google.golang.org/grpc" - - "vitess.io/vitess/go/vt/automation" - automationservicepb "vitess.io/vitess/go/vt/proto/automationservice" - "vitess.io/vitess/go/vt/servenv" -) - -func init() { - servenv.RegisterDefaultFlags() -} - -func main() { - servenv.ParseFlags("automation_server") - - fmt.Println("Automation Server, listening on:", *servenv.Port) - - if *servenv.Port == 0 { - fmt.Println("No port specified using --port.") - os.Exit(1) - } - - listener, err := net.Listen("tcp", fmt.Sprintf(":%v", *servenv.Port)) - if err != nil { - fmt.Printf("Failed to listen: %v", err) - os.Exit(2) - } - - grpcServer := grpc.NewServer() - scheduler, err := automation.NewScheduler() - if err != nil { - fmt.Printf("Failed to create scheduler: %v", err) - os.Exit(3) - } - scheduler.Run() - automationservicepb.RegisterAutomationServer(grpcServer, scheduler) - if err := grpcServer.Serve(listener); err != nil { - fmt.Println(err) - } -} diff --git a/go/cmd/automation_server/plugin_grpcvtctlclient.go b/go/cmd/automation_server/plugin_grpcvtctlclient.go deleted file mode 100644 index 6ffff52c5bc..00000000000 --- a/go/cmd/automation_server/plugin_grpcvtctlclient.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2019 The Vitess Authors. - -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 main - -// Imports and register the gRPC vtctl client. - -import ( - _ "vitess.io/vitess/go/vt/vtctl/grpcvtctlclient" -) diff --git a/go/cmd/automation_server/plugin_grpcvtworkerclient.go b/go/cmd/automation_server/plugin_grpcvtworkerclient.go deleted file mode 100644 index 74fa31ef4af..00000000000 --- a/go/cmd/automation_server/plugin_grpcvtworkerclient.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2019 The Vitess Authors. - -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 main - -// Imports and registers the gRPC vtworker client. - -import ( - _ "vitess.io/vitess/go/vt/worker/grpcvtworkerclient" -)