|
16 | 16 | package lifecycle |
17 | 17 |
|
18 | 18 | import ( |
19 | | - "bpm/config" |
20 | | - "bpm/models" |
21 | | - "bpm/runc/client" |
22 | | - "bpm/usertools" |
23 | 19 | "errors" |
24 | 20 | "fmt" |
25 | 21 | "io" |
26 | 22 | "os" |
27 | 23 | "os/exec" |
28 | 24 | "time" |
29 | 25 |
|
30 | | - "github.com/opencontainers/runtime-spec/specs-go" |
| 26 | + specs "github.com/opencontainers/runtime-spec/specs-go" |
31 | 27 |
|
32 | 28 | "code.cloudfoundry.org/clock" |
33 | 29 | "code.cloudfoundry.org/lager" |
| 30 | + |
| 31 | + "bpm/config" |
| 32 | + "bpm/models" |
| 33 | + "bpm/runc/client" |
| 34 | + "bpm/usertools" |
34 | 35 | ) |
35 | 36 |
|
36 | 37 | const ( |
37 | 38 | ContainerSigQuitGracePeriod = 5 * time.Second |
38 | 39 | ContainerStatePollInterval = 1 * time.Second |
39 | | - ContainerStateRunning = "running" |
40 | | - ContainerStatePaused = "paused" |
41 | | - ContainerStateStopped = "stopped" |
| 40 | + |
| 41 | + ContainerStateRunning = "running" |
| 42 | + ContainerStatePaused = "paused" |
| 43 | + ContainerStateStopped = "stopped" |
42 | 44 | ) |
43 | 45 |
|
44 | | -var TimeoutError = errors.New("failed to stop job within timeout") |
| 46 | +var ( |
| 47 | + timeoutError = errors.New("failed to stop job within timeout") |
| 48 | + isNotExistError = errors.New("process is not running or could not be found") |
| 49 | +) |
| 50 | + |
| 51 | +func IsNotExist(err error) bool { |
| 52 | + return err == isNotExistError |
| 53 | +} |
45 | 54 |
|
46 | 55 | //go:generate counterfeiter . UserFinder |
47 | 56 |
|
@@ -151,18 +160,14 @@ func (j *RuncLifecycle) StartProcess(logger lager.Logger, bpmCfg *config.BPMConf |
151 | 160 | ) |
152 | 161 | } |
153 | 162 |
|
154 | | -// GetProcess returns the following: |
155 | | -// - process, nil if the process is running (and no errors were encountered) |
156 | | -// - nil,nil if the process is not running and there is no other error |
157 | | -// - nil,error if there is any other error getting the process beyond it not running |
158 | | -func (j *RuncLifecycle) GetProcess(cfg *config.BPMConfig) (*models.Process, error) { |
| 163 | +func (j *RuncLifecycle) StatProcess(cfg *config.BPMConfig) (*models.Process, error) { |
159 | 164 | container, err := j.runcClient.ContainerState(cfg.ContainerID()) |
160 | 165 | if err != nil { |
161 | 166 | return nil, err |
162 | 167 | } |
163 | 168 |
|
164 | 169 | if container == nil { |
165 | | - return nil, nil |
| 170 | + return nil, isNotExistError |
166 | 171 | } |
167 | 172 |
|
168 | 173 | return newProcessFromContainerState( |
@@ -231,7 +236,7 @@ func (j *RuncLifecycle) StopProcess(logger lager.Logger, cfg *config.BPMConfig, |
231 | 236 | } |
232 | 237 |
|
233 | 238 | j.clock.Sleep(ContainerSigQuitGracePeriod) |
234 | | - return TimeoutError |
| 239 | + return timeoutError |
235 | 240 | } |
236 | 241 | } |
237 | 242 | } |
|
0 commit comments