Search in sources :

Example 46 with StartupCommand

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

the class ResourceManagerImpl method markHostAsDisconnected.

private void markHostAsDisconnected(HostVO host, final StartupCommand[] cmds) {
    if (host == null) {
        // reloading the host from db
        if (cmds != null) {
            final StartupCommand firstCmd = cmds[0];
            host = findHostByGuid(firstCmd.getGuid());
            if (host == null) {
                host = findHostByGuid(firstCmd.getGuidWithoutResource());
            }
        }
    }
    if (host != null) {
        // Change agent status to Alert, so that host is considered for
        // reconnection next time
        _agentMgr.agentStatusTransitTo(host, Status.Event.AgentDisconnected, _nodeId);
    }
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand)

Example 47 with StartupCommand

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

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) {
    boolean newHost = false;
    StartupCommand startup = cmds[0];
    HostVO host = getNewHost(cmds);
    if (host == null) {
        host = new HostVO(startup.getGuid());
        newHost = 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 = _podDao.listAllIncludingRemoved();
        for (final HostPodVO hpv : pods) {
            if (checkCIDR(hpv, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
                pod = hpv.getName();
                dataCenter = _dcDao.findById(hpv.getDataCenterId()).getName();
                break;
            }
        }
    }
    long dcId = -1;
    DataCenterVO dc = _dcDao.findByName(dataCenter);
    if (dc == null) {
        try {
            dcId = Long.parseLong(dataCenter);
            dc = _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 = _podDao.findByName(pod, dcId);
    if (p == null) {
        try {
            final long podId = Long.parseLong(pod);
            p = _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.
         * Others, like PxeServer, ExternalFireware don't require Pod
         */
    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 = _clusterDao.findBy(cluster, podId.longValue());
                if (c == null) {
                    c = new ClusterVO(dcId, podId.longValue(), cluster);
                    c = _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 = _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(_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 (newHost) {
        host = _hostDao.persist(host);
    } else {
        _hostDao.update(host.getId(), host);
    }
    if (startup instanceof StartupRoutingCommand) {
        final StartupRoutingCommand ssCmd = (StartupRoutingCommand) startup;
        updateSupportsClonedVolumes(host, ssCmd.getSupportsClonedVolumes());
    }
    try {
        resourceStateTransitTo(host, ResourceState.Event.InternalCreated, _nodeId);
        /* Agent goes to Connecting status */
        _agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, _nodeId);
    } catch (final Exception e) {
        s_logger.debug("Cannot transmit host " + host.getId() + " to Creating state", e);
        _agentMgr.agentStatusTransitTo(host, Status.Event.Error, _nodeId);
        try {
            resourceStateTransitTo(host, ResourceState.Event.Error, _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) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) SshException(com.cloud.utils.ssh.SshException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) StartupCommand(com.cloud.agent.api.StartupCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 48 with StartupCommand

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

the class ResourceManagerImpl method getNewHost.

private HostVO getNewHost(StartupCommand[] startupCommands) {
    StartupCommand startupCommand = startupCommands[0];
    HostVO host = findHostByGuid(startupCommand.getGuid());
    if (host != null) {
        return host;
    }
    host = findHostByGuid(startupCommand.getGuidWithoutResource());
    if (host != null) {
        return host;
    }
    return null;
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Example 49 with StartupCommand

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

the class BareMetalResourceBase method initialize.

@Override
public StartupCommand[] initialize() {
    StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.BareMetal, new HashMap<String, String>());
    cmd.setDataCenter(_zone);
    cmd.setPod(_pod);
    cmd.setCluster(_cluster);
    cmd.setGuid(_uuid);
    cmd.setName(_ip);
    cmd.setPrivateIpAddress(_ip);
    cmd.setStorageIpAddress(_ip);
    cmd.setVersion(BareMetalResourceBase.class.getPackage().getImplementationVersion());
    cmd.setCpus((int) _cpuNum);
    cmd.setSpeed(_cpuCapacity);
    cmd.setMemory(_memCapacity);
    cmd.setPrivateMacAddress(_mac);
    cmd.setPublicMacAddress(_mac);
    return new StartupCommand[] { cmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 50 with StartupCommand

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

the class HypervDirectConnectResource method initialize.

@Override
public final StartupCommand[] initialize() {
    // assert
    if (!_configureCalled) {
        final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()";
        s_logger.error(errMsg);
    }
    // Create default StartupRoutingCommand, then customise
    final StartupRoutingCommand defaultStartRoutCmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.Hyperv, RouterPrivateIpStrategy.HostLocal);
    // Identity within the data centre is decided by CloudStack kernel,
    // and passed via ServerResource.configure()
    defaultStartRoutCmd.setDataCenter(_zoneId);
    defaultStartRoutCmd.setPod(_podId);
    defaultStartRoutCmd.setCluster(_clusterId);
    defaultStartRoutCmd.setGuid(_guid);
    defaultStartRoutCmd.setName(_name);
    defaultStartRoutCmd.setPrivateIpAddress(_agentIp);
    defaultStartRoutCmd.setStorageIpAddress(_agentIp);
    defaultStartRoutCmd.setPool(_clusterGuid);
    s_logger.debug("Generated StartupRoutingCommand for _agentIp \"" + _agentIp + "\"");
    defaultStartRoutCmd.setVersion(this.getClass().getPackage().getImplementationVersion());
    // Specifics of the host's resource capacity and network configuration
    // comes from the host itself. CloudStack sanity checks network
    // configuration
    // and uses capacity info for resource allocation.
    final Command[] startCmds = requestStartupCommand(new Command[] { defaultStartRoutCmd });
    // TODO: may throw, is this okay?
    final StartupRoutingCommand startCmd = (StartupRoutingCommand) startCmds[0];
    // Assert that host identity is consistent with existing values.
    if (startCmd == null) {
        final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    if (!startCmd.getDataCenter().equals(defaultStartRoutCmd.getDataCenter())) {
        final String errMsg = String.format("Host %s (IP %s) changed zone/data center.  Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) {
        final String errMsg = String.format("Host %s (IP %s) changed pod.  Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) {
        final String errMsg = String.format("Host %s (IP %s) changed cluster.  Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) {
        final String errMsg = String.format("Host %s (IP %s) changed guid.  Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    if (!startCmd.getPrivateIpAddress().equals(defaultStartRoutCmd.getPrivateIpAddress())) {
        final String errMsg = String.format("Host %s (IP %s) IP address.  Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) {
        final String errMsg = String.format("Host %s (IP %s) name.  Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), _name, _agentIp);
        s_logger.error(errMsg);
        // TODO: valid to return null, or should we throw?
        return null;
    }
    // Host will also supply details of an existing StoragePool if it has
    // been configured with one.
    //
    // NB: if the host was configured
    // with a local storage pool, CloudStack may not be able to use it
    // unless
    // it is has service offerings configured to recognise this storage
    // type.
    StartupStorageCommand storePoolCmd = null;
    if (startCmds.length > 1) {
        storePoolCmd = (StartupStorageCommand) startCmds[1];
        // TODO: is this assertion required?
        if (storePoolCmd == null) {
            final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand";
            final String errMsg = String.format(frmtStr, _name, _agentIp);
            s_logger.error(errMsg);
            // TODO: valid to return null, or should we throw?
            return null;
        }
        s_logger.info("Host " + _name + " (IP " + _agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1]));
    } else {
        s_logger.info("Host " + _name + " (IP " + _agentIp + ") already configured with a storeage pool, details ");
    }
    return new StartupCommand[] { startCmd, storePoolCmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) Site2SiteVpnCfgCommand(com.cloud.agent.api.routing.Site2SiteVpnCfgCommand) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) ModifyVmNicConfigCommand(com.cloud.agent.api.ModifyVmNicConfigCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) SetStaticRouteCommand(com.cloud.agent.api.routing.SetStaticRouteCommand) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) CreateIpAliasCommand(com.cloud.agent.api.routing.CreateIpAliasCommand) SetMonitorServiceCommand(com.cloud.agent.api.routing.SetMonitorServiceCommand) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) RemoteAccessVpnCfgCommand(com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand) Command(com.cloud.agent.api.Command) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) StartCommand(com.cloud.agent.api.StartCommand) GetVmConfigCommand(com.cloud.agent.api.GetVmConfigCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) StartupCommand(com.cloud.agent.api.StartupCommand) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) IpAssocVpcCommand(com.cloud.agent.api.routing.IpAssocVpcCommand) SetNetworkACLCommand(com.cloud.agent.api.routing.SetNetworkACLCommand) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Aggregations

StartupCommand (com.cloud.agent.api.StartupCommand)60 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)28 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ConfigurationException (javax.naming.ConfigurationException)7 Command (com.cloud.agent.api.Command)6 StartupSecondaryStorageCommand (com.cloud.agent.api.StartupSecondaryStorageCommand)6 PingCommand (com.cloud.agent.api.PingCommand)5 HostVO (com.cloud.host.HostVO)5 URISyntaxException (java.net.URISyntaxException)5 Request (com.cloud.agent.transport.Request)4 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)3 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)3 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)3 StartCommand (com.cloud.agent.api.StartCommand)3 StartupProxyCommand (com.cloud.agent.api.StartupProxyCommand)3 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)2 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)2 CronCommand (com.cloud.agent.api.CronCommand)2