Create your own functionk working.

This commit is contained in:
Alex 2017-02-23 09:09:22 +00:00 committed by Alex Ellis
parent 98c9ef67f4
commit fe1e9fc52e
4 changed files with 51 additions and 9 deletions

View File

@ -1,4 +1,4 @@
<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">

View File

@ -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();

View File

@ -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
}

View File

@ -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 {