Skip to content
Snippets Groups Projects
Commit fe1e9fc5 authored by Alex's avatar Alex Committed by Alex Ellis
Browse files

Create your own functionk working.

parent 98c9ef67
No related branches found
No related tags found
No related merge requests found
<md-dialog aria-label="List dialog" layout="column" flex="80">
<md-dialog aria-label="List dialog" layout="column" flex="70">
<md-dialog-content class="md-padding">
<label>Define a function:</label>
<form name="userForm">
......@@ -10,14 +10,14 @@
</div>
<div layout-gt-xs="row">
<md-input-container class="md-block" flex-gt-sm>
<label>Name:</label>
<input name="serviceName" ng-model="item.name" required md-maxlength="200" minlength="4">
<label>Service name:</label>
<input name="serviceName" ng-model="item.service" required md-maxlength="200" minlength="4">
</md-input-container>
</div>
<div layout-gt-xs="row">
<md-input-container class="md-block" flex-gt-sm>
<label>fProcess:</label>
<input name="fprocess" ng-model="item.fprocess" required md-maxlength="200" minlength="4">
<input name="envProcess" ng-model="item.envProcess" required md-maxlength="200" minlength="1">
</md-input-container>
</div>
<div layout-gt-xs="row">
......
......@@ -10,9 +10,14 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', '$md
$scope.invocation = {
contentType: "text"
};
$scope.functionTemplate = {
image: ""
image: "",
envProcess: "",
network: "",
service: ""
};
$scope.invocation.request = ""
setInterval(function() {
refreshData();
......
......@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"io/ioutil"
......@@ -12,6 +13,7 @@ import (
"github.com/alexellis/faas/gateway/requests"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
io_prometheus_client "github.com/prometheus/client_model/go"
)
......@@ -78,5 +80,40 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
fmt.Println(request)
w.WriteHeader(http.StatusNotImplemented)
options := types.ServiceCreateOptions{}
spec := makeSpec(&request)
response, err := c.ServiceCreate(context.Background(), spec, options)
if err != nil {
log.Println(err)
}
log.Println(response.ID, response.Warnings)
}
}
func makeSpec(request *requests.CreateFunctionRequest) swarm.ServiceSpec {
max := uint64(1)
nets := []swarm.NetworkAttachmentConfig{
swarm.NetworkAttachmentConfig{Target: request.Network},
}
spec := swarm.ServiceSpec{
TaskTemplate: swarm.TaskSpec{
RestartPolicy: &swarm.RestartPolicy{
MaxAttempts: &max,
Condition: swarm.RestartPolicyConditionNone,
},
ContainerSpec: swarm.ContainerSpec{
Image: request.Image,
Env: []string{fmt.Sprintf("fprocess=%s", request.EnvProcess)},
Labels: map[string]string{"function": "true"},
},
Networks: nets,
},
Annotations: swarm.Annotations{
Name: request.Service,
},
}
return spec
}
......@@ -2,10 +2,10 @@ package requests
// CreateFunctionRequest create a function in the swarm.
type CreateFunctionRequest struct {
Service string `json:"service"`
FProcess string `json:"fprocess"`
Image string `json:"image"`
Network string `json:"network"`
Service string `json:"service"`
Image string `json:"image"`
Network string `json:"network"`
EnvProcess string `json:"envProcess"`
}
type AlexaSessionApplication struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment