Beispiel #1
0
func (bwh *BOSSWaveHandler) listenQueries(msg *bw.SimpleMessage) {
	var (
		// the publisher of the message. We incorporate this into the signal URI
		fromVK string
		// the computed signal based on the VK and query nonce
		signalURI string
		// query message
		query KeyValueQuery
	)
	fromVK = msg.From
	po := msg.GetOnePODF(GilesKeyValueQueryPIDString)
	if po == nil { // no query found
		return
	}

	if obj, ok := po.(bw.MsgPackPayloadObject); !ok {
		log.Error("Received query was not msgpack")
	} else if err := obj.ValueInto(&query); err != nil {
		log.Error(errors.Wrap(err, "Could not unmarshal received query"))
		return
	}

	signalURI = fmt.Sprintf("%s,queries", fromVK[:len(fromVK)-1])

	log.Infof("Got query %+v", query)
	res, err := bwh.a.HandleQuery(query.Query)
	if err != nil {
		msg := QueryError{
			Query: query.Query,
			Nonce: query.Nonce,
			Error: err.Error(),
		}
		po, _ := bw.CreateMsgPackPayloadObject(GilesQueryErrorPID, msg)
		log.Error(errors.Wrap(err, "Error evaluating query"))
		if err := bwh.iface.PublishSignal(signalURI, po); err != nil {
			log.Error(errors.Wrap(err, "Error sending response"))
		}
	}

	var reply []bw.PayloadObject

	switch t := res.(type) {
	case common.SmapMessageList:
		log.Debug("smap messages list")
		pos := POsFromSmapMessageList(query.Nonce, t)
		reply = append(reply, pos...)
	case common.DistinctResult:
		log.Debug("distinct list")
		reply = append(reply, POFromDistinctResult(query.Nonce, t))
	default:
		log.Debug("type %T", res)
	}
	log.Debugf("Reply on %s: %d", bwh.iface.SignalURI(signalURI), len(reply))

	if err := bwh.iface.PublishSignal(signalURI, reply...); err != nil {
		log.Error(errors.Wrap(err, "Error sending response"))
	}
}
Beispiel #2
0
func (msg QueryTimeseriesResult) ToMsgPackBW() (po bw.PayloadObject) {
	po, _ = bw.CreateMsgPackPayloadObject(GilesQueryTimeseriesResultPID, msg)
	return
}
Beispiel #3
0
func (msg KeyValueQuery) ToMsgPackBW() (po bw.PayloadObject) {
	po, _ = bw.CreateMsgPackPayloadObject(GilesKeyValueQueryPID, msg)
	return
}
Beispiel #4
0
func (msg QueryError) ToMsgPackBW() (po bw.PayloadObject) {
	po, _ = bw.CreateMsgPackPayloadObject(GilesQueryErrorPID, msg)
	return
}
Beispiel #5
0
func (msg Statistics) ToMsgPackBW() (po bw.PayloadObject) {
	po, _ = bw.CreateMsgPackPayloadObject(GilesTimeseriesPID, msg)
	return
}