Search in sources :

Example 1 with AffinityGroup

use of org.apache.cloudstack.affinity.AffinityGroup in project cloudstack by apache.

the class CreateAffinityGroupCmd method create.

@Override
public void create() throws ResourceAllocationException {
    AffinityGroup result = _affinityGroupService.createAffinityGroup(this);
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create affinity group entity" + affinityGroupName);
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup)

Example 2 with AffinityGroup

use of org.apache.cloudstack.affinity.AffinityGroup in project cloudstack by apache.

the class ConfigurationManagerImpl method createZone.

@Override
@DB
public DataCenterVO createZone(final long userId, final String zoneName, final String dns1, final String dns2, final String internalDns1, final String internalDns2, final String guestCidr, final String domain, final Long domainId, final NetworkType zoneType, final String allocationStateStr, final String networkDomain, final boolean isSecurityGroupEnabled, final boolean isLocalStorageEnabled, final String ip6Dns1, final String ip6Dns2) {
    // hence the method below is generic to check for common params
    if (guestCidr != null && !NetUtils.validateGuestCidr(guestCidr)) {
        throw new InvalidParameterValueException("Please enter a valid guest cidr");
    }
    // Validate network domain
    if (networkDomain != null) {
        if (!NetUtils.verifyDomainName(networkDomain)) {
            throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + "and the hyphen ('-'); can't start or end with \"-\"");
        }
    }
    checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId, allocationStateStr, ip6Dns1, ip6Dns2);
    final byte[] bytes = (zoneName + System.currentTimeMillis()).getBytes();
    final String zoneToken = UUID.nameUUIDFromBytes(bytes).toString();
    // Create the new zone in the database
    final DataCenterVO zoneFinal = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, guestCidr, domain, domainId, zoneType, zoneToken, networkDomain, isSecurityGroupEnabled, isLocalStorageEnabled, ip6Dns1, ip6Dns2);
    if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
        final Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
        zoneFinal.setAllocationState(allocationState);
    } else {
        // Zone will be disabled since 3.0. Admin should enable it after
        // physical network and providers setup.
        zoneFinal.setAllocationState(Grouping.AllocationState.Disabled);
    }
    return Transaction.execute(new TransactionCallback<DataCenterVO>() {

        @Override
        public DataCenterVO doInTransaction(final TransactionStatus status) {
            final DataCenterVO zone = _zoneDao.persist(zoneFinal);
            CallContext.current().putContextParameter(DataCenter.class, zone.getUuid());
            if (domainId != null) {
                // zone is explicitly dedicated to this domain
                // create affinity group associated and dedicate the zone.
                final AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null);
                final DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null, group.getId());
                _dedicatedDao.persist(dedicatedResource);
            }
            // Create default system networks
            createDefaultSystemNetworks(zone.getId());
            return zone;
        }
    });
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AllocationState(com.cloud.org.Grouping.AllocationState) TransactionStatus(com.cloud.utils.db.TransactionStatus) Grouping(com.cloud.org.Grouping) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup) DB(com.cloud.utils.db.DB)

Example 3 with AffinityGroup

use of org.apache.cloudstack.affinity.AffinityGroup in project cloudstack by apache.

the class DedicatedResourceManagerImpl method createDedicateZoneResponse.

@Override
public DedicateZoneResponse createDedicateZoneResponse(DedicatedResources resource) {
    DedicateZoneResponse dedicateZoneResponse = new DedicateZoneResponse();
    DataCenterVO dc = _zoneDao.findById(resource.getDataCenterId());
    DomainVO domain = _domainDao.findById(resource.getDomainId());
    AccountVO account = _accountDao.findById(resource.getAccountId());
    AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId());
    dedicateZoneResponse.setId(resource.getUuid());
    dedicateZoneResponse.setZoneId(dc.getUuid());
    dedicateZoneResponse.setZoneName(dc.getName());
    dedicateZoneResponse.setDomainId(domain.getUuid());
    dedicateZoneResponse.setAffinityGroupId(group.getUuid());
    if (account != null) {
        dedicateZoneResponse.setAccountId(account.getUuid());
    }
    dedicateZoneResponse.setObjectName("dedicatedzone");
    return dedicateZoneResponse;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DomainVO(com.cloud.domain.DomainVO) DedicateZoneResponse(org.apache.cloudstack.api.response.DedicateZoneResponse) AccountVO(com.cloud.user.AccountVO) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup)

