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"
This commit is contained in:
Rafael Weingärtner 2018-03-14 15:27:43 -03:00 committed by GitHub
parent 989e4e29dc
commit 972b8b71d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 286 additions and 339 deletions

View File

@ -33,10 +33,11 @@ env:
- PATH=$HOME/.local/bin:$PATH - PATH=$HOME/.local/bin:$PATH
matrix: matrix:
# Keep the TESTS sorted by name and grouped by type # Keep the TESTS sorted by name and grouped by type
- TESTS="smoke/test_certauthority_root"
- TESTS="smoke/test_accounts - TESTS="smoke/test_accounts
smoke/test_affinity_groups smoke/test_affinity_groups
smoke/test_affinity_groups_projects smoke/test_affinity_groups_projects
smoke/test_certauthority_root
smoke/test_deploy_vgpu_enabled_vm smoke/test_deploy_vgpu_enabled_vm
smoke/test_deploy_vm_iso smoke/test_deploy_vm_iso
smoke/test_deploy_vm_root_resize smoke/test_deploy_vm_root_resize

View File

@ -41,4 +41,6 @@ public interface Alert extends Identity, InternalIdentity {
boolean getArchived(); boolean getArchived();
String getName(); String getName();
String getContent();
} }

View File

@ -18,7 +18,6 @@ package com.cloud.resource;
import java.util.List; 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.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
import org.apache.cloudstack.api.command.admin.host.AddHostCmd; 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.UpdateHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd; 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.DiscoveryException;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceInUseException;
@ -41,25 +42,17 @@ public interface ResourceService {
/** /**
* Updates a host * Updates a host
* *
* @param cmd * @param cmd - the command specifying hostId
* - the command specifying hostId
* @return hostObject
* @throws NoTransitionException
*/ */
Host updateHost(UpdateHostCmd cmd) throws NoTransitionException; Host updateHost(UpdateHostCmd cmd) throws NoTransitionException;
Host cancelMaintenance(CancelMaintenanceCmd cmd); 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 * 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 * host related operation within the cluster
*
* @param cmd
* @return
* @throws IllegalArgumentException
* @throws DiscoveryException
*/ */
List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException; List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
@ -75,12 +68,6 @@ public interface ResourceService {
/** /**
* Deletes a host * Deletes a host
*
* @param hostId
* TODO
* @param isForced
* TODO
*
* @param true if deleted, false otherwise * @param true if deleted, false otherwise
*/ */
boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage); boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage);

View File

@ -16,8 +16,6 @@
// under the License. // under the License.
package org.apache.cloudstack.api.command.admin.host; package org.apache.cloudstack.api.command.admin.host;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType; import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants; 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.ServerApiException;
import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes; import com.cloud.event.EventTypes;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.Host; import com.cloud.host.Host;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class, @APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class ReconnectHostCmd extends BaseAsyncCmd { public class ReconnectHostCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName()); public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName());
@ -101,16 +102,15 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
public void execute() { public void execute() {
try { try {
Host result = _resourceService.reconnectHost(this); Host result = _resourceService.reconnectHost(this);
if (result != null) { HostResponse response = _responseGenerator.createHostResponse(result);
HostResponse response = _responseGenerator.createHostResponse(result); response.setResponseName(getCommandName());
response.setResponseName(getCommandName()); this.setResponseObject(response);
this.setResponseObject(response); } catch (InvalidParameterValueException e) {
} else { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reconnect host"); } catch (CloudRuntimeException e) {
} throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (Exception ex) { } catch (AgentUnavailableException e) {
s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, e.getMessage());
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} }
} }
} }

View File

