<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"strings"
	"time"

	"github.com/cloudfoundry-incubator/cf-debug-server"
	"github.com/cloudfoundry-incubator/cf-lager"
	"github.com/cloudfoundry-incubator/file-server/handlers"
	"github.com/cloudfoundry-incubator/runtime-schema/bbs/shared"
	"github.com/cloudfoundry-incubator/runtime-schema/heartbeater"
	Router "github.com/cloudfoundry-incubator/runtime-schema/router"
	"github.com/cloudfoundry/gunk/group_runner"
	"github.com/cloudfoundry/gunk/localip"
	"github.com/cloudfoundry/storeadapter/etcdstoreadapter"
	"github.com/cloudfoundry/storeadapter/workerpool"
	uuid "github.com/nu7hatch/gouuid"
	"github.com/pivotal-golang/lager"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/http_server"
	"github.com/tedsuo/ifrit/sigmon"
)

var serverAddress = flag.String(
	"address",
	"",
	"Specifies the address to bind to",
)

var etcdCluster = flag.String(
	"etcdCluster",
	"http://127.0.0.1:4001",
	"comma-separated list of etcd addresses (http://ip:port)",
)

var staticDirectory = flag.String(
	"staticDirectory",
	"",
	"Specifies the directory to serve local static files from",
)

var serverPort = flag.Int(
	"port",
	8080,
	"Specifies the port of the file server",
)

var ccPassword = flag.String(
	"ccPassword",
	"",
	"CloudController basic auth password",
)

var ccUsername = flag.String(
	"ccUsername",
	"",
	"CloudController basic auth username",
)

var ccAddress = flag.String(
	"ccAddress",
	"",
	"CloudController location",
)

var heartbeatInterval = flag.Duration(
	"heartbeatInterval",
	60*time.Second,
	"the interval between heartbeats for maintaining presence",
)

var skipCertVerify = flag.Bool(
	"skipCertVerify",
	false,
	"Skip SSL certificate verification",
)

var ccJobPollingInterval = flag.Duration(
	"ccJobPollingInterval",
	100*time.Millisecond,
	"the interval between job polling requests",
)

func main() {
	flag.Parse()

	logger := cf_lager.New("file-server")
	cf_debug_server.Run()

	group := group_runner.New([]group_runner.Member{
		{"file server", initializeServer(logger)},
		{"maintainer", initializeHeartbeater(logger)},
	})

	monitor := ifrit.Envoke(sigmon.New(group))
	logger.Info("ready")

	err := <-monitor.Wait()
	if err != nil {
		logger.Fatal("exited-with-failure", err)
	}
}

func initializeHeartbeater(logger lager.Logger) heartbeater.Heartbeater {
	if *serverAddress == "" {
		var err error
		*serverAddress, err = localip.LocalIP()
		if err != nil {
			logger.Fatal("obtaining-local-ip-failed", err)
		}
	}

	url := fmt.Sprintf("http://%s:%d/", *serverAddress, *serverPort)
	logger.Info("serving-files-location", lager.Data{"url": url})

	id, err := uuid.NewV4()
	if err != nil {
		logger.Fatal("create-uuid-failed", err)
	}

	etcdAdapter := etcdstoreadapter.NewETCDStoreAdapter(
		strings.Split(*etcdCluster, ","),
		workerpool.NewWorkerPool(10),
	)

	err = etcdAdapter.Connect()
	if err != nil {
		logger.Fatal("failed-to-connect-to-etcd", err)
	}

	return heartbeater.New(etcdAdapter, shared.FileServerSchemaPath(id.String()), url, *heartbeatInterval, logger)
}

