Skip to content

Commit 555e054

Browse files
committed
cleanup proccessed files in VR by setting cron on starting monitorring service
1 parent e4117e6 commit 555e054

File tree

15 files changed

+248
-60
lines changed

15 files changed

+248
-60
lines changed

api/src/main/java/com/cloud/network/element/NetworkElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, Reser
117117
/**
118118
* The network service provider is being shutdown. This should shutdown all instances of this element deployed for this provider.
119119
* @param context
120-
* @param networkServiceProvider
120+
* @param provider
121121
* @return boolean success/failure
122122
* @throws ConcurrentOperationException
123123
* @throws ResourceUnavailableException
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
import com.cloud.exception.CloudException;
23+
24+
import java.util.Arrays;
25+
import java.util.List;
26+
import java.util.stream.Collectors;
27+
28+
public class CleanProcessCommandCacheAnswer extends Answer {
29+
int numberOfFiles = 0;
30+
List<String> fileNames;
31+
32+
public CleanProcessCommandCacheAnswer(CleanProcessedCacheCommand cmd, String details) {
33+
super(cmd, new CloudException(details));
34+
}
35+
36+
public CleanProcessCommandCacheAnswer(CleanProcessedCacheCommand cmd, String details, boolean b) {
37+
super(cmd, true, details);
38+
String[] lines = details.split("\n");
39+
for (String line: lines) {
40+
parse(line);
41+
}
42+
}
43+
44+
void parse(String line) {
45+
if (line.startsWith("numberOfFiles:")) {
46+
String[] s = line.split(" ");
47+
numberOfFiles = Integer.parseInt(s[1]);
48+
} else if (line.startsWith("files:")) {
49+
String[] s = line.split(" ") ;
50+
fileNames = Arrays.stream(s, 1, s.length).collect(Collectors.toList());
51+
}
52+
}
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
import com.cloud.agent.api.routing.NetworkElementCommand;
23+
24+
public class CleanProcessedCacheCommand extends NetworkElementCommand {
25+
int days = 60;
26+
protected CleanProcessedCacheCommand () {
27+
}
28+
29+
public CleanProcessedCacheCommand (int days) {
30+
this.days = days;
31+
}
32+
33+
@Override
34+
public boolean executeInSequence() {
35+
return false;
36+
}
37+
38+
public int getDays() {
39+
return this.days;
40+
}
41+
}

core/src/main/java/com/cloud/agent/api/routing/SetMonitorServiceCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
public class SetMonitorServiceCommand extends NetworkElementCommand {
3535
public static final String ROUTER_MONITORING_ENABLED = "router.monitor.enabled";
3636
public static final String ROUTER_HEALTH_CHECKS_ENABLED = "router.health.checks.enabled";
37+
public static final String ROUTER_PROCESSED_COMMANDS_CLEANUP_INTERVAL = "router.processed.commands.cleanup.interval";
3738
public static final String ROUTER_HEALTH_CHECKS_BASIC_INTERVAL = "router.health.checks.basic.interval";
3839
public static final String ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL = "router.health.checks.advanced.interval";
3940
public static final String ROUTER_HEALTH_CHECKS_EXCLUDED = "router.health.checks.excluded";

core/src/main/java/com/cloud/agent/resource/virtualnetwork/VRScripts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class VRScripts {
4242
public static final String IP_ALIAS_CONFIG = "ip_aliases.json";
4343
public static final String LOAD_BALANCER_CONFIG = "load_balancer.json";
4444

45+
public static final String CLEANUP_PROCESSED = "cleanup_processed.sh";
4546
public static final String SYSTEM_VM_PATCHED = "patched.sh";
4647
public final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
4748
public final static Duration VR_SCRIPT_EXEC_TIMEOUT = Duration.standardMinutes(10);

core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import javax.naming.ConfigurationException;
3636

37+
import com.cloud.agent.api.CleanProcessCommandCacheAnswer;
38+
import com.cloud.agent.api.CleanProcessedCacheCommand;
3739
import com.cloud.agent.api.routing.UpdateNetworkCommand;
3840
import com.cloud.agent.api.to.IpAddressTO;
3941
import com.cloud.network.router.VirtualRouter;
@@ -142,6 +144,9 @@ public Answer executeRequest(final NetworkElementCommand cmd) {
142144
if (cmd instanceof UpdateNetworkCommand) {
143145
return execute((UpdateNetworkCommand) cmd);
144146
}
147+
if (cmd instanceof CleanProcessedCacheCommand) {
148+
return execute((CleanProcessedCacheCommand) cmd);
149+
}
145150

146151
if (_vrAggregateCommandsSet.containsKey(routerName)) {
147152
_vrAggregateCommandsSet.get(routerName).add(cmd);
@@ -445,6 +450,15 @@ private Answer execute(CheckRouterCommand cmd) {
445450
return new CheckRouterAnswer(cmd, result.getDetails(), true);
446451
}
447452

453+
private Answer execute(CleanProcessedCacheCommand cmd) {
454+
int days = cmd.getDays();
455+
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.CLEANUP_PROCESSED, Integer.toString(days));
456+
if (!result.isSuccess()) {
457+
return new CleanProcessCommandCacheAnswer(cmd, result.getDetails());
458+
}
459+
return new CleanProcessCommandCacheAnswer(cmd, result.getDetails(), true);
460+
}
461+
448462
private Answer execute(DiagnosticsCommand cmd) {
449463
_eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt("60", 60));
450464
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.DIAGNOSTICS, cmd.getSrciptArguments(), _eachTimeout);

core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private void setupHealthChecksRelatedInfo(MonitorService monitorService, SetMoni
7171

7272
monitorService.setExcludedHealthChecks(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_EXCLUDED));
7373
monitorService.setHealthChecksConfig(command.getHealthChecksConfig());
74+
monitorService.setDeleteProcessedFilesInterval(Integer.valueOf(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_PROCESSED_COMMANDS_CLEANUP_INTERVAL)));
7475
}
7576

7677
@Override

core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/MonitorService.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ public class MonitorService extends ConfigBase {
2828
public Integer healthChecksAdvancedRunInterval;
2929
public String excludedHealthChecks;
3030
public Map<String, String> healthChecksConfig;
31+
public Integer deleteProcessedFilesInterval;
3132

3233
public MonitorService() {
3334
super(ConfigBase.MONITORSERVICE);
3435
}
3536

3637
public MonitorService(String config, String disableMonitoring, String healthChecksEnabled) {
3738
super(ConfigBase.MONITORSERVICE);
38-
this.config = config;
39-
this.disableMonitoring = disableMonitoring;
40-
this.healthChecksEnabled = Boolean.parseBoolean(healthChecksEnabled);
39+
this.setConfig(config);
40+
this.setDisableMonitoring(disableMonitoring);
41+
this.setHealthChecksEnabled(Boolean.parseBoolean(healthChecksEnabled));
4142
}
4243

4344
public String getConfig() {
@@ -68,6 +69,10 @@ public Map<String, String> getHealthChecksConfig() {
6869
return healthChecksConfig;
6970
}
7071

72+
public Integer getDeleteProcessedFilesInterval() {
73+
return deleteProcessedFilesInterval;
74+
}
75+
7176
public void setConfig(String config) {
7277
this.config = config;
7378
}
@@ -99,4 +104,8 @@ public void setHealthChecksConfig(Map<String, String> healthChecksConfig) {
99104
public void setDeleteFromProcessedCache(boolean deleteFromProcessedCache) {
100105
this.deleteFromProcessedCache = deleteFromProcessedCache;
101106
}
107+
108+
public void setDeleteProcessedFilesInterval(Integer deleteProcessedFilesInterval) {
109+
this.deleteProcessedFilesInterval = deleteProcessedFilesInterval;
110+
}
102111
}

engine/orchestration/src/main/java/com/cloud/agent/manager/DirectAgentAttache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected void runInContext() {
241241
if (s_logger.isDebugEnabled()) {
242242
s_logger.debug(log(seq, "Executing request"));
243243
}
244-
ArrayList<Answer> answers = new ArrayList<Answer>(cmds.length);
244+
ArrayList<Answer> answers = new ArrayList<>(cmds.length);
245245
for (int i = 0; i < cmds.length; i++) {
246246
Answer answer = null;
247247
Command currentCmd = cmds[i];

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,30 +1402,31 @@ private boolean networkMeetsPersistenceCriteria(NetworkVO network, NetworkOfferi
14021402
@DB
14031403
public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException,
14041404
ResourceUnavailableException, InsufficientCapacityException {
1405-
final Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
1405+
final Pair<NetworkGuru, NetworkVO> implemented = new Pair<>(null, null);
14061406

14071407
NetworkVO network = _networksDao.findById(networkId);
14081408
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
14091409
if (isNetworkImplemented(network)) {
14101410
s_logger.debug("Network id=" + networkId + " is already implemented");
14111411
implemented.set(guru, network);
14121412
return implemented;
1413-
}
1414-
1415-
// Acquire lock only when network needs to be implemented
1416-
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
1417-
if (network == null) {
1418-
// see NetworkVO.java
1419-
final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
1420-
ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
1421-
throw ex;
1413+
} else {
1414+
// Acquire lock only when network needs to be implemented
1415+
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
1416+
if (network == null) {
1417+
// see NetworkVO.java
1418+
final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
1419+
ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
1420+
throw ex;
1421+
}
14221422
}
14231423

14241424
if (s_logger.isDebugEnabled()) {
14251425
s_logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement");
14261426
}
14271427

14281428
try {
1429+
// fixme: why is this repetition of block 20 lines back needed
14291430
if (isNetworkImplemented(network)) {
14301431
s_logger.debug("Network id=" + networkId + " is already implemented");
14311432
implemented.set(guru, network);
@@ -1472,10 +1473,10 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
14721473
return implemented;
14731474
} catch (final NoTransitionException e) {
14741475
s_logger.error(e.getMessage());
1475-
return new Pair<NetworkGuru, NetworkVO>(null, null);
1476+
return new Pair<>(null, null);
14761477
} catch (final CloudRuntimeException | OperationTimedoutException e) {
14771478
s_logger.error("Caught exception: " + e.getMessage());
1478-
return new Pair<NetworkGuru, NetworkVO>(null, null);
1479+
return new Pair<>(null, null);
14791480
} finally {
14801481
if (implemented.first() == null) {
14811482
s_logger.debug("Cleaning up because we're unable to implement the network " + network);
@@ -4416,12 +4417,12 @@ private void setStateMachine() {
44164417
}
44174418

44184419
private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId) {
4419-
final Map<Service, Set<Provider>> map = new HashMap<Service, Set<Provider>>();
4420+
final Map<Service, Set<Provider>> map = new HashMap<>();
44204421
final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
44214422
for (final NetworkServiceMapVO nsm : nsms) {
44224423
Set<Provider> providers = map.get(Service.getService(nsm.getService()));
44234424
if (providers == null) {
4424-
providers = new HashSet<Provider>();
4425+
providers = new HashSet<>();
44254426
}
44264427
providers.add(Provider.getProvider(nsm.getProvider()));
44274428
map.put(Service.getService(nsm.getService()), providers);
@@ -4433,14 +4434,14 @@ private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId)
44334434
public List<Provider> getProvidersForServiceInNetwork(final Network network, final Service service) {
44344435
final Map<Service, Set<Provider>> service2ProviderMap = getServiceProvidersMap(network.getId());
44354436
if (service2ProviderMap.get(service) != null) {
4436-
final List<Provider> providers = new ArrayList<Provider>(service2ProviderMap.get(service));
4437+
final List<Provider> providers = new ArrayList<>(service2ProviderMap.get(service));
44374438
return providers;
44384439
}
44394440
return null;
44404441
}
44414442

44424443
protected List<NetworkElement> getElementForServiceInNetwork(final Network network, final Service service) {
4443-
final List<NetworkElement> elements = new ArrayList<NetworkElement>();
4444+
final List<NetworkElement> elements = new ArrayList<>();
44444445
final List<Provider> providers = getProvidersForServiceInNetwork(network, service);
44454446
//Only support one provider now
44464447
if (providers == null) {

0 commit comments

Comments
 (0)