Skip to content

Commit

Permalink
project: switch to concord-client2 (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
brig authored Dec 27, 2023
1 parent c302761 commit e7bcfc4
Show file tree
Hide file tree
Showing 273 changed files with 3,619 additions and 4,149 deletions.
7 changes: 1 addition & 6 deletions agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</dependency>
<dependency>
<groupId>com.walmartlabs.concord</groupId>
<artifactId>concord-client</artifactId>
<artifactId>concord-client2</artifactId>
</dependency>
<dependency>
<groupId>com.walmartlabs.concord</groupId>
Expand Down Expand Up @@ -105,11 +105,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.walmartlabs.concord.agent.guice.WorkerModule;
import com.walmartlabs.concord.agent.mmode.MaintenanceModeListener;
import com.walmartlabs.concord.agent.mmode.MaintenanceModeNotifier;
import com.walmartlabs.concord.client.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.client2.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.server.queueclient.QueueClient;
import com.walmartlabs.concord.server.queueclient.message.ProcessRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@
* =====
*/

import com.walmartlabs.concord.client.ClientUtils;
import com.walmartlabs.concord.client.ProcessApi;
import com.walmartlabs.concord.client2.ClientUtils;
import com.walmartlabs.concord.client2.ProcessApi;
import com.walmartlabs.concord.common.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.File;
import java.nio.file.Path;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;

public class DefaultStateFetcher implements StateFetcher {

private static final Logger log = LoggerFactory.getLogger(DefaultStateFetcher.class);

private final ProcessApi processApi;

@Inject
Expand All @@ -44,26 +39,9 @@ public DefaultStateFetcher(ProcessApi processApi) {

@Override
public void downloadState(JobRequest job) throws Exception {
File payload = null;
try {
payload = ClientUtils.withRetry(AgentConstants.API_CALL_MAX_RETRIES, AgentConstants.API_CALL_RETRY_DELAY, () -> processApi.downloadState(job.getInstanceId()));
IOUtils.unzip(payload.toPath(), job.getPayloadDir(), StandardCopyOption.REPLACE_EXISTING);
} finally {
if (payload != null) {
delete(payload.toPath());
}
}
}

private static void delete(Path dir) {
if (dir == null) {
return;
}

try {
IOUtils.deleteRecursively(dir);
} catch (Exception e) {
log.warn("delete ['{}'] -> error", dir, e);
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);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.walmartlabs.concord.agent.cfg.GitConfiguration;
import com.walmartlabs.concord.agent.cfg.RepositoryCacheConfiguration;
import com.walmartlabs.concord.client.SecretClient;
import com.walmartlabs.concord.client2.SecretClient;
import com.walmartlabs.concord.imports.Import.SecretDefinition;
import com.walmartlabs.concord.repository.*;
import com.walmartlabs.concord.sdk.Secret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.walmartlabs.concord.agent.guice.AgentImportManager;
import com.walmartlabs.concord.agent.logging.ProcessLog;
import com.walmartlabs.concord.agent.remote.ProcessStatusUpdater;
import com.walmartlabs.concord.client.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.client2.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.imports.Import.SecretDefinition;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class AgentConfiguration {
private final long pollInterval;
private final int maintenanceModeListenerPort;

private final boolean explicitlyResolveV1Client;

@Inject
public AgentConfiguration(Config cfg) {
this.agentId = getStringOrDefault(cfg, "id", () -> UUID.randomUUID().toString());
Expand All @@ -82,6 +84,8 @@ public AgentConfiguration(Config cfg) {
this.maintenanceModeListenerPort = cfg.getInt("maintenanceModeListenerPort");

this.pollInterval = cfg.getDuration("pollInterval", TimeUnit.MILLISECONDS);

this.explicitlyResolveV1Client = cfg.getBoolean("explicitlyResolveV1Client");
}

public String getAgentId() {
Expand Down Expand Up @@ -139,4 +143,8 @@ public long getPollInterval() {
public int getMaintenanceModeListenerPort() {
return maintenanceModeListenerPort;
}

public boolean isExplicitlyResolveV1Client() {
return explicitlyResolveV1Client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.time.Duration;

import static com.walmartlabs.concord.agent.cfg.Utils.getStringOrDefault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public DependencyManagerConfiguration get() {
.cacheDir(cfg.getDependencyCacheDir())
.strictRepositories(cfg.dependencyStrictRepositories())
.exclusions(cfg.dependencyExclusions())
.explicitlyResolveV1Client(cfg.isExplicitlyResolveV1Client())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import com.walmartlabs.concord.ApiClient;
import com.walmartlabs.concord.client2.*;
import com.walmartlabs.concord.agent.DefaultStateFetcher;
import com.walmartlabs.concord.agent.StateFetcher;
import com.walmartlabs.concord.agent.logging.*;
import com.walmartlabs.concord.agent.remote.ApiClientFactory;
import com.walmartlabs.concord.agent.remote.ProcessStatusUpdater;
import com.walmartlabs.concord.client.ProcessApi;
import com.walmartlabs.concord.client.SecretClient;
import com.walmartlabs.concord.dependencymanager.DependencyManagerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.walmartlabs.concord.client.LogSegmentUpdateRequest;
import com.walmartlabs.concord.client2.LogSegmentUpdateRequest;
import org.immutables.value.Value;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* 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.
Expand All @@ -20,17 +20,13 @@
* =====
*/

import com.walmartlabs.concord.ApiClient;
import com.walmartlabs.concord.ApiException;
import com.walmartlabs.concord.agent.AgentConstants;
import com.walmartlabs.concord.client.ClientUtils;
import com.walmartlabs.concord.client.LogSegmentUpdateRequest;
import com.walmartlabs.concord.client.ProcessApi;
import com.walmartlabs.concord.client.ProcessLogV2Api;
import com.walmartlabs.concord.client2.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.ByteArrayInputStream;
import java.util.UUID;

public class RemoteLogAppender implements LogAppender {
Expand All @@ -48,11 +44,9 @@ public RemoteLogAppender(ApiClient apiClient) {

@Override
public void appendLog(UUID instanceId, byte[] ab) {
String path = "/api/v1/process/" + instanceId + "/log";

try {
ClientUtils.withRetry(AgentConstants.API_CALL_MAX_RETRIES, AgentConstants.API_CALL_RETRY_DELAY, () -> {
ClientUtils.postData(processApi.getApiClient(), path, ab);
processApi.appendProcessLog(instanceId, new ByteArrayInputStream(ab));
return null;
});
} catch (ApiException e) {
Expand All @@ -63,11 +57,9 @@ public void appendLog(UUID instanceId, byte[] ab) {

@Override
public boolean appendLog(UUID instanceId, long segmentId, byte[] ab) {
String path = "/api/v2/process/" + instanceId + "/log/segment/" + segmentId + "/data";

try {
ClientUtils.withRetry(AgentConstants.API_CALL_MAX_RETRIES, AgentConstants.API_CALL_RETRY_DELAY, () -> {
ClientUtils.postData(processApi.getApiClient(), path, ab);
processLogV2Api.appendProcessLogSegment(instanceId, segmentId, new ByteArrayInputStream(ab));
return null;
});
return true;
Expand All @@ -81,17 +73,17 @@ public boolean appendLog(UUID instanceId, long segmentId, byte[] ab) {
@Override
public boolean updateSegment(UUID instanceId, long segmentId, LogSegmentStats stats) {
LogSegmentUpdateRequest request = new LogSegmentUpdateRequest()
.setStatus(stats.status())
.setWarnings(stats.warnings())
.setErrors(stats.errors());
.status(stats.status())
.warnings(stats.warnings())
.errors(stats.errors());

try {
ClientUtils.withRetry(AgentConstants.API_CALL_MAX_RETRIES, AgentConstants.API_CALL_RETRY_DELAY,
() -> processLogV2Api.updateSegment(instanceId, segmentId, request));
() -> processLogV2Api.updateProcessLogSegment(instanceId, segmentId, request));
return true;
} catch (Exception e) {
log.warn("updateSegment ['{}', '{}', '{}'] -> error: {}", instanceId, segmentId, stats, e.getMessage());
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* =====
*/

import com.walmartlabs.concord.client.LogSegmentUpdateRequest;
import com.walmartlabs.concord.client2.LogSegmentUpdateRequest;

import java.util.*;
import java.util.function.Consumer;
Expand Down
Loading

0 comments on commit e7bcfc4

Please sign in to comment.