use of org.opencastproject.serviceregistry.api.HostRegistration in project opencast by opencast.
the class ServersListProviderTest method setUp.
@Before
public void setUp() throws Exception {
this.serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
serverListProvider = new ServersListProvider();
List<HostRegistration> hosts = new ArrayList<HostRegistration>();
hosts.add(new JaxbHostRegistration(HOST1, "1.1.1.1", 400000, 8, 8, true, false));
hosts.add(new JaxbHostRegistration(HOST2, "1.1.1.2", 400000, 8, 8, true, true));
hosts.add(new JaxbHostRegistration(HOST3, "1.1.1.3", 500000, 2, 8, false, false));
hosts.add(new JaxbHostRegistration(HOST4, "1.1.1.4", 500000, 6, 8, true, true));
EasyMock.expect(serviceRegistry.getHostRegistrations()).andReturn(hosts).anyTimes();
serverListProvider.setServiceRegistry(serviceRegistry);
serverListProvider.activate(null);
EasyMock.replay(serviceRegistry);
}
use of org.opencastproject.serviceregistry.api.HostRegistration in project opencast by opencast.
the class ServiceRegistryJpaImpl method getHostLoads.
/**
* Gets a map of hosts to the number of jobs currently loading that host
*
* @param em
* the entity manager
*
* @return the map of hosts to job counts
*/
SystemLoad getHostLoads(EntityManager em) {
final SystemLoad systemLoad = new SystemLoad();
// Find all jobs that are currently running on any given host, or get all of them
Query q = em.createNamedQuery("ServiceRegistration.hostloads");
List<Integer> statuses = new LinkedList<Integer>();
for (Status status : JOB_STATUSES_INFLUENCING_LOAD_BALANCING) {
statuses.add(status.ordinal());
}
q.setParameter("statuses", statuses);
// Note: This is used in the query to filter out workflow jobs.
// These jobs are load balanced by the workflow service directly.
q.setParameter("workflow_type", TYPE_WORKFLOW);
// Accumulate the numbers for relevant job statuses per host
for (Object result : q.getResultList()) {
Object[] resultArray = (Object[]) result;
String host = String.valueOf(resultArray[0]);
Status status = Status.values()[(int) resultArray[1]];
float load = ((Number) resultArray[2]).floatValue();
// Only queued, and running jobs are adding to the load, so every other status is discarded
if (status == null || !JOB_STATUSES_INFLUENCING_LOAD_BALANCING.contains(status)) {
load = 0.0f;
}
// Add the service registration
NodeLoad serviceLoad;
if (systemLoad.containsHost(host)) {
serviceLoad = systemLoad.get(host);
serviceLoad.setLoadFactor(serviceLoad.getLoadFactor() + load);
} else {
serviceLoad = new NodeLoad(host, load);
}
systemLoad.addNodeLoad(serviceLoad);
}
// This is important, otherwise services which have no current load are not listed in the output!
for (HostRegistration h : getHostRegistrations(em)) {
if (!systemLoad.containsHost(h.getBaseUrl())) {
systemLoad.addNodeLoad(new NodeLoad(h.getBaseUrl(), 0.0f));
}
}
return systemLoad;
}
use of org.opencastproject.serviceregistry.api.HostRegistration in project opencast by opencast.
the class ServiceRegistrationTest method testServiceRegistrationsByLoad.
@Test
public void testServiceRegistrationsByLoad() throws Exception {
List<ServiceRegistration> services = serviceRegistry.getServiceRegistrations();
List<HostRegistration> hosts = serviceRegistry.getHostRegistrations();
SystemLoad hostLoads = serviceRegistry.getHostLoads(serviceRegistry.emf.createEntityManager());
List<ServiceRegistration> availableServices = serviceRegistry.getServiceRegistrationsByLoad(JOB_TYPE_1, services, hosts, hostLoads);
// Make sure all hosts are available for processing
Assert.assertEquals(3, availableServices.size());
// Create a job and mark it as running.
Job job = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, false, null);
job.setStatus(Job.Status.RUNNING);
job = serviceRegistry.updateJob(job);
// Recalculate the number of available services
hostLoads = serviceRegistry.getHostLoads(serviceRegistry.emf.createEntityManager());
availableServices = serviceRegistry.getServiceRegistrationsByLoad(JOB_TYPE_1, services, hosts, hostLoads);
// Since the host load is not taken into account, still all tree services should show up
Assert.assertEquals(3, availableServices.size());
// Recalculate the number of available services after ignoring a host
hosts.remove(regType1Remotehost1.getHostRegistration());
availableServices = serviceRegistry.getServiceRegistrationsByLoad(JOB_TYPE_1, services, hosts, hostLoads);
// Since host 1 is now ignored, only two more services should show up
Assert.assertEquals(2, availableServices.size());
}
use of org.opencastproject.serviceregistry.api.HostRegistration in project opencast by opencast.
the class ServiceRegistrationTest method testHostCapacity.
@Test
public void testHostCapacity() throws Exception {
List<ServiceRegistration> services = serviceRegistry.getServiceRegistrations();
List<HostRegistration> hosts = serviceRegistry.getHostRegistrations();
SystemLoad hostLoads = serviceRegistry.getHostLoads(serviceRegistry.emf.createEntityManager());
List<ServiceRegistration> availableServices = serviceRegistry.getServiceRegistrationsWithCapacity(JOB_TYPE_1, services, hosts, hostLoads);
// Make sure all hosts are available for processing
Assert.assertEquals(3, availableServices.size());
// Create a job and mark it as running.
Job job = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, false, null);
job.setStatus(Job.Status.RUNNING);
job = serviceRegistry.updateJob(job);
// Recalculate the number of available services
hostLoads = serviceRegistry.getHostLoads(serviceRegistry.emf.createEntityManager());
availableServices = serviceRegistry.getServiceRegistrationsWithCapacity(JOB_TYPE_1, services, hosts, hostLoads);
// Since host 1 is now maxed out, only two more services should show up
Assert.assertEquals(2, availableServices.size());
// Recalculate the number of available services after ignoring a host
hosts.remove(regType1Remotehost1.getHostRegistration());
availableServices = serviceRegistry.getServiceRegistrationsWithCapacity(JOB_TYPE_1, services, hosts, hostLoads);
// Since remote host 1 is now ignored, only one more service should show up
Assert.assertEquals(1, availableServices.size());
}
use of org.opencastproject.serviceregistry.api.HostRegistration in project opencast by opencast.
the class ServiceRegistryJpaImpl method getMaxLoads.
/**
* {@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;
}
Aggregations