use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.
the class NetworkConfigCommand method doExecute.
@Override
protected void doExecute() {
service = get(NetworkConfigService.class);
JsonNode root = mapper.createObjectNode();
if (isNullOrEmpty(subjectClassKey)) {
if (remove) {
service.removeConfig();
}
addAll((ObjectNode) root);
} else {
SubjectFactory subjectFactory = nullIsIllegal(service.getSubjectFactory(subjectClassKey), subjectClassKey + E_CLASSKEY_NOT_REGISTERED);
if (isNullOrEmpty(subjectKey)) {
addSubjectClass((ObjectNode) root, subjectFactory);
} else {
Object s = subjectFactory.createSubject(subjectKey);
if (isNullOrEmpty(configKey)) {
if (remove) {
service.removeConfig(s);
}
addSubject((ObjectNode) root, s);
} else {
if (remove) {
service.removeConfig(subjectClassKey, s, configKey);
}
root = getSubjectConfig(getConfig(s, subjectClassKey, configKey));
}
}
}
try {
print("%s", mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root));
} catch (JsonProcessingException e) {
throw new IllegalStateException("Error writing JSON to string", e);
}
}
use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.
the class NetworkConfigCommand method addAll.
@SuppressWarnings("unchecked")
private void addAll(ObjectNode root) {
service.getSubjectClasses().forEach(sc -> {
SubjectFactory sf = service.getSubjectFactory(sc);
addSubjectClass(newObject(root, sf.subjectClassKey()), sf);
});
}
use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.
the class SubjectKeyCompleter method choices.
@Override
protected List<String> choices() {
NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class);
String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
if (subjectFactory == null) {
return Collections.emptyList();
}
// get all registered subject objects.
Set<Object> subjects = service.getSubjects(subjectFactory.subjectClass());
return subjects.stream().map(subjectFactory::subjectKey).collect(Collectors.toList());
}
use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.
the class NetworkConfigManager method registerConfigFactory.
@Override
@SuppressWarnings("unchecked")
public void registerConfigFactory(ConfigFactory configFactory) {
checkNotNull(configFactory, NULL_FACTORY_MSG);
if (factoryCounters.containsKey(key(configFactory))) {
factoryCounters.replace(key(configFactory), (factoryCounters.get(key(configFactory)) + 1));
} else {
factories.put(key(configFactory), configFactory);
factoryCounters.put(key(configFactory), 1);
configClasses.put(identifier(configFactory), configFactory.configClass());
SubjectFactory subjectFactory = configFactory.subjectFactory();
subjectClasses.putIfAbsent(subjectFactory.subjectClassKey(), subjectFactory);
subjectClassKeys.putIfAbsent(subjectFactory.subjectClass(), subjectFactory);
store.addConfigFactory(configFactory);
}
}
use of org.onosproject.net.config.SubjectFactory in project onos by opennetworkinglab.
the class NetworkConfigWebResource method download.
/**
* Gets entire network configuration base.
*
* @return 200 OK with network configuration JSON
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response download() {
NetworkConfigService service = get(NetworkConfigService.class);
ObjectNode root = mapper().createObjectNode();
service.getSubjectClasses().forEach(sc -> {
SubjectFactory subjectFactory = service.getSubjectFactory(sc);
produceJson(service, newObject(root, subjectFactory.subjectClassKey()), subjectFactory, sc);
});
return ok(root).build();
}
Aggregations