Example #1
0
func (s *Service) prepareNodesAsJsonMap() {
	if s.manifest.Nodes == nil || len(s.manifest.Nodes.([]interface{})) == 0 {
		logs.WithFields(s.fields).Warn("No nodes defined in service")
		return
	}
	tmpRes, err := utils.TransformYamlToJson(s.manifest.Nodes)
	var res []interface{} = tmpRes.([]interface{})
	if err != nil {
		logs.WithEF(err, s.fields).Fatal("Cannot transform yaml to json")
	}

	if res[0].(map[string]interface{})[NODE_HOSTNAME].(string) == "*" {
		if len(res) > 1 {
			logs.WithFields(s.fields).Fatal("You cannot mix all nodes with single node. Yet ?")
		}

		newNodes := *new([]interface{})
		machines, err := s.env.ListMachineNames()
		if err != nil {
			logs.WithEF(err, s.fields).Fatal("Cannot list machines to generate units")
		}
		for _, machine := range machines {
			node := utils.CopyMap(res[0].(map[string]interface{}))
			node[NODE_HOSTNAME] = machine
			newNodes = append(newNodes, node)
		}
		res = newNodes
	}
	s.nodesAsJsonMap = res
}
Example #2
0
func (s *Service) loadAttributes() {
	attr := utils.CopyMap(s.env.GetAttributes())
	files, err := utils.AttributeFiles(s.path + PATH_ATTRIBUTES)
	if err != nil {
		logs.WithEF(err, s.fields).WithField("path", s.path+PATH_ATTRIBUTES).Fatal("Cannot load Attributes files")
	}
	files, err = s.addIncludeFiles(files)
	if err != nil {
		logs.WithEF(err, s.fields).WithField("path", s.path+PATH_ATTRIBUTES).Fatal("Cannot load include files")
	}
	attr = attributes.MergeAttributesFilesForMap(attr, files)
	s.attributes = attr
	logs.WithFields(s.fields).WithField("attributes", s.attributes).Debug("Attributes loaded")
}
Example #3
0
func (u Unit) GenerateAttributes() map[string]interface{} {
	data := utils.CopyMap(u.Service.GetAttributes())
	data = mergemap.Merge(data, u.Service.NodeAttributes(u.hostname))
	return data
}