Search in sources :

Example 1 with DomainVO

use of com.cloud.domain.DomainVO in project CloudStack-archive by CloudStack-extras.

the class TestAsyncJobManager method testDomain.

public void testDomain() {
    getRandomMilliseconds(1, 100);
    DomainDao domainDao = new DomainDaoImpl();
    DomainVO domain1 = new DomainVO("d1", 2L, 1L, null);
    domainDao.create(domain1);
    DomainVO domain2 = new DomainVO("d2", 2L, 1L, null);
    domainDao.create(domain2);
    DomainVO domain3 = new DomainVO("d3", 2L, 1L, null);
    domainDao.create(domain3);
    DomainVO domain11 = new DomainVO("d11", 2L, domain1.getId(), null);
    domainDao.create(domain11);
    domainDao.remove(domain11.getId());
    DomainVO domain12 = new DomainVO("d12", 2L, domain1.getId(), null);
    domainDao.create(domain12);
    domainDao.remove(domain3.getId());
    DomainVO domain4 = new DomainVO("d4", 2L, 1L, null);
    domainDao.create(domain4);
}
Also used : DomainVO(com.cloud.domain.DomainVO) DomainDaoImpl(com.cloud.domain.dao.DomainDaoImpl) DomainDao(com.cloud.domain.dao.DomainDao)

Example 2 with DomainVO

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

the class NuageVspEntityBuilder method buildVspNetwork.

public VspNetwork buildVspNetwork(long domainId, Network network) {
    VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder().id(network.getId()).uuid(network.getUuid()).name(network.getName()).cidr(network.getCidr()).gateway(network.getGateway());
    DomainVO domain = _domainDao.findById(domainId);
    VspDomain vspDomain = buildVspDomain(domain);
    vspNetworkBuilder.domain(vspDomain);
    AccountVO account = _accountDao.findById(network.getAccountId());
    if (account != null) {
        vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
    }
    NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy()).publicAccess(networkOffering.getSupportsPublicAccess());
    if (network.getVpcId() != null) {
        VpcVO vpc = _vpcDao.findById(network.getVpcId());
        vspNetworkBuilder.vpcUuid(vpc.getUuid()).vpcName(vpc.getName()).networkType(VspNetwork.NetworkType.Vpc);
    } else {
        if (networkOffering.getGuestType() == Network.GuestType.Shared) {
            List<VlanVO> vlans = _vlanDao.listVlansByNetworkIdIncludingRemoved(network.getId());
            List<VspAddressRange> vspAddressRanges = Lists.transform(vlans, new Function<VlanVO, VspAddressRange>() {

                @Nullable
                @Override
                public VspAddressRange apply(VlanVO vlanVO) {
                    return new VspAddressRange.Builder().gateway(vlanVO.getVlanGateway()).netmask(vlanVO.getVlanNetmask()).build();
                }
            });
            vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared).addressRanges(vspAddressRanges);
        } else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat) || _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
            vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
        } else {
            vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
        }
    }
    boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
    vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
    String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
    vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
    if (usesVirtualRouter(networkOffering.getId())) {
        try {
            List<Pair<String, String>> ipAddressRanges = networkOffering.getGuestType() == Network.GuestType.Shared ? getSharedIpAddressRanges(network.getId()) : getIpAddressRanges(network);
            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
            vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
        } catch (InsufficientVirtualNetworkCapacityException ex) {
            s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
            throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
        }
    }
    return vspNetworkBuilder.build();
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) VspAddressRange(net.nuage.vsp.acs.client.api.model.VspAddressRange) AccountVO(com.cloud.user.AccountVO) DomainVO(com.cloud.domain.DomainVO) VpcVO(com.cloud.network.vpc.VpcVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) VlanVO(com.cloud.dc.VlanVO) Nullable(javax.annotation.Nullable) Pair(net.nuage.vsp.acs.client.common.model.Pair)

Example 3 with DomainVO

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

the class NuageVspElementTest method testApplyStaticNats.

@Test
public void testApplyStaticNats() throws CloudException {
    final Network network = mock(Network.class);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getVpcId()).thenReturn(null);
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    final DomainVO domVo = mock(DomainVO.class);
    when(_domainDao.findById(41l)).thenReturn(domVo);
    final NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
    when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
    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.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
    final Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    assertTrue(_nuageVspElement.applyStaticNats(network, new ArrayList<StaticNat>()));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) DomainVO(com.cloud.domain.DomainVO) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) HostVO(com.cloud.host.HostVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 4 with DomainVO

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

the class NuageVspElementTest method testImplement.

@Test
public void testImplement() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, URISyntaxException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getBroadcastUri()).thenReturn(new URI(""));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination deployDest = mock(DeployDestination.class);
    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);
    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.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_ipAddressDao.listStaticNatPublicIps(NETWORK_ID)).thenReturn(new ArrayList<IPAddressVO>());
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    assertTrue(_nuageVspElement.implement(network, offering, deployDest, context));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) URI(java.net.URI) HostVO(com.cloud.host.HostVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) IPAddressVO(com.cloud.network.dao.IPAddressVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 5 with DomainVO

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

the class ProjectManagerImpl method addAccountToProject.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project", async = true)
public boolean addAccountToProject(long projectId, String accountName, String email) {
    Account caller = CallContext.current().getCallingAccount();
    //check that the project exists
    Project project = getProject(projectId);
    if (project == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
        ex.addProxyObject(String.valueOf(projectId), "projectId");
        throw ex;
    }
    //User can be added to Active project only
    if (project.getState() != Project.State.Active) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Can't add account to the specified project id in state=" + project.getState() + " as it's no longer active");
        ex.addProxyObject(project.getUuid(), "projectId");
        throw ex;
    }
    //check that account-to-add exists
    Account account = null;
    if (accountName != null) {
        account = _accountMgr.getActiveAccountByName(accountName, project.getDomainId());
        if (account == null) {
            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account name=" + accountName + " in specified domain id");
            DomainVO domain = ApiDBUtils.findDomainById(project.getDomainId());
            String domainUuid = String.valueOf(project.getDomainId());
            if (domain != null) {
                domainUuid = domain.getUuid();
            }
            ex.addProxyObject(domainUuid, "domainId");
            throw ex;
        }
        //verify permissions - only project owner can assign
        _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
        //Check if the account already added to the project
        ProjectAccount projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, account.getId());
        if (projectAccount != null) {
            s_logger.debug("Account " + accountName + " already added to the project id=" + projectId);
            return true;
        }
    }
    if (_invitationRequired) {
        return inviteAccountToProject(project, account, email);
    } else {
        if (account == null) {
            throw new InvalidParameterValueException("Account information is required for assigning account to the project");
        }
        if (assignAccountToProject(project, account.getId(), ProjectAccount.Role.Regular) != null) {
            return true;
        } else {
            s_logger.warn("Failed to add account " + accountName + " to project id=" + projectId);
            return false;
        }
    }
}
Also used : Account(com.cloud.user.Account) DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent)

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