Search in sources :

Example 41 with Domain

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

the class ApiResponseHelper method createLBHealthCheckPolicyResponse.

@Override
public LBHealthCheckResponse createLBHealthCheckPolicyResponse(final List<? extends HealthCheckPolicy> healthcheckPolicies, final LoadBalancer lb) {
    final LBHealthCheckResponse hcResponse = new LBHealthCheckResponse();
    if (lb == null) {
        return hcResponse;
    }
    hcResponse.setlbRuleId(lb.getUuid());
    final Account account = ApiDBUtils.findAccountById(lb.getAccountId());
    if (account != null) {
        hcResponse.setAccountName(account.getAccountName());
        final Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
        if (domain != null) {
            hcResponse.setDomainId(domain.getUuid());
            hcResponse.setDomainName(domain.getName());
        }
    }
    final List<LBHealthCheckPolicyResponse> responses = new ArrayList<>();
    for (final HealthCheckPolicy healthcheckPolicy : healthcheckPolicies) {
        final LBHealthCheckPolicyResponse ruleResponse = new LBHealthCheckPolicyResponse(healthcheckPolicy);
        responses.add(ruleResponse);
    }
    hcResponse.setRules(responses);
    hcResponse.setObjectName("healthcheckpolicies");
    return hcResponse;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) LBHealthCheckPolicyResponse(com.cloud.api.response.LBHealthCheckPolicyResponse) ArrayList(java.util.ArrayList) LBHealthCheckResponse(com.cloud.api.response.LBHealthCheckResponse) Domain(com.cloud.legacymodel.domain.Domain) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 42 with Domain

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

the class ApiResponseHelper method createTemplatePermissionsResponse.

@Override
public TemplatePermissionsResponse createTemplatePermissionsResponse(final ResponseView view, final List<String> accountNames, final Long id) {
    Long templateOwnerDomain = null;
    final VirtualMachineTemplate template = ApiDBUtils.findTemplateById(id);
    final Account templateOwner = ApiDBUtils.findAccountById(template.getAccountId());
    if (view == ResponseView.Full) {
        // from that
        if (templateOwner != null) {
            templateOwnerDomain = templateOwner.getDomainId();
        }
    }
    final TemplatePermissionsResponse response = new TemplatePermissionsResponse();
    response.setId(template.getUuid());
    response.setPublicTemplate(template.isPublicTemplate());
    if (view == ResponseView.Full && templateOwnerDomain != null) {
        final Domain domain = ApiDBUtils.findDomainById(templateOwnerDomain);
        if (domain != null) {
            response.setDomainId(domain.getUuid());
        }
    }
    // Set accounts
    final List<String> projectIds = new ArrayList<>();
    final List<String> regularAccounts = new ArrayList<>();
    for (final String accountName : accountNames) {
        final Account account = ApiDBUtils.findAccountByNameDomain(accountName, templateOwner.getDomainId());
        if (account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
            regularAccounts.add(accountName);
        } else {
            // convert account to projectIds
            final Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
            if (project.getUuid() != null && !project.getUuid().isEmpty()) {
                projectIds.add(project.getUuid());
            } else {
                projectIds.add(String.valueOf(project.getId()));
            }
        }
    }
    if (!projectIds.isEmpty()) {
        response.setProjectIds(projectIds);
    }
    if (!regularAccounts.isEmpty()) {
        response.setAccountNames(regularAccounts);
    }
    response.setObjectName("templatepermission");
    return response;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) Project(com.cloud.projects.Project) VirtualMachineTemplate(com.cloud.legacymodel.storage.VirtualMachineTemplate) ArrayList(java.util.ArrayList) Domain(com.cloud.legacymodel.domain.Domain) TemplatePermissionsResponse(com.cloud.api.response.TemplatePermissionsResponse)

Example 43 with Domain

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

the class DomainDaoImpl method getDomainParentIds.

@Override
public Set<Long> getDomainParentIds(final long domainId) {
    final Set<Long> parentDomains = new HashSet<>();
    Domain domain = findById(domainId);
    if (domain != null) {
        parentDomains.add(domain.getId());
        while (domain.getParent() != null) {
            domain = findById(domain.getParent());
            parentDomains.add(domain.getId());
        }
    }
    return parentDomains;
}
Also used : Domain(com.cloud.legacymodel.domain.Domain) HashSet(java.util.HashSet)

Example 44 with Domain

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

the class ApiResponseHelper method createVlanIpRangeResponse.

