Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, Reser
/**
* The network service provider is being shutdown. This should shutdown all instances of this element deployed for this provider.
* @param context
* @param networkServiceProvider
* @param provider
* @return boolean success/failure
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package com.cloud.agent.api;

import com.cloud.exception.CloudException;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class CleanProcessCommandCacheAnswer extends Answer {
int numberOfFiles = 0;
List<String> fileNames;

public CleanProcessCommandCacheAnswer(CleanProcessedCacheCommand cmd, String details) {
super(cmd, new CloudException(details));
}

public CleanProcessCommandCacheAnswer(CleanProcessedCacheCommand cmd, String details, boolean b) {
super(cmd, true, details);
String[] lines = details.split("\n");
for (String line: lines) {
parse(line);
}
}

void parse(String line) {
if (line.startsWith("numberOfFiles:")) {
String[] s = line.split(" ");
numberOfFiles = Integer.parseInt(s[1]);
} else if (line.startsWith("files:")) {
String[] s = line.split(" ") ;
fileNames = Arrays.stream(s, 1, s.length).collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package com.cloud.agent.api;

import com.cloud.agent.api.routing.NetworkElementCommand;

public class CleanProcessedCacheCommand extends NetworkElementCommand {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nts: does this mean the answer should also inherit (from NetworkElementAnswer for instance)

int days = 60;
protected CleanProcessedCacheCommand () {
}

public CleanProcessedCacheCommand (int days) {
this.days = days;
}

@Override
public boolean executeInSequence() {
return false;
}

public int getDays() {
return this.days;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class SetMonitorServiceCommand extends NetworkElementCommand {
public static final String ROUTER_MONITORING_ENABLED = "router.monitor.enabled";
public static final String ROUTER_HEALTH_CHECKS_ENABLED = "router.health.checks.enabled";
public static final String ROUTER_PROCESSED_COMMANDS_CLEANUP_INTERVAL = "router.processed.commands.cleanup.interval";
public static final String ROUTER_HEALTH_CHECKS_BASIC_INTERVAL = "router.health.checks.basic.interval";
public static final String ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL = "router.health.checks.advanced.interval";
public static final String ROUTER_HEALTH_CHECKS_EXCLUDED = "router.health.checks.excluded";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class VRScripts {
public static final String IP_ALIAS_CONFIG = "ip_aliases.json";
public static final String LOAD_BALANCER_CONFIG = "load_balancer.json";

public static final String CLEANUP_PROCESSED = "cleanup_processed.sh";
public static final String SYSTEM_VM_PATCHED = "patched.sh";
public final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
public final static Duration VR_SCRIPT_EXEC_TIMEOUT = Duration.standardMinutes(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import javax.naming.ConfigurationException;

import com.cloud.agent.api.CleanProcessCommandCacheAnswer;
import com.cloud.agent.api.CleanProcessedCacheCommand;
import com.cloud.agent.api.routing.UpdateNetworkCommand;
import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.network.router.VirtualRouter;
Expand Down Expand Up @@ -142,6 +144,9 @@ public Answer executeRequest(final NetworkElementCommand cmd) {
if (cmd instanceof UpdateNetworkCommand) {
return execute((UpdateNetworkCommand) cmd);
}
if (cmd instanceof CleanProcessedCacheCommand) {
return execute((CleanProcessedCacheCommand) cmd);
}

if (_vrAggregateCommandsSet.containsKey(routerName)) {
_vrAggregateCommandsSet.get(routerName).add(cmd);
Expand Down Expand Up @@ -445,6 +450,15 @@ private Answer execute(CheckRouterCommand cmd) {
return new CheckRouterAnswer(cmd, result.getDetails(), true);
}

private Answer execute(CleanProcessedCacheCommand cmd) {
int days = cmd.getDays();
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.CLEANUP_PROCESSED, Integer.toString(days));
if (!result.isSuccess()) {
return new CleanProcessCommandCacheAnswer(cmd, result.getDetails());
}
return new CleanProcessCommandCacheAnswer(cmd, result.getDetails(), true);
}

private Answer execute(DiagnosticsCommand cmd) {
_eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt("60", 60));
final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.DIAGNOSTICS, cmd.getSrciptArguments(), _eachTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private void setupHealthChecksRelatedInfo(MonitorService monitorService, SetMoni

monitorService.setExcludedHealthChecks(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_EXCLUDED));
monitorService.setHealthChecksConfig(command.getHealthChecksConfig());
monitorService.setDeleteProcessedFilesInterval(Integer.valueOf(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_PROCESSED_COMMANDS_CLEANUP_INTERVAL)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ public class MonitorService extends ConfigBase {
public Integer healthChecksAdvancedRunInterval;
public String excludedHealthChecks;
public Map<String, String> healthChecksConfig;
public Integer deleteProcessedFilesInterval;

public MonitorService() {
super(ConfigBase.MONITORSERVICE);
}

public MonitorService(String config, String disableMonitoring, String healthChecksEnabled) {
super(ConfigBase.MONITORSERVICE);
this.config = config;
this.disableMonitoring = disableMonitoring;
this.healthChecksEnabled = Boolean.parseBoolean(healthChecksEnabled);
this.setConfig(config);
this.setDisableMonitoring(disableMonitoring);
this.setHealthChecksEnabled(Boolean.parseBoolean(healthChecksEnabled));
}

public String getConfig() {
Expand Down Expand Up @@ -68,6 +69,10 @@ public Map<String, String> getHealthChecksConfig() {
return healthChecksConfig;
}

public Integer getDeleteProcessedFilesInterval() {
return deleteProcessedFilesInterval;
}

public void setConfig(String config) {
this.config = config;
}
Expand Down Expand Up @@ -99,4 +104,8 @@ public void setHealthChecksConfig(Map<String, String> healthChecksConfig) {
public void setDeleteFromProcessedCache(boolean deleteFromProcessedCache) {
this.deleteFromProcessedCache = deleteFromProcessedCache;
}

public void setDeleteProcessedFilesInterval(Integer deleteProcessedFilesInterval) {
this.deleteProcessedFilesInterval = deleteProcessedFilesInterval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected void runInContext() {
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(seq, "Executing request"));
}
ArrayList<Answer> answers = new ArrayList<Answer>(cmds.length);
ArrayList<Answer> answers = new ArrayList<>(cmds.length);
for (int i = 0; i < cmds.length; i++) {
Answer answer = null;
Command currentCmd = cmds[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1402,30 +1402,31 @@ private boolean networkMeetsPersistenceCriteria(NetworkVO network, NetworkOfferi
@DB
public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
final Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
final Pair<NetworkGuru, NetworkVO> implemented = new Pair<>(null, null);

NetworkVO network = _networksDao.findById(networkId);
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
if (isNetworkImplemented(network)) {
s_logger.debug("Network id=" + networkId + " is already implemented");
implemented.set(guru, network);
return implemented;
}

// Acquire lock only when network needs to be implemented
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
if (network == null) {
// see NetworkVO.java
final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
throw ex;
} else {
// Acquire lock only when network needs to be implemented
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
if (network == null) {
// see NetworkVO.java
final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
throw ex;
}
}

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

try {
// fixme: why is this repetition of block 20 lines back needed
if (isNetworkImplemented(network)) {
s_logger.debug("Network id=" + networkId + " is already implemented");
implemented.set(guru, network);
Expand Down Expand Up @@ -1472,10 +1473,10 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
return implemented;
} catch (final NoTransitionException e) {
s_logger.error(e.getMessage());
return new Pair<NetworkGuru, NetworkVO>(null, null);
return new Pair<>(null, null);
} catch (final CloudRuntimeException | OperationTimedoutException e) {
s_logger.error("Caught exception: " + e.getMessage());
return new Pair<NetworkGuru, NetworkVO>(null, null);
return new Pair<>(null, null);
} finally {
if (implemented.first() == null) {
s_logger.debug("Cleaning up because we're unable to implement the network " + network);
Expand Down Expand Up @@ -4416,12 +4417,12 @@ private void setStateMachine() {
}

private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId) {
final Map<Service, Set<Provider>> map = new HashMap<Service, Set<Provider>>();
final Map<Service, Set<Provider>> map = new HashMap<>();
final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
for (final NetworkServiceMapVO nsm : nsms) {
Set<Provider> providers = map.get(Service.getService(nsm.getService()));
if (providers == null) {
providers = new HashSet<Provider>();
providers = new HashSet<>();
}
providers.add(Provider.getProvider(nsm.getProvider()));
map.put(Service.getService(nsm.getService()), providers);
Expand All @@ -4433,14 +4434,14 @@ private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId)
public List<Provider> getProvidersForServiceInNetwork(final Network network, final Service service) {
final Map<Service, Set<Provider>> service2ProviderMap = getServiceProvidersMap(network.getId());
if (service2ProviderMap.get(service) != null) {
final List<Provider> providers = new ArrayList<Provider>(service2ProviderMap.get(service));
final List<Provider> providers = new ArrayList<>(service2ProviderMap.get(service));
return providers;
}
return null;
}

protected List<NetworkElement> getElementForServiceInNetwork(final Network network, final Service service) {
final List<NetworkElement> elements = new ArrayList<NetworkElement>();
final List<NetworkElement> elements = new ArrayList<>();
final List<Provider> providers = getProvidersForServiceInNetwork(network, service);
//Only support one provider now
if (providers == null) {
Expand Down
Loading