use of org.openremote.model.rules.AssetRuleset in project openremote by openremote.
the class RulesHealthStatusProvider method getHealthStatus.
@Override
public Object getHealthStatus() {
int totalEngines = rulesService.tenantEngines.size() + rulesService.assetEngines.size();
int stoppedEngines = 0;
int errorEngines = 0;
if (rulesService.globalEngine != null) {
totalEngines++;
if (!rulesService.globalEngine.isRunning()) {
stoppedEngines++;
}
if (rulesService.globalEngine.isError()) {
errorEngines++;
}
}
ObjectNode tenantEngines = ValueUtil.createJsonObject();
for (RulesEngine<TenantRuleset> tenantEngine : rulesService.tenantEngines.values()) {
if (!tenantEngine.isRunning()) {
stoppedEngines++;
}
if (tenantEngine.isError()) {
errorEngines++;
}
tenantEngines.set(tenantEngine.getId().getRealm().orElse(""), getEngineHealthStatus(tenantEngine));
}
ObjectNode assetEngines = ValueUtil.createJsonObject();
for (RulesEngine<AssetRuleset> assetEngine : rulesService.assetEngines.values()) {
if (!assetEngine.isRunning()) {
stoppedEngines++;
}
if (assetEngine.isError()) {
errorEngines++;
}
assetEngines.set(assetEngine.getId().getAssetId().orElse(""), getEngineHealthStatus(assetEngine));
}
ObjectNode objectValue = ValueUtil.createJsonObject();
objectValue.put("totalEngines", totalEngines);
objectValue.put("stoppedEngines", stoppedEngines);
objectValue.put("errorEngines", errorEngines);
if (rulesService.globalEngine != null) {
objectValue.set("global", getEngineHealthStatus(rulesService.globalEngine));
}
objectValue.set("tenant", tenantEngines);
objectValue.set("asset", assetEngines);
return objectValue;
}
use of org.openremote.model.rules.AssetRuleset in project openremote by openremote.
the class RulesetResourceImpl method updateAssetRuleset.
@Override
public void updateAssetRuleset(@BeanParam RequestParams requestParams, Long id, AssetRuleset ruleset) {
AssetRuleset existingRuleset = rulesetStorageService.findById(AssetRuleset.class, id);
if (existingRuleset == null) {
throw new WebApplicationException(NOT_FOUND);
}
Asset asset = assetStorageService.find(existingRuleset.getAssetId(), false);
if (asset == null) {
throw new WebApplicationException(NOT_FOUND);
}
if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), asset.getId())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (!id.equals(ruleset.getId())) {
throw new WebApplicationException("Requested ID and ruleset ID don't match", BAD_REQUEST);
}
if (!existingRuleset.getAssetId().equals(ruleset.getAssetId())) {
throw new WebApplicationException("Can't update asset ID, delete and create the ruleset to reassign", BAD_REQUEST);
}
rulesetStorageService.merge(ruleset);
}
Aggregations