Skip to content

Commit

Permalink
[TH2-5069] Provided the ability to define configs directory using the… (
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro authored Sep 21, 2023
1 parent 4745640 commit c4ab2e1
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 199 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import com.exactpro.th2.common.schema.factory.CommonFactory

Then you will create an instance of imported class, by choosing one of the following options:

1. Create factory with configs from the default path (`/var/th2/config/*`):
1. Create factory with configs from the `th2.common.configuration-directory` environment variable or default path (`/var/th2/config/*`):
```
var factory = CommonFactory();
```
1. Create factory with configs from the specified file paths:
```
var factory = CommonFactory(rabbitMQ, routerMQ, routerGRPC, cradle, custom, prometheus, dictionariesDir);
```
1. Create factory with configs from the specified arguments:
```
var factory = CommonFactory.createFromArguments(args);
Expand All @@ -34,7 +30,8 @@ Then you will create an instance of imported class, by choosing one of the follo
* --dictionariesDir - path to the directory which contains files with the encoded dictionaries
* --prometheusConfiguration - path to json file with configuration for prometheus metrics server
* --boxConfiguration - path to json file with boxes configuration and information
* -c/--configs - folder with json files for schemas configurations with special names:
* -c/--configs - folder with json files for schemas configurations with special names.
If you doesn't specify -c/--configs common factory uses configs from the `th2.common.configuration-directory` environment variable or default path (`/var/th2/config/*`)
1. rabbitMq.json - configuration for RabbitMQ
2. mq.json - configuration for MessageRouter
Expand Down Expand Up @@ -494,6 +491,11 @@ dependencies {

## Release notes

### 5.5.0-dev

#### Changed:
+ Provided the ability to define configs directory using the `th2.common.configuration-directory` environment variable

### 5.4.2-dev

#### Fix
Expand Down Expand Up @@ -919,7 +921,7 @@ dependencies {
### 3.13.0

+ reads dictionaries from the /var/th2/config/dictionary folder.
+ uses mq_router, grpc_router, cradle_manager optional JSON configs from the /var/th2/config folder
+ uses mq_router, grpc_router, cradle_manager optional JSON configs from the `/var/th2/config` folder

### 3.11.0

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
testImplementation "org.testcontainers:testcontainers:1.17.1"
testImplementation "org.testcontainers:rabbitmq:1.17.1"
testImplementation("org.junit-pioneer:junit-pioneer:2.1.0") {
because("system property tests")
}

testFixturesImplementation group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit5', version: kotlin_version
testFixturesImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
release_version=5.4.2
release_version=5.5.0
description='th2 common library (Java)'
vcs_url=https://github.com/th2-net/th2-common-j
kapt.include.compile.classpath=false
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public abstract class AbstractCommonFactory implements AutoCloseable {
* @deprecated please use {@link #LOG4J_PROPERTIES_DEFAULT_PATH}
*/
@Deprecated
protected static final String LOG4J_PROPERTIES_DEFAULT_PATH_OLD = "/home/etc";
protected static final String LOG4J_PROPERTIES_DEFAULT_PATH = "/var/th2/config";
protected static final Path LOG4J_PROPERTIES_DEFAULT_PATH_OLD = Path.of("/home/etc");
protected static final Path LOG4J_PROPERTIES_DEFAULT_PATH = Path.of("/var/th2/config");
protected static final String LOG4J2_PROPERTIES_NAME = "log4j2.properties";

public static final ObjectMapper MAPPER = new ObjectMapper();
Expand Down Expand Up @@ -168,71 +168,6 @@ public AbstractCommonFactory(FactorySettings settings) {
stringSubstitutor = new StringSubstitutor(key -> defaultIfBlank(settings.getVariables().get(key), System.getenv(key)));
}

/**
* Create factory with default implementation schema classes
*
* @deprecated Please use {@link AbstractCommonFactory#AbstractCommonFactory(FactorySettings)}
*/
@Deprecated(since = "4.0.0", forRemoval = true)
public AbstractCommonFactory() {
this(new FactorySettings());
}

/**
* Create factory with non-default implementations schema classes
*
* @param messageRouterParsedBatchClass Class for {@link MessageRouter} which work with {@link MessageBatch}
* @param messageRouterRawBatchClass Class for {@link MessageRouter} which work with {@link RawMessageBatch}
* @param eventBatchRouterClass Class for {@link MessageRouter} which work with {@link EventBatch}
* @param grpcRouterClass Class for {@link GrpcRouter}
* @deprecated Please use {@link AbstractCommonFactory#AbstractCommonFactory(FactorySettings)}
*/
@Deprecated(since = "4.0.0", forRemoval = true)
public AbstractCommonFactory(
@NotNull Class<? extends MessageRouter<MessageBatch>> messageRouterParsedBatchClass,
@NotNull Class<? extends MessageRouter<RawMessageBatch>> messageRouterRawBatchClass,
@NotNull Class<? extends MessageRouter<MessageGroupBatch>> messageRouterMessageGroupBatchClass,
@NotNull Class<? extends MessageRouter<EventBatch>> eventBatchRouterClass,
@NotNull Class<? extends GrpcRouter> grpcRouterClass
) {
this(new FactorySettings()
.messageRouterParsedBatchClass(messageRouterParsedBatchClass)
.messageRouterRawBatchClass(messageRouterRawBatchClass)
.messageRouterMessageGroupBatchClass(messageRouterMessageGroupBatchClass)
.eventBatchRouterClass(eventBatchRouterClass)
.grpcRouterClass(grpcRouterClass)
);
}

/**
* Create factory with non-default implementations schema classes
*
* @param messageRouterParsedBatchClass Class for {@link MessageRouter} which work with {@link MessageBatch}
* @param messageRouterRawBatchClass Class for {@link MessageRouter} which work with {@link RawMessageBatch}
* @param eventBatchRouterClass Class for {@link MessageRouter} which work with {@link EventBatch}
* @param grpcRouterClass Class for {@link GrpcRouter}
* @param environmentVariables map with additional environment variables
* @deprecated Please use {@link AbstractCommonFactory#AbstractCommonFactory(FactorySettings)}
*/
@Deprecated(since = "4.0.0", forRemoval = true)
protected AbstractCommonFactory(
@NotNull Class<? extends MessageRouter<MessageBatch>> messageRouterParsedBatchClass,
@NotNull Class<? extends MessageRouter<RawMessageBatch>> messageRouterRawBatchClass,
@NotNull Class<? extends MessageRouter<MessageGroupBatch>> messageRouterMessageGroupBatchClass,
@NotNull Class<? extends MessageRouter<EventBatch>> eventBatchRouterClass,
@NotNull Class<? extends GrpcRouter> grpcRouterClass,
@NotNull Map<String, String> environmentVariables
) {
this(new FactorySettings()
.messageRouterParsedBatchClass(messageRouterParsedBatchClass)
.messageRouterRawBatchClass(messageRouterRawBatchClass)
.messageRouterMessageGroupBatchClass(messageRouterMessageGroupBatchClass)
.eventBatchRouterClass(eventBatchRouterClass)
.grpcRouterClass(grpcRouterClass)
.variables(environmentVariables)
);
}

public void start() {
DefaultExports.initialize();
PrometheusConfiguration prometheusConfiguration = loadPrometheusConfiguration();
Expand Down Expand Up @@ -855,8 +790,8 @@ public void close() {
LOGGER.info("Common factory has been closed");
}

protected static void configureLogger(String... paths) {
List<String> listPath = new ArrayList<>();
protected static void configureLogger(Path... paths) {
List<Path> listPath = new ArrayList<>();
listPath.add(LOG4J_PROPERTIES_DEFAULT_PATH);
listPath.add(LOG4J_PROPERTIES_DEFAULT_PATH_OLD);
listPath.addAll(Arrays.asList(requireNonNull(paths, "Paths can't be null")));
Expand Down
Loading

0 comments on commit c4ab2e1

Please sign in to comment.