Commit 8a30b99d1866aed83b242c4cc26cebb7a6819846
Merge branch 'master' of github.com:thingsboard/thingsboard
Showing
3 changed files
with
19 additions
and
4 deletions
application/src/main/java/org/thingsboard/server/service/apiusage/DefaultTbApiUsageStateService.java
@@ -147,6 +147,11 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { | @@ -147,6 +147,11 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { | ||
147 | public void process(TbProtoQueueMsg<ToUsageStatsServiceMsg> msg, TbCallback callback) { | 147 | public void process(TbProtoQueueMsg<ToUsageStatsServiceMsg> msg, TbCallback callback) { |
148 | ToUsageStatsServiceMsg statsMsg = msg.getValue(); | 148 | ToUsageStatsServiceMsg statsMsg = msg.getValue(); |
149 | TenantId tenantId = new TenantId(new UUID(statsMsg.getTenantIdMSB(), statsMsg.getTenantIdLSB())); | 149 | TenantId tenantId = new TenantId(new UUID(statsMsg.getTenantIdMSB(), statsMsg.getTenantIdLSB())); |
150 | + | ||
151 | + if (tenantProfileCache.get(tenantId) == null) { | ||
152 | + return; | ||
153 | + } | ||
154 | + | ||
150 | TenantApiUsageState tenantState; | 155 | TenantApiUsageState tenantState; |
151 | List<TsKvEntry> updatedEntries; | 156 | List<TsKvEntry> updatedEntries; |
152 | Map<ApiFeature, ApiUsageStateValue> result; | 157 | Map<ApiFeature, ApiUsageStateValue> result; |
@@ -343,7 +348,15 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { | @@ -343,7 +348,15 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { | ||
343 | long now = System.currentTimeMillis(); | 348 | long now = System.currentTimeMillis(); |
344 | myTenantStates.values().forEach(state -> { | 349 | myTenantStates.values().forEach(state -> { |
345 | if ((state.getNextCycleTs() > now) && (state.getNextCycleTs() - now < TimeUnit.HOURS.toMillis(1))) { | 350 | if ((state.getNextCycleTs() > now) && (state.getNextCycleTs() - now < TimeUnit.HOURS.toMillis(1))) { |
351 | + TenantId tenantId = state.getTenantId(); | ||
346 | state.setCycles(state.getNextCycleTs(), SchedulerUtils.getStartOfNextNextMonth()); | 352 | state.setCycles(state.getNextCycleTs(), SchedulerUtils.getStartOfNextNextMonth()); |
353 | + ToUsageStatsServiceMsg.Builder msg = ToUsageStatsServiceMsg.newBuilder(); | ||
354 | + msg.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); | ||
355 | + msg.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); | ||
356 | + for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) { | ||
357 | + msg.addValues(UsageStatsKVProto.newBuilder().setKey(key.name()).setValue(0).build()); | ||
358 | + } | ||
359 | + process(new TbProtoQueueMsg<>(UUID.randomUUID(), msg.build()), TbCallback.EMPTY); | ||
347 | } | 360 | } |
348 | }); | 361 | }); |
349 | } finally { | 362 | } finally { |
@@ -297,7 +297,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -297,7 +297,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
297 | try { | 297 | try { |
298 | handleUsageStats(msg, callback); | 298 | handleUsageStats(msg, callback); |
299 | } catch (Throwable e) { | 299 | } catch (Throwable e) { |
300 | - log.warn("[{}] Failed to process usge stats: {}", id, msg, e); | 300 | + log.warn("[{}] Failed to process usage stats: {}", id, msg, e); |
301 | callback.onFailure(e); | 301 | callback.onFailure(e); |
302 | } | 302 | } |
303 | }); | 303 | }); |
@@ -195,9 +195,11 @@ public class HashPartitionService implements PartitionService { | @@ -195,9 +195,11 @@ public class HashPartitionService implements PartitionService { | ||
195 | if (current.getServiceTypesList().contains(serviceType.name())) { | 195 | if (current.getServiceTypesList().contains(serviceType.name())) { |
196 | result.add(current.getServiceId()); | 196 | result.add(current.getServiceId()); |
197 | } | 197 | } |
198 | - for (ServiceInfo serviceInfo : currentOtherServices) { | ||
199 | - if (serviceInfo.getServiceTypesList().contains(serviceType.name())) { | ||
200 | - result.add(serviceInfo.getServiceId()); | 198 | + if (currentOtherServices != null) { |
199 | + for (ServiceInfo serviceInfo : currentOtherServices) { | ||
200 | + if (serviceInfo.getServiceTypesList().contains(serviceType.name())) { | ||
201 | + result.add(serviceInfo.getServiceId()); | ||
202 | + } | ||
201 | } | 203 | } |
202 | } | 204 | } |
203 | return result; | 205 | return result; |