Search in sources :

Example 1 with LocalServicePlan

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan in project kapua by eclipse.

the class AssetInfoStoreServiceImpl method query.

@Override
public AssetInfoListResult query(KapuaId scopeId, AssetInfoQuery query) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(query, "query");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.read);
    // 
    // Do the find
    AccountInfo accountInfo = getAccountServicePlan(scopeId);
    String scopeName = accountInfo.getAccount().getName();
    LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
    long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
    if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
        logger.debug("Storage not enabled for account {}, returning empty result", scopeName);
        return new AssetInfoListResultImpl();
    }
    try {
        String everyIndex = EsUtils.getAnyIndexName(scopeName);
        AssetInfoListResult result = null;
        result = EsAssetDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.ASSET_TYPE_NAME).query(query);
        return result;
    } catch (Exception exc) {
        // CassandraUtils.handleException(e);
        throw KapuaException.internalError(exc);
    }
}
Also used : AssetInfoListResult(org.eclipse.kapua.service.datastore.model.AssetInfoListResult) LocalServicePlan(org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan) AssetInfoListResultImpl(org.eclipse.kapua.service.datastore.internal.model.AssetInfoListResultImpl) KapuaException(org.eclipse.kapua.KapuaException)

Example 2 with LocalServicePlan

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan in project kapua by eclipse.

the class AssetInfoStoreServiceImpl method delete.

// 
// @Override
// public StorableId store(KapuaId scopeId, AssetInfoCreator creator)
// throws KapuaException
// {
// // TODO DAOs are ready, need to evaluate if this functionality
// // have to be available or not. Currently entries are added by
// // the message service directy
// throw KapuaException.internalError("Not implemented");
// }
// 
// @Override
// public StorableId update(KapuaId scopeId, AssetInfo assetInfo)
// throws KapuaException
// {
// // TODO DAOs are ready, need to evaluate if this functionality
// // have to be available or not. Currently entries are updated by
// // the message service directy
// throw KapuaException.internalError("Not implemented");
// }
@Override
public void delete(KapuaId scopeId, StorableId id) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(id, "id");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.delete);
    // 
    // Do the find
    AccountInfo accountInfo = getAccountServicePlan(scopeId);
    String scopeName = accountInfo.getAccount().getName();
    LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
    long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
    if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
        logger.debug("Storage not enabled for account {}, return", scopeName);
        return;
    }
    try {
        String everyIndex = EsUtils.getAnyIndexName(scopeName);
        EsAssetDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.ASSET_TYPE_NAME).deleteById(id.toString());
    } catch (Exception exc) {
        // CassandraUtils.handleException(e);
        throw KapuaException.internalError(exc);
    }
}
Also used : LocalServicePlan(org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan) KapuaException(org.eclipse.kapua.KapuaException)

Example 3 with LocalServicePlan

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan in project kapua by eclipse.

the class MessageStoreServiceImpl method count.

public long count(KapuaId scopeId, MessageQuery query) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(query, "query");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.read);
    // 
    // Do the find
    AccountInfo accountInfo = getAccountServicePlan(scopeId);
    String scopeName = accountInfo.getAccount().getName();
    LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
    long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
    if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
        logger.debug("Storage not enabled for account {}, returning empty result", scopeName);
        return 0;
    }
    try {
        String everyIndex = EsUtils.getAnyIndexName(scopeName);
        long result;
        result = EsMessageDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.MESSAGE_TYPE_NAME).count(query);
        return result;
    } catch (Exception exc) {
        // CassandraUtils.handleException(e);
        throw KapuaException.internalError(exc);
    }
}
Also used : LocalServicePlan(org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan) KapuaInvalidTopicException(org.eclipse.kapua.service.datastore.internal.elasticsearch.KapuaInvalidTopicException) ParseException(java.text.ParseException) EsDatastoreException(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException) DocumentAlreadyExistsException(org.elasticsearch.index.engine.DocumentAlreadyExistsException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) KapuaException(org.eclipse.kapua.KapuaException)

Example 4 with LocalServicePlan

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan in project kapua by eclipse.

the class MessageStoreServiceImpl method delete.

