Skip to content

Get dependency status based on docker service and docker container#429

Merged
antho1404 merged 32 commits intodevfrom
daemon-status-fix
Sep 11, 2018
Merged

Get dependency status based on docker service and docker container#429
antho1404 merged 32 commits intodevfrom
daemon-status-fix

Conversation

@antho1404
Copy link
Copy Markdown
Member

Pull request based on this one #411

@antho1404 antho1404 requested review from a team, NicolasMahe and krhubert September 5, 2018 10:09
@antho1404 antho1404 added this to the v1.2.0 milestone Sep 5, 2018
Copy link
Copy Markdown
Contributor

@ilgooz ilgooz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we can always add some more tests to inc branch coverage :)

Comment thread container/container.go

// containerExists return true if the docker service can be found, return false otherwise and return
// any errors that are not `NotFound` errors
func (c *Container) containerExists(namespace []string) (bool, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// containerExists checks if container with namespace can be found.

Comment thread container/container.go
// presenceHandling handle the error the check the presence of a docker resource.
// It returns any error that are not docker `NotFound` errors
// It returns a boolean that says if the docker resource exists
func presenceHandling(err error) (bool, error) {
Copy link
Copy Markdown
Contributor

@ilgooz ilgooz Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// presenceHandling checks err to see if it's a Docker NotFound error and if not
// it'll return the err back.

Comment thread container/container.go

// serviceExists return true if the docker container can be found, return false otherwise and return
// any errors that are not `NotFound` errors
func (c *Container) serviceExists(namespace []string) (bool, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// serviceExists checks if corresponding container for service namespace can be found.

Comment thread container/container.go
// - RUNNING: When the container is running in docker (whatever the status of the service)
// - STARTING: When the service is running but the container is not yet started
// - STOPPED: When neither the container nor the service are running in docker
func (c *Container) Status(namespace []string) (StatusType, error) {
Copy link
Copy Markdown
Contributor

@ilgooz ilgooz Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// status returns the status of the container based on the docker container and docker service.
// if any error occurs during the status check, status will be shown as UNKNOWN.
// otherwise the following rules will be applied to determine a status:
//  - RUNNING: when the container is running in docker regardless of the status of the service.
//  - STARTING: when the service is running but the container is not yet started.
//  - STOPPED: when the container and the service is not running in docker.

Comment thread container/container.go Outdated
func (c *Container) containerExists(namespace []string) (bool, error) {
container, err := c.FindContainer(namespace)
if err == nil && container.State != nil &&
xstrings.SliceContains([]string{"exited", "dead"}, container.State.Status) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !xstrings.SliceContains([]string{"exited", "dead"}, container.State.Status), nil ?

available statuses:
created, restarting, running, removing, paused, exited, dead

@antho1404 antho1404 changed the base branch from daemon-status to dev September 11, 2018 07:22
@antho1404 antho1404 requested a review from a team September 11, 2018 09:23
@antho1404 antho1404 merged commit c1ac6c4 into dev Sep 11, 2018
@antho1404 antho1404 deleted the daemon-status-fix branch September 11, 2018 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants