func sendDependencyNotice(a *app.App) {
	// notify everyone who depends on us
	for _, cpb := range a.Manifest.Capabilities {
		for _, dependent := range registry.GetDependents(cpb) {
			body := make(jsonData)
			inner := make(jsonData)
			inner[a.Manifest.InstanceId] = a.StatusString()
			body[cpb.Name] = inner
			dependent.Send("APP_DEPENDENCY", body)
		}
	}
}
func sendManifestOkAndDependencies(a *app.App) {
	// send manifest ok
	body := make(map[string]interface{})
	body["instanceId"] = a.Manifest.InstanceId
	a.Send("APP_MANIFEST_OK", body)
	// send dependencies
	body = make(map[string]interface{})
	for _, dep := range a.Manifest.Dependencies {
		inner := make(map[string]string)
		body[dep.Name] = inner
		for _, provider := range registry.GetProviders(dep) {
			inner[provider.Manifest.InstanceId] = provider.StatusString()
		}
	}
	a.Send("APP_DEPENDENCY", body)
}
func getMockApp() *app.App {
	// construct a new app
	a := new(app.App)
	a.Manifest = new(app.Manifest)
	a.Manifest.Name = "name1"
	a.Manifest.InstanceId = "instance1"

	// construct capabilities
	caps := make([]*app.Capability, 2)
	cap1 := new(app.Capability)
	v1, _ := semver.NewVersion("1.1.1")
	v2, _ := semver.NewVersion("1.1.2")
	cap1.Version = *v1
	cap1.Name = "capability1"
	caps[0] = cap1
	cap2 := new(app.Capability)
	cap2.Version = *v2
	cap2.Name = "capability2"
	caps[1] = cap2
	a.Manifest.Capabilities = caps

	// construct dependencies
	deps := make([]*app.Capability, 2)
	dep1 := new(app.Capability)
	dep1.Version = *v1
	dep1.Name = "dependency1"
	deps[0] = dep1
	dep2 := new(app.Capability)
	dep2.Version = *v2
	dep2.Name = "dependency2"
	deps[1] = dep2

	a.Manifest.Dependencies = deps

	return a
}
func sendManifestFail(a *app.App, reason string) {
	body := make(map[string]interface{})
	body["message"] = reason
	a.Send("APP_MANIFEST_FAIL", body)
}
// Changes the status of App a to the given status and priority.
// By design priority is ignored for all statuses other than STATUS_IN_USE.
func ChangeAppStatus(a *app.App, stat int, prio int) {
	a.Status = stat
	a.Priority = prio
	sendDependencyNotice(a)
}