Skip to content

Commit

Permalink
it: add testing-server module
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodrov committed Nov 9, 2023
1 parent 0d9d0d4 commit d890f5f
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 21 deletions.
2 changes: 2 additions & 0 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<module>runtime-v1</module>
<module>runtime-v2</module>
<module>compat</module>

<module>testing-server</module>
</modules>

<properties>
Expand Down
49 changes: 49 additions & 0 deletions it/testing-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.walmartlabs.concord.it</groupId>
<artifactId>parent</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>testing-concord-server</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.walmartlabs.concord.server</groupId>
<artifactId>concord-server</artifactId>
<exclusions>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins.ansible</groupId>
<artifactId>concord-ansible-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins</groupId>
<artifactId>concord-oneops-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins.noderoster</groupId>
<artifactId>concord-noderoster-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins</groupId>
<artifactId>pfed-sso</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.walmartlabs.concord.it.testingserver;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =====
*/

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigParseOptions;
import com.typesafe.config.ConfigResolveOptions;
import com.walmartlabs.concord.server.ConcordServer;
import com.walmartlabs.concord.server.ConcordServerModule;
import org.testcontainers.containers.PostgreSQLContainer;

import java.security.SecureRandom;
import java.util.Base64;
import java.util.Map;

public class TestingConcordServer implements AutoCloseable {

private PostgreSQLContainer<?> db;
private ConcordServer server;

public TestingConcordServer start() throws Exception {
db = new PostgreSQLContainer<>("postgres:15-alpine");
db.start();

server = ConcordServer.withModules(new ConcordServerModule(prepareConfig(db)))
.start();

return this;
}

@Override
public void close() throws Exception {
this.stop();
}

public void stop() throws Exception {
if (server != null) {
server.stop();
server = null;
}

if (db != null) {
db.stop();
db = null;
}
}

private static Config prepareConfig(PostgreSQLContainer<?> db) {
Config testConfig = ConfigFactory.parseMap(Map.of(
"db.url", db.getJdbcUrl(),
"db.appUsername", db.getUsername(),
"db.appPassword", db.getPassword(),
"db.inventoryUsername", db.getUsername(),
"db.inventoryPassword", db.getPassword(),
"db.changeLogParameters.defaultAdminToken", "foobar",
"secretStore.serverPassword", randomString(),
"secretStore.secretStoreSalt", randomString(),
"secretStore.projectSecretSalt", randomString()
));

Config defaultConfig = ConfigFactory.load("concord-server.conf", ConfigParseOptions.defaults(), ConfigResolveOptions.defaults().setAllowUnresolved(true))
.getConfig("concord-server");

return testConfig.withFallback(defaultConfig).resolve();
}

private static String randomString() {
byte[] ab = new byte[64];
new SecureRandom().nextBytes(ab);
return Base64.getEncoder().encodeToString(ab);
}

public static void main(String[] args) throws Exception {
TestingConcordServer server = new TestingConcordServer().start();
Thread.sleep(100000);
server.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ public <T> T txResult(TxResult<T> t) {

public boolean exists(DSLContext tx, UUID currentInstanceId, UUID parentInstanceId, UUID projectId, String exclusiveGroup) {
SelectConditionStep<Record1<Integer>> s = tx.selectOne()
.from(PROCESS_QUEUE)
.where(jsonbText(PROCESS_QUEUE.EXCLUSIVE, "group").eq(exclusiveGroup)
.and(PROCESS_QUEUE.PROJECT_ID.eq(projectId)
.and(PROCESS_QUEUE.INSTANCE_ID.notEqual(currentInstanceId)
.and(PROCESS_QUEUE.CURRENT_STATUS.in(RUNNING_STATUSES)))));
.from(PROCESS_QUEUE)
.where(jsonbText(PROCESS_QUEUE.EXCLUSIVE, "group").eq(exclusiveGroup)
.and(PROCESS_QUEUE.PROJECT_ID.eq(projectId)
.and(PROCESS_QUEUE.INSTANCE_ID.notEqual(currentInstanceId)
.and(PROCESS_QUEUE.CURRENT_STATUS.in(RUNNING_STATUSES)))));

// parent's
if (parentInstanceId != null) {
Expand Down Expand Up @@ -326,14 +326,14 @@ public ProcessKey anyNew(DSLContext tx, ProcessKey currentProcessKey, UUID proje
.and(PROCESS_QUEUE.CURRENT_STATUS.in(CANCELLABLE_STATUSES)))));

SelectJoinStep<Record1<UUID>> children = tx.withRecursive("children").as(
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID).from(ProcessQueue.PROCESS_QUEUE)
.where(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID.eq(currentProcessKey.getInstanceId()))
.unionAll(
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID)
.from(ProcessQueue.PROCESS_QUEUE)
.join(name("children"))
.on(ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID.eq(
field(name("children", "INSTANCE_ID"), UUID.class)))))
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID).from(ProcessQueue.PROCESS_QUEUE)
.where(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID.eq(currentProcessKey.getInstanceId()))
.unionAll(
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID)
.from(ProcessQueue.PROCESS_QUEUE)
.join(name("children"))
.on(ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID.eq(
field(name("children", "INSTANCE_ID"), UUID.class)))))
.select(field("children.INSTANCE_ID", UUID.class))
.from(name("children"));

Expand All @@ -346,14 +346,14 @@ public ProcessKey anyNew(DSLContext tx, ProcessKey currentProcessKey, UUID proje

private static SelectJoinStep<Record1<UUID>> parents(DSLContext tx, UUID parentInstanceId) {
return tx.withRecursive("parents").as(
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID).from(ProcessQueue.PROCESS_QUEUE)
.where(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID.eq(parentInstanceId))
.unionAll(
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID)
.from(ProcessQueue.PROCESS_QUEUE)
.join(name("parents"))
.on(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID.eq(
field(name("parents", "PARENT_INSTANCE_ID"), UUID.class)))))
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID).from(ProcessQueue.PROCESS_QUEUE)
.where(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID.eq(parentInstanceId))
.unionAll(
select(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID, ProcessQueue.PROCESS_QUEUE.PARENT_INSTANCE_ID)
.from(ProcessQueue.PROCESS_QUEUE)
.join(name("parents"))
.on(ProcessQueue.PROCESS_QUEUE.INSTANCE_ID.eq(
field(name("parents", "PARENT_INSTANCE_ID"), UUID.class)))))
.select(field("parents.INSTANCE_ID", UUID.class))
.from(name("parents"));
}
Expand Down

0 comments on commit d890f5f

Please sign in to comment.