use of org.apache.knox.gateway.services.registry.ServiceRegistry in project knox by apache.
the class DeploymentFactory method contributeServices.
private static void contributeServices(DeploymentContext context, Topology topology, Map<String, List<ServiceDeploymentContributor>> services) {
if (services != null) {
for (Service service : topology.getServices()) {
ServiceDeploymentContributor contributor = getServiceContributor(service.getRole(), service.getName(), service.getVersion());
if (contributor != null) {
try {
log.contributeService(service.getName(), service.getRole());
contributor.contributeService(context, service);
if (gatewayServices != null) {
ServiceRegistry sr = gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
if (sr != null) {
String regCode = sr.getRegistrationCode(topology.getName());
sr.registerService(regCode, topology.getName(), service.getRole(), service.getUrls());
}
}
} catch (Exception e) {
// Maybe it makes sense to throw exception
log.failedToContributeService(service.getName(), service.getRole(), e);
throw new DeploymentException("Failed to contribute service.", e);
}
}
}
}
}
use of org.apache.knox.gateway.services.registry.ServiceRegistry in project knox by apache.
the class HaServletContextListener method setupHaProvider.
private void setupHaProvider(HaDescriptor descriptor, ServletContext servletContext) {
GatewayServices services = (GatewayServices) servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
String clusterName = (String) servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
ServiceRegistry serviceRegistry = services.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
HaProvider provider = new DefaultHaProvider(descriptor);
List<String> serviceNames = descriptor.getEnabledServiceNames();
for (String serviceName : serviceNames) {
provider.addHaService(serviceName, serviceRegistry.lookupServiceURLs(clusterName, serviceName));
}
servletContext.setAttribute(PROVIDER_ATTRIBUTE_NAME, provider);
}
use of org.apache.knox.gateway.services.registry.ServiceRegistry in project knox by apache.
the class FrontendFunctionProcessorTest method setUp.
public void setUp(String username, Map<String, String> initParams, Attributes attributes) throws Exception {
ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-nn-scheme://test-nn-host:411").anyTimes();
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")).andReturn("test-jt-scheme://test-jt-host:511").anyTimes();
GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(mockGatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(mockServiceRegistry).anyTimes();
EasyMock.replay(mockServiceRegistry, mockGatewayServices);
String descriptorUrl = TestUtils.getResourceUrl(FrontendFunctionProcessorTest.class, "rewrite.xml").toExternalForm();
Log.setLog(new NoOpLogger());
server = new ServletTester();
server.setContextPath("/");
server.getContext().addEventListener(new UrlRewriteServletContextListener());
server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);
if (attributes != null) {
server.getContext().setAttributes(attributes);
}
server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster");
server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices);
FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
setupFilter.setFilter(new SetupFilter(username));
FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (initParams != null) {
for (Map.Entry<String, String> entry : initParams.entrySet()) {
rewriteFilter.setInitParameter(entry.getKey(), entry.getValue());
}
}
rewriteFilter.setFilter(new UrlRewriteServletFilter());
interactions = new ArrayQueue<MockInteraction>();
ServletHolder servlet = server.addServlet(MockServlet.class, "/");
servlet.setServlet(new MockServlet("mock-servlet", interactions));
server.start();
interaction = new MockInteraction();
request = HttpTester.newRequest();
response = null;
}
use of org.apache.knox.gateway.services.registry.ServiceRegistry in project knox by apache.
the class OozieServiceDefinitionTest method testOozieRewriteRulesForLiteralTemplateValuesBugKnox394.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testOozieRewriteRulesForLiteralTemplateValuesBugKnox394() throws Exception {
LOG_ENTER();
// This is a unique part of this test.
String testResource = "oozie-request-with-var.xml";
// Mock out the service url registry which is required for several url rewrite functions to work.
ServiceRegistry registry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(registry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-scheme://test-host:42").anyTimes();
// Mock out the gateway services registry which is required for several url rewrite functions to work.
GatewayServices services = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(services.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(registry).anyTimes();
UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(servletContext.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)).andReturn(rewriteProcessor).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(services).anyTimes();
EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
HttpServletRequest servletRequest = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.expect(servletRequest.getInputStream()).andReturn(new MockServletInputStream(TestUtils.getResourceStream(OozieServiceDefinitionTest.class, testResource))).anyTimes();
EasyMock.expect(servletRequest.getContentType()).andReturn("text/xml").anyTimes();
FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
EasyMock.expect(filterConfig.getInitParameter(UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM)).andReturn("OOZIE/oozie/configuration").anyTimes();
EasyMock.replay(registry, services, servletContext, servletRequest, filterConfig);
UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment(servletContext);
Reader rulesReader = TestUtils.getResourceReader("services/oozie/4.0.0/rewrite.xml", "UTF-8");
UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load("xml", rulesReader);
rulesReader.close();
rewriteProcessor.initialize(rewriteEnvironment, rewriteRules);
UrlRewriteRequest rewriteRequest = new UrlRewriteRequest(filterConfig, servletRequest);
InputStream stream = rewriteRequest.getInputStream();
Document document = XmlUtils.readXml(stream);
assertThat(document, hasXPath("/configuration/property[name='oozie.wf.application.path']/value", equalTo("${appPath}/workflow.xml")));
LOG_EXIT();
}
Aggregations