You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ra...@apache.org on 2018/03/14 18:27:46 UTC
[cloudstack] branch master updated: CLOUDSTACK-8855 Improve Error
Message for Host Alert State and reconnect host API. (#2387)
This is an automated email from the ASF dual-hosted git repository.
rafael pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/master by this push:
new 972b8b7 CLOUDSTACK-8855 Improve Error Message for Host Alert State and reconnect host API. (#2387)
972b8b7 is described below
commit 972b8b71d7fb60a64e8a05e7555f9f92ede7ff40
Author: Rafael Weingärtner <ra...@gmail.com>
AuthorDate: Wed Mar 14 15:27:43 2018 -0300
CLOUDSTACK-8855 Improve Error Message for Host Alert State and reconnect host API. (#2387)
* CLOUDSTACK-8855 Improve Error Message for Host Alert State
* [CLOUDSTACK-9846] create column to save the content of alert messages
Remove declaration of throws CloudRuntimeException
I also removed some unused variables and comments left behind
This closes #837
* Isolate a problematic test "smoke/test_certauthority_root"
---
.travis.yml | 3 +-
api/src/main/java/com/cloud/alert/Alert.java | 2 +
.../java/com/cloud/resource/ResourceService.java | 21 +--
.../api/command/admin/host/ReconnectHostCmd.java | 28 ++--
.../main/java/com/cloud/agent/AgentManager.java | 4 +-
.../com/cloud/agent/manager/AgentManagerImpl.java | 173 ++++++++++-----------
.../agent/manager/ClusteredAgentManagerImpl.java | 110 ++++++-------
.../src/main/java/com/cloud/alert/AlertVO.java | 12 ++
.../main/java/com/cloud/host/dao/HostDaoImpl.java | 1 -
.../META-INF/db/schema-41000to41100-cleanup.sql | 2 +-
.../resources/META-INF/db/schema-41000to41100.sql | 2 +-
.../resources/META-INF/db/schema-41100to41200.sql | 5 +-
.../storage/test/DirectAgentManagerSimpleImpl.java | 6 +-
.../cloud/network/element/NetscalerElement.java | 116 +++++++-------
requirements.txt | 3 +-
.../java/com/cloud/alert/AlertManagerImpl.java | 47 +++---
.../com/cloud/resource/ResourceManagerImpl.java | 37 ++---
.../org/apache/cloudstack/ca/CAManagerImpl.java | 51 +++---
.../apache/cloudstack/ca/CAManagerImplTest.java | 2 +-
19 files changed, 286 insertions(+), 339 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index be0bfb1..f4b52ba 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,10 +33,11 @@ env:
- PATH=$HOME/.local/bin:$PATH
matrix:
# Keep the TESTS sorted by name and grouped by type
+ - TESTS="smoke/test_certauthority_root"
+
- TESTS="smoke/test_accounts
smoke/test_affinity_groups
smoke/test_affinity_groups_projects
- smoke/test_certauthority_root
smoke/test_deploy_vgpu_enabled_vm
smoke/test_deploy_vm_iso
smoke/test_deploy_vm_root_resize
diff --git a/api/src/main/java/com/cloud/alert/Alert.java b/api/src/main/java/com/cloud/alert/Alert.java
index f774420..d85dca5 100644
--- a/api/src/main/java/com/cloud/alert/Alert.java
+++ b/api/src/main/java/com/cloud/alert/Alert.java
@@ -41,4 +41,6 @@ public interface Alert extends Identity, InternalIdentity {
boolean getArchived();
String getName();
+
+ String getContent();
}
diff --git a/api/src/main/java/com/cloud/resource/ResourceService.java b/api/src/main/java/com/cloud/resource/ResourceService.java
index 854b535..7082308 100644
--- a/api/src/main/java/com/cloud/resource/ResourceService.java
+++ b/api/src/main/java/com/cloud/resource/ResourceService.java
@@ -18,7 +18,6 @@ package com.cloud.resource;
import java.util.List;
-import com.cloud.dc.DataCenter;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
@@ -29,6 +28,8 @@ import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
+import com.cloud.dc.DataCenter;
+import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceInUseException;
@@ -41,25 +42,17 @@ public interface ResourceService {
/**
* Updates a host
*
- * @param cmd
- * - the command specifying hostId
- * @return hostObject
- * @throws NoTransitionException
+ * @param cmd - the command specifying hostId
*/
Host updateHost(UpdateHostCmd cmd) throws NoTransitionException;
Host cancelMaintenance(CancelMaintenanceCmd cmd);
- Host reconnectHost(ReconnectHostCmd cmd);
+ Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException;
/**
* We will automatically create an Apache CloudStack cluster to attach to the external cluster and return a hyper host to perform
* host related operation within the cluster
- *
- * @param cmd
- * @return
- * @throws IllegalArgumentException
- * @throws DiscoveryException
*/
List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
@@ -75,12 +68,6 @@ public interface ResourceService {
/**
* Deletes a host
- *
- * @param hostId
- * TODO
- * @param isForced
- * TODO
- *
* @param true if deleted, false otherwise
*/
boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage);
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
index 5e15637..34e439f 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
@@ -16,8 +16,6 @@
// under the License.
package org.apache.cloudstack.api.command.admin.host;
-import org.apache.log4j.Logger;
-
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
@@ -27,13 +25,16 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.Host;
import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
-@APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class,
- requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+@APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class ReconnectHostCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName());
@@ -101,16 +102,15 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
public void execute() {
try {
Host result = _resourceService.reconnectHost(this);
- if (result != null) {
- HostResponse response = _responseGenerator.createHostResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reconnect host");
- }
- } catch (Exception ex) {
- s_logger.warn("Exception: ", ex);
- throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+ HostResponse response = _responseGenerator.createHostResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } catch (InvalidParameterValueException e) {
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
+ } catch (CloudRuntimeException e) {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
+ } catch (AgentUnavailableException e) {
+ throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, e.getMessage());
}
}
}
diff --git a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java
index 933c3ea..c51970c 100644
--- a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java
+++ b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java
@@ -36,7 +36,7 @@ import com.cloud.resource.ServerResource;
*/
public interface AgentManager {
static final ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return",
- true);
+ true);
public enum TapAgentsAction {
Add, Del, Contains,
@@ -143,7 +143,7 @@ public interface AgentManager {
public void pullAgentOutMaintenance(long hostId);
- boolean reconnect(long hostId);
+ void reconnect(long hostId) throws AgentUnavailableException;
void rescan();
diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
index b735775..4b80fb1 100644
--- a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
@@ -38,7 +38,6 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.ca.CAManager;
-import com.cloud.configuration.ManagementServiceConfiguration;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -75,6 +74,7 @@ import com.cloud.agent.api.UnsupportedAnswer;
import com.cloud.agent.transport.Request;
import com.cloud.agent.transport.Response;
import com.cloud.alert.AlertManager;
+import com.cloud.configuration.ManagementServiceConfiguration;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
@@ -122,7 +122,6 @@ import com.cloud.utils.time.InaccurateClock;
**/
public class AgentManagerImpl extends ManagerBase implements AgentManager, HandlerFactory, Configurable {
protected static final Logger s_logger = Logger.getLogger(AgentManagerImpl.class);
- protected static final Logger status_logger = Logger.getLogger(Status.class);
/**
* _agents is a ConcurrentHashMap, but it is used from within a synchronized block. This will be reported by findbugs as JLM_JSR166_UTILCONCURRENT_MONITORENTER. Maybe a
@@ -133,7 +132,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
protected List<Pair<Integer, Listener>> _cmdMonitors = new ArrayList<Pair<Integer, Listener>>(17);
protected List<Pair<Integer, StartupCommandProcessor>> _creationMonitors = new ArrayList<Pair<Integer, StartupCommandProcessor>>(17);
protected List<Long> _loadingAgents = new ArrayList<Long>();
- protected int _monitorId = 0;
+ private int _monitorId = 0;
private final Lock _agentStatusLock = new ReentrantLock();
@Inject
@@ -180,28 +179,22 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Inject
ResourceManager _resourceMgr;
-
@Inject
ManagementServiceConfiguration mgmtServiceConf;
protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5",
- "Number of worker threads handling remote agent connections.", false);
+ "Number of worker threads handling remote agent connections.", false);
protected final ConfigKey<Integer> Port = new ConfigKey<Integer>("Advanced", Integer.class, "port", "8250", "Port to listen on for remote agent connections.", false);
protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800",
- "Seconds to wait before alerting on a disconnected agent", true);
+ "Seconds to wait before alerting on a disconnected agent", true);
protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16",
- "The number of direct agents to load each time", false);
+ "The number of direct agents to load each time", false);
protected final ConfigKey<Integer> DirectAgentPoolSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.pool.size", "500",
- "Default size for DirectAgentPool", false);
+ "Default size for DirectAgentPool", false);
protected final ConfigKey<Float> DirectAgentThreadCap = new ConfigKey<Float>("Advanced", Float.class, "direct.agent.thread.cap", "1",
- "Percentage (as a value between 0 and 1) of direct.agent.pool.size to be used as upper thread cap for a single direct agent to process requests", false);
- protected final ConfigKey<Boolean> CheckTxnBeforeSending = new ConfigKey<Boolean>(
- "Developer",
- Boolean.class,
- "check.txn.before.sending.agent.commands",
- "false",
- "This parameter allows developers to enable a check to see if a transaction wraps commands that are sent to the resource. This is not to be enabled on production systems.",
- true);
+ "Percentage (as a value between 0 and 1) of direct.agent.pool.size to be used as upper thread cap for a single direct agent to process requests", false);
+ protected final ConfigKey<Boolean> CheckTxnBeforeSending = new ConfigKey<Boolean>("Developer", Boolean.class, "check.txn.before.sending.agent.commands", "false",
+ "This parameter allows developers to enable a check to see if a transaction wraps commands that are sent to the resource. This is not to be enabled on production systems.", true);
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
@@ -241,7 +234,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
return true;
}
-
@Override
public Task create(final Task.Type type, final Link link, final byte[] data) {
return new AgentHandler(type, link, data);
@@ -436,8 +428,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
if (CheckTxnBeforeSending.value()) {
if (!noDbTxn()) {
throw new CloudRuntimeException("We do not allow transactions to be wrapped around commands sent to be executed on remote agents. "
- + "We cannot predict how long it takes a command to complete. "
- + "The transaction may be rolled back because the connection took too long.");
+ + "We cannot predict how long it takes a command to complete. " + "The transaction may be rolled back because the connection took too long.");
}
} else {
assert noDbTxn() : "I know, I know. Why are we so strict as to not allow txn across an agent call? ... Why are we so cruel ... Why are we such a dictator .... Too bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!";
@@ -564,15 +555,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
monitor.second().processConnect(host, cmd[i], forRebalance);
} catch (final Exception e) {
if (e instanceof ConnectionException) {
- final ConnectionException ce = (ConnectionException) e;
+ final ConnectionException ce = (ConnectionException)e;
if (ce.isSetupError()) {
- s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId +
- " due to " + e.getMessage());
+ s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw ce;
} else {
- s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId +
- " due to " + e.getMessage());
+ s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
return attache;
}
@@ -580,8 +569,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
} else {
- s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId +
- " due to " + e.getMessage(), e);
+ s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
}
@@ -634,7 +622,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
try {
final Class<?> clazz = Class.forName(resourceName);
final Constructor<?> constructor = clazz.getConstructor();
- resource = (ServerResource) constructor.newInstance();
+ resource = (ServerResource)constructor.newInstance();
} catch (final ClassNotFoundException e) {
s_logger.warn("Unable to find class " + host.getResource(), e);
} catch (final InstantiationException e) {
@@ -888,7 +876,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host disconnected, " + hostDesc,
- "If the agent for host [" + hostDesc + "] is not restarted within " + AlertWait + " seconds, host will go to Alert state");
+ "If the agent for host [" + hostDesc + "] is not restarted within " + AlertWait + " seconds, host will go to Alert state");
}
event = Status.Event.AgentDisconnected;
}
@@ -899,7 +887,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
final String podName = podVO != null ? podVO.getName() : "NO POD";
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podName;
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host in ALERT state, " + hostDesc,
- "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName());
+ "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName());
}
} else {
s_logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened");
@@ -987,33 +975,30 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
@Override
- public boolean reconnect(final long hostId) {
- HostVO host;
+ public void reconnect(final long hostId) throws AgentUnavailableException {
+ HostVO host = _hostDao.findById(hostId);
+ if (host == null) {
+ throw new CloudRuntimeException("Unable to find host: " + hostId);
+ }
- host = _hostDao.findById(hostId);
- if (host == null || host.getRemoved() != null) {
- s_logger.warn("Unable to find host " + hostId);
- return false;
+ if (host.getRemoved() != null) {
+ throw new CloudRuntimeException("Host has already been removed: " + hostId);
}
if (host.getStatus() == Status.Disconnected) {
- s_logger.info("Host is already disconnected, no work to be done");
- return true;
+ s_logger.debug("Host is already disconnected, no work to be done: " + hostId);
+ return;
}
if (host.getStatus() != Status.Up && host.getStatus() != Status.Alert && host.getStatus() != Status.Rebalancing) {
- s_logger.info("Unable to disconnect host because it is not in the correct state: host=" + hostId + "; Status=" + host.getStatus());
- return false;
+ throw new CloudRuntimeException("Unable to disconnect host because it is not in the correct state: host=" + hostId + "; Status=" + host.getStatus());
}
- final AgentAttache attache = findAttache(hostId);
+ AgentAttache attache = findAttache(hostId);
if (attache == null) {
- s_logger.info("Unable to disconnect host because it is not connected to this server: " + hostId);
- return false;
+ throw new CloudRuntimeException("Unable to disconnect host because it is not connected to this server: " + hostId);
}
-
disconnectWithoutInvestigation(attache, Event.ShutdownRequested);
- return true;
}
@Override
@@ -1049,8 +1034,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
}
return true;
- } else if (event == Event.ShutdownRequested) {
- return reconnect(hostId);
+ }
+ if (event == Event.ShutdownRequested) {
+ try {
+ reconnect(hostId);
+ } catch (CloudRuntimeException e) {
+ s_logger.debug("Error on shutdown request for hostID: " + hostId, e);
+ return false;
+ }
+ return true;
}
return false;
}
@@ -1166,7 +1158,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
_request.logD("Processing the first command ");
final StartupCommand[] startups = new StartupCommand[_cmds.length];
for (int i = 0; i < _cmds.length; i++) {
- startups[i] = (StartupCommand) _cmds[i];
+ startups[i] = (StartupCommand)_cmds[i];
}
final AgentAttache attache = handleConnectedAgent(_link, startups, _request);
@@ -1184,7 +1176,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
for (int i = 0; i < cmds.length; i++) {
cmd = cmds[i];
if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand ||
- cmd instanceof StartupStorageCommand) {
+ cmd instanceof StartupStorageCommand) {
answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, mgmtServiceConf.getPingInterval());
break;
}
@@ -1205,7 +1197,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
protected void processRequest(final Link link, final Request request) {
- final AgentAttache attache = (AgentAttache) link.attachment();
+ final AgentAttache attache = (AgentAttache)link.attachment();
final Command[] cmds = request.getCommands();
Command cmd = cmds[0];
boolean logD = true;
@@ -1256,10 +1248,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
final StartupStorageCommand startup = (StartupStorageCommand) cmd;
answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval());
} else if (cmd instanceof ShutdownCommand) {
- final ShutdownCommand shutdown = (ShutdownCommand) cmd;
+ final ShutdownCommand shutdown = (ShutdownCommand)cmd;
final String reason = shutdown.getReason();
- s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " +
- shutdown.getDetail());
+ s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + shutdown.getDetail());
if (reason.equals(ShutdownCommand.Update)) {
// disconnectWithoutInvestigation(attache, Event.UpdateNeeded);
throw new CloudRuntimeException("Agent update not implemented");
@@ -1268,16 +1259,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
return;
} else if (cmd instanceof AgentControlCommand) {
- answer = handleControlCommand(attache, (AgentControlCommand) cmd);
+ answer = handleControlCommand(attache, (AgentControlCommand)cmd);
} else {
- handleCommands(attache, request.getSequence(), new Command[] { cmd });
+ handleCommands(attache, request.getSequence(), new Command[] {cmd});
if (cmd instanceof PingCommand) {
- final long cmdHostId = ((PingCommand) cmd).getHostId();
+ final long cmdHostId = ((PingCommand)cmd).getHostId();
// if the router is sending a ping, verify the
// gateway was pingable
if (cmd instanceof PingRoutingCommand) {
- final boolean gatewayAccessible = ((PingRoutingCommand) cmd).isGatewayAccessible();
+ final boolean gatewayAccessible = ((PingRoutingCommand)cmd).isGatewayAccessible();
final HostVO host = _hostDao.findById(Long.valueOf(cmdHostId));
if (host != null) {
@@ -1286,22 +1277,18 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
// gateway (cannot ping the default route)
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
final HostPodVO podVO = _podDao.findById(host.getPodId());
- final String hostDesc =
- "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: "
- + podVO.getName();
+ final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
- _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(),
- "Host lost connection to gateway, " + hostDesc, "Host [" + hostDesc +
- "] lost connection to gateway (default route) and is possibly having network connection issues.");
+ _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + hostDesc,
+ "Host [" + hostDesc + "] lost connection to gateway (default route) and is possibly having network connection issues.");
} else {
_alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId());
}
} else {
- s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId +
- "; can't find the host in the DB");
+ s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId + "; can't find the host in the DB");
}
}
- answer = new PingAnswer((PingCommand) cmd);
+ answer = new PingAnswer((PingCommand)cmd);
} else if (cmd instanceof ReadyAnswer) {
final HostVO host = _hostDao.findById(attache.getId());
if (host == null) {
@@ -1337,7 +1324,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
protected void processResponse(final Link link, final Response response) {
- final AgentAttache attache = (AgentAttache) link.attachment();
+ final AgentAttache attache = (AgentAttache)link.attachment();
if (attache == null) {
s_logger.warn("Unable to process: " + response);
} else if (!attache.processAnswers(response.getSequence(), response)) {
@@ -1355,7 +1342,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
try {
final Request event = Request.parse(data);
if (event instanceof Response) {
- processResponse(task.getLink(), (Response) event);
+ processResponse(task.getLink(), (Response)event);
} else {
processRequest(task.getLink(), event);
}
@@ -1370,7 +1357,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} else if (type == Task.Type.CONNECT) {
} else if (type == Task.Type.DISCONNECT) {
final Link link = task.getLink();
- final AgentAttache attache = (AgentAttache) link.attachment();
+ final AgentAttache attache = (AgentAttache)link.attachment();
if (attache != null) {
disconnectWithInvestigation(attache, Event.AgentDisconnected);
} else {
@@ -1411,23 +1398,21 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
public boolean agentStatusTransitTo(final HostVO host, final Status.Event e, final long msId) {
try {
_agentStatusLock.lock();
- if (status_logger.isDebugEnabled()) {
+ if (s_logger.isDebugEnabled()) {
final ResourceState state = host.getResourceState();
final StringBuilder msg = new StringBuilder("Transition:");
msg.append("[Resource state = ").append(state);
msg.append(", Agent event = ").append(e.toString());
msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]");
- status_logger.debug(msg);
+ s_logger.debug(msg);
}
host.setManagementServerId(msId);
try {
return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao);
} catch (final NoTransitionException e1) {
- status_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() +
- ", mangement server id is " + msId);
- throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," +
- e1.getMessage());
+ s_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", mangement server id is " + msId);
+ throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," + e1.getMessage());
}
} finally {
_agentStatusLock.unlock();
@@ -1491,6 +1476,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
}
+ @Override
public void disconnectWithInvestigation(final long hostId, final Status.Event event) {
disconnectInternal(hostId, event, true);
}
@@ -1501,8 +1487,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
@Override
- public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource,
- final boolean forRebalance, boolean newHost) throws ConnectionException {
+ public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, final boolean forRebalance, boolean newHost) throws ConnectionException {
AgentAttache attache;
attache = createAttacheForDirectConnect(host, resource);
@@ -1579,17 +1564,17 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
/*
* Host is in non-operation state, so no investigation and direct put agent to Disconnected
*/
- status_logger.debug("Ping timeout but agent " + agentId + " is in resource state of " + resourceState + ", so no investigation");
+ s_logger.debug("Ping timeout but agent " + agentId + " is in resource state of " + resourceState + ", so no investigation");
disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
} else {
final HostVO host = _hostDao.findById(agentId);
- if (host != null && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM
- || host.getType() == Host.Type.SecondaryStorageCmdExecutor)) {
+ if (host != null
+ && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM || host.getType() == Host.Type.SecondaryStorageCmdExecutor)) {
s_logger.warn("Disconnect agent for CPVM/SSVM due to physical connection close. host: " + host.getId());
disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
} else {
- status_logger.debug("Ping timeout for agent " + agentId + ", do invstigation");
+ s_logger.debug("Ping timeout for agent " + agentId + ", do invstigation");
disconnectWithInvestigation(agentId, Event.PingTimeout);
}
}
@@ -1605,8 +1590,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
final HostPodVO podVO = _podDao.findById(host.getPodId());
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
- _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc, "Host ["
- + hostDesc + "] is ready for maintenance");
+ _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc,
+ "Host [" + hostDesc + "] is ready for maintenance");
}
}
} catch (final Throwable th) {
@@ -1708,7 +1693,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize,
- DirectAgentThreadCap };
+ DirectAgentThreadCap };
}
protected class SetHostParamsListener implements Listener {
@@ -1738,20 +1723,20 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) {
- if (cmd instanceof StartupRoutingCommand) {
- if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) {
- Map<String, String> params = new HashMap<String, String>();
- params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
+ if (cmd instanceof StartupRoutingCommand) {
+ if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
- try {
- SetHostParamsCommand cmds = new SetHostParamsCommand(params);
- Commands c = new Commands(cmds);
- send(host.getId(), c, this);
- } catch (AgentUnavailableException e) {
- s_logger.debug("Failed to send host params on host: " + host.getId());
+ try {
+ SetHostParamsCommand cmds = new SetHostParamsCommand(params);
+ Commands c = new Commands(cmds);
+ send(host.getId(), c, this);
+ } catch (AgentUnavailableException e) {
+ s_logger.debug("Failed to send host params on host: " + host.getId());
+ }
}
}
- }
}
diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
index 7a9678e..38822cb 100644
--- a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
+++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
@@ -46,12 +46,12 @@ import org.apache.cloudstack.ca.CAManager;
import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.ha.dao.HAConfigDao;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
+import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import org.apache.cloudstack.utils.security.SSLUtils;
-import org.apache.cloudstack.ha.dao.HAConfigDao;
-import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@@ -134,14 +134,12 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
super();
}
- protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false",
- "Enable agent load balancing between management server nodes", true);
+ protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false", "Enable agent load balancing between management server nodes", true);
protected final ConfigKey<Double> ConnectedAgentThreshold = new ConfigKey<Double>(Double.class, "agent.load.threshold", "Advanced", "0.7",
"What percentage of the agents can be held by one management server before load balancing happens", true);
- protected final ConfigKey<Integer> LoadSize = new ConfigKey<Integer>(Integer.class, "direct.agent.load.size", "Advanced", "16",
- "How many agents to connect to in each round", true);
- protected final ConfigKey<Integer> ScanInterval = new ConfigKey<Integer>(Integer.class, "direct.agent.scan.interval", "Advanced", "90",
- "Interval between scans to load agents", false, ConfigKey.Scope.Global, 1000);
+ protected final ConfigKey<Integer> LoadSize = new ConfigKey<Integer>(Integer.class, "direct.agent.load.size", "Advanced", "16", "How many agents to connect to in each round", true);
+ protected final ConfigKey<Integer> ScanInterval = new ConfigKey<Integer>(Integer.class, "direct.agent.scan.interval", "Advanced", "90", "Interval between scans to load agents", false,
+ ConfigKey.Scope.Global, 1000);
@Override
public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException {
@@ -342,8 +340,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
final HostTransferMapVO transferVO = _hostTransferDao.findById(hostId);
if (transferVO != null) {
if (transferVO.getFutureOwner() == _nodeId && transferVO.getState() == HostTransferState.TransferStarted) {
- s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " +
- _nodeId);
+ s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " + _nodeId);
return true;
}
}
@@ -352,8 +349,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
// don't process disconnect if the disconnect came for the host via delayed cluster notification,
// but the host has already reconnected to the current management server
if (!attache.forForward()) {
- s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId +
- " as the host is directly connected to the current management server " + _nodeId);
+ s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is directly connected to the current management server " + _nodeId);
return true;
}
@@ -367,19 +363,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
@Override
- public boolean reconnect(final long hostId) {
- Boolean result;
- try {
- result = propagateAgentEvent(hostId, Event.ShutdownRequested);
- if (result != null) {
- return result;
- }
- } catch (final AgentUnavailableException e) {
- s_logger.debug("cannot propagate agent reconnect because agent is not available", e);
- return false;
- }
+ public void reconnect(final long hostId) throws CloudRuntimeException, AgentUnavailableException {
+ Boolean result = propagateAgentEvent(hostId, Event.ShutdownRequested);
+ if (result == null) {
+ super.reconnect(hostId);
- return super.reconnect(hostId);
+ }
+ if (!result) {
+ throw new CloudRuntimeException("Failed to propagating agent change request event:" + Event.ShutdownRequested + " to host:" + hostId);
+ }
}
public void notifyNodesInCluster(final AgentAttache attache) {
@@ -398,18 +390,18 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
protected static void logT(final byte[] bytes, final String msg) {
- s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
- (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+ s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
+ + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
}
protected static void logD(final byte[] bytes, final String msg) {
- s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
- (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+ s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
+ + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
}
protected static void logI(final byte[] bytes, final String msg) {
- s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
- (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+ s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
+ + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
}
public boolean routeToPeer(final String peer, final byte[] bytes) {
@@ -443,8 +435,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
logI(bytes, "Unable to route to peer: " + Request.parse(bytes).toString() + " due to " + e.getMessage());
} catch (ClassNotFoundException | UnsupportedVersionException ex) {
// Request.parse thrown exception when we try to log it, log as much as we can
- logI(bytes, "Unable to route to peer due to" + e.getMessage()
- + ". Also caught exception when parsing request: " + ex.getMessage());
+ logI(bytes, "Unable to route to peer due to" + e.getMessage() + ". Also caught exception when parsing request: " + ex.getMessage());
}
}
}
@@ -489,8 +480,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
try {
prevCh.close();
} catch (final Exception e) {
- s_logger.info("[ignored]"
- + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
+ s_logger.info("[ignored]" + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
}
}
if (ch == null || ch == prevCh) {
@@ -597,7 +587,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.info("Closing: " + ch.toString());
ch.close();
} catch (final IOException e) {
- s_logger.info("[ignored] error on closing channel: " +ch.toString(), e);
+ s_logger.info("[ignored] error on closing channel: " + ch.toString(), e);
}
}
}
@@ -770,8 +760,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
@Override
- public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException,
- OperationTimedoutException {
+ public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException, OperationTimedoutException {
boolean result = false;
if (event == Event.RequestAgentRebalance) {
return setToWaitForRebalance(agentId, currentOwnerId, futureOwnerId);
@@ -837,8 +826,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
avLoad = allManagedAgents.size() / allMS.size();
} else {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() +
- "; number of managed agents is " + allManagedAgents.size());
+ s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() + "; number of managed agents is "
+ + allManagedAgents.size());
}
return;
}
@@ -991,8 +980,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
// remove the host from re-balance list and delete from op_host_transfer DB
// no need to do anything with the real attache as we haven't modified it yet
final Date cutTime = DateUtil.currentGMTTime();
- final HostTransferMapVO transferMap =
- _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
+ final HostTransferMapVO transferMap = _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
if (transferMap == null) {
s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host");
@@ -1010,8 +998,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
final ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner());
if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
- s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms +
- ", skipping rebalance for the host");
+ s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host");
iterator.remove();
_hostTransferDao.completeAgentTransfer(hostId);
continue;
@@ -1027,8 +1014,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
} else {
- s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() +
- " and listener queue size is " + attache.getNonRecurringListenersSize());
+ s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is "
+ + attache.getNonRecurringListenersSize());
}
}
} else {
@@ -1094,8 +1081,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (result) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
- " as a part of rebalance process");
+ s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
}
result = loadDirectlyConnectedHost(host, true);
} else {
@@ -1103,17 +1089,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
} catch (final Exception ex) {
- s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
- " as a part of rebalance process due to:", ex);
+ s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process due to:",
+ ex);
result = false;
}
if (result) {
- s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
- " as a part of rebalance process");
+ s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
} else {
- s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
- " as a part of rebalance process");
+ s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
}
}
@@ -1144,8 +1128,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
// 2) Get all transfer requests and route them to peer
Request requestToTransfer = forwardAttache.getRequestToTransfer();
while (requestToTransfer != null) {
- s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " +
- _nodeId + " to " + futureOwnerId);
+ s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + _nodeId + " to " + futureOwnerId);
final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes());
if (!routeResult) {
logD(requestToTransfer.getBytes(), "Failed to route request to peer");
@@ -1198,8 +1181,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (attache == null) {
s_logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing");
} else {
- s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " +
- attache.getNonRecurringListenersSize() + ", can't start host rebalancing");
+ s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " + attache.getNonRecurringListenersSize()
+ + ", can't start host rebalancing");
}
return false;
}
@@ -1255,8 +1238,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} catch (final Exception e) {
// Scheduling host scan task in peer MS is a best effort operation during host add, regular host scan
// happens at fixed intervals anyways. So handling any exceptions that may be thrown
- s_logger.warn("Exception happened while trying to schedule host scan task on mgmt server " + _clusterMgr.getSelfPeerName() +
- ", ignoring as regular host scan happens at fixed interval anyways", e);
+ s_logger.warn(
+ "Exception happened while trying to schedule host scan task on mgmt server " + _clusterMgr.getSelfPeerName() + ", ignoring as regular host scan happens at fixed interval anyways",
+ e);
return null;
}
@@ -1372,15 +1356,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
final String jsonReturn = _gson.toJson(answers);
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " +
- (System.currentTimeMillis() - startTick) + " ms, return result: " + jsonReturn);
+ s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return result: "
+ + jsonReturn);
}
return jsonReturn;
} else {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " +
- (System.currentTimeMillis() - startTick) + " ms, return null result");
+ s_logger.debug(
+ "Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return null result");
}
}
} catch (final AgentUnavailableException e) {
diff --git a/engine/schema/src/main/java/com/cloud/alert/AlertVO.java b/engine/schema/src/main/java/com/cloud/alert/AlertVO.java
index 70ef469..1f2cd9d 100644
--- a/engine/schema/src/main/java/com/cloud/alert/AlertVO.java
+++ b/engine/schema/src/main/java/com/cloud/alert/AlertVO.java
@@ -53,6 +53,9 @@ public class AlertVO implements Alert {
@Column(name = "subject", length = 999)
private String subject;
+ @Column(name = "content", length = 5000)
+ private String content;
+
@Column(name = "sent_count")
private int sentCount = 0;
@@ -191,4 +194,13 @@ public class AlertVO implements Alert {
public void setName(String name) {
this.name = name;
}
+
+ @Override
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
}
diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
index e48bfd5..5af099d 100644
--- a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
@@ -80,7 +80,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join host_tags on host.id = host_tags.host_id and host_tags.tag = ?";
-
protected SearchBuilder<HostVO> TypePodDcStatusSearch;
protected SearchBuilder<HostVO> IdStatusSearch;
diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41000to41100-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-41000to41100-cleanup.sql
index d7a080e..f8d9ce9 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41000to41100-cleanup.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41000to41100-cleanup.sql
@@ -66,4 +66,4 @@ CREATE VIEW `cloud`.`user_view` AS
left join
`cloud`.`async_job` ON async_job.instance_id = user.id
and async_job.instance_type = 'User'
- and async_job.job_status = 0;
+ and async_job.job_status = 0;
\ No newline at end of file
diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41000to41100.sql b/engine/schema/src/main/resources/META-INF/db/schema-41000to41100.sql
index 2e7f9e9..70a76d9 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41000to41100.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41000to41100.sql
@@ -566,4 +566,4 @@ CREATE TABLE IF NOT EXISTS `cloud`.`external_netscaler_controlcenter` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `cloud`.`sslcerts` ADD COLUMN `name` varchar(255) NULL default NULL COMMENT 'Name of the Certificate';
-ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `service_package_id` varchar(255) NULL default NULL COMMENT 'Netscaler ControlCenter Service Package';
+ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `service_package_id` varchar(255) NULL default NULL COMMENT 'Netscaler ControlCenter Service Package';
\ No newline at end of file
diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41100to41200.sql b/engine/schema/src/main/resources/META-INF/db/schema-41100to41200.sql
index 5667c5b..97bd5ae 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41100to41200.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41100to41200.sql
@@ -20,4 +20,7 @@
--;
-- [CLOUDSTACK-10314] Add reason column to ACL rule table
-ALTER TABLE `cloud`.`network_acl_item` ADD COLUMN `reason` VARCHAR(2500) AFTER `display`;
\ No newline at end of file
+ALTER TABLE `cloud`.`network_acl_item` ADD COLUMN `reason` VARCHAR(2500) AFTER `display`;
+
+--[CLOUDSTACK-9846] Make provision to store content and subject for Alerts in separate columns.
+ALTER TABLE `cloud`.`alert` ADD COLUMN `content` VARCHAR(5000);
diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
index 30cba4d..c6003af 100644
--- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
+++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
@@ -266,20 +266,16 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
}
@Override
- public boolean reconnect(long hostId) {
- // TODO Auto-generated method stub
- return false;
+ public void reconnect(long hostId) {
}
@Override
public boolean isAgentAttached(long hostId) {
- // TODO Auto-generated method stub
return false;
}
@Override
public boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance, boolean newHost) throws ConnectionException {
- // TODO Auto-generated method stub
return false;
}
diff --git a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/element/NetscalerElement.java
index 38a836d..1df1640 100644
--- a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/element/NetscalerElement.java
+++ b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/element/NetscalerElement.java
@@ -28,12 +28,6 @@ import java.util.UUID;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import com.google.gson.Gson;
-
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
@@ -41,6 +35,9 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationSe
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.cloudstack.region.gslb.GslbServiceProvider;
+import org.apache.log4j.Logger;
+import org.json.JSONException;
+import org.json.JSONObject;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
@@ -84,6 +81,7 @@ import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;
+import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientNetworkCapacityException;
@@ -154,10 +152,11 @@ import com.cloud.utils.net.UrlUtil;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile;
+import com.google.gson.Gson;
public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
- implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager,
- IpDeployer, StaticNatServiceProvider, GslbServiceProvider {
+implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager,
+IpDeployer, StaticNatServiceProvider, GslbServiceProvider {
private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
public static final AutoScaleCounterType AutoScaleCounterSnmp = new AutoScaleCounterType("snmp");
@@ -218,7 +217,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced
&& (config.getGuestType() == Network.GuestType.Isolated
- || config.getGuestType() == Network.GuestType.Shared)
+ || config.getGuestType() == Network.GuestType.Shared)
&& config.getTrafficType() == TrafficType.Guest);
boolean handleInBasicZone = (zone.getNetworkType() == NetworkType.Basic
&& config.getGuestType() == Network.GuestType.Shared && config.getTrafficType() == TrafficType.Guest);
@@ -242,7 +241,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@Override
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest,
ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
- InsufficientNetworkCapacityException {
+ InsufficientNetworkCapacityException {
if (!canHandle(guestConfig, Service.Lb)) {
return false;
@@ -271,7 +270,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
throw new ResourceUnavailableException(
"There are no NetScaler load balancer devices with the free capacity for implementing this network : "
+ e.getMessage(),
- DataCenter.class, guestConfig.getDataCenterId());
+ DataCenter.class, guestConfig.getDataCenterId());
}
}
@@ -286,7 +285,6 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
Map<String, String> _configs;
List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll();
HostVO hostVO = null;
- Map<String, Object> params;
if (ncc.size() > 0) {
NetScalerControlCenterVO nccVO = ncc.get(0);
String ipAddress = nccVO.getNccip();
@@ -414,7 +412,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@Override
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest,
ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException,
- ResourceUnavailableException {
+ ResourceUnavailableException {
return true;
}
@@ -593,45 +591,45 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
boolean dedicatedUse = (configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null)
? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
- if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
- String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
- s_logger.debug(msg);
- throw new InvalidParameterValueException(msg);
- }
+ if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
+ String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
+ s_logger.debug(msg);
+ throw new InvalidParameterValueException(msg);
+ }
- if (cmd.isGslbProvider()) {
+ if (cmd.isGslbProvider()) {
- if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())
- && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
- String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
- s_logger.debug(msg);
- throw new InvalidParameterValueException(msg);
- }
+ if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())
+ && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
+ String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
+ s_logger.debug(msg);
+ throw new InvalidParameterValueException(msg);
+ }
- if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
- String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
- s_logger.debug(msg);
- throw new InvalidParameterValueException(msg);
- }
+ if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
+ String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
+ s_logger.debug(msg);
+ throw new InvalidParameterValueException(msg);
+ }
- if (dedicatedUse) {
- throw new InvalidParameterValueException(
- "NetScaler provisioned to be GSLB service provider can only be configured for shared usage.");
- }
+ if (dedicatedUse) {
+ throw new InvalidParameterValueException(
+ "NetScaler provisioned to be GSLB service provider can only be configured for shared usage.");
+ }
- }
+ }
- if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) {
- throw new InvalidParameterValueException(
- "NetScaler can be provisioned to be exclusive GSLB service provider"
- + " only if its being configured as GSLB service provider also.");
- }
+ if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) {
+ throw new InvalidParameterValueException(
+ "NetScaler can be provisioned to be exclusive GSLB service provider"
+ + " only if its being configured as GSLB service provider also.");
+ }
- ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(),
- cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(),
- cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp());
+ ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(),
+ cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(),
+ cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp());
- return lbDeviceVO;
+ return lbDeviceVO;
}
@Override
@@ -759,7 +757,11 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
});
HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
- _agentMgr.reconnect(host.getId());
+ try {
+ _agentMgr.reconnect(host.getId());
+ } catch (AgentUnavailableException e) {
+ s_logger.warn("failed to reconnect host " + host, e);
+ }
return lbDeviceVo;
}
@@ -858,8 +860,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
boolean flag=false;
try {
result = _netscalerServicePackageDao.findByUuid(cmd.getId());
- if (result == null)
+ if (result == null) {
throw new CloudRuntimeException("Record does not Exists in the Table");
+ }
if(_networkOfferingDao.isUsingServicePackage(result.getUuid()))
{
@@ -869,10 +872,11 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
flag = _netscalerServicePackageDao.remove(result.getId());
} catch (Exception e) {
- if (e instanceof InvalidParameterValueException)
+ if (e instanceof InvalidParameterValueException) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
- else
- throw e;
+ } else {
+ throw e;
+ }
}
return flag;
@@ -884,18 +888,19 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) throws CloudRuntimeException {
NetScalerControlCenterVO result = _netscalerControlCenterDao.findByUuid(cmd.getId());
- if (result == null)
+ if (result == null) {
throw new CloudRuntimeException("External Netscaler Control Center Table does not contain record with this ID");
- else {
+ } else {
//ID list of Network Offering which are not removed and have service Package Uuid field not null.
List<Long> servicePackageId_list = _networkOfferingDao.listNetworkOfferingID();
if (servicePackageId_list.size() != 0) {
//VO list of Networks which are using Network Offering.
List<NetworkVO> networkVO_list = _networkDao.listNetworkVO(servicePackageId_list);
- if (networkVO_list != null && networkVO_list.size() != 0)
+ if (networkVO_list != null && networkVO_list.size() != 0) {
throw new CloudRuntimeException(
"ServicePackages published by NetScalerControlCenter are being used by NetworkOfferings. Try deleting NetworkOffering with ServicePackages and then delete NetScalerControlCenter.");
+ }
}
}
try {
@@ -1466,8 +1471,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@DB
public NetScalerControlCenterVO registerNetscalerControlCenter(RegisterNetscalerControlCenterCmd cmd) {
- if (_netscalerControlCenterDao.listAll() != null && _netscalerControlCenterDao.listAll().size() != 0)
+ if (_netscalerControlCenterDao.listAll() != null && _netscalerControlCenterDao.listAll().size() != 0) {
throw new CloudRuntimeException("One Netscaler Control Center already exist in the DataBase. At a time only one Netscaler Control Center is allowed");
+ }
final RegisterNetscalerControlCenterCmd cmdinfo = cmd;
String ipAddress = cmd.getIpaddress();
@@ -1511,7 +1517,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
Long serviceOfferingId = cmd.getServiceOfferingId();
DeploymentPlan plan = new DataCenterDeployment(dest.getDataCenter().getId());
try {
- resp = _netScalerVMManager.deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId);
+ resp = _netScalerVMManager.deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId);
} catch (InsufficientCapacityException e) {
e.printStackTrace();
}
@@ -1520,7 +1526,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@Override
public VirtualRouter stopNetscalerServiceVm(Long id, boolean forced, Account callingAccount, long callingUserId) throws ConcurrentOperationException,
- ResourceUnavailableException {
+ ResourceUnavailableException {
return _netScalerVMManager.stopNetScalerVm(id, forced, callingAccount, callingUserId);
}
}
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 5f2551e..4485f5d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -21,5 +21,4 @@ cloudmonkey
# Marvin dependencies are installed via its bundle
# Install the SolidFire SDK for Python
-solidfire-sdk-python
-
+solidfire-sdk-python
\ No newline at end of file
diff --git a/server/src/main/java/com/cloud/alert/AlertManagerImpl.java b/server/src/main/java/com/cloud/alert/AlertManagerImpl.java
index a58a4f8..5a7a8b4 100644
--- a/server/src/main/java/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/main/java/com/cloud/alert/AlertManagerImpl.java
@@ -39,12 +39,6 @@ import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.naming.ConfigurationException;
-import org.apache.log4j.Logger;
-
-import com.sun.mail.smtp.SMTPMessage;
-import com.sun.mail.smtp.SMTPSSLTransport;
-import com.sun.mail.smtp.SMTPTransport;
-
import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
@@ -52,6 +46,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.log4j.Logger;
import com.cloud.alert.dao.AlertDao;
import com.cloud.api.ApiDBUtils;
@@ -85,10 +80,12 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.SearchCriteria;
+import com.sun.mail.smtp.SMTPMessage;
+import com.sun.mail.smtp.SMTPSSLTransport;
+import com.sun.mail.smtp.SMTPTransport;
public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable {
private static final Logger s_logger = Logger.getLogger(AlertManagerImpl.class.getName());
- private static final Logger s_alertsLogger = Logger.getLogger("org.apache.cloudstack.alerts");
private static final long INITIAL_CAPACITY_CHECK_DELAY = 30L * 1000L; // Thirty seconds expressed in milliseconds.
@@ -205,8 +202,9 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
String capacityCheckPeriodStr = configs.get("capacity.check.period");
if (capacityCheckPeriodStr != null) {
_capacityCheckPeriod = Long.parseLong(capacityCheckPeriodStr);
- if (_capacityCheckPeriod <= 0)
+ if (_capacityCheckPeriod <= 0) {
_capacityCheckPeriod = Long.parseLong(Config.CapacityCheckPeriod.getDefaultValue());
+ }
}
_timer = new Timer("CapacityChecker");
@@ -249,7 +247,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
if (_emailAlert != null) {
_emailAlert.sendAlert(alertType, dataCenterId, podId, null, subject, body);
} else {
- s_alertsLogger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " + podId +
+ s_logger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " + podId +
" | message:: " + subject + " | body:: " + body);
}
} catch (Exception ex) {
@@ -589,7 +587,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
alertType = AlertManager.AlertType.ALERT_TYPE_LOCAL_STORAGE;
break;
- //Pod Level
+ //Pod Level
case Capacity.CAPACITY_TYPE_PRIVATE_IP:
msgSubject = "System Alert: Number of unallocated private IPs is low in pod " + pod.getName() + " of availability zone " + dc.getName();
totalStr = Double.toString(totalCapacity);
@@ -598,7 +596,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
alertType = AlertManager.AlertType.ALERT_TYPE_PRIVATE_IP;
break;
- //Zone Level
+ //Zone Level
case Capacity.CAPACITY_TYPE_SECONDARY_STORAGE:
msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc.getName();
totalStr = formatBytesToMegabytes(totalCapacity);
@@ -746,22 +744,22 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
// TODO: make sure this handles SSL transport (useAuth is true) and regular
public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) throws MessagingException,
- UnsupportedEncodingException {
- s_alertsLogger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " +
+ UnsupportedEncodingException {
+ s_logger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " +
podId + " | clusterId:: " + clusterId + " | message:: " + subject);
AlertVO alert = null;
if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) &&
- (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) {
+ (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) &&
+ (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) {
alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId);
}
@@ -770,6 +768,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
AlertVO newAlert = new AlertVO();
newAlert.setType(alertType.getType());
newAlert.setSubject(subject);
+ newAlert.setContent(content);
newAlert.setClusterId(clusterId);
newAlert.setPodId(podId);
newAlert.setDataCenterId(dataCenterId);
diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
index 2966d41..1955436 100755
--- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
@@ -30,10 +30,6 @@ import java.util.Random;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
@@ -50,6 +46,9 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
@@ -75,7 +74,6 @@ import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ClusterManager;
import com.cloud.configuration.Config;
-import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterDetailsVO;
import com.cloud.dc.ClusterVO;
@@ -249,8 +247,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Inject
private VMTemplateDao _templateDao;
@Inject
- private ConfigurationManager _configMgr;
- @Inject
private ClusterVSMMapDao _clusterVSMMapDao;
private final long _nodeId = ManagementServerNode.getManagementServerId();
@@ -610,7 +606,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long clusterId, final String clusterName, String url, String username, String password,
final String hypervisorType, final List<String> hostTags, final Map<String, String> params, final boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException,
- InvalidParameterValueException {
+ InvalidParameterValueException {
URI uri = null;
// Check if the zone exists in the system
@@ -836,7 +832,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
// Get storage pool host mappings here because they can be removed as a
// part of handleDisconnect later
- // TODO: find out the bad boy, what's a buggy logic!
final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
final ResourceStateAdapter.DeleteHostAnswer answer =
@@ -1166,15 +1161,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
- public Host reconnectHost(final ReconnectHostCmd cmd) {
- final Long hostId = cmd.getId();
+ public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
+ Long hostId = cmd.getId();
- final HostVO host = _hostDao.findById(hostId);
+ HostVO host = _hostDao.findById(hostId);
if (host == null) {
throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist");
}
-
- return _agentMgr.reconnect(hostId) ? host : null;
+ _agentMgr.reconnect(hostId);
+ return host;
}
@Override
@@ -2310,7 +2305,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
} else if (event == ResourceState.Event.AdminCancelMaintenance) {
return doCancelMaintenance(hostId);
} else if (event == ResourceState.Event.DeleteHost) {
- /* TODO: Ask alex why we assume the last two parameters are false */
return doDeleteHost(hostId, false, false);
} else if (event == ResourceState.Event.Unmanaged) {
return doUmanageHost(hostId);
@@ -2329,7 +2323,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
if (host.getHypervisorType() == HypervisorType.KVM || host.getHypervisorType() == HypervisorType.LXC) {
- final MaintainAnswer answer = (MaintainAnswer)_agentMgr.easySend(hostId, new MaintainCommand());
+ _agentMgr.easySend(hostId, new MaintainCommand());
}
_agentMgr.disconnectWithoutInvestigation(hostId, Event.ShutdownRequested);
@@ -2379,10 +2373,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId());
for (final HostVO host : hosts) {
try {
- /*
- * FIXME: this is a buggy logic, check with alex. Shouldn't
- * return if propagation return non null
- */
final Boolean result = propagateResourceEvent(host.getId(), ResourceState.Event.UpdatePassword);
if (result != null) {
return result;
@@ -2852,11 +2842,4 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
return false;
}
}
-
- @Override
- public boolean start() {
- // TODO Auto-generated method stub
- return super.start();
- }
-
}
diff --git a/server/src/main/java/org/apache/cloudstack/ca/CAManagerImpl.java b/server/src/main/java/org/apache/cloudstack/ca/CAManagerImpl.java
index 3a90431..02e7a42 100644
--- a/server/src/main/java/org/apache/cloudstack/ca/CAManagerImpl.java
+++ b/server/src/main/java/org/apache/cloudstack/ca/CAManagerImpl.java
@@ -191,7 +191,8 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
if (Strings.isNullOrEmpty(csr)) {
return false;
}
- final Certificate certificate = issueCertificate(csr, Collections.singletonList(host.getName()), Arrays.asList(host.getPrivateIpAddress(), host.getPublicIpAddress(), host.getStorageIpAddress()), CAManager.CertValidityPeriod.value(), caProvider);
+ final Certificate certificate = issueCertificate(csr, Collections.singletonList(host.getName()),
+ Arrays.asList(host.getPrivateIpAddress(), host.getPublicIpAddress(), host.getStorageIpAddress()), CAManager.CertValidityPeriod.value(), caProvider);
return deployCertificate(host, certificate, reconnect, null);
} catch (final AgentUnavailableException | OperationTimedoutException e) {
LOG.error("Host/agent is not available or operation timed out, failed to setup keystore and generate CSR for host/agent id=" + host.getId() + ", due to: ", e);
@@ -206,18 +207,19 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
cmd.setAccessDetail(sshAccessDetails);
}
CallContext.current().setEventDetails("generating keystore and CSR for host id: " + host.getId());
- final SetupKeystoreAnswer answer = (SetupKeystoreAnswer) agentManager.send(host.getId(), cmd);
+ final SetupKeystoreAnswer answer = (SetupKeystoreAnswer)agentManager.send(host.getId(), cmd);
return answer.getCsr();
}
@Override
- public boolean deployCertificate(final Host host, final Certificate certificate, final Boolean reconnect, final Map<String, String> sshAccessDetails) throws AgentUnavailableException, OperationTimedoutException {
+ public boolean deployCertificate(final Host host, final Certificate certificate, final Boolean reconnect, final Map<String, String> sshAccessDetails)
+ throws AgentUnavailableException, OperationTimedoutException {
final SetupCertificateCommand cmd = new SetupCertificateCommand(certificate);
if (sshAccessDetails != null && !sshAccessDetails.isEmpty()) {
cmd.setAccessDetail(sshAccessDetails);
}
CallContext.current().setEventDetails("deploying certificate for host id: " + host.getId());
- final SetupCertificateAnswer answer = (SetupCertificateAnswer) agentManager.send(host.getId(), cmd);
+ final SetupCertificateAnswer answer = (SetupCertificateAnswer)agentManager.send(host.getId(), cmd);
if (answer.getResult()) {
CallContext.current().setEventDetails("successfully deployed certificate for host id: " + host.getId());
} else {
@@ -227,9 +229,12 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
if (answer.getResult()) {
getActiveCertificatesMap().put(host.getPrivateIpAddress(), certificate.getClientCertificate());
if (sshAccessDetails == null && reconnect != null && reconnect) {
- LOG.info(String.format("Successfully setup certificate on host, reconnecting with agent with id=%d, name=%s, address=%s",
- host.getId(), host.getName(), host.getPublicIpAddress()));
- return agentManager.reconnect(host.getId());
+ LOG.info(String.format("Successfully setup certificate on host, reconnecting with agent with id=%d, name=%s, address=%s", host.getId(), host.getName(), host.getPublicIpAddress()));
+ try {
+ agentManager.reconnect(host.getId());
+ } catch (AgentUnavailableException | CloudRuntimeException e) {
+ LOG.debug("Error when reconnecting to host: " + host.getUuid(), e);
+ }
}
return true;
}
@@ -257,8 +262,7 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
if (host == null) {
return;
}
- alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_CA_CERT,
- host.getDataCenterId(), host.getPodId(), subject, message);
+ alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_CA_CERT, host.getDataCenterId(), host.getPodId(), subject, message);
}
@Override
@@ -303,7 +307,7 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
}
final DateTime now = DateTime.now(DateTimeZone.UTC);
final Map<String, X509Certificate> certsMap = caManager.getActiveCertificatesMap();
- for (final Iterator<Map.Entry<String, X509Certificate>> it = certsMap.entrySet().iterator(); it.hasNext(); ) {
+ for (final Iterator<Map.Entry<String, X509Certificate>> it = certsMap.entrySet().iterator(); it.hasNext();) {
final Map.Entry<String, X509Certificate> entry = it.next();
if (entry == null) {
continue;
@@ -315,19 +319,14 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
continue;
}
final Host host = hostDao.findByIp(hostIp);
- if (host == null || host.getManagementServerId() == null ||
- host.getManagementServerId() != ManagementServerNode.getManagementServerId() ||
- host.getStatus() != Status.Up) {
- if (host == null ||
- (host.getManagementServerId() != null &&
- host.getManagementServerId() != ManagementServerNode.getManagementServerId())) {
+ if (host == null || host.getManagementServerId() == null || host.getManagementServerId() != ManagementServerNode.getManagementServerId() || host.getStatus() != Status.Up) {
+ if (host == null || (host.getManagementServerId() != null && host.getManagementServerId() != ManagementServerNode.getManagementServerId())) {
it.remove();
}
continue;
}
- final String hostDescription = String.format("host id=%d, uuid=%s, name=%s, ip=%s, zone id=%d",
- host.getId(), host.getUuid(), host.getName(), hostIp, host.getDataCenterId());
+ final String hostDescription = String.format("host id=%d, uuid=%s, name=%s, ip=%s, zone id=%d", host.getId(), host.getUuid(), host.getName(), hostIp, host.getDataCenterId());
try {
certificate.checkValidity(now.plusDays(CertExpiryAlertPeriod.valueIn(host.getClusterId())).toDate());
@@ -345,7 +344,8 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
} catch (final Throwable ex) {
LOG.warn("Failed to auto-renew certificate for " + hostDescription + ", with error=", ex);
caManager.sendAlert(host, "Certificate auto-renewal failed for " + hostDescription,
- String.format("Certificate is going to expire for %s. Auto-renewal failed to renew the certificate, please renew it manually. It is not valid after %s.", hostDescription, certificate.getNotAfter()));
+ String.format("Certificate is going to expire for %s. Auto-renewal failed to renew the certificate, please renew it manually. It is not valid after %s.",
+ hostDescription, certificate.getNotAfter()));
}
} else {
if (alertMap.containsKey(hostIp)) {
@@ -355,8 +355,7 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
}
}
caManager.sendAlert(host, "Certificate expiring soon for " + hostDescription,
- String.format("Certificate is going to expire for %s. Please renew it, it is not valid after %s.",
- hostDescription, certificate.getNotAfter()));
+ String.format("Certificate is going to expire for %s. Please renew it, it is not valid after %s.", hostDescription, certificate.getNotAfter()));
alertMap.put(hostIp, new Date());
}
}
@@ -427,14 +426,6 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
@Override
public ConfigKey<?>[] getConfigKeys() {
- return new ConfigKey<?>[]{
- CAProviderPlugin,
- CertKeySize,
- CertSignatureAlgorithm,
- CertValidityPeriod,
- AutomaticCertRenewal,
- CABackgroundJobDelay,
- CertExpiryAlertPeriod
- };
+ return new ConfigKey<?>[] {CAProviderPlugin, CertKeySize, CertSignatureAlgorithm, CertValidityPeriod, AutomaticCertRenewal, CABackgroundJobDelay, CertExpiryAlertPeriod};
}
}
diff --git a/server/src/test/java/org/apache/cloudstack/ca/CAManagerImplTest.java b/server/src/test/java/org/apache/cloudstack/ca/CAManagerImplTest.java
index 14ecc97..64cbf20 100644
--- a/server/src/test/java/org/apache/cloudstack/ca/CAManagerImplTest.java
+++ b/server/src/test/java/org/apache/cloudstack/ca/CAManagerImplTest.java
@@ -113,7 +113,7 @@ public class CAManagerImplTest {
final X509Certificate certificate = CertUtils.generateV3Certificate(null, keyPair, keyPair.getPublic(), "CN=ca", "SHA256withRSA", 365, null, null);
Mockito.when(caProvider.issueCertificate(Mockito.anyString(), Mockito.anyList(), Mockito.anyList(), Mockito.anyInt())).thenReturn(new Certificate(certificate, null, Collections.singletonList(certificate)));
Mockito.when(agentManager.send(Mockito.anyLong(), Mockito.any(SetupKeyStoreCommand.class))).thenReturn(new SetupKeystoreAnswer("someCsr"));
- Mockito.when(agentManager.reconnect(Mockito.anyLong())).thenReturn(true);
+ Mockito.doNothing().when(agentManager).reconnect(Mockito.anyLong());
Assert.assertTrue(caManager.provisionCertificate(host, true, null));
Mockito.verify(agentManager, Mockito.times(2)).send(Mockito.anyLong(), Mockito.any(Answer.class));
Mockito.verify(agentManager, Mockito.times(1)).reconnect(Mockito.anyLong());
--
To stop receiving notification emails like this one, please contact
rafael@apache.org.