Search in sources :

Example 66 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class NiciraNvpElement method deleteNiciraNvpDevice.

@Override
public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
    Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
    NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao.findById(niciraDeviceId);
    if (niciraNvpDevice == null) {
        throw new InvalidParameterValueException("Could not find a nicira device with id " + niciraDeviceId);
    }
    // Find the physical network we work for
    Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        // Lets see if there are networks that use us
        // Find the nicira networks on this physical network
        List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
        if (networkList != null) {
            // Networks with broadcast type lswitch are ours
            for (NetworkVO network : networkList) {
                if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
                    if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
                        throw new CloudRuntimeException("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
                    }
                }
            }
        }
    }
    HostVO niciraHost = hostDao.findById(niciraNvpDevice.getHostId());
    Long hostId = niciraHost.getId();
    niciraHost.setResourceState(ResourceState.Maintenance);
    hostDao.update(hostId, niciraHost);
    resourceMgr.deleteHost(hostId, false, false);
    niciraNvpDao.remove(niciraDeviceId);
    return true;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO)

Example 67 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class NiciraNvpElement method applyPFRules.

/**
 * From interface PortForwardingServiceProvider
 */
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Service.PortForwarding)) {
        return false;
    }
    List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    if (routermapping == null) {
        s_logger.error("No logical router uuid found for network " + network.getDisplayText());
        return false;
    }
    List<PortForwardingRuleTO> portForwardingRules = new ArrayList<PortForwardingRuleTO>();
    for (PortForwardingRule rule : rules) {
        IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = vlanDao.findById(sourceIp.getVlanId());
        PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        portForwardingRules.add(ruleTO);
    }
    ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
    ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    return answer.getResult();
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) ConfigurePortForwardingRulesOnLogicalRouterCommand(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) ConfigurePortForwardingRulesOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 68 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class HostDaoImpl method findOldestExistentHypervisorHostInCluster.

@Override
public HostVO findOldestExistentHypervisorHostInCluster(long clusterId) {
    SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
    sc.setParameters("type", Host.Type.Routing);
    sc.setParameters("cluster", clusterId);
    sc.setParameters("status", Status.Up);
    sc.setParameters("resourceState", ResourceState.Enabled);
    Filter orderByFilter = new Filter(HostVO.class, "created", true, null, null);
    List<HostVO> hosts = search(sc, orderByFilter, null, false);
    if (hosts != null && hosts.size() > 0) {
        return hosts.get(0);
    }
    return null;
}
Also used : Filter(com.cloud.utils.db.Filter) HostVO(com.cloud.host.HostVO)

Example 69 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class HostDaoImpl method init.

@PostConstruct
public void init() {
    MaintenanceCountSearch = createSearchBuilder();
    MaintenanceCountSearch.and("cluster", MaintenanceCountSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    MaintenanceCountSearch.and("resourceState", MaintenanceCountSearch.entity().getResourceState(), SearchCriteria.Op.IN);
    MaintenanceCountSearch.done();
    HostTypeCountSearch = createSearchBuilder();
    HostTypeCountSearch.and("type", HostTypeCountSearch.entity().getType(), SearchCriteria.Op.EQ);
    HostTypeCountSearch.done();
    HostTypeZoneCountSearch = createSearchBuilder();
    HostTypeZoneCountSearch.and("type", HostTypeZoneCountSearch.entity().getType(), SearchCriteria.Op.EQ);
    HostTypeZoneCountSearch.and("dc", HostTypeZoneCountSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    HostTypeZoneCountSearch.and("removed", HostTypeZoneCountSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
    HostTypeZoneCountSearch.done();
    TypePodDcStatusSearch = createSearchBuilder();
    HostVO entity = TypePodDcStatusSearch.entity();
    TypePodDcStatusSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
    TypePodDcStatusSearch.and("pod", entity.getPodId(), SearchCriteria.Op.EQ);
    TypePodDcStatusSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
    TypePodDcStatusSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
    TypePodDcStatusSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
    TypePodDcStatusSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
    TypePodDcStatusSearch.done();
    MsStatusSearch = createSearchBuilder();
    MsStatusSearch.and("ms", MsStatusSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
    MsStatusSearch.and("type", MsStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
    MsStatusSearch.and("resourceState", MsStatusSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
    MsStatusSearch.done();
    TypeDcSearch = createSearchBuilder();
    TypeDcSearch.and("type", TypeDcSearch.entity().getType(), SearchCriteria.Op.EQ);
    TypeDcSearch.and("dc", TypeDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    TypeDcSearch.done();
    SecondaryStorageVMSearch = createSearchBuilder();
    SecondaryStorageVMSearch.and("type", SecondaryStorageVMSearch.entity().getType(), SearchCriteria.Op.EQ);
    SecondaryStorageVMSearch.and("dc", SecondaryStorageVMSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    SecondaryStorageVMSearch.and("status", SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    SecondaryStorageVMSearch.done();
    TypeDcStatusSearch = createSearchBuilder();
    TypeDcStatusSearch.and("type", TypeDcStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
    TypeDcStatusSearch.and("dc", TypeDcStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    TypeDcStatusSearch.and("status", TypeDcStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    TypeDcStatusSearch.and("resourceState", TypeDcStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
    TypeDcStatusSearch.done();
    TypeClusterStatusSearch = createSearchBuilder();
    TypeClusterStatusSearch.and("type", TypeClusterStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
    TypeClusterStatusSearch.and("cluster", TypeClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    TypeClusterStatusSearch.and("status", TypeClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    TypeClusterStatusSearch.and("resourceState", TypeClusterStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
    TypeClusterStatusSearch.done();
    IdStatusSearch = createSearchBuilder();
    IdStatusSearch.and("id", IdStatusSearch.entity().getId(), SearchCriteria.Op.EQ);
    IdStatusSearch.and("states", IdStatusSearch.entity().getStatus(), SearchCriteria.Op.IN);
    IdStatusSearch.done();
    DcPrivateIpAddressSearch = createSearchBuilder();
    DcPrivateIpAddressSearch.and("privateIpAddress", DcPrivateIpAddressSearch.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
    DcPrivateIpAddressSearch.and("dc", DcPrivateIpAddressSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    DcPrivateIpAddressSearch.done();
    DcStorageIpAddressSearch = createSearchBuilder();
    DcStorageIpAddressSearch.and("storageIpAddress", DcStorageIpAddressSearch.entity().getStorageIpAddress(), SearchCriteria.Op.EQ);
    DcStorageIpAddressSearch.and("dc", DcStorageIpAddressSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    DcStorageIpAddressSearch.done();
    PublicIpAddressSearch = createSearchBuilder();
    PublicIpAddressSearch.and("publicIpAddress", PublicIpAddressSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
    PublicIpAddressSearch.done();
    UnremovedIpAddressSearch = createSearchBuilder();
    // We don't want any removed hosts
    UnremovedIpAddressSearch.and("removed", UnremovedIpAddressSearch.entity().getRemoved(), Op.NULL);
    UnremovedIpAddressSearch.and().op("publicIpAddress", UnremovedIpAddressSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
    UnremovedIpAddressSearch.or("privateIpAddress", UnremovedIpAddressSearch.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
    UnremovedIpAddressSearch.cp();
    UnremovedIpAddressSearch.done();
    GuidSearch = createSearchBuilder();
    GuidSearch.and("guid", GuidSearch.entity().getGuid(), SearchCriteria.Op.EQ);
    GuidSearch.done();
    DcSearch = createSearchBuilder();
    DcSearch.and("dc", DcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    DcSearch.and("hypervisorType", DcSearch.entity().getHypervisorType(), Op.EQ);
    DcSearch.and("type", DcSearch.entity().getType(), Op.EQ);
    DcSearch.and("status", DcSearch.entity().getStatus(), Op.EQ);
    DcSearch.and("resourceState", DcSearch.entity().getResourceState(), Op.EQ);
    DcSearch.done();
    ClusterStatusSearch = createSearchBuilder();
    ClusterStatusSearch.and("cluster", ClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    ClusterStatusSearch.and("status", ClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    ClusterStatusSearch.done();
    TypeNameZoneSearch = createSearchBuilder();
    TypeNameZoneSearch.and("name", TypeNameZoneSearch.entity().getName(), SearchCriteria.Op.EQ);
    TypeNameZoneSearch.and("type", TypeNameZoneSearch.entity().getType(), SearchCriteria.Op.EQ);
    TypeNameZoneSearch.and("zoneId", TypeNameZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    TypeNameZoneSearch.done();
    PodSearch = createSearchBuilder();
    PodSearch.and("podId", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
    PodSearch.done();
    ClusterSearch = createSearchBuilder();
    ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    ClusterSearch.done();
    TypeSearch = createSearchBuilder();
    TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ);
    TypeSearch.done();
    StatusSearch = createSearchBuilder();
    StatusSearch.and("status", StatusSearch.entity().getStatus(), SearchCriteria.Op.IN);
    StatusSearch.done();
    ResourceStateSearch = createSearchBuilder();
    ResourceStateSearch.and("resourceState", ResourceStateSearch.entity().getResourceState(), SearchCriteria.Op.IN);
    ResourceStateSearch.done();
    NameLikeSearch = createSearchBuilder();
    NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
    NameLikeSearch.done();
    NameSearch = createSearchBuilder();
    NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
    NameSearch.done();
    SequenceSearch = createSearchBuilder();
    SequenceSearch.and("id", SequenceSearch.entity().getId(), SearchCriteria.Op.EQ);
    // SequenceSearch.addRetrieve("sequence", SequenceSearch.entity().getSequence());
    SequenceSearch.done();
    DirectlyConnectedSearch = createSearchBuilder();
    DirectlyConnectedSearch.and("resource", DirectlyConnectedSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    DirectlyConnectedSearch.and("ms", DirectlyConnectedSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
    DirectlyConnectedSearch.and("statuses", DirectlyConnectedSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    DirectlyConnectedSearch.and("resourceState", DirectlyConnectedSearch.entity().getResourceState(), SearchCriteria.Op.NOTIN);
    DirectlyConnectedSearch.done();
    ClusterHypervisorSearch = createSearchBuilder();
    ClusterHypervisorSearch.and("clusterId", ClusterHypervisorSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    ClusterHypervisorSearch.and("hypervisor", ClusterHypervisorSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
    ClusterHypervisorSearch.and("type", ClusterHypervisorSearch.entity().getType(), SearchCriteria.Op.EQ);
    ClusterHypervisorSearch.and("status", ClusterHypervisorSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    ClusterHypervisorSearch.done();
    UnmanagedDirectConnectSearch = createSearchBuilder();
    UnmanagedDirectConnectSearch.and("resource", UnmanagedDirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    UnmanagedDirectConnectSearch.and("server", UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
    UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
    UnmanagedDirectConnectSearch.and("resourceStates", UnmanagedDirectConnectSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
    UnmanagedDirectConnectSearch.and("clusterIn", UnmanagedDirectConnectSearch.entity().getClusterId(), SearchCriteria.Op.IN);
    try {
        HostTransferSearch = _hostTransferDao.createSearchBuilder();
    } catch (Throwable e) {
        s_logger.debug("error", e);
    }
    HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL);
    UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), JoinType.LEFTOUTER);
    ClusterManagedSearch = _clusterDao.createSearchBuilder();
    ClusterManagedSearch.and("managed", ClusterManagedSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
    UnmanagedDirectConnectSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getClusterId(), JoinType.INNER);
    UnmanagedDirectConnectSearch.done();
    DirectConnectSearch = createSearchBuilder();
    DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
    DirectConnectSearch.and().op("nullserver", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
    DirectConnectSearch.or("server", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
    DirectConnectSearch.cp();
    DirectConnectSearch.done();
    UnmanagedApplianceSearch = createSearchBuilder();
    UnmanagedApplianceSearch.and("resource", UnmanagedApplianceSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    UnmanagedApplianceSearch.and("server", UnmanagedApplianceSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
    UnmanagedApplianceSearch.and("types", UnmanagedApplianceSearch.entity().getType(), SearchCriteria.Op.IN);
    UnmanagedApplianceSearch.and("lastPinged", UnmanagedApplianceSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
    UnmanagedApplianceSearch.done();
    AvailHypevisorInZone = createSearchBuilder();
    AvailHypevisorInZone.and("zoneId", AvailHypevisorInZone.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    AvailHypevisorInZone.and("hostId", AvailHypevisorInZone.entity().getId(), SearchCriteria.Op.NEQ);
    AvailHypevisorInZone.and("type", AvailHypevisorInZone.entity().getType(), SearchCriteria.Op.EQ);
    AvailHypevisorInZone.groupBy(AvailHypevisorInZone.entity().getHypervisorType());
    AvailHypevisorInZone.done();
    HostsInStatusSearch = createSearchBuilder(Long.class);
    HostsInStatusSearch.selectFields(HostsInStatusSearch.entity().getId());
    HostsInStatusSearch.and("dc", HostsInStatusSearch.entity().getDataCenterId(), Op.EQ);
    HostsInStatusSearch.and("pod", HostsInStatusSearch.entity().getPodId(), Op.EQ);
    HostsInStatusSearch.and("cluster", HostsInStatusSearch.entity().getClusterId(), Op.EQ);
    HostsInStatusSearch.and("type", HostsInStatusSearch.entity().getType(), Op.EQ);
    HostsInStatusSearch.and("statuses", HostsInStatusSearch.entity().getStatus(), Op.IN);
    HostsInStatusSearch.done();
    CountRoutingByDc = createSearchBuilder(Long.class);
    CountRoutingByDc.select(null, Func.COUNT, null);
    CountRoutingByDc.and("dc", CountRoutingByDc.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    CountRoutingByDc.and("type", CountRoutingByDc.entity().getType(), SearchCriteria.Op.EQ);
    CountRoutingByDc.and("status", CountRoutingByDc.entity().getStatus(), SearchCriteria.Op.EQ);
    CountRoutingByDc.done();
    ManagedDirectConnectSearch = createSearchBuilder();
    ManagedDirectConnectSearch.and("resource", ManagedDirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    ManagedDirectConnectSearch.and("server", ManagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
    ManagedDirectConnectSearch.done();
    ManagedRoutingServersSearch = createSearchBuilder();
    ManagedRoutingServersSearch.and("server", ManagedRoutingServersSearch.entity().getManagementServerId(), SearchCriteria.Op.NNULL);
    ManagedRoutingServersSearch.and("type", ManagedRoutingServersSearch.entity().getType(), SearchCriteria.Op.EQ);
    ManagedRoutingServersSearch.done();
    RoutingSearch = createSearchBuilder();
    RoutingSearch.and("type", RoutingSearch.entity().getType(), SearchCriteria.Op.EQ);
    RoutingSearch.done();
    HostsForReconnectSearch = createSearchBuilder();
    HostsForReconnectSearch.and("resource", HostsForReconnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    HostsForReconnectSearch.and("server", HostsForReconnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
    HostsForReconnectSearch.and("lastPinged", HostsForReconnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
    HostsForReconnectSearch.and("resourceStates", HostsForReconnectSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
    HostsForReconnectSearch.and("cluster", HostsForReconnectSearch.entity().getClusterId(), SearchCriteria.Op.NNULL);
    HostsForReconnectSearch.and("status", HostsForReconnectSearch.entity().getStatus(), SearchCriteria.Op.IN);
    HostsForReconnectSearch.done();
    ClustersOwnedByMSSearch = createSearchBuilder(Long.class);
    ClustersOwnedByMSSearch.select(null, Func.DISTINCT, ClustersOwnedByMSSearch.entity().getClusterId());
    ClustersOwnedByMSSearch.and("resource", ClustersOwnedByMSSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    ClustersOwnedByMSSearch.and("cluster", ClustersOwnedByMSSearch.entity().getClusterId(), SearchCriteria.Op.NNULL);
    ClustersOwnedByMSSearch.and("server", ClustersOwnedByMSSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
    ClustersOwnedByMSSearch.done();
    ClustersForHostsNotOwnedByAnyMSSearch = createSearchBuilder(Long.class);
    ClustersForHostsNotOwnedByAnyMSSearch.select(null, Func.DISTINCT, ClustersForHostsNotOwnedByAnyMSSearch.entity().getClusterId());
    ClustersForHostsNotOwnedByAnyMSSearch.and("resource", ClustersForHostsNotOwnedByAnyMSSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    ClustersForHostsNotOwnedByAnyMSSearch.and("cluster", ClustersForHostsNotOwnedByAnyMSSearch.entity().getClusterId(), SearchCriteria.Op.NNULL);
    ClustersForHostsNotOwnedByAnyMSSearch.and("server", ClustersForHostsNotOwnedByAnyMSSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
    ClusterManagedSearch = _clusterDao.createSearchBuilder();
    ClusterManagedSearch.and("managed", ClusterManagedSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
    ClustersForHostsNotOwnedByAnyMSSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(), ClustersForHostsNotOwnedByAnyMSSearch.entity().getClusterId(), JoinType.INNER);
    ClustersForHostsNotOwnedByAnyMSSearch.done();
    AllClustersSearch = _clusterDao.createSearchBuilder(Long.class);
    AllClustersSearch.select(null, Func.NATIVE, AllClustersSearch.entity().getId());
    AllClustersSearch.and("managed", AllClustersSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
    AllClustersSearch.done();
    HostsInClusterSearch = createSearchBuilder();
    HostsInClusterSearch.and("resource", HostsInClusterSearch.entity().getResource(), SearchCriteria.Op.NNULL);
    HostsInClusterSearch.and("cluster", HostsInClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    HostsInClusterSearch.and("server", HostsInClusterSearch.entity().getManagementServerId(), SearchCriteria.Op.NNULL);
    HostsInClusterSearch.done();
    HostIdSearch = createSearchBuilder(Long.class);
    HostIdSearch.selectFields(HostIdSearch.entity().getId());
    HostIdSearch.and("dataCenterId", HostIdSearch.entity().getDataCenterId(), Op.EQ);
    HostIdSearch.done();
    _statusAttr = _allAttributes.get("status");
    _msIdAttr = _allAttributes.get("managementServerId");
    _pingTimeAttr = _allAttributes.get("lastPinged");
    _resourceStateAttr = _allAttributes.get("resourceState");
    assert (_statusAttr != null && _msIdAttr != null && _pingTimeAttr != null) : "Couldn't find one of these attributes";
}
Also used : HostVO(com.cloud.host.HostVO) PostConstruct(javax.annotation.PostConstruct)

Example 70 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class HostDaoImpl method resetHosts.

/*
     * Find hosts which is in Disconnected, Down, Alert and ping timeout and server is not null, set server to null
     */
private void resetHosts(long managementServerId, long lastPingSecondsAfter) {
    SearchCriteria<HostVO> sc = HostsForReconnectSearch.create();
    sc.setParameters("server", managementServerId);
    sc.setParameters("lastPinged", lastPingSecondsAfter);
    sc.setParameters("status", Status.Disconnected, Status.Down, Status.Alert);
    StringBuilder sb = new StringBuilder();
    // exclusive lock
    List<HostVO> hosts = lockRows(sc, null, true);
    for (HostVO host : hosts) {
        host.setManagementServerId(null);
        update(host.getId(), host);
        sb.append(host.getId());
        sb.append(" ");
    }
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Following hosts got reset: " + sb.toString());
    }
}
Also used : 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