Search in sources :

Example 11 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ImplicitPlannerTest method checkPreferredModeNoHostsAvailable.

@Test
public void checkPreferredModeNoHostsAvailable() throws InsufficientServerCapacityException {
    @SuppressWarnings("unchecked") VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    ExcludeList avoids = new ExcludeList();
    initializeForTest(vmProfile, plan);
    initializeForImplicitPlannerTest(false);
    // Mark the host 5, 6 and 7 to be in avoid list.
    avoids.addHost(5L);
    avoids.addHost(6L);
    avoids.addHost(7L);
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    // Validations.
    // Check cluster list is empty.
    assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) Test(org.junit.Test)

Example 12 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ImplicitPlannerTest method checkPreferredModePreferredHostAvailable.

@Test
public void checkPreferredModePreferredHostAvailable() throws InsufficientServerCapacityException {
    @SuppressWarnings("unchecked") VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    ExcludeList avoids = new ExcludeList();
    initializeForTest(vmProfile, plan);
    initializeForImplicitPlannerTest(true);
    // Mark the host 5 and 6 to be in avoid list.
    avoids.addHost(5L);
    avoids.addHost(6L);
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    // Validations.
    // Check cluster 1 and 2 are not in the cluster list.
    // Host 5 and 6 should also be in avoid list.
    assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
    boolean foundNeededCluster = false;
    for (Long cluster : clusterList) {
        if (cluster != 3) {
            fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
        } else {
            foundNeededCluster = true;
        }
    }
    assertTrue("Didn't find cluster 3 in the list. It should have been present", foundNeededCluster);
    Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
    assertFalse("Host 7 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(7L));
    Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
    hostsThatShouldBeInAvoidList.add(5L);
    hostsThatShouldBeInAvoidList.add(6L);
    assertTrue("Hosts 5 and 6 that should have been present were not found in avoid list", hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class NetworkHelperImpl method startVirtualRouter.

@Override
public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
        return start(router, user, caller, params, null);
    }
    if (router.getState() == State.Running) {
        s_logger.debug("Redundant router " + router.getInstanceName() + " is already running!");
        return router;
    }
    // We will wait until VR is up or fail
    if (router.getState() == State.Starting) {
        return waitRouter(router);
    }
    final DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
    DomainRouterVO result = null;
    assert router.getIsRedundantRouter();
    final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
    DomainRouterVO routerToBeAvoid = null;
    List<DomainRouterVO> routerList = null;
    if (networkIds.size() != 0) {
        routerList = _routerDao.findByNetwork(networkIds.get(0));
    } else if (router.getVpcId() != null) {
        routerList = _routerDao.listByVpcId(router.getVpcId());
    }
    if (routerList != null) {
        for (final DomainRouterVO rrouter : routerList) {
            if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) {
                if (routerToBeAvoid != null) {
                    throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" + ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" + rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class, rrouter.getDataCenterId());
                }
                routerToBeAvoid = rrouter;
            }
        }
    }
    if (routerToBeAvoid == null) {
        return start(router, user, caller, params, null);
    }
    // We would try best to deploy the router to another place
    final int retryIndex = 5;
    final ExcludeList[] avoids = new ExcludeList[5];
    avoids[0] = new ExcludeList();
    avoids[0].addPod(routerToBeAvoid.getPodIdToDeployIn());
    avoids[1] = new ExcludeList();
    avoids[1].addCluster(_hostDao.findById(routerToBeAvoid.getHostId()).getClusterId());
    avoids[2] = new ExcludeList();
    final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
    if (volumes != null && volumes.size() != 0) {
        avoids[2].addPool(volumes.get(0).getPoolId());
    }
    avoids[2].addHost(routerToBeAvoid.getHostId());
    avoids[3] = new ExcludeList();
    avoids[3].addHost(routerToBeAvoid.getHostId());
    avoids[4] = new ExcludeList();
    for (int i = 0; i < retryIndex; i++) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Try to deploy redundant virtual router:" + router.getHostName() + ", for " + i + " time");
        }
        plan.setAvoids(avoids[i]);
        try {
            result = start(router, user, caller, params, plan);
        } catch (final InsufficientServerCapacityException ex) {
            result = null;
        }
        if (result != null) {
            break;
        }
    }
    return result;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VolumeVO(com.cloud.storage.VolumeVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 14 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class VMEntityManagerImpl method deployVirtualMachine.

@Override
public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params, boolean deployOnGivenHost) throws InsufficientCapacityException, ResourceUnavailableException {
    // grab the VM Id and destination using the reservationId.
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
    if (vmReservation != null) {
        DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
        try {
            _itMgr.start(vm.getUuid(), params, reservedPlan, _planningMgr.getDeploymentPlannerByName(vmReservation.getDeploymentPlanner()));
        } catch (Exception ex) {
            // the instance may be started on another host instead of the intended one.
            if (!deployOnGivenHost) {
                DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
                if (reservedPlan.getAvoids() != null) {
                    plan.setAvoids(reservedPlan.getAvoids());
                }
                _itMgr.start(vm.getUuid(), params, plan, null);
            } else {
                throw ex;
            }
        }
    } else {
        // no reservation found. Let VirtualMachineManager retry
        _itMgr.start(vm.getUuid(), params, null, null);
    }
}
Also used : VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VMInstanceVO(com.cloud.vm.VMInstanceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AffinityConflictException(com.cloud.exception.AffinityConflictException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

Example 15 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class NetScalerVMManagerImpl method deployNetscalerServiceVm.

@Override
public Map<String, Object> deployNetscalerServiceVm(DeployNetscalerVpxCmd cmd) {
    DataCenter zone = _dcDao.findById(cmd.getZoneId());
    DeployDestination dest = new DeployDestination(zone, null, null, null);
    VMInstanceVO vmvo = null;
    Map<String, Object> resp = new HashMap<String, Object>();
    Long templateId = cmd.getTemplateId();
    Long serviceOfferingId = cmd.getServiceOfferingId();
    DeploymentPlan plan = new DataCenterDeployment(dest.getDataCenter().getId());
    try {
        resp = deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId);
    } catch (InsufficientCapacityException e) {
        e.printStackTrace();
    }
    return resp;
}
Also used : DataCenter(com.cloud.dc.DataCenter) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DeployDestination(com.cloud.deploy.DeployDestination) VMInstanceVO(com.cloud.vm.VMInstanceVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Aggregations

DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)87 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)45 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)34 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)26 StoragePool (com.cloud.storage.StoragePool)25 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)24 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)18 HashMap (java.util.HashMap)18 DeployDestination (com.cloud.deploy.DeployDestination)16 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)16 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)15 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)15 Host (com.cloud.host.Host)15 VolumeVO (com.cloud.storage.VolumeVO)15 Account (com.cloud.user.Account)15 DiskProfile (com.cloud.vm.DiskProfile)15 LinkedHashMap (java.util.LinkedHashMap)15 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)14