use of com.cloud.legacymodel.exceptions.ConnectionException in project cosmic by MissionCriticalCloud.
the class AgentManagerImplTest method testNotifyMonitorsOfConnectionWhenStoragePoolConnectionHostFailure.
@Test
public void testNotifyMonitorsOfConnectionWhenStoragePoolConnectionHostFailure() throws ConnectionException {
final ConnectionException connectionException = new ConnectionException(true, "storage pool could not be connected on host");
Mockito.when(hostDao.findById(Mockito.anyLong())).thenReturn(host);
Mockito.doThrow(connectionException).when(storagePoolMonitor).processConnect(Mockito.eq(host), Mockito.eq(cmds), Mockito.eq(false));
Mockito.doReturn(true).when(mgr).handleDisconnectWithoutInvestigation(Mockito.any(attache.getClass()), Mockito.any(Event.class), Mockito.anyBoolean(), Mockito.anyBoolean());
try {
mgr.notifyMonitorsOfConnection(attache, cmds, false);
Assert.fail("Connection Exception was expected");
} catch (final ConnectionException e) {
Assert.assertEquals(e.getMessage(), connectionException.getMessage());
}
Mockito.verify(mgr, Mockito.times(1)).handleDisconnectWithoutInvestigation(Mockito.any(attache.getClass()), Mockito.eq(Event.AgentDisconnected), Mockito.eq(true), Mockito.eq(true));
}
use of com.cloud.legacymodel.exceptions.ConnectionException in project cosmic by MissionCriticalCloud.
the class XcpServerDiscoverer method processConnect.
@Override
public void processConnect(final com.cloud.legacymodel.dc.Host agent, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
for (final StartupCommand startupCommand : startupCommands) {
if (!(startupCommand instanceof StartupRoutingCommand)) {
return;
}
final long agentId = agent.getId();
final StartupRoutingCommand startup = (StartupRoutingCommand) startupCommand;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
final HostVO host = this._hostDao.findById(agentId);
final ClusterVO cluster = this._clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
this._clusterDao.update(cluster.getId(), cluster);
} else if (!cluster.getGuid().equals(startup.getPool())) {
final String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
final Map<String, String> details = startup.getHostDetails();
final String prodBrand = details.get("product_brand").trim();
final String prodVersion = details.get("product_version").trim();
final String hotfix = details.get(XenserverConfigs.XS620HotFix);
final String prodVersionTextShort = details.get("product_version_text_short");
final String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
if (!resource.equals(host.getResource())) {
final String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
s_logger.debug(msg);
host.setResource(resource);
host.setSetup(false);
this._hostDao.update(agentId, host);
throw new HypervisorVersionChangedException(msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
final HostEnvironment env = new HostEnvironment();
final SetupCommand setup = new SetupCommand(env);
if (this._setupMultipath) {
setup.setMultipathOn();
}
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
final Answer answer = this._agentMgr.send(agentId, setup);
if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
host.setHypervisorVersion(prodVersion);
this._hostDao.update(host.getId(), host);
if (((SetupAnswer) answer).needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
}
} catch (final AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (final OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
}
use of com.cloud.legacymodel.exceptions.ConnectionException in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method processConnect.
@Override
public void processConnect(final Host host, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
for (final StartupCommand startupCommand : startupCommands) {
if (!(startupCommand instanceof StartupRoutingCommand)) {
return;
}
final long hostId = host.getId();
final StartupRoutingCommand startup = (StartupRoutingCommand) startupCommand;
final String dataCenter = startup.getDataCenter();
long dcId = -1;
Zone dc = _zoneRepository.findByName(dataCenter);
if (dc == null) {
try {
dcId = Long.parseLong(dataCenter);
dc = _zoneRepository.findById(dcId).orElse(null);
} catch (final NumberFormatException e) {
}
}
if (dc == null) {
throw new IllegalArgumentException("Host " + startup.getPrivateIpAddress() + " sent incorrect data center: " + dataCenter);
}
dcId = dc.getId();
final HypervisorType hypervisorType = startup.getHypervisorType();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host's hypervisorType is: " + hypervisorType);
}
final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<>();
// list all physicalnetworks in the zone & for each get the network names
final List<PhysicalNetworkVO> physicalNtwkList = _physicalNetworkDao.listByZone(dcId);
for (final PhysicalNetworkVO pNtwk : physicalNtwkList) {
final String publicName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Public, hypervisorType);
final String privateName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Management, hypervisorType);
final String guestName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Guest, hypervisorType);
final String storageName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Storage, hypervisorType);
// String controlName = _pNTrafficTypeDao._networkModel.getNetworkTag(pNtwk.getId(), TrafficType.Control, hypervisorType);
final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
info.setPhysicalNetworkId(pNtwk.getId());
info.setGuestNetworkName(guestName);
info.setPrivateNetworkName(privateName);
info.setPublicNetworkName(publicName);
info.setStorageNetworkName(storageName);
final PhysicalNetworkTrafficTypeVO mgmtTraffic = _pNTrafficTypeDao.findBy(pNtwk.getId(), TrafficType.Management);
if (mgmtTraffic != null) {
final String vlan = mgmtTraffic.getVlan();
info.setMgmtVlan(vlan);
}
networkInfoList.add(info);
}
// send the names to the agent
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending CheckNetworkCommand to check the Network is setup correctly on Agent");
}
final CheckNetworkCommand nwCmd = new CheckNetworkCommand(networkInfoList);
final CheckNetworkAnswer answer = (CheckNetworkAnswer) _agentMgr.easySend(hostId, nwCmd);
if (answer == null) {
s_logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId());
throw new ConnectionException(true, "Unable to get an answer to the CheckNetworkCommand from agent: " + host.getId());
}
if (!answer.getResult()) {
s_logger.warn("Unable to setup agent " + hostId + " due to " + answer.getDetails());
final String msg = "Incorrect Network setup on agent, Reinitialize agent after network names are setup, details : " + answer.getDetails();
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, host.getPodId(), msg, msg);
throw new ConnectionException(true, msg);
} else {
if (answer.needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after network setup.");
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Network setup is correct on Agent");
}
return;
}
}
}
use of com.cloud.legacymodel.exceptions.ConnectionException in project cosmic by MissionCriticalCloud.
the class AgentManagerImpl method notifyMonitorsOfConnection.
protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, final StartupCommand[] cmd, final boolean forRebalance) throws ConnectionException {
final long hostId = attache.getId();
final HostVO host = this._hostDao.findById(hostId);
for (final Pair<Integer, Listener> monitor : this._hostMonitors) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName());
}
try {
monitor.second().processConnect(host, cmd, forRebalance);
} catch (final Exception e) {
if (e instanceof ConnectionException) {
final ConnectionException ce = (ConnectionException) e;
if (ce.isSetupError()) {
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw ce;
} else {
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
return attache;
}
} else if (e instanceof HypervisorVersionChangedException) {
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
} else {
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
}
}
}
final Long dcId = host.getDataCenterId();
final ReadyCommand ready = new ReadyCommand(dcId, host.getId());
final Answer answer = easySend(hostId, ready);
if (answer == null || !answer.getResult()) {
// this is tricky part for secondary storage
// make it as disconnected, wait for secondary storage VM to be up
// return the attache instead of null, even it is disconnectede
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
}
agentStatusTransitTo(host, Event.Ready, this._nodeId);
attache.ready();
return attache;
}
use of com.cloud.legacymodel.exceptions.ConnectionException in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method createLocalStorage.
@DB
@Override
public StoragePool createLocalStorage(final Host host, final StoragePoolInfo pInfo) throws ConnectionException {
final DataCenterVO dc = this._dcDao.findById(host.getDataCenterId());
if (dc == null) {
return null;
}
final DataStore store;
StoragePoolVO pool = this._storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), host.getName(), pInfo.getLocalPath(), pInfo.getUuid());
try {
if (pool == null) {
// the path can be different, but if they have the same uuid, assume they are the same storage
pool = this._storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), host.getName(), null, pInfo.getUuid());
if (pool != null) {
s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different path " + pInfo.getLocalPath() + ", still treat it as the same pool");
}
}
final DataStoreProvider provider = this._dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
if (pool == null) {
final Map<String, Object> params = new HashMap<>();
params.put("zoneId", host.getDataCenterId());
params.put("clusterId", host.getClusterId());
params.put("podId", host.getPodId());
params.put("url", pInfo.getPoolType().toString() + "://" + host.getName() + "/" + pInfo.getLocalPath());
params.put("name", pInfo.getUuid());
params.put("localStorage", true);
params.put("details", pInfo.getDetails());
params.put("uuid", pInfo.getUuid());
params.put("providerName", provider.getName());
store = lifeCycle.initialize(params);
} else {
store = this._dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
pool = this._storagePoolDao.findById(store.getId());
if (pool.getStatus() != StoragePoolStatus.Maintenance && pool.getStatus() != StoragePoolStatus.Removed) {
final HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
lifeCycle.attachHost(store, scope, pInfo);
}
} catch (final Exception e) {
s_logger.warn("Unable to setup the local storage pool for " + host, e);
throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
}
// Enable the pool
pool.setStatus(StoragePoolStatus.Up);
this._storagePoolDao.persist(pool);
return pool;
}
Aggregations