use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ResourceCheckerTest method test_checkIfPodIsUsable_whenPodBelongsToDataCenter.
@Test
public void test_checkIfPodIsUsable_whenPodBelongsToDataCenter() throws Exception {
final DataCenterVO dataCenter = new DataCenterVO();
dataCenter.setId(1L);
dataCenter.setUuid("DataCenterUUID");
final HostPodVO hostPod = new HostPodVO();
hostPod.setDataCenterId(1L);
hostPod.setUuid("HostPodUUID");
final ResourceChecker resourceChecker = buildResourceChecker();
try {
resourceChecker.checkIfPodIsUsable(dataCenter, hostPod);
} catch (final InvalidParameterValueException e) {
fail("No InvalidParameterValueException should have been generated");
}
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ResourceCheckerTest method test_checkIfPodExists_whenPodDoesExist.
@Test
public void test_checkIfPodExists_whenPodDoesExist() throws Exception {
final HostPodVO hostPod = new HostPodVO();
when(hostPodDao.findById(1L)).thenReturn(hostPod);
final ResourceChecker resourceChecker = buildResourceChecker();
assertThat(resourceChecker.checkIfPodExists(1L), is(hostPod));
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createVlanIpRangeResponse.
@Override
public VlanIpRangeResponse createVlanIpRangeResponse(final Vlan vlan) {
final Long podId = ApiDBUtils.getPodIdForVlan(vlan.getId());
final VlanIpRangeResponse vlanResponse = new VlanIpRangeResponse();
vlanResponse.setId(vlan.getUuid());
if (vlan.getVlanType() != null) {
vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
}
vlanResponse.setVlan(vlan.getVlanTag());
final DataCenter zone = ApiDBUtils.findZoneById(vlan.getDataCenterId());
if (zone != null) {
vlanResponse.setZoneId(zone.getUuid());
}
if (podId != null) {
final HostPodVO pod = ApiDBUtils.findPodById(podId);
if (pod != null) {
vlanResponse.setPodId(pod.getUuid());
vlanResponse.setPodName(pod.getName());
}
}
vlanResponse.setGateway(vlan.getVlanGateway());
vlanResponse.setNetmask(vlan.getVlanNetmask());
// get start ip and end ip of corresponding vlan
final String ipRange = vlan.getIpRange();
if (ipRange != null) {
final String[] range = ipRange.split("-");
vlanResponse.setStartIp(range[0]);
vlanResponse.setEndIp(range[1]);
}
vlanResponse.setIp6Gateway(vlan.getIp6Gateway());
vlanResponse.setIp6Cidr(vlan.getIp6Cidr());
final String ip6Range = vlan.getIp6Range();
if (ip6Range != null) {
final String[] range = ip6Range.split("-");
vlanResponse.setStartIpv6(range[0]);
vlanResponse.setEndIpv6(range[1]);
}
if (vlan.getNetworkId() != null) {
final Network nw = ApiDBUtils.findNetworkById(vlan.getNetworkId());
if (nw != null) {
vlanResponse.setNetworkId(nw.getUuid());
}
}
final Account owner = ApiDBUtils.getVlanAccount(vlan.getId());
if (owner != null) {
populateAccount(vlanResponse, owner.getId());
populateDomain(vlanResponse, owner.getDomainId());
} else {
final Domain domain = ApiDBUtils.getVlanDomain(vlan.getId());
if (domain != null) {
populateDomain(vlanResponse, domain.getId());
} else {
final Long networkId = vlan.getNetworkId();
if (networkId != null) {
final Network network = _ntwkModel.getNetwork(networkId);
if (network != null) {
final Long accountId = network.getAccountId();
populateAccount(vlanResponse, accountId);
populateDomain(vlanResponse, ApiDBUtils.findAccountById(accountId).getDomainId());
}
}
}
}
if (vlan.getPhysicalNetworkId() != null) {
final PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
if (pnw != null) {
vlanResponse.setPhysicalNetworkId(pnw.getUuid());
}
}
vlanResponse.setObjectName("vlan");
return vlanResponse;
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ExplicitDedicationProcessor method updateAvoidList.
private ExcludeList updateAvoidList(final List<DedicatedResourceVO> dedicatedResources, final ExcludeList avoidList, final Zone zone) {
final ExcludeList includeList = new ExcludeList();
for (final DedicatedResourceVO dr : dedicatedResources) {
if (dr.getHostId() != null) {
includeList.addHost(dr.getHostId());
final HostVO dedicatedHost = _hostDao.findById(dr.getHostId());
includeList.addCluster(dedicatedHost.getClusterId());
includeList.addPod(dedicatedHost.getPodId());
}
if (dr.getClusterId() != null) {
includeList.addCluster(dr.getClusterId());
// add all hosts inside this in includeList
final List<HostVO> hostList = _hostDao.findByClusterId(dr.getClusterId());
for (final HostVO host : hostList) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
final ClusterVO dedicatedCluster = _clusterDao.findById(dr.getClusterId());
includeList.addPod(dedicatedCluster.getPodId());
}
if (dr.getPodId() != null) {
includeList.addPod(dr.getPodId());
// add all cluster under this pod in includeList
final List<ClusterVO> clusterList = _clusterDao.listByPodId(dr.getPodId());
for (final ClusterVO cluster : clusterList) {
final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null && !dedicatedResources.contains(dCluster)) {
avoidList.addCluster(cluster.getId());
} else {
includeList.addCluster(cluster.getId());
}
}
// add all hosts inside this pod in includeList
final List<HostVO> hostList = _hostDao.findByPodId(dr.getPodId());
for (final HostVO host : hostList) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
}
if (dr.getDataCenterId() != null) {
includeList.addZone(dr.getDataCenterId());
// add all Pod under this data center in includeList
final List<HostPodVO> podList = _podDao.listByDataCenterId(dr.getDataCenterId());
for (final HostPodVO pod : podList) {
final DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId());
if (dPod != null && !dedicatedResources.contains(dPod)) {
avoidList.addPod(pod.getId());
} else {
includeList.addPod(pod.getId());
}
}
final List<ClusterVO> clusterList = _clusterDao.listClustersByDcId(dr.getDataCenterId());
for (final ClusterVO cluster : clusterList) {
final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null && !dedicatedResources.contains(dCluster)) {
avoidList.addCluster(cluster.getId());
} else {
includeList.addCluster(cluster.getId());
}
}
// add all hosts inside this in includeList
final List<HostVO> hostList = _hostDao.listByDataCenterId(dr.getDataCenterId());
for (final HostVO host : hostList) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
}
}
// Update avoid list using includeList.
// add resources in avoid list which are not in include list.
final List<HostPodVO> pods = _podDao.listByDataCenterId(zone.getId());
final List<ClusterVO> clusters = _clusterDao.listClustersByDcId(zone.getId());
final List<HostVO> hosts = _hostDao.listByDataCenterId(zone.getId());
final Set<Long> podsInIncludeList = includeList.getPodsToAvoid();
final Set<Long> clustersInIncludeList = includeList.getClustersToAvoid();
final Set<Long> hostsInIncludeList = includeList.getHostsToAvoid();
for (final HostPodVO pod : pods) {
if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) {
avoidList.addPod(pod.getId());
}
}
for (final ClusterVO cluster : clusters) {
if (clustersInIncludeList != null && !clustersInIncludeList.contains(cluster.getId())) {
avoidList.addCluster(cluster.getId());
}
}
for (final HostVO host : hosts) {
if (hostsInIncludeList != null && !hostsInIncludeList.contains(host.getId())) {
avoidList.addHost(host.getId());
}
}
return avoidList;
}
use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class AgentManagerImpl method handleDisconnectWithInvestigation.
protected boolean handleDisconnectWithInvestigation(final AgentAttache attache, Status.Event event) {
final long hostId = attache.getId();
HostVO host = _hostDao.findById(hostId);
if (host != null) {
Status nextStatus = null;
try {
nextStatus = host.getStatus().getNextStatus(event);
} catch (final NoTransitionException ne) {
/*
* Agent may be currently in status of Down, Alert, Removed, namely there is no next status for some events. Why this can happen? Ask God not me. I hate there was
* no piece of comment for code handling race condition. God knew what race condition the code dealt with!
*/
s_logger.debug("Caught exception while getting agent's next status", ne);
}
if (nextStatus == Status.Alert) {
/* OK, we are going to the bad status, let's see what happened */
s_logger.info("Investigating why host " + hostId + " has disconnected with event " + event);
Status determinedState = investigate(attache);
// if state cannot be determined do nothing and bail out
if (determinedState == null) {
if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) {
s_logger.warn("Agent " + hostId + " state cannot be determined for more than " + AlertWait + "(" + AlertWait.value() + ") seconds, will go to Alert state");
determinedState = Status.Alert;
} else {
s_logger.warn("Agent " + hostId + " state cannot be determined, do nothing");
return false;
}
}
final Status currentStatus = host.getStatus();
s_logger.info("The agent from host " + hostId + " state determined is " + determinedState);
if (determinedState == Status.Down) {
final String message = "Host is down: " + host.getId() + "-" + host.getName() + ". Starting HA on the VMs";
s_logger.error(message);
if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host down, " + host.getId(), message);
}
event = Status.Event.HostDown;
} else if (determinedState == Status.Up) {
/* Got ping response from host, bring it back */
s_logger.info("Agent is determined to be up and running");
agentStatusTransitTo(host, Status.Event.Ping, _nodeId);
return false;
} else if (determinedState == Status.Disconnected) {
s_logger.warn("Agent is disconnected but the host is still up: " + host.getId() + "-" + host.getName());
if (currentStatus == Status.Disconnected) {
if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) {
s_logger.warn("Host " + host.getId() + " has been disconnected past the wait time it should be disconnected.");
event = Status.Event.WaitedTooLong;
} else {
s_logger.debug("Host " + host.getId() + " has been determined to be disconnected but it hasn't passed the wait time yet.");
return false;
}
} else if (currentStatus == Status.Up) {
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
final HostPodVO podVO = _podDao.findById(host.getPodId());
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host disconnected, " + hostDesc, "If the agent for host [" + hostDesc + "] is not restarted within " + AlertWait + " seconds, host will go to Alert state");
}
event = Status.Event.AgentDisconnected;
}
} else {
// if we end up here we are in alert state, send an alert
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
final HostPodVO podVO = _podDao.findById(host.getPodId());
final String podName = podVO != null ? podVO.getName() : "NO POD";
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podName;
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host in ALERT state, " + hostDesc, "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName());
}
} else {
s_logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened");
}
}
handleDisconnectWithoutInvestigation(attache, event, true, true);
// Maybe the host magically reappeared?
host = _hostDao.findById(hostId);
if (host != null && host.getStatus() == Status.Down) {
_haMgr.scheduleRestartForVmsOnHost(host, true);
}
return true;
}
Aggregations