// construct the app based on its manifest
func (c *commandStrategy) appManifest() bool {
	c.app.RWMutex.Lock()
	defer c.app.RWMutex.Unlock()

	logging.Debug("Parsing application's manifest")

	man, err := decodeManifest(c.body)
	if err != nil {
		logging.Error("App's manifest is invalid: %s", err)
		sendManifestFail(c.app, err.Error())
		return false
	}
	if _, exists := registry.GetInstance(man.InstanceId); exists {
		logging.Error("App's instance id is already taken: %s", man.InstanceId)
		sendManifestFail(c.app, fmt.Sprintf("instanceId %s is in use", man.InstanceId))
		return false
	}
	c.app.Status = app.STATUS_DOWN
	c.app.Manifest = man
	registry.Register(c.app)
	sendManifestOkAndDependencies(c.app)
	logging.Info("App '%s' now connected with manifest parsed", c.app.Manifest.InstanceId)
	return true
}
Exemple #2
0
// send this message query to all targeted apps
func (c *commandStrategy) msgQuery() error {
	c.app.RWMutex.RLock()
	defer c.app.RWMutex.RUnlock()

	logging.Debug("Processing query from %s", c.app.Manifest.InstanceId)
	mq, err := parseMsgQuery(c)
	if err != nil {
		return err
	}

	msg_archive.RecordMsg(c.app, mq.id)
	body := make(jsonData)
	body["fromInstanceId"] = c.app.Manifest.InstanceId
	body["id"] = mq.id
	body["priority"] = mq.priority
	body["data"] = mq.data
	body["instanceId"] = mq.instanceIds
	body["action"] = mq.action
	body["capability"] = mq.capability.Name

	// if this is an undirected query
	if len(mq.instanceIds) == 0 {
		// send to all providers of the capability
		for _, provider := range registry.GetProviders(mq.capability) {
			provider.Send("MSG_QUERY", body)
		}
	} else {
		// this is a directed query, send to all given instance ids
		for _, instName := range mq.instanceIds {
			if inst, ok := registry.GetInstance(instName); ok {
				inst.Send("MSG_QUERY", body)
			}
		}
	}
	return nil
}