-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1194 from bosch-io/feature/configure-mongo-read-s…
…ettings-for-updater-persistence make readConcern and readPreference to use for MongoThingsSearchUpdaterPersistence configurable
- Loading branch information
Showing
12 changed files
with
327 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../org/eclipse/ditto/thingsearch/service/common/config/DefaultUpdaterPersistenceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.thingsearch.service.common.config; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Objects; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.internal.utils.config.ConfigWithFallback; | ||
import org.eclipse.ditto.internal.utils.config.DittoConfigError; | ||
import org.eclipse.ditto.internal.utils.persistence.mongo.config.MongoDbConfig; | ||
import org.eclipse.ditto.internal.utils.persistence.mongo.config.ReadConcern; | ||
import org.eclipse.ditto.internal.utils.persistence.mongo.config.ReadPreference; | ||
|
||
import com.typesafe.config.Config; | ||
|
||
/** | ||
* This class is the default implementation of {@link UpdaterPersistenceConfig}. | ||
*/ | ||
@Immutable | ||
public final class DefaultUpdaterPersistenceConfig implements UpdaterPersistenceConfig { | ||
|
||
private static final String CONFIG_PATH = "persistence"; | ||
|
||
private final ReadPreference readPreference; | ||
private final ReadConcern readConcern; | ||
|
||
|
||
private DefaultUpdaterPersistenceConfig(final ConfigWithFallback config) { | ||
final var readPreferenceString = | ||
config.getString(MongoDbConfig.OptionsConfig.OptionsConfigValue.READ_PREFERENCE.getConfigPath()); | ||
readPreference = ReadPreference.ofReadPreference(readPreferenceString) | ||
.orElseThrow(() -> { | ||
final String msg = | ||
MessageFormat.format("Could not parse a ReadPreference from configured string <{0}>", | ||
readPreferenceString); | ||
return new DittoConfigError(msg); | ||
}); | ||
final var readConcernString = | ||
config.getString(MongoDbConfig.OptionsConfig.OptionsConfigValue.READ_CONCERN.getConfigPath()); | ||
readConcern = ReadConcern.ofReadConcern(readConcernString) | ||
.orElseThrow(() -> { | ||
final String msg = | ||
MessageFormat.format("Could not parse a ReadConcern from configured string <{0}>", | ||
readConcernString); | ||
return new DittoConfigError(msg); | ||
}); | ||
} | ||
|
||
/** | ||
* Returns an instance of DefaultUpdaterPersistenceConfig based on the settings of the specified Config. | ||
* | ||
* @param config is supposed to provide the settings of the stream config at {@value CONFIG_PATH}. | ||
* @return the instance. | ||
* @throws DittoConfigError if {@code config} is invalid. | ||
*/ | ||
public static DefaultUpdaterPersistenceConfig of(final Config config) { | ||
return new DefaultUpdaterPersistenceConfig(ConfigWithFallback.newInstance(config, CONFIG_PATH, ConfigValue.values())); | ||
} | ||
|
||
|
||
@Override | ||
public ReadPreference readPreference() { | ||
return readPreference; | ||
} | ||
|
||
@Override | ||
public ReadConcern readConcern() { | ||
return readConcern; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final DefaultUpdaterPersistenceConfig that = (DefaultUpdaterPersistenceConfig) o; | ||
return readPreference == that.readPreference && readConcern == that.readConcern; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(readPreference, readConcern); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [" + | ||
"readPreference=" + readPreference + | ||
", readConcern=" + readConcern + | ||
"]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...in/java/org/eclipse/ditto/thingsearch/service/common/config/UpdaterPersistenceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.thingsearch.service.common.config; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.internal.utils.config.KnownConfigValue; | ||
import org.eclipse.ditto.internal.utils.persistence.mongo.config.ReadConcern; | ||
import org.eclipse.ditto.internal.utils.persistence.mongo.config.ReadPreference; | ||
|
||
/** | ||
* Provides configuration settings of the Search updater persistence. | ||
*/ | ||
@Immutable | ||
public interface UpdaterPersistenceConfig { | ||
|
||
/** | ||
* Gets the desired read preference that should be used for queries done in the updater persistence. | ||
* | ||
* @return the desired read preference. | ||
*/ | ||
ReadPreference readPreference(); | ||
|
||
/** | ||
* Gets the desired read concern that should be used for queries done in the updater persistence. | ||
* | ||
* @return the desired read concern. | ||
*/ | ||
ReadConcern readConcern(); | ||
|
||
/** | ||
* An enumeration of known config path expressions and their associated default values for {@code UpdaterPersistenceConfig}. | ||
*/ | ||
enum ConfigValue implements KnownConfigValue { | ||
|
||
/** | ||
* Determines the read preference used for MongoDB connections. See {@link ReadPreference} for available options. | ||
*/ | ||
READ_PREFERENCE("readPreference", "primaryPreferred"), | ||
|
||
/** | ||
* Determines the read concern used for MongoDB connections. See {@link ReadConcern} for available options. | ||
*/ | ||
READ_CONCERN("readConcern", "default"); | ||
|
||
private final String configPath; | ||
private final Object defaultValue; | ||
|
||
ConfigValue(final String configPath, final Object defaultValue) { | ||
this.configPath = configPath; | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@Override | ||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public String getConfigPath() { | ||
return configPath; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.