// Execute is part of the Operation interface.
187509
func (rl *resignLeadership) Execute(state State) (*State, error) {
	// TODO(fwereade): this hits a lot of interestingly intersecting problems.
	//
	// 1) we can't yet create a sufficiently dumbed-down hook context for a
	//    leader-deposed hook to run as specced. (This is the proximate issue,
	//    and is sufficient to prevent us from implementing this op right.)
	// 2) we want to write a state-file change, so this has to be an operation
	//    (or, at least, it has to be serialized with all other operations).
	//      * note that the change we write must *not* include the RunHook
	//        operation for leader-deposed -- we want to run this at high
	//        priority, in any possible state, and not to disturn what's
	//        there other than to note that we no longer think we're leader.
	// 3) the hook execution itself *might* not need to be serialized with
	//    other operations, which is moot until we consider that:
	// 4) we want to invoke this behaviour from elsewhere (ie when we don't
	//    have an api connection available), but:
	// 5) we can't get around the serialization requirement in (2).
	//
	// So. I *think* that the right approach is to implement a no-api uniter
	// variant, that we run *instead of* the normal uniter when the API is
	// unavailable, and replace with a real uniter when appropriate; this
	// implies that we need to take care not to allow the implementations to
	// diverge, but implementing them both as "uniters" is probably the best
	// way to encourage logic-sharing and prevent that problem.
	//
	// In the short term, though, we can just run leader-deposed as soon as we
	// can build the right environment. Not sure whether this particular type
	// will still be justified, or whether it'll just be a plain old RunHook --
	// I *think* it will stay, because the state-writing behaviour will stay
	// very different (ie just write `.Leader = false` and don't step on pre-
	// queued hooks).
	logger.Warningf("we should run a leader-deposed hook here, but we can't yet")
	return nil, nil
}
557510
func Execute(name string, stdin string, args ...string) (string, string, error) {
	cmd := exec.Command(name, args...)
	cmd.Stdin = strings.NewReader(stdin)
	stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
	cmd.Stdout = stdout
	cmd.Stderr = stderr

	err := cmd.Run()
	return stdout.String(), stderr.String(), errors.Annotatef(err, "cannot run command %s", name)
}
1196351
func (p *insertPlan) Execute(ctx context.Context) (*table.Table, error) {
	t, err := table.New([]string{})
	if err != nil {
		return nil, err
	}
	return t, update(ctx, p.stm.Data(), p.stm.OutputGraphNames(), p.store, func(g storage.Graph, d []*triple.Triple) error {
		tracer.Trace(p.tracer, func() []string {
			return []string{"Inserting triples to graph \"" + g.ID(ctx) + "\""}
		})
		return g.AddTriples(ctx, d)
	})
}
686280
func (c *Connection) Execute(ex *ExecuteRequest) (*ExecuteResponse, error) {
	c.dbMu.RLock()
	defer c.dbMu.RUnlock()
	if c.db == nil {
		return nil, ErrConnectionDoesNotExist
	}
	return c.store.execute(c, ex)
}
591786
func (command *CapnpCommand) Execute() error {
	var apiDef raml.APIDefinition

	command.Language = strings.ToLower(command.Language)
	if command.Language != "go" && command.Language != "plain" {
		return fmt.Errorf("canpnp generator only support plain & Go-compatible schema")
	}

	log.Debug("Generating capnp models")

	err := raml.ParseFile(command.RAMLFile, &apiDef)
	if err != nil {
		return err
	}
	return codegen.GenerateCapnp(&apiDef, command.Dir, command.Language, command.Package)
}
88199
func (e *remoteExecutor) Execute(command []string, in io.Reader, out, errOut io.Writer) error {
	klog.V(3).Infof("Remote executor running command: %s", strings.Join(command, " "))
	execOptions := &kexec.ExecOptions{
		StreamOptions: kexec.StreamOptions{
			Namespace:     e.Namespace,
			PodName:       e.PodName,
			ContainerName: e.ContainerName,
			IOStreams: genericclioptions.IOStreams{
				In:     in,
				Out:    out,
				ErrOut: errOut,
			},
			Stdin: in != nil,
		},
		SuggestedCmdUsage: e.SuggestedCmdUsage,
		Executor:          &kexec.DefaultRemoteExecutor{},
		PodClient:         e.Client.CoreV1(),
		Config:            e.Config,
		Command:           command,
	}
	err := execOptions.Validate()
	if err != nil {
		klog.V(4).Infof("Error from remote command validation: %v", err)
		return err
	}
	err = execOptions.Run()
	if err != nil {
		klog.V(4).Infof("Error from remote execution: %v", err)
	}
	return err
}
254292
func (e *Executor) Execute(ctx context.Context, method string, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable) (result *sqltypes.Result, err error) {
	span, ctx := trace.NewSpan(ctx, "executor.Execute")
	span.Annotate("method", method)
	trace.AnnotateSQL(span, sql)
	defer span.Finish()

	logStats := NewLogStats(ctx, method, sql, bindVars)
	result, err = e.execute(ctx, safeSession, sql, bindVars, logStats)
	logStats.Error = err

	// The mysql plugin runs an implicit rollback whenever a connection closes.
	// To avoid spamming the log with no-op rollback records, ignore it if
	// it was a no-op record (i.e. didn't issue any queries)
	if !(logStats.StmtType == "ROLLBACK" && logStats.ShardQueries == 0) {
		logStats.Send()
	}
	return result, err
}
222517
func (command *DocsCommand) Execute() error {
	log.Debug("Generating api docs in %s", command.Format)
	apiDef := new(raml.APIDefinition)
	err := raml.ParseFile(command.RamlFile, apiDef)
	if err != nil {
		return err
	}
	return codegen.GenerateDocs(apiDef, command.Format, command.OutputFile)
}
265795
func (p *ListCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
	c.Conf.Debug = p.debug
	c.Conf.DebugSQL = p.debugSQL
	c.Conf.DBPath = p.dbpath
	c.Conf.DBType = p.dbtype
	c.Conf.HTTPProxy = p.httpProxy
	log.SetLogger(p.logDir, c.Conf.Quiet, c.Conf.Debug, p.logJSON)
	if !c.Conf.Validate() {
		return subcommands.ExitUsageError
	}

	driver, locked, err := db.NewDB(c.Conf.DBType, c.Conf.DBPath, c.Conf.DebugSQL)
	if err != nil {
		if locked {
			log.Errorf("Failed to Open DB. Close DB connection: %s", err)
			return subcommands.ExitFailure
		}
		log.Errorf("%s", err)
		return subcommands.ExitFailure
	}
	defer driver.CloseDB()

	jsonMetas, xmlMetas, err := nvd.ListFetchedFeeds(driver)
	if err != nil {
		log.Errorf("%s", err)
		return subcommands.ExitFailure
	}
	sort.Slice(jsonMetas, func(i, j int) bool {
		return jsonMetas[i].URL < jsonMetas[j].URL
	})
	sort.Slice(xmlMetas, func(i, j int) bool {
		return xmlMetas[i].URL < xmlMetas[j].URL
	})

	jvnMetas, err := jvn.ListFetchedFeeds(driver)
	if err != nil {
		log.Errorf("%s", err)
		return subcommands.ExitFailure
	}
	sort.Slice(jvnMetas, func(i, j int) bool {
		return jvnMetas[i].URL < jvnMetas[j].URL
	})

	metas := []models.FeedMeta{}
	for _, mm := range [][]models.FeedMeta{jsonMetas, xmlMetas, jvnMetas} {
		metas = append(metas, mm...)
	}
	data := [][]string{}
	for _, meta := range metas {
		data = append(data, meta.ToTableWriterRow())
	}
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Source", "Year", "Status", "Fetched", "Latest"})
	table.SetBorder(true)
	table.SetHeaderColor(
		tablewriter.Colors{tablewriter.Bold},
		tablewriter.Colors{tablewriter.Bold},
		tablewriter.Colors{tablewriter.Bold},
		tablewriter.Colors{tablewriter.Bold},
		tablewriter.Colors{tablewriter.Bold})
	table.AppendBulk(data)
	table.Render()

	cmds := []string{}
	for _, mm := range [][]models.FeedMeta{jsonMetas, xmlMetas, jvnMetas} {
		cmd := getUpdateCommand(mm)
		if cmd != "" {
			cmds = append(cmds, cmd)
		}
	}

	if 0 < len(cmds) {
		fmt.Printf("\nTo update feeds, execute the following commands.\n")
		for _, cmd := range cmds {
			fmt.Println(cmd)
		}
	}

	return subcommands.ExitSuccess
}
326671
func (s *ServeCmd) Execute(args []string) error {
	if len(args) == 0 {
		return errors.New("specify the spec to serve as argument to the serve command")
	}

	specDoc, err := loads.Spec(args[0])
	if err != nil {
		return err
	}
	b, err := json.MarshalIndent(specDoc.Spec(), "", "  ")
	if err != nil {
		return err
	}

	basePath := s.BasePath
	if basePath == "" {
		basePath = "/"
	}

	listener, err := net.Listen("tcp4", net.JoinHostPort(s.Host, strconv.Itoa(s.Port)))
	if err != nil {
		return err
	}
	sh, sp, err := swag.SplitHostPort(listener.Addr().String())
	if err != nil {
		return err
	}
	if sh == "0.0.0.0" {
		sh = "localhost"
	}

	visit := s.DocURL
	handler := http.NotFoundHandler()
	if !s.NoUI {
		if s.Flavor == "redoc" {
			handler = middleware.Redoc(middleware.RedocOpts{
				BasePath: basePath,
				SpecURL:  path.Join(basePath, "swagger.json"),
				Path:     "docs",
			}, handler)
			visit = fmt.Sprintf("http://%s:%d%s", sh, sp, path.Join(basePath, "docs"))
		} else if visit != "" || s.Flavor == "swagger" {
			if visit == "" {
				visit = "http://petstore.swagger.io/"
			}
			u, err := url.Parse(visit)
			if err != nil {
				return err
			}
			q := u.Query()
			q.Add("url", fmt.Sprintf("http://%s:%d%s", sh, sp, path.Join(basePath, "swagger.json")))
			u.RawQuery = q.Encode()
			visit = u.String()
		}
	}

	handler = handlers.CORS()(middleware.Spec(basePath, b, handler))
	errFuture := make(chan error)
	go func() {
		docServer := new(http.Server)
		docServer.SetKeepAlivesEnabled(true)
		docServer.Handler = handler

		errFuture <- docServer.Serve(listener)
	}()

	if !s.NoOpen && !s.NoUI {
		err := webbrowser.Open(visit)
		if err != nil {
			return err
		}
	}
	log.Println("serving docs at", visit)
	return <-errFuture
}
1198552
func (j *JSONPath) Execute(wr io.Writer, data interface{}) error {
	fullResults, err := j.FindResults(data)
	if err != nil {
		return err
	}
	for ix := range fullResults {
		if err := j.PrintResults(wr, fullResults[ix]); err != nil {
			return err
		}
	}
	return nil
}
1335187
func (s *Shell) Execute(command string, arguments ...string) (*Command, error) {
	request := NewExecuteCommandRequest(s.client.url, s.id, command, arguments, &s.client.Parameters)
	defer request.Free()

	response, err := s.client.sendRequest(request)
	if err != nil {
		return nil, err
	}

	commandID, err := ParseExecuteCommandResponse(response)
	if err != nil {
		return nil, err
	}

	cmd := newCommand(s, commandID)

	return cmd, nil
}
930851
func (del *Delete) Execute(vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
	if del.QueryTimeout != 0 {
		cancel := vcursor.SetContextTimeout(time.Duration(del.QueryTimeout) * time.Millisecond)
		defer cancel()
	}

	switch del.Opcode {
	case DeleteUnsharded:
		return del.execDeleteUnsharded(vcursor, bindVars)
	case DeleteEqual:
		return del.execDeleteEqual(vcursor, bindVars)
	case DeleteScatter:
		return del.execDeleteByDestination(vcursor, bindVars, key.DestinationAllShards{})
	case DeleteByDestination:
		return del.execDeleteByDestination(vcursor, bindVars, del.TargetDestination)
	default:
		// Unreachable.
		return nil, fmt.Errorf("unsupported opcode: %v", del)
	}
}
477388
func Execute(a *Action) error {
	seen := make(map[*Action]error)
	return execute(seen, a)
}
720240
func (p *PreparedQuery) execute(query *structs.PreparedQuery,
	reply *structs.PreparedQueryExecuteResponse,
	forceConnect bool) error {
	state := p.srv.fsm.State()

	// If we're requesting Connect-capable services, then switch the
	// lookup to be the Connect function.
	f := state.CheckServiceNodes
	if query.Service.Connect || forceConnect {
		f = state.CheckConnectServiceNodes
	}

	_, nodes, err := f(nil, query.Service.Service)
	if err != nil {
		return err
	}

	// Filter out any unhealthy nodes.
	nodes = nodes.FilterIgnore(query.Service.OnlyPassing,
		query.Service.IgnoreCheckIDs)

	// Apply the node metadata filters, if any.
	if len(query.Service.NodeMeta) > 0 {
		nodes = nodeMetaFilter(query.Service.NodeMeta, nodes)
	}

	// Apply the service metadata filters, if any.
	if len(query.Service.ServiceMeta) > 0 {
		nodes = serviceMetaFilter(query.Service.ServiceMeta, nodes)
	}

	// Apply the tag filters, if any.
	if len(query.Service.Tags) > 0 {
		nodes = tagFilter(query.Service.Tags, nodes)
	}

	// Capture the nodes and pass the DNS information through to the reply.
	reply.Service = query.Service.Service
	reply.Nodes = nodes
	reply.DNS = query.DNS

	// Stamp the result for this datacenter.
	reply.Datacenter = p.srv.config.Datacenter

	return nil
}
1346321
func (al *acceptLeadership) Execute(state State) (*State, error) {
	return nil, errors.New("prepare always errors; Execute is never valid")
}
76095
func (t *Template) Execute(mapping func(string) string) (str string, err error) {
	b := new(bytes.Buffer)
	s := new(state)
	s.node = t.tree.Root
	s.mapper = mapping
	s.writer = b
	err = t.eval(s)
	if err != nil {
		return
	}
	return b.String(), nil
}