Search in sources :

Example 6 with SubjectFactory

use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.

the class NetworkConfigWebResource method download.

/**
 * Gets all network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @return 200 OK with network configuration JSON
 */
@GET
@Path("{subjectClassKey}/{subjectKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response download(@PathParam("subjectClassKey") String subjectClassKey, @PathParam("subjectKey") String subjectKey) {
    NetworkConfigService service = get(NetworkConfigService.class);
    ObjectNode root = mapper().createObjectNode();
    SubjectFactory subjectFactory = nullIsNotFound(service.getSubjectFactory(subjectClassKey), subjectClassNotFoundErrorString(subjectClassKey));
    produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey), true, subjectNotFoundErrorString(subjectClassKey, subjectKey));
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with SubjectFactory

use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.

the class NetworkConfigWebResource method upload.

/**
 * Upload specific network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @param configKey       configuration class key
 * @param request         network configuration JSON rooted at the top node
 * @return 200 OK
 * @throws IOException if unable to parse the request
 */
@POST
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response upload(@PathParam("subjectClassKey") String subjectClassKey, @PathParam("subjectKey") String subjectKey, @PathParam("configKey") String configKey, InputStream request) throws IOException {
    NetworkConfigService service = get(NetworkConfigService.class);
    JsonNode root = readTreeFromStream(mapper(), request);
    SubjectFactory subjectFactory = nullIsNotFound(service.getSubjectFactory(subjectClassKey), subjectClassNotValidErrorString(subjectClassKey));
    service.applyConfig(subjectClassKey, subjectFactory.createSubject(subjectKey), configKey, root);
    return Response.ok().build();
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) JsonNode(com.fasterxml.jackson.databind.JsonNode) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 8 with SubjectFactory

use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.

the class NetworkConfigWebResource method delete.

/**
 * Clear specific network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @param configKey       configuration class key
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
@SuppressWarnings("unchecked")
public Response delete(@PathParam("subjectClassKey") String subjectClassKey, @PathParam("subjectKey") String subjectKey, @PathParam("configKey") String configKey) {
    NetworkConfigService service = get(NetworkConfigService.class);
    SubjectFactory subjectFactory = nullIsNotFound(service.getSubjectFactory(subjectClassKey), subjectClassNotValidErrorString(subjectClassKey));
    service.removeConfig(subjectClassKey, subjectFactory.createSubject(subjectKey), configKey);
    return Response.noContent().build();
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

SubjectFactory (org.onosproject.net.config.SubjectFactory)8 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)5 Path (javax.ws.rs.Path)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 NetworkConfigRegistry (org.onosproject.net.config.NetworkConfigRegistry)1