use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class ApiResponseHelper method createAutoScaleVmProfileResponse.
@Override
public AutoScaleVmProfileResponse createAutoScaleVmProfileResponse(AutoScaleVmProfile profile) {
AutoScaleVmProfileResponse response = new AutoScaleVmProfileResponse();
response.setId(profile.getUuid());
if (profile.getZoneId() != null) {
DataCenter zone = ApiDBUtils.findZoneById(profile.getZoneId());
if (zone != null) {
response.setZoneId(zone.getUuid());
}
}
if (profile.getServiceOfferingId() != null) {
ServiceOffering so = ApiDBUtils.findServiceOfferingById(profile.getServiceOfferingId());
if (so != null) {
response.setServiceOfferingId(so.getUuid());
}
}
if (profile.getTemplateId() != null) {
VMTemplateVO template = ApiDBUtils.findTemplateById(profile.getTemplateId());
if (template != null) {
response.setTemplateId(template.getUuid());
}
}
response.setOtherDeployParams(profile.getOtherDeployParams());
response.setCounterParams(profile.getCounterParams());
response.setDestroyVmGraceperiod(profile.getDestroyVmGraceperiod());
User user = ApiDBUtils.findUserById(profile.getAutoScaleUserId());
if (user != null) {
response.setAutoscaleUserId(user.getUuid());
}
response.setObjectName("autoscalevmprofile");
// Populates the account information in the response
populateOwner(response, profile);
return response;
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class RecreateHostAllocator method allocateTo.
@Override
public List<Host> allocateTo(VirtualMachineProfile vm, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) {
List<Host> hosts = super.allocateTo(vm, plan, type, avoid, returnUpTo);
if (hosts != null && !hosts.isEmpty()) {
return hosts;
}
s_logger.debug("First fit was unable to find a host");
VirtualMachine.Type vmType = vm.getType();
if (vmType == VirtualMachine.Type.User) {
s_logger.debug("vm is not a system vm so let's just return empty list");
return new ArrayList<Host>();
}
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
List<PodCluster> pcs = _resourceMgr.listByDataCenter(dc.getId());
//basic network type for zone maps to direct untagged case
if (dc.getNetworkType().equals(NetworkType.Basic)) {
s_logger.debug("Direct Networking mode so we can only allow the host to be allocated in the same pod due to public ip address cannot change");
List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
VolumeVO vol = vols.get(0);
long podId = vol.getPodId();
s_logger.debug("Pod id determined from volume " + vol.getId() + " is " + podId);
Iterator<PodCluster> it = pcs.iterator();
while (it.hasNext()) {
PodCluster pc = it.next();
if (pc.getPod().getId() != podId) {
it.remove();
}
}
}
Set<Pair<Long, Long>> avoidPcs = new HashSet<Pair<Long, Long>>();
Set<Long> hostIdsToAvoid = avoid.getHostsToAvoid();
if (hostIdsToAvoid != null) {
for (Long hostId : hostIdsToAvoid) {
Host h = _hostDao.findById(hostId);
if (h != null) {
avoidPcs.add(new Pair<Long, Long>(h.getPodId(), h.getClusterId()));
}
}
}
for (Pair<Long, Long> pcId : avoidPcs) {
s_logger.debug("Removing " + pcId + " from the list of available pods");
pcs.remove(new PodCluster(new HostPodVO(pcId.first()), pcId.second() != null ? new ClusterVO(pcId.second()) : null));
}
for (PodCluster p : pcs) {
if (p.getPod().getAllocationState() != Grouping.AllocationState.Enabled) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Pod name: " + p.getPod().getName() + ", podId: " + p.getPod().getId() + " is in " + p.getPod().getAllocationState().name() + " state, skipping this and trying other pods");
}
continue;
}
Long clusterId = p.getCluster() == null ? null : p.getCluster().getId();
if (p.getCluster() != null && p.getCluster().getAllocationState() != Grouping.AllocationState.Enabled) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cluster name: " + p.getCluster().getName() + ", clusterId: " + clusterId + " is in " + p.getCluster().getAllocationState().name() + " state, skipping this and trying other pod-clusters");
}
continue;
}
DataCenterDeployment newPlan = new DataCenterDeployment(plan.getDataCenterId(), p.getPod().getId(), clusterId, null, null, null);
hosts = super.allocateTo(vm, newPlan, type, avoid, returnUpTo);
if (hosts != null && !hosts.isEmpty()) {
return hosts;
}
}
s_logger.debug("Unable to find any available pods at all!");
return new ArrayList<Host>();
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class BasicNetworkTopology method applyRules.
@Override
public boolean applyRules(final Network network, final VirtualRouter router, final String typeString, final boolean isPodLevelException, final Long podId, final boolean failWhenDisconnect, final RuleApplierWrapper<RuleApplier> ruleApplierWrapper) throws ResourceUnavailableException {
if (router == null) {
s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
}
final RuleApplier ruleApplier = ruleApplierWrapper.getRuleType();
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
// isPodLevelException and podId is only used for basic zone
assert !(!isZoneBasic && isPodLevelException || isZoneBasic && isPodLevelException && podId == null);
final List<VirtualRouter> connectedRouters = new ArrayList<VirtualRouter>();
final List<VirtualRouter> disconnectedRouters = new ArrayList<VirtualRouter>();
boolean result = true;
final String msg = "Unable to apply " + typeString + " on disconnected router ";
if (router.getState() == State.Running) {
s_logger.debug("Applying " + typeString + " in network " + network);
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getState() == Status.Up) {
throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
}
s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
return false;
}
try {
result = ruleApplier.accept(getVisitor(), router);
connectedRouters.add(router);
} catch (final AgentUnavailableException e) {
s_logger.warn(msg + router.getInstanceName(), e);
disconnectedRouters.add(router);
}
// disconnection, no need to proceed with the rest
if (!result) {
if (isZoneBasic && isPodLevelException) {
throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterId());
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend");
} else {
s_logger.warn("Unable to apply " + typeString + ", virtual router is not in the right state " + router.getState());
if (isZoneBasic && isPodLevelException) {
throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
}
throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
}
if (!connectedRouters.isEmpty()) {
// Shouldn't we include this check inside the method?
if (!isZoneBasic && !disconnectedRouters.isEmpty()) {
// now, stop them for synchronization
for (final VirtualRouter virtualRouter : disconnectedRouters) {
// If we have at least 1 disconnected redundant router, callhandleSingleWorkingRedundantRouter().
if (virtualRouter.getIsRedundantRouter()) {
_networkHelper.handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
break;
}
}
}
} else if (!disconnectedRouters.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
}
if (isZoneBasic && isPodLevelException) {
throw new ResourceUnavailableException(msg, Pod.class, podId);
}
throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
}
result = true;
if (failWhenDisconnect) {
result = !connectedRouters.isEmpty();
}
return result;
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class BaremetaNetworkGuru method reserve.
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientVirtualNetworkCapacityException {
if (dest.getHost().getHypervisorType() != HypervisorType.BareMetal) {
super.reserve(nic, network, vm, dest, context);
return;
}
HostVO host = _hostDao.findById(dest.getHost().getId());
_hostDao.loadDetails(host);
String intentIp = host.getDetail(ApiConstants.IP_ADDRESS);
if (intentIp == null) {
super.reserve(nic, network, vm, dest, context);
return;
}
String oldIp = nic.getIPv4Address();
boolean getNewIp = false;
if (oldIp == null) {
getNewIp = true;
} else {
// we need to get a new ip address if we try to deploy a vm in a
// different pod
final IPAddressVO ipVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), oldIp);
if (ipVO != null) {
PodVlanMapVO mapVO = _podVlanDao.listPodVlanMapsByVlan(ipVO.getVlanId());
if (mapVO.getPodId() != dest.getPod().getId()) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
// release the old ip here
_ipAddrMgr.markIpAsUnavailable(ipVO.getId());
_ipAddressDao.unassignIpAddress(ipVO.getId());
}
});
nic.setIPv4Address(null);
getNewIp = true;
}
}
}
if (getNewIp) {
// we don't set reservationStrategy to Create because we need this
// method to be called again for the case when vm fails to deploy in
// Pod1, and we try to redeploy it in Pod2
getBaremetalIp(nic, dest.getPod(), vm, network, intentIp);
}
DataCenter dc = _dcDao.findById(network.getDataCenterId());
nic.setIPv4Dns1(dc.getDns1());
nic.setIPv4Dns2(dc.getDns2());
/*
* Pod pod = dest.getPod(); Pair<String, Long> ip =
* _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(),
* dest.getPod().getId(), nic.getId(), context.getReservationId(),
* intentIp); if (ip == null) { throw new
* InsufficientAddressCapacityException
* ("Unable to get a management ip address", Pod.class, pod.getId()); }
*
* nic.setIp4Address(ip.first());
* nic.setMacAddress(NetUtils.long2Mac(NetUtils
* .createSequenceBasedMacAddress(ip.second())));
* nic.setGateway(pod.getGateway()); nic.setFormat(AddressFormat.Ip4);
* String netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
* nic.setNetmask(netmask);
* nic.setBroadcastType(BroadcastDomainType.Native);
* nic.setBroadcastUri(null); nic.setIsolationUri(null);
*/
s_logger.debug("Allocated a nic " + nic + " for " + vm);
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testImplementFail.
@Test
public void testImplementFail() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
when(physnet.getId()).thenReturn(NETWORK_ID);
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
mock(DeploymentPlan.class);
final NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
final DeployDestination dest = mock(DeployDestination.class);
final DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
final HostVO brocadeHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
when(brocadeHost.getId()).thenReturn(NETWORK_ID);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
final Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
when(guestGuru.implement(network, offering, dest, res)).thenReturn(network);
final CreateNetworkAnswer answer = mock(CreateNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
final Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork == null);
verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Aggregations