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