Search in sources :

Example 16 with TopologyService

use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.

the class WebsocketEchoTest method setupGatewayConfig.

/**
 * Initialize the configs and components required for this test.
 *
 * @param backend
 * @throws IOException
 */
private static void setupGatewayConfig(final String backend) throws IOException {
    services = new DefaultGatewayServices();
    topoDir = createDir();
    URL serviceUrl = ClassLoader.getSystemResource("websocket-services");
    final File descriptor = new File(topoDir, "websocket.xml");
    final FileOutputStream stream = new FileOutputStream(descriptor);
    createKnoxTopology(backend).toStream(stream);
    stream.close();
    final TestTopologyListener topoListener = new TestTopologyListener();
    final Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(gatewayConfig.getGatewayTopologyDir()).andReturn(topoDir.toString()).anyTimes();
    EasyMock.expect(gatewayConfig.getGatewayProvidersConfigDir()).andReturn(topoDir.getAbsolutePath() + "/shared-providers").anyTimes();
    EasyMock.expect(gatewayConfig.getGatewayDescriptorsDir()).andReturn(topoDir.getAbsolutePath() + "/descriptors").anyTimes();
    EasyMock.expect(gatewayConfig.getGatewayServicesDir()).andReturn(serviceUrl.getFile()).anyTimes();
    EasyMock.expect(gatewayConfig.getEphemeralDHKeySize()).andReturn("2048").anyTimes();
    EasyMock.expect(gatewayConfig.getGatewaySecurityDir()).andReturn(topoDir.toString()).anyTimes();
    /* Websocket configs */
    EasyMock.expect(gatewayConfig.isWebsocketEnabled()).andReturn(true).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxTextMessageSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxBinaryMessageSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxTextMessageBufferSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxBinaryMessageBufferSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketInputBufferSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketAsyncWriteTimeout()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketIdleTimeout()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_IDLE_TIMEOUT).anyTimes();
    EasyMock.expect(gatewayConfig.getRemoteRegistryConfigurationNames()).andReturn(Collections.emptyList()).anyTimes();
    EasyMock.replay(gatewayConfig);
    try {
        services.init(gatewayConfig, options);
    } catch (ServiceLifecycleException e) {
        e.printStackTrace();
    }
    DeploymentFactory.setGatewayServices(services);
    final TopologyService monitor = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    monitor.addTopologyChangeListener(topoListener);
    monitor.reloadTopologies();
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) URL(java.net.URL) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) TopologyService(org.apache.knox.gateway.services.topology.TopologyService)

Example 17 with TopologyService

use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.

the class WebsocketMultipleConnectionTest method setupGatewayConfig.

/**
 * Initialize the configs and components required for this test.
 *
 * @param backend
 * @throws IOException
 */
private static void setupGatewayConfig(final String backend) throws IOException {
    services = new DefaultGatewayServices();
    topoDir = createDir();
    URL serviceUrl = ClassLoader.getSystemResource("websocket-services");
    final File descriptor = new File(topoDir, "websocket.xml");
    final FileOutputStream stream = new FileOutputStream(descriptor);
    createKnoxTopology(backend).toStream(stream);
    stream.close();
    final TestTopologyListener topoListener = new TestTopologyListener();
    final Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(gatewayConfig.getGatewayTopologyDir()).andReturn(topoDir.toString()).anyTimes();
    EasyMock.expect(gatewayConfig.getGatewayProvidersConfigDir()).andReturn(topoDir.getAbsolutePath() + "/shared-providers").anyTimes();
    EasyMock.expect(gatewayConfig.getGatewayDescriptorsDir()).andReturn(topoDir.getAbsolutePath() + "/descriptors").anyTimes();
    EasyMock.expect(gatewayConfig.getGatewayServicesDir()).andReturn(serviceUrl.getFile()).anyTimes();
    EasyMock.expect(gatewayConfig.getEphemeralDHKeySize()).andReturn("2048").anyTimes();
    EasyMock.expect(gatewayConfig.getGatewaySecurityDir()).andReturn(topoDir.toString()).anyTimes();
    /* Websocket configs */
    EasyMock.expect(gatewayConfig.isWebsocketEnabled()).andReturn(true).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxTextMessageSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxBinaryMessageSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxTextMessageBufferSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketMaxBinaryMessageBufferSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketInputBufferSize()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketAsyncWriteTimeout()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT).anyTimes();
    EasyMock.expect(gatewayConfig.getWebsocketIdleTimeout()).andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_IDLE_TIMEOUT).anyTimes();
    EasyMock.expect(gatewayConfig.getRemoteRegistryConfigurationNames()).andReturn(Collections.emptyList()).anyTimes();
    EasyMock.replay(gatewayConfig);
    try {
        services.init(gatewayConfig, options);
    } catch (ServiceLifecycleException e) {
        e.printStackTrace();
    }
    DeploymentFactory.setGatewayServices(services);
    final TopologyService monitor = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    monitor.addTopologyChangeListener(topoListener);
    monitor.reloadTopologies();
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) URL(java.net.URL) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) TopologyService(org.apache.knox.gateway.services.topology.TopologyService)

Example 18 with TopologyService

use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.

the class TopologiesResource method getSimpleDescriptor.

@GET
@Produces({ APPLICATION_JSON, TEXT_PLAIN })
@Path(SINGLE_DESCRIPTOR_API_PATH)
public Response getSimpleDescriptor(@PathParam("name") String name) {
    Response response;
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    File descriptorFile = null;
    for (File sd : ts.getDescriptors()) {
        // If the file name matches the specified id
        if (FilenameUtils.getBaseName(sd.getName()).equals(name)) {
            descriptorFile = sd;
            break;
        }
    }
    if (descriptorFile != null) {
        String mediaType = APPLICATION_JSON;
        byte[] content = null;
        try {
            if ("yml".equals(FilenameUtils.getExtension(descriptorFile.getName()))) {
                mediaType = TEXT_PLAIN;
            }
            content = FileUtils.readFileToByteArray(descriptorFile);
            response = ok().type(mediaType).entity(content).build();
        } catch (IOException e) {
            log.failedToReadConfigurationFile(descriptorFile.getAbsolutePath(), e);
            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        }
    } else {
        response = Response.status(Response.Status.NOT_FOUND).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GatewayServices(org.apache.knox.gateway.services.GatewayServices) IOException(java.io.IOException) File(java.io.File) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with TopologyService

use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.

the class TopologiesResource method deleteTopology.

@DELETE
@Produces(APPLICATION_JSON)
@Path(SINGLE_TOPOLOGY_API_PATH)
public Response deleteTopology(@PathParam("id") String id) {
    boolean deleted = false;
    if (!"admin".equals(id)) {
        GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
        TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
        for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
            if (t.getName().equals(id)) {
                ts.deleteTopology(t);
                deleted = true;
            }
        }
    } else {
        deleted = false;
    }
    return ok().entity("{ \"deleted\" : " + deleted + " }").build();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 20 with TopologyService

use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.

the class TopologiesResource method deleteSimpleDescriptor.

@DELETE
@Produces(APPLICATION_JSON)
@Path(SINGLE_DESCRIPTOR_API_PATH)
public Response deleteSimpleDescriptor(@PathParam("name") String name) {
    Response response = null;
    if (!"admin".equals(name)) {
        GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
        TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
        if (ts.deleteDescriptor(name)) {
            response = ok().entity("{ \"deleted\" : \"descriptor " + name + "\" }").build();
        }
    }
    if (response == null) {
        response = notModified().build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GatewayServices(org.apache.knox.gateway.services.GatewayServices) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Aggregations

TopologyService (org.apache.knox.gateway.services.topology.TopologyService)23 GatewayServices (org.apache.knox.gateway.services.GatewayServices)17 Path (javax.ws.rs.Path)12 File (java.io.File)11 Produces (javax.ws.rs.Produces)9 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)7 GET (javax.ws.rs.GET)6 Response (javax.ws.rs.core.Response)6 ArrayList (java.util.ArrayList)5 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)5 Topology (org.apache.knox.gateway.topology.Topology)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 HashMap (java.util.HashMap)4 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 Consumes (javax.ws.rs.Consumes)3 DELETE (javax.ws.rs.DELETE)3 PUT (javax.ws.rs.PUT)3 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)3