Skip to content

Commit

Permalink
save room metadata and send on timeout forwards
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Apr 12, 2019
1 parent 716ec1e commit ade6512
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 171 deletions.
4 changes: 2 additions & 2 deletions api/room_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (g *RoomPingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
g.App.DBClient.WithContext(r.Context()),
mr,
g.App.KubernetesClient,
payload.Status,
payload,
g.App.Config,
room,
g.App.SchedulerCache,
Expand Down Expand Up @@ -251,7 +251,7 @@ func (g *RoomStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
g.App.DBClient.WithContext(r.Context()),
mr,
g.App.KubernetesClient,
payload.Status,
payload,
g.App.Config,
room,
g.App.SchedulerCache,
Expand Down
8 changes: 8 additions & 0 deletions api/room_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down Expand Up @@ -157,6 +158,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
}).Times(2)
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any()).Times(2)
mockPipeline.EXPECT().ZRem(lKey, roomName).Times(2)
Expand Down Expand Up @@ -288,6 +290,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down Expand Up @@ -324,6 +327,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down Expand Up @@ -386,6 +390,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down Expand Up @@ -521,6 +526,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down Expand Up @@ -558,6 +564,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": `{"ipv6Label":"","type":"sometype"}`,
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down Expand Up @@ -616,6 +623,7 @@ forwarders:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand Down
2 changes: 1 addition & 1 deletion config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ reporters:
region: "region"
http:
timeout: "5s"
putURL: "localhost:8080"
putURL: "http://localhost:8080"
region: "region"
scaleUpTimeoutSeconds: 600
scaleDownTimeoutSeconds: 600
Expand Down
2 changes: 1 addition & 1 deletion config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ reporters:
region: "test"
http:
timeout: "5s"
putURL: "localhost:8080"
putURL: "http://localhost:8080"
region: "test"
scaleUpTimeoutSeconds: 300
scaleDownTimeoutSeconds: 300
Expand Down
13 changes: 4 additions & 9 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ func SetRoomStatus(
db pginterfaces.DB,
mr *models.MixedMetricsReporter,
clientset kubernetes.Interface,
status string,
roomPayload *models.RoomStatusPayload,
config *viper.Viper,
room *models.Room,
schedulerCache *models.SchedulerCache,
Expand All @@ -1214,18 +1214,13 @@ func SetRoomStatus(
return err
}
roomsCountByStatus, err := room.SetStatus(
redisClient,
db,
mr,
status,
cachedScheduler.Scheduler,
status == models.StatusOccupied,
)
redisClient, db, mr,
roomPayload, cachedScheduler.Scheduler)
if err != nil {
return err
}

if status != models.StatusOccupied {
if roomPayload.Status != models.StatusOccupied {
return nil
}

Expand Down
11 changes: 7 additions & 4 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6352,6 +6352,7 @@ containers:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
Expand All @@ -6370,7 +6371,7 @@ containers:
mockDb,
mr,
clientset,
status,
&models.RoomStatusPayload{Status: status},
config,
room,
schedulerCache,
Expand All @@ -6389,6 +6390,7 @@ containers:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().Eval(models.ZaddIfNotExists, gomock.Any(), roomName)
Expand Down Expand Up @@ -6465,7 +6467,7 @@ containers:
mockDb,
mr,
clientset,
status,
&models.RoomStatusPayload{Status: status},
config,
room,
schedulerCache,
Expand All @@ -6486,6 +6488,7 @@ containers:
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
"metadata": "",
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().Eval(models.ZaddIfNotExists, gomock.Any(), roomName)
Expand Down Expand Up @@ -6520,7 +6523,7 @@ containers:
mockDb,
mr,
clientset,
status,
&models.RoomStatusPayload{Status: status},
config,
room,
schedulerCache,
Expand All @@ -6544,7 +6547,7 @@ containers:
mockDb,
mr,
clientset,
status,
&models.RoomStatusPayload{Status: status},
config,
room,
schedulerCache,
Expand Down
49 changes: 39 additions & 10 deletions dev-room/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# External deps
import sys
import signal
import time
import requests
Expand All @@ -8,32 +7,51 @@
import threading
from logging.config import fileConfig

# Internal deps
# Internal deps
import constant
from api import Healthcheck, Address, Status, IncreaseCPUUsage, IncreaseMemUsage
from api import (
Healthcheck, Address, Status,
IncreaseCPUUsage, IncreaseMemUsage
)

fileConfig('logging_config.ini')
logger = logging.getLogger()

status = "ready"


def sigterm_handler(signal, frame):
global status
print('Terminating room')
status = "terminating"
requests.put("{}/{}".format(constant.MAESTRO_ADDR, constant.ROOM_PING_ENDPOINT), json={"timestamp": int(time.time()), "status": status})
requests.put("{}/{}".format(
constant.MAESTRO_ADDR,
constant.ROOM_PING_ENDPOINT,
), json={"timestamp": int(time.time()), "status": status})
exit()


signal.signal(signal.SIGTERM, sigterm_handler)
signal.signal(signal.SIGINT, sigterm_handler)


def ping():
while True:
try:
print("ping {}/{}".format(constant.MAESTRO_ADDR, constant.ROOM_PING_ENDPOINT))
print("ping {}/{}".format(
constant.MAESTRO_ADDR,
constant.ROOM_PING_ENDPOINT))
print("status {}".format(status))
requests.put("{}/{}".format(constant.MAESTRO_ADDR, constant.ROOM_PING_ENDPOINT), json={"timestamp": int(time.time()), "status": status})
requests.put("{}/{}".format(
constant.MAESTRO_ADDR,
constant.ROOM_PING_ENDPOINT,
), json={
"timestamp": int(time.time()),
"status": status,
"metadata": {
"region": "us"
}
})
except Exception as ex:
print(str(ex))
pass
Expand All @@ -42,10 +60,21 @@ def ping():

while True:
try:
print("polling {}/{}".format(constant.MAESTRO_ADDR, constant.ROOM_ADDR_ENDPOINT))
r = requests.get("{}/{}".format(constant.MAESTRO_ADDR, constant.ROOM_ADDR_ENDPOINT))
print("polling {}/{}".format(
constant.MAESTRO_ADDR,
constant.ROOM_ADDR_ENDPOINT))

r = requests.get("{}/{}".format(
constant.MAESTRO_ADDR,
constant.ROOM_ADDR_ENDPOINT))
if r.status_code == 200:
r = requests.put("{}/{}".format(constant.MAESTRO_ADDR, constant.ROOM_STATUS_ENDPOINT), json={"timestamp": int(time.time()), "status": "ready"})
r = requests.put("{}/{}".format(
constant.MAESTRO_ADDR,
constant.ROOM_STATUS_ENDPOINT,
), json={
"timestamp": int(time.time()),
"status": "ready",
})
break
except Exception as ex:
print(str(ex))
Expand All @@ -60,4 +89,4 @@ def ping():
app.add_route('/address', Address())
app.add_route('/status', Status())
app.add_route('/increase_cpu', IncreaseCPUUsage())
app.add_route('/increase_mem', IncreaseMemUsage())
app.add_route('/increase_mem', IncreaseMemUsage())
71 changes: 0 additions & 71 deletions manifests/maestro-boomforce-game.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion manifests/scheduler-config-5.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"shutdownTimeout": 10,
"autoscaling": {
"min": 4,
"min": 1,
"up": {
"delta": 1,
"trigger": {
Expand Down
Loading

0 comments on commit ade6512

Please sign in to comment.