Search in sources :

Example 1 with StorableId

use of org.eclipse.kapua.service.datastore.model.StorableId in project kapua by eclipse.

the class MetricInfoStoreServiceImpl method find.

@Override
public MetricInfo find(KapuaId scopeId, StorableId id) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(id, "id");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.read);
    MetricInfoQueryImpl q = new MetricInfoQueryImpl();
    q.setLimit(1);
    ArrayList<StorableId> ids = new ArrayList<StorableId>();
    ids.add(id);
    AndPredicateImpl allPredicates = new AndPredicateImpl();
    allPredicates.addPredicate(new IdsPredicateImpl(EsMessageField.ID, ids));
    MetricInfoListResult result = this.query(scopeId, q);
    if (result == null || result.size() == 0)
        return null;
    MetricInfo topicInfo = result.get(0);
    return topicInfo;
}
Also used : StorableId(org.eclipse.kapua.service.datastore.model.StorableId) IdsPredicateImpl(org.eclipse.kapua.service.datastore.internal.model.query.IdsPredicateImpl) AndPredicateImpl(org.eclipse.kapua.service.datastore.internal.model.query.AndPredicateImpl) MetricInfoListResult(org.eclipse.kapua.service.datastore.model.MetricInfoListResult) MetricInfo(org.eclipse.kapua.service.datastore.model.MetricInfo) MetricInfoQueryImpl(org.eclipse.kapua.service.datastore.internal.model.query.MetricInfoQueryImpl) ArrayList(java.util.ArrayList)

Example 2 with StorableId

use of org.eclipse.kapua.service.datastore.model.StorableId in project kapua by eclipse.

the class EsDocumentBuilder method build.

// TODO move to a dedicated EsTopicBuilder Class
public EsDocumentBuilder build(String scopeName, TopicInfo topicInfo) throws IOException, KapuaInvalidTopicException {
    String topicName = topicInfo.getFullTopicName();
    KapuaTopic topic = new KapuaTopic(topicName);
    String semTopic = topic.getSemanticTopic();
    StorableId msgId = topicInfo.getLastMessageId();
    Date msgTimestamp = topicInfo.getLastMessageTimestamp();
    String asset = topic.getAsset();
    XContentBuilder topicBuilder = this.getTopicBuilder(semTopic, msgId.toString(), msgTimestamp, asset, scopeName);
    this.setTopicId(this.getTopicKey(topicName));
    this.setTopicBuilder(topicBuilder);
    return this;
}
Also used : StorableId(org.eclipse.kapua.service.datastore.model.StorableId) Date(java.util.Date) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 3 with StorableId

use of org.eclipse.kapua.service.datastore.model.StorableId in project kapua by eclipse.

the class PredicateConverter method toElasticsearchQuery.

public QueryBuilder toElasticsearchQuery(IdsPredicate predicate) throws KapuaException {
    if (predicate == null)
        throw KapuaException.internalError(String.format("Predicate parameter is undefined"));
    Set<StorableId> ids = predicate.getIdSet();
    Set<String> stringIds = new HashSet<String>(ids.size());
    for (StorableId id : ids) stringIds.add(id.toString());
    QueryBuilder idsQuery = QueryBuilders.idsQuery(stringIds.toArray(new String[] {}));
    return idsQuery;
}
Also used : StorableId(org.eclipse.kapua.service.datastore.model.StorableId) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) HashSet(java.util.HashSet)

Example 4 with StorableId

use of org.eclipse.kapua.service.datastore.model.StorableId in project kapua by eclipse.

the class AssetInfoStoreServiceImpl method find.

