Search in sources :

Example 1 with Version

use of org.apache.knox.gateway.topology.Version in project knox by apache.

the class TopologyRulesModuleTest method testParseServiceParamsInKnoxFormat.

@Test
public void testParseServiceParamsInKnoxFormat() throws IOException, SAXException {
    Digester digester = loader.newDigester();
    String name = "org/apache/knox/gateway/topology/xml/service-param-topology-knox-format.xml";
    URL url = ClassLoader.getSystemResource(name);
    assertThat("Failed to find URL for resource " + name, url, notNullValue());
    File file = new File(url.getFile());
    TopologyBuilder topologyBuilder = digester.parse(url);
    Topology topology = topologyBuilder.build();
    assertThat("Failed to parse resource " + name, topology, notNullValue());
    topology.setTimestamp(file.lastModified());
    assertThat(topology.getName(), is("test-topology-name"));
    assertThat(topology.getTimestamp(), is(file.lastModified()));
    assertThat(topology.getServices().size(), is(1));
    Provider provider = topology.getProviders().iterator().next();
    assertThat(provider, notNullValue());
    assertThat(provider.getRole(), is("test-provider-role"));
    assertThat(provider.getName(), is("test-provider-name"));
    assertThat(provider.getParams(), hasEntry(is("test-provider-param-name-1"), is("test-provider-param-value-1")));
    assertThat(provider.getParams(), hasEntry(is("test-provider-param-name-2"), is("test-provider-param-value-2")));
    Service service = topology.getServices().iterator().next();
    assertThat(service, notNullValue());
    assertThat(service.getRole(), is("test-service-role"));
    assertThat(service.getUrls().size(), is(2));
    assertThat(service.getUrls(), hasItem("test-service-scheme://test-service-host1:42/test-service-path"));
    assertThat(service.getUrls(), hasItem("test-service-scheme://test-service-host2:42/test-service-path"));
    assertThat(service.getName(), is("test-service-name"));
    assertThat(service.getParams(), hasEntry(is("test-service-param-name-1"), is("test-service-param-value-1")));
    assertThat(service.getParams(), hasEntry(is("test-service-param-name-2"), is("test-service-param-value-2")));
    assertThat(service.getVersion(), is(new Version(1, 0, 0)));
}
Also used : TopologyBuilder(org.apache.knox.gateway.topology.builder.TopologyBuilder) Version(org.apache.knox.gateway.topology.Version) Digester(org.apache.commons.digester3.Digester) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) File(java.io.File) URL(java.net.URL) Provider(org.apache.knox.gateway.topology.Provider) Test(org.junit.Test)

Example 2 with Version

use of org.apache.knox.gateway.topology.Version in project knox by apache.

the class BeanConverter method getService.

private static org.apache.knox.gateway.topology.Service getService(Service service) {
    org.apache.knox.gateway.topology.Service deploymentService = new org.apache.knox.gateway.topology.Service();
    deploymentService.setRole(service.getRole());
    deploymentService.setName(service.getName());
    if (service.getVersion() != null) {
        deploymentService.setVersion(new Version(service.getVersion()));
    }
    for (Param param : service.getParams()) {
        deploymentService.addParam(getParam(param));
    }
    for (String url : service.getUrls()) {
        deploymentService.addUrl(url);
    }
    return deploymentService;
}
Also used : Version(org.apache.knox.gateway.topology.Version)

Example 3 with Version

use of org.apache.knox.gateway.topology.Version in project knox by apache.

the class TopologyRulesModuleTest method testParseSimpleTopologyXmlInKnoxFormat.

@Test
public void testParseSimpleTopologyXmlInKnoxFormat() throws IOException, SAXException, URISyntaxException {
    Digester digester = loader.newDigester();
    String name = "org/apache/knox/gateway/topology/xml/simple-topology-knox-format.xml";
    URL url = ClassLoader.getSystemResource(name);
    assertThat("Failed to find URL for resource " + name, url, notNullValue());
    File file = new File(url.getFile());
    TopologyBuilder topologyBuilder = digester.parse(url);
    Topology topology = topologyBuilder.build();
    assertThat("Failed to parse resource " + name, topology, notNullValue());
    topology.setTimestamp(file.lastModified());
    assertThat(topology.getName(), is("topology"));
    assertThat(topology.getTimestamp(), is(file.lastModified()));
    assertThat(topology.getServices().size(), is(3));
    Service comp = topology.getServices().iterator().next();
    assertThat(comp, notNullValue());
    assertThat(comp.getRole(), is("WEBHDFS"));
    assertThat(comp.getVersion().toString(), is("2.4.0"));
    assertThat(comp.getUrls().size(), is(2));
    assertThat(comp.getUrls(), hasItem("http://host1:80/webhdfs"));
    assertThat(comp.getUrls(), hasItem("http://host2:80/webhdfs"));
    Provider provider = topology.getProviders().iterator().next();
    assertThat(provider, notNullValue());
    assertThat(provider.isEnabled(), is(true));
    assertThat(provider.getRole(), is("authentication"));
    assertThat(provider.getParams().size(), is(5));
    Service service = topology.getService("WEBHDFS", "webhdfs", new Version(2, 4, 0));
    assertEquals(comp, service);
    comp = topology.getService("RESOURCEMANAGER", null, new Version("2.5.0"));
    assertThat(comp, notNullValue());
    assertThat(comp.getRole(), is("RESOURCEMANAGER"));
    assertThat(comp.getVersion().toString(), is("2.5.0"));
    assertThat(comp.getUrl(), is("http://host1:8088/ws"));
    comp = topology.getService("HIVE", "hive", null);
    assertThat(comp, notNullValue());
    assertThat(comp.getRole(), is("HIVE"));
    assertThat(comp.getName(), is("hive"));
    assertThat(comp.getUrl(), is("http://host2:10001/cliservice"));
}
Also used : TopologyBuilder(org.apache.knox.gateway.topology.builder.TopologyBuilder) Version(org.apache.knox.gateway.topology.Version) Digester(org.apache.commons.digester3.Digester) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) File(java.io.File) URL(java.net.URL) Provider(org.apache.knox.gateway.topology.Provider) Test(org.junit.Test)

Example 4 with Version

use of org.apache.knox.gateway.topology.Version in project knox by apache.

the class BeanConverter method getApplication.

private static Application getApplication(org.apache.knox.gateway.topology.Application application) {
    Application applicationResource = new Application();
    applicationResource.setRole(application.getRole());
    applicationResource.setName(application.getName());
    Version version = application.getVersion();
    if (version != null) {
        applicationResource.setVersion(version.toString());
    }
    Collection<org.apache.knox.gateway.topology.Param> paramsList = application.getParamsList();
    if (paramsList != null && !paramsList.isEmpty()) {
        for (org.apache.knox.gateway.topology.Param param : paramsList) {
            applicationResource.getParams().add(getParam(param));
        }
    }
    for (String url : application.getUrls()) {
        applicationResource.getUrls().add(url);
    }
    return applicationResource;
}
Also used : Version(org.apache.knox.gateway.topology.Version)

Example 5 with Version

use of org.apache.knox.gateway.topology.Version in project knox by apache.

the class BeanConverter method getService.

private static Service getService(org.apache.knox.gateway.topology.Service service) {
    Service serviceResource = new Service();
    serviceResource.setRole(service.getRole());
    serviceResource.setName(service.getName());
    Version version = service.getVersion();
    if (version != null) {
        serviceResource.setVersion(version.toString());
    }
    Collection<org.apache.knox.gateway.topology.Param> paramsList = service.getParamsList();
    if (paramsList != null && !paramsList.isEmpty()) {
        for (org.apache.knox.gateway.topology.Param param : paramsList) {
            serviceResource.getParams().add(getParam(param));
        }
    }
    for (String url : service.getUrls()) {
        serviceResource.getUrls().add(url);
    }
    return serviceResource;
}
Also used : Version(org.apache.knox.gateway.topology.Version)

Aggregations

Version (org.apache.knox.gateway.topology.Version)6 File (java.io.File)2 URL (java.net.URL)2 Digester (org.apache.commons.digester3.Digester)2 Provider (org.apache.knox.gateway.topology.Provider)2 Service (org.apache.knox.gateway.topology.Service)2 Topology (org.apache.knox.gateway.topology.Topology)2 TopologyBuilder (org.apache.knox.gateway.topology.builder.TopologyBuilder)2 Test (org.junit.Test)2