Skip to content

Commit

Permalink
Changed session cache size to 5 for SFTP and upgrade Spring Boot to 2…
Browse files Browse the repository at this point in the history
….3.3.RELEASE
  • Loading branch information
jcustovic committed Sep 2, 2020
1 parent 376e98f commit 5475511
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The project **Data Exchange Client** allows you to connect to SFTP or FTP servers and configure upload and download pullers.

Current stable version: **1.5.1**
Current stable version: **1.5.2**

## How to use

Expand Down
66 changes: 13 additions & 53 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.dataexchange</groupId>
<artifactId>data-exchange-client</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>
<packaging>jar</packaging>

<name>data-exchange-client</name>
Expand All @@ -14,17 +14,17 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<java.version>1.8</java.version>

<spring-integration-aws.version>2.0.1.RELEASE</spring-integration-aws.version>
<spring-integration-aws.version>2.3.3.RELEASE</spring-integration-aws.version>
<com.amazonaws.sdk.version>1.11.792</com.amazonaws.sdk.version> <!-- from spring-integration-aws -->

<commons-lang3.version>3.8.1</commons-lang3.version>
<com.amazonaws.sdk>1.11.336</com.amazonaws.sdk>
<commons-lang3.version>3.10</commons-lang3.version>

<!-- Test -->
<org.apache.sshd.version>2.1.0</org.apache.sshd.version>
Expand All @@ -37,7 +37,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<version>Hoxton.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -71,7 +71,6 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>

<dependency>
Expand All @@ -84,6 +83,11 @@
<artifactId>spring-integration-ftp</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-aws</artifactId>
Expand Down Expand Up @@ -115,17 +119,16 @@
<version>${commons-beanutils.version}</version>
</dependency>


<!-- AWS -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${com.amazonaws.sdk}</version>
<version>${com.amazonaws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${com.amazonaws.sdk}</version>
<version>${com.amazonaws.sdk.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -167,47 +170,4 @@
</dependency>
</dependencies>

<pluginRepositories>
<pluginRepository>
<id>libs-local</id>
<url>https://bin.private.zooplus.net/artifactory/libs-local</url>
</pluginRepository>
<pluginRepository>
<id>remote-repos</id>
<url>https://bin.private.zooplus.net/artifactory/remote-repos</url>
</pluginRepository>
</pluginRepositories>

<repositories>
<repository>
<id>finance-artifactory</id>
<url>https://bin.private.zooplus.net/artifactory/finance-local</url>
</repository>
<repository>
<id>logistics-local</id>
<url>https://bin.private.zooplus.net/artifactory/logistics-local</url>
</repository>
<repository>
<id>remote-repos</id>
<url>https://bin.private.zooplus.net/artifactory/remote-repos</url>
</repository>
<repository>
<id>libs-local</id>
<url>https://bin.private.zooplus.net/artifactory/libs-local</url>
</repository>
</repositories>

<distributionManagement>
<repository>
<id>zooplus</id>
<name>zooplus-releases</name>
<url>https://bin.private.zooplus.net/artifactory/logistics-local</url>
</repository>
<snapshotRepository>
<id>zooplus</id>
<name>zooplus-snapshots</name>
<url>https://bin.private.zooplus.net/artifactory/snapshots-local</url>
</snapshotRepository>
</distributionManagement>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
@Component
public class DynamicConfigurationCreator {

public static final int DEFAULT_SESSION_CACHE_SIZE = 5;

@Autowired
private MainConfiguration configuration;
@Autowired
Expand Down Expand Up @@ -126,7 +128,7 @@ private CachingSessionFactory sftpSessionFactory(SftpPollerConfiguration sftpPol
sftpSessionFactory.setTimeout(30_000);
sftpSessionFactory.setAllowUnknownKeys(true);

return createSessionFactory(sftpSessionFactory, 1, sftpPollerConfiguration.getUsername(),
return createSessionFactory(sftpSessionFactory, DEFAULT_SESSION_CACHE_SIZE, sftpPollerConfiguration.getUsername(),
sftpPollerConfiguration.getHost());
}

Expand All @@ -147,7 +149,7 @@ private CachingSessionFactory ftpSessionFactory(FtpPollerConfiguration ftpPoller
ftpSessionFactory.setConfig(ftpClientConfig);
}

return createSessionFactory(ftpSessionFactory, 5, ftpPollerConfiguration.getUsername(),
return createSessionFactory(ftpSessionFactory, DEFAULT_SESSION_CACHE_SIZE, ftpPollerConfiguration.getUsername(),
ftpPollerConfiguration.getHost());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MonitoringConfig {
public AbstractRequestHandlerAdvice pollerUpdateAdvice() {
return new AbstractRequestHandlerAdvice() {
@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) {
Message unwrap = message;
if (message instanceof AdviceMessage) {
unwrap = ((AdviceMessage<?>) message).getInputMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.Map;


@Component
@RefreshScope
@ConfigurationProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -88,12 +86,11 @@ public void read(String source, OutputStream outputStream) throws IOException {
LOGGER.info("Reading started {}", source);
targetSession.read(source, fos);
long endTime = System.nanoTime();
BigDecimal bytesPerSec = new BigDecimal(fos.getByteCount() / ((endTime - startTime) / 1000000000f))
BigDecimal bytesPerSec = BigDecimal.valueOf(fos.getByteCount() / ((endTime - startTime) / 1000000000f))
.setScale(4, BigDecimal.ROUND_HALF_UP);
BigDecimal kBytesPerSec = bytesPerSec.divide(BigDecimal.valueOf(1024f), 2, RoundingMode.HALF_UP);

submitExecutor.execute(() -> {
LocalDate.now().format(DateTimeFormatter.ofPattern("YYYY-MM"));
IndexRequest request = createIndexRequest(source, fos.getCount(), kBytesPerSec, OperationType.DOWNLOAD);
try {
esClient.index(request, RequestOptions.DEFAULT);
Expand All @@ -109,7 +106,7 @@ public void write(InputStream inputStream, String destination) throws IOExceptio
long startTime = System.nanoTime();
targetSession.write(cis, destination);
long endTime = System.nanoTime();
BigDecimal bytesPerSec = new BigDecimal(cis.getByteCount() / ((endTime - startTime) / 1000000000f))
BigDecimal bytesPerSec = BigDecimal.valueOf(cis.getByteCount() / ((endTime - startTime) / 1000000000f))
.setScale(4, BigDecimal.ROUND_HALF_UP);
BigDecimal kBytesPerSec = bytesPerSec.divide(BigDecimal.valueOf(1024f), 2, RoundingMode.HALF_UP);

Expand Down Expand Up @@ -178,6 +175,11 @@ public Object getClientInstance() {
return targetSession.getClientInstance();
}

@Override
public String getHostPort() {
return targetSession.getHostPort();
}

@Override
public boolean test() {
return targetSession.test();
Expand Down

0 comments on commit 5475511

Please sign in to comment.