Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions it/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,16 @@
<artifactId>annotations</artifactId>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/filtered-resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.common.TemporaryPath;
import com.walmartlabs.concord.common.ZipUtils;
import com.walmartlabs.concord.sdk.Constants;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand All @@ -36,27 +36,24 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;

public final class ITUtils {

private static final char[] RANDOM_CHARS = "abcdef0123456789".toCharArray();

public static byte[] archive(URI uri) throws IOException {
return archive(uri, null);
}

public static byte[] archive(URI uri, String depsDir) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(out)) {
ZipUtils.zip(zip, Paths.get(uri));
if (depsDir != null) {
ZipUtils.zip(zip, Constants.Files.LIBRARIES_DIR_NAME + "/", Paths.get(depsDir));
try (TemporaryPath tmpDir = preprocessDir(uri)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(out)) {
ZipUtils.zip(zip, tmpDir.path());
}
return out.toByteArray();
}
return out.toByteArray();
}

public static String resourceToString(Class<?> klass, String resource) throws Exception {
Expand Down Expand Up @@ -109,6 +106,31 @@ public static String randomPwd() {
return "pwd_" + randomString() + "A!";
}

private static TemporaryPath preprocessDir(URI uri) throws IOException {
Path src = Paths.get(uri);

// copy files from the specified URI to a temporary directory
TemporaryPath tmpDir = PathUtils.tempDir("test");
PathUtils.copy(src, tmpDir.path());

// find and replace all PROJECT_VERSION strings with the current ${project.version}
try (Stream<Path> yamlFiles = Files.walk(tmpDir.path())) {
for (Path yamlFile : yamlFiles.filter(f -> {
String fileName = f.getFileName().toString().toLowerCase();
return fileName.endsWith(".yaml") || fileName.endsWith(".yml") || fileName.endsWith(".json");
}).toList()) {
String content = Files.readString(yamlFile);
if (!content.contains("PROJECT_VERSION")) {
continue;
}
content = content.replaceAll("PROJECT_VERSION", Version.PROJECT_VERSION);
Files.writeString(yamlFile, content, StandardOpenOption.TRUNCATE_EXISTING);
}
}

return tmpDir;
}

private ITUtils() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.walmartlabs.concord.it.common;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2018 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 java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public final class Version {

public static final String PROJECT_VERSION;

static {
try (InputStream in = Version.class.getResourceAsStream("version.properties")) {
Properties props = new Properties();
props.load(in);
PROJECT_VERSION = props.getProperty("project.version");
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private Version() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,10 @@
* =====
*/

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public final class ITConstants {

public static final String PROJECT_VERSION;
public static final long DEFAULT_TEST_TIMEOUT = 120000;

static {
PROJECT_VERSION = getProperties("version.properties").getProperty("project.version");
}

private static Properties getProperties(String path) {
try (InputStream in = ClassLoader.getSystemResourceAsStream(path)) {
Properties props = new Properties();
props.load(in);
return props;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private ITConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.walmartlabs.concord.client2.HostEntry;
import com.walmartlabs.concord.client2.NodeRosterHostsApi;
import com.walmartlabs.concord.client2.ProcessEntry;
import com.walmartlabs.concord.it.common.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -46,7 +47,7 @@ public void test() throws Exception {
// run the Ansible flow first to get some data

String concordYml = resourceToString(NodeRosterIT.class.getResource("noderoster/ansible.yml"))
.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION);
.replaceAll("PROJECT_VERSION", Version.PROJECT_VERSION);

ConcordProcess proc = concord.processes().start(new Payload()
.concordYml(concordYml)
Expand All @@ -67,7 +68,7 @@ public void test() throws Exception {
// run the Node Roster flow next to test the plugin

concordYml = resourceToString(ProcessIT.class.getResource("noderoster/noderoster.yml"))
.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION);
.replaceAll("PROJECT_VERSION", Version.PROJECT_VERSION);

proc = concord.processes().start(new Payload()
.concordYml(concordYml));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ca.ibodrov.concord.testcontainers.junit5.ConcordRule;
import com.walmartlabs.concord.client2.*;
import com.walmartlabs.concord.common.ConfigurationUtils;
import com.walmartlabs.concord.it.common.Version;
import com.walmartlabs.concord.sdk.Constants;
import com.walmartlabs.concord.sdk.MapUtils;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -347,7 +348,7 @@ public void testCheckpointsParallel() throws Exception {
@Test
public void testNoStateAfterCheckpoint() throws Exception {
String concordYml = resourceToString(ProcessIT.class.getResource("checkpointState/concord.yml"))
.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION);
.replaceAll("PROJECT_VERSION", Version.PROJECT_VERSION);

Payload payload = new Payload().concordYml(concordYml);

Expand Down Expand Up @@ -418,7 +419,7 @@ public void testForkCheckpoints() throws Exception {
@Test
public void testCheckpointsWith3rdPartyClasses() throws Exception {
String concordYml = resourceToString(NodeRosterIT.class.getResource("checkpointClasses/concord.yml"))
.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION);
.replaceAll("PROJECT_VERSION", Version.PROJECT_VERSION);

ConcordProcess proc = concord.processes().start(new Payload()
.concordYml(concordYml));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.icegreen.greenmail.junit5.GreenMailExtension;
import com.icegreen.greenmail.util.ServerSetup;
import com.walmartlabs.concord.client2.ProcessEntry;
import com.walmartlabs.concord.it.common.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.Testcontainers;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void test() throws Exception {

// SMTP host and port must be accessible by the process
// i.e. when running in a container the host must point to the docker host's address
concordYml = concordYml.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION)
concordYml = concordYml.replaceAll("PROJECT_VERSION", Version.PROJECT_VERSION)
.replaceAll("SMTP_HOST", concord.hostAddressAccessibleByContainers())
.replaceAll("SMTP_PORT", String.valueOf(mailServer.getSmtp().getPort()));

Expand Down
49 changes: 1 addition & 48 deletions it/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,67 +268,20 @@
<configuration>
<overWriteIfNewer>true</overWriteIfNewer>
<artifactItems>
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>ansible-tasks</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>ansible-template</artifactId>
<version>${project.version}</version>
<destFileName>ansible-template.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>concord-tasks</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>dynamic-tasks</artifactId>
<version>${project.version}</version>
</artifactItem>

<!-- TODO this should be automated -->
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>noderoster-tasks</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
<groupId>com.walmartlabs.concord.server.plugins.noderoster</groupId>
<artifactId>concord-noderoster-plugin-client2</artifactId>
<version>${project.version}</version>
</artifactItem>

<!-- TODO this should be automated -->
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>smtp-tasks</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
</artifactItem>
<artifactItem>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</artifactItem>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
</dependency>

<!-- used by DependenciesIT as an example dependency -->
<!-- used by DependenciesIT as example dependencies -->
<artifactItem>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>example-tasks</artifactId>
<version>${project.version}</version>
<destFileName>example.jar</destFileName>
</artifactItem>

<dependency>
<groupId>com.walmartlabs.concord.plugins.basic</groupId>
<artifactId>ansible-tasks</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AnsibleEventIT extends AbstractServerIT {
@SuppressWarnings("unchecked")
public void testEvent() throws Exception {
URI uri = AnsibleEventIT.class.getResource("ansibleEvent").toURI();
byte[] payload = archive(uri, ITConstants.DEPENDENCIES_DIR);
byte[] payload = archive(uri);

// ---

Expand Down Expand Up @@ -81,7 +81,7 @@ public void testEvent() throws Exception {
@Test
public void testIgnoredFailures() throws Exception {
URI uri = AnsibleEventIT.class.getResource("ansibleIgnoredFailures").toURI();
byte[] payload = archive(uri, ITConstants.DEPENDENCIES_DIR);
byte[] payload = archive(uri);

// ---

Expand Down Expand Up @@ -123,7 +123,7 @@ public void testIgnoredFailures() throws Exception {
@Test
public void testFailedHosts() throws Exception {
URI uri = AnsibleEventIT.class.getResource("ansibleFailedHosts").toURI();
byte[] payload = archive(uri, ITConstants.DEPENDENCIES_DIR);
byte[] payload = archive(uri);

// ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AnsibleEventProcessorIT extends AbstractServerIT {
@Test
public void test() throws Exception {
URI uri = AnsibleEventProcessorIT.class.getResource("ansibleEventProcessor").toURI();
byte[] payload = archive(uri, ITConstants.DEPENDENCIES_DIR);
byte[] payload = archive(uri);

// ---

Expand Down Expand Up @@ -66,7 +66,7 @@ public void test() throws Exception {
@Test
public void testLongNames() throws Exception {
URI uri = AnsibleEventProcessorIT.class.getResource("ansibleEventProcessor").toURI();
byte[] payload = archive(uri, ITConstants.DEPENDENCIES_DIR);
byte[] payload = archive(uri);

// ---

Expand Down
Loading