Search in sources :

Example 1 with ClusterSettingScope

use of io.datarouter.clustersetting.ClusterSettingScope in project datarouter by hotpads.

the class ClusterSettingsHandler method parseClusterSettingKeyFromParams.

private ClusterSettingKey parseClusterSettingKeyFromParams() {
    String name = params.required("name").trim();
    // allow unrecognized serverType
    String serverTypePersistentString = params.required("serverType");
    String serverName = params.optional("serverName").orElse("");
    ClusterSettingScope scope = ClusterSettingScope.fromParams(serverTypePersistentString, serverName);
    return new ClusterSettingKey(name, scope, serverTypePersistentString, serverName);
}
Also used : ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) ClusterSettingScope(io.datarouter.clustersetting.ClusterSettingScope) OptionalString(io.datarouter.web.handler.types.optional.OptionalString)

Example 2 with ClusterSettingScope

use of io.datarouter.clustersetting.ClusterSettingScope in project datarouter by hotpads.

the class ClusterSettingService method getValidityForWebappInstance.

private ClusterSettingValidity getValidityForWebappInstance(ClusterSetting databeanSetting, WebappInstance webappInstance) {
    String name = databeanSetting.getName();
    ClusterSettingScope scope = databeanSetting.getScope();
    if (!settingRootFinder.isRecognized(name)) {
        if (clusterSettingRoot.settingsExcludedFromUnknownSettingsAlert.get().stream().anyMatch(setting -> StringTool.containsCaseInsensitive(name, setting))) {
            return ClusterSettingValidity.VALID;
        }
        return ClusterSettingValidity.UNKNOWN;
    }
    CachedSetting<?> memorySetting = settingRootFinder.getSettingByName(name).orElse(null);
    if (memorySetting == null) {
        return ClusterSettingValidity.UNREFERENCED;
    }
    if (scope == ClusterSettingScope.SERVER_TYPE) {
        String serverType = databeanSetting.getServerType();
        try {
            serverTypes.fromPersistentString(serverType);
        } catch (RuntimeException e) {
            return ClusterSettingValidity.INVALID_SERVER_TYPE;
        }
    }
    if (scope == ClusterSettingScope.SERVER_NAME) {
        String serverName = databeanSetting.getServerName();
        String serverTypeFromWebappInstanceDao = webappInstanceDao.getServerTypeByServerName().get(serverName);
        if (StringTool.isEmpty(serverTypeFromWebappInstanceDao)) {
            return ClusterSettingValidity.INVALID_SERVER_NAME;
        }
    }
    if (isClusterSettingRedundantForWebappInstance(memorySetting, databeanSetting, webappInstance)) {
        return ClusterSettingValidity.REDUNDANT;
    }
    int oldSettingAlertThresholdDays = clusterSettingRoot.oldSettingAlertThresholdDays.get();
    if (clusterSettingLogDao.isOldDatabaseSetting(databeanSetting, oldSettingAlertThresholdDays)) {
        if (clusterSettingRoot.isExcludedOldSettingString(name)) {
            return ClusterSettingValidity.VALID;
        }
        return ClusterSettingValidity.OLD;
    }
    return ClusterSettingValidity.VALID;
}
Also used : ClusterSettingScope(io.datarouter.clustersetting.ClusterSettingScope)

Aggregations

ClusterSettingScope (io.datarouter.clustersetting.ClusterSettingScope)2 ClusterSettingKey (io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey)1 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)1