Search in sources :

Example 11 with ServiceRegistration

use of org.opencastproject.serviceregistry.api.ServiceRegistration in project opencast by opencast.

the class CleanupWorkflowOperationHandlerTest method createWfrServiceRegistration.

private ServiceRegistration createWfrServiceRegistration(String hostname, String path) {
    ServiceRegistration wfrServiceReg = EasyMock.createNiceMock(ServiceRegistration.class);
    EasyMock.expect(wfrServiceReg.getHost()).andReturn(hostname).anyTimes();
    EasyMock.expect(wfrServiceReg.getPath()).andReturn(path).anyTimes();
    EasyMock.replay(wfrServiceReg);
    return wfrServiceReg;
}
Also used : ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration)

Example 12 with ServiceRegistration

use of org.opencastproject.serviceregistry.api.ServiceRegistration in project opencast by opencast.

the class CleanupWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    cleanupWOH = new CleanupWorkflowOperationHandler();
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getBaseUri()).andReturn(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX)).anyTimes();
    EasyMock.replay(workspace);
    cleanupWOH.setWorkspace(workspace);
    List<ServiceRegistration> wfrServiceRegistrations = new ArrayList<ServiceRegistration>();
    wfrServiceRegistrations.add(createWfrServiceRegistration(HOSTNAME_NODE1, WFR_URL_PREFIX));
    wfrServiceRegistrations.add(createWfrServiceRegistration(HOSTNAME_NODE2, WFR_URL_PREFIX));
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getServiceRegistrationsByType(EasyMock.eq(WorkingFileRepository.SERVICE_TYPE))).andReturn(wfrServiceRegistrations).anyTimes();
    Job currentJob = EasyMock.createNiceMock(Job.class);
    currentJob.setArguments((List<String>) EasyMock.anyObject());
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(currentJob).anyTimes();
    EasyMock.expect(serviceRegistry.updateJob((Job) EasyMock.anyObject())).andReturn(currentJob).anyTimes();
    EasyMock.expect(serviceRegistry.getChildJobs(EasyMock.anyLong())).andReturn(new ArrayList<Job>()).anyTimes();
    EasyMock.replay(serviceRegistry, currentJob);
    cleanupWOH.setServiceRegistry(serviceRegistry);
    TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpResponse httpResponse = EasyMock.createNiceMock(HttpResponse.class);
    StatusLine responseStatusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(responseStatusLine.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
    EasyMock.expect(httpResponse.getStatusLine()).andReturn(responseStatusLine).anyTimes();
    EasyMock.expect(httpClient.execute(StoreUrisArgumentMatcher.createMatcher(deletedFilesURIs, UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX)))).andReturn(httpResponse).anyTimes();
    EasyMock.replay(httpClient, httpResponse, responseStatusLine);
    cleanupWOH.setTrustedHttpClient(httpClient);
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) StatusLine(org.apache.http.StatusLine) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Before(org.junit.Before)

Example 13 with ServiceRegistration

use of org.opencastproject.serviceregistry.api.ServiceRegistration in project opencast by opencast.

the class ServicesListProviderTest method setUp.

@Before
public void setUp() throws Exception {
    serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    ServiceRegistration sr1 = new ServiceRegistrationInMemoryImpl(SERVICE_TYPE_1, "host1", "service-path-1", true);
    ServiceRegistration sr2 = new ServiceRegistrationInMemoryImpl(SERVICE_TYPE_2, "host1", "service-path-2", false);
    ServiceRegistration sr3 = new ServiceRegistrationInMemoryImpl(SERVICE_TYPE_3, "host1", "service-path-3", true);
    EasyMock.expect(serviceRegistry.getServiceRegistrations()).andReturn(Arrays.asList(sr1, sr2, sr3)).anyTimes();
    servicesListProvider = new ServicesListProvider();
    servicesListProvider.setServiceRegistry(serviceRegistry);
    servicesListProvider.activate(null);
    servicesQuery = new ServicesListQuery();
    EasyMock.replay(serviceRegistry);
}
Also used : ServiceRegistrationInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistrationInMemoryImpl) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) ServicesListQuery(org.opencastproject.index.service.resources.list.query.ServicesListQuery) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Before(org.junit.Before)

Example 14 with ServiceRegistration

use of org.opencastproject.serviceregistry.api.ServiceRegistration in project opencast by opencast.

the class JobTest method testHandlerRegistration.