func initializeServer(logger lager.Logger) ifrit.Runner {
	if *staticDirectory == "" {
		logger.Fatal("static-directory-missing", nil)
	}
	if *ccAddress == "" {
		logger.Fatal("cc-address-missing", nil)
	}
	if *ccUsername == "" {
		logger.Fatal("cc-username-missing", nil)
	}
	if *ccPassword == "" {
		logger.Fatal("cc-password-missing", nil)
	}

	actions := handlers.New(handlers.Config{
		CCJobPollingInterval: *ccJobPollingInterval,
		CCAddress:            *ccAddress,
		CCPassword:           *<PASSWORD>,
		CCUsername:           *ccUsername,
		SkipCertVerify:       *skipCertVerify,
		StaticDirectory:      *staticDirectory,
	}, logger)

	router, err := Router.NewFileServerRoutes().Router(actions)

	if err != nil {
		logger.Error("router-building-failed", err)
		os.Exit(1)<commit_msg>use the bbs file server heartbeat<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"strings"
	"time"

	"github.com/cloudfoundry-incubator/cf-debug-server"
	"github.com/cloudfoundry-incubator/cf-lager"
	"github.com/cloudfoundry-incubator/file-server/handlers"
	Bbs "github.com/cloudfoundry-incubator/runtime-schema/bbs"
	Router "github.com/cloudfoundry-incubator/runtime-schema/router"
	"github.com/cloudfoundry/gunk/group_runner"
	"github.com/cloudfoundry/gunk/localip"
	"github.com/cloudfoundry/gunk/timeprovider"
	"github.com/cloudfoundry/storeadapter/etcdstoreadapter"
	"github.com/cloudfoundry/storeadapter/workerpool"
	uuid "github.com/nu7hatch/gouuid"
	"github.com/pivotal-golang/lager"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/http_server"
	"github.com/tedsuo/ifrit/sigmon"
)

var serverAddress = flag.String(
	"address",
	"",
	"Specifies the address to bind to",
)

var etcdCluster = flag.String(
	"etcdCluster",
	"http://127.0.0.1:4001",
	"comma-separated list of etcd addresses (http://ip:port)",
)

var staticDirectory = flag.String(
	"staticDirectory",
	"",
	"Specifies the directory to serve local static files from",
)

var serverPort = flag.Int(
	"port",
	8080,
	"Specifies the port of the file server",
)

var ccPassword = flag.String(
	"ccPassword",
	"",
	"CloudController basic auth password",
)

var ccUsername = flag.String(
	"ccUsername",
	"",
	"CloudController basic auth username",
)

var ccAddress = flag.String(
	"ccAddress",
	"",
	"CloudController location",
)

var heartbeatInterval = flag.Duration(
	"heartbeatInterval",
	60*time.Second,
	"the interval between heartbeats for maintaining presence",
)

var skipCertVerify = flag.Bool(
	"skipCertVerify",
	false,
	"Skip SSL certificate verification",
)

var ccJobPollingInterval = flag.Duration(
	"ccJobPollingInterval",
	100*time.Millisecond,
	"the interval between job polling requests",
)

func main() {
	flag.Parse()

	logger := cf_lager.New("file-server")
	cf_debug_server.Run()

	group := group_runner.New([]group_runner.Member{
		{"file server", initializeServer(logger)},
		{"maintainer", initializeHeartbeater(logger)},
	})

	monitor := ifrit.Envoke(sigmon.New(group))
	logger.Info("ready")

	err := <-monitor.Wait()
	if err != nil {
		logger.Fatal("exited-with-failure", err)
	}
}

func initializeHeartbeater(logger lager.Logger) ifrit.Runner {
	etcdAdapter := etcdstoreadapter.NewETCDStoreAdapter(
		strings.Split(*etcdCluster, ","),
		workerpool.NewWorkerPool(10),
	)

	err := etcdAdapter.Connect()
	if err != nil {
		logger.Fatal("failed-to-connect-to-etcd", err)
	}

	bbs := Bbs.NewFileServerBBS(etcdAdapter, timeprovider.NewTimeProvider(), logger)

	if *serverAddress == "" {
		var err error
		*serverAddress, err = localip.LocalIP()
		if err != nil {
			logger.Fatal("obtaining-local-ip-failed", err)
		}
	}

	url := fmt.Sprintf("http://%s:%d/", *serverAddress, *serverPort)
	logger.Info("serving-files-location", lager.Data{"url": url})

	id, err := uuid.NewV4()
	if err != nil {
		logger.Fatal("create-uuid-failed", err)
	}

	return bbs.NewFileServerHeartbeat(url, id.String(), *heartbeatInterval)
}

func initializeServer(logger lager.Logger) ifrit.Runner {
	if *staticDirectory == "" {
		logger.Fatal("static-directory-missing", nil)
	}
	if *ccAddress == "" {
		logger.Fatal("cc-address-missing", nil)
	}
	if *ccUsername == "" {
		logger.Fatal("cc-username-missing", nil)
	}
	if *ccPassword == "" {
		logger.Fatal("cc-password-missing", nil)
	}

	actions := handlers.New(handlers.Config{
		CCJobPollingInterval: *ccJobPollingInterval,
		CCAddress:            *ccAddress,
		CCPassword:           *ccPassword,
		CCUsername:           *ccUsername,
		SkipCertVerify:       *skipCertVerify,
		StaticDirectory:      *staticDirectory,
	}, logger)

	router, err := Router.NewFileServerRoutes().Router(actions)

	if err != nil {
		logger.Error("router-building-failed", err)
		os.Exit(1)
{'fraction_non_alphanumeric': 0.14965197215777262, 'fraction_numerical': 0.006187161639597835, 'mean_word_length': 4.655247813411079, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6727479', 'n_tokens_mistral': 2888, 'n_tokens_neox': 2746, 'n_words': 489}