Search in sources :

Example 6 with KapuaException

use of org.eclipse.kapua.KapuaException 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 7 with KapuaException

use of org.eclipse.kapua.KapuaException 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 8 with KapuaException

use of org.eclipse.kapua.KapuaException 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)

Example 9 with KapuaException

use of org.eclipse.kapua.KapuaException in project kapua by eclipse.

the class MetricInfoStoreServiceImpl method count.

@Override
public long count(KapuaId scopeId, MetricInfoQuery 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 = EsMetricDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.METRIC_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) KapuaException(org.eclipse.kapua.KapuaException)

Example 10 with KapuaException

use of org.eclipse.kapua.KapuaException in project kapua by eclipse.

the class MetricInfoStoreServiceImpl method delete.

@Override
public void delete(KapuaId scopeId, MetricInfoQuery 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);
    }
    try {
        String everyIndex = EsUtils.getAnyIndexName(scopeName);
        EsMetricDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.METRIC_TYPE_NAME).deleteByQuery(query);
        return;
    } 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)

Aggregations

KapuaException (org.eclipse.kapua.KapuaException)99 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)53 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)50 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)50 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)48 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)48 KapuaIllegalArgumentException (org.eclipse.kapua.KapuaIllegalArgumentException)19 LocalServicePlan (org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan)17 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)12 Date (java.util.Date)11 KapuaIllegalAccessException (org.eclipse.kapua.KapuaIllegalAccessException)10 Account (org.eclipse.kapua.service.account.Account)9 DeviceCallExecutor (org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor)8 DeviceManagementException (org.eclipse.kapua.service.device.management.commons.exception.DeviceManagementException)8 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)8 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)8 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)8 IOException (java.io.IOException)7 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)7 UnknownHostException (java.net.UnknownHostException)6