Search in sources :

Example 6 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class ResourceLimitManagerImpl method updateResourceLimit.

@Override
public ResourceLimitVO updateResourceLimit(final Long accountId, final Long domainId, final Integer typeId, Long max) {
    final Account caller = CallContext.current().getCallingAccount();
    if (max == null) {
        max = new Long(Resource.RESOURCE_UNLIMITED);
    } else if (max.longValue() < Resource.RESOURCE_UNLIMITED) {
        throw new InvalidParameterValueException("Please specify either '-1' for an infinite limit, or a limit that is at least '0'.");
    }
    // Map resource type
    ResourceType resourceType = null;
    if (typeId != null) {
        for (final ResourceType type : Resource.ResourceType.values()) {
            if (type.getOrdinal() == typeId.intValue()) {
                resourceType = type;
            }
        }
        if (resourceType == null) {
            throw new InvalidParameterValueException("Please specify valid resource type");
        }
    }
    // Convert max storage size from GiB to bytes
    if ((resourceType == ResourceType.primary_storage || resourceType == ResourceType.secondary_storage) && max >= 0) {
        max = max * ResourceType.bytesToGiB;
    }
    ResourceOwnerType ownerType = null;
    Long ownerId = null;
    if (accountId != null) {
        final Account account = this._entityMgr.findById(Account.class, accountId);
        if (account == null) {
            throw new InvalidParameterValueException("Unable to find account " + accountId);
        }
        if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
            throw new InvalidParameterValueException("Can't update system account");
        }
        // only Unlimited value is accepted if account is  Root Admin
        if (this._accountMgr.isRootAdmin(account.getId()) && max.shortValue() != Resource.RESOURCE_UNLIMITED) {
            throw new InvalidParameterValueException("Only " + Resource.RESOURCE_UNLIMITED + " limit is supported for Root Admin accounts");
        }
        if ((caller.getAccountId() == accountId.longValue()) && (this._accountMgr.isDomainAdmin(caller.getId()) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
            // If the admin is trying to update his own account, disallow.
            throw new PermissionDeniedException("Unable to update resource limit for his own account " + accountId + ", permission denied");
        }
        if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
            this._accountMgr.checkAccess(caller, AccessType.ModifyProject, true, account);
        } else {
            this._accountMgr.checkAccess(caller, null, true, account);
        }
        ownerType = ResourceOwnerType.Account;
        ownerId = accountId;
    } else if (domainId != null) {
        final Domain domain = this._entityMgr.findById(Domain.class, domainId);
        this._accountMgr.checkAccess(caller, domain);
        if (Domain.ROOT_DOMAIN == domainId.longValue()) {
            // no one can add limits on ROOT domain, disallow...
            throw new PermissionDeniedException("Cannot update resource limit for ROOT domain " + domainId + ", permission denied");
        }
        if ((caller.getDomainId() == domainId.longValue()) && caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
            // if the admin is trying to update their own domain, disallow...
            throw new PermissionDeniedException("Unable to update resource limit for domain " + domainId + ", permission denied");
        }
        final Long parentDomainId = domain.getParent();
        if (parentDomainId != null) {
            final DomainVO parentDomain = this._domainDao.findById(parentDomainId);
            final long parentMaximum = findCorrectResourceLimitForDomain(parentDomain, resourceType);
            if ((parentMaximum >= 0) && (max.longValue() > parentMaximum)) {
                throw new InvalidParameterValueException("Domain " + domain.getName() + "(id: " + parentDomain.getId() + ") has maximum allowed resource limit " + parentMaximum + " for " + resourceType + ", please specify a value less that or equal to " + parentMaximum);
            }
        }
        ownerType = ResourceOwnerType.Domain;
        ownerId = domainId;
    }
    if (ownerId == null) {
        throw new InvalidParameterValueException("AccountId or domainId have to be specified in order to update resource limit");
    }
    final ResourceLimitVO limit = this._resourceLimitDao.findByOwnerIdAndType(ownerId, ownerType, resourceType);
    if (limit != null) {
        // Update the existing limit
        this._resourceLimitDao.update(limit.getId(), max);
        return this._resourceLimitDao.findById(limit.getId());
    } else {
        return this._resourceLimitDao.persist(new ResourceLimitVO(resourceType, max, ownerId, ownerType));
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceOwnerType(com.cloud.legacymodel.configuration.Resource.ResourceOwnerType) ResourceType(com.cloud.legacymodel.configuration.Resource.ResourceType) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) Domain(com.cloud.legacymodel.domain.Domain) ResourceLimitVO(com.cloud.configuration.ResourceLimitVO)

