func (cbf *circuitBreakerFactory) getOrCreateCircuitBreakerWithKey(key string, closeAfter int, halfOpenAfter time.Duration) ICircuitBreaker { // if cbf.cbs == nil { // cbf.cbs = make(map[string] *CircuitBreaker) // } i, ok := cbf.cbs[key] if ok { return i } else { newCircuitBreaker := &CircuitBreaker{ name: key, CircuitBreakerState: CLOSED, closeAfter: closeAfter, halfOpenAfter: halfOpenAfter, logger: stdlog.GetFromFlags(), failureCount: closeAfter} cbf.cbs[key] = newCircuitBreaker return newCircuitBreaker } }
const legacyPatchDir = "/mnt/massive04/a/sakai/resources/patches/" const ( patchSuccess = "1" // patchSuccess only when everything goes perfectly right tomcatDown = "2" // tomcatDown when tomcat never comes cleanly back tomcatNoShutdown = "4" // tomcatNoShutdown when we can't kill Tomcat inProgress = "10" // inProgress to block other patchers ) var token = flag.String("token", "", "the custom security token") var patchDir = flag.String("dir", "/tmp", "directory to store downloaded patches") var patchWeb = flag.String("web", "https://s3.amazonaws.com/longsight-patches/", "website with patch files") var localIP = flag.String("ip", "", "override automatic ip detection") var startupWaitSeconds = flag.Int("waitTime", 240, "amount of time to wait for Tomcat to startup") var propertyFiles = [4]string{"instance.properties", "dev.properties", "local.properties", "sakai.properties"} var patcherUID = uint32(os.Getuid()) var logger = stdlog.GetFromFlags() var outputBuffer bytes.Buffer func init() { flag.Parse() if len(*token) < 1 { fmt.Println("Please provide a valid security token") os.Exit(1) } } func main() { ip, _ := externalIP() logger.Debug("Auto-detected IPs on this server:" + ip) // User is overriding the auto-detected IPs
func main() { config := new(Config) addIdx := false initDb := false flag.StringVar(&config.Neo4JUrl, "db", "http://*****:*****@localhost:7474/", "Neo4J URL") flag.StringVar(&config.WorkDir, "workdir", "", "The work dir for temporary files") flag.BoolVar(&addIdx, "add_indexes", false, "Create non-essential indexes") flag.BoolVar(&initDb, "init_db", false, "Initialize the DB - create constraints") flag.Parse() app = App{ Config: config, Logger: stdlog.GetFromFlags(), } if app.Config.Neo4JUrl == "" { log.Fatal("db must be provided") } if flag.NArg() > 0 { if app.Config.WorkDir == "" { log.Fatal("Workdir must be provided") } st, err := os.Stat(app.Config.WorkDir) if err != nil { log.Fatal(err) } if !st.Mode().IsDir() { log.Fatal("Workdir is not a directory") } app.Config.WorkDir, err = filepath.Abs(app.Config.WorkDir) if err != nil { log.Fatal(err) } } log.Print("Connecting to Neo4j...") connect(&app) if initDb { log.Print("Creating constraints") addConstraints(app.GraphDB) } if addIdx { log.Print("Creating indexes") addIndexes(app.GraphDB) } if flag.NArg() == 0 { app.Logger.Info("No key file added, quitting") os.Exit(0) } initMetrics(&app) filename := flag.Arg(0) keych := make(KeyChan) log.Print("Launching key reader...") go ReadKeys(filename, keych) LoadKeysBulk(&app, keych) //LoadKeys(app, keych) }
func main() { var ( bytes []byte data map[string]service err error graph *gographviz.Graph project string ) logger = stdlog.GetFromFlags() project = "" // Load docker-compose.yml bytes, err = ioutil.ReadFile("docker-compose.yml") if err != nil { abort(err.Error()) } // Parse it as YML data = make(map[string]service, 5) yaml.Unmarshal(bytes, &data) if err != nil { abort(err.Error()) } // Create directed graph graph = gographviz.NewGraph() graph.SetName(project) graph.SetDir(true) // Add legend graph.AddSubGraph(project, "cluster_legend", map[string]string{"label": "Legend"}) graph.AddNode("cluster_legend", "legend_service", map[string]string{"label": "service"}) graph.AddNode("cluster_legend", "legend_service_with_ports", map[string]string{ "label": "\"service with exposed ports\\n80:80 443:443\\n--volume1[:host_dir1]\\n--volume2[:host_dir2]\"", "shape": "box"}) graph.AddEdge("legend_service", "legend_service_with_ports", true, map[string]string{"label": "links"}) graph.AddEdge("legend_service_with_ports", "legend_service", true, map[string]string{"label": "volumes_from", "style": "dashed"}) // Round one: populate nodes for name, service := range data { var attrs = map[string]string{"label": name} if service.Ports != nil { attrs["label"] += "\\n" + strings.Join(service.Ports, " ") attrs["shape"] = "box" } if service.Volumes != nil { attrs["label"] += "\\n--" + strings.Join(service.Volumes, "\\n--") } attrs["label"] = fmt.Sprintf("\"%s\"", attrs["label"]) graph.AddNode(project, name, attrs) } // Round two: populate connections for name, service := range data { // links if service.Links != nil { for _, linkTo := range service.Links { if strings.Contains(linkTo, ":") { linkTo = strings.Split(linkTo, ":")[0] } graph.AddEdge(name, linkTo, true, nil) } } // volumes_from if service.VolumesFrom != nil { for _, linkTo := range service.VolumesFrom { graph.AddEdge(name, linkTo, true, map[string]string{"style": "dotted"}) } } } fmt.Print(graph) }