|
@@ -243,6 +243,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
|
@@ -243,6 +243,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
243
|
|
243
|
|
244
|
private void updateTenantState(TenantApiUsageState state, TenantProfile tenantProfile) {
|
244
|
private void updateTenantState(TenantApiUsageState state, TenantProfile tenantProfile) {
|
245
|
TenantProfileData oldProfileData = state.getTenantProfileData();
|
245
|
TenantProfileData oldProfileData = state.getTenantProfileData();
|
|
|
246
|
+ state.setTenantProfileId(tenantProfile.getId());
|
246
|
state.setTenantProfileData(tenantProfile.getProfileData());
|
247
|
state.setTenantProfileData(tenantProfile.getProfileData());
|
247
|
Map<ApiFeature, Boolean> result = state.checkStateUpdatedDueToThresholds();
|
248
|
Map<ApiFeature, Boolean> result = state.checkStateUpdatedDueToThresholds();
|
248
|
if (!result.isEmpty()) {
|
249
|
if (!result.isEmpty()) {
|
|
@@ -257,8 +258,10 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
|
@@ -257,8 +258,10 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
257
|
long ts = System.currentTimeMillis();
|
258
|
long ts = System.currentTimeMillis();
|
258
|
List<TsKvEntry> profileThresholds = new ArrayList<>();
|
259
|
List<TsKvEntry> profileThresholds = new ArrayList<>();
|
259
|
for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) {
|
260
|
for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) {
|
260
|
- if (oldData == null || oldData.getProfileThreshold(key) != newData.getProfileThreshold(key)) {
|
|
|
261
|
- profileThresholds.add(new BasicTsKvEntry(ts, new LongDataEntry(key.getApiLimitKey(), newData.getProfileThreshold(key))));
|
261
|
+ long newProfileThreshold = newData.getProfileThreshold(key);
|
|
|
262
|
+ if (oldData == null || oldData.getProfileThreshold(key) != newProfileThreshold) {
|
|
|
263
|
+ log.info("[{}] Updating profile threshold [{}]:[{}]", tenantId, key, newProfileThreshold);
|
|
|
264
|
+ profileThresholds.add(new BasicTsKvEntry(ts, new LongDataEntry(key.getApiLimitKey(), newProfileThreshold)));
|
262
|
}
|
265
|
}
|
263
|
}
|
266
|
}
|
264
|
if (!profileThresholds.isEmpty()) {
|
267
|
if (!profileThresholds.isEmpty()) {
|
|
@@ -267,6 +270,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
|
@@ -267,6 +270,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
267
|
}
|
270
|
}
|
268
|
|
271
|
|
269
|
private void persistAndNotify(TenantApiUsageState state, Map<ApiFeature, Boolean> result) {
|
272
|
private void persistAndNotify(TenantApiUsageState state, Map<ApiFeature, Boolean> result) {
|
|
|
273
|
+ log.info("[{}] Detected update of the API state: {}", state.getTenantId(), result);
|
270
|
apiUsageStateService.update(state.getApiUsageState());
|
274
|
apiUsageStateService.update(state.getApiUsageState());
|
271
|
clusterService.onApiStateChange(state.getApiUsageState(), null);
|
275
|
clusterService.onApiStateChange(state.getApiUsageState(), null);
|
272
|
long ts = System.currentTimeMillis();
|
276
|
long ts = System.currentTimeMillis();
|
|
@@ -320,6 +324,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
|
@@ -320,6 +324,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService { |
320
|
}
|
324
|
}
|
321
|
}
|
325
|
}
|
322
|
}
|
326
|
}
|
|
|
327
|
+ log.debug("[{}] Initialized state: {}", tenantId, dbStateEntity);
|
323
|
myTenantStates.put(tenantId, tenantState);
|
328
|
myTenantStates.put(tenantId, tenantState);
|
324
|
} catch (InterruptedException | ExecutionException e) {
|
329
|
} catch (InterruptedException | ExecutionException e) {
|
325
|
log.warn("[{}] Failed to fetch api usage state from db.", tenantId, e);
|
330
|
log.warn("[{}] Failed to fetch api usage state from db.", tenantId, e);
|