Search in sources :

Example 1 with DefaultTenantProfileConfiguration

use of org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration in project thingsboard by thingsboard.

the class TbMsgTimeseriesNode method onTenantProfileUpdate.

void onTenantProfileUpdate(TenantProfile tenantProfile) {
    DefaultTenantProfileConfiguration configuration = (DefaultTenantProfileConfiguration) tenantProfile.getProfileData().getConfiguration();
    tenantProfileDefaultStorageTtl = TimeUnit.DAYS.toSeconds(configuration.getDefaultStorageTtlDays());
}
Also used : DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)

Example 2 with DefaultTenantProfileConfiguration

use of org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration in project thingsboard by thingsboard.

the class TenantProfileServiceImpl method findOrCreateDefaultTenantProfile.

@Override
public TenantProfile findOrCreateDefaultTenantProfile(TenantId tenantId) {
    log.trace("Executing findOrCreateDefaultTenantProfile");
    TenantProfile defaultTenantProfile = findDefaultTenantProfile(tenantId);
    if (defaultTenantProfile == null) {
        defaultTenantProfile = new TenantProfile();
        defaultTenantProfile.setDefault(true);
        defaultTenantProfile.setName("Default");
        TenantProfileData profileData = new TenantProfileData();
        profileData.setConfiguration(new DefaultTenantProfileConfiguration());
        defaultTenantProfile.setProfileData(profileData);
        defaultTenantProfile.setDescription("Default tenant profile");
        defaultTenantProfile.setIsolatedTbCore(false);
        defaultTenantProfile.setIsolatedTbRuleEngine(false);
        defaultTenantProfile = saveTenantProfile(tenantId, defaultTenantProfile);
    }
    return defaultTenantProfile;
}
Also used : TenantProfileData(org.thingsboard.server.common.data.tenant.profile.TenantProfileData) TenantProfile(org.thingsboard.server.common.data.TenantProfile) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)

Example 3 with DefaultTenantProfileConfiguration

use of org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration in project thingsboard by thingsboard.

the class TelemetryController method saveTelemetry.

private DeferredResult<ResponseEntity> saveTelemetry(TenantId curTenantId, EntityId entityIdSrc, String requestBody, long ttl) throws ThingsboardException {
    Map<Long, List<KvEntry>> telemetryRequest;
    JsonElement telemetryJson;
    try {
        telemetryJson = new JsonParser().parse(requestBody);
    } catch (Exception e) {
        return getImmediateDeferredResult("Unable to parse timeseries payload: Invalid JSON body!", HttpStatus.BAD_REQUEST);
    }
    try {
        telemetryRequest = JsonConverter.convertToTelemetry(telemetryJson, System.currentTimeMillis());
    } catch (Exception e) {
        return getImmediateDeferredResult("Unable to parse timeseries payload. Invalid JSON body: " + e.getMessage(), HttpStatus.BAD_REQUEST);
    }
    List<TsKvEntry> entries = new ArrayList<>();
    for (Map.Entry<Long, List<KvEntry>> entry : telemetryRequest.entrySet()) {
        for (KvEntry kv : entry.getValue()) {
            entries.add(new BasicTsKvEntry(entry.getKey(), kv));
        }
    }
    if (entries.isEmpty()) {
        return getImmediateDeferredResult("No timeseries data found in request body!", HttpStatus.BAD_REQUEST);
    }
    SecurityUser user = getCurrentUser();
    return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.WRITE_TELEMETRY, entityIdSrc, (result, tenantId, entityId) -> {
        long tenantTtl = ttl;
        if (!TenantId.SYS_TENANT_ID.equals(tenantId) && tenantTtl == 0) {
            TenantProfile tenantProfile = tenantProfileCache.get(tenantId);
            tenantTtl = TimeUnit.DAYS.toSeconds(((DefaultTenantProfileConfiguration) tenantProfile.getProfileData().getConfiguration()).getDefaultStorageTtlDays());
        }
        tsSubService.saveAndNotify(tenantId, user.getCustomerId(), entityId, entries, tenantTtl, new FutureCallback<Void>() {

            @Override
            public void onSuccess(@Nullable Void tmp) {
                logTelemetryUpdated(user, entityId, entries, null);
                result.setResult(new ResponseEntity(HttpStatus.OK));
            }

            @Override
            public void onFailure(Throwable t) {
                logTelemetryUpdated(user, entityId, entries, t);
                AccessValidator.handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR);
            }
        });
    });
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) ArrayList(java.util.ArrayList) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) UncheckedApiException(org.thingsboard.server.service.telemetry.exception.UncheckedApiException) JsonParseException(com.google.gson.JsonParseException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) InvalidParametersException(org.thingsboard.server.service.telemetry.exception.InvalidParametersException) ResponseEntity(org.springframework.http.ResponseEntity) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) List(java.util.List) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) JsonParser(com.google.gson.JsonParser)

Example 4 with DefaultTenantProfileConfiguration

use of org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration in project thingsboard by thingsboard.

the class AssetDataValidator method validateCreate.

@Override
protected void validateCreate(TenantId tenantId, Asset asset) {
    DefaultTenantProfileConfiguration profileConfiguration = (DefaultTenantProfileConfiguration) tenantProfileCache.get(tenantId).getProfileData().getConfiguration();
    if (!BaseAssetService.TB_SERVICE_QUEUE.equals(asset.getType())) {
        long maxAssets = profileConfiguration.getMaxAssets();
        validateNumberOfEntitiesPerTenant(tenantId, assetDao, maxAssets, EntityType.ASSET);
    }
}
Also used : DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)

Example 5 with DefaultTenantProfileConfiguration

use of org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration in project thingsboard by thingsboard.

the class DashboardDataValidator method validateCreate.

@Override
protected void validateCreate(TenantId tenantId, Dashboard data) {
    DefaultTenantProfileConfiguration profileConfiguration = (DefaultTenantProfileConfiguration) tenantProfileCache.get(tenantId).getProfileData().getConfiguration();
    long maxDashboards = profileConfiguration.getMaxDashboards();
    validateNumberOfEntitiesPerTenant(tenantId, dashboardDao, maxDashboards, EntityType.DASHBOARD);
}
Also used : DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)

Aggregations

DefaultTenantProfileConfiguration (org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)22 TenantProfile (org.thingsboard.server.common.data.TenantProfile)8 TenantProfileData (org.thingsboard.server.common.data.tenant.profile.TenantProfileData)7 TenantId (org.thingsboard.server.common.data.id.TenantId)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Test (org.junit.Test)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 PageLink (org.thingsboard.server.common.data.page.PageLink)2 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Arrays (java.util.Arrays)1