Search in sources :

Example 1 with Topology

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;
}
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 2 with Topology

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;
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Topology(org.apache.knox.gateway.service.admin.beans.Topology) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

Topology (org.apache.knox.gateway.service.admin.beans.Topology)2 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 GatewayServices (org.apache.knox.gateway.services.GatewayServices)1 TopologyService (org.apache.knox.gateway.services.topology.TopologyService)1