<commit_before>package main

import (
	"encoding/gob"
	"fmt"
	"os"

	"github.com/Symantec/Dominator/lib/json"
	"github.com/Symantec/Dominator/lib/log"
	"github.com/Symantec/Dominator/lib/srpc"
	proto "github.com/Symantec/Dominator/proto/hypervisor"
)

func getUpdatesSubcommand(args []string, logger log.DebugLogger) {
	if err := getUpdates(logger); err != nil {
		fmt.Fprintf(os.Stderr, "Error getting updates: %s\n", err)
		os.Exit(1)
	}
	os.Exit(0)
}

func getUpdates(logger log.DebugLogger) error {
	hypervisor := fmt.Sprintf("%s:%d", *hypervisorHostname, *hypervisorPortNum)
	return getUpdatesOnHypervisor(hypervisor, logger)
}

func getUpdatesOnHypervisor(hypervisor string, logger log.DebugLogger) error {
	client, err := srpc.DialHTTP("tcp", hypervisor, 0)
	if err != nil {
		return err
	}
	defer client.Close()
	conn, err := client.Call("Hypervisor.GetUpdates")
	if err != nil {
		return err
	}
	defer conn.Close()
	decoder := gob.NewDecoder(conn)
	for {
		var update proto.Update
		if err := decoder.Decode(&update); err != nil {
			return err
		}
		if err := json.WriteWithIndent(os.Stdout, "    ", update); err != nil {
			return err
		}
	}
	return nil
}
<commit_msg>Extend vm-control get-updates subcommand to query Fleet Manager.<commit_after>package main

import (
	"encoding/gob"
	"fmt"
	"os"

	"github.com/Symantec/Dominator/lib/json"
	"github.com/Symantec/Dominator/lib/log"
	"github.com/Symantec/Dominator/lib/srpc"
	fm_proto "github.com/Symantec/Dominator/proto/fleetmanager"
	hyper_proto "github.com/Symantec/Dominator/proto/hypervisor"
)

func getUpdatesSubcommand(args []string, logger log.DebugLogger) {
	if err := getUpdates(logger); err != nil {
		fmt.Fprintf(os.Stderr, "Error getting updates: %s\n", err)
		os.Exit(1)
	}
	os.Exit(0)
}

func getUpdates(logger log.DebugLogger) error {
	if *hypervisorHostname != "" {
		return getUpdatesOnHypervisor(
			fmt.Sprintf("%s:%d", *hypervisorHostname, *hypervisorPortNum),
			logger)
	} else if *fleetManagerHostname != "" {
		return getUpdatesOnFleetManager(
			fmt.Sprintf("%s:%d", *fleetManagerHostname, *fleetManagerPortNum),
			logger)
	} else {
		return getUpdatesOnHypervisor(fmt.Sprintf(":%d", *hypervisorPortNum),
			logger)
	}

}

func getUpdatesOnFleetManager(fleetManager string,
	logger log.DebugLogger) error {
	client, err := srpc.DialHTTP("tcp", fleetManager, 0)
	if err != nil {
		return err
	}
	defer client.Close()
	conn, err := client.Call("FleetManager.GetUpdates")
	if err != nil {
		return err
	}
	defer conn.Close()
	encoder := gob.NewEncoder(conn)
	request := fm_proto.GetUpdatesRequest{Location: *location}
	if err := encoder.Encode(request); err != nil {
		return err
	}
	if err := conn.Flush(); err != nil {
		return err
	}
	decoder := gob.NewDecoder(conn)
	for {
		var update fm_proto.Update
		if err := decoder.Decode(&update); err != nil {
			return err
		}
		if err := json.WriteWithIndent(os.Stdout, "    ", update); err != nil {
			return err
		}
	}
	return nil
}

func getUpdatesOnHypervisor(hypervisor string, logger log.DebugLogger) error {
	client, err := srpc.DialHTTP("tcp", hypervisor, 0)
	if err != nil {
		return err
	}
	defer client.Close()
	conn, err := client.Call("Hypervisor.GetUpdates")
	if err != nil {
		return err
	}
	defer conn.Close()
	decoder := gob.NewDecoder(conn)
	for {
		var update hyper_proto.Update
		if err := decoder.Decode(&update); err != nil {
			return err
		}
		if err := json.WriteWithIndent(os.Stdout, "    ", update); err != nil {
			return err
		}
	}
	return nil
}

{'fraction_non_alphanumeric': 0.14082098061573547, 'fraction_numerical': 0.0019954389965792475, 'mean_word_length': 4.190828402366864, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3074191', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1284, 'n_words': 276}