use of com.cloud.host.HostVO in project cloudstack by apache.
the class ImplicitDedicationPlanner method getUpdatedClusterList.
private List<Long> getUpdatedClusterList(List<Long> clusterList, Set<Long> hostsSet) {
List<Long> updatedClusterList = new ArrayList<Long>();
for (Long cluster : clusterList) {
List<HostVO> hosts = resourceMgr.listAllHostsInCluster(cluster);
Set<Long> hostsInClusterSet = new HashSet<Long>();
for (HostVO host : hosts) {
hostsInClusterSet.add(host.getId());
}
if (!hostsSet.containsAll(hostsInClusterSet)) {
updatedClusterList.add(cluster);
}
}
return updatedClusterList;
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class BaremetalVlanManagerImpl method releaseVlan.
@Override
public void releaseVlan(Network nw, VirtualMachineProfile vm) {
List<BaremetalRctVO> vos = rctDao.listAll();
if (vos.isEmpty()) {
throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
}
BaremetalRctVO vo = vos.get(0);
BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
RackPair rp = findRack(rct, host.getPrivateMacAddress());
assert rp != null : String.format("where is my rack???");
int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
BaremetalVlanStruct struct = new BaremetalVlanStruct();
struct.setHostMac(rp.host.getMac());
struct.setPort(rp.host.getPort());
struct.setSwitchIp(rp.rack.getL2Switch().getIp());
struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
struct.setSwitchType(rp.rack.getL2Switch().getType());
struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
struct.setVlan(vlan);
BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
backend.removePortFromVlan(struct);
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method updateSite2SiteVpnConnectionState.
@DB
protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers) {
for (final DomainRouterVO router : routers) {
if (router.getRole() == Role.INTERNAL_LB_VM) {
continue;
}
final List<Site2SiteVpnConnectionVO> conns = _s2sVpnMgr.getConnectionsForRouter(router);
if (conns == null || conns.isEmpty()) {
continue;
}
if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.PRIMARY) {
continue;
}
if (router.getState() != VirtualMachine.State.Running) {
for (final Site2SiteVpnConnectionVO conn : conns) {
if (conn.getState() != Site2SiteVpnConnection.State.Error) {
conn.setState(Site2SiteVpnConnection.State.Disconnected);
_s2sVpnConnectionDao.persist(conn);
}
}
continue;
}
final List<String> ipList = new ArrayList<String>();
for (final Site2SiteVpnConnectionVO conn : conns) {
if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected && conn.getState() != Site2SiteVpnConnection.State.Connecting) {
continue;
}
final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
ipList.add(gw.getGatewayIp());
}
final String privateIP = router.getPrivateIpAddress();
final HostVO host = _hostDao.findById(router.getHostId());
if (host == null || host.getState() != Status.Up) {
continue;
} else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
/* Only cover hosts managed by this management server */
continue;
} else if (privateIP != null) {
final CheckS2SVpnConnectionsCommand command = new CheckS2SVpnConnectionsCommand(ipList);
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
command.setWait(30);
final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
CheckS2SVpnConnectionsAnswer answer = null;
if (origAnswer instanceof CheckS2SVpnConnectionsAnswer) {
answer = (CheckS2SVpnConnectionsAnswer) origAnswer;
} else {
s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
continue;
}
if (!answer.getResult()) {
s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
continue;
}
for (final Site2SiteVpnConnectionVO conn : conns) {
final Site2SiteVpnConnectionVO lock = _s2sVpnConnectionDao.acquireInLockTable(conn.getId());
if (lock == null) {
throw new CloudRuntimeException("Unable to acquire lock for site to site vpn connection id " + conn.getId());
}
try {
if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected && conn.getState() != Site2SiteVpnConnection.State.Connecting) {
continue;
}
final Site2SiteVpnConnection.State oldState = conn.getState();
final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
if (answer.isIPPresent(gw.getGatewayIp())) {
if (answer.isConnected(gw.getGatewayIp())) {
conn.setState(Site2SiteVpnConnection.State.Connected);
} else {
conn.setState(Site2SiteVpnConnection.State.Disconnected);
}
_s2sVpnConnectionDao.persist(conn);
if (oldState != conn.getState()) {
final String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switched from " + oldState + " to " + conn.getState();
final String context = "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " + " just switched from " + oldState + " to " + conn.getState();
s_logger.info(context);
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
}
}
} finally {
_s2sVpnConnectionDao.releaseFromLockTable(lock.getId());
}
}
}
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method recoverRedundantNetwork.
// Ensure router status is update to date before execute this function. The
// function would try best to recover all routers except PRIMARY
protected void recoverRedundantNetwork(final DomainRouterVO primaryRouter, final DomainRouterVO backupRouter) {
if (primaryRouter.getState() == VirtualMachine.State.Running && backupRouter.getState() == VirtualMachine.State.Running) {
final HostVO primaryHost = _hostDao.findById(primaryRouter.getHostId());
final HostVO backupHost = _hostDao.findById(backupRouter.getHostId());
if (primaryHost.getState() == Status.Up && backupHost.getState() == Status.Up) {
final String title = "Reboot " + backupRouter.getInstanceName() + " to ensure redundant virtual routers work";
if (s_logger.isDebugEnabled()) {
s_logger.debug(title);
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, backupRouter.getDataCenterId(), backupRouter.getPodIdToDeployIn(), title, title);
try {
rebootRouter(backupRouter.getId(), true, false);
} catch (final ConcurrentOperationException e) {
s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
} catch (final ResourceUnavailableException e) {
s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
} catch (final InsufficientCapacityException e) {
s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
}
}
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class NetworkHelperImpl method startRouters.
@Override
public List<DomainRouterVO> startRouters(final RouterDeploymentDefinition routerDeploymentDefinition) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final List<DomainRouterVO> runningRouters = new ArrayList<DomainRouterVO>();
for (DomainRouterVO router : routerDeploymentDefinition.getRouters()) {
boolean skip = false;
final State state = router.getState();
if (router.getHostId() != null && state != State.Running) {
final HostVO host = _hostDao.findById(router.getHostId());
if (host == null || host.getState() != Status.Up) {
skip = true;
}
}
if (!skip) {
if (state != State.Running) {
router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), routerDeploymentDefinition.getParams());
}
if (router != null) {
runningRouters.add(router);
}
}
}
return runningRouters;
}
Aggregations