Search in sources :

Example 81 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class HighAvailabilityManagerImplTest method scheduleRestartForVmsOnHostNonEmptyVMList.

@Test
public void scheduleRestartForVmsOnHostNonEmptyVMList() {
    Mockito.when(hostVO.getId()).thenReturn(1l);
    Mockito.when(hostVO.getType()).thenReturn(Host.Type.Routing);
    Mockito.when(hostVO.getHypervisorType()).thenReturn(HypervisorType.XenServer);
    List<VMInstanceVO> vms = new ArrayList<VMInstanceVO>();
    VMInstanceVO vm1 = Mockito.mock(VMInstanceVO.class);
    Mockito.when(vm1.getHostId()).thenReturn(1l);
    Mockito.when(vm1.getInstanceName()).thenReturn("i-2-3-VM");
    Mockito.when(vm1.getType()).thenReturn(VirtualMachine.Type.User);
    Mockito.when(vm1.isHaEnabled()).thenReturn(true);
    vms.add(vm1);
    VMInstanceVO vm2 = Mockito.mock(VMInstanceVO.class);
    Mockito.when(vm2.getHostId()).thenReturn(1l);
    Mockito.when(vm2.getInstanceName()).thenReturn("r-2-VM");
    Mockito.when(vm2.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
    Mockito.when(vm2.isHaEnabled()).thenReturn(true);
    vms.add(vm2);
    Mockito.when(_instanceDao.listByHostId(Mockito.anyLong())).thenReturn(vms);
    Mockito.when(_instanceDao.findByUuid(vm1.getUuid())).thenReturn(vm1);
    Mockito.when(_instanceDao.findByUuid(vm2.getUuid())).thenReturn(vm2);
    Mockito.when(_podDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(HostPodVO.class));
    Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(DataCenterVO.class));
    Mockito.when(_haDao.findPreviousHA(Mockito.anyLong())).thenReturn(Arrays.asList(Mockito.mock(HaWorkVO.class)));
    Mockito.when(_haDao.persist((HaWorkVO) Mockito.anyObject())).thenReturn(Mockito.mock(HaWorkVO.class));
    Mockito.when(_serviceOfferingDao.findById(vm1.getServiceOfferingId())).thenReturn(Mockito.mock(ServiceOfferingVO.class));
    highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) Test(org.junit.Test)

Example 82 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnPrivateIpAddressTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnPrivateIpAddressTest() {
    HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
    Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(1);
    Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(new ArrayList<ClusterVO>());
    configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Random(java.util.Random) VolumeVO(com.cloud.storage.VolumeVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 83 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class RulesManagerImpl method createStaticNatForIp.

protected List<StaticNat> createStaticNatForIp(IpAddress sourceIp, Account caller, boolean forRevoke) {
    List<StaticNat> staticNats = new ArrayList<StaticNat>();
    if (!sourceIp.isOneToOneNat()) {
        s_logger.debug("Source ip id=" + sourceIp + " is not one to one nat");
        return staticNats;
    }
    Long networkId = sourceIp.getAssociatedWithNetworkId();
    if (networkId == null) {
        throw new CloudRuntimeException("Ip address is not associated with any network");
    }
    VMInstanceVO vm = _vmInstanceDao.findByIdIncludingRemoved(sourceIp.getAssociatedWithVmId());
    Network network = _networkModel.getNetwork(networkId);
    if (network == null) {
        CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address to map to specified vm id");
        ex.addProxyObject(vm.getUuid(), "vmId");
        throw ex;
    }
    if (caller != null) {
        _accountMgr.checkAccess(caller, null, true, sourceIp);
    }
    // create new static nat rule
    // Get nic IP4 address
    Nic guestNic = _networkModel.getNicInNetworkIncludingRemoved(vm.getId(), networkId);
    if (guestNic == null) {
        throw new InvalidParameterValueException("Vm doesn't belong to the network with specified id");
    }
    String dstIp;
    dstIp = sourceIp.getVmIp();
    if (dstIp == null) {
        throw new InvalidParameterValueException("Vm ip is not set as dnat ip for this public ip");
    }
    String srcMac = null;
    try {
        srcMac = _networkModel.getNextAvailableMacAddressInNetwork(networkId);
    } catch (InsufficientAddressCapacityException e) {
        throw new CloudRuntimeException("Insufficient MAC address for static NAT instantiation.");
    }
    StaticNatImpl staticNat = new StaticNatImpl(sourceIp.getAllocatedToAccountId(), sourceIp.getAllocatedInDomainId(), networkId, sourceIp.getId(), dstIp, srcMac, forRevoke);
    staticNats.add(staticNat);
    return staticNats;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) Nic(com.cloud.vm.Nic)

Example 84 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class AccountManagerImpl method doDisableAccount.

private boolean doDisableAccount(long accountId) throws ConcurrentOperationException, ResourceUnavailableException {
    List<VMInstanceVO> vms = _vmDao.listByAccountId(accountId);
    boolean success = true;
    for (VMInstanceVO vm : vms) {
        try {
            try {
                _itMgr.advanceStop(vm.getUuid(), false);
            } catch (OperationTimedoutException ote) {
                s_logger.warn("Operation for stopping vm timed out, unable to stop vm " + vm.getHostName(), ote);
                success = false;
            }
        } catch (AgentUnavailableException aue) {
            s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getHostName(), aue);
            success = false;
        }
    }
    return success;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VMInstanceVO(com.cloud.vm.VMInstanceVO)

Example 85 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class ImplicitPlannerTest method checkWhenDcInAvoidList.

@Test
public void checkWhenDcInAvoidList() throws InsufficientServerCapacityException {
    DataCenterVO mockDc = mock(DataCenterVO.class);
    ExcludeList avoids = mock(ExcludeList.class);
    VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    VMInstanceVO vm = mock(VMInstanceVO.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    when(avoids.shouldAvoid(mockDc)).thenReturn(true);
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    when(vm.getDataCenterId()).thenReturn(1L);
    when(dcDao.findById(1L)).thenReturn(mockDc);
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    assertTrue("Cluster list should be null/empty if the dc is in avoid list", (clusterList == null || clusterList.isEmpty()));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) VMInstanceVO(com.cloud.vm.VMInstanceVO) Test(org.junit.Test)

Aggregations

VMInstanceVO (com.cloud.vm.VMInstanceVO)131 ArrayList (java.util.ArrayList)40 HostVO (com.cloud.host.HostVO)34 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 Account (com.cloud.user.Account)28 VolumeVO (com.cloud.storage.VolumeVO)24 Test (org.junit.Test)24 HostPodVO (com.cloud.dc.HostPodVO)15 HashMap (java.util.HashMap)14 NetworkVO (com.cloud.network.dao.NetworkVO)13 User (com.cloud.user.User)13 NicVO (com.cloud.vm.NicVO)13 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)13 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)12 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)12 ActionEvent (com.cloud.event.ActionEvent)11 Random (java.util.Random)11 Answer (com.cloud.agent.api.Answer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10