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;
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations