Search in sources :

Example 21 with ComponentConfigService

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

the class ComponentPropertyNameCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Component name is the previous argument.
    String componentName = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
    ComponentConfigService service = get(ComponentConfigService.class);
    SortedSet<String> strings = delegate.getStrings();
    Set<ConfigProperty> properties = service.getProperties(componentName);
    if (properties != null) {
        properties.forEach(property -> strings.add(property.name()));
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ConfigProperty(org.onosproject.cfg.ConfigProperty)

Example 22 with ComponentConfigService

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

the class CreateRoutes method doExecute.

@Override
protected void doExecute() {
    ComponentConfigService service = get(ComponentConfigService.class);
    service.setProperty("org.onosproject.routescale.ScaleTestManager", "routeCount", String.valueOf(routeCount));
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService)

Example 23 with ComponentConfigService

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

the class LinksWebResource method setVanishStaleLink.

/**
 * Set useStaleLinkAge status.
 *
 * @onos.rsModel VanishedLink
 * @param stream input JSON
 * @return 200 ok.
 * BAD_REQUEST if the JSON is invalid
 */
@POST
@Path("{usestalelinkage}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response setVanishStaleLink(InputStream stream) {
    try {
        // Parse the input stream
        ObjectNode root = (ObjectNode) mapper().readTree(stream);
        if (root.has("active")) {
            ComponentConfigService useStaleLink = get(ComponentConfigService.class);
            useStaleLink.setProperty("org.onosproject.provider.lldp.impl.LldpLinkProvider", "useStaleLinkAge", String.valueOf(root.get("active")));
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.ok().build();
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 24 with ComponentConfigService

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

the class ComponentConfigWebResource method getComponentConfigs.

/**
 * Gets all component configurations.
 * Returns collection of all registered component configurations.
 *
 * @return 200 OK with a collection of component configurations
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getComponentConfigs() {
    ComponentConfigService service = get(ComponentConfigService.class);
    Set<String> components = service.getComponentNames();
    ObjectNode root = mapper().createObjectNode();
    components.forEach(c -> encodeConfigs(c, service.getProperties(c), root));
    return ok(root).build();
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with ComponentConfigService

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

the class ComponentConfigWebResource method setConfigs.

/**
 * Selectively sets configuration properties.
 * Sets only the properties present in the JSON request.
 *
 * @param component component name
 * @param preset preset the property if true
 * @param request   JSON configuration
 * @return 200 OK
 * @throws IOException to signify bad request
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("{component}")
public Response setConfigs(@PathParam("component") String component, @DefaultValue("false") @QueryParam("preset") boolean preset, InputStream request) throws IOException {
    ComponentConfigService service = get(ComponentConfigService.class);
    ObjectNode props = readTreeFromStream(mapper(), request);
    List<String> errorMsgs = new ArrayList<String>();
    if (preset) {
        props.fieldNames().forEachRemaining(k -> {
            try {
                service.preSetProperty(component, k, props.path(k).asText());
            } catch (IllegalArgumentException e) {
                errorMsgs.add(e.getMessage());
            }
        });
    } else {
        props.fieldNames().forEachRemaining(k -> {
            try {
                service.setProperty(component, k, props.path(k).asText());
            } catch (IllegalArgumentException e) {
                errorMsgs.add(e.getMessage());
            }
        });
    }
    if (!errorMsgs.isEmpty()) {
        return Response.status(MULTI_STATUS_RESPONE).entity(produceErrorJson(errorMsgs)).build();
    }
    return Response.ok().build();
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) 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