Skip to content

Commit 45a3f7b

Browse files
committed
1055 Reorganize
1 parent 1a62cb4 commit 45a3f7b

13 files changed

Lines changed: 94 additions & 121 deletions

File tree

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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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+
*/
7+
18
package com.bytechef.ee.platform.component.remote.client.facade;
29

3-
import com.bytechef.ee.platform.component.remote.client.AbstractWorkerClient;
4-
import com.bytechef.ee.remote.client.DefaultRestClient;
510
import com.bytechef.platform.component.ComponentConnection;
611
import com.bytechef.platform.component.facade.ConnectionDefinitionFacade;
7-
import org.jspecify.annotations.Nullable;
8-
import org.springframework.cloud.client.discovery.DiscoveryClient;
912
import org.springframework.stereotype.Component;
10-
import tools.jackson.databind.ObjectMapper;
1113

1214
/**
1315
* @version ee

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
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+
*/
7+
18
package com.bytechef.ee.platform.component.remote.web.rest.facade;
29

310
import com.bytechef.platform.component.ComponentConnection;
411
import com.bytechef.platform.component.facade.ConnectionDefinitionFacade;
512
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
6-
import io.swagger.v3.oas.annotations.Hidden;
713
import jakarta.validation.Valid;
814
import org.springframework.http.ResponseEntity;
915
import org.springframework.web.bind.annotation.RequestBody;

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

Lines changed: 16 additions & 28 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;
@@ -24,11 +15,8 @@
2415
import com.bytechef.platform.scheduler.ConnectionRefreshScheduler;
2516
import java.time.Duration;
2617
import java.time.Instant;
27-
import java.util.Date;
28-
2918
import org.slf4j.Logger;
3019
import org.slf4j.LoggerFactory;
31-
import org.stringtemplate.v4.ST;
3220
import software.amazon.awssdk.services.scheduler.SchedulerClient;
3321
import software.amazon.awssdk.services.scheduler.model.ConflictException;
3422
import software.amazon.awssdk.services.scheduler.model.FlexibleTimeWindowMode;
@@ -43,17 +31,12 @@ public class AwsConnectionRefreshScheduler implements ConnectionRefreshScheduler
4331

4432
private static final Logger log = LoggerFactory.getLogger(AwsConnectionRefreshScheduler.class);
4533

46-
private final int pollingTriggerCheckPeriod;
4734
private final SchedulerClient schedulerClient;
4835
private final String sqsArn;
4936
private final String roleArn;
5037

5138
@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+
public AwsConnectionRefreshScheduler(ApplicationProperties.Cloud.Aws aws, SchedulerClient schedulerClient) {
5740
this.schedulerClient = schedulerClient;
5841

5942
String accountId = aws.getAccountId();
@@ -80,18 +63,23 @@ public void scheduleConnectionRefresh(Long connectionId, Instant expiry, String
8063
String scheduleName = CONNECTION_REFRESH + tenantId + connectionId;
8164
String clientToken = tenantId + connectionId;
8265

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

8674
long refreshMinutes = Math.max(1, minutesUntilExpiry - 5);
8775

8876
String scheduleExpression = "rate(" + refreshMinutes + " minutes)";
8977

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);
78+
log.info(
79+
"Scheduling connection refresh for connection: {}, tenant: {}, expiry time: {}, refresh time: {}, " +
80+
"schedule expression: {}, SQS ARN: {}, role ARN: {}",
81+
connectionId, tenantId, expiry, refreshMinutes, scheduleExpression,
82+
sqsArn + ":" + SCHEDULER_CONNECTION_REFRESH_QUEUE, roleArn);
9583

9684
Target sqsTarget = Target.builder()
9785
.roleArn(roleArn)
@@ -106,7 +94,7 @@ public void scheduleConnectionRefresh(Long connectionId, Instant expiry, String
10694
.scheduleExpression(scheduleExpression)
10795
.target(sqsTarget)
10896
.flexibleTimeWindow(mode -> mode.mode(FlexibleTimeWindowMode.OFF))
109-
.startDate(Instant.now().plus(Duration.ofMinutes(1))));
97+
.startDate(now.plus(Duration.ofMinutes(1))));
11098

