Search in sources :

Example 16 with StartupRoutingCommand

use of com.cloud.agent.api.StartupRoutingCommand in project CloudStack-archive by CloudStack-extras.

the class FakeComputingResource method initialize.

@Override
public StartupCommand[] initialize() {
    Map<String, VmState> changes = null;
    final List<Object> info = getHostInfo();
    final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal, changes);
    fillNetworkInformation(cmd);
    cmd.getHostDetails().putAll(getVersionStrings());
    cmd.setCluster(getConfiguredProperty("cluster", "1"));
    StoragePoolInfo pi = initializeLocalStorage();
    StartupStorageCommand sscmd = new StartupStorageCommand();
    sscmd.setPoolInfo(pi);
    sscmd.setGuid(pi.getUuid());
    sscmd.setDataCenter((String) _params.get("zone"));
    sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
    return new StartupCommand[] { cmd, sscmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) VmState(com.cloud.agent.api.StartupRoutingCommand.VmState) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 17 with StartupRoutingCommand

use of com.cloud.agent.api.StartupRoutingCommand in project CloudStack-archive by CloudStack-extras.

the class AgentRoutingResource method initialize.

@Override
public StartupCommand[] initialize() {
    synchronized (_vms) {
        _vms.clear();
    }
    Map<String, State> changes = _simMgr.getVmStates(this.hostGuid);
    Map<String, MockVMVO> vmsMaps = _simMgr.getVms(this.hostGuid);
    totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed();
    totalMem = agentHost.getMemorySize();
    for (Map.Entry<String, MockVMVO> entry : vmsMaps.entrySet()) {
        MockVMVO vm = entry.getValue();
        usedCpu += vm.getCpu();
        usedMem += vm.getMemory();
        _runningVms.put(entry.getKey(), new Pair<Long, Long>(Long.valueOf(vm.getCpu()), vm.getMemory()));
    }
    List<Object> info = getHostInfo();
    StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.Simulator, RouterPrivateIpStrategy.HostLocal);
    cmd.setStateChanges(changes);
    Map<String, String> hostDetails = new HashMap<String, String>();
    hostDetails.put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
    cmd.setHostDetails(hostDetails);
    cmd.setAgentTag("agent-simulator");
    cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
    cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
    cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
    cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
    cmd.setStorageNetmask(agentHost.getStorageNetMask());
    cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
    cmd.setStorageIpAddressDeux(agentHost.getStorageIpAddress());
    cmd.setStorageNetmaskDeux(agentHost.getStorageNetMask());
    cmd.setStorageMacAddressDeux(agentHost.getStorageIpAddress());
    cmd.setName(agentHost.getName());
    cmd.setGuid(agentHost.getGuid());
    cmd.setVersion(agentHost.getVersion());
    cmd.setAgentTag("agent-simulator");
    cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
    cmd.setPod(String.valueOf(agentHost.getPodId()));
    cmd.setCluster(String.valueOf(agentHost.getClusterId()));
    StartupStorageCommand ssCmd = initializeLocalSR();
    return new StartupCommand[] { cmd, ssCmd };
}
Also used : HashMap(java.util.HashMap) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) RouterPrivateIpStrategy(com.cloud.network.Networks.RouterPrivateIpStrategy) MockVMVO(com.cloud.simulator.MockVMVO) StartupCommand(com.cloud.agent.api.StartupCommand) State(com.cloud.vm.VirtualMachine.State) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with StartupRoutingCommand

use of com.cloud.agent.api.StartupRoutingCommand in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method initialize.

@Override
public StartupCommand[] initialize() {
    Map<String, State> changes = null;
    synchronized (_vms) {
        _vms.clear();
        changes = sync();
    }
    final List<Object> info = getHostInfo();
    final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal);
    cmd.setStateChanges(changes);
    fillNetworkInformation(cmd);
    _privateIp = cmd.getPrivateIpAddress();
    cmd.getHostDetails().putAll(getVersionStrings());
    cmd.setPool(_pool);
    cmd.setCluster(_clusterId);
    cmd.setGatewayIpAddress(_localGateway);
    StartupStorageCommand sscmd = null;
    try {
        KVMStoragePool localStoragePool = _storagePoolMgr.createStoragePool(_localStorageUUID, "localhost", _localStoragePath, StoragePoolType.Filesystem);
        com.cloud.agent.api.StoragePoolInfo pi = new com.cloud.agent.api.StoragePoolInfo(localStoragePool.getUuid(), cmd.getPrivateIpAddress(), _localStoragePath, _localStoragePath, StoragePoolType.Filesystem, localStoragePool.getCapacity(), localStoragePool.getUsed());
        sscmd = new StartupStorageCommand();
        sscmd.setPoolInfo(pi);
        sscmd.setGuid(pi.getUuid());
        sscmd.setDataCenter(_dcId);
        sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
    } catch (CloudRuntimeException e) {
    }
    if (sscmd != null) {
        return new StartupCommand[] { cmd, sscmd };
    } else {
        return new StartupCommand[] { cmd };
    }
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) State(com.cloud.vm.VirtualMachine.State) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 19 with StartupRoutingCommand

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

