Search in sources :

Example 11 with PhysicalNetworkTrafficTypeVO

use of com.cloud.network.dao.PhysicalNetworkTrafficTypeVO in project cloudstack by apache.

the class NetworkOrchestrator method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    final long hostId = host.getId();
    final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    final String dataCenter = startup.getDataCenter();
    long dcId = -1;
    DataCenterVO dc = _dcDao.findByName(dataCenter);
    if (dc == null) {
        try {
            dcId = Long.parseLong(dataCenter);
            dc = _dcDao.findById(dcId);
        } 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<PhysicalNetworkSetupInfo>();
    // 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;
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Aggregations

PhysicalNetworkTrafficTypeVO (com.cloud.network.dao.PhysicalNetworkTrafficTypeVO)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)5 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)5 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)5 InvalidParameterException (java.security.InvalidParameterException)5 ConfigurationException (javax.naming.ConfigurationException)5 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)4 ActionEvent (com.cloud.event.ActionEvent)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ArrayList (java.util.ArrayList)3 DataCenterVO (com.cloud.dc.DataCenterVO)2 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1 Command (com.cloud.agent.api.Command)1 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)1 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)1