11199
log.info("Schedule created successfully.");
112100
} catch (ConflictException e) {
@@ -118,7 +106,7 @@ public void scheduleConnectionRefresh(Long connectionId, Instant expiry, String
118106
.scheduleExpression(scheduleExpression)
119107
.target(sqsTarget)
120108
.flexibleTimeWindow(mode -> mode.mode(FlexibleTimeWindowMode.OFF))
121-
.startDate(Instant.now().plus(Duration.ofMinutes(1))));
109+
.startDate(now.plus(Duration.ofMinutes(1))));
122110

123111
log.info("Schedule updated successfully.");
124112
}

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: 3 additions & 15 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;
2423
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;
2824
import org.slf4j.Logger;
2925
import org.slf4j.LoggerFactory;
3026
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -71,19 +67,11 @@ AwsConnectionRefreshScheduler awsConnectionRefreshScheduler(
7167
.region(awsRegionProvider.getRegion())
7268
.build();
7369

74-
return new AwsConnectionRefreshScheduler(aws, polling, schedulerClient);
70+
return new AwsConnectionRefreshScheduler(aws, schedulerClient);
7571
}
7672

7773
@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);
74+
ConnectionRefreshListener connectionRefreshListener(ConnectionDefinitionFacade remoteConnectionDefinitionFacade) {
75+
return new ConnectionRefreshListener(remoteConnectionDefinitionFacade);
8876
}
8977
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
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+
*/
7+
18
package com.bytechef.ee.platform.scheduler.aws.listener;
29

3-
import com.bytechef.atlas.configuration.service.WorkflowService;
4-
import com.bytechef.platform.component.ComponentConnection;
10+
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsConnectionRefreshSchedulerConstants.SCHEDULER_CONNECTION_REFRESH_QUEUE;
11+
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsTriggerSchedulerConstants.SPLITTER;
12+
513
import com.bytechef.platform.component.facade.ConnectionDefinitionFacade;
6-
import com.bytechef.platform.workflow.execution.accessor.JobPrincipalAccessorRegistry;
714
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
815
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;
15-
16-
import java.time.Duration;
17-
import java.time.Instant;
18-
import java.util.Map;
19-
20-
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsConnectionRefreshSchedulerConstants.CONNECTION_REFRESH;
21-
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsConnectionRefreshSchedulerConstants.SCHEDULER_CONNECTION_REFRESH_QUEUE;
22-
import static com.bytechef.ee.platform.scheduler.aws.constant.AwsTriggerSchedulerConstants.SPLITTER;
2316

