Exemplo n.º 1
0
func GetRecords(msg *bw.SimpleMessage) []*MetadataRecord {
	parts := strings.Split(msg.URI, "/")
	uri := strings.Join(parts[:len(parts)-2], "/") + "/*"
	var records []*MetadataRecord

	for _ = range msg.POs {
		rec := &MetadataRecord{
			Key:       parts[len(parts)-1],
			Namespace: parts[0],
			URI:       uri,
			VK:        msg.From,
			Time:      time.Now().UnixNano(),
			Msg:       msg,
		}
		meta, ok := msg.GetOnePODF(bw.PODFSMetadata).(bw.MetadataPayloadObject)
		if ok {
			val := meta.Value()
			if val != nil {
				rec.Value = []byte(val.Value)
			} else {
				rec.Value = meta.GetContents()
			}
		} else {
			rec.Value = msg.POs[0].GetContents()
		}
		records = append(records, rec)
	}
	return records
}
Exemplo n.º 2
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"))
	}
}
Exemplo n.º 3
0
func (f *forwarder) send(msg *bw.SimpleMessage) {
	f.RLock()
	for view := range f.forwardList {
		select {
		case view.C <- msg:
		default:
			log.Warningf("Dropping msg")
			msg.Dump()
		}
	}
	f.RUnlock()
}
Exemplo n.º 4
0
func GetDistinctList(nonce uint32, msg *bw.SimpleMessage) (bool, messages.QueryListResult, error) {
	var (
		po         bw.PayloadObject
		listResult messages.QueryListResult
	)
	if po = msg.GetOnePODF(messages.GilesQueryListResultPIDString); po != nil {
		if err := po.(bw.MsgPackPayloadObject).ValueInto(&listResult); err != nil {
			return false, listResult, err
		}
		if listResult.Nonce != nonce {
			return false, listResult, nil
		}
		return true, listResult, nil
	}
	return false, listResult, nil
}
Exemplo n.º 5
0
// Extracts Timeseries from Giles response. Returns false if no related message was found
func GetTimeseries(nonce uint32, msg *bw.SimpleMessage) (bool, messages.QueryTimeseriesResult, error) {
	var (
		po                bw.PayloadObject
		timeseriesResults messages.QueryTimeseriesResult
	)
	if po = msg.GetOnePODF(messages.GilesQueryTimeseriesResultPIDString); po != nil {
		if err := po.(bw.MsgPackPayloadObject).ValueInto(&timeseriesResults); err != nil {
			return false, timeseriesResults, err
		}
		if timeseriesResults.Nonce != nonce {
			return false, timeseriesResults, nil
		}
		return true, timeseriesResults, nil
	}
	return false, timeseriesResults, nil
}
Exemplo n.º 6
0
// Extracts QueryError from Giles response. Returns false if no related message was found
func GetError(nonce uint32, msg *bw.SimpleMessage) (bool, error) {
	var (
		po         bw.PayloadObject
		queryError messages.QueryError
	)
	if po = msg.GetOnePODF(messages.GilesQueryErrorPIDString); po != nil {
		if err := po.(bw.MsgPackPayloadObject).ValueInto(&queryError); err != nil {
			return false, err
		}
		if queryError.Nonce != nonce {
			return false, nil
		}
		return true, nil
	}
	return false, nil
}
Exemplo n.º 7
0
func (bwh *BOSSWaveHandler) listenCQBS(msg *bw.SimpleMessage) {
	var (
		// the publisher of the message. We incorporate this into the signal URI
		fromVK 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"))
	}

	subscription := bwh.StartSubscriber(fromVK, query)
	go bwh.a.HandleNewSubscriber(subscription, query.Query)
}