<commit_before>package cloudfoundry

import (
	"fmt"
	"strings"

	"github.com/codegangsta/cli"
	"github.com/enaml-ops/enaml"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/auctioneer"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/cc_uploader"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/converger"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/file_server"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/nsync"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/route_emitter"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/ssh_proxy"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/stager"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/tps"
	"github.com/enaml-ops/pluginlib/util"
	"github.com/xchapter7x/lo"
)

func NewDiegoBrainPartition(c *cli.Context) InstanceGrouper {
	caCert, err := pluginutil.LoadResourceFromContext(c, "bbs-ca-cert")
	if err != nil {
		lo.G.Fatalf("bbs ca cert: %s\n", err.Error())
	}

	clientCert, err := pluginutil.LoadResourceFromContext(c, "bbs-client-cert")
	if err != nil {
		lo.G.Fatalf("bbs client cert: %s\n", err.Error())
	}

	clientKey, err := pluginutil.LoadResourceFromContext(c, "bbs-client-key")
	if err != nil {
		lo.G.Fatalf("bbs client key: %s\n", err.Error())
	}
	return &diegoBrain{
		AZs:                       c.StringSlice("az"),
		StemcellName:              c.String("stemcell-name"),
		VMTypeName:                c.String("diego-brain-vm-type"),
		PersistentDiskType:        c.String("diego-brain-disk-type"),
		NetworkName:               c.String("network"),
		NetworkIPs:                c.StringSlice("diego-brain-ip"),
		BBSCACert:                 caCert,
		BBSClientCert:             clientCert,
		BBSClientKey:              clientKey,
		BBSAPILocation:            c.String("bbs-api"),
		BBSRequireSSL:             c.BoolT("bbs-require-ssl"),
		SkipSSLCertVerify:         c.BoolT("skip-cert-verify"),
		CCUploaderJobPollInterval: c.Int("cc-uploader-poll-interval"),
		SystemDomain:              c.String("system-domain"),
		CCInternalAPIUser:         c.String("cc-internal-api-user"),
		CCInternalAPIPassword:     c.String("<PASSWORD>"),
		CCFetchTimeout:            c.Int("cc-fetch-timeout"),
		CCBulkBatchSize:           c.Int("cc-bulk-batch-size"),
		FSListenAddr:              c.String("fs-listen-addr"),
		FSStaticDirectory:         c.String("fs-static-dir"),
		FSDebugAddr:               c.String("fs-debug-addr"),
		FSLogLevel:                c.String("fs-log-level"),
		MetronPort:                c.Int("metron-port"),
		NATSUser:                  c.String("nats-user"),
		NATSPassword:              c.String("nats-pass"),
		NATSPort:                  c.Int("nats-port"),
		NATSMachines:              c.StringSlice("nats-machine-ip"),
		AllowSSHAccess:            c.Bool("allow-app-ssh-access"),
		SSHProxyClientSecret:      c.String("ssh-proxy-uaa-secret"),
		CCExternalPort:            c.Int("cc-external-port"),
		TrafficControllerURL:      c.String("traffic-controller-url"),
		ConsulAgent:               NewConsulAgent(c, []string{}),
		Metron:                    NewMetron(c),
		Statsd:                    NewStatsdInjector(c),
	}
}

func (d *diegoBrain) ToInstanceGroup() *enaml.InstanceGroup {
	ig := &enaml.InstanceGroup{
		Name:               "diego_brain-partition",
		Instances:          len(d.NetworkIPs),
		VMType:             d.VMTypeName,
		AZs:                d.AZs,
		PersistentDiskType: d.PersistentDiskType,
		Stemcell:           d.StemcellName,
		Networks: []enaml.Network{
			{Name: d.NetworkName, StaticIPs: d.NetworkIPs},
		},
		Update: enaml.Update{
			MaxInFlight: 1,
		},
	}
	consulJob := d.ConsulAgent.CreateJob()
	metronJob := d.Metron.CreateJob()
	statsdJob := d.Statsd.CreateJob()

	ig.AddJob(d.newAuctioneer())
	ig.AddJob(d.newCCUploader())
	ig.AddJob(d.newConverger())
	ig.AddJob(d.newFileServer())
	ig.AddJob(d.newNsync())
	ig.AddJob(d.newRouteEmitter())
	ig.AddJob(d.newSSHProxy())
	ig.AddJob(d.newStager())
	ig.AddJob(d.newTPS())
	ig.AddJob(&consulJob)
	ig.AddJob(&metronJob)
	ig.AddJob(&statsdJob)
	return ig
}

