<commit_before>// Leader acts as a transient team leader
// It register each service's active locations.
package leader

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"strconv"
	"strings"

	"github.com/chrislusf/glow/resource"
	"github.com/labstack/echo"
)

func (tl *TeamLeader) listAgentsHandler(c *echo.Context) error {
	c.JSON(http.StatusAccepted, tl.LeaderResource.Topology.Resource)
	return nil
}

func (tl *TeamLeader) requestAgentHandler(c *echo.Context) error {
	requestBlob := []byte(c.Request().FormValue("request"))
	var request resource.AllocationRequest
	err := json.Unmarshal(requestBlob, &request)
	if err != nil {
		return fmt.Errorf("request JSON unmarshal error:%v, json:%s", err, string(requestBlob))
	}

	fmt.Printf("request:\n%+v\n", request)

	result := tl.allocate(&request)
	fmt.Printf("result: %v\n%+v\n", result.Error, result.Allocations)
	if result.Error != "" {
		c.JSON(http.StatusNotFound, result)
	}

	c.JSON(http.StatusAccepted, result)

	return nil
}

func (tl *TeamLeader) updateAgentHandler(c *echo.Context) error {
	servicePortString := c.Request().FormValue("servicePort")
	servicePort, err := strconv.Atoi(servicePortString)
	if err != nil {
		log.Printf("Strange: servicePort not found: %s, %v", servicePortString, err)
	}
	host := c.Request().Host<commit_msg>show more data when listing agents<commit_after>// Leader acts as a transient team leader
// It register each service's active locations.
package leader

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"strconv"
	"strings"

	"github.com/chrislusf/glow/resource"
	"github.com/labstack/echo"
)

func (tl *TeamLeader) listAgentsHandler(c *echo.Context) error {
	c.JSON(http.StatusAccepted, tl.LeaderResource.Topology)
	return nil
}

func (tl *TeamLeader) requestAgentHandler(c *echo.Context) error {
	requestBlob := []byte(c.Request().FormValue("request"))
	var request resource.AllocationRequest
	err := json.Unmarshal(requestBlob, &request)
	if err != nil {
		return fmt.Errorf("request JSON unmarshal error:%v, json:%s", err, string(requestBlob))
	}

	fmt.Printf("request:\n%+v\n", request)

	result := tl.allocate(&request)
	fmt.Printf("result: %v\n%+v\n", result.Error, result.Allocations)
	if result.Error != "" {
		c.JSON(http.StatusNotFound, result)
	}

	c.JSON(http.StatusAccepted, result)

	return nil
}

func (tl *TeamLeader) updateAgentHandler(c *echo.Context) error {
	servicePortString := c.Request().FormValue("servicePort")
	servicePort, err := strconv.Atoi(servicePortString)
	if err != nil {
		log.Printf("Strange: servicePort not found: %s, %v", servicePortString, err)
	}
	host := c.Request().Host
{'fraction_non_alphanumeric': 0.14965727341964966, 'fraction_numerical': 0.0, 'mean_word_length': 5.123543123543124, 'pattern_counts': {'":': 0, '<': 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': '524702', 'n_tokens_mistral': 934, 'n_tokens_neox': 913, 'n_words': 204}