Search in sources :

Example 96 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createExtractResponse.

// TODO: we need to deprecate uploadVO, since extract is done in a synchronous fashion
@Override
public ExtractResponse createExtractResponse(final Long id, final Long zoneId, final Long accountId, final String mode, final String url) {
    final ExtractResponse response = new ExtractResponse();
    response.setObjectName("template");
    final VMTemplateVO template = ApiDBUtils.findTemplateById(id);
    response.setId(template.getUuid());
    response.setName(template.getName());
    if (zoneId != null) {
        final DataCenter zone = ApiDBUtils.findZoneById(zoneId);
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setMode(mode);
    response.setUrl(url);
    response.setState(UploadStatus.DOWNLOAD_URL_CREATED.toString());
    final Account account = ApiDBUtils.findAccountById(accountId);
    response.setAccountId(account.getUuid());
    return response;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) DataCenter(com.cloud.legacymodel.dc.DataCenter) ExtractResponse(com.cloud.api.response.ExtractResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 97 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createAffinityGroupResponse.

@Override
public AffinityGroupResponse createAffinityGroupResponse(final AffinityGroup group) {
    final AffinityGroupResponse response = new AffinityGroupResponse();
    final Account account = ApiDBUtils.findAccountById(group.getAccountId());
    response.setId(group.getUuid());
    response.setAccountName(account.getAccountName());
    response.setName(group.getName());
    response.setType(group.getType());
    response.setDescription(group.getDescription());
    final Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
    if (domain != null) {
        response.setDomainId(domain.getUuid());
        response.setDomainName(domain.getName());
    }
    response.setObjectName("affinitygroup");
    return response;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) AffinityGroupResponse(com.cloud.affinity.AffinityGroupResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 98 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createResourceCountResponse.

@Override
public ResourceCountResponse createResourceCountResponse(final ResourceCount resourceCount) {
    final ResourceCountResponse resourceCountResponse = new ResourceCountResponse();
    if (resourceCount.getResourceOwnerType() == ResourceOwnerType.Account) {
        final Account accountTemp = ApiDBUtils.findAccountById(resourceCount.getOwnerId());
        if (accountTemp != null) {
            populateAccount(resourceCountResponse, accountTemp.getId());
            populateDomain(resourceCountResponse, accountTemp.getDomainId());
        }
    } else if (resourceCount.getResourceOwnerType() == ResourceOwnerType.Domain) {
        populateDomain(resourceCountResponse, resourceCount.getOwnerId());
    }
    resourceCountResponse.setResourceType(Integer.toString(resourceCount.getType().getOrdinal()));
    resourceCountResponse.setResourceCount(resourceCount.getCount());
    resourceCountResponse.setObjectName("resourcecount");
    return resourceCountResponse;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) ResourceCountResponse(com.cloud.api.response.ResourceCountResponse)

Example 99 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createSSHKeyPairResponse.

@Override
public SSHKeyPairResponse createSSHKeyPairResponse(final SSHKeyPair sshkeyPair, final boolean privatekey) {
    SSHKeyPairResponse response = new SSHKeyPairResponse(sshkeyPair.getName(), sshkeyPair.getFingerprint());
    if (privatekey) {
        response = new CreateSSHKeyPairResponse(sshkeyPair.getName(), sshkeyPair.getFingerprint(), sshkeyPair.getPrivateKey());
    }
    final Account account = ApiDBUtils.findAccountById(sshkeyPair.getAccountId());
    response.setAccountName(account.getAccountName());
    final Domain domain = ApiDBUtils.findDomainById(sshkeyPair.getDomainId());
    response.setDomainId(domain.getUuid());
    response.setDomainName(domain.getName());
    return response;
}
Also used : CreateSSHKeyPairResponse(com.cloud.api.response.CreateSSHKeyPairResponse) SSHKeyPairResponse(com.cloud.api.response.SSHKeyPairResponse) UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) CreateSSHKeyPairResponse(com.cloud.api.response.CreateSSHKeyPairResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 100 with Account

use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createDedicatedGuestVlanRangeResponse.

@Override
public GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(final GuestVlan vlan) {
    final GuestVlanRangeResponse guestVlanRangeResponse = new GuestVlanRangeResponse();
    guestVlanRangeResponse.setId(vlan.getUuid());
    final Long accountId = ApiDBUtils.getAccountIdForGuestVlan(vlan.getId());
    final Account owner = ApiDBUtils.findAccountById(accountId);
    if (owner != null) {
        populateAccount(guestVlanRangeResponse, owner.getId());
        populateDomain(guestVlanRangeResponse, owner.getDomainId());
    }
    guestVlanRangeResponse.setGuestVlanRange(vlan.getGuestVlanRange());
    guestVlanRangeResponse.setPhysicalNetworkId(vlan.getPhysicalNetworkId());
    final PhysicalNetworkVO physicalNetwork = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
    guestVlanRangeResponse.setZoneId(physicalNetwork.getDataCenterId());
    return guestVlanRangeResponse;
}
Also used : UserAccount(com.cloud.legacymodel.user.UserAccount) Account(com.cloud.legacymodel.user.Account) GuestVlanRangeResponse(com.cloud.api.response.GuestVlanRangeResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Aggregations

Account (com.cloud.legacymodel.user.Account)435 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)229 ActionEvent (com.cloud.event.ActionEvent)120 ArrayList (java.util.ArrayList)103 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)98 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)78 User (com.cloud.legacymodel.user.User)73 DB (com.cloud.utils.db.DB)59 List (java.util.List)58 Pair (com.cloud.legacymodel.utils.Pair)53 Network (com.cloud.legacymodel.network.Network)48 CallContext (com.cloud.context.CallContext)47 DomainVO (com.cloud.domain.DomainVO)47 UserAccount (com.cloud.legacymodel.user.UserAccount)47 Filter (com.cloud.utils.db.Filter)47 TransactionStatus (com.cloud.utils.db.TransactionStatus)40 Domain (com.cloud.legacymodel.domain.Domain)39 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)37 Test (org.junit.Test)36 Ternary (com.cloud.legacymodel.utils.Ternary)34