Example 7 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class ResourceLimitManagerImpl method searchForLimits.

@Override
public List<ResourceLimitVO> searchForLimits(final Long id, Long accountId, Long domainId, final Integer type, final Long startIndex, final Long pageSizeVal) {
    final Account caller = CallContext.current().getCallingAccount();
    final List<ResourceLimitVO> limits = new ArrayList<>();
    final boolean isAccount;
    if (!this._accountMgr.isAdmin(caller.getId())) {
        accountId = caller.getId();
        domainId = null;
    } else {
        if (domainId != null) {
            // verify domain information and permissions
            final Domain domain = this._domainDao.findById(domainId);
            if (domain == null) {
                // return empty set
                return limits;
            }
            this._accountMgr.checkAccess(caller, domain);
            if (accountId != null) {
                // Verify account information and permissions
                final Account account = this._accountDao.findById(accountId);
                if (account == null) {
                    // return empty set
                    return limits;
                }
                this._accountMgr.checkAccess(caller, null, true, account);
                domainId = null;
            }
        }
    }
    // Map resource type
    ResourceType resourceType = null;
    if (type != null) {
        try {
            resourceType = ResourceType.values()[type];
        } catch (final ArrayIndexOutOfBoundsException e) {
            throw new InvalidParameterValueException("Please specify a valid resource type.");
        }
    }
    // If id is passed in, get the record and return it if permission check has passed
    if (id != null) {
        final ResourceLimitVO vo = this._resourceLimitDao.findById(id);
        if (vo.getAccountId() != null) {
            this._accountMgr.checkAccess(caller, null, true, this._accountDao.findById(vo.getAccountId()));
            limits.add(vo);
        } else if (vo.getDomainId() != null) {
            this._accountMgr.checkAccess(caller, this._domainDao.findById(vo.getDomainId()));
            limits.add(vo);
        }
        return limits;
    }
    // If account is not specified, default it to caller account
    if (accountId == null) {
        if (domainId == null) {
            accountId = caller.getId();
            isAccount = true;
        } else {
            isAccount = false;
        }
    } else {
        isAccount = true;
    }
    final SearchBuilder<ResourceLimitVO> sb = this._resourceLimitDao.createSearchBuilder();
    sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
    sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
    sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
    final SearchCriteria<ResourceLimitVO> sc = sb.create();
    final Filter filter = new Filter(ResourceLimitVO.class, "id", true, startIndex, pageSizeVal);
    if (accountId != null) {
        sc.setParameters("accountId", accountId);
    }
    if (domainId != null) {
        sc.setParameters("domainId", domainId);
        sc.setParameters("accountId", (Object[]) null);
    }
    if (resourceType != null) {
        sc.setParameters("type", resourceType);
    }
    final List<ResourceLimitVO> foundLimits = this._resourceLimitDao.search(sc, filter);
    if (resourceType != null) {
        if (foundLimits.isEmpty()) {
            if (isAccount) {
                limits.add(new ResourceLimitVO(resourceType, findCorrectResourceLimitForAccount(this._accountMgr.getAccount(accountId), resourceType), accountId, ResourceOwnerType.Account));
            } else {
                limits.add(new ResourceLimitVO(resourceType, findCorrectResourceLimitForDomain(this._domainDao.findById(domainId), resourceType), domainId, ResourceOwnerType.Domain));
            }
        } else {
            limits.addAll(foundLimits);
        }
    } else {
        limits.addAll(foundLimits);
        // see if any limits are missing from the table, and if yes - get it from the config table and add
        final ResourceType[] resourceTypes = ResourceCount.ResourceType.values();
        if (foundLimits.size() != resourceTypes.length) {
            final List<String> accountLimitStr = new ArrayList<>();
            final List<String> domainLimitStr = new ArrayList<>();
            for (final ResourceLimitVO foundLimit : foundLimits) {
                if (foundLimit.getAccountId() != null) {
                    accountLimitStr.add(foundLimit.getType().toString());
                } else {
                    domainLimitStr.add(foundLimit.getType().toString());
                }
            }
            // get default from config values
            if (isAccount) {
                if (accountLimitStr.size() < resourceTypes.length) {
                    for (final ResourceType rt : resourceTypes) {
                        if (!accountLimitStr.contains(rt.toString()) && rt.supportsOwner(ResourceOwnerType.Account)) {
                            limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForAccount(this._accountMgr.getAccount(accountId), rt), accountId, ResourceOwnerType.Account));
                        }
                    }
                }
            } else {
                if (domainLimitStr.size() < resourceTypes.length) {
                    for (final ResourceType rt : resourceTypes) {
                        if (!domainLimitStr.contains(rt.toString()) && rt.supportsOwner(ResourceOwnerType.Domain)) {
                            limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForDomain(this._domainDao.findById(domainId), rt), domainId, ResourceOwnerType.Domain));
                        }
                    }
                }
            }
        }
    }
    return limits;
}
Also used : Account(com.cloud.legacymodel.user.Account) ArrayList(java.util.ArrayList) ResourceType(com.cloud.legacymodel.configuration.Resource.ResourceType) ResourceLimitVO(com.cloud.configuration.ResourceLimitVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Filter(com.cloud.utils.db.Filter) Domain(com.cloud.legacymodel.domain.Domain)

Example 8 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method listHostsForMigrationOfVM.

@Override
public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> listHostsForMigrationOfVM(final Long vmId, final Long startIndex, final Long pageSize, final String keyword) {
    final Account caller = getCaller();
    if (!_accountMgr.isRootAdmin(caller.getId())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Caller is not a root admin, permission denied to migrate the VM");
        }
        throw new PermissionDeniedException("No permission to migrate VM, Only Root Admin can migrate a VM!");
    }
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    if (vm == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the VM with given id");
        throw ex;
    }
    if (vm.getState() != State.Running) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("VM is not running, cannot migrate the vm" + vm);
        }
        final InvalidParameterValueException ex = new InvalidParameterValueException("VM is not Running, cannot " + "migrate the vm with specified id");
        ex.addProxyObject(vm.getUuid(), "vmId");
        throw ex;
    }
    if (_serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.pciDevice.toString()) != null) {
        s_logger.info(" Live Migration of GPU enabled VM : " + vm.getInstanceName() + " is not supported");
        // Return empty list.
        return new Ternary<>(new Pair<>(new ArrayList<HostVO>(), new Integer(0)), new ArrayList<>(), new HashMap<>());
    }
    if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.KVM)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(vm + " is not XenServer/KVM, cannot migrate this VM.");
        }
        throw new InvalidParameterValueException("Unsupported Hypervisor Type for VM migration, we support " + "XenServer/KVM only");
    }
    final long srcHostId = vm.getHostId();
    final Host srcHost = _hostDao.findById(srcHostId);
    if (srcHost == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Unable to find the host with id: " + srcHostId + " of this VM:" + vm);
        }
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the host (with specified id) of VM with specified id");
        ex.addProxyObject(String.valueOf(srcHostId), "hostId");
        ex.addProxyObject(vm.getUuid(), "vmId");
        throw ex;
    }
    // Check if the vm can be migrated with storage.
    boolean canMigrateWithStorage = false;
    if (vm.getType() == VirtualMachineType.User) {
        final HypervisorCapabilitiesVO capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
        if (capabilities != null) {
            canMigrateWithStorage = capabilities.isStorageMotionSupported();
        }
    }
    // Check if the vm is using any disks on local storage.
    final VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm, null, _offeringDao.findById(vm.getId(), vm.getServiceOfferingId()), null, null);
    final List<VolumeVO> volumes = _volumeDao.findCreatedByInstance(vmProfile.getId());
    boolean usesLocal = false;
    for (final VolumeVO volume : volumes) {
        final DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId());
        final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
        if (diskProfile.useLocalStorage()) {
            usesLocal = true;
            break;
        }
    }
    if (!canMigrateWithStorage && usesLocal) {
        throw new InvalidParameterValueException("Unsupported operation, VM uses Local storage, cannot migrate");
    }
    final HostType hostType = srcHost.getType();
    final Pair<List<HostVO>, Integer> allHostsPair;
    final List<HostVO> allHosts;
    final Map<Host, Boolean> requiresStorageMotion = new HashMap<>();
    final DataCenterDeployment plan;
    if (canMigrateWithStorage) {
        allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null, null, null, keyword, null, null, srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
        allHosts = allHostsPair.first();
        allHosts.remove(srcHost);
        for (final VolumeVO volume : volumes) {
            final Long volClusterId = _poolDao.findById(volume.getPoolId()).getClusterId();
            // only check for volume which are not in zone wide primary store, as only those may require storage motion
            if (volClusterId != null) {
                for (final Iterator<HostVO> iterator = allHosts.iterator(); iterator.hasNext(); ) {
                    final Host host = iterator.next();
                    if (!host.getClusterId().equals(volClusterId) || usesLocal) {
                        if (hasSuitablePoolsForVolume(volume, host, vmProfile)) {
                            requiresStorageMotion.put(host, true);
                        } else {
                            iterator.remove();
                        }
                    }
                }
            }
        }
        plan = new DataCenterDeployment(srcHost.getDataCenterId(), null, null, null, null, null);
    } else {
        final Long cluster = srcHost.getClusterId();
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Searching for all hosts in cluster " + cluster + " for migrating VM " + vm);
        }
        allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, keyword, null, null, null, null);
        // Filter out the current host.
        allHosts = allHostsPair.first();
        allHosts.remove(srcHost);
        plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(), srcHost.getClusterId(), null, null, null);
    }
    final Pair<List<? extends Host>, Integer> otherHosts = new Pair<>(allHosts, new Integer(allHosts.size()));
    List<Host> suitableHosts = new ArrayList<>();
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(srcHostId);
    // call affinitygroup chain
    final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
    if (vmGroupCount > 0) {
        for (final AffinityGroupProcessor processor : _affinityProcessors) {
            processor.process(vmProfile, plan, excludes);
        }
    }
    final Account account = vmProfile.getOwner();
    for (final HostVO host : allHosts) {
        final DedicatedResourceVO dedicatedResourceVO = dedicatedResourceDao.findByHostId(host.getId());
        if (dedicatedResourceVO != null && dedicatedResourceVO.getDomainId() != account.getDomainId()) {
            final Domain domain = _domainDao.findById(dedicatedResourceVO.getDomainId());
            if (domain != null) {
                s_logger.debug("Host " + host.getName() + " is dedicated to domain " + domain.getName() + " so not suitable for migration for VM " + vmProfile.getInstanceName());
            }
            excludes.addHost(host.getId());
        }
    }
    for (final HostAllocator allocator : hostAllocators) {
        if (canMigrateWithStorage) {
            suitableHosts = allocator.allocateTo(vmProfile, plan, HostType.Routing, excludes, allHosts, HostAllocator.RETURN_UPTO_ALL, false);
        } else {
            suitableHosts = allocator.allocateTo(vmProfile, plan, HostType.Routing, excludes, HostAllocator.RETURN_UPTO_ALL, false);
        }
        if (suitableHosts != null && !suitableHosts.isEmpty()) {
            break;
        }
    }
    if (s_logger.isDebugEnabled()) {
        if (suitableHosts.isEmpty()) {
            s_logger.debug("No suitable hosts found");
        } else {
            s_logger.debug("Hosts having capacity and suitable for migration: " + suitableHosts);
        }
    }
    return new Ternary<>(otherHosts, suitableHosts, requiresStorageMotion);
}
Also used : HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) Account(com.cloud.legacymodel.user.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HostAllocator(com.cloud.agent.manager.allocator.HostAllocator) HostType(com.cloud.model.enumeration.HostType) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) AffinityGroupProcessor(com.cloud.affinity.AffinityGroupProcessor) SSHKeyPair(com.cloud.legacymodel.user.SSHKeyPair) Pair(com.cloud.legacymodel.utils.Pair) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Ternary(com.cloud.legacymodel.utils.Ternary) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.legacymodel.dc.Host) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) HostVO(com.cloud.host.HostVO) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) Domain(com.cloud.legacymodel.domain.Domain)

