Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ func (handler *ContainersHandlersImpl) GetHandler(params containers.GetParams) m
op := trace.NewOperationFromID(context.Background(), params.OpID, "containers.GetHandler(%s)", params.ID)
defer trace.End(trace.Begin("GetHandler", op))

h := exec.GetContainer(context.Background(), uid.Parse(params.ID))
h, err := exec.GetContainer(context.Background(), uid.Parse(params.ID))
if err != nil {
return containers.NewGetDefault(503).WithPayload(&models.Error{Message: err.Error()})
}
if h == nil {
return containers.NewGetNotFound().WithPayload(&models.Error{Message: fmt.Sprintf("container %s not found", params.ID)})
}
Expand Down
10 changes: 5 additions & 5 deletions lib/portlayer/exec/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ func newContainer(base *containerBase) *Container {
return c
}

func GetContainer(ctx context.Context, id uid.UID) *Handle {
func GetContainer(ctx context.Context, id uid.UID) (*Handle, error) {
// get from the cache
container := Containers.Container(id.String())
if container != nil {
return container.NewHandle(ctx)
}

return nil
return nil, nil
}

func (c *ContainerInfo) String() string {
Expand Down Expand Up @@ -318,20 +318,20 @@ func (c *Container) WaitForState(s State) <-chan struct{} {
return eventChan
}

func (c *Container) NewHandle(ctx context.Context) *Handle {
func (c *Container) NewHandle(ctx context.Context) (*Handle, error) {
// Call property collector to fill the data
if c.vm != nil {
op := trace.FromContext(ctx, "")
// FIXME: this should be calling the cache to decide if a refresh is needed
if err := c.Refresh(op); err != nil {
op.Errorf("refreshing container %s failed: %s", c, err)
return nil // nil indicates error
return nil, err
}
}

// return a handle that represents zero changes over the current configuration
// for this container
return newHandle(c)
return newHandle(c), nil
}

// Refresh updates config and runtime info, holding a lock only while swapping
Expand Down
6 changes: 3 additions & 3 deletions lib/portlayer/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func eventCallback(ie events.Event) {
operation := func() error {
var err error

handle := container.NewHandle(op)
if handle == nil {
err = fmt.Errorf("Handle for %s cannot be created", ie.Reference())
handle, err := container.NewHandle(op)
if err != nil {
err = fmt.Errorf("Handle for %s cannot be created: %s", ie.Reference(), err)
log.Error(err)
return err
}
Expand Down
5 changes: 4 additions & 1 deletion lib/portlayer/network/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ func (c *Container) Refresh(ctx context.Context) error {

// this will "refresh" the container executor config that contains
// the current ip addresses
h := exec.GetContainer(ctx, c.ID())
h, err := exec.GetContainer(ctx, c.ID())
if err != nil {
return fmt.Errorf("could not find container %s: %s", c.ID(), err)
}
if h == nil {
return fmt.Errorf("could not find container %s", c.ID())
}
Expand Down
11 changes: 9 additions & 2 deletions lib/portlayer/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ func handleEvent(netctx *Context, ie events.Event) {
op := trace.NewOperation(context.Background(), fmt.Sprintf("handleEvent(%s)", ie.EventID()))
op.Infof("Handling Event: %s", ie.EventID())
// grab the operation from the event
handle := exec.GetContainer(op, uid.Parse(ie.Reference()))
handle, err := exec.GetContainer(op, uid.Parse(ie.Reference()))
if err != nil {
op.Errorf("Could not find container: %s", err)
return
}
if handle == nil {
_, err := netctx.RemoveIDFromScopes(op, ie.Reference())
if err != nil {
Expand Down Expand Up @@ -196,7 +200,10 @@ func engageContext(op trace.Operation, netctx *Context, em event.EventManager) e
defer s.Resume()
for _, c := range exec.Containers.Containers(nil) {
log.Debugf("adding container %s", c)
h := c.NewHandle(op)
h, err := c.NewHandle(op)
if err != nil {
return err
}
defer h.Close()

// add any user created networks that show up in container's config
Expand Down
6 changes: 3 additions & 3 deletions lib/portlayer/portlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ func TakeCareOfSerialPorts(op trace.Operation, sess *session.Session) {

operation := func() error {
// Obtain a container handle
handle := containers[i].NewHandle(op)
if handle == nil {
err := fmt.Errorf("unable to obtain a handle for container %s", containerID)
handle, err := containers[i].NewHandle(op)
if err != nil {
err := fmt.Errorf("unable to obtain a handle for container %s: %s", containerID, err)
op.Errorf("%s", err)

return err
Expand Down