Search in sources :

Example 71 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method createDedicatePodResponse.

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

Example 72 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method dedicateHost.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_DEDICATE_RESOURCE, eventDescription = "dedicating a Host")
public List<DedicatedResourceVO> dedicateHost(final Long hostId, final Long domainId, final String accountName) {
    Long accountId = null;
    if (accountName != null) {
        final Account caller = CallContext.current().getCallingAccount();
        final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, null);
        accountId = owner.getId();
    }
    checkAccountAndDomain(accountId, domainId);
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Unable to find host by id " + hostId);
    } else {
        // check if host is of routing type
        if (host.getType() != Host.Type.Routing) {
            throw new CloudRuntimeException("Invalid host type for host " + host.getName());
        }
        final DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId);
        final DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId());
        final DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId());
        final DedicatedResourceVO dedicatedZoneOfHost = _dedicatedDao.findByZoneId(host.getDataCenterId());
        if (dedicatedHost != null) {
            s_logger.error("Host " + host.getName() + " is already dedicated");
            throw new CloudRuntimeException("Host " + host.getName() + " is already dedicated");
        }
        if (dedicatedClusterOfHost != null) {
            final boolean domainIdInChildreanList = getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId);
            // can dedicate a host to an account/domain if cluster is dedicated to parent-domain
            if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
                final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
                s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated");
                throw new CloudRuntimeException("Host's Cluster " + cluster.getName() + " is already dedicated");
            }
        }
        if (dedicatedPodOfHost != null) {
            final boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId);
            // can dedicate a host to an account/domain if pod is dedicated to parent-domain
            if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
                final HostPodVO pod = _podDao.findById(host.getPodId());
                s_logger.error("Host's Pod " + pod.getName() + " is already dedicated");
                throw new CloudRuntimeException("Host's Pod " + pod.getName() + " is already dedicated");
            }
        }
        if (dedicatedZoneOfHost != null) {
            final boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId);
            // can dedicate a host to an account/domain if zone is dedicated to parent-domain
            if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
                final Zone zone = zoneRepository.findOne(host.getDataCenterId());
                s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated");
                throw new CloudRuntimeException("Host's Data Center " + zone.getName() + " is already dedicated");
            }
        }
    }
    final List<Long> childDomainIds = getDomainChildIds(domainId);
    childDomainIds.add(domainId);
    checkHostSuitabilityForExplicitDedication(accountId, childDomainIds, hostId);
    final Long accountIdFinal = accountId;
    return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>() {

        @Override
        public List<DedicatedResourceVO> doInTransaction(final TransactionStatus status) {
            // find or create the affinity group by name under this account/domain
            final AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal);
            if (group == null) {
                s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group");
                throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
            }
            DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, null, hostId, null, null, group.getId());
            try {
                dedicatedResource.setDomainId(domainId);
                if (accountIdFinal != null) {
                    dedicatedResource.setAccountId(accountIdFinal);
                }
                dedicatedResource = _dedicatedDao.persist(dedicatedResource);
            } catch (final Exception e) {
                s_logger.error("Unable to dedicate host due to " + e.getMessage(), e);
                throw new CloudRuntimeException("Failed to dedicate host. Please contact Cloud Support.");
            }
            final List<DedicatedResourceVO> result = new ArrayList<>();
            result.add(dedicatedResource);
            return result;
        }
    });
}
Also used : Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) Zone(com.cloud.db.model.Zone) TransactionStatus(com.cloud.utils.db.TransactionStatus) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) AffinityGroup(com.cloud.affinity.AffinityGroup) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) List(java.util.List) ArrayList(java.util.ArrayList) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 73 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method deletePod.

@Override
@DB
public boolean deletePod(final DeletePodCmd cmd) {
    final Long podId = cmd.getId();
    // Make sure the pod exists
    if (!validPod(podId)) {
        throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist.");
    }
    checkIfPodIsDeletable(podId);
    final HostPodVO pod = _podDao.findById(podId);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // Delete private ip addresses for the pod if there are any
            final List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(podId, pod.getDataCenterId());
            if (!privateIps.isEmpty()) {
                if (!_privateIpAddressDao.deleteIpAddressByPod(podId)) {
                    throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
                }
            }
            // Delete link local ip addresses for the pod
            final List<DataCenterLinkLocalIpAddressVO> localIps = _linkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId());
            if (!localIps.isEmpty()) {
                if (!_linkLocalIpAllocDao.deleteIpAddressByPod(podId)) {
                    throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
                }
            }
            // Delete vlans associated with the pod
            final List<? extends Vlan> vlans = _networkModel.listPodVlans(podId);
            if (vlans != null && !vlans.isEmpty()) {
                for (final Vlan vlan : vlans) {
                    _vlanDao.remove(vlan.getId());
                }
            }
            // Delete corresponding capacity records
            _capacityDao.removeBy(null, null, podId, null, null);
            // Delete the pod
            if (!_podDao.remove(podId)) {
                throw new CloudRuntimeException("Failed to delete pod " + podId);
            }
            // remove from dedicated resources
            final DedicatedResourceVO dr = _dedicatedDao.findByPodId(podId);
            if (dr != null) {
                _dedicatedDao.remove(dr.getId());
            }
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(com.cloud.dc.Vlan) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostPodVO(com.cloud.dc.HostPodVO) DB(com.cloud.utils.db.DB)

Example 74 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class AlertGenerator method publishAlertOnEventBus.

public static void publishAlertOnEventBus(final String alertType, final long dataCenterId, final Long podId, final String subject, final String body) {
    final String configKey = Config.PublishAlertEvent.key();
    final String value = s_configDao.getValue(configKey);
    final boolean configValue = Boolean.parseBoolean(value);
    if (!configValue) {
        return;
    }
    try {
        s_eventBus = ComponentContext.getComponent(EventBus.class);
    } catch (final NoSuchBeanDefinitionException nbe) {
        // no provider is configured to provide events bus, so just return
        return;
    }
    final com.cloud.framework.events.Event event = new Event(ManagementService.Name, EventCategory.ALERT_EVENT.getName(), alertType, null, null);
    final Map<String, String> eventDescription = new HashMap<>();
    final Zone zone = s_zoneRepository.findOne(dataCenterId);
    final HostPodVO pod = s_podDao.findById(podId);
    eventDescription.put("event", alertType);
    if (zone != null) {
        eventDescription.put("dataCenterId", zone.getUuid());
    } else {
        eventDescription.put("dataCenterId", null);
    }
    if (pod != null) {
        eventDescription.put("podId", pod.getUuid());
    } else {
        eventDescription.put("podId", null);
    }
    eventDescription.put("subject", subject);
    eventDescription.put("body", body);
    final String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    event.setDescription(eventDescription);
    try {
        s_eventBus.publish(event);
    } catch (final EventBusException e) {
        s_logger.warn("Failed to publish alert on the the event bus.");
    }
}
Also used : HashMap(java.util.HashMap) Zone(com.cloud.model.Zone) EventBus(com.cloud.framework.events.EventBus) HostPodVO(com.cloud.dc.HostPodVO) Date(java.util.Date) Event(com.cloud.framework.events.Event) Event(com.cloud.framework.events.Event) EventBusException(com.cloud.framework.events.EventBusException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 75 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class XcpServerDiscoverer method createHostVOForDirectConnectAgent.

@Override
public HostVO createHostVOForDirectConnectAgent(final HostVO host, final StartupCommand[] startup, final ServerResource resource, final Map<String, String> details, final List<String> hostTags) {
    final StartupCommand firstCmd = startup[0];
    if (!(firstCmd instanceof StartupRoutingCommand)) {
        return null;
    }
    final StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
    if (ssCmd.getHypervisorType() != HypervisorType.XenServer) {
        return null;
    }
    final HostPodVO pod = _podDao.findById(host.getPodId());
    final Zone zone = zoneRepository.findOne(host.getDataCenterId());
    s_logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.XenServer + ". Checking CIDR...");
    _resourceMgr.checkCIDR(pod, zone, ssCmd.getPrivateIpAddress(), ssCmd.getPrivateNetmask());
    return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.XenServer, details, hostTags);
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) Zone(com.cloud.model.Zone) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HostPodVO(com.cloud.dc.HostPodVO)

Aggregations

HostPodVO (com.cloud.dc.HostPodVO)126 ArrayList (java.util.ArrayList)52 HostVO (com.cloud.host.HostVO)47 ClusterVO (com.cloud.dc.ClusterVO)46 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 DataCenterVO (com.cloud.dc.DataCenterVO)39 Account (com.cloud.user.Account)25 DB (com.cloud.utils.db.DB)25 Test (org.junit.Test)23 ConfigurationException (javax.naming.ConfigurationException)22 TransactionStatus (com.cloud.utils.db.TransactionStatus)21 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 VMInstanceVO (com.cloud.vm.VMInstanceVO)18 Random (java.util.Random)18 VolumeVO (com.cloud.storage.VolumeVO)17 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)16 HashMap (java.util.HashMap)16 List (java.util.List)16 Zone (com.cloud.db.model.Zone)15 DataCenter (com.cloud.dc.DataCenter)14