the class CloudZonesStartupProcessor method updateComputeHost.

protected void updateComputeHost(final HostVO host, final StartupCommand startup, final Host.Type type) throws AgentAuthnException {
    String zoneToken = startup.getDataCenter();
    if (zoneToken == null) {
        s_logger.warn("No Zone Token passed in, cannot not find zone for the agent");
        throw new AgentAuthnException("No Zone Token passed in, cannot not find zone for agent");
    }
    DataCenterVO zone = _zoneDao.findByToken(zoneToken);
    if (zone == null) {
        zone = _zoneDao.findByName(zoneToken);
        if (zone == null) {
            try {
                long zoneId = Long.parseLong(zoneToken);
                zone = _zoneDao.findById(zoneId);
                if (zone == null) {
                    throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
                }
            } catch (NumberFormatException nfe) {
                throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Successfully loaded the DataCenter from the zone token passed in ");
    }
    long zoneId = zone.getId();
    ResourceDetail maxHostsInZone = _zoneDetailsDao.findDetail(zoneId, ZoneConfig.MaxHosts.key());
    if (maxHostsInZone != null) {
        long maxHosts = Long.parseLong(maxHostsInZone.getValue());
        long currentCountOfHosts = _hostDao.countRoutingHostsByDataCenter(zoneId);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Number of hosts in Zone:" + currentCountOfHosts + ", max hosts limit: " + maxHosts);
        }
        if (currentCountOfHosts >= maxHosts) {
            throw new AgentAuthnException("Number of running Routing hosts in the Zone:" + zone.getName() + " is already at the max limit:" + maxHosts + ", cannot start one more host");
        }
    }
    HostPodVO pod = null;
    if (startup.getPrivateIpAddress() == null) {
        s_logger.warn("No private IP address passed in for the agent, cannot not find pod for agent");
        throw new AgentAuthnException("No private IP address passed in for the agent, cannot not find pod for agent");
    }
    if (startup.getPrivateNetmask() == null) {
        s_logger.warn("No netmask passed in for the agent, cannot not find pod for agent");
        throw new AgentAuthnException("No netmask passed in for the agent, cannot not find pod for agent");
    }
    if (host.getPodId() != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Pod is already created for this agent, looks like agent is reconnecting...");
        }
        pod = _podDao.findById(host.getPodId());
        if (!checkCIDR(type, pod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
            pod = null;
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Subnet of Pod does not match the subnet of the agent, not using this Pod: " + host.getPodId());
            }
        } else {
            updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
        }
    }
    if (pod == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Trying to detect the Pod to use from the agent's ip address and netmask passed in ");
        }
        //deduce pod
        boolean podFound = false;
        List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
        for (HostPodVO hostPod : podsInZone) {
            if (checkCIDR(type, hostPod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
                pod = hostPod;
                //found the default POD having the same subnet.
                updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
                podFound = true;
                break;
            }
        }
        if (!podFound) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Creating a new Pod since no default Pod found that matches the agent's ip address and netmask passed in ");
            }
            if (startup.getGatewayIpAddress() == null) {
                s_logger.warn("No Gateway IP address passed in for the agent, cannot create a new pod for the agent");
                throw new AgentAuthnException("No Gateway IP address passed in for the agent, cannot create a new pod for the agent");
            }
            //auto-create a new pod, since pod matching the agent's ip is not found
            String podName = "POD-" + (podsInZone.size() + 1);
            try {
                String gateway = startup.getGatewayIpAddress();
                String cidr = NetUtils.getCidrFromGatewayAndNetmask(gateway, startup.getPrivateNetmask());
                String[] cidrPair = cidr.split("\\/");
                String cidrAddress = cidrPair[0];
                long cidrSize = Long.parseLong(cidrPair[1]);
                String startIp = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
                String endIp = NetUtils.getIpRangeEndIpFromCidr(cidrAddress, cidrSize);
                pod = _configurationManager.createPod(-1, podName, zoneId, gateway, cidr, startIp, endIp, null, true);
            } catch (Exception e) {
                // no longer tolerate exception during the cluster creation phase
                throw new CloudRuntimeException("Unable to create new Pod " + podName + " in Zone: " + zoneId, e);
            }
        }
    }
    final StartupRoutingCommand scc = (StartupRoutingCommand) startup;
    ClusterVO cluster = null;
    if (host.getClusterId() != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Cluster is already created for this agent, looks like agent is reconnecting...");
        }
        cluster = _clusterDao.findById(host.getClusterId());
    }
    if (cluster == null) {
        //auto-create cluster - assume one host per cluster
        String clusterName = "Cluster-" + startup.getPrivateIpAddress();
        ClusterVO existingCluster = _clusterDao.findBy(clusterName, pod.getId());
        if (existingCluster != null) {
            cluster = existingCluster;
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Creating a new Cluster for this agent with name: " + clusterName + " in Pod: " + pod.getId() + ", in Zone:" + zoneId);
            }
            cluster = new ClusterVO(zoneId, pod.getId(), clusterName);
            cluster.setHypervisorType(scc.getHypervisorType().toString());
            try {
                cluster = _clusterDao.persist(cluster);
            } catch (Exception e) {
                // no longer tolerate exception during the cluster creation phase
                throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + pod.getId() + " and data center " + zoneId, e);
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Detected Zone: " + zoneId + ", Pod: " + pod.getId() + ", Cluster:" + cluster.getId());
    }
    host.setDataCenterId(zone.getId());
    host.setPodId(pod.getId());
    host.setClusterId(cluster.getId());
    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.setType(type);
    host.setStorageUrl(startup.getIqn());
    host.setLastPinged(System.currentTimeMillis() >> 10);
    host.setCaps(scc.getCapabilities());
    host.setCpus(scc.getCpus());
    host.setTotalMemory(scc.getMemory());
    host.setSpeed(scc.getSpeed());
    HypervisorType hyType = scc.getHypervisorType();
    host.setHypervisorType(hyType);
    host.setHypervisorVersion(scc.getHypervisorVersion());
    updateHostDetails(host, scc);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) ResourceDetail(org.apache.cloudstack.api.ResourceDetail) HostPodVO(com.cloud.dc.HostPodVO) ConfigurationException(javax.naming.ConfigurationException) ConnectionException(com.cloud.exception.ConnectionException) AgentAuthnException(com.cloud.agent.manager.authn.AgentAuthnException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) AgentAuthnException(com.cloud.agent.manager.authn.AgentAuthnException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 20 with StartupRoutingCommand

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

the class KvmDummyResourceBase method initialize.

@Override
public StartupCommand[] initialize() {
    StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap<String, String>());
    cmd.setDataCenter(_zoneId);
    cmd.setPod(_podId);
    cmd.setCluster(_clusterId);
    cmd.setGuid(_guid);
    cmd.setName(_agentIp);
    cmd.setPrivateIpAddress(_agentIp);
    cmd.setStorageIpAddress(_agentIp);
    cmd.setVersion(KvmDummyResourceBase.class.getPackage().getImplementationVersion());
    return new StartupCommand[] { cmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Aggregations

StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)40 StartupCommand (com.cloud.agent.api.StartupCommand)27 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ClusterVO (com.cloud.dc.ClusterVO)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 ConnectionException (com.cloud.exception.ConnectionException)6 HostVO (com.cloud.host.HostVO)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 ConfigurationException (javax.naming.ConfigurationException)5 HostPodVO (com.cloud.dc.HostPodVO)4 Command (com.cloud.agent.api.Command)3 Commands (com.cloud.agent.manager.Commands)3 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)3 PingCommand (com.cloud.agent.api.PingCommand)2 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)2 SetupAnswer (com.cloud.agent.api.SetupAnswer)2 SetupCommand (com.cloud.agent.api.SetupCommand)2 StartCommand (com.cloud.agent.api.StartCommand)2 StoragePoolInfo (com.cloud.agent.api.StoragePoolInfo)2