Search in sources :

Example 16 with CheckNetworkCommand

use of com.cloud.agent.api.CheckNetworkCommand in project cosmic by MissionCriticalCloud.

the class XenServer610WrapperTest method testCheckNetworkCommandFailure.

@Test
public void testCheckNetworkCommandFailure() {
    final XenServer610Resource xenServer610Resource = new XenServer610Resource();
    final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
    final List<PhysicalNetworkSetupInfo> setupInfos = new ArrayList<>();
    setupInfos.add(info);
    final CheckNetworkCommand checkNet = new CheckNetworkCommand(setupInfos);
    final Answer answer = xenServer610Resource.executeRequest(checkNet);
    assertTrue(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) XenServer610Resource(com.cloud.hypervisor.xenserver.resource.XenServer610Resource) ArrayList(java.util.ArrayList) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo) Test(org.junit.Test)

Example 17 with CheckNetworkCommand

use of com.cloud.agent.api.CheckNetworkCommand in project cosmic by MissionCriticalCloud.

the class XenServer620WrapperTest method testCheckNetworkCommandFailure.

@Test
public void testCheckNetworkCommandFailure() {
    final XenServer620Resource xenServer620Resource = new XenServer620Resource();
    final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
    final List<PhysicalNetworkSetupInfo> setupInfos = new ArrayList<>();
    setupInfos.add(info);
    final CheckNetworkCommand checkNet = new CheckNetworkCommand(setupInfos);
    final Answer answer = xenServer620Resource.executeRequest(checkNet);
    assertTrue(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) ArrayList(java.util.ArrayList) XenServer620Resource(com.cloud.hypervisor.xenserver.resource.XenServer620Resource) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo) Test(org.junit.Test)

Example 18 with CheckNetworkCommand

use of com.cloud.agent.api.CheckNetworkCommand in project cloudstack by apache.

the class DummyResource method executeRequest.

@Override
public Answer executeRequest(Command cmd) {
    if (cmd instanceof CheckNetworkCommand) {
        return new CheckNetworkAnswer((CheckNetworkCommand) cmd, true, null);
    }
    System.out.println("Received Command: " + cmd.toString());
    Answer answer = new Answer(cmd, !_negative, "response");
    System.out.println("Replying with: " + answer.toString());
    return answer;
}
Also used : CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) Answer(com.cloud.agent.api.Answer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand)

Example 19 with CheckNetworkCommand

use of com.cloud.agent.api.CheckNetworkCommand in project cloudstack by apache.

the class CheckNetworkCommandTest method setUp.

@Before
public void setUp() {
    @SuppressWarnings("unchecked") List<PhysicalNetworkSetupInfo> net = Mockito.mock(List.class);
    cnc = new CheckNetworkCommand(net);
}
Also used : CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo) Before(org.junit.Before)

Example 20 with CheckNetworkCommand

use of com.cloud.agent.api.CheckNetworkCommand 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

CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)30 Answer (com.cloud.agent.api.Answer)26 PhysicalNetworkSetupInfo (com.cloud.network.PhysicalNetworkSetupInfo)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)21 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)8 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 AttachAnswer (com.cloud.storage.command.AttachAnswer)6 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)5 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)5 RebootAnswer (com.cloud.agent.api.RebootAnswer)4 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)3 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)3 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)3 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)3 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)3