Esempio n. 1
0
func (mm *Manifest) makePropertyMap(cfg []byte) error {

	m := make(map[interface{}]interface{})
	if err := yaml.Unmarshal(cfg, &m); err != nil {
		return err
	}

	// parse property definitions
	for name, properties := range m {
		var prop Property
		for key, value := range properties.(map[interface{}]interface{}) {
			if name := key.(string); strings.HasPrefix(name, "type.") {
				prop.ConstructorName = strings.TrimPrefix(name, "type.")
				prop.ConstructorArgs = make(map[string]interface{})
				for _, item := range value.([]interface{}) {
					switch item.(type) {
					case string:
						prop.ConstructorArgs[item.(string)] = true
					case map[interface{}]interface{}:
						for k, v := range item.(map[interface{}]interface{}) {
							prop.ConstructorArgs[k.(string)] = v
						}
					default:
						LOG.Warn("unknown item type of property %v", item)
					}
				}
			}
		}
		mm.Properties[name.(string)] = prop
	}

	return nil
}
Esempio n. 2
0
func (mm *Manifest) makeModelMap(cfg []byte) error {
	m := make(map[interface{}]interface{})
	if err := yaml.Unmarshal(cfg, &m); err != nil {
		return err
	}
	for name, models := range m {
		model := Model{"", "", nil, make(map[string]string)}
		for key, value := range models.(map[interface{}]interface{}) {

			switch key.(string) {
			case "displayname":
				model.DisplayName = value.(string)
			case "identifier":
				model.Identifier = value.(string)
			case "properties":
				for _, prop := range value.([]interface{}) {
					if _, found := mm.Properties[prop.(string)]; !found {
						return fmt.Errorf("property %s not defined", prop.(string))
					}
					model.Properties = append(model.Properties, prop.(string))
				}
			case "references":
				for _, refer := range value.([]interface{}) {
					switch refer.(type) {
					case string:
						model.References[refer.(string)] = refer.(string)
					case map[interface{}]interface{}:
						for k, v := range refer.(map[interface{}]interface{}) {
							model.References[k.(string)] = v.(string)
						}
					default:
						LOG.Warn("unknown item type of references %v", refer)
					}
				}
			default:
			}
		}
		mm.Models[name.(string)] = model
	}

	// check if references all exists
	for _, model := range mm.Models {
		for _, refer := range model.References {
			if _, found := mm.Models[refer]; !found {
				return fmt.Errorf("model %v referred cannot be found", refer)
			}
		}
	}

	return nil
}
Esempio n. 3
0
func NewManifestCollection(root string) (ManifestCollection, error) {
	var err error
	files, err := filepath.Glob(filepath.Join(root, "*"))
	if err != nil {
		return nil, err
	}

	manifests := make(map[string]*Manifest)

	LOG.Debug("collection manifests: %v from %v", files, root)

	for _, file := range files {
		var property, model []byte
		var manifest *Manifest

		propYAML := filepath.Join(file, "properties.yaml")
		modelYAML := filepath.Join(file, "models.yaml")
		name := filepath.Base(file)

		stat, err := os.Stat(file)
		if err != nil || !stat.IsDir() {
			goto ERROR_OUT
		}

		if property, err = ioutil.ReadFile(propYAML); err != nil {
			goto ERROR_OUT
		}

		if model, err = ioutil.ReadFile(modelYAML); err != nil {
			goto ERROR_OUT
		}

		if manifest, err = NewManifest(name, property, model); err != nil {
			goto ERROR_OUT
		}

		manifests[name] = manifest
		continue

	ERROR_OUT:
		LOG.Warn(err)
	}

	return manifests, nil
}