/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoadOnNode(java.lang.String) */ @Override public NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException, NotFoundException { Query query = null; EntityManager em = null; try { em = emf.createEntityManager(); query = em.createNamedQuery("HostRegistration.getMaxLoadByHostName"); query.setParameter("host", host); return new NodeLoad(host, ((Number) query.getSingleResult()).floatValue()); } catch (NoResultException e) { throw new NotFoundException(e); } catch (Exception e) { throw new ServiceRegistryException(e); } finally { if (em != null) em.close(); } }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoads() */ @Override public SystemLoad getMaxLoads() throws ServiceRegistryException { SystemLoad systemLoad = new SystemLoad(); systemLoad.addNodeLoad(new NodeLoad(LOCALHOST, Runtime.getRuntime().availableProcessors())); return systemLoad; }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoadOnNode(java.lang.String) */ @Override public NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException { if (hosts.containsKey(host)) { return new NodeLoad(host, hosts.get(host).getMaxLoad()); } throw new ServiceRegistryException("Unable to find host " + host + " in service registry"); }
@Override public SystemLoad getCurrentHostLoads() { SystemLoad systemLoad = new SystemLoad(); for (String host : hosts.keySet()) { NodeLoad node = new NodeLoad(); node.setHost(host); for (ServiceRegistration service : services.get(host)) { if (service.isInMaintenanceMode() || !service.isOnline()) { continue; } Set<Job> hostJobs = jobHosts.get(service); float loadSum = 0.0f; if (hostJobs != null) { for (Job job : hostJobs) { if (job.getStatus() != null && JOB_STATUSES_INFLUENCING_LOAD_BALANCING.contains(job.getStatus())) { loadSum += job.getJobLoad(); } } } node.setLoadFactor(node.getLoadFactor() + loadSum); } systemLoad.addNodeLoad(node); } return systemLoad; }
/** * {@inheritDoc} * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoads() */ @Override public SystemLoad getMaxLoads() throws ServiceRegistryException { final SystemLoad loads = new SystemLoad(); for (HostRegistration host : getHostRegistrations()) { NodeLoad load = new NodeLoad(host.getBaseUrl(), host.getMaxLoad()); loads.addNodeLoad(load); } return loads; }