<commit_before>package client

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"
)

// NomadServer is connection parameters to a nomad server
type NomadServer struct {
	Address string
	Port    int
}

// Details represents a json object in a nomad job
type Details struct {
	Running int `json:"running"`
}

// Summary represents a json object in a nomad job
type Summary struct {
	Details Details `json:"server"`
}

// JobSummary represents a json object in a nomad job
type JobSummary struct {
	Summary Summary `json:"Summary"`
}

// Job is a representation of nomad job
type Job struct {
	Name       string     `json:"Name"`
	Priority   int        `json:"Priority"`
	Status     string     `json:"status"`
	JobSummary JobSummary `json:"JobSummary"`
}

// Host is a representation of a nomad client node
type Host struct {
	ID    string `json:"ID"`
	Name  string `json:"Name"`
	Drain bool   `json:"Drain"`
}

var httpClient = &http.Client{Timeout: 5 * time.Second}

// Jobs will parse the json representation from the nomad rest api
func Jobs(nomad *NomadServer) []Job {
	jobs := make([]Job, 0)
	decodeJSON(url(nomad)+"/v1/jobs", &jobs)
	return jobs
}

// Hosts will parse the json representation from the nomad rest api
func Hosts(nomad *NomadServer) []Host {
	hosts := make([]Host, 0)
	decodeJSON(url(nomad)+"/v1/nodes", &hosts)
	return hosts
}

func url(nomad *NomadServer) string {
	return fmt.Sprintf("http://%v:%v", nomad.Address, nomad.Port)
}

func decodeJSON(url string, target interface{}) error {
	r, err := httpClient.Get(url)
	if err != nil {
		return err
	}
	defer r.Body.Close()
	return json.NewDecoder(r.Body).Decode(target)
}
<commit_msg>Adding node drain function to framework<commit_after>package client

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"
	"strconv"
)

// NomadServer is connection parameters to a nomad server
type NomadServer struct {
	Address string
	Port    int
}

// Details represents a json object in a nomad job
type Details struct {
	Running int `json:"running"`
}

// Summary represents a json object in a nomad job
type Summary struct {
	Details Details `json:"server"`
}

// JobSummary represents a json object in a nomad job
type JobSummary struct {
	Summary Summary `json:"Summary"`
}

// Job is a representation of nomad job
type Job struct {
	Name       string     `json:"Name"`
	Priority   int        `json:"Priority"`
	Status     string     `json:"status"`
	JobSummary JobSummary `json:"JobSummary"`
}

// Host is a representation of a nomad client node
type Host struct {
	ID    string `json:"ID"`
	Name  string `json:"Name"`
	Drain bool   `json:"Drain"`
}

var httpClient = &http.Client{Timeout: 5 * time.Second}

// Jobs will parse the json representation from the nomad rest api
func Jobs(nomad *NomadServer) []Job {
	jobs := make([]Job, 0)
	decodeJSON(url(nomad)+"/v1/jobs", &jobs)
	return jobs
}

// Hosts will parse the json representation from the nomad rest api
func Hosts(nomad *NomadServer) []Host {
	hosts := make([]Host, 0)
	decodeJSON(url(nomad)+"/v1/nodes", &hosts)
	return hosts
}

func Drain(nomad *NomadServer, id string, enable bool) string {
        client := &http.Client{}
        resp, _ := client.Post(url(nomad) + "/v1/node/" + id + "/drain?enable=" + strconv.FormatBool(enable), "application/json", nil)
        return resp.Status
}

func url(nomad *NomadServer) string {
	return fmt.Sprintf("http://%v:%v", nomad.Address, nomad.Port)
}

func decodeJSON(url string, target interface{}) error {
	r, err := httpClient.Get(url)
	if err != nil {
		return err
	}
	defer r.Body.Close()
	return json.NewDecoder(r.Body).Decode(target)
}

{'fraction_non_alphanumeric': 0.12288956545806809, 'fraction_numerical': 0.003044561306393579, 'mean_word_length': 3.864064602960969, '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': '619851', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1163, 'n_words': 396}