add required memory configuration to Route

This commit is contained in:
Pedro Nasser
2016-09-09 00:53:46 -03:00
parent 77813b1d3f
commit f461312553
2 changed files with 13 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS routes (
app_name character varying(256) NOT NULL,
path text NOT NULL,
image character varying(256) NOT NULL,
memory integer NOT NULL,
headers text NOT NULL,
config text NOT NULL,
PRIMARY KEY (app_name, path)
@@ -31,7 +32,7 @@ const extrasTableCreate = `CREATE TABLE IF NOT EXISTS extras (
value character varying(256) NOT NULL
);`
const routeSelector = `SELECT app_name, path, image, headers, config FROM routes`
const routeSelector = `SELECT app_name, path, image, memory, headers, config FROM routes`
type rowScanner interface {
Scan(dest ...interface{}) error
@@ -182,6 +183,7 @@ func (ds *PostgresDatastore) StoreRoute(route *models.Route) (*models.Route, err
app_name,
path,
image,
memory,
headers,
config
)
@@ -189,12 +191,14 @@ func (ds *PostgresDatastore) StoreRoute(route *models.Route) (*models.Route, err
ON CONFLICT (app_name, path) DO UPDATE SET
path = $2,
image = $3,
headers = $4,
config = $5;
memory = $4,
headers = $5,
config = $6;
`,
route.AppName,
route.Path,
route.Image,
route.Memory,
string(hbyte),
string(cbyte),
)
@@ -225,6 +229,7 @@ func scanRoute(scanner rowScanner, route *models.Route) error {
&route.AppName,
&route.Path,
&route.Image,
&route.Memory,
&headerStr,
&configStr,
)

View File

@@ -24,6 +24,7 @@ type Route struct {
AppName string `json:"appname,omitempty"`
Path string `json:"path,omitempty"`
Image string `json:"image,omitempty"`
Memory uint64 `json:"memory,omitempty"`
Headers http.Header `json:"headers,omitempty"`
Config `json:"config"`
}
@@ -43,6 +44,10 @@ func (r *Route) Validate() error {
res = append(res, ErrRoutesValidationMissingImage)
}
if r.Memory == 0 {
r.Memory = 128
}
if r.AppName == "" {
res = append(res, ErrRoutesValidationMissingAppName)
}