@ -36,7 +36,7 @@ import com.cloud.resource.ServerResource;
*/ */
public interface AgentManager { 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", 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 { public enum TapAgentsAction {
Add, Del, Contains, Add, Del, Contains,
@ -143,7 +143,7 @@ public interface AgentManager {
public void pullAgentOutMaintenance(long hostId); public void pullAgentOutMaintenance(long hostId);
boolean reconnect(long hostId); void reconnect(long hostId) throws AgentUnavailableException;
void rescan(); void rescan();

View File

@ -38,7 +38,6 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.cloudstack.ca.CAManager; import org.apache.cloudstack.ca.CAManager;
import com.cloud.configuration.ManagementServiceConfiguration;
import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; 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.Request;
import com.cloud.agent.transport.Response; import com.cloud.agent.transport.Response;
import com.cloud.alert.AlertManager; import com.cloud.alert.AlertManager;
import com.cloud.configuration.ManagementServiceConfiguration;
import com.cloud.dc.ClusterVO; import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
@ -122,7 +122,6 @@ import com.cloud.utils.time.InaccurateClock;
**/ **/
public class AgentManagerImpl extends ManagerBase implements AgentManager, HandlerFactory, Configurable { public class AgentManagerImpl extends ManagerBase implements AgentManager, HandlerFactory, Configurable {
protected static final Logger s_logger = Logger.getLogger(AgentManagerImpl.class); 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 * _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, Listener>> _cmdMonitors = new ArrayList<Pair<Integer, Listener>>(17);
protected List<Pair<Integer, StartupCommandProcessor>> _creationMonitors = new ArrayList<Pair<Integer, StartupCommandProcessor>>(17); protected List<Pair<Integer, StartupCommandProcessor>> _creationMonitors = new ArrayList<Pair<Integer, StartupCommandProcessor>>(17);
protected List<Long> _loadingAgents = new ArrayList<Long>(); protected List<Long> _loadingAgents = new ArrayList<Long>();
protected int _monitorId = 0; private int _monitorId = 0;
private final Lock _agentStatusLock = new ReentrantLock(); private final Lock _agentStatusLock = new ReentrantLock();
@Inject @Inject
@ -180,28 +179,22 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Inject @Inject
ResourceManager _resourceMgr; ResourceManager _resourceMgr;
@Inject @Inject
ManagementServiceConfiguration mgmtServiceConf; ManagementServiceConfiguration mgmtServiceConf;
protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5", 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> 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", 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", 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", 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", 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); "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>( protected final ConfigKey<Boolean> CheckTxnBeforeSending = new ConfigKey<Boolean>("Developer", Boolean.class, "check.txn.before.sending.agent.commands", "false",
"Developer", "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);
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 @Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { 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; return true;
} }
@Override @Override
public Task create(final Task.Type type, final Link link, final byte[] data) { public Task create(final Task.Type type, final Link link, final byte[] data) {
return new AgentHandler(type, link, data); return new AgentHandler(type, link, data);
@ -436,8 +428,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
if (CheckTxnBeforeSending.value()) { if (CheckTxnBeforeSending.value()) {
if (!noDbTxn()) { if (!noDbTxn()) {
throw new CloudRuntimeException("We do not allow transactions to be wrapped around commands sent to be executed on remote agents. " 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. " + "We cannot predict how long it takes a command to complete. " + "The transaction may be rolled back because the connection took too long.");
+ "The transaction may be rolled back because the connection took too long.");
} }
} else { } 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!"; 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); monitor.second().processConnect(host, cmd[i], forRebalance);
} catch (final Exception e) { } catch (final Exception e) {
if (e instanceof ConnectionException) { if (e instanceof ConnectionException) {
final ConnectionException ce = (ConnectionException) e; final ConnectionException ce = (ConnectionException)e;
if (ce.isSetupError()) { if (ce.isSetupError()) {
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
" due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true); handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw ce; throw ce;
} else { } else {
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
" due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true); handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
return attache; return attache;
} }
@ -580,8 +569,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true); handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e); throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
} else { } else {
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
" due to " + e.getMessage(), e);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true); handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e); throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
} }
@ -634,7 +622,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
try { try {
final Class<?> clazz = Class.forName(resourceName); final Class<?> clazz = Class.forName(resourceName);
final Constructor<?> constructor = clazz.getConstructor(); final Constructor<?> constructor = clazz.getConstructor();
resource = (ServerResource) constructor.newInstance(); resource = (ServerResource)constructor.newInstance();
} catch (final ClassNotFoundException e) { } catch (final ClassNotFoundException e) {
s_logger.warn("Unable to find class " + host.getResource(), e); s_logger.warn("Unable to find class " + host.getResource(), e);
} catch (final InstantiationException 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(); 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) { 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, _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; 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 podName = podVO != null ? podVO.getName() : "NO POD";
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podName; 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, _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 { } else {
s_logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened"); 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 @Override
public boolean reconnect(final long hostId) { public void reconnect(final long hostId) throws AgentUnavailableException {
HostVO host; HostVO host = _hostDao.findById(hostId);
if (host == null) {
throw new CloudRuntimeException("Unable to find host: " + hostId);
}
host = _hostDao.findById(hostId); if (host.getRemoved() != null) {
if (host == null || host.getRemoved() != null) { throw new CloudRuntimeException("Host has already been removed: " + hostId);
s_logger.warn("Unable to find host " + hostId);
return false;
} }
if (host.getStatus() == Status.Disconnected) { if (host.getStatus() == Status.Disconnected) {
s_logger.info("Host is already disconnected, no work to be done"); s_logger.debug("Host is already disconnected, no work to be done: " + hostId);
return true; return;
} }
if (host.getStatus() != Status.Up && host.getStatus() != Status.Alert && host.getStatus() != Status.Rebalancing) { 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()); throw new CloudRuntimeException("Unable to disconnect host because it is not in the correct state: host=" + hostId + "; Status=" + host.getStatus());
return false;
} }
final AgentAttache attache = findAttache(hostId); AgentAttache attache = findAttache(hostId);
if (attache == null) { if (attache == null) {
s_logger.info("Unable to disconnect host because it is not connected to this server: " + hostId); throw new CloudRuntimeException("Unable to disconnect host because it is not connected to this server: " + hostId);
return false;
} }
disconnectWithoutInvestigation(attache, Event.ShutdownRequested); disconnectWithoutInvestigation(attache, Event.ShutdownRequested);
return true;
} }
@Override @Override
@ -1049,8 +1034,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true); handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
} }
return 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; return false;
} }
@ -1166,7 +1158,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
_request.logD("Processing the first command "); _request.logD("Processing the first command ");
final StartupCommand[] startups = new StartupCommand[_cmds.length]; final StartupCommand[] startups = new StartupCommand[_cmds.length];
for (int i = 0; i < _cmds.length; i++) { 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); 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++) { for (int i = 0; i < cmds.length; i++) {
cmd = cmds[i]; cmd = cmds[i];
if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand || 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()); answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, mgmtServiceConf.getPingInterval());
break; break;
} }
@ -1205,7 +1197,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
protected void processRequest(final Link link, final Request request) { 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(); final Command[] cmds = request.getCommands();
Command cmd = cmds[0]; Command cmd = cmds[0];
boolean logD = true; boolean logD = true;
@ -1256,10 +1248,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
final StartupStorageCommand startup = (StartupStorageCommand) cmd; final StartupStorageCommand startup = (StartupStorageCommand) cmd;
answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval()); answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval());
} else if (cmd instanceof ShutdownCommand) { } else if (cmd instanceof ShutdownCommand) {
final ShutdownCommand shutdown = (ShutdownCommand) cmd; final ShutdownCommand shutdown = (ShutdownCommand)cmd;
final String reason = shutdown.getReason(); final String reason = shutdown.getReason();
s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + shutdown.getDetail());
shutdown.getDetail());
if (reason.equals(ShutdownCommand.Update)) { if (reason.equals(ShutdownCommand.Update)) {
// disconnectWithoutInvestigation(attache, Event.UpdateNeeded); // disconnectWithoutInvestigation(attache, Event.UpdateNeeded);
throw new CloudRuntimeException("Agent update not implemented"); throw new CloudRuntimeException("Agent update not implemented");
@ -1268,16 +1259,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
return; return;
} else if (cmd instanceof AgentControlCommand) { } else if (cmd instanceof AgentControlCommand) {
answer = handleControlCommand(attache, (AgentControlCommand) cmd); answer = handleControlCommand(attache, (AgentControlCommand)cmd);
} else { } else {
handleCommands(attache, request.getSequence(), new Command[] { cmd }); handleCommands(attache, request.getSequence(), new Command[] {cmd});
if (cmd instanceof PingCommand) { 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 // if the router is sending a ping, verify the
// gateway was pingable // gateway was pingable
if (cmd instanceof PingRoutingCommand) { if (cmd instanceof PingRoutingCommand) {
final boolean gatewayAccessible = ((PingRoutingCommand) cmd).isGatewayAccessible(); final boolean gatewayAccessible = ((PingRoutingCommand)cmd).isGatewayAccessible();
final HostVO host = _hostDao.findById(Long.valueOf(cmdHostId)); final HostVO host = _hostDao.findById(Long.valueOf(cmdHostId));
if (host != null) { if (host != null) {
@ -1286,22 +1277,18 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
// gateway (cannot ping the default route) // gateway (cannot ping the default route)
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId()); final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
final HostPodVO podVO = _podDao.findById(host.getPodId()); final HostPodVO podVO = _podDao.findById(host.getPodId());
final String hostDesc = final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
"name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: "
+ podVO.getName();
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(), _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + hostDesc,
"Host lost connection to gateway, " + hostDesc, "Host [" + hostDesc + "Host [" + hostDesc + "] lost connection to gateway (default route) and is possibly having network connection issues.");
"] lost connection to gateway (default route) and is possibly having network connection issues.");
} else { } else {
_alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId()); _alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId());
} }
} else { } else {
s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId + s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId + "; can't find the host in the DB");
"; can't find the host in the DB");
} }
} }
answer = new PingAnswer((PingCommand) cmd); answer = new PingAnswer((PingCommand)cmd);
} else if (cmd instanceof ReadyAnswer) { } else if (cmd instanceof ReadyAnswer) {
final HostVO host = _hostDao.findById(attache.getId()); final HostVO host = _hostDao.findById(attache.getId());
if (host == null) { if (host == null) {
@ -1337,7 +1324,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
protected void processResponse(final Link link, final Response response) { protected void processResponse(final Link link, final Response response) {
final AgentAttache attache = (AgentAttache) link.attachment(); final AgentAttache attache = (AgentAttache)link.attachment();
if (attache == null) { if (attache == null) {
s_logger.warn("Unable to process: " + response); s_logger.warn("Unable to process: " + response);
} else if (!attache.processAnswers(response.getSequence(), response)) { } else if (!attache.processAnswers(response.getSequence(), response)) {
@ -1355,7 +1342,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
try { try {
final Request event = Request.parse(data); final Request event = Request.parse(data);
if (event instanceof Response) { if (event instanceof Response) {
processResponse(task.getLink(), (Response) event); processResponse(task.getLink(), (Response)event);
} else { } else {
processRequest(task.getLink(), event); 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.CONNECT) {
} else if (type == Task.Type.DISCONNECT) { } else if (type == Task.Type.DISCONNECT) {
final Link link = task.getLink(); final Link link = task.getLink();
final AgentAttache attache = (AgentAttache) link.attachment(); final AgentAttache attache = (AgentAttache)link.attachment();
if (attache != null) { if (attache != null) {
disconnectWithInvestigation(attache, Event.AgentDisconnected); disconnectWithInvestigation(attache, Event.AgentDisconnected);
} else { } 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) { public boolean agentStatusTransitTo(final HostVO host, final Status.Event e, final long msId) {
try { try {
_agentStatusLock.lock(); _agentStatusLock.lock();
if (status_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
final ResourceState state = host.getResourceState(); final ResourceState state = host.getResourceState();
final StringBuilder msg = new StringBuilder("Transition:"); final StringBuilder msg = new StringBuilder("Transition:");
msg.append("[Resource state = ").append(state); msg.append("[Resource state = ").append(state);
msg.append(", Agent event = ").append(e.toString()); msg.append(", Agent event = ").append(e.toString());
msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]"); msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]");
status_logger.debug(msg); s_logger.debug(msg);
} }
host.setManagementServerId(msId); host.setManagementServerId(msId);
try { try {
return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao); return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao);
} catch (final NoTransitionException e1) { } catch (final NoTransitionException e1) {
status_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + s_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", mangement server id is " + msId);
", 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());
throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," +
e1.getMessage());
} }
} finally { } finally {
_agentStatusLock.unlock(); _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) { public void disconnectWithInvestigation(final long hostId, final Status.Event event) {
disconnectInternal(hostId, event, true); disconnectInternal(hostId, event, true);
} }
@ -1501,8 +1487,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
@Override @Override
public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, final boolean forRebalance, boolean newHost) throws ConnectionException {
final boolean forRebalance, boolean newHost) throws ConnectionException {
AgentAttache attache; AgentAttache attache;
attache = createAttacheForDirectConnect(host, resource); 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 * 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); disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
} else { } else {
final HostVO host = _hostDao.findById(agentId); final HostVO host = _hostDao.findById(agentId);
if (host != null && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM if (host != null
|| host.getType() == Host.Type.SecondaryStorageCmdExecutor)) { && (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()); s_logger.warn("Disconnect agent for CPVM/SSVM due to physical connection close. host: " + host.getId());
disconnectWithoutInvestigation(agentId, Event.ShutdownRequested); disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
} else { } 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); disconnectWithInvestigation(agentId, Event.PingTimeout);
} }
} }
@ -1605,8 +1590,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId()); final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
final HostPodVO podVO = _podDao.findById(host.getPodId()); 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_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc, "Host [" _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc,
+ hostDesc + "] is ready for maintenance"); "Host [" + hostDesc + "] is ready for maintenance");
} }
} }
} catch (final Throwable th) { } catch (final Throwable th) {
@ -1708,7 +1693,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize, return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize,
DirectAgentThreadCap }; DirectAgentThreadCap };
} }
protected class SetHostParamsListener implements Listener { protected class SetHostParamsListener implements Listener {
@ -1738,20 +1723,20 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override @Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) { public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) {
if (cmd instanceof StartupRoutingCommand) { if (cmd instanceof StartupRoutingCommand) {
if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) { if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout")); params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
try { try {
SetHostParamsCommand cmds = new SetHostParamsCommand(params); SetHostParamsCommand cmds = new SetHostParamsCommand(params);
Commands c = new Commands(cmds); Commands c = new Commands(cmds);
send(host.getId(), c, this); send(host.getId(), c, this);
} catch (AgentUnavailableException e) { } catch (AgentUnavailableException e) {
s_logger.debug("Failed to send host params on host: " + host.getId()); s_logger.debug("Failed to send host params on host: " + host.getId());
}
} }
} }
}
} }

