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;
}
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;
}
});
}
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;
}
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.");
}
}
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);
}
Aggregations