func (s *System) Handle(protoCmd *proto.Cmd) *proto.Reply { args := []string{ "--sleep", PT_SLEEP_SECONDS, } ptSummary := cmd.NewRealCmd(s.CmdName, args...) output, err := ptSummary.Run() if err != nil { s.logger.Error(fmt.Sprintf("%s: %s", s.CmdName, err)) } result := &proto.SysinfoResult{ Raw: output, } return protoCmd.Reply(result, err) }
func (m *MySQL) Handle(protoCmd *proto.Cmd) *proto.Reply { // Get service instance serviceInstance, err := getServiceInstance(protoCmd) if err != nil { return protoCmd.Reply(nil, err) } // Load the MySQL instance info (DSN, name, etc.). mysqlIt := &proto.MySQLInstance{} if err = m.ir.Get(serviceInstance.Service, serviceInstance.InstanceId, mysqlIt); err != nil { return protoCmd.Reply(nil, err) } // Parse DSN to get user, pass, host, port, socket as separate fields // @todo parsing DSN should be as a method on proto.MySQLInstance.DSN or at least parser should be injected dsn, err := NewDSN(mysqlIt.DSN) if err != nil { return protoCmd.Reply(nil, err) } // Create params for ptMySQLSummary args := CreateParamsForPtMySQLSummary(dsn) // Run ptMySQLSummary with params ptMySQLSummary := cmd.NewRealCmd(m.CmdName, args...) output, err := ptMySQLSummary.Run() if err != nil { m.logger.Error(fmt.Sprintf("%s: %s", m.CmdName, err)) } result := &proto.SysinfoResult{ Raw: output, } return protoCmd.Reply(result, err) }
func (s *TestSuite) TestCmdNotFound(t *C) { unknownCmd := cmd.NewRealCmd("unknown-cmd") output, err := unknownCmd.Run() t.Assert(output, Equals, "") t.Assert(err, Equals, cmd.ErrNotFound) }