@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; }
protected AgentAttache createAttache(final long id) { s_logger.debug("create forwarding ClusteredAgentAttache for " + id); final HostVO host = _hostDao.findById(id); final AgentAttache attache = new ClusteredAgentAttache(this, id, host.getName()); AgentAttache old = null; synchronized (_agents) { old = _agents.get(id); _agents.put(id, attache); } if (old != null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Remove stale agent attache from current management server"); } removeAgent(old, Status.Removed); } return attache; }
/** * 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 boolean agentStatusTransitTo(final HostVO host, final Status.Event e, final long msId) { try { _agentStatusLock.lock(); if (s_logger.isDebugEnabled()) { final ResourceState state = host.getResourceState(); final StringBuilder msg = new StringBuilder("Transition:"); msg.append("[Resource state = ").append(state); msg.append(", Agent event = ").append(e.toString()); msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]"); s_logger.debug(msg); } host.setManagementServerId(msId); try { return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao); } catch (final NoTransitionException e1) { s_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", mangement server id is " + msId); throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," + e1.getMessage()); } } finally { _agentStatusLock.unlock(); } }
/** * Return true if host goes into Maintenance mode, only when: * - No Running, Migrating or Failed migrations (host_id = last_host_id) for the host */ protected boolean isHostInMaintenance(HostVO host, List<VMInstanceVO> runningVms, List<VMInstanceVO> migratingVms, List<VMInstanceVO> failedMigrations) throws NoTransitionException { if (CollectionUtils.isEmpty(runningVms) && CollectionUtils.isEmpty(migratingVms)) { return CollectionUtils.isEmpty(failedMigrations) ? setHostIntoMaintenance(host) : setHostIntoErrorInMaintenance(host, failedMigrations); } else if (retryHostMaintenance.containsKey(host.getId())) { Integer retriesLeft = retryHostMaintenance.get(host.getId()); if (retriesLeft != null) { if (retriesLeft <= 0) { retryHostMaintenance.remove(host.getId()); s_logger.debug(String.format("No retries left while preparing KVM host %s (%s) for Maintenance, " + "please investigate this connection.", host.getId(), host.getName())); return setHostIntoErrorInMaintenance(host, failedMigrations); } retriesLeft--; retryHostMaintenance.put(host.getId(), retriesLeft); s_logger.debug(String.format("Retries left preparing KVM host %s (%s) for Maintenance: %s", host.getId(), host.getName(), retriesLeft)); } } return false; }
@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; }
if (host != null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Assign embedded console proxy running at " + host.getName() + " to user vm " + userVmId + " with public IP " + host.getPublicIpAddress()); if (publicIp == null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Host " + host.getName() + "/" + host.getPrivateIpAddress() + " does not have public interface, we will return its private IP for cosole proxy.");
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 HostVO findHostByName(final String name) { final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getName(), Op.EQ, name); return sc.find(); }
@Override protected AgentAttache createAttacheForConnect(final HostVO host, final Link link) { s_logger.debug("create ClusteredAgentAttache for " + host.getId()); final AgentAttache attache = new ClusteredAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates()); link.attach(attache); AgentAttache old = null; synchronized (_agents) { old = _agents.get(host.getId()); _agents.put(host.getId(), attache); } if (old != null) { old.disconnect(Status.Removed); } return attache; }
@Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); s_logger.debug("In createPool. Attaching the pool to each of the hosts."); List<HostVO> poolHosts = new ArrayList<HostVO>(); for (HostVO host : hosts) { try { storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); poolHosts.add(host); } catch (StorageConflictException se) { primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Storage has already been added as local storage to host: " + host.getName()); } catch (Exception e) { s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } if (poolHosts.isEmpty()) { s_logger.warn("No host can access storage pool " + dataStore + " in this zone."); primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts."); } dataStoreHelper.attachZone(dataStore, hypervisorType); return true; }
@Override public HostStats getHostStatistics(final long hostId) { final Answer answer = _agentMgr.easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(), hostId)); if (answer != null && answer instanceof UnsupportedAnswer) { return null; } if (answer == null || !answer.getResult()) { final String msg = "Unable to obtain host " + hostId + " statistics. "; s_logger.warn(msg); return null; } else { // now construct the result object if (answer instanceof GetHostStatsAnswer) { return ((GetHostStatsAnswer)answer).getHostStats(); } } return null; }
@Override public ServerResource reloadResource(HostVO host) { String resourceName = host.getResource(); ServerResource resource = getResource(resourceName); if (resource != null) { _hostDao.loadDetails(host); updateNetworkLabels(host); HashMap<String, Object> params = buildConfigParams(host); try { resource.configure(host.getName(), params); } catch (ConfigurationException e) { s_logger.warn("Unable to configure resource due to " + e.getMessage()); return null; } if (!resource.start()) { s_logger.warn("Unable to start the resource"); return null; } } return resource; }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { if (s_logger.isDebugEnabled()) { s_logger.debug("Changing password for host name = " + host.getName()); } // update password for this host final DetailVO nv = _detailsDao.findDetail(host.getId(), ApiConstants.USERNAME); if (nv.getValue().equals(cmd.getUsername())) { final DetailVO nvp = _detailsDao.findDetail(host.getId(), ApiConstants.PASSWORD); nvp.setValue(DBEncryptionUtil.encrypt(cmd.getPassword())); _detailsDao.persist(nvp); } else { // if one host in the cluster has diff username then // rollback to maintain consistency throw new InvalidParameterValueException("The username is not same for the hosts.."); } } });
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { for (final HostVO h : hosts) { if (s_logger.isDebugEnabled()) { s_logger.debug("Changing password for host name = " + h.getName()); } // update password for this host final DetailVO nv = _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME); if (nv.getValue().equals(command.getUsername())) { final DetailVO nvp = _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD); nvp.setValue(DBEncryptionUtil.encrypt(command.getPassword())); _detailsDao.persist(nvp); } else { // if one host in the cluster has diff username then // rollback to maintain consistency throw new InvalidParameterValueException("The username is not same for all hosts, please modify passwords for individual hosts."); } } } });
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; }
protected HostVO findConsoleProxyHostByName(String name) { QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getType(), Op.EQ, Host.Type.ConsoleProxy); sc.and(sc.entity().getName(), Op.EQ, name); return sc.find(); }
@Override public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) { StartupCommand firstCmd = startup[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand)firstCmd); if (ssCmd.getHypervisorType() != HypervisorType.XenServer) { return null; } HostPodVO pod = _podDao.findById(host.getPodId()); DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); s_logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.XenServer + ". Checking CIDR..."); _resourceMgr.checkCIDR(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPrivateNetmask()); return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.XenServer, details, hostTags); }
@Override public final HostVO createHostVOForDirectConnectAgent(final HostVO host, final StartupCommand[] startup, final ServerResource resource, final Map<String, String> details, final List<String> hostTags) { StartupCommand firstCmd = startup[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand)firstCmd); if (ssCmd.getHypervisorType() != HypervisorType.Hyperv) { return null; } s_logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.Hyperv + ". Checking CIDR..."); HostPodVO pod = _podDao.findById(host.getPodId()); DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); _resourceMgr.checkCIDR(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPrivateNetmask()); return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Hyperv, details, hostTags); }
@Override public DedicateHostResponse createDedicateHostResponse(DedicatedResources resource) { DedicateHostResponse dedicateHostResponse = new DedicateHostResponse(); HostVO host = _hostDao.findById(resource.getHostId()); DomainVO domain = _domainDao.findById(resource.getDomainId()); AccountVO account = _accountDao.findById(resource.getAccountId()); AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId()); dedicateHostResponse.setId(resource.getUuid()); dedicateHostResponse.setHostId(host.getUuid()); dedicateHostResponse.setHostName(host.getName()); dedicateHostResponse.setDomainId(domain.getUuid()); dedicateHostResponse.setAffinityGroupId(group.getUuid()); if (account != null) { dedicateHostResponse.setAccountId(account.getUuid()); } dedicateHostResponse.setObjectName("dedicatedhost"); return dedicateHostResponse; }