Skip to content

Commit e941e61

Browse files
committed
1055 Reorganize
1 parent 1a62cb4 commit e941e61

27 files changed

Lines changed: 160 additions & 487 deletions

File tree

server/ee/apps/scheduler-app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
implementation(project(":server:ee:libs:config:observability-config"))
3232
implementation(project(":server:ee:libs:core:discovery:discovery-redis"))
3333
implementation(project(":server:ee:libs:platform:platform-component:platform-component-remote-client"))
34+
implementation(project(":server:ee:libs:platform:platform-connection:platform-connection-remote-client"))
3435
implementation(project(":server:ee:libs:platform:platform-scheduler:platform-scheduler-impl"))
3536
implementation(project(":server:ee:libs:platform:platform-scheduler:platform-scheduler-remote-rest"))
3637
implementation(project(":server:ee:libs:platform:platform-workflow:platform-workflow-execution:platform-workflow-execution-remote-client"))

server/ee/libs/platform/platform-component/platform-component-remote-client/src/main/java/com/bytechef/ee/platform/component/remote/client/facade/RemoteConnectionDefinitionFacadeClient.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

server/ee/libs/platform/platform-component/platform-component-remote-client/src/main/java/com/bytechef/ee/platform/component/remote/client/service/RemoteConnectionDefinitionServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Optional<String> executeBaseUri(
7878
}
7979

