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