Search in sources :

Example 96 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class NuageVspManagerImpl method initMessageBusListeners.

@DB
private void initMessageBusListeners() {
    // Create corresponding enterprise and profile in VSP when creating a CS Domain
    _messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() {

        @Override
        public void onPublishMessage(String senderAddress, String subject, Object args) {
            Long domainId = (Long) args;
            Domain domain = _domainDao.findById(domainId);
            try {
                _domainDao.acquireInLockTable(domain.getId());
                List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
                for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                    VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
                    SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.ADD);
                    _agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
                }
            } finally {
                _domainDao.releaseFromLockTable(domain.getId());
            }
        }
    });
    // Clean up corresponding resources in VSP when deleting a CS Domain
    _messageBus.subscribe(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {

        @Override
        public void onPublishMessage(String senderAddress, String subject, Object args) {
            DomainVO domain = (DomainVO) args;
            List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
            for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
                CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
                _agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
            }
        }
    });
    // Delete corresponding enterprise and profile in VSP when deleting a CS Domain
    _messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {

        @Override
        public void onPublishMessage(String senderAddress, String subject, Object args) {
            DomainVO domain = (DomainVO) args;
            List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
            for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
                SyncDomainCommand syncCmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.REMOVE);
                _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
            }
        }
    });
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) MessageSubscriber(org.apache.cloudstack.framework.messagebus.MessageSubscriber) SyncDomainCommand(com.cloud.agent.api.sync.SyncDomainCommand) DomainVO(com.cloud.domain.DomainVO) CleanUpDomainCommand(com.cloud.agent.api.manager.CleanUpDomainCommand) VspDomainCleanUp(net.nuage.vsp.acs.client.api.model.VspDomainCleanUp) ArrayList(java.util.ArrayList) List(java.util.List) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) Domain(com.cloud.domain.Domain) DB(com.cloud.utils.db.DB)

Example 97 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class NuageVspElementTest method testShutdownVpc.

@Test
public void testShutdownVpc() throws Exception {
    final Vpc vpc = mock(Vpc.class);
    when(vpc.getUuid()).thenReturn("aaaaaa");
    when(vpc.getState()).thenReturn(Vpc.State.Inactive);
    when(vpc.getDomainId()).thenReturn(NETWORK_ID);
    when(vpc.getZoneId()).thenReturn(NETWORK_ID);
    when(vpc.getId()).thenReturn(NETWORK_ID);
    final DomainVO dom = mock(DomainVO.class);
    when(dom.getName()).thenReturn("domain");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(dom);
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    PhysicalNetworkVO physNet = mock(PhysicalNetworkVO.class);
    when(physNet.getIsolationMethods()).thenReturn(Lists.newArrayList(PhysicalNetwork.IsolationMethod.VSP.name()));
    when(physNet.getId()).thenReturn(NETWORK_ID);
    when(_physicalNetworkDao.listByZone(NETWORK_ID)).thenReturn(Lists.newArrayList(physNet));
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Lists.newArrayList(nuageVspDevice));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    DomainRouterVO domainRouter = mock(DomainRouterVO.class);
    when(domainRouter.getUuid()).thenReturn("aaaaaa");
    when(_domainRouterDao.listByVpcId(NETWORK_ID)).thenReturn(Lists.newArrayList(domainRouter));
    final Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    assertTrue(_nuageVspElement.shutdownVpc(vpc, context));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) DomainVO(com.cloud.domain.DomainVO) Account(com.cloud.user.Account) Answer(com.cloud.agent.api.Answer) Vpc(com.cloud.network.vpc.Vpc) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) ReservationContext(com.cloud.vm.ReservationContext) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 98 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testTrash.

@Test
public void testTrash() throws Exception {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getName()).thenReturn("trash");
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
    final DomainVO domain = mock(DomainVO.class);
    when(domain.getUuid()).thenReturn("aaaaaa");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] { nuageVspDevice }));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    when(_nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
    assertTrue(_nuageVspGuestNetworkGuru.trash(network, offering));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) DomainVO(com.cloud.domain.DomainVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) HostVO(com.cloud.host.HostVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 99 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class IAMApiServiceTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    caller = new AccountVO(callerAccountName, callerDomainId, null, Account.ACCOUNT_TYPE_ADMIN, UUID.randomUUID().toString());
    callerId = caller.getId();
    callerDomain = new DomainVO();
    callerDomain.setPath(callerDomainPath);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
    CallContext.register(user, caller);
    when(_domainDao.findById(callerDomainId)).thenReturn(callerDomain);
    doNothing().when(_accountMgr).checkAccess(caller, callerDomain);
}
Also used : DomainVO(com.cloud.domain.DomainVO) UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 100 with DomainVO

use of com.cloud.domain.DomainVO in project cosmic by MissionCriticalCloud.

the class ResourceLimitManagerImpl method findCorrectResourceLimitForDomain.

@Override
public long findCorrectResourceLimitForDomain(final Domain domain, final ResourceType type) {
    long max = Resource.RESOURCE_UNLIMITED;
    // no limits on ROOT domain
    if (domain.getId() == Domain.ROOT_DOMAIN) {
        return Resource.RESOURCE_UNLIMITED;
    }
    // Check account
    ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(domain.getId(), ResourceOwnerType.Domain, type);
    if (limit != null) {
        max = limit.getMax().longValue();
    } else {
        // check domain hierarchy
        Long domainId = domain.getParent();
        while ((domainId != null) && (limit == null)) {
            if (domainId == Domain.ROOT_DOMAIN) {
                break;
            }
            limit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
            final DomainVO tmpDomain = _domainDao.findById(domainId);
            domainId = tmpDomain.getParent();
        }
        if (limit != null) {
            max = limit.getMax().longValue();
        } else {
            Long value;
            value = domainResourceLimitMap.get(type);
            if (value != null) {
                if (value < 0) {
                    // return unlimit if value is set to negative
                    return max;
                }
                if (type == ResourceType.primary_storage || type == ResourceType.secondary_storage) {
                    value = value * ResourceType.bytesToGiB;
                }
                return value;
            }
        }
    }
    return max;
}
Also used : DomainVO(com.cloud.domain.DomainVO) ResourceLimitVO(com.cloud.configuration.ResourceLimitVO)

Aggregations

DomainVO (com.cloud.domain.DomainVO)196 Account (com.cloud.user.Account)85 AccountVO (com.cloud.user.AccountVO)64 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)53 DomainDao (com.cloud.domain.dao.DomainDao)30 Field (java.lang.reflect.Field)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 SslCertDao (com.cloud.network.dao.SslCertDao)29 AccountManager (com.cloud.user.AccountManager)29 SslCertVO (com.cloud.network.dao.SslCertVO)27 List (java.util.List)26 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)24 Pair (com.cloud.utils.Pair)24 Domain (com.cloud.domain.Domain)23 Filter (com.cloud.utils.db.Filter)23 File (java.io.File)23 IOException (java.io.IOException)23 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)23 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22