<commit_before>package cbboot

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "github.com/gorilla/mux"
    "github.com/sequenceiq/cloudbreak-bootstrap/cbboot/model"
)

const (
    RootPath = "/cbboot"
    HealthEP = RootPath + "/health"
    ServerSaveEP = RootPath + "/server/save"
    ServerDistributeEP = RootPath + "/server/distribute"
    ConsulConfigSaveEP = RootPath + "/consul/config/save"
    ConsulConfigDistributeEP = RootPath + "/consul/config/distribute"
    ConsulRunEP = RootPath + "/consul/run"
    ConsulRunDistributeEP = RootPath + "/consul/run/distribute"
    AmbariRunDistributeEP = RootPath + "/ambari/run/distribute"
    AmbariAgentRunEP = RootPath + "/ambari/agent/run"
    AmbariServerRunEP = RootPath + "/ambari/server/run"
)

func healthCheckHandler(w http.ResponseWriter, req *http.Request) {
    log.Printf("[web] handleHealtchCheck executed")
    cResp := model.Response{Status: "OK"}
    json.NewEncoder(w).Encode(cResp)
}

func NewCloudbreakBootstrapWeb() {

    address := fmt.Sprintf(":%d", determineBootstrapPort())
    username, password := determineAuthCredentials()

    log.Printf("[web] NewCloudbreakBootstrapWeb")

    authenticator := Authenticator{Username:username, Password:password}

    r := mux.NewRouter()
    r.HandleFunc(HealthEP, healthCheckHandler).Methods("GET")
    r.Handle(ServerSaveEP, authenticator.wrap(serverRequestHandler)).Methods("POST")<commit_msg>write to logfile and console<commit_after>package cbboot

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "github.com/gorilla/mux"
    "github.com/sequenceiq/cloudbreak-bootstrap/cbboot/model"
    "os"
    "io"
)

const (
    RootPath = "/cbboot"
    HealthEP = RootPath + "/health"
    ServerSaveEP = RootPath + "/server/save"
    ServerDistributeEP = RootPath + "/server/distribute"
    ConsulConfigSaveEP = RootPath + "/consul/config/save"
    ConsulConfigDistributeEP = RootPath + "/consul/config/distribute"
    ConsulRunEP = RootPath + "/consul/run"
    ConsulRunDistributeEP = RootPath + "/consul/run/distribute"
    AmbariRunDistributeEP = RootPath + "/ambari/run/distribute"
    AmbariAgentRunEP = RootPath + "/ambari/agent/run"
    AmbariServerRunEP = RootPath + "/ambari/server/run"
)

func healthCheckHandler(w http.ResponseWriter, req *http.Request) {
    log.Printf("[web] handleHealtchCheck executed")
    cResp := model.Response{Status: "OK"}
    json.NewEncoder(w).Encode(cResp)
}

func NewCloudbreakBootstrapWeb() {

    logFile, err := os.OpenFile("/var/log/cbboot.log", os.O_APPEND | os.O_CREATE | os.O_RDWR, 0666)
    if err != nil {
        log.Printf("Error opening log file: %v", err)
    }
    defer logFile.Close()
    log.SetOutput(io.MultiWriter(os.Stdout, logFile))

    address := fmt.Sprintf(":%d", determineBootstrapPort())
    username, password := determineAuthCredentials()

    log.Printf("[web] NewCloudbreakBootstrapWeb")

    authenticator := Authenticator{Username:username, Password:password}

    r := mux.NewRouter()
    r.HandleFunc(HealthEP, healthCheckHandler).Methods("GET")
    r.Handle(ServerSaveEP, authenticator.wrap(serverRequestHandler)).Methods("POST")
{'fraction_non_alphanumeric': 0.13362887903736542, 'fraction_numerical': 0.001266624445851805, 'mean_word_length': 4.038277511961723, 'pattern_counts': {'":': 2, '<': 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': '3569412', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1033, 'n_words': 171}