func (d *diegoBrain) HasValidValues() bool {
	return len(d.AZs) > 0 &&
		d.StemcellName != "" &&
		len(d.NetworkIPs) > 0 &&
		d.VMTypeName != "" &&
		d.PersistentDiskType != "" &&
		d.NetworkName != "" &&
		d.BBSCACert != "" &&
		d.BBSClientCert != "" &&
		d.BBSClientKey != "" &&
		d.BBSAPILocation != "" &&
		d.CCInternalAPIUser != "" &&
		d.CCInternalAPIPassword != "" &&
		d.SystemDomain != "" &&
		d.ConsulAgent.HasValidValues() &&
		d.Metron.HasValidValues()
}<commit_msg>[#125968975] adding field error log output for diego brain flags<commit_after>package cloudfoundry

import (
	"fmt"
	"strings"

	"github.com/codegangsta/cli"
	"github.com/enaml-ops/enaml"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/auctioneer"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/cc_uploader"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/converger"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/file_server"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/nsync"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/route_emitter"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/ssh_proxy"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/stager"
	"github.com/enaml-ops/omg-product-bundle/products/cloudfoundry/enaml-gen/tps"
	"github.com/enaml-ops/pluginlib/util"
	"github.com/xchapter7x/lo"
)

func NewDiegoBrainPartition(c *cli.Context) InstanceGrouper {
	caCert, err := pluginutil.LoadResourceFromContext(c, "bbs-ca-cert")
	if err != nil {
		lo.G.Fatalf("bbs ca cert: %s\n", err.Error())
	}

	clientCert, err := pluginutil.LoadResourceFromContext(c, "bbs-client-cert")
	if err != nil {
		lo.G.Fatalf("bbs client cert: %s\n", err.Error())
	}

	clientKey, err := pluginutil.LoadResourceFromContext(c, "bbs-client-key")
	if err != nil {
		lo.G.Fatalf("bbs client key: %s\n", err.Error())
	}
	return &diegoBrain{
		AZs:                       c.StringSlice("az"),
		StemcellName:              c.String("stemcell-name"),
		VMTypeName:                c.String("diego-brain-vm-type"),
		PersistentDiskType:        c.String("diego-brain-disk-type"),
		NetworkName:               c.String("network"),
		NetworkIPs:                c.StringSlice("diego-brain-ip"),
		BBSCACert:                 caCert,
		BBSClientCert:             clientCert,
		BBSClientKey:              clientKey,
		BBSAPILocation:            c.String("bbs-api"),
		BBSRequireSSL:             c.BoolT("bbs-require-ssl"),
		SkipSSLCertVerify:         c.BoolT("skip-cert-verify"),
		CCUploaderJobPollInterval: c.Int("cc-uploader-poll-interval"),
		SystemDomain:              c.String("system-domain"),
		CCInternalAPIUser:         c.String("cc-internal-api-user"),
		CCInternalAPIPassword:     c.String("cc-internal-api-password"),
		CCFetchTimeout:            c.Int("cc-fetch-timeout"),
		CCBulkBatchSize:           c.Int("cc-bulk-batch-size"),
		FSListenAddr:              c.String("fs-listen-addr"),
		FSStaticDirectory:         c.String("fs-static-dir"),
		FSDebugAddr:               c.String("fs-debug-addr"),
		FSLogLevel:                c.String("fs-log-level"),
		MetronPort:                c.Int("metron-port"),
		NATSUser:                  c.String("nats-user"),
		NATSPassword:              c.String("nats-pass"),
		NATSPort:                  c.Int("nats-port"),
		NATSMachines:              c.StringSlice("nats-machine-ip"),
		AllowSSHAccess:            c.Bool("allow-app-ssh-access"),
		SSHProxyClientSecret:      c.String("ssh-proxy-uaa-secret"),
		CCExternalPort:            c.Int("cc-external-port"),
		TrafficControllerURL:      c.String("traffic-controller-url"),
		ConsulAgent:               NewConsulAgent(c, []string{}),
		Metron:                    NewMetron(c),
		Statsd:                    NewStatsdInjector(c),
	}
}

func (d *diegoBrain) ToInstanceGroup() *enaml.InstanceGroup {
	ig := &enaml.InstanceGroup{
		Name:               "diego_brain-partition",
		Instances:          len(d.NetworkIPs),
		VMType:             d.VMTypeName,
		AZs:                d.AZs,
		PersistentDiskType: d.PersistentDiskType,
		Stemcell:           d.StemcellName,
		Networks: []enaml.Network{
			{Name: d.NetworkName, StaticIPs: d.NetworkIPs},
		},
		Update: enaml.Update{
			MaxInFlight: 1,
		},
	}
	consulJob := d.ConsulAgent.CreateJob()
	metronJob := d.Metron.CreateJob()
	statsdJob := d.Statsd.CreateJob()

	ig.AddJob(d.newAuctioneer())
	ig.AddJob(d.newCCUploader())
	ig.AddJob(d.newConverger())
	ig.AddJob(d.newFileServer())
	ig.AddJob(d.newNsync())
	ig.AddJob(d.newRouteEmitter())
	ig.AddJob(d.newSSHProxy())
	ig.AddJob(d.newStager())
	ig.AddJob(d.newTPS())
	ig.AddJob(&consulJob)
	ig.AddJob(&metronJob)
	ig.AddJob(&statsdJob)
	return ig
}

func (d *diegoBrain) HasValidValues() bool {

	lo.G.Debugf("checking '%s' for valid flags", "diego brain")

	if len(d.AZs) <= 0 {
		lo.G.Debugf("could not find the correct number of AZs configured '%v' : '%v'", len(d.AZs), d.AZs)
	}

	if len(d.NetworkIPs) <= 0 {
		lo.G.Debugf("could not find the correct number of network ips configured '%v' : '%v'", len(d.NetworkIPs), d.NetworkIPs)
	}

	if d.StemcellName == "" {
		lo.G.Debugf("could not find a valid stemcellname '%v'", d.StemcellName)
	}

	if d.VMTypeName == "" {
		lo.G.Debugf("could not find a valid vmtypename '%v'", d.VMTypeName)
	}
	if d.PersistentDiskType == "" {
		lo.G.Debugf("could not find a valid PersistentDiskType '%v'", d.PersistentDiskType)
	}
	if d.NetworkName == "" {
		lo.G.Debugf("could not find a valid networkname '%v'", d.NetworkName)
	}
	if d.BBSCACert == "" {
		lo.G.Debugf("could not find a valid bbscacert '%v'", d.BBSCACert)
	}
	if d.BBSClientCert == "" {
		lo.G.Debugf("could not find a valid bbsclientcert '%v'", d.BBSClientCert)
	}
	if d.BBSAPILocation == "" {
		lo.G.Debugf("could not find a valid BBSAPILocation '%v'", d.BBSAPILocation)
	}
	if d.CCInternalAPIUser == "" {
		lo.G.Debugf("could not find a valid CCInternalAPIUser '%v'", d.CCInternalAPIUser)
	}
	if d.CCInternalAPIPassword == "" {
		lo.G.Debugf("could not find a valid CCInternalAPIPassword '%v'", d.CCInternalAPIPassword)
	}
	if d.SystemDomain == "" {
		lo.G.Debugf("could not find a valid SystemDomain '%v'", d.SystemDomain)
	}

	return len(d.AZs) > 0 &&
		d.StemcellName != "" &&
		len(d.NetworkIPs) > 0 &&
		d.VMTypeName != "" &&
		d.PersistentDiskType != "" &&
		d.NetworkName != "" &&
		d.BBSCACert != "" &&
		d.BBSClientCert != "" &&
		d.BBSClientKey != "" &&
		d.BBSAPILocation != "" &&
		d.CCInternalAPIUser != "" &&
		d.CCInternalAPIPassword != "" &&
		d.SystemDomain != "" &&
		d.ConsulAgent.HasValidValues() &&
		d.Metron.HasValidValues()
}
{'fraction_non_alphanumeric': 0.16153144940747494, 'fraction_numerical': 0.001731996353691887, 'mean_word_length': 3.0814732142857144, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '2639919', 'n_tokens_mistral': 4294, 'n_tokens_neox': 4079, 'n_words': 551}