@Override
public AssetInfo find(KapuaId scopeId, StorableId id) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(id, "id");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.read);
    AssetInfoQueryImpl q = new AssetInfoQueryImpl();
    q.setLimit(1);
    ArrayList<StorableId> ids = new ArrayList<StorableId>();
    ids.add(id);
    AndPredicateImpl allPredicates = new AndPredicateImpl();
    allPredicates.addPredicate(new IdsPredicateImpl(EsMessageField.ID, ids));
    AssetInfoListResult result = this.query(scopeId, q);
    if (result == null || result.size() == 0)
        return null;
    AssetInfo assetInfo = result.get(0);
    return assetInfo;
}
Also used : StorableId(org.eclipse.kapua.service.datastore.model.StorableId) IdsPredicateImpl(org.eclipse.kapua.service.datastore.internal.model.query.IdsPredicateImpl) AndPredicateImpl(org.eclipse.kapua.service.datastore.internal.model.query.AndPredicateImpl) AssetInfoListResult(org.eclipse.kapua.service.datastore.model.AssetInfoListResult) ArrayList(java.util.ArrayList) AssetInfoQueryImpl(org.eclipse.kapua.service.datastore.internal.model.query.AssetInfoQueryImpl) AssetInfo(org.eclipse.kapua.service.datastore.model.AssetInfo)

Example 5 with StorableId

use of org.eclipse.kapua.service.datastore.model.StorableId in project kapua by eclipse.

the class MessageStoreServiceImpl method storeMessage.

private StorableId storeMessage(String accountName, Message message, int maxTopicDepth, long indexedOn, long receivedOn, long ttl, MetricsIndexBy indexBy) throws IOException, ParseException, EsDatastoreException, KapuaInvalidTopicException {
    // Extract schema metadata
    EsSchema.Metadata schemaMetadata = this.esSchema.synch(accountName, indexedOn);
    Date indexedOnDt = new Date(indexedOn);
    Date receivedOnDt = new Date(receivedOn);
    StorableId messageId;
    if (message.getId() != null)
        messageId = message.getId();
    else {
        UUID uuid = UUID.randomUUID();
        messageId = new StorableIdImpl(uuid.toString());
    }
    // Parse document
    EsDocumentBuilder docBuilder = new EsDocumentBuilder();
    docBuilder.build(accountName, messageId, message, indexedOnDt, receivedOnDt);
    Map<String, EsMetric> esMetrics = docBuilder.getMessageMetrics();
    this.esSchema.updateMessageMappings(accountName, indexedOn, esMetrics);
    // TODO Investigate why update indivudual performs better than update bulk (!!!)
    this.updateIndividually(schemaMetadata, docBuilder);
    return messageId;
}
Also used : StorableId(org.eclipse.kapua.service.datastore.model.StorableId) EsDocumentBuilder(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDocumentBuilder) EsMetric(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsMetric) EsSchema(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsSchema) UUID(java.util.UUID) Date(java.util.Date) StorableIdImpl(org.eclipse.kapua.service.datastore.internal.model.StorableIdImpl)

Aggregations

StorableId (org.eclipse.kapua.service.datastore.model.StorableId)8 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 AndPredicateImpl (org.eclipse.kapua.service.datastore.internal.model.query.AndPredicateImpl)3 IdsPredicateImpl (org.eclipse.kapua.service.datastore.internal.model.query.IdsPredicateImpl)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 EsDocumentBuilder (org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDocumentBuilder)1 EsMetric (org.eclipse.kapua.service.datastore.internal.elasticsearch.EsMetric)1 EsSchema (org.eclipse.kapua.service.datastore.internal.elasticsearch.EsSchema)1 StorableIdImpl (org.eclipse.kapua.service.datastore.internal.model.StorableIdImpl)1 AssetInfoQueryImpl (org.eclipse.kapua.service.datastore.internal.model.query.AssetInfoQueryImpl)1 MetricInfoQueryImpl (org.eclipse.kapua.service.datastore.internal.model.query.MetricInfoQueryImpl)1 TopicInfoQueryImpl (org.eclipse.kapua.service.datastore.internal.model.query.TopicInfoQueryImpl)1 AssetInfo (org.eclipse.kapua.service.datastore.model.AssetInfo)1 AssetInfoListResult (org.eclipse.kapua.service.datastore.model.AssetInfoListResult)1 MetricInfo (org.eclipse.kapua.service.datastore.model.MetricInfo)1 MetricInfoListResult (org.eclipse.kapua.service.datastore.model.MetricInfoListResult)1 TopicInfo (org.eclipse.kapua.service.datastore.model.TopicInfo)1