Search in sources :

Example 6 with TopologyService

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;
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) ArrayList(java.util.ArrayList) 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 7 with TopologyService

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;
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with TopologyService

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;
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) Topology(org.apache.knox.gateway.service.admin.beans.Topology) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 9 with TopologyService

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);
}
Also used : Topology(org.apache.knox.gateway.topology.Topology) TopologyService(org.apache.knox.gateway.services.topology.TopologyService)

Example 10 with TopologyService

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;
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TopologyService(org.apache.knox.gateway.services.topology.TopologyService)

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