Search in sources :

Example 1 with HostRegistration

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);
}
Also used : JaxbHostRegistration(org.opencastproject.serviceregistry.api.JaxbHostRegistration) HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) JaxbHostRegistration(org.opencastproject.serviceregistry.api.JaxbHostRegistration) Before(org.junit.Before)

Example 2 with HostRegistration

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;
}
Also used : HttpStatus(org.apache.http.HttpStatus) Status(org.opencastproject.job.api.Job.Status) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) SystemLoad(org.opencastproject.serviceregistry.api.SystemLoad) LinkedList(java.util.LinkedList) NodeLoad(org.opencastproject.serviceregistry.api.SystemLoad.NodeLoad) HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration)

Example 3 with HostRegistration

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());
}
Also used : HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) SystemLoad(org.opencastproject.serviceregistry.api.SystemLoad) Job(org.opencastproject.job.api.Job) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Test(org.junit.Test)

Example 4 with HostRegistration

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());
}
Also used : HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) SystemLoad(org.opencastproject.serviceregistry.api.SystemLoad) Job(org.opencastproject.job.api.Job) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Test(org.junit.Test)

Example 5 with HostRegistration

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;
}
Also used : HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) SystemLoad(org.opencastproject.serviceregistry.api.SystemLoad) NodeLoad(org.opencastproject.serviceregistry.api.SystemLoad.NodeLoad)

Aggregations

HostRegistration (org.opencastproject.serviceregistry.api.HostRegistration)11 SystemLoad (org.opencastproject.serviceregistry.api.SystemLoad)5 ServiceRegistration (org.opencastproject.serviceregistry.api.ServiceRegistration)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ServersListQuery (org.opencastproject.index.service.resources.list.query.ServersListQuery)2 Job (org.opencastproject.job.api.Job)2 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)2 NodeLoad (org.opencastproject.serviceregistry.api.SystemLoad.NodeLoad)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1