summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
9d6b3ed)
Fix assumptions which are not in-line with API documentation,
i.e. that getRevision() will return a magic string and never null.
Once the users are fixed, getRevision() will return null as per
its defined contract.
Change-Id: Ia7d45325d9f45ff6dc237461fc4ea4d45901675a
Signed-off-by: Robert Varga <rovarga@cisco.com>
private static final Logger LOG = LoggerFactory.getLogger(NetconfDevice.class);
private static final Logger LOG = LoggerFactory.getLogger(NetconfDevice.class);
- public static final Function<QName, SourceIdentifier> QNAME_TO_SOURCE_ID_FUNCTION = new Function<QName, SourceIdentifier>() {
- @Override
- public SourceIdentifier apply(final QName input) {
- return RevisionSourceIdentifier
- .create(input.getLocalName(), Optional.fromNullable(input.getFormattedRevision()));
- }
- };
+ public static final Function<QName, SourceIdentifier> QNAME_TO_SOURCE_ID_FUNCTION =
+ input -> RevisionSourceIdentifier.create(input.getLocalName(),
+ Optional.fromNullable(input.getFormattedRevision()));
protected final RemoteDeviceId id;
private final boolean reconnectOnSchemasChange;
protected final RemoteDeviceId id;
private final boolean reconnectOnSchemasChange;
private void registerToBaseNetconfStream(final NetconfDeviceRpc deviceRpc, final NetconfDeviceCommunicator listener) {
// TODO check whether the model describing create subscription is present in schema
// Perhaps add a default schema context to support create-subscription if the model was not provided (same as what we do for base netconf operations in transformer)
private void registerToBaseNetconfStream(final NetconfDeviceRpc deviceRpc, final NetconfDeviceCommunicator listener) {
// TODO check whether the model describing create subscription is present in schema
// Perhaps add a default schema context to support create-subscription if the model was not provided (same as what we do for base netconf operations in transformer)
- final CheckedFuture<DOMRpcResult, DOMRpcException> rpcResultListenableFuture =
- deviceRpc.invokeRpc(NetconfMessageTransformUtil.toPath(NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME), NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT);
+ final CheckedFuture<DOMRpcResult, DOMRpcException> rpcResultListenableFuture = deviceRpc.invokeRpc(
+ NetconfMessageTransformUtil.toPath(NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME),
+ NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT);
final NotificationHandler.NotificationFilter filter = new NotificationHandler.NotificationFilter() {
@Override
final NotificationHandler.NotificationFilter filter = new NotificationHandler.NotificationFilter() {
@Override
}
private Collection<QName> getQNameFromSourceIdentifiers(final Collection<SourceIdentifier> identifiers) {
}
private Collection<QName> getQNameFromSourceIdentifiers(final Collection<SourceIdentifier> identifiers) {
- final Collection<QName> qNames = Collections2.transform(identifiers, new Function<SourceIdentifier, QName>() {
- @Override
- public QName apply(final SourceIdentifier sourceIdentifier) {
- return getQNameFromSourceIdentifier(sourceIdentifier);
- }
- });
+ final Collection<QName> qNames = Collections2.transform(identifiers, this::getQNameFromSourceIdentifier);
if (qNames.isEmpty()) {
LOG.debug("{}: Unable to map any source identifiers to a capability reported by device : {}", id, identifiers);
if (qNames.isEmpty()) {
LOG.debug("{}: Unable to map any source identifiers to a capability reported by device : {}", id, identifiers);
private QName getQNameFromSourceIdentifier(final SourceIdentifier identifier) {
// Required sources are all required and provided merged in DeviceSourcesResolver
for (final QName qname : deviceSources.getRequiredSourcesQName()) {
private QName getQNameFromSourceIdentifier(final SourceIdentifier identifier) {
// Required sources are all required and provided merged in DeviceSourcesResolver
for (final QName qname : deviceSources.getRequiredSourcesQName()) {
- if(qname.getLocalName().equals(identifier.getName()) == false) {
+ if (!qname.getLocalName().equals(identifier.getName())) {
- if(identifier.getRevision().equals(SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION) &&
- qname.getRevision() == null) {
- return qname;
- }
-
- if (qname.getFormattedRevision().equals(identifier.getRevision())) {
+ final String rev = getNullableRev(identifier);
+ if (rev == null) {
+ if (qname.getRevision() == null) {
+ return qname;
+ }
+ } else if (qname.getFormattedRevision().equals(rev)) {
// return null since we cannot find the QName, this capability will be removed from required sources and not reported as unresolved-capability
return null;
}
// return null since we cannot find the QName, this capability will be removed from required sources and not reported as unresolved-capability
return null;
}
+
+ private String getNullableRev(final SourceIdentifier identifier) {
+ final String rev = identifier.getRevision();
+ return rev == null || SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION.equals(rev) ? null : rev;
+ }
final String moduleName = sourceIdentifier.getName();
// If formatted revision is SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION, we have to omit it from request
final String moduleName = sourceIdentifier.getName();
// If formatted revision is SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION, we have to omit it from request
- final String formattedRevision = sourceIdentifier.getRevision().equals(SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION) ? null : sourceIdentifier.getRevision();
+ final String badRev = sourceIdentifier.getRevision();
+ final String formattedRevision = SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION.equals(badRev) ? null : badRev;
final Optional<String> revision = Optional.fromNullable(formattedRevision);
final NormalizedNode<?, ?> getSchemaRequest = createGetSchemaRequest(moduleName, revision);
final Optional<String> revision = Optional.fromNullable(formattedRevision);
final NormalizedNode<?, ?> getSchemaRequest = createGetSchemaRequest(moduleName, revision);