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);
}
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));
}
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();
}
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();
}
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();
}
Aggregations