Search in sources :

Example 46 with HostVO

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;
}
Also used : ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) HashSet(java.util.HashSet)

Example 47 with HostVO

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);
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BaremetalSwitchBackend(com.cloud.baremetal.networkservice.BaremetalSwitchBackend) BaremetalVlanStruct(com.cloud.baremetal.networkservice.BaremetalVlanStruct) HostVO(com.cloud.host.HostVO)

Example 48 with HostVO

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());
                }
            }
        }
    }
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) ArrayList(java.util.ArrayList) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) DB(com.cloud.utils.db.DB)

Example 49 with HostVO

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);
            }
        }
    }
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO)

Example 50 with HostVO

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;
}
Also used : State(com.cloud.vm.VirtualMachine.State) RedundantState(com.cloud.network.router.VirtualRouter.RedundantState) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46