Search in sources :

Example 6 with AssetRuleset

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;
}
Also used : AssetRuleset(org.openremote.model.rules.AssetRuleset) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TenantRuleset(org.openremote.model.rules.TenantRuleset)

Example 7 with AssetRuleset

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);
}
Also used : AssetRuleset(org.openremote.model.rules.AssetRuleset) WebApplicationException(javax.ws.rs.WebApplicationException) Asset(org.openremote.model.asset.Asset)

Aggregations

AssetRuleset (org.openremote.model.rules.AssetRuleset)7 WebApplicationException (javax.ws.rs.WebApplicationException)4 Asset (org.openremote.model.asset.Asset)4 TenantRuleset (org.openremote.model.rules.TenantRuleset)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InputStream (java.io.InputStream)1 GlobalRuleset (org.openremote.model.rules.GlobalRuleset)1 Ruleset (org.openremote.model.rules.Ruleset)1