本文整理匯總了Golang中github.com/cloudfoundry-incubator/receptor.DesiredLRPCreateRequest類的典型用法代碼示例。如果您正苦於以下問題:Golang DesiredLRPCreateRequest類的具體用法?Golang DesiredLRPCreateRequest怎麽用?Golang DesiredLRPCreateRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DesiredLRPCreateRequest類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2:
session, err := client.NewSession()
Expect(err).NotTo(HaveOccurred())
output, err := session.Output("/usr/bin/env")
Expect(err).NotTo(HaveOccurred())
Expect(string(output)).To(ContainSubstring("USER=vcap"))
Expect(string(output)).To(ContainSubstring("TEST=foobar"))
Expect(string(output)).To(ContainSubstring(fmt.Sprintf("INSTANCE_INDEX=%d", index)))
}
var (
processGuid string
fileServerStaticDir string
runtime ifrit.Process
address string
lrp receptor.DesiredLRPCreateRequest
)
BeforeEach(func() {
processGuid = helpers.GenerateGuid()
address = componentMaker.Addresses.SSHProxy
var fileServer ifrit.Runner
fileServer, fileServerStaticDir = componentMaker.FileServer()
runtime = ginkgomon.Invoke(grouper.NewParallel(os.Kill, grouper.Members{
{"router", componentMaker.Router()},
{"file-server", fileServer},
{"rep", componentMaker.Rep()},
示例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:
Context("when the task is not privileged", func() {
BeforeEach(func() {
taskRequest.Privileged = false
})
It("fails", func() {
var task receptor.TaskResponse
Eventually(helpers.TaskStatePoller(receptorClient, taskRequest.TaskGuid, &task)).Should(Equal(receptor.TaskStateCompleted))
Expect(task.Failed).To(BeTrue())
})
})
})
Context("when a LRP that tries to do privileged things is requested", func() {
var lrpRequest receptor.DesiredLRPCreateRequest
BeforeEach(func() {
lrpRequest = helpers.PrivilegedLRPCreateRequest(helpers.GenerateGuid())
})
JustBeforeEach(func() {
err := receptorClient.CreateDesiredLRP(lrpRequest)
Expect(err).NotTo(HaveOccurred())
})
Context("when the LRP is privileged", func() {
BeforeEach(func() {
lrpRequest.Privileged = true
})
示例5: 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,
//.........這裏部分代碼省略.........
示例6:
archiveFiles = fixtures.GoServerApp()
})
JustBeforeEach(func() {
archive_helper.CreateZipArchive(
filepath.Join(fileServerStaticDir, "lrp.zip"),
archiveFiles,
)
})
AfterEach(func() {
helpers.StopProcesses(runtime)
})
Describe("desiring", func() {
var lrp receptor.DesiredLRPCreateRequest
BeforeEach(func() {
lrp = helpers.DefaultLRPCreateRequest(processGuid, "log-guid", 1)
lrp.Setup = &models.DownloadAction{
From: fmt.Sprintf("http://%s/v1/static/%s", componentMaker.Addresses.FileServer, "lrp.zip"),
To: "/tmp",
User: "vcap",
}
lrp.Action = &models.RunAction{
User: "vcap",
Path: "/tmp/go-server",
Env: []models.EnvironmentVariable{{"PORT", "8080"}},
}
})
示例7: 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)
}