@Override
public void delete(KapuaId scopeId, StorableId id) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(id, "id");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.delete);
    // 
    // Do the find
    AccountInfo accountInfo = getAccountServicePlan(scopeId);
    String scopeName = accountInfo.getAccount().getName();
    LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
    long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
    if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
        logger.debug("Storage not enabled for account {}, return", scopeName);
        return;
    }
    try {
        String everyIndex = EsUtils.getAnyIndexName(scopeName);
        EsMessageDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.MESSAGE_TYPE_NAME).deleteById(id.toString());
    } catch (Exception exc) {
        // CassandraUtils.handleException(e);
        throw KapuaException.internalError(exc);
    }
}
Also used : LocalServicePlan(org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan) KapuaInvalidTopicException(org.eclipse.kapua.service.datastore.internal.elasticsearch.KapuaInvalidTopicException) ParseException(java.text.ParseException) EsDatastoreException(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException) DocumentAlreadyExistsException(org.elasticsearch.index.engine.DocumentAlreadyExistsException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) KapuaException(org.eclipse.kapua.KapuaException)

Example 5 with LocalServicePlan

use of org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan in project kapua by eclipse.

the class MessageStoreServiceImpl method query.

@Override
public MessageListResult query(KapuaId scopeId, MessageQuery query) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(query, "query");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.read);
    // 
    // Do the find
    AccountInfo accountInfo = getAccountServicePlan(scopeId);
    String scopeName = accountInfo.getAccount().getName();
    LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
    long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
    if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
        logger.debug("Storage not enabled for account {}, returning empty result", scopeName);
        return new MessageListResultImpl();
    }
    try {
        String everyIndex = EsUtils.getAnyIndexName(scopeName);
        MessageListResult result = null;
        result = EsMessageDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.MESSAGE_TYPE_NAME).query(query);
        return result;
    } catch (Exception exc) {
        // CassandraUtils.handleException(e);
        throw KapuaException.internalError(exc);
    }
}
Also used : MessageListResultImpl(org.eclipse.kapua.service.datastore.internal.model.MessageListResultImpl) LocalServicePlan(org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan) MessageListResult(org.eclipse.kapua.service.datastore.model.MessageListResult) KapuaInvalidTopicException(org.eclipse.kapua.service.datastore.internal.elasticsearch.KapuaInvalidTopicException) ParseException(java.text.ParseException) EsDatastoreException(org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException) DocumentAlreadyExistsException(org.elasticsearch.index.engine.DocumentAlreadyExistsException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

KapuaException (org.eclipse.kapua.KapuaException)17 LocalServicePlan (org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan)17 IOException (java.io.IOException)5 UnknownHostException (java.net.UnknownHostException)5 ParseException (java.text.ParseException)5 EsDatastoreException (org.eclipse.kapua.service.datastore.internal.elasticsearch.EsDatastoreException)5 KapuaInvalidTopicException (org.eclipse.kapua.service.datastore.internal.elasticsearch.KapuaInvalidTopicException)5 DocumentAlreadyExistsException (org.elasticsearch.index.engine.DocumentAlreadyExistsException)5 MessageQueryImpl (org.eclipse.kapua.service.datastore.internal.model.query.MessageQueryImpl)2 MetricInfoQueryImpl (org.eclipse.kapua.service.datastore.internal.model.query.MetricInfoQueryImpl)2 TopicMatchPredicateImpl (org.eclipse.kapua.service.datastore.internal.model.query.TopicMatchPredicateImpl)2 TopicInfo (org.eclipse.kapua.service.datastore.model.TopicInfo)2 TopicInfoListResult (org.eclipse.kapua.service.datastore.model.TopicInfoListResult)2 Date (java.util.Date)1 AssetInfoListResultImpl (org.eclipse.kapua.service.datastore.internal.model.AssetInfoListResultImpl)1 MessageListResultImpl (org.eclipse.kapua.service.datastore.internal.model.MessageListResultImpl)1 MetricInfoListResultImpl (org.eclipse.kapua.service.datastore.internal.model.MetricInfoListResultImpl)1 TopicInfoListResultImpl (org.eclipse.kapua.service.datastore.internal.model.TopicInfoListResultImpl)1 AssetInfoListResult (org.eclipse.kapua.service.datastore.model.AssetInfoListResult)1 MessageListResult (org.eclipse.kapua.service.datastore.model.MessageListResult)1