Add storage API abstraction

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-06-22 09:16:49 -03:00
committed by Marcos Lilljedahl
19 changed files with 277 additions and 83 deletions

View File

@@ -1,6 +1,7 @@
package pwd
import (
"io"
"time"
"github.com/play-with-docker/play-with-docker/docker"
@@ -42,10 +43,11 @@ func init() {
}
type pwd struct {
docker docker.DockerApi
tasks SchedulerApi
broadcast BroadcastApi
storage storage.StorageApi
docker docker.DockerApi
tasks SchedulerApi
broadcast BroadcastApi
storage storage.StorageApi
clientCount int32
}
type PWDApi interface {
@@ -60,18 +62,21 @@ type PWDApi interface {
InstanceResizeTerminal(instance *types.Instance, cols, rows uint) error
InstanceAttachTerminal(instance *types.Instance) error
InstanceUploadFromUrl(instance *types.Instance, url string) error
InstanceUploadFromReader(instance *types.Instance, filename string, reader io.Reader) error
InstanceGet(session *types.Session, name string) *types.Instance
// TODO remove this function when we add the session prefix to the PWD url
InstanceFindByIP(ip string) *types.Instance
InstanceFindByAlias(sessionPrefix, alias string) *types.Instance
InstanceFindByIPAndSession(sessionPrefix, ip string) *types.Instance
InstanceDelete(session *types.Session, instance *types.Instance) error
InstanceWriteToTerminal(instance *types.Instance, data string)
InstanceWriteToTerminal(sessionId, instanceName string, data string)
InstanceAllowedImages() []string
InstanceExec(instance *types.Instance, cmd []string) (int, error)
ClientNew(id string, session *types.Session) *types.Client
ClientResizeViewPort(client *types.Client, cols, rows uint)
ClientClose(client *types.Client)
ClientCount() int
}
func NewPWD(d docker.DockerApi, t SchedulerApi, b BroadcastApi, s storage.StorageApi) *pwd {
@@ -83,7 +88,7 @@ func (p *pwd) setGauges() {
ses := float64(s)
i, _ := p.storage.InstanceCount()
ins := float64(i)
c, _ := p.storage.ClientCount()
c := p.ClientCount()
cli := float64(c)
clientsGauge.Set(cli)