Search in sources :

Example 26 with ComponentConfigService

use of org.onosproject.cfg.ComponentConfigService in project onos by opennetworkinglab.

the class ComponentConfigWebResource method getComponentConfig.

/**
 * Gets specified value of a specified component and variable.
 *
 * @param component component name
 * @param attribute  attribute name
 * @return 200 OK with a collection of component configurations
 */
@GET
@Path("{component}/{attribute}")
@Produces(MediaType.APPLICATION_JSON)
public Response getComponentConfig(@PathParam("component") String component, @PathParam("attribute") String attribute) {
    ComponentConfigService service = get(ComponentConfigService.class);
    ObjectNode root = mapper().createObjectNode();
    encodeConfigs(component, attribute, nullIsNotFound(service.getProperty(component, attribute), (service.getProperties(component) == null) ? "No such component" : (service.getProperty(component, attribute) == null) ? ("No such attribute in " + component) : "No such attribute and component"), root);
    return ok(root).build();
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with ComponentConfigService

use of org.onosproject.cfg.ComponentConfigService in project onos by opennetworkinglab.

the class ComponentConfigWebResource method unsetConfigs.

/**
 * Selectively clears configuration properties.
 * Clears only the properties present in the JSON request.
 *
 * @param component component name
 * @param request   JSON configuration
 * @return 204 NO CONTENT
 * @throws IOException to signify bad request
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("{component}")
public Response unsetConfigs(@PathParam("component") String component, InputStream request) throws IOException {
    ComponentConfigService service = get(ComponentConfigService.class);
    ObjectNode props = readTreeFromStream(mapper(), request);
    props.fieldNames().forEachRemaining(k -> service.unsetProperty(component, k));
    return Response.noContent().build();
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Aggregations

ComponentConfigService (org.onosproject.cfg.ComponentConfigService)27 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 GET (javax.ws.rs.GET)7 Before (org.junit.Before)5 CoreService (org.onosproject.core.CoreService)4 Hashtable (java.util.Hashtable)3 Consumes (javax.ws.rs.Consumes)3 ComponentContext (org.osgi.service.component.ComponentContext)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 POST (javax.ws.rs.POST)2 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)2 EasyMock.anyObject (org.easymock.EasyMock.anyObject)2 ConfigProperty (org.onosproject.cfg.ConfigProperty)2 NullProviders (org.onosproject.provider.nil.NullProviders)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1