示例#1
0
文件: compare.go 项目: jbayer/spiff
func listToMap(list []yaml.Node) map[string]yaml.Node {
	toMap := make(map[string]yaml.Node)

	for _, val := range list {
		name, ok := yaml.FindString(val, "name")
		if !ok {
			return nil
		}

		asMap, ok := val.(map[string]yaml.Node)
		if !ok {
			return nil
		}

		newMap := make(map[string]yaml.Node)
		for key, val := range asMap {
			if key != "name" {
				newMap[key] = val
			}
		}

		toMap[name] = newMap
	}

	return toMap
}
示例#2
0
文件: flow.go 项目: jbayer/spiff
func stepName(index int, value yaml.Node) string {
	name, ok := yaml.FindString(value, "name")
	if ok {
		return name
	}

	return fmt.Sprintf("[%d]", index)
}
示例#3
0
文件: compare.go 项目: jbayer/spiff
func findByNameOrIndex(node yaml.Node, others []yaml.Node, index int) (string, yaml.Node, bool) {
	name, ok := yaml.FindString(node, "name")
	if !ok {
		return findByIndex(others, index)
	}

	key, node, found := findByName(name, others)
	if !found {
		return findByIndex(others, index)
	}

	return key, node, true
}
示例#4
0
文件: compare.go 项目: jbayer/spiff
func findByName(name string, nodes []yaml.Node) (string, yaml.Node, bool) {
	for _, node := range nodes {
		otherName, ok := yaml.FindString(node, "name")
		if !ok {
			continue
		}

		if otherName == name {
			return name, node, true
		}
	}

	return "", nil, false
}
示例#5
0
文件: compare.go 项目: jbayer/spiff
func jobMap(jobs []yaml.Node) map[string]yaml.Node {
	byName := make(map[string]yaml.Node)

	for index, job := range jobs {
		attrs, ok := job.(map[string]yaml.Node)
		attrs["index"] = index

		name, ok := yaml.FindString(job, "name")
		if !ok {
			panic("job without string name")
		}

		byName[name] = attrs
	}

	return byName
}
示例#6
0
文件: auto.go 项目: jbayer/spiff
func (e AutoExpr) Evaluate(binding Binding) (yaml.Node, bool) {
	if len(e.Path) == 3 && e.Path[0] == "resource_pools" && e.Path[2] == "size" {
		jobs, found := binding.FindFromRoot([]string{"jobs"})
		if !found {
			return nil, false
		}

		jobsList, ok := jobs.([]yaml.Node)
		if !ok {
			return nil, false
		}

		size := 0

		for _, job := range jobsList {
			poolName, ok := yaml.FindString(job, "resource_pool")
			if !ok {
				continue
			}

			if poolName != e.Path[1] {
				continue
			}

			instances, ok := yaml.FindInt(job, "instances")
			if !ok {
				return nil, false
			}

			size += instances
		}

		return size, true
	}

	return nil, false
}