use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class RestconfImpl method getOperations.
@Override
@Deprecated
public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
if (!identifier.contains(ControllerContext.MOUNT)) {
final String errMsg = "URI has bad format. If operations behind mount point should be showed, URI has to " + " end with " + ControllerContext.MOUNT;
LOG.debug("{} for {}", errMsg, identifier);
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
final var entry = OperationsResourceUtils.contextForModelContext(modelContext(mountPoint), mountPoint);
return new NormalizedNodeContext(entry.getKey(), entry.getValue());
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class BrokerFacade method patchConfigurationDataWithinTransaction.
public PatchStatusContext patchConfigurationDataWithinTransaction(final PatchContext patchContext) throws Exception {
final DOMMountPoint mountPoint = patchContext.getInstanceIdentifierContext().getMountPoint();
// get new transaction and schema context on server or on mounted device
final EffectiveModelContext schemaContext;
final DOMDataTreeReadWriteTransaction patchTransaction;
if (mountPoint == null) {
schemaContext = patchContext.getInstanceIdentifierContext().getSchemaContext();
patchTransaction = this.domDataBroker.newReadWriteTransaction();
} else {
schemaContext = modelContext(mountPoint);
final Optional<DOMDataBroker> optional = mountPoint.getService(DOMDataBroker.class);
if (optional.isPresent()) {
patchTransaction = optional.get().newReadWriteTransaction();
} else {
// if mount point does not have broker it is not possible to continue and global error is reported
LOG.error("Http Patch {} has failed - device {} does not support broker service", patchContext.getPatchId(), mountPoint.getIdentifier());
return new PatchStatusContext(patchContext.getPatchId(), null, false, ImmutableList.of(new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier())));
}
}
final List<PatchStatusEntity> editCollection = new ArrayList<>();
List<RestconfError> editErrors;
boolean withoutError = true;
for (final PatchEntity patchEntity : patchContext.getData()) {
final PatchEditOperation operation = patchEntity.getOperation();
switch(operation) {
case CREATE:
if (withoutError) {
try {
postDataWithinTransaction(patchTransaction, CONFIGURATION, patchEntity.getTargetNode(), patchEntity.getNode(), schemaContext);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
LOG.error("Error call http Patch operation {} on target {}", operation, patchEntity.getTargetNode().toString());
editErrors = new ArrayList<>();
editErrors.addAll(e.getErrors());
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, editErrors));
withoutError = false;
}
}
break;
case REPLACE:
if (withoutError) {
try {
putDataWithinTransaction(patchTransaction, CONFIGURATION, patchEntity.getTargetNode(), patchEntity.getNode(), schemaContext);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
LOG.error("Error call http Patch operation {} on target {}", operation, patchEntity.getTargetNode().toString());
editErrors = new ArrayList<>();
editErrors.addAll(e.getErrors());
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, editErrors));
withoutError = false;
}
}
break;
case DELETE:
case REMOVE:
if (withoutError) {
try {
deleteDataWithinTransaction(patchTransaction, CONFIGURATION, patchEntity.getTargetNode());
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
LOG.error("Error call http Patch operation {} on target {}", operation, patchEntity.getTargetNode().toString());
editErrors = new ArrayList<>();
editErrors.addAll(e.getErrors());
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, editErrors));
withoutError = false;
}
}
break;
case MERGE:
if (withoutError) {
try {
mergeDataWithinTransaction(patchTransaction, CONFIGURATION, patchEntity.getTargetNode(), patchEntity.getNode(), schemaContext);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
LOG.error("Error call http Patch operation {} on target {}", operation, patchEntity.getTargetNode().toString());
editErrors = new ArrayList<>();
editErrors.addAll(e.getErrors());
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, editErrors));
withoutError = false;
}
}
break;
default:
LOG.error("Unsupported http Patch operation {} on target {}", operation, patchEntity.getTargetNode().toString());
break;
}
}
// if errors then cancel transaction and return error status
if (!withoutError) {
patchTransaction.cancel();
return new PatchStatusContext(patchContext.getPatchId(), ImmutableList.copyOf(editCollection), false, null);
}
// if no errors commit transaction
final CountDownLatch waiter = new CountDownLatch(1);
final FluentFuture<? extends CommitInfo> future = patchTransaction.commit();
final PatchStatusContextHelper status = new PatchStatusContextHelper();
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
status.setStatus(new PatchStatusContext(patchContext.getPatchId(), ImmutableList.copyOf(editCollection), true, null));
waiter.countDown();
}
@Override
public void onFailure(final Throwable throwable) {
// if commit failed it is global error
LOG.error("Http Patch {} transaction commit has failed", patchContext.getPatchId());
status.setStatus(new PatchStatusContext(patchContext.getPatchId(), ImmutableList.copyOf(editCollection), false, ImmutableList.of(new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, throwable.getMessage()))));
waiter.countDown();
}
}, MoreExecutors.directExecutor());
waiter.await();
return status.getStatus();
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class TestXmlBodyReaderMountPoint method checkExpectValueNormalizeNodeContext.
protected void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode, final NormalizedNodeContext nnContext, final QName qualifiedName) {
YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
final DataSchemaNode mountDataSchemaNode = modelContext(mountPoint).getDataChildByName(dataSchemaNode.getQName());
assertNotNull(mountDataSchemaNode);
if (qualifiedName != null && dataSchemaNode instanceof DataNodeContainer) {
final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(qualifiedName);
dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
} else {
assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
}
assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class BrokerFacadeTest method testPatchConfigurationDataWithinTransactionMountFail.
/**
* Negative test for Patch operation when mounted device does not support {@link DOMDataBroker service.}
* Patch operation should fail with global error.
*/
@Test
public void testPatchConfigurationDataWithinTransactionMountFail() throws Exception {
final PatchContext patchContext = mock(PatchContext.class);
final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
when(identifierContext.getMountPoint()).thenReturn(mountPoint);
// missing broker on mounted device
when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.empty());
when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
// assert not successful operation with error
assertNotNull(status.getGlobalErrors());
assertEquals(1, status.getGlobalErrors().size());
assertEquals(ErrorType.APPLICATION, status.getGlobalErrors().get(0).getErrorType());
assertEquals(ErrorTag.OPERATION_FAILED, status.getGlobalErrors().get(0).getErrorTag());
assertFalse("Patch operation should fail on mounted device without Broker", status.isOk());
}
use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.
the class BrokerFacadeTest method testPatchConfigurationDataWithinTransactionMount.
/**
* Test Patch method on mounted device with no data.
*/
@Test
public void testPatchConfigurationDataWithinTransactionMount() throws Exception {
final PatchContext patchContext = mock(PatchContext.class);
final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
when(patchContext.getData()).thenReturn(new ArrayList<>());
doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
// return mount point with broker
when(identifierContext.getMountPoint()).thenReturn(mountPoint);
when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.of(mountDataBroker));
when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
when(mountDataBroker.newReadWriteTransaction()).thenReturn(transaction);
doReturn(CommitInfo.emptyFluentFuture()).when(transaction).commit();
final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
// assert success
assertTrue("Patch operation should be successful on mounted device", status.isOk());
}
Aggregations