Commit 42d23327 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Make taskServices work with ServiceDeployment

Also removes the RoutingKey / Exchange hack.
parent b0d75e75
......@@ -240,10 +240,6 @@ func (c *config) consume(deliveries <-chan amqp.Delivery) {
false, // signal the server to requeue the message
)
} else {
// extend the task with additional information
newTask.Exchange = d.Exchange
newTask.RoutingKey = d.RoutingKey
// enqueue the task
newTask.Log("RECEIVED via %v-%v", d.Exchange, d.RoutingKey)
c.scheduleTask(newTask)
......
......@@ -36,15 +36,14 @@ type (
Credentials map[string][]s.Credential `json:"credentials"`
Questionnaire map[string]string `json:"questionnaire"`
// this relates to the polymorphic type added by the polymorphic serializer
ResourceType string `json:"resourcetype"`
// VO is only set if this is a VODeployment
VO vo `json:"vo,omitempty"`
// Service may be filled by scheduleTask
Service service `json:"service,omitempty"`
// Exchange and RoutingKey are inserted when we receive the task via RabbitMQ
Exchange string
RoutingKey string
}
// taskReply is sent back to the backend to inform it about executed deployment actions
......@@ -83,49 +82,58 @@ func (te taskReply) Log(formatString string, params ...interface{}) {
log.Printf("%s "+formatString, append([]interface{}{te}, params...)...)
}
// taskServices finds the services which need to be deployed for the given task
func (c *config) taskServices(t task) (services []service, err error) {
// hacky: we need to determine exchange and routing key when we fetched manually from the rest
// interface
if t.Exchange == "" || t.RoutingKey == "" {
// Option 1: VODeployment
if t.ResourceType == "VODeployment" && t.VO != (vo{}) {
if t.VO.ResourceType == "Group" {
t.Exchange = "groups"
t.RoutingKey = t.VO.Name
var ok bool
services, ok = c.GroupToServices[t.VO.Name]
if !ok {
err = fmt.Errorf(
"%s: Group %s has no mapped services",
t,
t.VO.Name,
)
return
}
} else if t.VO.ResourceType == "Entitlement" {
t.Exchange = "entitlements"
t.RoutingKey = t.VO.Name
var ok bool
services, ok = c.EntitlementToServices[t.VO.Name]
if !ok {
err = fmt.Errorf(
"%s: Entitlement %s has no mapped services",
t,
t.VO.Name,
)
return
}
}
}
switch t.Exchange {
case "groups":
var ok bool
services, ok = c.GroupToServices[t.RoutingKey]
if !ok {
err = fmt.Errorf(
"%s: Group %s has no mapped services",
t,
t.RoutingKey,
)
return
} else if t.ResourceType == "ServiceDeployment" && t.Service != (service{}) {
// we should hopefully only find one matching service
// See Issue #3
for _, groupServices := range c.GroupToServices {
for _, service := range groupServices {
if service.Name == t.Service.Name {
services = append(services, service)
}
}
}
case "entitlements":
var ok bool
services, ok = c.EntitlementToServices[t.RoutingKey]
if !ok {
err = fmt.Errorf(
"%s: Entitlement %s has no mapped services",
t,
t.RoutingKey,
)
return
for _, entitlementServices := range c.EntitlementToServices {
for _, service := range entitlementServices {
if service.Name == t.Service.Name {
services = append(services, service)
}
}
}
case "sites":
// TODO implement
} else {
err = fmt.Errorf("Task is neither a VODeployment or a ServiceDeployment")
return
}
if len(services) == 0 {
t.Log("Unable to determine services for this task")
err = fmt.Errorf("Task has no services")
}
return
}
......@@ -279,7 +287,7 @@ func (c *config) scheduleTask(t task) (err error) {
serviceTask.Log("Scheduling execution for %s", svc.Name)
// put the in the task queue
// put them in the task queue
c.NewTasks <- serviceTask
}
return
......
Markdown is supported
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