Skip to content

Commit

Permalink
docs: add doc to run function & lambdo service
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodenMaiden committed May 16, 2024
1 parent 17b4f6d commit 9c673db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 14 additions & 8 deletions routes/function/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,17 @@ func (c *Controller) RunFunction(ctx *gin.Context) {
return
}

// retrieving freshly created function state
fnState, err = c.Scheduler.GetStateByID(
fmt.Sprintf(fnID.String(), ":", res.ID),
)

if err != nil {
return
}
}

if err != nil {
} else if err != nil { // else if the error is not a record not found, we return an error
log.Println(err.Error())
ctx.AbortWithStatusJSON(500, gin.H{"error": "Could not cold start the function"})
return
}

Expand All @@ -235,9 +236,9 @@ func (c *Controller) RunFunction(ctx *gin.Context) {
// we check if it is ready
fnState, err := c.Scheduler.GetStateByID(stateID)

// if the error is something else than a record not found, we return an error, else we retry since it is not ready yet
if err != nil {
ctx.AbortWithStatusJSON(500, gin.H{"error": err.Error()})
log.Println(err.Error())
ctx.AbortWithStatusJSON(500, gin.H{"Could not cold start the function": err.Error()})
return
}

Expand All @@ -249,15 +250,16 @@ func (c *Controller) RunFunction(ctx *gin.Context) {

// if even after 5 attempts the function is not ready, we return an error
if fnState.Status != database.FnReady {
ctx.AbortWithStatusJSON(500, gin.H{"error": "Function is not ready"})
ctx.AbortWithStatusJSON(503, gin.H{"error": "Function is not ready"})
return
}
}

// we notify everyone that the function is running
err = c.Scheduler.SetStatus(stateID, database.FnRunning)

if err != nil {
log.Println(err.Error())
log.Println(fmt.Sprint("Could not update state of VM", fnState.ID ,": ", err.Error()))
ctx.AbortWithStatusJSON(500, gin.H{"error": "Cannot update function's status"})
return
}
Expand All @@ -268,8 +270,9 @@ func (c *Controller) RunFunction(ctx *gin.Context) {
bytes.NewReader(fnBody),
)

// if the function had trouble running, we update the status to unknown
if err != nil {
ctx.AbortWithStatusJSON(500, gin.H{"error": err.Error()})
ctx.AbortWithStatusJSON(500, gin.H{"error": err.Error()})
_ = c.Scheduler.SetStatus(stateID, database.FnUnknownState)
return
} else {
Expand All @@ -279,6 +282,9 @@ func (c *Controller) RunFunction(ctx *gin.Context) {
err = c.Scheduler.SetStatus(stateID, database.FnReady)

if err != nil {
log.Println(
fmt.Sprint("Could not update state of VM", fnState.ID ,": ", err.Error()),
)
log.Println(err.Error())
}
}
Expand Down
4 changes: 4 additions & 0 deletions scheduler/lambdoService.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ type LambdoService struct {
}

type LambdoSpawnRequest struct {
// URL to the rootfs of the function
RootfsURL string `json:"rootfs"`
// Ports that the virtual machine needs to be exposed
// right now we only support one port
RequestedPorts []uint16 `json:"requestedPorts"`
}

type LambdoSpawnResponse struct {
ID string `json:"ID"`
// Ports mapped by lambdo, leading to the requested ports
Ports []uint16 `json:"ports"`
}

Expand Down

0 comments on commit 9c673db

Please sign in to comment.