本文整理汇总了Golang中github.com/openshift/geard/containers/jobs.Response.SuccessWithWrite方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.SuccessWithWrite方法的具体用法?Golang Response.SuccessWithWrite怎么用?Golang Response.SuccessWithWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/geard/containers/jobs.Response
的用法示例。
在下文中一共展示了Response.SuccessWithWrite方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Execute
func (j *containerLog) Execute(resp jobs.Response) {
if _, err := os.Stat(j.Id.UnitPathFor()); err != nil {
resp.Failure(ErrContainerNotFound)
return
}
w := resp.SuccessWithWrite(jobs.ResponseOk, true, false)
err := systemd.WriteLogsTo(w, j.Id.UnitNameFor(), 30, time.After(30*time.Second))
if err != nil {
log.Printf("job_container_log: Unable to fetch journal logs: %s\n", err.Error())
}
}
示例2: Execute
func (j *getEnvironment) Execute(resp jobs.Response) {
id := j.Id
file, erro := os.Open(id.EnvironmentPathFor())
if erro != nil {
resp.Failure(ErrEnvironmentNotFound)
return
}
defer file.Close()
w := resp.SuccessWithWrite(jobs.ResponseOk, false, false)
if _, err := io.Copy(w, file); err != nil {
log.Printf("job_content: Unable to write environment file: %+v", err)
return
}
}
示例3: Execute
func (j *startContainer) Execute(resp jobs.Response) {
unitName := j.Id.UnitNameFor()
unitPath := j.Id.UnitPathFor()
inState, tooSoon := inStateOrTooSoon(j.Id, unitName, true, false, rateLimitChanges)
if inState {
w := resp.SuccessWithWrite(jobs.ResponseAccepted, true, false)
fmt.Fprintf(w, "Container %s starting\n", j.Id)
return
}
if tooSoon {
resp.Failure(ErrStartRequestThrottled)
return
}
if errs := csystemd.SetUnitStartOnBoot(j.Id, true); errs != nil {
log.Print("alter_container_state: Unable to persist whether the unit is started on boot: ", errs)
resp.Failure(ErrContainerStartFailed)
return
}
if err := systemd.EnableAndReloadUnit(systemd.Connection(), unitName, unitPath); err != nil {
if systemd.IsNoSuchUnit(err) || systemd.IsFileNotFound(err) {
resp.Failure(ErrContainerNotFound)
return
}
log.Printf("alter_container_state: Could not enable container %s: %v", unitName, err)
resp.Failure(ErrContainerStartFailed)
return
}
if err := systemd.Connection().StartUnitJob(unitName, "replace"); err != nil {
log.Printf("alter_container_state: Could not start container %s: %v", unitName, err)
resp.Failure(ErrContainerStartFailed)
return
}
w := resp.SuccessWithWrite(jobs.ResponseAccepted, true, false)
fmt.Fprintf(w, "Container %s starting\n", j.Id)
}
示例4: Execute
func (j *listImages) Execute(resp jobs.Response) {
// TODO: config item for docker port
dockerClient, err := docker.NewClient(j.DockerSocket)
if err != nil {
log.Printf("job_list_images: Couldn't connect to docker: %+v", err)
resp.Failure(ErrListImagesFailed)
return
}
imgs, err := dockerClient.ListImages(false)
if err != nil {
log.Printf("job_list_images: Couldn't connect to docker: %+v", err)
resp.Failure(ErrListImagesFailed)
return
}
w := resp.SuccessWithWrite(jobs.ResponseAccepted, true, false)
for _, img := range imgs {
fmt.Fprintf(w, "%+v\n", img.RepoTags[0])
}
}
示例5: Execute
func (j *buildImage) Execute(resp jobs.Response) {
w := resp.SuccessWithWrite(jobs.ResponseAccepted, true, false)
fmt.Fprintf(w, "Processing build-image request:\n")
// TODO: download source, add bind-mount
unitName := containers.JobIdentifier(j.Name).UnitNameForBuild()
unitDescription := fmt.Sprintf("Builder for %s", j.Tag)
stdout, err := systemd.ProcessLogsForUnit(unitName)
if err != nil {
stdout = utils.EmptyReader
log.Printf("job_build_image: Unable to fetch build logs: %s, %+v", err.Error(), err)
}
defer stdout.Close()
conn, errc := systemd.NewConnection()
if errc != nil {
log.Print("job_build_image:", errc)
fmt.Fprintf(w, "Unable to watch start status", errc)
return
}
slice := DefaultSlice
systemd.IsUnitProperty(conn, j.BaseImage+".service", func(properties map[string]interface{}) bool {
value, ok := properties["Slice"]
if ok {
slice = value.(string)
}
return ok
})
if err := conn.Subscribe(); err != nil {
log.Print("job_build_image:", err)
fmt.Fprintf(w, "Unable to watch start status", errc)
return
}
defer conn.Unsubscribe()
// make subscription global for efficiency
var (
changes <-chan map[string]*dbus.UnitStatus
errch <-chan error
)
if resp.StreamResult() {
changes, errch = conn.SubscribeUnitsCustom(1*time.Second, 2,
func(s1 *dbus.UnitStatus, s2 *dbus.UnitStatus) bool {
return true
},
func(unit string) bool {
return unit != unitName
})
}
fmt.Fprintf(w, "Running sti build unit: %s\n", unitName)
log.Printf("build_image: Running build %s", unitName)
var startCmd []string
if _, err := os.Stat(gearBinaryPath); err != nil {
log.Println("gear executable is not installed on system; using sti builder image")
startCmd = []string{
"/usr/bin/docker", "run",
"-rm",
"-v", "/run/docker.sock:/run/docker.sock",
"-t", builderImage,
"sti", "build", j.Source, j.BaseImage, j.Tag,
"-U", "unix:///run/docker.sock",
}
} else {
startCmd = []string{
gearBinaryPath, "build", j.Source, j.BaseImage, j.Tag,
}
}
if j.RuntimeImage != "" {
startCmd = append(startCmd, "--runtime-image")
startCmd = append(startCmd, j.RuntimeImage)
}
if j.Clean {
startCmd = append(startCmd, "--clean")
}
if j.Verbose {
startCmd = append(startCmd, "--debug")
}
if j.CallbackUrl != "" {
startCmd = append(startCmd, "--callbackUrl="+j.CallbackUrl)
}
log.Printf("build_image: Will execute %v", startCmd)
status, err := systemd.Connection().StartTransientUnit(
unitName,
"fail",
dbus.PropExecStart(startCmd, true),
dbus.PropDescription(unitDescription),
dbus.PropRemainAfterExit(true),
dbus.PropSlice(slice),
//.........这里部分代码省略.........
示例6: Execute
//.........这里部分代码省略.........
Image: req.Image,
PortSpec: portSpec,
Slice: sliceName + ".slice",
Isolate: req.Isolate,
ReqId: req.RequestIdentifier.String(),
HomeDir: id.HomePath(),
RunDir: id.RunPathFor(),
EnvironmentPath: environmentPath,
ExecutablePath: filepath.Join("/", "usr", "bin", "gear"),
IncludePath: "",
PortPairs: reserved,
SocketUnitName: socketUnitName,
SocketActivationType: socketActivationType,
DockerFeatures: config.SystemDockerFeatures,
}
var templateName string
switch {
case req.SocketActivation:
templateName = "SOCKETACTIVATED"
case config.SystemDockerFeatures.ForegroundRun:
templateName = "FOREGROUND"
default:
templateName = "SIMPLE"
}
if erre := csystemd.ContainerUnitTemplate.ExecuteTemplate(unit, templateName, args); erre != nil {
log.Printf("install_container: Unable to output template: %+v", erre)
resp.Failure(ErrContainerCreateFailed)
defer os.Remove(unitVersionPath)
return
}
if err := unit.Close(); err != nil {
log.Printf("install_container: Unable to finish writing unit: %+v", err)
resp.Failure(ErrContainerCreateFailed)
defer os.Remove(unitVersionPath)
return
}
// swap the new definition with the old one
if err := utils.AtomicReplaceLink(unitVersionPath, unitPath); err != nil {
log.Printf("install_container: Failed to activate new unit: %+v", err)
resp.Failure(ErrContainerCreateFailed)
return
}
state.Close()
// write whether this container should be started on next boot
if req.Started {
if errs := csystemd.SetUnitStartOnBoot(id, true); errs != nil {
log.Print("install_container: Unable to write container boot link: ", err)
resp.Failure(ErrContainerCreateFailed)
return
}
}
// Generate the socket file and ignore failures
paths := []string{unitPath}
if req.SocketActivation {
if err := writeSocketUnit(socketUnitPath, &args); err == nil {
paths = []string{unitPath, socketUnitPath}
}
}
if err := systemd.EnableAndReloadUnit(systemd.Connection(), unitName, paths...); err != nil {
log.Printf("install_container: Could not enable container %s (%v): %v", unitName, paths, err)
resp.Failure(ErrContainerCreateFailed)
return
}
if req.Started {
if req.SocketActivation {
// Start the socket file, not the service and ignore failures
if err := systemd.Connection().StartUnitJob(socketUnitName, "replace"); err != nil {
log.Printf("install_container: Could not start container socket %s: %v", socketUnitName, err)
resp.Failure(ErrContainerCreateFailed)
return
}
} else {
if err := systemd.Connection().StartUnitJob(unitName, "replace"); err != nil {
log.Printf("install_container: Could not start container %s: %v", unitName, err)
resp.Failure(ErrContainerCreateFailed)
return
}
}
}
w := resp.SuccessWithWrite(jobs.ResponseAccepted, true, false)
if req.Started {
fmt.Fprintf(w, "Container %s is starting\n", id)
} else {
fmt.Fprintf(w, "Container %s is installed\n", id)
}
}