@Test
public void testHandlerRegistration() throws Exception {
    String url = "http://type1handler:8080";
    serviceRegistry.registerHost(url, "127.0.0.1", 1024, 1, 1);
    String jobType = "type1";
    // we should start with no handlers
    List<ServiceRegistration> hosts = serviceRegistry.getServiceRegistrationsByLoad(jobType);
    assertEquals(0, hosts.size());
    // register a handler
    serviceRegistry.registerService(jobType, url, PATH);
    hosts = serviceRegistry.getServiceRegistrationsByLoad(jobType);
    assertEquals(1, hosts.size());
    assertEquals(url, hosts.get(0).getHost());
    // set the handler to be in maintenance mode
    serviceRegistry.setMaintenanceStatus(url, true);
    hosts = serviceRegistry.getServiceRegistrationsByLoad(jobType);
    assertEquals(0, hosts.size());
    // set it back to normal mode
    serviceRegistry.setMaintenanceStatus(url, false);
    hosts = serviceRegistry.getServiceRegistrationsByLoad(jobType);
    assertEquals(1, hosts.size());
    // unregister
    serviceRegistry.unRegisterService(jobType, url);
    hosts = serviceRegistry.getServiceRegistrationsByLoad(jobType);
    assertEquals(0, hosts.size());
}
Also used : Arrays.mkString(org.opencastproject.util.data.Arrays.mkString) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Test(org.junit.Test)

Example 15 with ServiceRegistration

use of org.opencastproject.serviceregistry.api.ServiceRegistration in project opencast by opencast.

the class ServiceRegistryEndpoint method getHealthStatus.

@GET
@Path("health.xml")
@Produces(MediaType.APPLICATION_XML)
@RestQuery(name = "health", description = "Checks the status of the registered services", returnDescription = "Returns NO_CONTENT if services are in a proper state", restParameters = { @RestParameter(name = "serviceType", isRequired = false, type = Type.STRING, description = "The service type identifier"), @RestParameter(name = "host", isRequired = false, type = Type.STRING, description = "The host, including the http(s) protocol") }, reponses = { @RestResponse(responseCode = SC_OK, description = "Service states returned"), @RestResponse(responseCode = SC_NOT_FOUND, description = "No service of that type on that host is registered."), @RestResponse(responseCode = SC_SERVICE_UNAVAILABLE, description = "An error has occurred during stats processing") })
public Response getHealthStatus(@QueryParam("serviceType") String serviceType, @QueryParam("host") String host) throws NotFoundException {
    try {
        List<ServiceRegistration> services = null;
        if (isNotBlank(serviceType) && isNotBlank(host)) {
            // This is a request for one specific service. Return it, or SC_NOT_FOUND if not found
            ServiceRegistration reg = serviceRegistry.getServiceRegistration(serviceType, host);
            if (reg == null)
                throw new NotFoundException();
            services = new LinkedList<ServiceRegistration>();
            services.add(reg);
        } else if (isBlank(serviceType) && isBlank(host)) {
            // This is a request for all service registrations
            services = serviceRegistry.getServiceRegistrations();
        } else if (isNotBlank(serviceType)) {
            // This is a request for all service registrations of a particular type
            services = serviceRegistry.getServiceRegistrationsByType(serviceType);
        } else if (isNotBlank(host)) {
            // This is a request for all service registrations of a particular host
            services = serviceRegistry.getServiceRegistrationsByHost(host);
        }
        int healthy = 0;
        int warning = 0;
        int error = 0;
        for (ServiceRegistration reg : services) {
            if (ServiceState.NORMAL == reg.getServiceState()) {
                healthy++;
            } else if (ServiceState.WARNING == reg.getServiceState()) {
                warning++;
            } else if (ServiceState.ERROR == reg.getServiceState()) {
                error++;
            } else {
                error++;
            }
        }
        JaxbServiceHealth stats = new JaxbServiceHealth(healthy, warning, error);
        return Response.ok(stats).build();
    } catch (ServiceRegistryException e) {
        throw new WebApplicationException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) JaxbServiceHealth(org.opencastproject.serviceregistry.api.JaxbServiceHealth) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) JaxbServiceRegistration(org.opencastproject.serviceregistry.api.JaxbServiceRegistration) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

ServiceRegistration (org.opencastproject.serviceregistry.api.ServiceRegistration)20 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 EntityManager (javax.persistence.EntityManager)5 Job (org.opencastproject.job.api.Job)5 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)5 NotFoundException (org.opencastproject.util.NotFoundException)5 URISyntaxException (java.net.URISyntaxException)4 NoResultException (javax.persistence.NoResultException)4 PersistenceException (javax.persistence.PersistenceException)4 RollbackException (javax.persistence.RollbackException)4 HostRegistration (org.opencastproject.serviceregistry.api.HostRegistration)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 EntityTransaction (javax.persistence.EntityTransaction)3 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)3 SystemLoad (org.opencastproject.serviceregistry.api.SystemLoad)3 HostRegistrationJpaImpl (org.opencastproject.serviceregistry.impl.jpa.HostRegistrationJpaImpl)3 ServiceRegistrationJpaImpl (org.opencastproject.serviceregistry.impl.jpa.ServiceRegistrationJpaImpl)3 ConfigurationException (org.osgi.service.cm.ConfigurationException)3