8080
@Override
81-
public Context createConnectionRefreshContext(String componentName, ComponentConnection componentConnection) {
81+
public ComponentConnection executeConnectionRefresh(ComponentConnection componentConnection) {
8282
throw new UnsupportedOperationException();
8383
}
8484

server/ee/libs/platform/platform-component/platform-component-remote-rest/src/main/java/com/bytechef/ee/platform/component/remote/web/rest/facade/RemoteConnectionDefinitionFacadeController.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

server/ee/libs/platform/platform-connection/platform-connection-remote-client/src/main/java/com/bytechef/ee/platform/connection/remote/client/fasade/RemoteConnectionFacadeClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public void delete(Long id) {
3232
throw new UnsupportedOperationException();
3333
}
3434

35+
@Override
36+
public Long executeConnectionRefresh(Long connectionId) {
37+
throw new UnsupportedOperationException();
38+
}
39+
3540
@Override
3641
public ConnectionDTO getConnection(Long id) {
3742
throw new UnsupportedOperationException();

server/ee/libs/platform/platform-scheduler/platform-scheduler-aws/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ dependencies {
55
implementation("io.awspring.cloud:spring-cloud-aws-sqs")
66
implementation(project(":server:libs:config:app-config"))
77
implementation(project(":server:libs:core:commons:commons-util"))
8+
implementation(project(":server:libs:core:tenant:tenant-api"))
89
implementation(project(":server:libs:platform:platform-scheduler:platform-scheduler-api"))
910
implementation(project(":server:libs:platform:platform-workflow:platform-workflow-coordinator:platform-workflow-coordinator-api"))
1011
implementation(project(":server:libs:platform:platform-api"))
12+
implementation(project(":server:libs:platform:platform-connection:platform-connection-api"))
1113

1214
implementation(project(":server:ee:libs:core:cloud:cloud-aws"))
1315
implementation(project(":server:ee:libs:core:message:message-broker:message-broker-aws"))

server/ee/libs/platform/platform-scheduler/platform-scheduler-aws/src/main/java/com/bytechef/ee/platform/scheduler/aws/AwsConnectionRefreshScheduler.java

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
/*
22
* Copyright 2025 ByteChef
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
4+
* Licensed under the ByteChef Enterprise license (the "Enterprise License");
5+
* you may not use this file except in compliance with the Enterprise License.
156
*/
167

178
package com.bytechef.ee.platform.scheduler.aws;
@@ -22,13 +13,11 @@
2213
import com.bytechef.config.ApplicationProperties;
2314
import com.bytechef.ee.platform.scheduler.aws.constant.AwsTriggerSchedulerConstants;
2415
import com.bytechef.platform.scheduler.ConnectionRefreshScheduler;
16+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2517
import java.time.Duration;
2618
import java.time.Instant;
27-
import java.util.Date;
28-
2919
import org.slf4j.Logger;
3020
import org.slf4j.LoggerFactory;
31-
import org.stringtemplate.v4.ST;
3221
import software.amazon.awssdk.services.scheduler.SchedulerClient;
3322
import software.amazon.awssdk.services.scheduler.model.ConflictException;
3423
import software.amazon.awssdk.services.scheduler.model.FlexibleTimeWindowMode;
@@ -43,17 +32,12 @@ public class AwsConnectionRefreshScheduler implements ConnectionRefreshScheduler
4332

4433
private static final Logger log = LoggerFactory.getLogger(AwsConnectionRefreshScheduler.class);
4534

46-
private final int pollingTriggerCheckPeriod;
4735
private final SchedulerClient schedulerClient;
4836
private final String sqsArn;
4937
private final String roleArn;
5038

51-
@SuppressWarnings("E1")
52-
public AwsConnectionRefreshScheduler(
53-
ApplicationProperties.Cloud.Aws aws, ApplicationProperties.Coordinator.Trigger.Polling polling,
54-
SchedulerClient schedulerClient) {
55-
56-
this.pollingTriggerCheckPeriod = polling.getCheckPeriod();
39+
@SuppressFBWarnings("EI")
40+
public AwsConnectionRefreshScheduler(ApplicationProperties.Cloud.Aws aws, SchedulerClient schedulerClient) {
5741
this.schedulerClient = schedulerClient;
5842

5943
String accountId = aws.getAccountId();
@@ -80,18 +64,23 @@ public void scheduleConnectionRefresh(Long connectionId, Instant expiry, String
8064
String scheduleName = CONNECTION_REFRESH + tenantId + connectionId;
8165
String clientToken = tenantId + connectionId;
8266

83-
long secondsUntilExpiry = Duration.between(Instant.now(), expiry).getSeconds();
67+
Instant now = Instant.now();
68+
69+
Duration between = Duration.between(now, expiry);
70+
71+
long secondsUntilExpiry = between.getSeconds();
72+
8473
long minutesUntilExpiry = secondsUntilExpiry / 60;
8574

8675
long refreshMinutes = Math.max(1, minutesUntilExpiry - 5);
8776

8877
String scheduleExpression = "rate(" + refreshMinutes + " minutes)";
8978

90-
log.info("Scheduling connection refresh for connection: {}, tenant: {}", connectionId, tenantId);
91-
log.info("Expiry time: {}, Refresh time: {}", expiry, refreshMinutes);
92-
log.info("Schedule expression: {}", scheduleExpression);
93-
log.info("SQS ARN: {}", sqsArn + ":" + SCHEDULER_CONNECTION_REFRESH_QUEUE);
94-
log.info("Role ARN: {}", roleArn);
79+
log.info(
80+
"Scheduling connection refresh for connection: {}, tenant: {}, expiry time: {}, refresh time: {}, " +
81+
"schedule expression: {}, SQS ARN: {}, role ARN: {}",
82+
connectionId, tenantId, expiry, refreshMinutes, scheduleExpression,
83+
sqsArn + ":" + SCHEDULER_CONNECTION_REFRESH_QUEUE, roleArn);
9584

9685
Target sqsTarget = Target.builder()
9786
.roleArn(roleArn)
@@ -106,7 +95,7 @@ public void scheduleConnectionRefresh(Long connectionId, Instant expiry, String
10695
.scheduleExpression(scheduleExpression)
10796
.target(sqsTarget)
10897
.flexibleTimeWindow(mode -> mode.mode(FlexibleTimeWindowMode.OFF))
109-
.startDate(Instant.now().plus(Duration.ofMinutes(1))));
98+
.startDate(now.plus(Duration.ofMinutes(1))));
11099

111100
log.info("Schedule created successfully.");
112101
} catch (ConflictException e) {
@@ -118,7 +107,7 @@ public void scheduleConnectionRefresh(Long connectionId, Instant expiry, String
118107
.scheduleExpression(scheduleExpression)
119108
.target(sqsTarget)
120109
.flexibleTimeWindow(mode -> mode.mode(FlexibleTimeWindowMode.OFF))
121-
.startDate(Instant.now().plus(Duration.ofMinutes(1))));
110+
.startDate(now.plus(Duration.ofMinutes(1))));
122111

123112
log.info("Schedule updated successfully.");
124113
}

server/ee/libs/platform/platform-scheduler/platform-scheduler-aws/src/main/java/com/bytechef/ee/platform/scheduler/aws/AwsTriggerScheduler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import com.bytechef.platform.scheduler.TriggerScheduler;
2020
import com.bytechef.platform.workflow.WorkflowExecutionId;
2121
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22-
23-
import java.time.Duration;
2422
import java.time.Instant;
2523
import java.util.Map;
2624
import org.slf4j.Logger;

server/ee/libs/platform/platform-scheduler/platform-scheduler-aws/src/main/java/com/bytechef/ee/platform/scheduler/aws/config/AwsConnectionRefreshSchedulerConfiguration.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
package com.bytechef.ee.platform.scheduler.aws.config;
1818

19-
import com.bytechef.atlas.configuration.service.WorkflowService;
2019
import com.bytechef.config.ApplicationProperties;
2120
import com.bytechef.ee.platform.scheduler.aws.AwsConnectionRefreshScheduler;
2221
import com.bytechef.ee.platform.scheduler.aws.listener.ConnectionRefreshListener;
2322
import com.bytechef.platform.annotation.ConditionalOnEEVersion;
24-
import com.bytechef.platform.component.facade.ConnectionDefinitionFacade;
25-
import com.bytechef.platform.component.facade.TriggerDefinitionFacade;
26-
import com.bytechef.platform.workflow.execution.accessor.JobPrincipalAccessorRegistry;
27-
import com.bytechef.platform.workflow.execution.service.TriggerStateService;
23+
import com.bytechef.platform.connection.facade.ConnectionFacade;
2824
import org.slf4j.Logger;
2925
import org.slf4j.LoggerFactory;
3026
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -61,29 +57,17 @@ AwsConnectionRefreshScheduler awsConnectionRefreshScheduler(
6157

6258
ApplicationProperties.Cloud.Aws aws = applicationProperties.getCloud()
6359
.getAws();
64-
ApplicationProperties.Coordinator.Trigger.Polling polling = applicationProperties
65-
.getCoordinator()
66-
.getTrigger()
67-
.getPolling();
6860

6961
SchedulerClient schedulerClient = SchedulerClient.builder()
7062
.credentialsProvider(awsCredentialsProvider)
7163
.region(awsRegionProvider.getRegion())
7264
.build();
7365

74-
return new AwsConnectionRefreshScheduler(aws, polling, schedulerClient);
66+
return new AwsConnectionRefreshScheduler(aws, schedulerClient);
7567
}
7668

7769
@Bean
78-
ConnectionRefreshListener connectionRefreshListener(
79-
AwsCredentialsProvider awsCredentialsProvider, AwsRegionProvider awsRegionProvider,
80-
ConnectionDefinitionFacade remoteConnectionDefinitionFacade) {
81-
82-
SchedulerClient schedulerClient = SchedulerClient.builder()
83-
.credentialsProvider(awsCredentialsProvider)
84-
.region(awsRegionProvider.getRegion())
85-
.build();
86-
87-
return new ConnectionRefreshListener(schedulerClient, remoteConnectionDefinitionFacade);
70+
ConnectionRefreshListener connectionRefreshListener(ConnectionFacade connectionFacade) {
71+
return new ConnectionRefreshListener(connectionFacade);
8872
}
8973
}
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
package com.bytechef.ee.platform.scheduler.aws.listener;
2-
3-
import com.bytechef.atlas.configuration.service.WorkflowService;
4-
import com.bytechef.platform.component.ComponentConnection;
5-
import com.bytechef.platform.component.facade.ConnectionDefinitionFacade;
6-
import com.bytechef.platform.workflow.execution.accessor.JobPrincipalAccessorRegistry;
7-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
8-
import io.awspring.cloud.sqs.annotation.SqsListener;
9-
import org.slf4j.Logger;
10-
import org.springframework.stereotype.Component;
11-
import software.amazon.awssdk.services.scheduler.SchedulerClient;
12-
import software.amazon.awssdk.services.scheduler.model.FlexibleTimeWindow;
13-
import software.amazon.awssdk.services.scheduler.model.FlexibleTimeWindowMode;
14-
import software.amazon.awssdk.services.scheduler.model.UpdateScheduleRequest;
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the ByteChef Enterprise license (the "Enterprise License");
5+
* you may not use this file except in compliance with the Enterprise License.
6+
*/
157

16-
import java.time.Duration;
17-
import java.time.Instant;
18-
import java.util.Map;
8+
package com.bytechef.ee.platform.scheduler.aws.listener;
199

20-
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsConnectionRefreshSchedulerConstants.CONNECTION_REFRESH;
2110
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsConnectionRefreshSchedulerConstants.SCHEDULER_CONNECTION_REFRESH_QUEUE;
2211
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsTriggerSchedulerConstants.SPLITTER;
2312

13+
import com.bytechef.platform.connection.facade.ConnectionFacade;
14+
import com.bytechef.tenant.TenantContext;
15+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16+
import io.awspring.cloud.sqs.annotation.SqsListener;
17+
2418
/**
2519
* @version ee
2620
*
2721
* @author Nikolina Spehar
2822
*/
2923
public class ConnectionRefreshListener {
3024

31-
private final ConnectionDefinitionFacade remoteConnectionDefinitionFacade;
32-
private final SchedulerClient schedulerClient;
25+
private final ConnectionFacade connectionFacade;
3326

3427
@SuppressFBWarnings("EI")
35-
public ConnectionRefreshListener(
36-
SchedulerClient schedulerClient, ConnectionDefinitionFacade remoteConnectionDefinitionFacade) {
37-
38-
this.schedulerClient = schedulerClient;
39-
this.remoteConnectionDefinitionFacade = remoteConnectionDefinitionFacade;
28+
public ConnectionRefreshListener(ConnectionFacade connectionFacade) {
29+
this.connectionFacade = connectionFacade;
4030
}
4131

4232
@SqsListener(SCHEDULER_CONNECTION_REFRESH_QUEUE)
@@ -45,24 +35,6 @@ public void onSchedule(String message) {
4535
String tenantId = split[0];
4636
Long connectionId = Long.valueOf(split[1]);
4737

48-
refreshConnection(tenantId, connectionId);
49-
}
50-
51-
private Instant refreshConnection(String tenantId, Long connectionId) {
52-
Instant connectionExpiry = null;
53-
54-
ComponentConnection componentConnection = remoteConnectionDefinitionFacade.executeConnectionRefresh(
55-
tenantId, connectionId);
56-
57-
if (componentConnection != null) {
58-
Map<String, ?> parameters = componentConnection.getParameters();
59-
60-
Long expiresIn = (Long) parameters.get("expires_in");
61-
62-
connectionExpiry = Instant.now()
63-
.plusSeconds(expiresIn);
64-
}
65-
66-
return connectionExpiry;
38+
TenantContext.runWithTenantId(tenantId, () -> connectionFacade.executeConnectionRefresh(connectionId));
6739
}
6840
}

0 commit comments

Comments
 (0)