func New(cfg config.Config) *Server { m := machine.New(cfg.BootId, cfg.PublicIP, cfg.Metadata()) m.RefreshState() regClient := etcd.NewClient(cfg.EtcdServers) regClient.SetConsistency(etcd.STRONG_CONSISTENCY) r := registry.New(regClient) eb := event.NewEventBus() eb.Listen() eventClient := etcd.NewClient(cfg.EtcdServers) eventClient.SetConsistency(etcd.STRONG_CONSISTENCY) es := registry.NewEventStream(eventClient, r) var verifier *sign.SignatureVerifier if cfg.VerifyUnits { var err error verifier, err = sign.NewSignatureVerifierFromAuthorizedKeysFile(cfg.AuthorizedKeysFile) if err != nil { log.Errorln("Failed to get any key from authorized key file in verify_units mode:", err) verifier = sign.NewSignatureVerifier() } } a, err := agent.New(r, eb, m, cfg.AgentTTL, cfg.UnitPrefix, verifier) if err != nil { //TODO: return this as an error object rather than panicking panic(err) } e := engine.New(r, eb, m) return &Server{a, e, m, r, eb, es} }
// getRegistry initializes a connection to the Registry func getRegistry() registry.Registry { tun := getTunnelFlag() machines := []string{globalFlags.Endpoint} client := etcd.NewClient(machines) if tun != "" { sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false) if err != nil { fmt.Fprintf(os.Stderr, "Failed initializing SSH client: %v\n", err) os.Exit(1) } dial := func(network, addr string) (net.Conn, error) { tcpaddr, err := net.ResolveTCPAddr(network, addr) if err != nil { return nil, err } return sshClient.DialTCP(network, nil, tcpaddr) } tr := http.Transport{ Dial: dial, TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, } client.SetTransport(&tr) } return registry.New(client, globalFlags.EtcdKeyPrefix) }
func getRegistry(context *cli.Context) *registry.Registry { tun := getTunnelFlag(context) endpoint := context.GlobalString("endpoint") machines := []string{endpoint} client := etcd.NewClient(machines) if tun != "" { sshClient, err := ssh.NewSSHClient("core", tun) if err != nil { panic(err) } dial := func(network, addr string) (net.Conn, error) { tcpaddr, err := net.ResolveTCPAddr(network, addr) if err != nil { return nil, err } return sshClient.DialTCP(network, nil, tcpaddr) } tr := http.Transport{ Dial: dial, TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, } client.SetTransport(&tr) } return registry.New(client) }
func getRegistry() *registry.Registry { tun := getTunnelFlag() endpoint := getEndpointFlag() machines := []string{endpoint} client := etcd.NewClient(machines) if tun != "" { sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false) if err != nil { log.Fatalf("Failed initializing SSH client: %v", err) } dial := func(network, addr string) (net.Conn, error) { tcpaddr, err := net.ResolveTCPAddr(network, addr) if err != nil { return nil, err } return sshClient.DialTCP(network, nil, tcpaddr) } tr := http.Transport{ Dial: dial, TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, } client.SetTransport(&tr) } return registry.New(client) }
func New(cfg config.Config) *Server { m := machine.New(cfg.BootId, cfg.PublicIP, cfg.Metadata()) m.RefreshState() regClient := etcd.NewClient(cfg.EtcdServers) regClient.SetConsistency(etcd.STRONG_CONSISTENCY) r := registry.New(regClient) eb := event.NewEventBus() eb.Listen() eventClient := etcd.NewClient(cfg.EtcdServers) eventClient.SetConsistency(etcd.STRONG_CONSISTENCY) es := registry.NewEventStream(eventClient) a, err := agent.New(r, eb, m, cfg.AgentTTL, cfg.UnitPrefix) if err != nil { //TODO: return this as an error object rather than panicking panic(err) } e := engine.New(r, eb, m) return &Server{a, e, m, r, eb, es} }
func NewRegistryClient(trans *http.Transport, endpoint, keyPrefix string, requestTimeout time.Duration) (API, error) { machines := []string{endpoint} client, err := etcd.NewClient(machines, *trans, requestTimeout) if err != nil { return nil, err } return registry.New(client, keyPrefix), nil }
func NewRegistryClient(trans *http.Transport, endpoint, keyPrefix string) (API, error) { machines := []string{endpoint} client, err := etcd.NewClient(machines, *trans) if err != nil { return nil, err } return registry.New(client, keyPrefix), nil }
func New(cfg config.Config) (*Server, error) { mach, err := newMachineFromConfig(cfg) if err != nil { return nil, err } mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory) if err != nil { return nil, err } eClient, err := etcd.NewClient(cfg.EtcdServers, http.Transport{}) if err != nil { return nil, err } reg := registry.New(eClient, cfg.EtcdKeyPrefix) a, err := newAgentFromConfig(mach, reg, cfg, mgr) if err != nil { return nil, err } e := engine.New(reg, mach) sStream := systemd.NewEventStream(mgr) rStream, err := registry.NewEventStream(eClient, reg) if err != nil { return nil, err } aHandler := agent.NewEventHandler(a) eHandler := engine.NewEventHandler(e) eBus := event.NewEventBus() eBus.AddListener("engine", eHandler) eBus.AddListener("agent", aHandler) listeners, err := activation.Listeners(false) if err != nil { return nil, err } mux := api.NewServeMux(reg) for _, f := range listeners { go http.Serve(f, mux) } return &Server{a, e, rStream, sStream, eBus, mach, nil}, nil }
func newEngineFromConfig(mach *machine.Machine, cfg config.Config) (*engine.Engine, error) { regClient := etcd.NewClient(cfg.EtcdServers) regClient.SetConsistency(etcd.STRONG_CONSISTENCY) reg := registry.New(regClient, cfg.EtcdKeyPrefix) eClient := etcd.NewClient(cfg.EtcdServers) eClient.SetConsistency(etcd.STRONG_CONSISTENCY) eStream, err := registry.NewEventStream(eClient, reg) if err != nil { return nil, err } return engine.New(reg, eStream, mach), nil }
func newAgentFromConfig(mach machine.Machine, cfg config.Config, mgr unit.UnitManager) (*agent.Agent, error) { regClient := newEtcdClientFromConfig(cfg) reg := registry.New(regClient, cfg.EtcdKeyPrefix) var verifier *sign.SignatureVerifier if cfg.VerifyUnits { var err error verifier, err = sign.NewSignatureVerifierFromAuthorizedKeysFile(cfg.AuthorizedKeysFile) if err != nil { log.Errorln("Failed to get any key from authorized key file in verify_units mode:", err) verifier = sign.NewSignatureVerifier() } } return agent.New(mgr, reg, mach, cfg.AgentTTL, verifier) }
func getRegistryClient() (client.API, error) { var dial func(string, string) (net.Conn, error) tun := getTunnelFlag() if tun != "" { sshClient, err := ssh.NewSSHClient(globalFlags.SSHUserName, tun, getChecker(), false) if err != nil { return nil, fmt.Errorf("failed initializing SSH client: %v", err) } dial = func(network, addr string) (net.Conn, error) { tcpaddr, err := net.ResolveTCPAddr(network, addr) if err != nil { return nil, err } return sshClient.DialTCP(network, nil, tcpaddr) } } tlsConfig, err := etcd.ReadTLSConfigFiles(globalFlags.EtcdCAFile, globalFlags.EtcdCertFile, globalFlags.EtcdKeyFile) if err != nil { return nil, err } trans := &http.Transport{ Dial: dial, TLSClientConfig: tlsConfig, } timeout := time.Duration(globalFlags.RequestTimeout*1000) * time.Millisecond machines := []string{globalFlags.Endpoint} eClient, err := etcd.NewClient(machines, trans, timeout) if err != nil { return nil, err } reg := registry.New(eClient, globalFlags.EtcdKeyPrefix) if msg, ok := checkVersion(reg); !ok { stderr(msg) } return &client.RegistryClient{reg}, nil }
func New(cfg config.Config) (*Server, error) { mach, err := newMachineFromConfig(cfg) if err != nil { return nil, err } mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory) if err != nil { return nil, err } eClient := etcd.NewClient(cfg.EtcdServers) reg := registry.New(eClient, cfg.EtcdKeyPrefix) a, err := newAgentFromConfig(mach, reg, cfg, mgr) if err != nil { return nil, err } e := engine.New(reg, mach) sStream := systemd.NewEventStream(mgr) rStream, err := registry.NewEventStream(eClient, reg) if err != nil { return nil, err } aHandler := agent.NewEventHandler(a) eHandler := engine.NewEventHandler(e) eBus := event.NewEventBus() eBus.AddListener("engine", eHandler) eBus.AddListener("agent", aHandler) return &Server{a, e, rStream, sStream, eBus, mach, nil}, nil }
func newAgentFromConfig(mach *machine.Machine, cfg config.Config) (*agent.Agent, error) { regClient := etcd.NewClient(cfg.EtcdServers) regClient.SetConsistency(etcd.STRONG_CONSISTENCY) reg := registry.New(regClient, cfg.EtcdKeyPrefix) eClient := etcd.NewClient(cfg.EtcdServers) eClient.SetConsistency(etcd.STRONG_CONSISTENCY) eStream, err := registry.NewEventStream(eClient, reg) if err != nil { return nil, err } var verifier *sign.SignatureVerifier if cfg.VerifyUnits { var err error verifier, err = sign.NewSignatureVerifierFromAuthorizedKeysFile(cfg.AuthorizedKeysFile) if err != nil { log.Errorln("Failed to get any key from authorized key file in verify_units mode:", err) verifier = sign.NewSignatureVerifier() } } return agent.New(reg, eStream, mach, cfg.AgentTTL, verifier) }
func newRegistryEventStreamFromConfig(cfg config.Config) (*registry.EventStream, error) { eClient := newEtcdClientFromConfig(cfg) reg := registry.New(eClient, cfg.EtcdKeyPrefix) return registry.NewEventStream(eClient, reg) }
func newEngineFromConfig(mach machine.Machine, cfg config.Config) (*engine.Engine, error) { regClient := newEtcdClientFromConfig(cfg) reg := registry.New(regClient, cfg.EtcdKeyPrefix) return engine.New(reg, mach), nil }
func New(cfg config.Config) (*Server, error) { mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory) if err != nil { return nil, err } mach, err := newMachineFromConfig(cfg, mgr) if err != nil { return nil, err } tlsConfig, err := etcd.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile) if err != nil { return nil, err } eTrans := http.Transport{TLSClientConfig: tlsConfig} timeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond eClient, err := etcd.NewClient(cfg.EtcdServers, eTrans, timeout) if err != nil { return nil, err } reg := registry.New(eClient, cfg.EtcdKeyPrefix) pub := agent.NewUnitStatePublisher(mgr, reg, mach) gen := unit.NewUnitStateGenerator(mgr) a, err := newAgentFromConfig(mach, reg, cfg, mgr, gen) if err != nil { return nil, err } ar, err := newAgentReconcilerFromConfig(reg, eClient, cfg) if err != nil { return nil, err } e, err := newEngineFromConfig(reg, eClient, mach, cfg) if err != nil { return nil, err } listeners, err := activation.Listeners(false) if err != nil { return nil, err } hrt, mon, err := newHeartMonitorFromConfig(mach, reg, cfg) if err != nil { return nil, err } apiServer := api.NewServer(listeners, api.NewServeMux(reg)) apiServer.Serve() eIval := time.Duration(cfg.EngineReconcileInterval*1000) * time.Millisecond srv := Server{ agent: a, aReconciler: ar, usGen: gen, usPub: pub, engine: e, mach: mach, hrt: hrt, mon: mon, api: apiServer, stop: nil, engineReconcileInterval: eIval, } return &srv, nil }
func New(cfg config.Config) (*Server, error) { mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory) if err != nil { return nil, err } mach, err := newMachineFromConfig(cfg, mgr) if err != nil { return nil, err } tlsConfig, err := etcd.TLSClientConfig(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile) if err != nil { return nil, err } eClient, err := etcd.NewClient(cfg.EtcdServers, http.Transport{TLSClientConfig: tlsConfig}) if err != nil { return nil, err } reg := registry.New(eClient, cfg.EtcdKeyPrefix) pub := agent.NewUnitStatePublisher(mgr, reg, mach) gen := unit.NewUnitStateGenerator(mgr) a, err := newAgentFromConfig(mach, reg, cfg, mgr, gen) if err != nil { return nil, err } ar, err := newAgentReconcilerFromConfig(reg, cfg) if err != nil { return nil, err } e := engine.New(reg, mach) rStream, err := registry.NewEventStream(eClient, reg) if err != nil { return nil, err } eBus := event.NewEventBus() eBus.AddListener(event.JobEvent, ar.Trigger) eBus.AddListener(event.GlobalEvent, e.Trigger) listeners, err := activation.Listeners(false) if err != nil { return nil, err } hrt, mon, err := newHeartMonitorFromConfig(mach, reg, cfg) if err != nil { return nil, err } apiServer := api.NewServer(listeners, api.NewServeMux(reg)) apiServer.Serve() srv := Server{ agent: a, aReconciler: ar, usGen: gen, usPub: pub, engine: e, rStream: rStream, eBus: eBus, mach: mach, hrt: hrt, mon: mon, api: apiServer, stop: nil, } return &srv, nil }