use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.
the class TopologiesResource method getProviderConfigurations.
@GET
@Produces({ APPLICATION_JSON })
@Path(PROVIDERCONFIG_API_PATH)
public HrefListing getProviderConfigurations() {
HrefListing listing = new HrefListing();
listing.setHref(buildHref(request));
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
List<HrefListItem> configs = new ArrayList<>();
TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
// Get all the simple descriptor file names
for (File providerConfig : ts.getProviderConfigurations()) {
String id = FilenameUtils.getBaseName(providerConfig.getName());
configs.add(new HrefListItem(buildHref(id, request), providerConfig.getName()));
}
listing.setItems(configs);
return listing;
}
use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.
the class TopologiesResource method getTopology.
@GET
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Path(SINGLE_TOPOLOGY_API_PATH)
public Topology getTopology(@PathParam("id") String id) {
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
GatewayConfig config = (GatewayConfig) request.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
if (t.getName().equals(id)) {
try {
t.setUri(new URI(buildURI(t, config, request)));
} catch (URISyntaxException se) {
t.setUri(null);
}
return BeanConverter.getTopology(t);
}
}
return null;
}
use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.
the class TopologiesResource method uploadTopology.
@PUT
@Consumes({ APPLICATION_JSON, APPLICATION_XML })
@Path(SINGLE_TOPOLOGY_API_PATH)
public Topology uploadTopology(@PathParam("id") String id, Topology t) {
Topology result = null;
GatewayServices gs = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
t.setName(id);
TopologyService ts = gs.getService(GatewayServices.TOPOLOGY_SERVICE);
// Check for existing topology with the same name, to see if it had been generated
boolean existingGenerated = false;
for (org.apache.knox.gateway.topology.Topology existingTopology : ts.getTopologies()) {
if (existingTopology.getName().equals(id)) {
existingGenerated = existingTopology.isGenerated();
break;
}
}
// out of sync with the source descriptor. Otherwise, deploy the updated version.
if (!existingGenerated) {
ts.deployTopology(BeanConverter.getTopology(t));
result = getTopology(id);
} else {
log.disallowedOverwritingGeneratedTopology(id);
}
return result;
}
use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.
the class GatewayServicesContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
GatewayServices gs = GatewayServer.getGatewayServices();
sce.getServletContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, gs);
String topologyName = (String) sce.getServletContext().getAttribute("org.apache.knox.gateway.gateway.cluster");
TopologyService ts = gs.getService(GatewayServices.TOPOLOGY_SERVICE);
Topology topology = getTopology(ts, topologyName);
sce.getServletContext().setAttribute("org.apache.knox.gateway.topology", topology);
}
use of org.apache.knox.gateway.services.topology.TopologyService in project knox by apache.
the class ServiceTestResource method getServiceTestURLs.
private List<String> getServiceTestURLs(GatewayConfig conf, String role, Topology topology) {
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
List<String> fullURLs = new ArrayList<>();
if (services != null) {
TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
Map<String, List<String>> urls = ts.getServiceTestURLs(topology, conf);
List<String> urlPaths = urls.get(role);
if (urlPaths != null) {
String base = buildURI(topology, conf, request);
for (String u : urlPaths) {
fullURLs.add(base + u);
}
}
}
return fullURLs;
}
Aggregations