本文整理汇总了Golang中github.com/cloudfoundry-incubator/receptor.DesiredLRPCreateRequest.Monitor方法的典型用法代码示例。如果您正苦于以下问题:Golang DesiredLRPCreateRequest.Monitor方法的具体用法?Golang DesiredLRPCreateRequest.Monitor怎么用?Golang DesiredLRPCreateRequest.Monitor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/receptor.DesiredLRPCreateRequest
的用法示例。
在下文中一共展示了DesiredLRPCreateRequest.Monitor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
&models.RunAction{
User: "vcap",
Path: "sh",
Args: []string{
"-c",
`while true; do echo "sup dawg" | nc -l 127.0.0.1 -p 9999; done`,
},
},
},
}
// busybox nc doesn't support -z
lrp.Monitor = &models.RunAction{
User: "vcap",
Path: "sh",
Args: []string{
"-c",
"echo -n '' | telnet localhost 3456 >/dev/null 2>&1 && true",
},
}
})
It("can ssh to appropriate app instance container", func() {
verifySSH(address, processGuid, 0)
verifySSH(address, processGuid, 1)
})
It("supports local port fowarding", func() {
clientConfig := &ssh.ClientConfig{
User: fmt.Sprintf("diego:%s/%d", processGuid, 0),
Auth: []ssh.AuthMethod{ssh.Password("")},
}
示例2: desireLrp
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
primaryPort := uint16(0)
if params.Monitor.Port != 0 {
primaryPort = params.Monitor.Port
} else if len(params.ExposedPorts) > 0 {
primaryPort = params.ExposedPorts[0]
}
routes := appRunner.buildRoutes(params, primaryPort)
vcapAppURIs := []string{}
for _, route := range routes.AppRoutes {
vcapAppURIs = append(vcapAppURIs, route.Hostnames...)
}
vcapApplication := struct {
ApplicationName string `json:"application_name"`
ApplicationURIs []string `json:"application_uris"`
Name string `json:"name"`
URIs []string `json:"uris"`
Limits struct {
Disk int `json:"disk,omitempty"`
Memory int `json:"mem,omitempty"`
} `json:"limits,omitempty"`
}{}
vcapApplication.ApplicationName = params.Name
vcapApplication.Name = params.Name
vcapApplication.ApplicationURIs = vcapAppURIs
vcapApplication.URIs = vcapAppURIs
vcapApplication.Limits.Disk = params.DiskMB
vcapApplication.Limits.Memory = params.MemoryMB
vcapAppBytes, err := json.Marshal(vcapApplication)
if err != nil {
return err
}
envVars := buildEnvironmentVariables(params.EnvironmentVariables)
envVars = append(envVars, receptor.EnvironmentVariable{Name: "VCAP_APPLICATION", Value: string(vcapAppBytes)})
envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})
req := receptor.DesiredLRPCreateRequest{
ProcessGuid: params.Name,
Domain: lrpDomain,
RootFS: params.RootFS,
Instances: params.Instances,
Routes: routes.RoutingInfo(),
CPUWeight: params.CPUWeight,
MemoryMB: params.MemoryMB,
DiskMB: params.DiskMB,
Privileged: params.Privileged,
Ports: params.ExposedPorts,
LogGuid: params.Name,
LogSource: "APP",
MetricsGuid: params.Name,
EnvironmentVariables: envVars,
Annotation: params.Annotation,
Setup: params.Setup,
Action: &models.RunAction{
Path: params.StartCommand,
Args: params.AppArgs,
Dir: params.WorkingDir,
User: params.User,
},
}
var healthCheckArgs []string
if params.Monitor.Timeout != 0 {
healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
}
switch params.Monitor.Method {
case PortMonitor:
req.Monitor = &models.RunAction{
Path: "/tmp/healthcheck",
Args: append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
LogSource: "HEALTH",
User: params.User,
}
case URLMonitor:
req.Monitor = &models.RunAction{
Path: "/tmp/healthcheck",
Args: append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
LogSource: "HEALTH",
User: params.User,
}
}
return appRunner.receptorClient.CreateDesiredLRP(req)
}
示例3: desireLrp
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
primaryPort := uint16(0)
if params.Monitor.Port != 0 {
primaryPort = params.Monitor.Port
} else if len(params.ExposedPorts) > 0 {
primaryPort = params.ExposedPorts[0]
}
envVars := buildEnvironmentVariables(params.EnvironmentVariables)
envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})
var appRoutes route_helpers.AppRoutes
if params.NoRoutes {
appRoutes = route_helpers.AppRoutes{}
} else if len(params.RouteOverrides) > 0 {
routeMap := make(map[uint16][]string)
for _, override := range params.RouteOverrides {
routeMap[override.Port] = append(routeMap[override.Port], fmt.Sprintf("%s.%s", override.HostnamePrefix, appRunner.systemDomain))
}
for port, hostnames := range routeMap {
appRoutes = append(appRoutes, route_helpers.AppRoute{
Hostnames: hostnames,
Port: port,
})
}
} else {
appRoutes = appRunner.buildDefaultRoutingInfo(params.Name, params.ExposedPorts, primaryPort)
}
req := receptor.DesiredLRPCreateRequest{
ProcessGuid: params.Name,
Domain: lrpDomain,
RootFS: params.RootFS,
Instances: params.Instances,
Routes: appRoutes.RoutingInfo(),
CPUWeight: params.CPUWeight,
MemoryMB: params.MemoryMB,
DiskMB: params.DiskMB,
Privileged: params.Privileged,
Ports: params.ExposedPorts,
LogGuid: params.Name,
LogSource: "APP",
MetricsGuid: params.Name,
EnvironmentVariables: envVars,
Setup: params.Setup,
Action: &models.RunAction{
Path: params.StartCommand,
Args: params.AppArgs,
Dir: params.WorkingDir,
},
}
var healthCheckArgs []string
if params.Monitor.Timeout != 0 {
healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
}
switch params.Monitor.Method {
case PortMonitor:
req.Monitor = &models.RunAction{
Path: "/tmp/healthcheck",
Args: append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
LogSource: "HEALTH",
}
case URLMonitor:
req.Monitor = &models.RunAction{
Path: "/tmp/healthcheck",
Args: append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
LogSource: "HEALTH",
}
}
return appRunner.receptorClient.CreateDesiredLRP(req)
}
示例4: desireLrp
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
primaryPort := route_helpers.GetPrimaryPort(params.Monitor.Port, params.ExposedPorts)
private, public, err := appRunner.keygen.GenerateRSAKeyPair(2048)
if err != nil {
return err
}
routes := appRunner.buildRoutesWithDefaults(params, primaryPort)
routes.DiegoSSHRoute = &route_helpers.DiegoSSHRoute{
Port: 2222,
PrivateKey: private,
}
vcapAppURIs := []string{}
for _, route := range routes.AppRoutes {
vcapAppURIs = append(vcapAppURIs, route.Hostnames...)
}
vcapApplication := struct {
ApplicationName string `json:"application_name"`
ApplicationURIs []string `json:"application_uris"`
Name string `json:"name"`
URIs []string `json:"uris"`
Limits struct {
Disk int `json:"disk,omitempty"`
Memory int `json:"mem,omitempty"`
} `json:"limits,omitempty"`
}{}
vcapApplication.ApplicationName = params.Name
vcapApplication.Name = params.Name
vcapApplication.ApplicationURIs = vcapAppURIs
vcapApplication.URIs = vcapAppURIs
vcapApplication.Limits.Disk = params.DiskMB
vcapApplication.Limits.Memory = params.MemoryMB
vcapAppBytes, err := json.Marshal(vcapApplication)
if err != nil {
return err
}
envVars := buildEnvironmentVariables(params.EnvironmentVariables)
envVars = append(envVars, receptor.EnvironmentVariable{Name: "VCAP_APPLICATION", Value: string(vcapAppBytes)})
envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})
if _, exists := params.EnvironmentVariables["VCAP_SERVICES"]; !exists {
envVars = append(envVars, receptor.EnvironmentVariable{Name: "VCAP_SERVICES", Value: "{}"})
}
setupAction := &models.SerialAction{
Actions: []models.Action{
params.Setup,
&models.DownloadAction{
From: "http://file_server.service.dc1.consul:8080/v1/static/diego-sshd.tgz",
To: "/tmp",
User: "vcap",
},
},
}
hostKey, err := appRunner.keygen.GenerateRSAPrivateKey(2048)
if err != nil {
return err
}
req := receptor.DesiredLRPCreateRequest{
ProcessGuid: params.Name,
Domain: lrpDomain,
RootFS: params.RootFS,
Instances: params.Instances,
Routes: routes.RoutingInfo(),
CPUWeight: params.CPUWeight,
MemoryMB: params.MemoryMB,
DiskMB: params.DiskMB,
Privileged: params.Privileged,
Ports: append(params.ExposedPorts, 2222),
LogGuid: params.Name,
LogSource: "APP",
MetricsGuid: params.Name,
EnvironmentVariables: envVars,
Annotation: params.Annotation,
Setup: setupAction,
Action: &models.ParallelAction{
Actions: []models.Action{
&models.RunAction{
Path: "/tmp/diego-sshd",
Args: []string{
"-address=0.0.0.0:2222",
fmt.Sprintf("-authorizedKey=%s", public),
fmt.Sprintf("-hostKey=%s", hostKey),
},
Dir: "/tmp",
User: params.User,
},
&models.RunAction{
Path: params.StartCommand,
Args: params.AppArgs,
Dir: params.WorkingDir,
User: params.User,
//.........这里部分代码省略.........
示例5:
Eventually(func() []receptor.ActualLRPResponse {
lrps, err := receptorClient.ActualLRPsByProcessGuid(processGuid)
Expect(err).NotTo(HaveOccurred())
return lrps
}).Should(HaveLen(1))
Eventually(helpers.HelloWorldInstancePoller(componentMaker.Addresses.Router, helpers.DefaultHost)).Should(ConsistOf([]string{"0"}))
})
Context("when it's unhealthy for longer than its start timeout", func() {
BeforeEach(func() {
lrp.StartTimeout = 5
lrp.Monitor = &models.RunAction{
User: "vcap",
Path: "false",
}
})
It("eventually marks the LRP as crashed", func() {
Eventually(func() []receptor.ActualLRPResponse {
lrps, err := receptorClient.ActualLRPsByProcessGuid(processGuid)
Expect(err).NotTo(HaveOccurred())
return lrps
}).Should(HaveLen(1))
var actualLRP receptor.ActualLRPResponse
Eventually(
helpers.LRPStatePoller(receptorClient, processGuid, &actualLRP),
).Should(Equal(receptor.ActualLRPStateCrashed))
示例6: desireLrp
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
primaryPort := uint16(0)
if params.Monitor.Port != 0 {
primaryPort = params.Monitor.Port
} else if len(params.ExposedPorts) > 0 {
primaryPort = params.ExposedPorts[0]
}
envVars := buildEnvironmentVariables(params.EnvironmentVariables)
envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})
routes := appRunner.buildRoutes(params, primaryPort)
req := receptor.DesiredLRPCreateRequest{
ProcessGuid: params.Name,
Domain: lrpDomain,
RootFS: params.RootFS,
Instances: params.Instances,
Routes: routes.RoutingInfo(),
CPUWeight: params.CPUWeight,
MemoryMB: params.MemoryMB,
DiskMB: params.DiskMB,
Privileged: params.Privileged,
Ports: params.ExposedPorts,
LogGuid: params.Name,
LogSource: "APP",
MetricsGuid: params.Name,
EnvironmentVariables: envVars,
Annotation: params.Annotation,
Setup: params.Setup,
Action: &models.RunAction{
Path: params.StartCommand,
Args: params.AppArgs,
Dir: params.WorkingDir,
User: userForPrivilege(params.Privileged),
},
}
var healthCheckArgs []string
if params.Monitor.Timeout != 0 {
healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
}
switch params.Monitor.Method {
case PortMonitor:
req.Monitor = &models.RunAction{
Path: "/tmp/healthcheck",
Args: append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
LogSource: "HEALTH",
User: userForPrivilege(params.Privileged),
}
case URLMonitor:
req.Monitor = &models.RunAction{
Path: "/tmp/healthcheck",
Args: append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
LogSource: "HEALTH",
User: userForPrivilege(params.Privileged),
}
}
return appRunner.receptorClient.CreateDesiredLRP(req)
}