diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-07-30 15:14:17 +0530 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2021-07-30 18:05:09 +0000 |
commit | df5869629e4ffd6cb0b1ccb81c1fe17cdd73f851 (patch) | |
tree | b6633de7ba8efc028053e5b0a3f710b7d8fe34ab /sdnr/wt/data-provider/provider/src/main | |
parent | 0c8d2c3d7dfd79a25107480af718d3d76cd45f39 (diff) |
devicemanager-core refactoring and support for TLS mountpoints using data-provider interface
Use NodeId instead of String for mountpointname and enhance data-provider for creation of TLS mountpoints using REST or from the UI
Issue-ID: CCSDK-3403
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: Iafb9fe81c2e1d1152beef2b86299edb78a870d85
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/main')
-rw-r--r-- | sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java index ad712847f..2bf67fde9 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java @@ -95,12 +95,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hLtpListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadStatusInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadStatusOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadTlsKeyEntryInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadTlsKeyEntryOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadTlsKeyEntryOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.tls.key.entry.output.Pagination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.tls.key.entry.output.PaginationBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -119,6 +124,8 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab public static final String CONFIGURATIONFILE = "etc/dataprovider.properties"; private static final long DATABASE_TIMEOUT_MS = 120 * 1000L; private static final @NonNull InstanceIdentifier<Keystore> KEYSTORE_IIF = InstanceIdentifier.create(Keystore.class); + private static final Pagination EMPTY_PAGINATION = new PaginationBuilder().setSize(Uint32.valueOf(20)) + .setTotal(Uint64.valueOf(0)).setPage(Uint64.valueOf(1)).build(); private static final long DEFAULT_PAGESIZE = 20; private static final long DEFAULT_PAGE = 1; @@ -407,6 +414,45 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab return result.buildFuture(); } + @Override + public ListenableFuture<RpcResult<ReadTlsKeyEntryOutput>> readTlsKeyEntry(ReadTlsKeyEntryInput input) { + LOG.debug("RPC Request: readTlsKeyEntry with input {}", input); + RpcResultBuilder<ReadTlsKeyEntryOutput> result = read(() -> DataProviderServiceImpl.this.readTlsKeys(input)); + return result.buildFuture(); + } + + // -- private classes and functions + + private ReadTlsKeyEntryOutputBuilder readTlsKeys(ReadTlsKeyEntryInput input) { + Optional<Keystore> result = Optional.empty(); + try { + result = this.dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, KEYSTORE_IIF) + .get(); + } catch (InterruptedException | ExecutionException e) { + LOG.warn("problem reading netconf-keystore: ", e); + } + ReadTlsKeyEntryOutputBuilder output = new ReadTlsKeyEntryOutputBuilder(); + if (result.isEmpty()) { + return output.setData(Arrays.asList()).setPagination(EMPTY_PAGINATION); + } + Map<KeyCredentialKey, KeyCredential> keyCredential = result.get().getKeyCredential(); + if (keyCredential == null) { + return output.setData(Arrays.asList()).setPagination(EMPTY_PAGINATION); + } + long pageNum = input.getPagination() == null ? DEFAULT_PAGE + : input.getPagination().getPage() == null ? DEFAULT_PAGE : input.getPagination().getPage().longValue(); + long size = input.getPagination() == null ? DEFAULT_PAGESIZE + : input.getPagination().getSize() == null ? DEFAULT_PAGESIZE + : input.getPagination().getSize().longValue(); + long from = pageNum > 0 ? (pageNum - 1) * size : 0; + output.setData(keyCredential.keySet().stream().skip(from).limit(size).map(e -> e.getKeyId()) + .collect(Collectors.toList())); + output.setPagination(new PaginationBuilder().setPage(Uint64.valueOf(pageNum)) + .setSize(Uint32.valueOf(output.getData().size())).setTotal(Uint64.valueOf(keyCredential.size())) + .build()); + return output; + } + private static String assembleExceptionMessage(Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); |