本文整理汇总了Golang中github.com/coreos/fleet/agent.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: New
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}
}
示例2: New
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}
}
示例3: newAgentFromConfig
func newAgentFromConfig(mach machine.Machine, reg registry.Registry, cfg config.Config, mgr unit.UnitManager) (*agent.Agent, error) {
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)
}
示例4: newAgentFromConfig
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)
}
示例5: New
func New(cfg config.Config) (*Server, error) {
agentTTL, err := time.ParseDuration(cfg.AgentTTL)
if err != nil {
return nil, err
}
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 := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
if err != nil {
return nil, err
}
eCfg := etcd.Config{
Transport: &http.Transport{TLSClientConfig: tlsConfig},
Endpoints: cfg.EtcdServers,
}
eClient, err := etcd.New(eCfg)
if err != nil {
return nil, err
}
etcdRequestTimeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond
kAPI := etcd.NewKeysAPI(eClient)
reg := registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)
pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
gen := unit.NewUnitStateGenerator(mgr)
a := agent.New(mgr, gen, reg, mach, agentTTL)
var rStream pkg.EventStream
if !cfg.DisableWatches {
rStream = registry.NewEtcdEventStream(kAPI, cfg.EtcdKeyPrefix)
}
lManager := lease.NewEtcdLeaseManager(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)
ar := agent.NewReconciler(reg, rStream)
e := engine.New(reg, lManager, rStream, mach)
listeners, err := activation.Listeners(false)
if err != nil {
return nil, err
}
hrt := heart.New(reg, mach)
mon := heart.NewMonitor(agentTTL)
apiServer := api.NewServer(listeners, api.NewServeMux(reg, cfg.TokenLimit))
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,
disableEngine: cfg.DisableEngine,
}
return &srv, nil
}
示例6: newAgentFromConfig
func newAgentFromConfig(mach machine.Machine, reg registry.Registry, cfg config.Config, mgr unit.UnitManager, uGen *unit.UnitStateGenerator) (*agent.Agent, error) {
return agent.New(mgr, uGen, reg, mach, cfg.AgentTTL)
}
示例7: New
func New(cfg config.Config, listeners []net.Listener) (*Server, error) {
agentTTL, err := time.ParseDuration(cfg.AgentTTL)
if err != nil {
return nil, err
}
mgr, err := systemd.NewSystemdUnitManager(cfg.UnitsDirectory, cfg.SystemdUser)
if err != nil {
return nil, err
}
mach, err := newMachineFromConfig(cfg, mgr)
if err != nil {
return nil, err
}
tlsConfig, err := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
if err != nil {
return nil, err
}
eCfg := etcd.Config{
Transport: &http.Transport{TLSClientConfig: tlsConfig},
Endpoints: cfg.EtcdServers,
HeaderTimeoutPerRequest: (time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond),
Username: cfg.EtcdUsername,
Password: cfg.EtcdPassword,
}
eClient, err := etcd.New(eCfg)
if err != nil {
return nil, err
}
kAPI := etcd.NewKeysAPI(eClient)
var (
reg engine.CompleteRegistry
genericReg interface{}
)
lManager := lease.NewEtcdLeaseManager(kAPI, cfg.EtcdKeyPrefix)
if !cfg.EnableGRPC {
genericReg = registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix)
if obj, ok := genericReg.(engine.CompleteRegistry); ok {
reg = obj
}
} else {
etcdReg := registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix)
genericReg = rpc.NewRegistryMux(etcdReg, mach, lManager)
if obj, ok := genericReg.(engine.CompleteRegistry); ok {
reg = obj
}
}
pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
gen := unit.NewUnitStateGenerator(mgr)
a := agent.New(mgr, gen, reg, mach, agentTTL)
var rStream pkg.EventStream
if !cfg.DisableWatches {
rStream = registry.NewEtcdEventStream(kAPI, cfg.EtcdKeyPrefix)
}
ar := agent.NewReconciler(reg, rStream)
var e *engine.Engine
if !cfg.EnableGRPC {
e = engine.New(reg, lManager, rStream, mach, nil)
} else {
regMux := genericReg.(*rpc.RegistryMux)
e = engine.New(reg, lManager, rStream, mach, regMux.EngineChanged)
if cfg.DisableEngine {
go regMux.ConnectToRegistry(e)
}
}
if len(listeners) == 0 {
listeners, err = activation.Listeners(false)
if err != nil {
return nil, err
}
}
hrt := heart.New(reg, mach)
mon := NewMonitor(agentTTL)
apiServer := api.NewServer(listeners, api.NewServeMux(reg, cfg.TokenLimit))
apiServer.Serve()
eIval := time.Duration(cfg.EngineReconcileInterval*1000) * time.Millisecond
srv := Server{
agent: a,
aReconciler: ar,
usGen: gen,
usPub: pub,
engine: e,
mach: mach,
//.........这里部分代码省略.........
示例8: New
func New(cfg config.Config) (*Server, error) {
etcdRequestTimeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond
agentTTL, err := time.ParseDuration(cfg.AgentTTL)
if err != nil {
return nil, err
}
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}
eClient, err := etcd.NewClient(cfg.EtcdServers, eTrans, etcdRequestTimeout)
if err != nil {
return nil, err
}
reg := registry.New(eClient, cfg.EtcdKeyPrefix)
pub := agent.NewUnitStatePublisher(mgr, reg, mach, agentTTL)
gen := unit.NewUnitStateGenerator(mgr)
a := agent.New(mgr, gen, reg, mach, agentTTL)
rStream := registry.NewEtcdEventStream(eClient, cfg.EtcdKeyPrefix)
ar := agent.NewReconciler(reg, rStream)
e := engine.New(reg, rStream, mach)
listeners, err := activation.Listeners(false)
if err != nil {
return nil, err
}
hrt := heart.New(reg, mach)
mon := heart.NewMonitor(agentTTL)
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
}
示例9: New
func New(cfg config.Config) (*Server, error) {
agentTTL, err := time.ParseDuration(cfg.AgentTTL)
if err != nil {
return nil, err
}
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 := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
if err != nil {
return nil, err
}
etcdRequestTimeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond
// set a per server request timeout that is the global request timeout divided by the number of quorum nodes (i.e. 3 out of 5)
// this ensures that the the retry logic in etcd can try at least 3 servers before the global timeout fires and cancels the entire request
quorumCount := (len(cfg.EtcdServers) / 2) + 1
etcdRequestPerServerTimeout := etcdRequestTimeout
if quorumCount > 1 {
etcdRequestPerServerTimeout = time.Duration(int64(etcdRequestTimeout) / int64(quorumCount))
}
log.Infof("Etcd endpoints: %v", strings.Join(cfg.EtcdServers, ","))
log.Infof("Setting global request timeout of %v and per server request timeout of %v using a quorum count of %v", etcdRequestTimeout, etcdRequestPerServerTimeout, quorumCount)
eCfg := etcd.Config{
Transport: &http.Transport{TLSClientConfig: tlsConfig},
Endpoints: cfg.EtcdServers,
HeaderTimeoutPerRequest: etcdRequestPerServerTimeout,
}
eClient, err := etcd.New(eCfg)
if err != nil {
return nil, err
}
kAPI := etcd.NewKeysAPI(eClient)
reg := registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)
pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
gen := unit.NewUnitStateGenerator(mgr)
a := agent.New(mgr, gen, reg, mach, agentTTL)
rStream := registry.NewEtcdEventStream(kAPI, cfg.EtcdKeyPrefix)
lManager := lease.NewEtcdLeaseManager(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)
ar := agent.NewReconciler(reg, rStream)
e := engine.New(reg, lManager, rStream, mach)
listeners, err := activation.Listeners(false)
if err != nil {
return nil, err
}
hrt := heart.New(reg, mach)
mon := heart.NewMonitor(agentTTL)
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
}