Skip to content

Commit cb7e89b

Browse files
committed
Fix dynamic changing of the scheduled task interval
1 parent 9cb055c commit cb7e89b

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorServi
6666
this.unit = unit;
6767
}
6868

69-
protected ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorService, Runnable command,
69+
public ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorService, Runnable command,
7070
ConfigKey<?> configKey, int enableIntervalSeconds, TimeUnit unit) {
7171
validateArgs(executorService, command, configKey);
7272
this.executorService = executorService;

server/src/main/java/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.Set;
24-
import java.util.Timer;
25-
import java.util.TimerTask;
24+
import java.util.concurrent.Executors;
25+
import java.util.concurrent.ScheduledExecutorService;
26+
import java.util.concurrent.TimeUnit;
2627

2728
import javax.inject.Inject;
2829
import javax.naming.ConfigurationException;
@@ -48,7 +49,10 @@
4849
import org.apache.cloudstack.context.CallContext;
4950
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
5051
import org.apache.cloudstack.framework.config.ConfigKey;
51-
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
52+
import org.apache.cloudstack.framework.config.ConfigKeyScheduledExecutionWrapper;
53+
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
54+
55+
import com.cloud.utils.concurrency.NamedThreadFactory;
5256

5357
import com.cloud.alert.AlertManager;
5458
import com.cloud.configuration.Config;
@@ -179,15 +183,15 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
179183

180184
int _connLimit;
181185
int _subnetsLimit;
182-
private Timer _vpnCheckTimer;
186+
private ScheduledExecutorService _vpnCheckExecutor;
183187

184188
@Override
185189
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
186190
Map<String, String> configs = _configDao.getConfiguration(params);
187191
_connLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnConnectionPerVpnGatewayLimit.key()), 4);
188192
_subnetsLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnSubnetsPerCustomerGatewayLimit.key()), 10);
189193
assert (_s2sProviders.iterator().hasNext()) : "Did not get injected with a list of S2S providers!";
190-
_vpnCheckTimer = new Timer("VpnCustomerGateway-ObsoleteCheck", true);
194+
_vpnCheckExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpnCustomerGateway-ExcludedAndObsoleteCheck"));
191195
return true;
192196
}
193197

@@ -1152,21 +1156,20 @@ public Site2SiteVpnGateway updateVpnGateway(Long id, String customId, Boolean fo
11521156

11531157
@Override
11541158
public boolean start() {
1155-
final long checkInterval = VpnCustomerGatewayObsoleteCheckInterval.value();
1156-
if (checkInterval > 0) {
1157-
TimerTask task = new CheckVpnCustomerGatewayObsoleteParametersTask();
1158-
_vpnCheckTimer.schedule(task, checkInterval * 60 * 60 * 1000L, checkInterval * 60 * 60 * 1000L);
1159-
logger.info("Scheduled VPN customer gateway obsolete parameters check with interval: " + checkInterval + " hours");
1160-
} else {
1161-
logger.debug("VPN customer gateway obsolete check is disabled (interval = 0)");
1162-
}
1159+
ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(
1160+
_vpnCheckExecutor,
1161+
new CheckVpnCustomerGatewayObsoleteParametersTask(),
1162+
VpnCustomerGatewayObsoleteCheckInterval,
1163+
60,
1164+
TimeUnit.MINUTES);
1165+
runner.start();
11631166
return true;
11641167
}
11651168

11661169
@Override
11671170
public boolean stop() {
1168-
if (_vpnCheckTimer != null) {
1169-
_vpnCheckTimer.cancel();
1171+
if (_vpnCheckExecutor != null) {
1172+
_vpnCheckExecutor.shutdownNow();
11701173
}
11711174
return true;
11721175
}
@@ -1184,7 +1187,7 @@ public ConfigKey<?>[] getConfigKeys() {
11841187
VpnCustomerGatewayObsoleteCheckInterval};
11851188
}
11861189

1187-
protected class CheckVpnCustomerGatewayObsoleteParametersTask extends ManagedContextTimerTask {
1190+
protected class CheckVpnCustomerGatewayObsoleteParametersTask extends ManagedContextRunnable {
11881191

11891192
@Override
11901193
protected void runInContext() {
@@ -1203,7 +1206,7 @@ protected void runInContext() {
12031206
}
12041207
if (CollectionUtils.isNotEmpty(obsoleteParameters)) {
12051208
obsoleteCount++;
1206-
message.add("obsolete parameter(s) " + excludedParameters.toString());
1209+
message.add("obsolete parameter(s) " + obsoleteParameters.toString());
12071210
}
12081211

12091212
if (CollectionUtils.isNotEmpty(message)) {

ui/public/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4057,7 +4057,7 @@
40574057
"message.volumes.managed": "Volumes controlled by CloudStack.",
40584058
"message.volumes.unmanaged": "Volumes not controlled by CloudStack.",
40594059
"message.vpc.restart.required": "Restart is required for VPC(s). Click here to view VPC(s) which require restart.",
4060-
"message.vpn.customer.gateway.contains.obsolete.parameters": "The VPN Customer Gateway is configured with parameters marked as obsolete. Consider changing the parameters using Update VPN Customer Gateway.",
4060+
"message.vpn.customer.gateway.contains.excluded.obsolete.parameters": "This VPN Customer Gateway contains cryptographic parameters that are marked as excluded or obsolete by the Administrator. Consider changing them using the Update VPN Customer Gateway form.",
40614061
"message.vpn.customer.gateway.excluded.parameter": " is marked as excluded. Please choose another value.",
40624062
"message.vpn.customer.gateway.obsolete.parameter": " is marked as obsolete/insecure. Please choose another value.",
40634063
"message.vpn.customer.gateway.obsolete.parameter.tooltip": "This parameter value is marked as obsolete/insecure.",

ui/src/components/view/ListView.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180
</span>
181181
<span v-else-if="$route.path.startsWith('/vpncustomergateway')">
182182
&nbsp;
183-
<a-tooltip v-if="record.excludedparameters || record.obsoleteparameters" :title="$t('message.vpn.customer.gateway.contains.obsolete.parameters')">
183+
<a-tooltip
184+
v-if="record.excludedparameters || record.obsoleteparameters"
185+
:title="$t('message.vpn.customer.gateway.contains.excluded.obsolete.parameters')">
184186
<warning-outlined :style="{ color: $config.theme['@warning-color'] }" />
185187
</a-tooltip>
186188
</span>

0 commit comments

Comments
 (0)