<commit_before>package main

import (
	"chaos-galago/processor/Godeps/_workspace/src/chaos-galago/shared/utils"
	"chaos-galago/processor/Godeps/_workspace/src/github.com/cloudfoundry-community/go-cfclient"
	"chaos-galago/processor/utils"
	"database/sql"
	"fmt"
	"os"
	"strconv"
	"time"
)

var (
	dbConnectionString string
	err                error
	config             *cfclient.Config
)

func init() {
	dbConnectionString, err = sharedUtils.GetDBConnectionDetails()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	config = utils.LoadCFConfig()
	fmt.Println("\nConfig loaded:")
	fmt.Println(config)
}

func freakOut(err error) bool {
	if err != nil {
		fmt.Println("An error has occured")
		fmt.Println(err.Error())
		time.Sleep(60 * time.Second)
		return true
	}
	return false
}

func main() {
	cfClient := cfclient.NewClient(config)
OUTER:
	for {
		db, err := sql.Open("mysql", dbConnectionString)
		if freakOut(err) {
			db.Close()
			continue OUTER
		}
		services := utils.GetBoundApps(db)
		if len(services) == 0 {
			db.Close()
			time.Sleep(60 * time.Second)
			continue OUTER
		}
	SERVICES:
		for _, service := range services {
			if utils.ShouldProcess(service.Frequency, service.LastProcessed) {
				fmt.Printf("\nProcessing chaos for %s", service.AppID)
				err = utils.UpdateLastProcessed(db, service.AppID, utils.TimeNow())
				if freakOut(err) {
					continue SERVICES
				}
				if utils.ShouldRun(service.Probability) {
					fmt.Printf("\nRunning chaos for %s", service.AppID)
					appInstances := cfClient.GetAppInstances(service.AppID)
					if utils.IsAppHealthy(appInstances) {
						fmt.Printf("\nApp %s is Healthy\n", service.AppID)
						chaosInstance := strconv.Itoa(utils.PickAppInstance(appInstances))
						fmt.Printf("\nAbout to kill app instance: %s at index: %s", service.AppID, chaosInstance)
						cfClient.KillAppInstance(service.AppID, chaosInstance)
						err = utils.UpdateLastProcessed(db, service.AppID, utils.TimeNow())
						if freakOut(err) {
							continue SERVICES
						}
					} else {
						fmt.Printf("\nApp %s is unhealthy, skipping\n", service.AppID)
						continue SERVICES
					}
				} else {
					fmt.Printf("\nNot running chaos for %s", service.AppID)
					err = utils.UpdateLastProcessed(db, service.AppID, utils.TimeNow())
					if freakOut(err) {
						continue SERVICES
					}
				}
			} else {
				fmt.Printf("\nSkipping processing chaos for %s", service.AppID)
				continue SERVICES
			}
		}
		db.Close()
		time.Sleep(60 * time.Second)
	}
}
<commit_msg>prevent cfclient password from appearing in logs<commit_after>package main

import (
	"chaos-galago/processor/Godeps/_workspace/src/chaos-galago/shared/utils"
	"chaos-galago/processor/Godeps/_workspace/src/github.com/cloudfoundry-community/go-cfclient"
	"chaos-galago/processor/utils"
	"database/sql"
	"fmt"
	"os"
	"strconv"
	"time"
)

var (
	dbConnectionString string
	err                error
	config             *cfclient.Config
)

func init() {
	dbConnectionString, err = sharedUtils.GetDBConnectionDetails()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	config = utils.LoadCFConfig()
	fmt.Println("\nConfig loaded:")
	fmt.Println("ApiAddress: ", config.ApiAddress)
	fmt.Println("LoginAddress: ", config.LoginAddress)
	fmt.Println("Username: ", config.Username)
	fmt.Println("SkipSslValidation: ", config.SkipSslValidation)
}

func freakOut(err error) bool {
	if err != nil {
		fmt.Println("An error has occured")
		fmt.Println(err.Error())
		time.Sleep(60 * time.Second)
		return true
	}
	return false
}

func main() {
	cfClient := cfclient.NewClient(config)
OUTER:
	for {
		db, err := sql.Open("mysql", dbConnectionString)
		if freakOut(err) {
			db.Close()
			continue OUTER
		}
		services := utils.GetBoundApps(db)
		if len(services) == 0 {
			db.Close()
			time.Sleep(60 * time.Second)
			continue OUTER
		}
	SERVICES:
		for _, service := range services {
			if utils.ShouldProcess(service.Frequency, service.LastProcessed) {
				fmt.Printf("\nProcessing chaos for %s", service.AppID)
				err = utils.UpdateLastProcessed(db, service.AppID, utils.TimeNow())
				if freakOut(err) {
					continue SERVICES
				}
				if utils.ShouldRun(service.Probability) {
					fmt.Printf("\nRunning chaos for %s", service.AppID)
					appInstances := cfClient.GetAppInstances(service.AppID)
					if utils.IsAppHealthy(appInstances) {
						fmt.Printf("\nApp %s is Healthy\n", service.AppID)
						chaosInstance := strconv.Itoa(utils.PickAppInstance(appInstances))
						fmt.Printf("\nAbout to kill app instance: %s at index: %s", service.AppID, chaosInstance)
						cfClient.KillAppInstance(service.AppID, chaosInstance)
						err = utils.UpdateLastProcessed(db, service.AppID, utils.TimeNow())
						if freakOut(err) {
							continue SERVICES
						}
					} else {
						fmt.Printf("\nApp %s is unhealthy, skipping\n", service.AppID)
						continue SERVICES
					}
				} else {
					fmt.Printf("\nNot running chaos for %s", service.AppID)
					err = utils.UpdateLastProcessed(db, service.AppID, utils.TimeNow())
					if freakOut(err) {
						continue SERVICES
					}
				}
			} else {
				fmt.Printf("\nSkipping processing chaos for %s", service.AppID)
				continue SERVICES
			}
		}
		db.Close()
		time.Sleep(60 * time.Second)
	}
}

{'fraction_non_alphanumeric': 0.12941847206385404, 'fraction_numerical': 0.003040668947168377, 'mean_word_length': 3.3785357737104826, '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': '1256703', 'n_tokens_mistral': 2145, 'n_tokens_neox': 1810, 'n_words': 357}