View File

@ -46,12 +46,12 @@ import org.apache.cloudstack.ca.CAManager;
import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; 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.ManagedContextRunnable;
import org.apache.cloudstack.managed.context.ManagedContextTimerTask; 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.identity.ManagementServerNode;
import org.apache.cloudstack.utils.security.SSLUtils; 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 org.apache.log4j.Logger;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
@ -134,14 +134,12 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
super(); super();
} }
protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false", protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false", "Enable agent load balancing between management server nodes", true);
"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", 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); "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", 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);
"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,
protected final ConfigKey<Integer> ScanInterval = new ConfigKey<Integer>(Integer.class, "direct.agent.scan.interval", "Advanced", "90", ConfigKey.Scope.Global, 1000);
"Interval between scans to load agents", false, ConfigKey.Scope.Global, 1000);
@Override @Override
public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException { 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); final HostTransferMapVO transferVO = _hostTransferDao.findById(hostId);
if (transferVO != null) { if (transferVO != null) {
if (transferVO.getFutureOwner() == _nodeId && transferVO.getState() == HostTransferState.TransferStarted) { 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 " + s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " + _nodeId);
_nodeId);
return true; 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, // 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 // but the host has already reconnected to the current management server
if (!attache.forForward()) { if (!attache.forForward()) {
s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + 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);
" as the host is directly connected to the current management server " + _nodeId);
return true; return true;
} }
@ -367,19 +363,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} }
@Override @Override
public boolean reconnect(final long hostId) { public void reconnect(final long hostId) throws CloudRuntimeException, AgentUnavailableException {
Boolean result; Boolean result = propagateAgentEvent(hostId, Event.ShutdownRequested);
try { if (result == null) {
result = propagateAgentEvent(hostId, Event.ShutdownRequested); super.reconnect(hostId);
if (result != null) {
return result;
}
} catch (final AgentUnavailableException e) {
s_logger.debug("cannot propagate agent reconnect because agent is not available", e);
return false;
}
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) { 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) { protected static void logT(final byte[] bytes, final String msg) {
s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
(Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg); + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
} }
protected static void logD(final byte[] bytes, final String 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) + ": " + s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
(Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg); + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
} }
protected static void logI(final byte[] bytes, final String 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) + ": " + s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
(Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg); + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
} }
public boolean routeToPeer(final String peer, final byte[] bytes) { 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()); logI(bytes, "Unable to route to peer: " + Request.parse(bytes).toString() + " due to " + e.getMessage());
} catch (ClassNotFoundException | UnsupportedVersionException ex) { } catch (ClassNotFoundException | UnsupportedVersionException ex) {
// Request.parse thrown exception when we try to log it, log as much as we can // 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() logI(bytes, "Unable to route to peer due to" + e.getMessage() + ". Also caught exception when parsing request: " + ex.getMessage());
+ ". Also caught exception when parsing request: " + ex.getMessage());
} }
} }
} }
@ -489,8 +480,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
try { try {
prevCh.close(); prevCh.close();
} catch (final Exception e) { } catch (final Exception e) {
s_logger.info("[ignored]" s_logger.info("[ignored]" + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
+ "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
} }
} }
if (ch == null || ch == prevCh) { if (ch == null || ch == prevCh) {
@ -597,7 +587,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.info("Closing: " + ch.toString()); s_logger.info("Closing: " + ch.toString());
ch.close(); ch.close();
} catch (final IOException e) { } 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 @Override
public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException, public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException, OperationTimedoutException {
OperationTimedoutException {
boolean result = false; boolean result = false;
if (event == Event.RequestAgentRebalance) { if (event == Event.RequestAgentRebalance) {
return setToWaitForRebalance(agentId, currentOwnerId, futureOwnerId); return setToWaitForRebalance(agentId, currentOwnerId, futureOwnerId);
@ -837,8 +826,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
avLoad = allManagedAgents.size() / allMS.size(); avLoad = allManagedAgents.size() / allMS.size();
} else { } else {
if (s_logger.isDebugEnabled()) { 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() + 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 "
"; number of managed agents is " + allManagedAgents.size()); + allManagedAgents.size());
} }
return; 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 // 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 // no need to do anything with the real attache as we haven't modified it yet
final Date cutTime = DateUtil.currentGMTTime(); final Date cutTime = DateUtil.currentGMTTime();
final HostTransferMapVO transferMap = final HostTransferMapVO transferMap = _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
_hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
if (transferMap == null) { if (transferMap == null) {
s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host"); 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()); final ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner());
if (ms != null && ms.getState() != ManagementServerHost.State.Up) { 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 + s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host");
", skipping rebalance for the host");
iterator.remove(); iterator.remove();
_hostTransferDao.completeAgentTransfer(hostId); _hostTransferDao.completeAgentTransfer(hostId);
continue; continue;
@ -1027,8 +1014,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} }
} else { } else {
s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is "
" and listener queue size is " + attache.getNonRecurringListenersSize()); + attache.getNonRecurringListenersSize());
} }
} }
} else { } else {
@ -1094,8 +1081,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (result) { if (result) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
" as a part of rebalance process");
} }
result = loadDirectlyConnectedHost(host, true); result = loadDirectlyConnectedHost(host, true);
} else { } else {
@ -1103,17 +1089,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} }
} catch (final Exception ex) { } catch (final Exception ex) {
s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + 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:",
" as a part of rebalance process due to:", ex); ex);
result = false; result = false;
} }
if (result) { if (result) {
s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
" as a part of rebalance process");
} else { } else {
s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
" 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 // 2) Get all transfer requests and route them to peer
Request requestToTransfer = forwardAttache.getRequestToTransfer(); Request requestToTransfer = forwardAttache.getRequestToTransfer();
while (requestToTransfer != null) { while (requestToTransfer != null) {
s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + _nodeId + " to " + futureOwnerId);
_nodeId + " to " + futureOwnerId);
final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes()); final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes());
if (!routeResult) { if (!routeResult) {
logD(requestToTransfer.getBytes(), "Failed to route request to peer"); logD(requestToTransfer.getBytes(), "Failed to route request to peer");
@ -1198,8 +1181,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (attache == null) { if (attache == null) {
s_logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing"); s_logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing");
} else { } else {
s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " + s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " + attache.getNonRecurringListenersSize()
attache.getNonRecurringListenersSize() + ", can't start host rebalancing"); + ", can't start host rebalancing");
} }
return false; return false;
} }
@ -1255,8 +1238,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} catch (final Exception e) { } catch (final Exception e) {
// Scheduling host scan task in peer MS is a best effort operation during host add, regular host scan // 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 // 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() + s_logger.warn(
", ignoring as regular host scan happens at fixed interval anyways", e); "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; return null;
} }
@ -1372,15 +1356,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
final String jsonReturn = _gson.toJson(answers); final String jsonReturn = _gson.toJson(answers);
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return result: "
(System.currentTimeMillis() - startTick) + " ms, return result: " + jsonReturn); + jsonReturn);
} }
return jsonReturn; return jsonReturn;
} else { } else {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + s_logger.debug(
(System.currentTimeMillis() - startTick) + " ms, return null result"); "Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return null result");
} }
} }
} catch (final AgentUnavailableException e) { } catch (final AgentUnavailableException e) {

View File

@ -53,6 +53,9 @@ public class AlertVO implements Alert {
@Column(name = "subject", length = 999) @Column(name = "subject", length = 999)
private String subject; private String subject;
@Column(name = "content", length = 5000)
private String content;
@Column(name = "sent_count") @Column(name = "sent_count")
private int sentCount = 0; private int sentCount = 0;
@ -191,4 +194,13 @@ public class AlertVO implements Alert {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@Override
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
} }

View File

@ -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 = ?"; 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> TypePodDcStatusSearch;
protected SearchBuilder<HostVO> IdStatusSearch; protected SearchBuilder<HostVO> IdStatusSearch;

View File

@ -66,4 +66,4 @@ CREATE VIEW `cloud`.`user_view` AS
left join left join
`cloud`.`async_job` ON async_job.instance_id = user.id `cloud`.`async_job` ON async_job.instance_id = user.id
and async_job.instance_type = 'User' and async_job.instance_type = 'User'
and async_job.job_status = 0; and async_job.job_status = 0;

View File

@ -566,4 +566,4 @@ CREATE TABLE IF NOT EXISTS `cloud`.`external_netscaler_controlcenter` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) 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`.`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';

