/** * Get running host IDs within the same hypervisor, cluster and datacenter than hostId. ID hostId is not included on the returned list */ protected List<Long> getRunningHostIdsInTheSameCluster(Long clusterId, long dataCenterId, HypervisorType hypervisorType, long hostId) { List<Long> list = hostDao.listByDataCenterIdAndHypervisorType(dataCenterId, hypervisorType) .stream() .filter(x -> x.getHypervisorType().equals(hypervisorType) && x.getStatus().equals(Status.Up) && x.getType().equals(Host.Type.Routing) && x.getClusterId().equals(clusterId) && x.getId() != hostId) .map(x -> x.getId()) .collect(Collectors.toList()); Collections.shuffle(list); return list; }
private void updateNetworkLabels(HostVO host) { //check if networkLabels need to be updated in details //we send only private and storage network label to the resource. String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(host.getDataCenterId(), host.getHypervisorType()); String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(host.getDataCenterId(), host.getHypervisorType()); String privateDevice = host.getDetail("private.network.device"); String storageDevice = host.getDetail("storage.network.device1"); boolean update = false; if (privateNetworkLabel != null && !privateNetworkLabel.equalsIgnoreCase(privateDevice)) { host.setDetail("private.network.device", privateNetworkLabel); update = true; } if (storageNetworkLabel != null && !storageNetworkLabel.equalsIgnoreCase(storageDevice)) { host.setDetail("storage.network.device1", storageNetworkLabel); update = true; } if (update) { _hostDao.saveDetails(host); } }
/** * Set retries for transiting the host into Maintenance */ protected void setHostMaintenanceRetries(HostVO host) { Integer retries = HostMaintenanceRetries.valueIn(host.getClusterId()); retryHostMaintenance.put(host.getId(), retries); s_logger.debug(String.format("Setting the host %s (%s) retries for Maintenance mode: %s", host.getId(), host.getName(), retries)); }
@Override public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) { if (!(startup[0] instanceof StartupExternalLoadBalancerCommand)) { return null; } if(host.getName().equalsIgnoreCase("NetScalerControlCenter")) { host.setType(Host.Type.NetScalerControlCenter); } else { host.setType(Host.Type.ExternalLoadBalancer); } return host; }
@Override public List<HostVO> listAllUpHosts(Type type, Long clusterId, Long podId, long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); if (type != null) { sc.and(sc.entity().getType(), Op.EQ, type); } if (clusterId != null) { sc.and(sc.entity().getClusterId(), Op.EQ, clusterId); } if (podId != null) { sc.and(sc.entity().getPodId(), Op.EQ, podId); } sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); return sc.list(); }
private boolean checkIfHostIsDedicated(HostVO host) { long hostId = host.getId(); DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); if (dedicatedHost != null || dedicatedClusterOfHost != null || dedicatedPodOfHost != null) { return true; } else { return false; } }
protected List<Long> findHostByPod(long podId, Long excludeHostId) { QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getType(), Op.EQ, Type.Routing); sc.and(sc.entity().getPodId(), Op.EQ, podId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); List<HostVO> hosts = sc.list(); List<Long> hostIds = new ArrayList<Long>(hosts.size()); for (HostVO h : hosts) { hostIds.add(h.getId()); } if (excludeHostId != null) { hostIds.remove(excludeHostId); } return hostIds; }
protected HashMap<String, Object> buildConfigParams(HostVO host) { HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5); params.putAll(host.getDetails()); params.put("guid", host.getGuid()); params.put("zone", Long.toString(host.getDataCenterId())); if (host.getPodId() != null) { params.put("pod", Long.toString(host.getPodId())); if (host.getClusterId() != null) { params.put("cluster", Long.toString(host.getClusterId())); String guid = null; ClusterVO cluster = _clusterDao.findById(host.getClusterId()); if (cluster.getGuid() == null) { guid = host.getDetail("pool"); } else { guid = cluster.getGuid(); params.put("ipaddress", host.getPrivateIpAddress()); params.put("secondary.storage.vm", "false"); params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString()));
@Override public boolean hostConnect(long hostId, long storagePoolId) { HostVO host = hostDao.findById(hostId); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); if (storagePoolHost == null) { storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, ""); storagePoolHostDao.persist(storagePoolHost); } if (host.getHypervisorType().equals(HypervisorType.XenServer)) { handleXenServer(host.getClusterId(), host.getId(), storagePoolId); } else if (host.getHypervisorType().equals(HypervisorType.KVM)) { handleKVM(hostId, storagePoolId); } return true; }
@Override public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { if (host.getType() != com.cloud.host.Host.Type.Routing || host.getHypervisorType() != HypervisorType.Ovm) { return null; } _resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage); return new DeleteHostAnswer(true); }
private <R extends InternalIdentity> void send(Command cmd, long physicalNetworkId, Class<R> resourceClass, R resource) throws ResourceUnavailableException { HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(physicalNetworkId); Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (isFailure(answer)) { s_logger.error(cmd.getClass().getName() + " for " + resourceClass.getName() + " " + resource.getId() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if (hasFailureDetails(answer)) { throw new ResourceUnavailableException(answer.getDetails(), resourceClass, resource.getId()); } } }
public long[] getNeighbors(Host agent) { List<Long> neighbors = new ArrayList<Long>(); List<HostVO> cluster_hosts = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); for (HostVO host : cluster_hosts) { if (host.getId() == agent.getId() || (host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC)) { continue; } neighbors.add(host.getId()); } return ArrayUtils.toPrimitive(neighbors.toArray(new Long[neighbors.size()])); }
protected AgentAttache createAttacheForConnect(final HostVO host, final Link link) throws ConnectionException { s_logger.debug("create ConnectedAgentAttache for " + host.getId()); final AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates()); link.attach(attache); AgentAttache old = null; synchronized (_agents) { old = _agents.put(host.getId(), attache); } if (old != null) { old.disconnect(Status.Removed); } return attache; }
@Override public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) { State newState = transition.getToState(); State oldState = transition.getCurrentState(); if (newState != State.Starting && newState != State.Error && newState != State.Expunging) { return true; } if (vo.getHypervisorType() != HypervisorType.BareMetal) { return true; } HostVO host = _hostDao.findById(vo.getHostId()); if (host == null) { s_logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion"); return true; } _hostDao.loadDetails(host); if (newState == State.Starting) { host.setDetail("vmName", vo.getInstanceName()); s_logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details"); } else { if (host.getDetail("vmName") != null && host.getDetail("vmName").equalsIgnoreCase(vo.getInstanceName())) { s_logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details"); host.getDetails().remove("vmName"); } } _hostDao.saveDetails(host); return true; }
private boolean sharedNetworkSupportNumericalVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) { List<VlanVO> networkVlans = vlanDao.listVlansByNetworkId(network.getId()); if (networkVlans.size() == 1){ for (VlanVO vlanVO : networkVlans) { long vlanId = Long.parseLong(vlanVO.getVlanTag()); String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid"); if (l2GatewayServiceUuid == null){ throw new CloudRuntimeException("No L2 Gateway Service Uuid found on " + niciraNvpHost.getName()); } ConfigureSharedNetworkVlanIdCommand cmd = new ConfigureSharedNetworkVlanIdCommand(lSwitchUuid, l2GatewayServiceUuid , vlanId, ownerName, network.getId()); ConfigureSharedNetworkVlanIdAnswer answer = (ConfigureSharedNetworkVlanIdAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to configure Shared network " + network.getDisplayText()); return false; } } } return true; }
@Override public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUStatistics(final HostVO host) { final Answer answer = _agentMgr.easySend(host.getId(), new GetGPUStatsCommand(host.getGuid(), host.getName())); if (answer != null && answer instanceof UnsupportedAnswer) { return null; } if (answer == null || !answer.getResult()) { final String msg = "Unable to obtain GPU stats for host " + host.getName(); s_logger.warn(msg); return null; } else { // now construct the result object if (answer instanceof GetGPUStatsAnswer) { return ((GetGPUStatsAnswer)answer).getGroupDetails(); } } return null; }
@Override public void postDiscovery(List<HostVO> hosts, long msId) { if (_useServiceVM) { for (HostVO h : hosts) { _agentMgr.agentStatusTransitTo(h, Event.AgentDisconnected, msId); } } for (HostVO h : hosts) { associateTemplatesToZone(h.getId(), h.getDataCenterId()); } }
/** * Sends VMs metrics to the configured graphite host. */ protected void sendVmMetricsToGraphiteHost(Map<Object, Object> metrics, HostVO host) { s_logger.debug(String.format("Sending VmStats of host %s to %s host %s:%s", host.getId(), externalStatsType, externalStatsHost, externalStatsPort)); try { GraphiteClient g = new GraphiteClient(externalStatsHost, externalStatsPort); g.sendMetrics(metrics); } catch (GraphiteException e) { s_logger.debug("Failed sending VmStats to Graphite host " + externalStatsHost + ":" + externalStatsPort + ": " + e.getMessage()); } }
@Override public List<HostVO> listAllUpAndEnabledHostsInOneZoneByType(final Type type, final long dcId) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getType(), Op.EQ, type); sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); sc.and(sc.entity().getResourceState(), Op.EQ, ResourceState.Enabled); return sc.list(); }