Search in sources :

Example 6 with StartupRoutingCommand

use of com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
    for (final StartupCommand startupCommand : startupCommands) {
        if (!(startupCommand instanceof StartupRoutingCommand)) {
            return;
        }
        final long hostId = host.getId();
        final StartupRoutingCommand startup = (StartupRoutingCommand) startupCommand;
        final String dataCenter = startup.getDataCenter();
        long dcId = -1;
        Zone dc = _zoneRepository.findByName(dataCenter);
        if (dc == null) {
            try {
                dcId = Long.parseLong(dataCenter);
                dc = _zoneRepository.findById(dcId).orElse(null);
            } 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<>();
        // 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 : Zone(com.cloud.db.model.Zone) ArrayList(java.util.ArrayList) CheckNetworkAnswer(com.cloud.legacymodel.communication.answer.CheckNetworkAnswer) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) HypervisorType(com.cloud.model.enumeration.HypervisorType) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo)

Example 7 with StartupRoutingCommand

use of com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand in project cosmic by MissionCriticalCloud.

the class AgentManagerImpl method connectAgent.

protected void connectAgent(final Link link, final Command[] cmds, final Request request) {
    // send startupanswer to agent in the very beginning, so agent can move on without waiting for the answer for an undetermined time, if we put this logic into another
    // thread pool.
    final StartupAnswer[] answers = new StartupAnswer[cmds.length];
    Command cmd;
    for (int i = 0; i < cmds.length; i++) {
        cmd = cmds[i];
        if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand || cmd instanceof StartupStorageCommand) {
            answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, getPingInterval());
            break;
        }
    }
    Response response = null;
    response = new Response(request, answers[0], this._nodeId, -1);
    try {
        link.send(response.toBytes());
    } catch (final ClosedChannelException e) {
        s_logger.debug("Failed to send startupanswer: " + e.toString());
    }
    this._connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
}
Also used : StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) StartupProxyCommand(com.cloud.legacymodel.communication.command.startup.StartupProxyCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Response(com.cloud.common.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) StartupStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupStorageCommand) StartupSecondaryStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) CheckHealthCommand(com.cloud.legacymodel.communication.command.CheckHealthCommand) PingRoutingCommand(com.cloud.legacymodel.communication.command.PingRoutingCommand) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) StartupProxyCommand(com.cloud.legacymodel.communication.command.startup.StartupProxyCommand) StartupSecondaryStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand) StartupStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupStorageCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)

Example 8 with StartupRoutingCommand

use of com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method createHostVO.

protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags, final ResourceStateAdapter.Event stateEvent) {
    final StartupCommand startup = cmds[0];
    HostVO host = findHostByGuid(startup.getGuid());
    boolean isNew = false;
    if (host == null) {
        host = findHostByGuid(startup.getGuidWithoutResource());
    }
    if (host == null) {
        host = new HostVO(startup.getGuid());
        isNew = true;
    }
    String dataCenter = startup.getDataCenter();
    String pod = startup.getPod();
    final String cluster = startup.getCluster();
    if (pod != null && dataCenter != null && pod.equalsIgnoreCase("default") && dataCenter.equalsIgnoreCase("default")) {
        final List<HostPodVO> pods = this._podDao.listAllIncludingRemoved();
        for (final HostPodVO hpv : pods) {
            if (checkCIDR(hpv, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
                pod = hpv.getName();
                dataCenter = this._dcDao.findById(hpv.getDataCenterId()).getName();
                break;
            }
        }
    }
    long dcId;
    DataCenterVO dc = this._dcDao.findByName(dataCenter);
    if (dc == null) {
        try {
            dcId = Long.parseLong(dataCenter);
            dc = this._dcDao.findById(dcId);
        } catch (final NumberFormatException e) {
            s_logger.debug("Cannot parse " + dataCenter + " into Long.");
        }
    }
    if (dc == null) {
        throw new IllegalArgumentException("Host " + startup.getPrivateIpAddress() + " sent incorrect data center: " + dataCenter);
    }
    dcId = dc.getId();
    HostPodVO p = this._podDao.findByName(pod, dcId);
    if (p == null) {
        try {
            final long podId = Long.parseLong(pod);
            p = this._podDao.findById(podId);
        } catch (final NumberFormatException e) {
            s_logger.debug("Cannot parse " + pod + " into Long.");
        }
    }
    /*
         * ResourceStateAdapter is responsible for throwing Exception if Pod is
         * null and non-null is required. for example, XcpServerDiscoever.
         */
    final Long podId = p == null ? null : p.getId();
    Long clusterId = null;
    if (cluster != null) {
        try {
            clusterId = Long.valueOf(cluster);
        } catch (final NumberFormatException e) {
            if (podId != null) {
                ClusterVO c = this._clusterDao.findBy(cluster, podId.longValue());
                if (c == null) {
                    c = new ClusterVO(dcId, podId.longValue(), cluster);
                    c = this._clusterDao.persist(c);
                }
                clusterId = c.getId();
            }
        }
    }
    if (startup instanceof StartupRoutingCommand) {
        final StartupRoutingCommand ssCmd = (StartupRoutingCommand) startup;
        final List<String> implicitHostTags = ssCmd.getHostTags();
        if (!implicitHostTags.isEmpty()) {
            if (hostTags == null) {
                hostTags = this._hostTagsDao.gethostTags(host.getId());
            }
            if (hostTags != null) {
                implicitHostTags.removeAll(hostTags);
                hostTags.addAll(implicitHostTags);
            } else {
                hostTags = implicitHostTags;
            }
        }
    }
    host.setDataCenterId(dc.getId());
    host.setPodId(podId);
    host.setClusterId(clusterId);
    host.setPrivateIpAddress(startup.getPrivateIpAddress());
    host.setPrivateNetmask(startup.getPrivateNetmask());
    host.setPrivateMacAddress(startup.getPrivateMacAddress());
    host.setPublicIpAddress(startup.getPublicIpAddress());
    host.setPublicMacAddress(startup.getPublicMacAddress());
    host.setPublicNetmask(startup.getPublicNetmask());
    host.setStorageIpAddress(startup.getStorageIpAddress());
    host.setStorageMacAddress(startup.getStorageMacAddress());
    host.setStorageNetmask(startup.getStorageNetmask());
    host.setVersion(startup.getVersion());
    host.setName(startup.getName());
    host.setManagementServerId(this._nodeId);
    host.setStorageUrl(startup.getIqn());
    host.setLastPinged(System.currentTimeMillis() >> 10);
    host.setHostTags(hostTags);
    host.setDetails(details);
    if (startup.getStorageIpAddressDeux() != null) {
        host.setStorageIpAddressDeux(startup.getStorageIpAddressDeux());
        host.setStorageMacAddressDeux(startup.getStorageMacAddressDeux());
        host.setStorageNetmaskDeux(startup.getStorageNetmaskDeux());
    }
    if (resource != null) {
        /* null when agent is connected agent */
        host.setResource(resource.getClass().getName());
    }
    host = (HostVO) dispatchToStateAdapters(stateEvent, true, host, cmds, resource, details, hostTags);
    if (host == null) {
        throw new CloudRuntimeException("No resource state adapter response");
    }
    if (isNew) {
        host = this._hostDao.persist(host);
    } else {
        this._hostDao.update(host.getId(), host);
    }
    try {
        resourceStateTransitTo(host, ResourceState.Event.InternalCreated, this._nodeId);
        /* Agent goes to Connecting status */
        this._agentMgr.agentStatusTransitTo(host, Event.AgentConnected, this._nodeId);
    } catch (final Exception e) {
        s_logger.debug("Cannot transmit host " + host.getId() + " to Creating state", e);
        this._agentMgr.agentStatusTransitTo(host, Event.Error, this._nodeId);
        try {
            resourceStateTransitTo(host, ResourceState.Event.Error, this._nodeId);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Cannot transmit host " + host.getId() + "to Error state", e);
        }
    }
    return host;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) HostPodVO(com.cloud.dc.HostPodVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceInUseException(com.cloud.legacymodel.exceptions.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) SshException(com.cloud.utils.ssh.SshException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.legacymodel.exceptions.UnableDeleteHostException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DiscoveryException(com.cloud.legacymodel.exceptions.DiscoveryException) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)

Example 9 with StartupRoutingCommand

use of com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand in project cosmic by MissionCriticalCloud.

the class StoragePoolMonitorTest method setUp.

@Before
public void setUp() throws Exception {
    storageManager = Mockito.mock(StorageManagerImpl.class);
    poolDao = Mockito.mock(PrimaryDataStoreDao.class);
    storagePoolMonitor = new StoragePoolMonitor(storageManager, poolDao);
    host = new HostVO("some-uuid");
    pool = new StoragePoolVO();
    pool.setScope(ScopeType.CLUSTER);
    pool.setStatus(StoragePoolStatus.Up);
    pool.setId(123L);
    cmds = new StartupRoutingCommand[] { new StartupRoutingCommand() };
    cmds[0].setHypervisorType(HypervisorType.KVM);
}
Also used : StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) StorageManagerImpl(com.cloud.storage.StorageManagerImpl) HostVO(com.cloud.host.HostVO) PrimaryDataStoreDao(com.cloud.storage.datastore.db.PrimaryDataStoreDao) Before(org.junit.Before)

Example 10 with StartupRoutingCommand

use of com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand in project cosmic by MissionCriticalCloud.

the class DeploymentPlanningManagerImpl method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand[] startupCommands, final boolean forRebalance) {
    for (final StartupCommand startupCommand : startupCommands) {
        if (!(startupCommand instanceof StartupRoutingCommand)) {
            return;
        }
        final PlannerHostReservationVO reservationEntry = _plannerHostReserveDao.findByHostId(host.getId());
        if (reservationEntry == null) {
            // record the host in this table
            final PlannerHostReservationVO newHost = new PlannerHostReservationVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId());
            _plannerHostReserveDao.persist(newHost);
        }
    }
}
Also used : StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)

Aggregations

StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)16 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)14 HostVO (com.cloud.host.HostVO)4 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)4 ClusterVO (com.cloud.dc.ClusterVO)3 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 ConnectionException (com.cloud.legacymodel.exceptions.ConnectionException)3 Commands (com.cloud.agent.manager.Commands)2 HostPodVO (com.cloud.dc.HostPodVO)2 StartupSecondaryStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand)2 StartupStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupStorageCommand)2 Before (org.junit.Before)2 Listener (com.cloud.agent.Listener)1 Response (com.cloud.common.transport.Response)1 Zone (com.cloud.db.model.Zone)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)1 HostDao (com.cloud.host.dao.HostDao)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1