Search in sources :

Example 1 with TopologyService

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

the class TopologiesResource method uploadProviderConfiguration.

@PUT
@Consumes({ APPLICATION_XML, APPLICATION_JSON, TEXT_PLAIN })
@Path(SINGLE_PROVIDERCONFIG_API_PATH)
public Response uploadProviderConfiguration(@PathParam("name") String name, @Context HttpHeaders headers, String content) {
    Response response = null;
    GatewayServices gs = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    TopologyService ts = gs.getService(GatewayServices.TOPOLOGY_SERVICE);
    File existing = getExistingConfigFile(ts.getProviderConfigurations(), name);
    boolean isUpdate = (existing != null);
    // If it's an update, then use the matching existing filename; otherwise, use the media type to determine the file
    // extension.
    String filename = isUpdate ? existing.getName() : getFileNameForResource(name, headers);
    if (ts.deployProviderConfiguration(filename, content)) {
        try {
            if (isUpdate) {
                response = Response.noContent().build();
            } else {
                response = created(new URI(buildHref(request))).build();
            }
        } catch (URISyntaxException e) {
            log.invalidResourceURI(e.getInput(), e.getReason(), e);
            response = status(Response.Status.BAD_REQUEST).entity("{ \"error\" : \"Failed to deploy provider configuration " + name + "\" }").build();
        }
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GatewayServices(org.apache.knox.gateway.services.GatewayServices) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 2 with TopologyService

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

the class TopologiesResource method getTopologies.

@GET
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Path(TOPOLOGIES_API_PATH)
public SimpleTopologyWrapper getTopologies() {
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    ArrayList<SimpleTopology> st = new ArrayList<SimpleTopology>();
    GatewayConfig conf = (GatewayConfig) request.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
    for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
        st.add(getSimpleTopology(t, conf));
    }
    Collections.sort(st, new TopologyComparator());
    SimpleTopologyWrapper stw = new SimpleTopologyWrapper();
    for (SimpleTopology t : st) {
        stw.topologies.add(t);
    }
    return stw;
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) ArrayList(java.util.ArrayList) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with TopologyService

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

the class TopologiesResource method getProviderConfiguration.

@GET
@Produces({ APPLICATION_XML, APPLICATION_JSON, TEXT_PLAIN })
@Path(SINGLE_PROVIDERCONFIG_API_PATH)
public Response getProviderConfiguration(@PathParam("name") String name) {
    Response response;
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    File providerConfigFile = null;
    for (File pc : ts.getProviderConfigurations()) {
        // If the file name matches the specified id
        if (FilenameUtils.getBaseName(pc.getName()).equals(name)) {
            providerConfigFile = pc;
            break;
        }
    }
    if (providerConfigFile != null) {
        byte[] content = null;
        try {
            content = FileUtils.readFileToByteArray(providerConfigFile);
            response = ok().entity(content).build();
        } catch (IOException e) {
            log.failedToReadConfigurationFile(providerConfigFile.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 4 with TopologyService

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

the class TopologiesResource method deleteProviderConfiguration.

@DELETE
@Produces(APPLICATION_JSON)
@Path(SINGLE_PROVIDERCONFIG_API_PATH)
public Response deleteProviderConfiguration(@PathParam("name") String name) {
    Response response;
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    if (ts.deleteProviderConfiguration(name)) {
        response = ok().entity("{ \"deleted\" : \"provider config " + name + "\" }").build();
    } else {
        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)

Example 5 with TopologyService

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

the class TopologiesResource method getSimpleDescriptors.

@GET
@Produces({ APPLICATION_JSON })
@Path(DESCRIPTORS_API_PATH)
public HrefListing getSimpleDescriptors() {
    HrefListing listing = new HrefListing();
    listing.setHref(buildHref(request));
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    List<HrefListItem> descriptors = new ArrayList<>();
    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
    for (File descriptor : ts.getDescriptors()) {
        String id = FilenameUtils.getBaseName(descriptor.getName());
        descriptors.add(new HrefListItem(buildHref(id, request), descriptor.getName()));
    }
    listing.setItems(descriptors);
    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)

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