Commit 79889b7c authored by Stefan Dähling's avatar Stefan Dähling
Browse files

create new name for agency in local depl

parent 20cf6de1
Pipeline #261710 passed with stages
in 2 minutes and 50 seconds
......@@ -53,6 +53,7 @@ import (
"log"
"net/http"
"os"
"strconv"
"time"
agcli "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/agency/client"
......@@ -195,7 +196,7 @@ func (ams *AMS) getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyIn
func (ams *AMS) createMAS(masSpec schemas.MASSpec) (err error) {
// fill masInfo
var masInfo schemas.MASInfo
var numAgencies map[int]int
var numAgencies []int
masInfo, numAgencies, err = ams.configureMAS(masSpec)
if err != nil {
return
......@@ -215,7 +216,7 @@ func (ams *AMS) createMAS(masSpec schemas.MASSpec) (err error) {
}
// startMAS starts the MAS
func (ams *AMS) startMAS(masID int, masInfo schemas.MASInfo, numAgencies map[int]int) (err error) {
func (ams *AMS) startMAS(masID int, masInfo schemas.MASInfo, numAgencies []int) (err error) {
err = ams.stor.storeMAS(masID, masInfo)
if err != nil {
ams.logError.Println(err.Error())
......@@ -231,13 +232,7 @@ func (ams *AMS) startMAS(masID int, masInfo schemas.MASInfo, numAgencies map[int
}
// deploy containers
image := ""
pullSecret := ""
if len(masInfo.ImageGroups) > 0 {
image = masInfo.ImageGroups[0].Image
pullSecret = masInfo.ImageGroups[0].PullSecret
}
err = ams.depl.newMAS(masID, image, pullSecret, numAgencies, masInfo.Config.Logging,
err = ams.depl.newMAS(masID, masInfo.ImageGroups, masInfo.Config.Logging,
masInfo.Config.MQTT, masInfo.Config.DF)
if err != nil {
ams.logError.Println(err.Error())
......@@ -249,8 +244,8 @@ func (ams *AMS) startMAS(masID int, masInfo schemas.MASInfo, numAgencies map[int
}
// configureMAS fills the missing configuration as agencies, agent ids and addresses
func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo, numAgencies map[int]int,
err error) {
func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
numAgencies []int, err error) {
// extract all image groups
imageTemp := make(map[string]interface{})
for i := range masSpec.ImageGroups {
......@@ -274,7 +269,7 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
// total number of agents and total number of agencies
masInfo.Agents.Counter = 0
numAgencies = make(map[int]int)
numAgencies = make([]int, len(masSpec.ImageGroups), len(masSpec.ImageGroups))
masInfo.Agencies.Counter = 0
for i := range masSpec.ImageGroups {
masInfo.Agents.Counter += len(masSpec.ImageGroups[i].Agents)
......@@ -301,8 +296,11 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
for j := range masSpec.ImageGroups[i].Agents {
masInfo.Agents.Instances[agentID].Spec = masSpec.ImageGroups[i].Agents[j]
masInfo.Agents.Instances[agentID].ID = agentID
masInfo.Agents.Instances[agentID].AgencyID = agencyIDOffset + j/masSpec.Config.NumAgentsPerAgency
masInfo.Agents.Instances[agentID].AgencyID = agencyIDOffset +
j/masSpec.Config.NumAgentsPerAgency
masInfo.Agents.Instances[agentID].ImageGroupID = i
masInfo.Agents.Instances[agentID].Address.Agency = "-im-" + strconv.Itoa(i) + "-agency-" +
strconv.Itoa(j/masSpec.Config.NumAgentsPerAgency)
for j := range masInfo.Graph.Node {
if masInfo.Graph.Node[j].ID == masInfo.Agents.Instances[i].Spec.NodeID {
masInfo.Graph.Node[j].Agent = append(masInfo.Graph.Node[j].Agent,
......@@ -325,6 +323,7 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
ImageGroupID: i,
ID: agencyID,
Logger: masSpec.Config.Logger,
Name: "-im-" + strconv.Itoa(i) + "-agency-" + strconv.Itoa(j),
}
for k := 0; k < masSpec.Config.NumAgentsPerAgency; k++ {
if agentCounter >= len(masSpec.ImageGroups[i].Agents) {
......
......@@ -61,7 +61,7 @@ import (
// deployment interface for interaction with storage
type deployment interface {
newMAS(masID int, image string, pullSecret string, numAgencies map[int]int, logging bool, mqtt bool,
newMAS(masID int, images []schemas.ImageGroupInfo, logging bool, mqtt bool,
df bool) (err error)
scaleMAS(masID int, deltaAgencies int) (err error)
deleteMAS(masID int) (err error)
......@@ -73,26 +73,28 @@ type localDeployment struct {
}
// newMAS triggers the cluster manager to start new agency containers
func (localdepl *localDeployment) newMAS(masID int, image string, pullSecret string,
numAgencies map[int]int, logging bool, mqtt bool, df bool) (err error) {
for i := 0; i < numAgencies[0]; i++ {
temp := schemas.StubAgencyConfig{
MASID: masID,
AgencyID: i,
NumAgents: 10,
Image: image,
Logging: logging,
MQTT: mqtt,
DF: df,
}
js, _ := json.Marshal(temp)
var statusCode int
httpClient := &http.Client{Timeout: time.Second * 10}
_, statusCode, err = httpretry.Post(httpClient, "http://"+localdepl.hostName+
":8000/api/container", " ", js, time.Second*2, 2)
if err == nil {
if statusCode != http.StatusCreated {
err = errors.New("Cannot create agency")
func (localdepl *localDeployment) newMAS(masID int, images []schemas.ImageGroupInfo,
logging bool, mqtt bool, df bool) (err error) {
for i := range images {
for j := 0; j < len(images[i].Agencies); j++ {
temp := schemas.StubAgencyConfig{
MASID: masID,
AgencyID: j,
ImageGroupID: i,
Image: images[i].Image,
Logging: logging,
MQTT: mqtt,
DF: df,
}
js, _ := json.Marshal(temp)
var statusCode int
httpClient := &http.Client{Timeout: time.Second * 10}
_, statusCode, err = httpretry.Post(httpClient, "http://"+localdepl.hostName+
":8000/api/container", " ", js, time.Second*2, 2)
if err == nil {
if statusCode != http.StatusCreated {
err = errors.New("Cannot create agency")
}
}
}
}
......
......@@ -52,6 +52,7 @@ import (
"strconv"
"time"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
apiappsv1 "k8s.io/api/apps/v1"
apicorev1 "k8s.io/api/core/v1"
resource "k8s.io/apimachinery/pkg/api/resource"
......@@ -70,8 +71,8 @@ type kubeDeplyoment struct {
}
// newMAS triggers the cluster manager to start new agency containers
func (kube *kubeDeplyoment) newMAS(masID int, image string, pullSecret string,
numAgencies map[int]int, logging bool, mqtt bool, df bool) (err error) {
func (kube *kubeDeplyoment) newMAS(masID int, images []schemas.ImageGroupInfo, logging bool,
mqtt bool, df bool) (err error) {
var exist bool
exist, err = kube.existStatefulSet(masID)
if err == nil {
......@@ -93,7 +94,8 @@ func (kube *kubeDeplyoment) newMAS(masID int, image string, pullSecret string,
dfEnv = "OFF"
}
err = kube.createStatefulSet(masID, image, pullSecret, numAgencies[0], loggingEnv, mqttEnv,
err = kube.createStatefulSet(masID, images[0].Image, images[0].PullSecret,
len(images[0].Agencies), loggingEnv, mqttEnv,
dfEnv)
} else {
// error
......
......@@ -322,13 +322,13 @@ func createMASStorage(masID int, masInfo schemas.MASInfo) (ret schemas.MASInfo)
ret.ID = masID
for i := 0; i < ret.Agents.Counter; i++ {
ret.Agents.Instances[i].MASID = masID
ret.Agents.Instances[i].Address.Agency = "mas-" + strconv.Itoa(masID) + "-agency-" +
strconv.Itoa(ret.Agents.Instances[i].AgencyID) + ".mas" + strconv.Itoa(masID) + "agencies"
ret.Agents.Instances[i].Address.Agency = "mas-" + ret.Agents.Instances[i].Address.Agency +
".mas" + strconv.Itoa(masID) + "agencies"
}
for i := 0; i < ret.Agencies.Counter; i++ {
ret.Agencies.Instances[i].MASID = masID
ret.Agencies.Instances[i].Name = "mas-" + strconv.Itoa(masID) + "-agency-" + strconv.Itoa(i) +
".mas" + strconv.Itoa(masID) + "agencies"
ret.Agencies.Instances[i].Name = "mas-" + strconv.Itoa(masID) +
ret.Agencies.Instances[i].Name + ".mas" + strconv.Itoa(masID) + "agencies"
}
return
}
......
......@@ -229,12 +229,13 @@ func (stub *LocalStub) deleteMQTT() (err error) {
}
// createAgency starts a new agency docker image
func (stub *LocalStub) createAgency(image string, agents int, masID int, agencyID int, logging bool,
func (stub *LocalStub) createAgency(image string, masID int, imID int, agencyID int, logging bool,
mqtt bool, df bool) (err error) {
com := "docker run -d"
com += " --name=mas-" + strconv.Itoa(masID) + "-agency-" + strconv.Itoa(agencyID) + ".mas" +
strconv.Itoa(masID) + "agencies" //.clonemap"
com += " --hostname=mas-" + strconv.Itoa(masID) + "-agency-" + strconv.Itoa(agencyID)
com += " --name=mas-" + strconv.Itoa(masID) + "-im-" + strconv.Itoa(imID) + "-agency-" +
strconv.Itoa(agencyID) + ".mas" + strconv.Itoa(masID) + "agencies"
com += " --hostname=mas-" + strconv.Itoa(masID) + "-im-" + strconv.Itoa(imID) + "-agency-" +
strconv.Itoa(agencyID)
com += " --network=clonemap-net"
//com += " -e CLONEMAP_SUFFIX=\".clonemap\" "
if logging {
......
......@@ -97,8 +97,8 @@ func (stub *LocalStub) handleAPI(w http.ResponseWriter, r *http.Request) {
agname := "mas-" + strconv.Itoa(agconfig.MASID) + "-agency-" +
strconv.Itoa(agconfig.AgencyID)
fmt.Println("Create Agency Container " + agname)
err = stub.createAgency(agconfig.Image, agconfig.NumAgents,
agconfig.MASID, agconfig.AgencyID, agconfig.Logging, agconfig.MQTT, agconfig.DF)
err = stub.createAgency(agconfig.Image, agconfig.MASID, agconfig.ImageGroupID,
agconfig.AgencyID, agconfig.Logging, agconfig.MQTT, agconfig.DF)
if err == nil {
stub.agencies = append(stub.agencies, agconfig)
err = httpreply.Created(w, nil, "text/plain", []byte("Ressource Created"))
......
......@@ -186,13 +186,13 @@ type AgencyStatus struct {
// StubAgencyConfig holds configuration of agency to be started or terminated
type StubAgencyConfig struct {
MASID int `json:"masid"`
AgencyID int `json:"agencyid"`
NumAgents int `json:"numagents"`
Image string `json:"image"`
Logging bool `json:"logging"` // switch for logging module
MQTT bool `json:"mqtt"` //switch for mqtt
DF bool `json:"df"` //switch for df
MASID int `json:"masid"`
AgencyID int `json:"agencyid"`
ImageGroupID int `json:"imid"` // ID of agency image
Image string `json:"image"`
Logging bool `json:"logging"` // switch for logging module
MQTT bool `json:"mqtt"` //switch for mqtt
DF bool `json:"df"` //switch for df
}
// ACLMessage struct representing agent message
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment