use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class FirstFitPlanner method scanPodsForDestination.
private List<Long> scanPodsForDestination(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) {
final ServiceOffering offering = vmProfile.getServiceOffering();
final int requiredCpu = offering.getCpu();
final long requiredRam = offering.getRamSize() * 1024L * 1024L;
// list pods under this zone by cpu and ram capacity
List<Long> prioritizedPodIds = new ArrayList<>();
final Pair<List<Long>, Map<Long, Double>> podCapacityInfo = listPodsByCapacity(plan.getDataCenterId(), requiredCpu, requiredRam);
final List<Long> podsWithCapacity = podCapacityInfo.first();
if (!podsWithCapacity.isEmpty()) {
if (avoid.getPodsToAvoid() != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the podId list these pods from avoid set: " + avoid.getPodsToAvoid());
}
podsWithCapacity.removeAll(avoid.getPodsToAvoid());
}
if (!isRootAdmin(vmProfile)) {
final List<Long> disabledPods = listDisabledPods(plan.getDataCenterId());
if (!disabledPods.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the podId list these pods that are disabled: " + disabledPods);
}
podsWithCapacity.removeAll(disabledPods);
}
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No pods found having a host with enough capacity, returning.");
}
return null;
}
if (!podsWithCapacity.isEmpty()) {
prioritizedPodIds = reorderPods(podCapacityInfo, vmProfile, plan);
if (prioritizedPodIds == null || prioritizedPodIds.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No Pods found for destination, returning.");
}
return null;
}
final List<Long> clusterList = new ArrayList<>();
// loop over pods
for (final Long podId : prioritizedPodIds) {
s_logger.debug("Checking resources under Pod: " + podId);
final List<Long> clustersUnderPod = scanClustersForDestinationInZoneOrPod(podId, false, vmProfile, plan, avoid);
if (clustersUnderPod != null) {
clusterList.addAll(clustersUnderPod);
}
}
return clusterList;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No Pods found after removing disabled pods and pods in avoid list, returning.");
}
return null;
}
}
use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method upgradeVmDb.
@Override
public boolean upgradeVmDb(final long vmId, final long serviceOfferingId) {
final VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
vmForUpdate.setServiceOfferingId(serviceOfferingId);
final ServiceOffering newSvcOff = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
vmForUpdate.setHaEnabled(newSvcOff.getOfferHA());
vmForUpdate.setLimitCpuUse(newSvcOff.getLimitCpuUse());
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
return _vmDao.update(vmId, vmForUpdate);
}
use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method orchestrateReConfigureVm.
private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
final long newServiceofferingId = vm.getServiceOfferingId();
final ServiceOffering newServiceOffering = _offeringDao.findById(vm.getId(), newServiceofferingId);
final HostVO hostVo = _hostDao.findById(vm.getHostId());
final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId());
final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId());
final long minMemory = (long) (newServiceOffering.getRamSize() / memoryOvercommitRatio);
final ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse());
final Long dstHostId = vm.getHostId();
final ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId());
work.setStep(Step.Prepare);
work.setResourceType(ItWorkVO.ResourceType.Host);
work.setResourceId(vm.getHostId());
_workDao.persist(work);
boolean success = false;
try {
if (reconfiguringOnExistingHost) {
vm.setServiceOfferingId(oldServiceOffering.getId());
// release the old capacity
_capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
vm.setServiceOfferingId(newServiceofferingId);
// lock the new capacity
_capacityMgr.allocateVmCapacity(vm, false);
}
final Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), reconfigureCmd);
if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
}
success = true;
} catch (final OperationTimedoutException e) {
throw new AgentUnavailableException("Operation timed out on reconfiguring " + vm, dstHostId);
} catch (final AgentUnavailableException e) {
throw e;
} finally {
if (!success) {
// release the new capacity
_capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
vm.setServiceOfferingId(oldServiceOffering.getId());
// allocate the old capacity
_capacityMgr.allocateVmCapacity(vm, false);
}
}
return vm;
}
use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createNetworkOfferingResponse.
@Override
public NetworkOfferingResponse createNetworkOfferingResponse(final NetworkOffering offering) {
final NetworkOfferingResponse response = new NetworkOfferingResponse();
response.setId(offering.getUuid());
response.setName(offering.getName());
response.setDisplayText(offering.getDisplayText());
response.setTags(offering.getTags());
response.setTrafficType(offering.getTrafficType().toString());
response.setIsDefault(offering.isDefault());
response.setSpecifyVlan(offering.getSpecifyVlan());
response.setConserveMode(offering.isConserveMode());
response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
response.setAvailability(offering.getAvailability().toString());
response.setIsPersistent(offering.getIsPersistent());
response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
response.setEgressDefaultPolicy(offering.getEgressDefaultPolicy());
response.setConcurrentConnections(offering.getConcurrentConnections());
response.setSupportsStrechedL2Subnet(offering.getSupportsStrechedL2());
final Long so;
if (offering.getServiceOfferingId() != null) {
so = offering.getServiceOfferingId();
} else {
so = ApiDBUtils.findDefaultRouterServiceOffering();
}
if (so != null) {
final ServiceOffering serviceOffering = ApiDBUtils.findServiceOfferingById(so);
if (serviceOffering != null) {
response.setServiceOfferingId(serviceOffering.getUuid());
response.setServiceOfferingName(serviceOffering.getName());
}
}
final ServiceOffering secondaryServiceOffering = _serviceOfferingDao.findById(offering.getSecondaryServiceOfferingId());
if (secondaryServiceOffering != null) {
response.setSecondaryServiceOfferingId(secondaryServiceOffering.getUuid());
response.setSecondaryServiceOfferingName(secondaryServiceOffering.getName());
}
if (offering.getGuestType() != null) {
response.setGuestIpType(offering.getGuestType().toString());
}
response.setState(offering.getState().name());
final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
final List<ServiceResponse> serviceResponses = new ArrayList<>();
for (final Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
final Service service = entry.getKey();
final Set<Provider> srvc_providers = entry.getValue();
final ServiceResponse svcRsp = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
svcRsp.setName(service.getName());
final List<ProviderResponse> providers = getProviderResponses(srvc_providers);
svcRsp.setProviders(providers);
if (Service.Lb == service) {
final List<CapabilityResponse> lbCapResponse = new ArrayList<>();
final CapabilityResponse lbIsoaltion = new CapabilityResponse();
lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
lbCapResponse.add(lbIsoaltion);
final CapabilityResponse eLb = new CapabilityResponse();
eLb.setName(Capability.ElasticLb.getName());
eLb.setValue(offering.getElasticLb() ? "true" : "false");
lbCapResponse.add(eLb);
final CapabilityResponse inline = new CapabilityResponse();
inline.setName(Capability.InlineMode.getName());
inline.setValue(offering.isInline() ? "true" : "false");
lbCapResponse.add(inline);
svcRsp.setCapabilities(lbCapResponse);
} else if (Service.SourceNat == service) {
final List<CapabilityResponse> capabilities = new ArrayList<>();
final CapabilityResponse sharedSourceNat = new CapabilityResponse();
sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
capabilities.add(sharedSourceNat);
final CapabilityResponse redundantRouter = new CapabilityResponse();
redundantRouter.setName(Capability.RedundantRouter.getName());
redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
capabilities.add(redundantRouter);
svcRsp.setCapabilities(capabilities);
} else if (service == Service.StaticNat) {
final List<CapabilityResponse> staticNatCapResponse = new ArrayList<>();
final CapabilityResponse eIp = new CapabilityResponse();
eIp.setName(Capability.ElasticIp.getName());
eIp.setValue(offering.getElasticIp() ? "true" : "false");
staticNatCapResponse.add(eIp);
final CapabilityResponse associatePublicIp = new CapabilityResponse();
associatePublicIp.setName(Capability.AssociatePublicIP.getName());
associatePublicIp.setValue(offering.getAssociatePublicIP() ? "true" : "false");
staticNatCapResponse.add(associatePublicIp);
svcRsp.setCapabilities(staticNatCapResponse);
}
serviceResponses.add(svcRsp);
}
response.setForVpc(_configMgr.isOfferingForVpc(offering));
response.setServices(serviceResponses);
// set network offering details
final Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
if (details != null && !details.isEmpty()) {
response.setDetails(details);
}
response.setObjectName("networkoffering");
return response;
}
use of com.cloud.offering.ServiceOffering in project cosmic by MissionCriticalCloud.
the class FirstFitAllocator method allocateTo.
@Override
public List<Host> allocateTo(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final Type type, final ExcludeList avoid, final List<? extends Host> hosts, final int returnUpTo, final boolean considerReservedCapacity) {
final long dcId = plan.getDataCenterId();
final Long podId = plan.getPodId();
final Long clusterId = plan.getClusterId();
final ServiceOffering offering = vmProfile.getServiceOffering();
final VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
final Account account = vmProfile.getOwner();
List<Host> suitableHosts = new ArrayList<>();
final List<Host> hostsCopy = new ArrayList<>(hosts);
if (type == Host.Type.Storage) {
// routing or not.
return suitableHosts;
}
final String hostTagOnOffering = offering.getHostTag();
final String hostTagOnTemplate = template.getTemplateTag();
final boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
final boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
final String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (haVmTag != null) {
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
} else {
if (hostTagOnOffering == null && hostTagOnTemplate == null) {
hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
} else {
if (hasSvcOfferingTag) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
}
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy);
}
}
if (hasTemplateTag) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
}
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy);
}
}
}
}
if (!hostsCopy.isEmpty()) {
suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
}
return suitableHosts;
}
Aggregations