@Override
public VlanIpRangeResponse createVlanIpRangeResponse(final Vlan vlan) {
    final Long podId = ApiDBUtils.getPodIdForVlan(vlan.getId());
    final VlanIpRangeResponse vlanResponse = new VlanIpRangeResponse();
    vlanResponse.setId(vlan.getUuid());
    if (vlan.getVlanType() != null) {
        vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
    }
    vlanResponse.setVlan(vlan.getVlanTag());
    final DataCenter zone = ApiDBUtils.findZoneById(vlan.getDataCenterId());
    if (zone != null) {
        vlanResponse.setZoneId(zone.getUuid());
    }
    if (podId != null) {
        final HostPodVO pod = ApiDBUtils.findPodById(podId);
        if (pod != null) {
            vlanResponse.setPodId(pod.getUuid());
            vlanResponse.setPodName(pod.getName());
        }
    }
    vlanResponse.setGateway(vlan.getVlanGateway());
    vlanResponse.setNetmask(vlan.getVlanNetmask());
    // get start ip and end ip of corresponding vlan
    final String ipRange = vlan.getIpRange();
    if (ipRange != null) {
        final String[] range = ipRange.split("-");
        vlanResponse.setStartIp(range[0]);
        vlanResponse.setEndIp(range[1]);
    }
    vlanResponse.setIp6Gateway(vlan.getIp6Gateway());
    vlanResponse.setIp6Cidr(vlan.getIp6Cidr());
    final String ip6Range = vlan.getIp6Range();
    if (ip6Range != null) {
        final String[] range = ip6Range.split("-");
        vlanResponse.setStartIpv6(range[0]);
        vlanResponse.setEndIpv6(range[1]);
    }
    if (vlan.getNetworkId() != null) {
        final Network nw = ApiDBUtils.findNetworkById(vlan.getNetworkId());
        if (nw != null) {
            vlanResponse.setNetworkId(nw.getUuid());
        }
    }
    final Account owner = ApiDBUtils.getVlanAccount(vlan.getId());
    if (owner != null) {
        populateAccount(vlanResponse, owner.getId());
        populateDomain(vlanResponse, owner.getDomainId());
    } else {
        final Domain domain = ApiDBUtils.getVlanDomain(vlan.getId());
        if (domain != null) {
            populateDomain(vlanResponse, domain.getId());
        } else {
            final Long networkId = vlan.getNetworkId();
            if (networkId != null) {
                final Network network = this._ntwkModel.getNetwork(networkId);
                if (network != null) {
                    final Long accountId = network.getAccountId();
                    populateAccount(vlanResponse, accountId);
                    populateDomain(vlanResponse, ApiDBUtils.findAccountById(accountId).getDomainId());
                }
            }
        }
    }
    if (vlan.getPhysicalNetworkId() != null) {
        final PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
        if (pnw != null) {
            vlanResponse.setPhysicalNetworkId(pnw.getUuid());
        }
    }
    vlanResponse.setObjectName("vlan");
    return vlanResponse;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) VlanIpRangeResponse(com.cloud.api.response.VlanIpRangeResponse) DataCenter(com.cloud.legacymodel.dc.DataCenter) PhysicalNetwork(com.cloud.network.PhysicalNetwork) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) Domain(com.cloud.legacymodel.domain.Domain) HostPodVO(com.cloud.dc.HostPodVO)

Example 45 with Domain

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

the class ApiResponseHelper method createLBStickinessPolicyResponse.

@Override
public LBStickinessResponse createLBStickinessPolicyResponse(final StickinessPolicy stickinessPolicy, final LoadBalancer lb) {
    final LBStickinessResponse spResponse = new LBStickinessResponse();
    spResponse.setlbRuleId(lb.getUuid());
    final Account accountTemp = ApiDBUtils.findAccountById(lb.getAccountId());
    if (accountTemp != null) {
        spResponse.setAccountName(accountTemp.getAccountName());
        final Domain domain = ApiDBUtils.findDomainById(accountTemp.getDomainId());
        if (domain != null) {
            spResponse.setDomainId(domain.getUuid());
            spResponse.setDomainName(domain.getName());
        }
    }
    final List<LBStickinessPolicyResponse> responses = new ArrayList<>();
    final LBStickinessPolicyResponse ruleResponse = new LBStickinessPolicyResponse(stickinessPolicy);
    responses.add(ruleResponse);
    spResponse.setRules(responses);
    spResponse.setObjectName("stickinesspolicies");
    return spResponse;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) ArrayList(java.util.ArrayList) Domain(com.cloud.legacymodel.domain.Domain) LBStickinessPolicyResponse(com.cloud.api.response.LBStickinessPolicyResponse) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

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