2417
/**
2518
* @version ee
@@ -29,13 +22,9 @@
2922
public class ConnectionRefreshListener {
3023

3124
private final ConnectionDefinitionFacade remoteConnectionDefinitionFacade;
32-
private final SchedulerClient schedulerClient;
3325

3426
@SuppressFBWarnings("EI")
35-
public ConnectionRefreshListener(
36-
SchedulerClient schedulerClient, ConnectionDefinitionFacade remoteConnectionDefinitionFacade) {
37-
38-
this.schedulerClient = schedulerClient;
27+
public ConnectionRefreshListener(ConnectionDefinitionFacade remoteConnectionDefinitionFacade) {
3928
this.remoteConnectionDefinitionFacade = remoteConnectionDefinitionFacade;
4029
}
4130

@@ -45,24 +34,6 @@ public void onSchedule(String message) {
4534
String tenantId = split[0];
4635
Long connectionId = Long.valueOf(split[1]);
4736

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;
37+
remoteConnectionDefinitionFacade.executeConnectionRefresh(tenantId, connectionId);
6738
}
6839
}

server/ee/libs/platform/platform-scheduler/platform-scheduler-aws/src/test/java/com/bytechef/ee/platform/scheduler/aws/AwsConnectionRefreshSchedulerTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@
1919
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertNotNull;
22-
import static org.mockito.ArgumentMatchers.any;
23-
import static org.mockito.Mockito.mock;
24-
import static org.mockito.Mockito.mockStatic;
2522
import static org.mockito.Mockito.verify;
26-
import static org.mockito.Mockito.when;
2723

2824
import com.bytechef.commons.util.JsonUtils;
29-
import com.bytechef.config.ApplicationProperties;
3025
import java.time.Instant;
3126
import java.time.LocalDateTime;
3227
import java.time.ZoneOffset;
@@ -39,10 +34,7 @@
3934
import software.amazon.awssdk.services.scheduler.SchedulerClient;
4035
import software.amazon.awssdk.services.scheduler.model.CreateScheduleRequest;
4136
import software.amazon.awssdk.services.scheduler.model.CreateScheduleRequest.Builder;
42-
import software.amazon.awssdk.services.scheduler.model.CreateScheduleResponse;
4337
import software.amazon.awssdk.services.scheduler.model.DeleteScheduleRequest;
44-
import software.amazon.awssdk.services.scheduler.model.DeleteScheduleResponse;
45-
import software.amazon.awssdk.services.scheduler.model.UpdateScheduleResponse;
4638

4739
/**
4840
* @author Nikolina Spehar

server/ee/libs/platform/platform-scheduler/platform-scheduler-remote-client/src/main/java/com/bytechef/ee/platform/scheduler/remote/client/RemoteConnectionRefreshSchedulerClient.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import com.bytechef.platform.scheduler.ConnectionRefreshScheduler;
1212
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1313
import java.time.Instant;
14-
import java.util.Map;
15-
1614
import org.springframework.stereotype.Component;
1715

1816
/**

server/ee/libs/platform/platform-scheduler/platform-scheduler-remote-rest/src/main/java/com/bytechef/ee/platform/scheduler/remote/web/rest/RemoteConnectionRefreshSchedulerController.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
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.
15+
*/
16+
117
package com.bytechef.ee.platform.scheduler.remote.web.rest;
218

319
import com.bytechef.platform.scheduler.ConnectionRefreshScheduler;
4-
import com.bytechef.platform.workflow.WorkflowExecutionId;
520
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
621
import jakarta.validation.Valid;
22+
import java.time.Instant;
723
import org.springframework.web.bind.annotation.RequestBody;
824
import org.springframework.web.bind.annotation.RequestMapping;
925
import org.springframework.web.bind.annotation.RequestMethod;
1026
import org.springframework.web.bind.annotation.RestController;
1127

12-
import java.time.Instant;
13-
1428
/**
1529
* @author Nikolina Spehar
1630
*/
@@ -30,7 +44,8 @@ public RemoteConnectionRefreshSchedulerController(ConnectionRefreshScheduler con
3044
consumes = {
3145
"application/json"
3246
})
33-
void cancelConnectionRefresh(@Valid @RequestBody ScheduleConnectionRefreshRequest scheduleConnectionRefreshRequest) {
47+
void cancelConnectionRefresh(
48+
@Valid @RequestBody ScheduleConnectionRefreshRequest scheduleConnectionRefreshRequest) {
3449
connectionRefreshScheduler.cancelConnectionRefresh(
3550
scheduleConnectionRefreshRequest.connectionId, scheduleConnectionRefreshRequest.tenantId);
3651
}
@@ -41,7 +56,8 @@ void cancelConnectionRefresh(@Valid @RequestBody ScheduleConnectionRefreshReques
4156
consumes = {
4257
"application/json"
4358
})
44-
void scheduleConnectionRefresh(@Valid @RequestBody ScheduleConnectionRefreshRequest scheduleConnectionRefreshRequest) {
59+
void scheduleConnectionRefresh(
60+
@Valid @RequestBody ScheduleConnectionRefreshRequest scheduleConnectionRefreshRequest) {
4561
connectionRefreshScheduler.scheduleConnectionRefresh(
4662
scheduleConnectionRefreshRequest.connectionId,
4763
scheduleConnectionRefreshRequest.expiry,

server/ee/libs/platform/platform-workflow/platform-workflow-execution/platform-workflow-execution-remote-rest/src/main/java/com/bytechef/ee/platform/workflow/execution/remote/web/rest/facade/RemoteConnectionLifecycleFacadeController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
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.
15+
*/
16+
117
package com.bytechef.ee.platform.workflow.execution.remote.web.rest.facade;
218

319
/**

0 commit comments

Comments
 (0)