Example 9 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class LdapManagerImpl method linkDomainToLdap.

@Override
public LinkDomainToLdapResponse linkDomainToLdap(final Long domainId, final String type, final String name, final short accountType) {
    Validate.notNull(type, "type cannot be null. It should either be GROUP or OU");
    Validate.notNull(domainId, "domainId cannot be null.");
    Validate.notEmpty(name, "GROUP or OU name cannot be empty");
    // Account type should be 0 or 2. check the constants in com.cloud.legacymodel.user.Account
    Validate.isTrue(accountType == 0 || accountType == 2, "accountype should be either 0(normal user) or 2(domain admin)");
    final Domain domain = _domainManager.getDomain(domainId);
    final LinkType linkType = LdapManager.LinkType.valueOf(type.toUpperCase());
    final LdapTrustMapVO vo = _ldapTrustMapDao.persist(new LdapTrustMapVO(domainId, linkType, name, accountType));
    final LinkDomainToLdapResponse response = new LinkDomainToLdapResponse(domain.getUuid(), vo.getType().toString(), vo.getName(), vo.getAccountType());
    return response;
}
Also used : LinkDomainToLdapResponse(com.cloud.api.response.LinkDomainToLdapResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 10 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class NiciraNvpGuestNetworkGuruTest method testImplement.

@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT", "VXLAN" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(Network.State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final DeployDestination dest = mock(DeployDestination.class);
    final Zone zone = mock(Zone.class);
    when(dest.getZone()).thenReturn(zone);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
    when(agentmgr.easySend(eq(NETWORK_ID), any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), any());
}
Also used : Account(com.cloud.legacymodel.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.CreateLogicalSwitchAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) Zone(com.cloud.db.model.Zone) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.legacymodel.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.legacymodel.domain.Domain) Test(org.junit.Test)

Aggregations

Domain (com.cloud.legacymodel.domain.Domain)55 Account (com.cloud.legacymodel.user.Account)37 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)20 UserAccount (com.cloud.legacymodel.user.UserAccount)19 ArrayList (java.util.ArrayList)16 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)11 Project (com.cloud.projects.Project)11 DomainVO (com.cloud.domain.DomainVO)10 Network (com.cloud.legacymodel.network.Network)10 DomainResponse (com.cloud.api.response.DomainResponse)8 Pair (com.cloud.legacymodel.utils.Pair)7 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)7 HostVO (com.cloud.host.HostVO)6 List (java.util.List)6 Filter (com.cloud.utils.db.Filter)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)4 CloudAuthenticationException (com.cloud.legacymodel.exceptions.CloudAuthenticationException)4 NetworkVO (com.cloud.network.dao.NetworkVO)4