+
+ @Override
+ public ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
+ final AddTrustedCertificateInput input) {
+ final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+
+ for (TrustedCertificate certificate : input.getTrustedCertificate()) {
+ writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
+ keystoreIid.child(TrustedCertificate.class, certificate.key()), certificate);
+ }
+
+ final SettableFuture<RpcResult<AddTrustedCertificateOutput>> rpcResult = SettableFuture.create();
+
+ writeTransaction.commit().addCallback(new FutureCallback<CommitInfo>() {
+ @Override
+ public void onSuccess(final CommitInfo result) {
+ LOG.debug("add-trusted-certificate success. Input: {}", input);
+ rpcResult.set(RpcResultBuilder.success(new AddTrustedCertificateOutputBuilder().build()).build());
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.warn("add-trusted-certificate failed. Input: {}", input, throwable);
+ rpcResult.setException(throwable);
+ }
+ }, MoreExecutors.directExecutor());
+
+ return rpcResult;
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<RemoveTrustedCertificateOutput>> removeTrustedCertificate(
+ final RemoveTrustedCertificateInput input) {
+ final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+ final List<String> names = input.getName();
+
+ for (final String name : names) {
+ writeTransaction.delete(LogicalDatastoreType.CONFIGURATION,
+ keystoreIid.child(TrustedCertificate.class, new TrustedCertificateKey(name)));
+ }
+
+ final SettableFuture<RpcResult<RemoveTrustedCertificateOutput>> rpcResult = SettableFuture.create();
+
+ writeTransaction.commit().addCallback(new FutureCallback<CommitInfo>() {
+ @Override
+ public void onSuccess(final CommitInfo result) {
+ LOG.debug("remove-trusted-certificate success. Input: {}", input);
+ rpcResult.set(RpcResultBuilder.success(new RemoveTrustedCertificateOutputBuilder().build()).build());
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.warn("remove-trusted-certificate failed. Input: {}", input, throwable);
+ rpcResult.setException(throwable);
+ }
+ }, MoreExecutors.directExecutor());
+
+ return rpcResult;
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
+ final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+
+ for (PrivateKey key: input.getPrivateKey()) {
+ writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
+ keystoreIid.child(PrivateKey.class, key.key()), key);
+ }
+
+ final SettableFuture<RpcResult<AddPrivateKeyOutput>> rpcResult = SettableFuture.create();
+
+ writeTransaction.commit().addCallback(new FutureCallback<CommitInfo>() {
+ @Override
+ public void onSuccess(final CommitInfo result) {
+ LOG.debug("add-private-key success. Input: {}", input);
+ rpcResult.set(RpcResultBuilder.success(new AddPrivateKeyOutputBuilder().build()).build());
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.warn("add-private-key failed. Input: {}", input, throwable);
+ rpcResult.setException(throwable);
+ }
+ }, MoreExecutors.directExecutor());
+
+ return rpcResult;
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<RemovePrivateKeyOutput>> removePrivateKey(final RemovePrivateKeyInput input) {
+ final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+ final List<String> names = input.getName();
+
+ for (final String name : names) {
+ writeTransaction.delete(LogicalDatastoreType.CONFIGURATION,
+ keystoreIid.child(PrivateKey.class, new PrivateKeyKey(name)));
+ }
+
+ final SettableFuture<RpcResult<RemovePrivateKeyOutput>> rpcResult = SettableFuture.create();
+
+ writeTransaction.commit().addCallback(new FutureCallback<CommitInfo>() {
+ @Override
+ public void onSuccess(final CommitInfo result) {
+ LOG.debug("remove-private-key success. Input: {}", input);
+ rpcResult.set(RpcResultBuilder.success(new RemovePrivateKeyOutputBuilder().build()).build());
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.warn("remove-private-key failed. Input: {}", input, throwable);
+ rpcResult.setException(throwable);
+ }
+ }, MoreExecutors.directExecutor());
+
+ return rpcResult;
+ }