Example 4 with AffinityGroup

use of org.apache.cloudstack.affinity.AffinityGroup in project cloudstack by apache.

the class DedicatedResourceManagerImpl method findOrCreateDedicatedAffinityGroup.

private AffinityGroup findOrCreateDedicatedAffinityGroup(Long domainId, Long accountId) {
    if (domainId == null) {
        return null;
    }
    AffinityGroup group = null;
    String accountName = null;
    String affinityGroupName = null;
    if (accountId != null) {
        AccountVO account = _accountDao.findById(accountId);
        accountName = account.getAccountName();
        group = _affinityGroupDao.findByAccountAndType(accountId, "ExplicitDedication");
        if (group != null) {
            return group;
        }
        // default to a groupname with account/domain information
        affinityGroupName = "DedicatedGrp-" + accountName;
    } else {
        // domain level group
        group = _affinityGroupDao.findDomainLevelGroupByType(domainId, "ExplicitDedication");
        if (group != null) {
            return group;
        }
        // default to a groupname with account/domain information
        String domainName = _domainDao.findById(domainId).getName();
        affinityGroupName = "DedicatedGrp-domain-" + domainName;
    }
    group = _affinityGroupService.createAffinityGroup(accountName, null, domainId, affinityGroupName, "ExplicitDedication", "dedicated resources group");
    return group;
}
Also used : AccountVO(com.cloud.user.AccountVO) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup)

Example 5 with AffinityGroup

use of org.apache.cloudstack.affinity.AffinityGroup in project cloudstack by apache.

the class DedicatedResourceManagerImpl method createDedicatePodResponse.

@Override
public DedicatePodResponse createDedicatePodResponse(DedicatedResources resource) {
    DedicatePodResponse dedicatePodResponse = new DedicatePodResponse();
    HostPodVO pod = _podDao.findById(resource.getPodId());
    DomainVO domain = _domainDao.findById(resource.getDomainId());
    AccountVO account = _accountDao.findById(resource.getAccountId());
    AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId());
    dedicatePodResponse.setId(resource.getUuid());
    dedicatePodResponse.setPodId(pod.getUuid());
    dedicatePodResponse.setPodName(pod.getName());
    dedicatePodResponse.setDomainId(domain.getUuid());
    dedicatePodResponse.setAffinityGroupId(group.getUuid());
    if (account != null) {
        dedicatePodResponse.setAccountId(account.getUuid());
    }
    dedicatePodResponse.setObjectName("dedicatedpod");
    return dedicatePodResponse;
}
Also used : DomainVO(com.cloud.domain.DomainVO) DedicatePodResponse(org.apache.cloudstack.api.response.DedicatePodResponse) HostPodVO(com.cloud.dc.HostPodVO) AccountVO(com.cloud.user.AccountVO) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup)

Aggregations

AffinityGroup (org.apache.cloudstack.affinity.AffinityGroup)15 DataCenterVO (com.cloud.dc.DataCenterVO)6 AccountVO (com.cloud.user.AccountVO)6 ClusterVO (com.cloud.dc.ClusterVO)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)5 HostPodVO (com.cloud.dc.HostPodVO)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 HostVO (com.cloud.host.HostVO)5 Account (com.cloud.user.Account)5 DB (com.cloud.utils.db.DB)5 TransactionStatus (com.cloud.utils.db.TransactionStatus)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 DomainVO (com.cloud.domain.DomainVO)4 ActionEvent (com.cloud.event.ActionEvent)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ConfigurationException (javax.naming.ConfigurationException)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 Network (com.cloud.network.Network)2 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)2