View File

@ -20,4 +20,7 @@
--; --;
-- [CLOUDSTACK-10314] Add reason column to ACL rule table -- [CLOUDSTACK-10314] Add reason column to ACL rule table
ALTER TABLE `cloud`.`network_acl_item` ADD COLUMN `reason` VARCHAR(2500) AFTER `display`; 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);

View File

@ -266,20 +266,16 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
} }
@Override @Override
public boolean reconnect(long hostId) { public void reconnect(long hostId) {
// TODO Auto-generated method stub
return false;
} }
@Override @Override
public boolean isAgentAttached(long hostId) { public boolean isAgentAttached(long hostId) {
// TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance, boolean newHost) throws ConnectionException { public boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance, boolean newHost) throws ConnectionException {
// TODO Auto-generated method stub
return false; return false;
} }

View File

@ -28,12 +28,6 @@ import java.util.UUID;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; 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.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException; 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.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.cloudstack.region.gslb.GslbServiceProvider; 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.AgentManager;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
@ -84,6 +81,7 @@ import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlan;
import com.cloud.event.ActionEvent; import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes; import com.cloud.event.EventTypes;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.InsufficientNetworkCapacityException;
@ -154,10 +152,11 @@ import com.cloud.utils.net.UrlUtil;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
import com.google.gson.Gson;
public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager,
IpDeployer, StaticNatServiceProvider, GslbServiceProvider { IpDeployer, StaticNatServiceProvider, GslbServiceProvider {
private static final Logger s_logger = Logger.getLogger(NetscalerElement.class); private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
public static final AutoScaleCounterType AutoScaleCounterSnmp = new AutoScaleCounterType("snmp"); public static final AutoScaleCounterType AutoScaleCounterSnmp = new AutoScaleCounterType("snmp");
@ -218,7 +217,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced
&& (config.getGuestType() == Network.GuestType.Isolated && (config.getGuestType() == Network.GuestType.Isolated
|| config.getGuestType() == Network.GuestType.Shared) || config.getGuestType() == Network.GuestType.Shared)
&& config.getTrafficType() == TrafficType.Guest); && config.getTrafficType() == TrafficType.Guest);
boolean handleInBasicZone = (zone.getNetworkType() == NetworkType.Basic boolean handleInBasicZone = (zone.getNetworkType() == NetworkType.Basic
&& config.getGuestType() == Network.GuestType.Shared && config.getTrafficType() == TrafficType.Guest); && config.getGuestType() == Network.GuestType.Shared && config.getTrafficType() == TrafficType.Guest);
@ -242,7 +241,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@Override @Override
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest,
ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientNetworkCapacityException { InsufficientNetworkCapacityException {
if (!canHandle(guestConfig, Service.Lb)) { if (!canHandle(guestConfig, Service.Lb)) {
return false; return false;
@ -271,7 +270,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
throw new ResourceUnavailableException( throw new ResourceUnavailableException(
"There are no NetScaler load balancer devices with the free capacity for implementing this network : " "There are no NetScaler load balancer devices with the free capacity for implementing this network : "
+ e.getMessage(), + e.getMessage(),
DataCenter.class, guestConfig.getDataCenterId()); DataCenter.class, guestConfig.getDataCenterId());
} }
} }
@ -286,7 +285,6 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
Map<String, String> _configs; Map<String, String> _configs;
List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll(); List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll();
HostVO hostVO = null; HostVO hostVO = null;
Map<String, Object> params;
if (ncc.size() > 0) { if (ncc.size() > 0) {
NetScalerControlCenterVO nccVO = ncc.get(0); NetScalerControlCenterVO nccVO = ncc.get(0);
String ipAddress = nccVO.getNccip(); String ipAddress = nccVO.getNccip();
@ -414,7 +412,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@Override @Override
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest,
ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException,
ResourceUnavailableException { ResourceUnavailableException {
return true; return true;
} }
@ -593,45 +591,45 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
boolean dedicatedUse = (configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null) boolean dedicatedUse = (configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null)
? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false; ? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) { if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
String msg = "Only Netscaler VPX load balancers can be specified for dedicated use"; String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
s_logger.debug(msg); s_logger.debug(msg);
throw new InvalidParameterValueException(msg); throw new InvalidParameterValueException(msg);
} }
if (cmd.isGslbProvider()) { if (cmd.isGslbProvider()) {
if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName()) if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())
&& !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) { && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider"; String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
s_logger.debug(msg); s_logger.debug(msg);
throw new InvalidParameterValueException(msg); throw new InvalidParameterValueException(msg);
} }
if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) { if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider"; String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
s_logger.debug(msg); s_logger.debug(msg);
throw new InvalidParameterValueException(msg); throw new InvalidParameterValueException(msg);
} }
if (dedicatedUse) { if (dedicatedUse) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
"NetScaler provisioned to be GSLB service provider can only be configured for shared usage."); "NetScaler provisioned to be GSLB service provider can only be configured for shared usage.");
} }
} }
if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) { if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
"NetScaler can be provisioned to be exclusive GSLB service provider" "NetScaler can be provisioned to be exclusive GSLB service provider"
+ " only if its being configured as GSLB service provider also."); + " only if its being configured as GSLB service provider also.");
} }
ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(),
cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(), cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(),
cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp()); cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp());
return lbDeviceVO; return lbDeviceVO;
} }
@Override @Override
@ -759,7 +757,11 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
}); });
HostVO host = _hostDao.findById(lbDeviceVo.getHostId()); 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; return lbDeviceVo;
} }
@ -858,8 +860,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
boolean flag=false; boolean flag=false;
try { try {
result = _netscalerServicePackageDao.findByUuid(cmd.getId()); result = _netscalerServicePackageDao.findByUuid(cmd.getId());
if (result == null) if (result == null) {
throw new CloudRuntimeException("Record does not Exists in the Table"); throw new CloudRuntimeException("Record does not Exists in the Table");
}
if(_networkOfferingDao.isUsingServicePackage(result.getUuid())) if(_networkOfferingDao.isUsingServicePackage(result.getUuid()))
{ {
@ -869,10 +872,11 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
flag = _netscalerServicePackageDao.remove(result.getId()); flag = _netscalerServicePackageDao.remove(result.getId());
} catch (Exception e) { } catch (Exception e) {
if (e instanceof InvalidParameterValueException) if (e instanceof InvalidParameterValueException) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
else } else {
throw e; throw e;
}
} }
return flag; return flag;
@ -884,18 +888,19 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) throws CloudRuntimeException { public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) throws CloudRuntimeException {
NetScalerControlCenterVO result = _netscalerControlCenterDao.findByUuid(cmd.getId()); 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"); 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. //ID list of Network Offering which are not removed and have service Package Uuid field not null.
List<Long> servicePackageId_list = _networkOfferingDao.listNetworkOfferingID(); List<Long> servicePackageId_list = _networkOfferingDao.listNetworkOfferingID();
if (servicePackageId_list.size() != 0) { if (servicePackageId_list.size() != 0) {
//VO list of Networks which are using Network Offering. //VO list of Networks which are using Network Offering.
List<NetworkVO> networkVO_list = _networkDao.listNetworkVO(servicePackageId_list); 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( throw new CloudRuntimeException(
"ServicePackages published by NetScalerControlCenter are being used by NetworkOfferings. Try deleting NetworkOffering with ServicePackages and then delete NetScalerControlCenter."); "ServicePackages published by NetScalerControlCenter are being used by NetworkOfferings. Try deleting NetworkOffering with ServicePackages and then delete NetScalerControlCenter.");
}
} }
} }
try { try {
@ -1466,8 +1471,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@DB @DB
public NetScalerControlCenterVO registerNetscalerControlCenter(RegisterNetscalerControlCenterCmd cmd) { 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"); 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; final RegisterNetscalerControlCenterCmd cmdinfo = cmd;
String ipAddress = cmd.getIpaddress(); String ipAddress = cmd.getIpaddress();
@ -1511,7 +1517,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
Long serviceOfferingId = cmd.getServiceOfferingId(); Long serviceOfferingId = cmd.getServiceOfferingId();
DeploymentPlan plan = new DataCenterDeployment(dest.getDataCenter().getId()); DeploymentPlan plan = new DataCenterDeployment(dest.getDataCenter().getId());
try { try {
resp = _netScalerVMManager.deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId); resp = _netScalerVMManager.deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId);
} catch (InsufficientCapacityException e) { } catch (InsufficientCapacityException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1520,7 +1526,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
@Override @Override
public VirtualRouter stopNetscalerServiceVm(Long id, boolean forced, Account callingAccount, long callingUserId) throws ConcurrentOperationException, public VirtualRouter stopNetscalerServiceVm(Long id, boolean forced, Account callingAccount, long callingUserId) throws ConcurrentOperationException,
ResourceUnavailableException { ResourceUnavailableException {
return _netScalerVMManager.stopNetScalerVm(id, forced, callingAccount, callingUserId); return _netScalerVMManager.stopNetScalerVm(id, forced, callingAccount, callingUserId);
} }
} }

View File

@ -21,5 +21,4 @@ cloudmonkey
# Marvin dependencies are installed via its bundle # Marvin dependencies are installed via its bundle
# Install the SolidFire SDK for Python # Install the SolidFire SDK for Python
solidfire-sdk-python solidfire-sdk-python

View File

@ -39,12 +39,6 @@ import javax.mail.URLName;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.naming.ConfigurationException; 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.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable; 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.managed.context.ManagedContextTimerTask;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.log4j.Logger;
import com.cloud.alert.dao.AlertDao; import com.cloud.alert.dao.AlertDao;
import com.cloud.api.ApiDBUtils; import com.cloud.api.ApiDBUtils;
@ -85,10 +80,12 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.SearchCriteria; 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 { public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable {
private static final Logger s_logger = Logger.getLogger(AlertManagerImpl.class.getName()); 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. 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"); String capacityCheckPeriodStr = configs.get("capacity.check.period");
if (capacityCheckPeriodStr != null) { if (capacityCheckPeriodStr != null) {
_capacityCheckPeriod = Long.parseLong(capacityCheckPeriodStr); _capacityCheckPeriod = Long.parseLong(capacityCheckPeriodStr);
if (_capacityCheckPeriod <= 0) if (_capacityCheckPeriod <= 0) {
_capacityCheckPeriod = Long.parseLong(Config.CapacityCheckPeriod.getDefaultValue()); _capacityCheckPeriod = Long.parseLong(Config.CapacityCheckPeriod.getDefaultValue());
}
} }
_timer = new Timer("CapacityChecker"); _timer = new Timer("CapacityChecker");
@ -249,7 +247,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
if (_emailAlert != null) { if (_emailAlert != null) {
_emailAlert.sendAlert(alertType, dataCenterId, podId, null, subject, body); _emailAlert.sendAlert(alertType, dataCenterId, podId, null, subject, body);
} else { } else {
s_alertsLogger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " + podId + s_logger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " + podId +
" | message:: " + subject + " | body:: " + body); " | message:: " + subject + " | body:: " + body);
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -589,7 +587,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
alertType = AlertManager.AlertType.ALERT_TYPE_LOCAL_STORAGE; alertType = AlertManager.AlertType.ALERT_TYPE_LOCAL_STORAGE;
break; break;
//Pod Level //Pod Level
case Capacity.CAPACITY_TYPE_PRIVATE_IP: 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(); msgSubject = "System Alert: Number of unallocated private IPs is low in pod " + pod.getName() + " of availability zone " + dc.getName();
totalStr = Double.toString(totalCapacity); totalStr = Double.toString(totalCapacity);
@ -598,7 +596,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
alertType = AlertManager.AlertType.ALERT_TYPE_PRIVATE_IP; alertType = AlertManager.AlertType.ALERT_TYPE_PRIVATE_IP;
break; break;
//Zone Level //Zone Level
case Capacity.CAPACITY_TYPE_SECONDARY_STORAGE: case Capacity.CAPACITY_TYPE_SECONDARY_STORAGE:
msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc.getName(); msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc.getName();
totalStr = formatBytesToMegabytes(totalCapacity); 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 // 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, public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) throws MessagingException,
UnsupportedEncodingException { UnsupportedEncodingException {
s_alertsLogger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " + s_logger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " +
podId + " | clusterId:: " + clusterId + " | message:: " + subject); podId + " | clusterId:: " + clusterId + " | message:: " + subject);
AlertVO alert = null; AlertVO alert = null;
if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) && if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) && (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) && (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) && (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) && (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) && (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) && (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) && (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) && (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) &&
(alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) { (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) {
alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId); alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId);
} }
@ -770,6 +768,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
AlertVO newAlert = new AlertVO(); AlertVO newAlert = new AlertVO();
newAlert.setType(alertType.getType()); newAlert.setType(alertType.getType());
newAlert.setSubject(subject); newAlert.setSubject(subject);
newAlert.setContent(content);
newAlert.setClusterId(clusterId); newAlert.setClusterId(clusterId);
newAlert.setPodId(podId); newAlert.setPodId(podId);
newAlert.setDataCenterId(dataCenterId); newAlert.setDataCenterId(dataCenterId);

