Search in sources :

Example 21 with TopologyService

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

the class TopologiesResource method uploadSimpleDescriptor.

@PUT
@Consumes({ APPLICATION_JSON, TEXT_PLAIN })
@Path(SINGLE_DESCRIPTOR_API_PATH)
public Response uploadSimpleDescriptor(@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.getDescriptors(), 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.deployDescriptor(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 descriptor " + 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 22 with TopologyService

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

the class GatewayServer method redeployTopologies.

public static void redeployTopologies(String topologyName) {
    TopologyService ts = getGatewayServices().getService(GatewayServices.TOPOLOGY_SERVICE);
    ts.reloadTopologies();
    ts.redeployTopologies(topologyName);
}
Also used : TopologyService(org.apache.knox.gateway.services.topology.TopologyService)

Example 23 with TopologyService

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

the class GatewayServer method cleanupTopologyDeployments.

private void cleanupTopologyDeployments() {
    File deployDir = new File(config.getGatewayDeploymentDir());
    TopologyService ts = getGatewayServices().getService(GatewayServices.TOPOLOGY_SERVICE);
    for (Topology topology : ts.getTopologies()) {
        cleanupTopologyDeployments(deployDir, topology);
    }
}
Also used : Topology(org.apache.knox.gateway.topology.Topology) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File) 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