Skip to content

Commit

Permalink
Refactored some proxy code to reuse with wolfpack (vmware#7261)
Browse files Browse the repository at this point in the history
Refactored the system, volume, container, and stream swagger code
into proxy code.

1) Moved the errors.go from backends to a new folder to be accessed
by all folders outside of the backends folder.
2) Refactored Container proxy and moved from engine/backends to engine/proxy
3) Refactored Volume proxy and moved from engine/backends to engine/proxy
4) Refactored System proxy and moved from engine/backends to engine/proxy
5) Refactored Stream proxy and moved from engine/backends to engine/proxy
6) Adopted some common patterns in all the proxies
7) Moved common networking util calls to engine/networking
8) Fix up unit tests
9) Changed all "not yet implemented messages"
10) Updated robot scripts

More refactoring will be needed to make these proxy less dependent on
docker types and portlayer swagger types.

Helps resolves vmware#7210 and vmware#7232
  • Loading branch information
Loc Nguyen authored and singhshwetaQE committed Apr 3, 2018
1 parent 01a04bc commit cfe035c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 0 additions & 4 deletions lib/apiservers/engine/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@ func setPortMapping(info *models.ContainerInfo, backend *ContainerBackend, conta
}
for _, e := range endpointsOK.Payload {
if len(e.Ports) > 0 && e.Scope == constants.BridgeScopeType {
<<<<<<< d14b5abfb36b03fbf05ce7655a551d9f9c05d205
if err = network.MapPorts(container, e, container.ContainerID); err != nil {
=======
if err = MapPorts(container, e, container.ContainerID); err != nil {
>>>>>>> Correct ps output after network connect
log.Errorf(err.Error())
return err
}
Expand Down
5 changes: 4 additions & 1 deletion lib/apiservers/engine/backends/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import (
"github.com/vmware/vic/lib/apiservers/portlayer/client/scopes"
"github.com/vmware/vic/lib/apiservers/portlayer/models"
"github.com/vmware/vic/lib/archive"
"github.com/vmware/vic/lib/config/executor"
"github.com/vmware/vic/lib/constants"
"github.com/vmware/vic/lib/metadata"
"github.com/vmware/vic/pkg/errors"
Expand Down Expand Up @@ -1403,11 +1402,15 @@ payloadLoop:
ips = []string{""}
}
c := cache.ContainerCache().GetContainer(t.ContainerConfig.ContainerID)
<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
if c != nil {
ports = append(ports, network.PortForwardingInformation(c, ips)...)
} else {
log.Warningf("Container is not found in cache: %s", t.ContainerConfig.ContainerID)
}
=======
ports = append(ports, network.PortForwardingInformation(c, ips)...)
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
}

// verify that the repo:tag exists for the container -- if it doesn't then we should present the
Expand Down
28 changes: 25 additions & 3 deletions lib/apiservers/engine/backends/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ import (
plscopes "github.com/vmware/vic/lib/apiservers/portlayer/client/scopes"
"github.com/vmware/vic/lib/apiservers/portlayer/models"
plmodels "github.com/vmware/vic/lib/apiservers/portlayer/models"
<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
<<<<<<< d14b5abfb36b03fbf05ce7655a551d9f9c05d205
=======
"github.com/vmware/vic/lib/archive"
>>>>>>> Correct ps output after network connect
=======
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
"github.com/vmware/vic/lib/config/executor"
"github.com/vmware/vic/lib/metadata"
"github.com/vmware/vic/pkg/trace"
Expand Down Expand Up @@ -806,6 +809,7 @@ func TestPortInformation(t *testing.T) {
co.Name = "bar"
cache.ContainerCache().AddContainer(co)

<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
<<<<<<< 1b361d7b10429a75d3fa7ec622cc19d885d95a61
// unless there are entries in vicnetwork.ContainerByPort we won't report them as bound
ports := network.PortForwardingInformation(nil, ips)
Expand All @@ -828,19 +832,27 @@ func TestPortInformation(t *testing.T) {
=======
// unless there are entries in containerByPort we won't report them as bound
ports := portForwardingInformation(mockContainerInfo, ips)
=======
// unless there are entries in vicnetwork.ContainerByPort we won't report them as bound
ports := network.PortForwardingInformation(co, ips)
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
assert.Empty(t, ports, "There should be no bound IPs at this point for forwarding")

// the current port binding should show up as a direct port
ports = directPortInformation(mockContainerInfo)
ports = network.DirectPortInformation(mockContainerInfo)
assert.NotEmpty(t, ports, "There should be a direct port")

containerByPort["8000"] = containerID
ports = portForwardingInformation(mockContainerInfo, ips)
network.ContainerByPort["8000"] = containerID
ports = network.PortForwardingInformation(co, ips)
assert.NotEmpty(t, ports, "There should be bound IPs")
assert.Equal(t, 1, len(ports), "Expected 1 port binding, found %d", len(ports))
// now that this port presents as a forwarded port it should NOT present as a direct port
<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
ports = directPortInformation(mockContainerInfo)
>>>>>>> Fix DHCP and IP reporting for container networks
=======
ports = network.DirectPortInformation(mockContainerInfo)
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
assert.Empty(t, ports, "There should not be a direct port")

port, _ = nat.NewPort("tcp", "80")
Expand All @@ -852,13 +864,18 @@ func TestPortInformation(t *testing.T) {

// forwarding of 00 should never happen, but this is allowing us to confirm that
// it's kicked out by the function even if present in the map
<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
<<<<<<< 1b361d7b10429a75d3fa7ec622cc19d885d95a61
network.ContainerByPort["00"] = containerID
ports = network.PortForwardingInformation(co, ips)
=======
containerByPort["00"] = containerID
ports = portForwardingInformation(mockContainerInfo, ips)
>>>>>>> Fix DHCP and IP reporting for container networks
=======
network.ContainerByPort["00"] = containerID
ports = network.PortForwardingInformation(co, ips)
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
assert.NotEmpty(t, ports, "There should be 1 bound IP")
assert.Equal(t, 1, len(ports), "Expected 1 port binding, found %d", len(ports))

Expand All @@ -868,13 +885,18 @@ func TestPortInformation(t *testing.T) {
HostPort: "800",
}
portMap[port] = portBindings
<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
<<<<<<< 1b361d7b10429a75d3fa7ec622cc19d885d95a61
network.ContainerByPort["800"] = containerID
ports = network.PortForwardingInformation(co, ips)
=======
containerByPort["800"] = containerID
ports = portForwardingInformation(mockContainerInfo, ips)
>>>>>>> Fix DHCP and IP reporting for container networks
=======
network.ContainerByPort["800"] = containerID
ports = network.PortForwardingInformation(co, ips)
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
assert.Equal(t, 2, len(ports), "Expected 2 port binding, found %d", len(ports))
}

Expand Down
4 changes: 4 additions & 0 deletions lib/apiservers/engine/network/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,11 @@ func PortForwardingInformation(vc *viccontainer.VicContainer, ips []string) []ty
//c := cache.ContainerCache().GetContainer(cid)

if vc == nil {
<<<<<<< 01a04bc73dd368d76ae28d0f138d80ff2eb542da
log.Errorf("No container provided")
=======
log.Errorf("Could not find container with ID %s", vc.ContainerID)
>>>>>>> Refactored some proxy code to reuse with wolfpack (#7261)
return nil
}

Expand Down

0 comments on commit cfe035c

Please sign in to comment.