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
4 changes: 2 additions & 2 deletions agent/src/main/java/com/walmartlabs/concord/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.walmartlabs.concord.agent.mmode.MaintenanceModeListener;
import com.walmartlabs.concord.agent.mmode.MaintenanceModeNotifier;
import com.walmartlabs.concord.client2.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.server.queueclient.QueueClient;
import com.walmartlabs.concord.server.queueclient.message.ProcessRequest;
import com.walmartlabs.concord.server.queueclient.message.ProcessResponse;
Expand Down Expand Up @@ -235,7 +235,7 @@ private JobRequest take(QueueClient queueClient) throws Exception {
return null;
}

Path workDir = IOUtils.createTempDir(agentCfg.getPayloadDir(), "workDir");
Path workDir = PathUtils.createTempDir(agentCfg.getPayloadDir(), "workDir");

return JobRequest.from(resp, workDir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.walmartlabs.concord.client2.ClientUtils;
import com.walmartlabs.concord.client2.ProcessApi;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.ZipUtils;

import javax.inject.Inject;
import java.io.InputStream;
Expand All @@ -40,7 +40,7 @@ public DefaultStateFetcher(ProcessApi processApi) {
@Override
public void downloadState(JobRequest job) throws Exception {
try (InputStream is = ClientUtils.withRetry(AgentConstants.API_CALL_MAX_RETRIES, AgentConstants.API_CALL_RETRY_DELAY, () -> processApi.downloadState(job.getInstanceId()))){
IOUtils.unzip(is, job.getPayloadDir(), StandardCopyOption.REPLACE_EXISTING);
ZipUtils.unzip(is, job.getPayloadDir(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.google.inject.Injector;
import com.walmartlabs.concord.agent.cfg.AgentConfiguration;
import com.walmartlabs.concord.agent.guice.WorkerModule;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.server.queueclient.message.ProcessResponse;

import javax.inject.Inject;
Expand All @@ -49,7 +49,7 @@ public OneShotRunner(AgentConfiguration agentCfg,

public void run(String processResponseJson) throws Exception {
var processResponse = objectMapper.readValue(processResponseJson, ProcessResponse.class);
var workDir = IOUtils.createTempDir(agentCfg.getPayloadDir(), "workDir");
var workDir = PathUtils.createTempDir(agentCfg.getPayloadDir(), "workDir");
var jobRequest = JobRequest.from(processResponse, workDir);

var workerModule = new WorkerModule(agentCfg.getAgentId(), jobRequest.getInstanceId(), jobRequest.getSessionToken());
Expand Down
4 changes: 2 additions & 2 deletions agent/src/main/java/com/walmartlabs/concord/agent/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.walmartlabs.concord.agent.logging.ProcessLog;
import com.walmartlabs.concord.agent.remote.ProcessStatusUpdater;
import com.walmartlabs.concord.client2.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.imports.Import.SecretDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -105,7 +105,7 @@ public void run() {
Path payloadDir = jobRequest.getPayloadDir();
try {
log.info("exec ['{}'] -> removing the payload directory: {}", instanceId, payloadDir);
IOUtils.deleteRecursively(payloadDir);
PathUtils.deleteRecursively(payloadDir);
} catch (IOException e) {
log.warn("exec ['{}'] -> can't remove the payload directory: {}", instanceId, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

import com.typesafe.config.Config;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -58,7 +58,7 @@ public static Path getOptionalAbsolutePath(Config cfg, String key) {
public static Path getOrCreatePath(Config cfg, String key) {
try {
if (!cfg.hasPath(key)) {
return IOUtils.createTempDir(key);
return PathUtils.createTempDir(key);
}

String value = cfg.getString(key);
Expand All @@ -73,7 +73,7 @@ public static Path getOrCreatePath(Config cfg, String key) {

return p;
}
return IOUtils.createTempDir(value);
return PathUtils.createTempDir(value);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.walmartlabs.concord.agent.ExecutionException;
import com.walmartlabs.concord.agent.Utils;
import com.walmartlabs.concord.agent.cfg.PreForkConfiguration;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -166,7 +166,7 @@ private void maintenance() {

private static void cleanup(ProcessEntry process) {
try {
IOUtils.deleteRecursively(process.workDir);
PathUtils.deleteRecursively(process.workDir);
} catch (IOException e) {
log.info("cleanup ['{}'] -> error: {}", process.workDir, e.getMessage());
// ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.walmartlabs.concord.agent.logging.ProcessLog;
import com.walmartlabs.concord.agent.logging.ProcessLogFactory;
import com.walmartlabs.concord.agent.remote.AttachmentsUploader;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.common.Posix;
import com.walmartlabs.concord.dependencymanager.DependencyEntity;
import com.walmartlabs.concord.dependencymanager.DependencyManager;
Expand Down Expand Up @@ -239,7 +239,7 @@ private void persistWorkDir(UUID instanceId, Path src) {
}

log.info("exec ['{}'] -> persisting the payload directory into {}...", instanceId, dst);
IOUtils.copy(src, dst);
PathUtils.copy(src, dst);

// persistentWorkDir is mostly useful when the Agent is running in a container
// typically it is running as PID 456 - all files created by the process
Expand Down Expand Up @@ -279,7 +279,7 @@ private void cleanup(UUID instanceId, ProcessEntry pe) {
Path workDir = pe.getWorkDir();
try {
log.info("exec ['{}'] -> removing the working directory: {}", instanceId, workDir);
IOUtils.deleteRecursively(workDir);
PathUtils.deleteRecursively(workDir);
} catch (IOException e) {
log.warn("exec ['{}'] -> can't remove the working directory: {}", instanceId, e.getMessage());
}
Expand Down Expand Up @@ -486,7 +486,7 @@ private ProcessEntry fork(RunnerJob job, String[] cmd) throws ExecutionException
ProcessEntry entry = processPool.take(hc, () -> {
// can't use workDirBase, "preforks" start before they receive their process payload
// create a new temporary directory
Path workDir = IOUtils.createTempDir("workDir");
Path workDir = PathUtils.createTempDir("workDir");
return start(workDir, cmd);
});

Expand All @@ -495,7 +495,7 @@ private ProcessEntry fork(RunnerJob job, String[] cmd) throws ExecutionException
// the process' workDir
Path dst = entry.getWorkDir();
// TODO use move
IOUtils.copy(src, dst);
PathUtils.copy(src, dst);

writeInstanceId(job.getInstanceId(), dst);

Expand Down Expand Up @@ -540,7 +540,7 @@ private ProcessEntry start(Path workDir, String[] cmd) throws IOException {

// TODO constants
Map<String, String> env = b.environment();
env.put(IOUtils.TMP_DIR_KEY, IOUtils.TMP_DIR.toAbsolutePath().toString());
env.put(PathUtils.TMP_DIR_KEY, PathUtils.TMP_DIR.toAbsolutePath().toString());
env.put("_CONCORD_ATTACHMENTS_DIR", workDir.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME)
.toAbsolutePath().toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* =====
*/

import com.walmartlabs.concord.common.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,7 +61,7 @@ public void delete() {
public void log(InputStream src) throws IOException {
Path f = logFile();
try (OutputStream dst = Files.newOutputStream(f, StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
IOUtils.copy(src, dst);
src.transferTo(dst);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import com.walmartlabs.concord.agent.AgentConstants;
import com.walmartlabs.concord.client2.*;
import com.walmartlabs.concord.common.IOUtils;
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;

Expand All @@ -47,9 +48,9 @@ public void upload(UUID instanceId, Path workDir) throws Exception {
return;
}

try (TemporaryPath tmp = IOUtils.tempFile("attachments", ".zip")) {
try (TemporaryPath tmp = PathUtils.tempFile("attachments", ".zip")) {
try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(Files.newOutputStream(tmp.path()))) {
IOUtils.zip(zip, attachmentsDir);
ZipUtils.zip(zip, attachmentsDir);
}

ProcessApi api = new ProcessApi(apiClient);
Expand Down
9 changes: 5 additions & 4 deletions cli/src/main/java/com/walmartlabs/concord/cli/RemoteRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import com.walmartlabs.concord.client2.ApiClient;
import com.walmartlabs.concord.client2.ApiException;
import com.walmartlabs.concord.client2.ProcessApi;
import com.walmartlabs.concord.common.IOUtils;
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 picocli.CommandLine.Command;
Expand Down Expand Up @@ -190,13 +191,13 @@ private static TemporaryPath prepareArchive(Path src) throws IOException {
throw new IOException("Expected a path to a single concord.yaml (or .yml) file or a directory with flows, got " + src);
}

var dst = IOUtils.tempFile("payload", ".zip");
var dst = PathUtils.tempFile("payload", ".zip");

try (var zip = new ZipArchiveOutputStream(dst.path(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
if (Files.isRegularFile(src)) {
IOUtils.zipFile(zip, src, src.getFileName().toString());
ZipUtils.zipFile(zip, src, src.getFileName().toString());
} else if (Files.isDirectory(src)) {
IOUtils.zip(zip, src, PAYLOAD_ARCHIVE_FILTERS);
ZipUtils.zip(zip, src, PAYLOAD_ARCHIVE_FILTERS);
}
}

Expand Down
6 changes: 3 additions & 3 deletions cli/src/main/java/com/walmartlabs/concord/cli/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.walmartlabs.concord.cli.runner.*;
import com.walmartlabs.concord.common.ConfigurationUtils;
import com.walmartlabs.concord.common.FileVisitor;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.dependencymanager.DependencyManager;
import com.walmartlabs.concord.dependencymanager.DependencyManagerConfiguration;
import com.walmartlabs.concord.dependencymanager.DependencyManagerRepositories;
Expand Down Expand Up @@ -162,11 +162,11 @@ public Integer call() throws Exception {
if (verbosity.verbose()) {
System.out.println("Cleaning target directory");
}
IOUtils.deleteRecursively(targetDir);
PathUtils.deleteRecursively(targetDir);
}

// copy everything into target except target
IOUtils.copy(sourceDir, targetDir, "^target$", new CopyNotifier(verbosity.verbose() ? 0 : 100), StandardCopyOption.REPLACE_EXISTING);
PathUtils.copy(sourceDir, targetDir, "^target$", new CopyNotifier(verbosity.verbose() ? 0 : 100), StandardCopyOption.REPLACE_EXISTING);
} else {
throw new IllegalArgumentException("Not a directory or single Concord YAML file: " + sourceDir);
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/test/java/com/walmartlabs/concord/cli/LintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* =====
*/

import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import com.walmartlabs.concord.common.TemporaryPath;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
Expand Down Expand Up @@ -53,8 +53,8 @@ private static int lint(String payload) throws Exception {
URI uri = LintTest.class.getResource(payload).toURI();
Path source = Paths.get(uri);

try (TemporaryPath dst = IOUtils.tempDir("cli-tests")) {
IOUtils.copy(source, dst.path());
try (TemporaryPath dst = PathUtils.tempDir("cli-tests")) {
PathUtils.copy(source, dst.path());

App app = new App();
CommandLine cmd = new CommandLine(app);
Expand Down
4 changes: 2 additions & 2 deletions cli/src/test/java/com/walmartlabs/concord/cli/RunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* =====
*/

import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.PathUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import picocli.CommandLine;
Expand Down Expand Up @@ -121,7 +121,7 @@ private int run(String payload, List<String> args, String defaultCfg) throws Exc
URI uri = RunTest.class.getResource(payload).toURI();
Path source = Paths.get(uri);

IOUtils.copy(source, tempDir);
PathUtils.copy(source, tempDir);

App app = new App();
CommandLine cmd = new CommandLine(app);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ private String buildDockerCmd() throws IOException {
c.add(entryPoint);
}
if (generateUsers) {
Path tmp = IOUtils.createTempFile("passwd", ".docker"); // NOSONAR
Path tmp = PathUtils.createTempFile("passwd", ".docker"); // NOSONAR
tmpPaths.add(tmp);

try (InputStream src = Objects.requireNonNull(DockerProcessBuilder.class.getResourceAsStream("dockerPasswd"));
OutputStream dst = Files.newOutputStream(tmp)) {
IOUtils.copy(src, dst);
src.transferTo(dst);
}
c.add("-v");
c.add(tmp.toAbsolutePath() + ":/etc/passwd:ro");
Expand Down Expand Up @@ -450,7 +450,7 @@ public String[] cmd() {
public void close() {
for (Path p : tmpPaths) {
try {
IOUtils.deleteRecursively(p);
PathUtils.deleteRecursively(p);
} catch (IOException e) {
log.warn("delete '{}' -> error: {}", p, e.getMessage());
}
Expand Down
48 changes: 48 additions & 0 deletions common/src/main/java/com/walmartlabs/concord/common/GrepUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.walmartlabs.concord.common;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2025 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.*;
import java.util.ArrayList;
import java.util.List;

public final class GrepUtils {

public static List<String> grep(String pattern, byte[] ab) throws IOException {
return grep(pattern, new ByteArrayInputStream(ab));
}

public static List<String> grep(String pattern, InputStream in) throws IOException {
List<String> result = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.matches(pattern)) {
result.add(line);
}
}
}
return result;
}

private GrepUtils() {
}
}
Loading