View File

@ -30,10 +30,6 @@ import java.util.Random;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; 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.ApiConstants;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; 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.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.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.utils.identity.ManagementServerNode; import org.apache.cloudstack.utils.identity.ManagementServerNode;
import org.apache.commons.collections.CollectionUtils; 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.AgentManager;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
@ -75,7 +74,6 @@ import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao; import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ClusterManager; import com.cloud.cluster.ClusterManager;
import com.cloud.configuration.Config; import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterDetailsVO; import com.cloud.dc.ClusterDetailsVO;
import com.cloud.dc.ClusterVO; import com.cloud.dc.ClusterVO;
@ -249,8 +247,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Inject @Inject
private VMTemplateDao _templateDao; private VMTemplateDao _templateDao;
@Inject @Inject
private ConfigurationManager _configMgr;
@Inject
private ClusterVSMMapDao _clusterVSMMapDao; private ClusterVSMMapDao _clusterVSMMapDao;
private final long _nodeId = ManagementServerNode.getManagementServerId(); 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, 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, final String hypervisorType, final List<String> hostTags, final Map<String, String> params, final boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException,
InvalidParameterValueException { InvalidParameterValueException {
URI uri = null; URI uri = null;
// Check if the zone exists in the system // 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 // Get storage pool host mappings here because they can be removed as a
// part of handleDisconnect later // part of handleDisconnect later
// TODO: find out the bad boy, what's a buggy logic!
final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId); final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
final ResourceStateAdapter.DeleteHostAnswer answer = final ResourceStateAdapter.DeleteHostAnswer answer =
@ -1166,15 +1161,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
} }
@Override @Override
public Host reconnectHost(final ReconnectHostCmd cmd) { public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
final Long hostId = cmd.getId(); Long hostId = cmd.getId();
final HostVO host = _hostDao.findById(hostId); HostVO host = _hostDao.findById(hostId);
if (host == null) { if (host == null) {
throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist"); throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist");
} }
_agentMgr.reconnect(hostId);
return _agentMgr.reconnect(hostId) ? host : null; return host;
} }
@Override @Override
@ -2310,7 +2305,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
} else if (event == ResourceState.Event.AdminCancelMaintenance) { } else if (event == ResourceState.Event.AdminCancelMaintenance) {
return doCancelMaintenance(hostId); return doCancelMaintenance(hostId);
} else if (event == ResourceState.Event.DeleteHost) { } else if (event == ResourceState.Event.DeleteHost) {
/* TODO: Ask alex why we assume the last two parameters are false */
return doDeleteHost(hostId, false, false); return doDeleteHost(hostId, false, false);
} else if (event == ResourceState.Event.Unmanaged) { } else if (event == ResourceState.Event.Unmanaged) {
return doUmanageHost(hostId); return doUmanageHost(hostId);
@ -2329,7 +2323,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
} }
if (host.getHypervisorType() == HypervisorType.KVM || host.getHypervisorType() == HypervisorType.LXC) { 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); _agentMgr.disconnectWithoutInvestigation(hostId, Event.ShutdownRequested);
@ -2379,10 +2373,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId()); final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId());
for (final HostVO host : hosts) { for (final HostVO host : hosts) {
try { 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); final Boolean result = propagateResourceEvent(host.getId(), ResourceState.Event.UpdatePassword);
if (result != null) { if (result != null) {
return result; return result;
@ -2852,11 +2842,4 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
return false; return false;
} }
} }
@Override
public boolean start() {
// TODO Auto-generated method stub
return super.start();
}
} }

