Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This Stream will implement pagination when fetching data from the FragmentRepository. (This may be implemented in a variety of ways, using Spring JpaRepository Pageable interface, or alternately Spring Data supports streaming from a repository directly, but this needs to be investigated for suitability.)

Here is a proposed end-to-end flow - a simplified example to show how greatly this can reduce memory usage:

Code Block
languagejava
// In CPS core
Stream<DataNode> queryDataNodesAsStream(String dataspaceName, String anchorName, String cpsPath, FetchDescendantsOption fetchDescendantsOption) {
    final var anchor = getAnchor(dataspaceName, anchorName);
	return fragmentRepository.streamByAnchorAndCpsPath(anchor, cpsPath)
			.map(fragment -> fetchDescendants(fragment, fetchDescendantsOption))
			.map(fragment -> toDataNode(fragment));
}

// In NCMP
private YangModelCmHandle getAnyReadyCmHandleByModuleSetTag(final String moduleSetTag) {
    return cmHandleQueries.queryNcmpRegistryByCpsPath("/dmi-registry/cm-handles[@module-set-tag='" + moduleSetTag + "']", DIRECT_CHILDREN_ONLY)
			.map(YangDataConverter::convertCmHandleToYangModel)
            .filter(cmHandle -> cmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY)
            .findFirst()
            .orElse(null);
}


CPS and NCMP Rest APIs

Instead of returning Collections from Rest APIs, a Stream may be returned, greatly reducing memory pressure on the server.