Example #1
0
func executeVtctl(ctx context.Context, server string, args []string, addHeaderAndFooter bool) (string, error) {
	var output bytes.Buffer
	loggerToBufferFunc := createLoggerEventToBufferFunction(&output)
	outputLogger := newOutputLogger(loggerToBufferFunc)

	startMsg := fmt.Sprintf("Executing remote vtctl command: %v server: %v", args, server)
	if addHeaderAndFooter {
		outputLogger.Infof(startMsg)
	}
	log.Info(startMsg)

	err := vtctlclient.RunCommandAndWait(
		ctx, server, args,
		// TODO(mberlin): Should these values be configurable as flags?
		30*time.Second, // dialTimeout
		time.Hour,      // actionTimeout
		createLoggerEventToBufferFunction(&output))

	endMsg := fmt.Sprintf("Executed remote vtctl command: %v server: %v err: %v", args, server, err)
	if addHeaderAndFooter {
		outputLogger.Infof(endMsg)
	}
	// Log full output to log file (but not to the buffer).
	log.Infof("%v output (starting on next line):\n%v", endMsg, output.String())

	return output.String(), err
}
Example #2
0
func main() {
	defer exit.Recover()

	flag.Parse()

	err := vtctlclient.RunCommandAndWait(
		context.Background(), *server, flag.Args(),
		*dialTimeout, *actionTimeout,
		func(e *logutil.LoggerEvent) {
			switch e.Level {
			case logutil.LOGGER_INFO:
				log.Info(e.String())
			case logutil.LOGGER_WARNING:
				log.Warning(e.String())
			case logutil.LOGGER_ERROR:
				log.Error(e.String())
			case logutil.LOGGER_CONSOLE:
				fmt.Print(e.String())
			}
		})
	if err != nil {
		log.Error(err)
		os.Exit(1)
	}
}
Example #3
0
// ExecuteVtctl runs vtctl using vtctlclient. The stream of LoggerEvent messages is concatenated into one output string.
func ExecuteVtctl(ctx context.Context, server string, args []string) (string, error) {
	var output bytes.Buffer

	err := vtctlclient.RunCommandAndWait(
		ctx, server, args,
		// TODO(mberlin): Should these values be configurable as flags?
		30*time.Second, // dialTimeout
		time.Hour,      // actionTimeout
		10*time.Second, // lockWaitTimeout
		CreateLoggerEventToBufferFunction(&output))

	return output.String(), err
}
Example #4
0
// ExecuteVtctl runs vtctl using vtctlclient. The stream of Event
// messages is concatenated into one output string.
func ExecuteVtctl(ctx context.Context, server string, args []string) (string, error) {
	var output bytes.Buffer

	log.Infof("Executing remote vtctl command: %v server: %v", args, server)
	err := vtctlclient.RunCommandAndWait(
		ctx, server, args,
		// TODO(mberlin): Should these values be configurable as flags?
		30*time.Second, // dialTimeout
		time.Hour,      // actionTimeout
		CreateLoggerEventToBufferFunction(&output))
	log.Infof("Executed remote vtctl command: %v server: %v err: %v output (starting on next line):\n%v", args, server, err, output.String())

	return output.String(), err
}
Example #5
0
func main() {
	defer exit.Recover()

	flag.Parse()

	logger := logutil.NewConsoleLogger()

	err := vtctlclient.RunCommandAndWait(
		context.Background(), *server, flag.Args(),
		*dialTimeout, *actionTimeout,
		func(e *logutilpb.Event) {
			logutil.LogEvent(logger, e)
		})
	if err != nil {
		log.Error(err)
		os.Exit(1)
	}
}