本文整理匯總了Golang中github.com/openshift/geard/containers/jobs.Response.Failure方法的典型用法代碼示例。如果您正苦於以下問題:Golang Response.Failure方法的具體用法?Golang Response.Failure怎麽用?Golang Response.Failure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/geard/containers/jobs.Response
的用法示例。
在下文中一共展示了Response.Failure方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Execute
func (j *patchEnvironment) Execute(resp jobs.Response) {
if err := j.Write(true); err != nil {
resp.Failure(ErrEnvironmentUpdateFailed)
return
}
resp.Success(jobs.ResponseOk)
}
示例2: Execute
func (j *linkContainers) Execute(resp jobs.Response) {
for i := range j.Links {
if errw := j.Links[i].NetworkLinks.Write(j.Links[i].Id.NetworkLinksPathFor(), false); errw != nil {
resp.Failure(ErrLinkContainersFailed)
return
}
}
resp.Success(jobs.ResponseOk)
}
示例3: Execute
func (j *containerPorts) Execute(resp jobs.Response) {
portPairs, err := containers.GetExistingPorts(j.Id)
if err != nil {
log.Printf("job_container_ports_log: Unable to find unit: %s\n", err.Error())
resp.Failure(ErrContainerNotFound)
return
}
resp.SuccessWithData(jobs.ResponseAccepted, ContainerPortsResponse{portPairs})
}
示例4: 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())
}
}
示例5: 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)
}
示例6: 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])
}
}
示例7: Execute
func (j *deleteContainer) Execute(resp jobs.Response) {
unitName := j.Id.UnitNameFor()
unitPath := j.Id.UnitPathFor()
unitDefinitionsPath := j.Id.VersionedUnitsPathFor()
idleFlagPath := j.Id.IdleUnitPathFor()
socketUnitPath := j.Id.SocketUnitPathFor()
homeDirPath := j.Id.BaseHomePath()
runDirPath := j.Id.RunPathFor()
networkLinksPath := j.Id.NetworkLinksPathFor()
_, err := systemd.Connection().GetUnitProperties(unitName)
switch {
case systemd.IsNoSuchUnit(err):
resp.Success(jobs.ResponseOk)
return
case err != nil:
resp.Failure(ErrDeleteContainerFailed)
return
}
if err := systemd.Connection().StopUnitJob(unitName, "fail"); err != nil {
log.Printf("delete_container: Unable to queue stop unit job: %v", err)
}
ports, err := containers.GetExistingPorts(j.Id)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("delete_container: Unable to read existing port definitions: %v", err)
}
ports = port.PortPairs{}
}
if err := portReserver.ReleaseExternalPorts(ports); err != nil {
log.Printf("delete_container: Unable to release ports: %v", err)
}
if err := os.Remove(unitPath); err != nil && !os.IsNotExist(err) {
resp.Failure(ErrDeleteContainerFailed)
return
}
if err := os.Remove(idleFlagPath); err != nil && !os.IsNotExist(err) {
resp.Failure(ErrDeleteContainerFailed)
return
}
if err := csystemd.SetUnitStartOnBoot(j.Id, false); err != nil {
log.Printf("delete_container: Unable to clear unit boot state: %v", err)
}
if err := os.Remove(socketUnitPath); err != nil && !os.IsNotExist(err) {
log.Printf("delete_container: Unable to remove socket unit path: %v", err)
}
if err := os.Remove(networkLinksPath); err != nil && !os.IsNotExist(err) {
log.Printf("delete_container: Unable to remove network links file: %v", err)
}
if err := os.RemoveAll(unitDefinitionsPath); err != nil {
log.Printf("delete_container: Unable to remove definitions for container: %v", err)
}
if err := os.RemoveAll(filepath.Dir(runDirPath)); err != nil {
log.Printf("delete_container: Unable to remove run directory: %v", err)
}
if err := os.RemoveAll(filepath.Dir(homeDirPath)); err != nil {
log.Printf("delete_container: Unable to remove home directory: %v", err)
}
if _, err := systemd.Connection().DisableUnitFiles([]string{unitPath, socketUnitPath}, false); err != nil {
log.Printf("delete_container: Some units have not been disabled: %v", err)
}
if err := systemd.Connection().Reload(); err != nil {
log.Printf("delete_container: Some units have not been disabled: %v", err)
}
resp.Success(jobs.ResponseOk)
}
示例8: Execute
func (req *installContainer) Execute(resp jobs.Response) {
id := req.Id
unitName := id.UnitNameFor()
unitPath := id.UnitPathFor()
unitVersionPath := id.VersionedUnitPathFor(req.RequestIdentifier.String())
socketUnitName := id.SocketUnitNameFor()
socketUnitPath := id.SocketUnitPathFor()
var socketActivationType string
if req.SocketActivation {
socketActivationType = "enabled"
if !req.SkipSocketProxy {
socketActivationType = "proxied"
}
}
// attempt to download the environment if it is remote
env := req.Environment
if env != nil {
if err := env.Fetch(100 * 1024); err != nil {
resp.Failure(ErrContainerCreateFailed)
return
}
if env.Empty() {
env = nil
}
}
// open and lock the base path (to prevent simultaneous updates)
state, exists, err := utils.OpenFileExclusive(unitPath, 0664)
if err != nil {
log.Print("install_container: Unable to lock unit file: ", err)
resp.Failure(ErrContainerCreateFailed)
}
defer state.Close()
// write a new file to disk that describes the new service
unit, err := utils.CreateFileExclusive(unitVersionPath, 0664)
if err != nil {
log.Print("install_container: Unable to open unit file definition: ", err)
resp.Failure(ErrContainerCreateFailed)
return
}
defer unit.Close()
// if this is an existing container, read the currently reserved ports
existingPorts := port.PortPairs{}
if exists {
existingPorts, err = containers.GetExistingPorts(id)
if err != nil {
if _, ok := err.(*os.PathError); !ok {
log.Print("install_container: Unable to read existing ports from file: ", err)
resp.Failure(ErrContainerCreateFailed)
return
}
}
}
// allocate and reserve ports for this container
reserved, erra := portReserver.AtomicReserveExternalPorts(unitVersionPath, req.Ports, existingPorts)
if erra != nil {
log.Printf("install_container: Unable to reserve external ports: %+v", erra)
resp.Failure(ErrContainerCreateFailedPortsReserved)
return
}
if len(reserved) > 0 {
resp.WritePendingSuccess(PendingPortMappingName, reserved)
}
var portSpec string
if req.Simple && len(reserved) == 0 {
portSpec = "-P"
} else {
portSpec = dockerPortSpec(reserved)
}
// write the environment to disk
var environmentPath string
if env != nil {
if errw := env.Write(false); errw != nil {
resp.Failure(ErrContainerCreateFailed)
return
}
environmentPath = env.Id.EnvironmentPathFor()
}
// write the network links (if any) to disk
if req.NetworkLinks != nil {
if errw := req.NetworkLinks.Write(id.NetworkLinksPathFor(), false); errw != nil {
resp.Failure(ErrContainerCreateFailed)
return
}
}
var sliceName string
if "" == req.SystemdSlice {
sliceName = DefaultSlice
} else {
sliceNames := []string{}
sliceFound := false
//.........這裏部分代碼省略.........