View File

@ -191,7 +191,8 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
if (Strings.isNullOrEmpty(csr)) { if (Strings.isNullOrEmpty(csr)) {
return false; 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); return deployCertificate(host, certificate, reconnect, null);
} catch (final AgentUnavailableException | OperationTimedoutException e) { } 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); 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); cmd.setAccessDetail(sshAccessDetails);
} }
CallContext.current().setEventDetails("generating keystore and CSR for host id: " + host.getId()); 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(); return answer.getCsr();
} }
@Override @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); final SetupCertificateCommand cmd = new SetupCertificateCommand(certificate);
if (sshAccessDetails != null && !sshAccessDetails.isEmpty()) { if (sshAccessDetails != null && !sshAccessDetails.isEmpty()) {
cmd.setAccessDetail(sshAccessDetails); cmd.setAccessDetail(sshAccessDetails);
} }
CallContext.current().setEventDetails("deploying certificate for host id: " + host.getId()); 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()) { if (answer.getResult()) {
CallContext.current().setEventDetails("successfully deployed certificate for host id: " + host.getId()); CallContext.current().setEventDetails("successfully deployed certificate for host id: " + host.getId());
} else { } else {
@ -227,9 +229,12 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
if (answer.getResult()) { if (answer.getResult()) {
getActiveCertificatesMap().put(host.getPrivateIpAddress(), certificate.getClientCertificate()); getActiveCertificatesMap().put(host.getPrivateIpAddress(), certificate.getClientCertificate());
if (sshAccessDetails == null && reconnect != null && reconnect) { 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", 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()));
host.getId(), host.getName(), host.getPublicIpAddress())); try {
return agentManager.reconnect(host.getId()); agentManager.reconnect(host.getId());
} catch (AgentUnavailableException | CloudRuntimeException e) {
LOG.debug("Error when reconnecting to host: " + host.getUuid(), e);
}
} }
return true; return true;
} }
@ -257,8 +262,7 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
if (host == null) { if (host == null) {
return; return;
} }
alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_CA_CERT, alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_CA_CERT, host.getDataCenterId(), host.getPodId(), subject, message);
host.getDataCenterId(), host.getPodId(), subject, message);
} }
@Override @Override
@ -303,7 +307,7 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
} }
final DateTime now = DateTime.now(DateTimeZone.UTC); final DateTime now = DateTime.now(DateTimeZone.UTC);
final Map<String, X509Certificate> certsMap = caManager.getActiveCertificatesMap(); 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(); final Map.Entry<String, X509Certificate> entry = it.next();
if (entry == null) { if (entry == null) {
continue; continue;
@ -315,19 +319,14 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
continue; continue;
} }
final Host host = hostDao.findByIp(hostIp); final Host host = hostDao.findByIp(hostIp);
if (host == null || host.getManagementServerId() == null || if (host == null || host.getManagementServerId() == null || host.getManagementServerId() != ManagementServerNode.getManagementServerId() || host.getStatus() != Status.Up) {
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(); it.remove();
} }
continue; continue;
} }
final String hostDescription = String.format("host id=%d, uuid=%s, name=%s, ip=%s, zone id=%d", 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());
host.getId(), host.getUuid(), host.getName(), hostIp, host.getDataCenterId());
try { try {
certificate.checkValidity(now.plusDays(CertExpiryAlertPeriod.valueIn(host.getClusterId())).toDate()); certificate.checkValidity(now.plusDays(CertExpiryAlertPeriod.valueIn(host.getClusterId())).toDate());
@ -345,7 +344,8 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
} catch (final Throwable ex) { } catch (final Throwable ex) {
LOG.warn("Failed to auto-renew certificate for " + hostDescription + ", with error=", ex); LOG.warn("Failed to auto-renew certificate for " + hostDescription + ", with error=", ex);
caManager.sendAlert(host, "Certificate auto-renewal failed for " + hostDescription, 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 { } else {
if (alertMap.containsKey(hostIp)) { if (alertMap.containsKey(hostIp)) {
@ -355,8 +355,7 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
} }
} }
caManager.sendAlert(host, "Certificate expiring soon for " + hostDescription, 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.", String.format("Certificate is going to expire for %s. Please renew it, it is not valid after %s.", hostDescription, certificate.getNotAfter()));
hostDescription, certificate.getNotAfter()));
alertMap.put(hostIp, new Date()); alertMap.put(hostIp, new Date());
} }
} }
@ -427,14 +426,6 @@ public class CAManagerImpl extends ManagerBase implements CAManager {
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[]{ return new ConfigKey<?>[] {CAProviderPlugin, CertKeySize, CertSignatureAlgorithm, CertValidityPeriod, AutomaticCertRenewal, CABackgroundJobDelay, CertExpiryAlertPeriod};
CAProviderPlugin,
CertKeySize,
CertSignatureAlgorithm,
CertValidityPeriod,
AutomaticCertRenewal,
CABackgroundJobDelay,
CertExpiryAlertPeriod
};
} }
} }

View File

@ -113,7 +113,7 @@ public class CAManagerImplTest {
final X509Certificate certificate = CertUtils.generateV3Certificate(null, keyPair, keyPair.getPublic(), "CN=ca", "SHA256withRSA", 365, null, null); 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(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.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)); 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(2)).send(Mockito.anyLong(), Mockito.any(Answer.class));
Mockito.verify(agentManager, Mockito.times(1)).reconnect(Mockito.anyLong()); Mockito.verify(agentManager, Mockito.times(1)).reconnect(Mockito.anyLong());