use of org.apache.knox.gateway.service.admin.beans.Topology 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.service.admin.beans.Topology in project knox by apache.
the class TopologyMarshaller method readFrom.
@Override
public Topology readFrom(Class<Topology> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
try {
if (isReadable(type, genericType, annotations, mediaType)) {
Map<String, Object> properties = Collections.emptyMap();
JAXBContext context = JAXBContext.newInstance(new Class[] { Topology.class }, properties);
InputStream is = entityStream;
Unmarshaller u = context.createUnmarshaller();
u.setProperty(UnmarshallerProperties.MEDIA_TYPE, mediaType.getType() + "/" + mediaType.getSubtype());
Topology topology = (Topology) u.unmarshal(is);
return topology;
}
} catch (JAXBException e) {
throw new IOException(e);
}
return null;
}
Aggregations