import com.google.common.util.concurrent.SettableFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.ModifyAction;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
protected volatile boolean finished = false;
protected final boolean isLockAllowed;
- public AbstractWriteTx(final RemoteDeviceId id, final NetconfBaseOps netconfOps, final boolean rollbackSupport,
+ @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Behavior-only subclasses")
+ AbstractWriteTx(final RemoteDeviceId id, final NetconfBaseOps netconfOps, final boolean rollbackSupport,
final boolean isLockAllowed) {
- this.netOps = netconfOps;
+ netOps = netconfOps;
this.id = id;
this.rollbackSupport = rollbackSupport;
this.isLockAllowed = isLockAllowed;
return true;
}
+ // FIXME: only called from ctor which needs @SuppressDBWarnings. Refactor class hierarchy without this method (here)
protected abstract void init();
protected abstract void cleanup();
return;
}
- final DataContainerChild editStructure = netOps.createEditConfigStrcture(Optional.ofNullable(data),
+ final DataContainerChild editStructure = netOps.createEditConfigStructure(Optional.ofNullable(data),
Optional.of(ModifyAction.REPLACE), path);
editConfig(path, Optional.ofNullable(data), editStructure, Optional.empty(), "put");
}
return;
}
- final DataContainerChild editStructure = netOps.createEditConfigStrcture(Optional.ofNullable(data),
+ final DataContainerChild editStructure = netOps.createEditConfigStructure(Optional.ofNullable(data),
Optional.empty(), path);
editConfig(path, Optional.ofNullable(data), editStructure, Optional.empty(), "merge");
}
@Override
public synchronized void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
checkEditable(store);
- final DataContainerChild editStructure = netOps.createEditConfigStrcture(Optional.empty(),
+ final DataContainerChild editStructure = netOps.createEditConfigStructure(Optional.empty(),
Optional.of(ModifyAction.DELETE), path);
editConfig(path, Optional.empty(), editStructure, Optional.of(ModifyAction.NONE), "delete");
}
@Override
public void onSuccess(final RpcResult<Void> result) {
if (!result.isSuccessful()) {
- final Collection<RpcError> errors = result.getErrors();
resultFuture.setException(new TransactionCommitFailedException(
String.format("Commit of transaction %s failed", getIdentifier()),
- errors.toArray(new RpcError[errors.size()])));
+ result.getErrors().toArray(new RpcError[0])));
return;
}
final NetconfDocumentedException exception =
new NetconfDocumentedException(
id + ":RPC during tx returned an exception" + throwable.getMessage(),
+ // FIXME: add proper unmask/wrap to ExecutionException
new Exception(throwable),
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- ErrorSeverity.ERROR);
+ ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
transformed.setException(exception);
}
}, MoreExecutors.directExecutor());
return transformed;
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void extractResult(final List<DOMRpcResult> domRpcResults,
final SettableFuture<RpcResult<Void>> transformed) {
- DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
+ ErrorType errType = ErrorType.APPLICATION;
ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringBuilder msgBuilder = new StringBuilder();
boolean errorsEncouneterd = false;
- String errorTag = "operation-failed";
+ ErrorTag errorTag = ErrorTag.OPERATION_FAILED;
for (final DOMRpcResult domRpcResult : domRpcResults) {
if (!domRpcResult.getErrors().isEmpty()) {
errorsEncouneterd = true;
final RpcError error = domRpcResult.getErrors().iterator().next();
- final RpcError.ErrorType errorType = error.getErrorType();
- switch (errorType) {
- case RPC:
- errType = DocumentedException.ErrorType.RPC;
- break;
- case PROTOCOL:
- errType = DocumentedException.ErrorType.PROTOCOL;
- break;
- case TRANSPORT:
- errType = DocumentedException.ErrorType.TRANSPORT;
- break;
- case APPLICATION:
- errType = DocumentedException.ErrorType.APPLICATION;
- break;
- default:
- errType = DocumentedException.ErrorType.APPLICATION;
- break;
- }
- errSeverity = error.getSeverity().toNetconf();
+ errType = error.getErrorType();
+ errSeverity = error.getSeverity();
msgBuilder.append(error.getMessage());
msgBuilder.append(error.getInfo());
errorTag = error.getTag();
}
}
if (errorsEncouneterd) {
- final NetconfDocumentedException exception = new NetconfDocumentedException(id
- + ":RPC during tx failed. " + msgBuilder.toString(),
- errType,
- DocumentedException.ErrorTag.from(errorTag),
- errSeverity);
+ final NetconfDocumentedException exception = new NetconfDocumentedException(
+ id + ":RPC during tx failed. " + msgBuilder, errType, errorTag, errSeverity);
transformed.setException(exception);
return;
}