Skip to content

Commit

Permalink
Fixed ReportWriter issue (#137)
Browse files Browse the repository at this point in the history
ReportProcessor.processReport() is now only called with ReportTypes that
are supported.

# Checklist

The following aspects have been respected by the author of this pull
request, confirmed by both pull request assignee **and** reviewer:

* Adherence to coding conventions
  * [x] Pull Request Assignee
  * [x] Reviewer
* Adherence to javadoc conventions
  * [x] Pull Request Assignee
  * [x] Reviewer
* Changelog update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* README update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* config update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* SDCcc executable ran against a test device (if necessary)
  * [x] Pull Request Assignee
  * [x] Reviewer
  • Loading branch information
ben-Draeger authored Feb 22, 2024
1 parent bbdc6c3 commit eeeed0a
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- local address resolver doing a probe which may not be tolerated by some peers
- potential NullPointerException in DescriptionModificationUptPrecondition
- the test case for Glue:R0036_0 not accepting a SOAPFault as a valid answer for Subscribe messages
- ReportWriter.write() could be called with ReportTypes it did not support.

## [8.0.1] - 2023-09-13

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This Source Code Form is subject to the terms of the MIT License.
* Copyright (c) 2023 Draegerwerk AG & Co. KGaA.
* Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA.
*
* SPDX-License-Identifier: MIT
*/
Expand Down Expand Up @@ -53,8 +53,15 @@
import org.somda.sdc.biceps.consumer.access.RemoteMdibAccessImpl;
import org.somda.sdc.biceps.consumer.access.factory.RemoteMdibAccessFactory;
import org.somda.sdc.biceps.consumer.preprocessing.DuplicateContextStateHandleHandler;
import org.somda.sdc.biceps.model.message.AbstractAlertReport;
import org.somda.sdc.biceps.model.message.AbstractComponentReport;
import org.somda.sdc.biceps.model.message.AbstractContextReport;
import org.somda.sdc.biceps.model.message.AbstractMetricReport;
import org.somda.sdc.biceps.model.message.AbstractOperationalStateReport;
import org.somda.sdc.biceps.model.message.AbstractReport;
import org.somda.sdc.biceps.model.message.DescriptionModificationReport;
import org.somda.sdc.biceps.model.message.GetMdibResponse;
import org.somda.sdc.biceps.model.message.WaveformStream;
import org.somda.sdc.biceps.model.participant.Mdib;
import org.somda.sdc.biceps.model.participant.MdibVersion;
import org.somda.sdc.biceps.provider.preprocessing.DuplicateChecker;
Expand Down Expand Up @@ -249,11 +256,28 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory(
+ " same version has already been applied, and is expected behavior when e.g."
+ " descriptors update, as both a report for description and state will arrive.");
}
LOG.debug(
"Applying report with mdib version {}, type {}",
ImpliedValueUtil.getReportMdibVersion(report),
report.getClass().getSimpleName());
reportProcessor.processReport(report);
if (report instanceof WaveformStream
|| report instanceof AbstractMetricReport
|| report instanceof AbstractAlertReport
|| report instanceof AbstractOperationalStateReport
|| report instanceof AbstractComponentReport
|| report instanceof AbstractContextReport
|| report instanceof DescriptionModificationReport) {
LOG.debug(
"Applying report with mdib version {}, type {}",
ImpliedValueUtil.getReportMdibVersion(report),
report.getClass().getSimpleName());
reportProcessor.processReport(report);
} else {
// other reports do not modify the Mdib and hence cannot be passed into
// reportProcessor.processReport().
// simply ignore them.
LOG.debug(
"Ignoring report of type {} with MdibVersion {} as it is not expected to "
+ "change the Mdib anyway.",
report.getClass().getSimpleName(),
ImpliedValueUtil.getReportMdibVersion(report));
}
} catch (final Exception e) {
fail(e);
}
Expand Down Expand Up @@ -323,7 +347,28 @@ public HistorianResult uniqueEpisodicReportBasedHistoryUntilTimestamp(final Stri
"Applying report with mdib version {}, type {}",
ImpliedValueUtil.getReportMdibVersion(report),
report.getClass().getSimpleName());
reportProcessor.processReport(report);
if (report instanceof WaveformStream
|| report instanceof AbstractMetricReport
|| report instanceof AbstractAlertReport
|| report instanceof AbstractOperationalStateReport
|| report instanceof AbstractComponentReport
|| report instanceof AbstractContextReport
|| report instanceof DescriptionModificationReport) {
LOG.debug(
"Applying report with mdib version {}, type {}",
ImpliedValueUtil.getReportMdibVersion(report),
report.getClass().getSimpleName());
reportProcessor.processReport(report);
} else {
// other reports do not modify the Mdib and hence cannot be passed into
// reportProcessor.processReport().
// simply ignore them.
LOG.debug(
"Ignoring report of type {} with MdibVersion {} as it is not expected to "
+ "change the Mdib anyway.",
report.getClass().getSimpleName(),
ImpliedValueUtil.getReportMdibVersion(report));
}
} catch (final Exception e) {
fail(e);
}
Expand Down Expand Up @@ -479,35 +524,6 @@ public Stream<AbstractReport> getAllReportsWithLowerMdibVersion(
}
}

// TODO javadoc and maybe instead of getting all reports with lowertimestamp get the storage directly. So dont apply
// every report manually but provide a result
public Stream<AbstractReport> getAllReportsWithLowerTimestamp(
final String sequenceId,
@Nullable final BigInteger minimumMdibVersion,
final long maximumTimestamp,
final QName... bodyTypes) {
try {
final var messages =
messageStorage.getInboundMessagesByTimestampAndBodyType(sequenceId, maximumTimestamp, bodyTypes);

var iter = messages.getStream()
.sequential() // the stateful filter operation below is not thread-safe
.map(this::unmarshallReportKeepUUID);
if (minimumMdibVersion != null) {
iter = iter.filter(it ->
ImpliedValueUtil.getReportMdibVersion(it.getLeft()).compareTo(minimumMdibVersion) >= 1);
}
return filterReportDuplicates(iter).map(Pair::getLeft);
} catch (IOException e) {
final var errorMessage = "Error while trying to retrieve reports from storage";
LOG.error("{}: {}", errorMessage, e.getMessage());
LOG.debug("{}", errorMessage, e);
fail(e);
// unreachable, silence warnings
throw new RuntimeException(e);
}
}

/**
* Applies a report on a stored mdib.
*
Expand Down Expand Up @@ -535,11 +551,29 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin
+ " same version has already been applied, and is expected behavior when e.g."
+ " descriptors update, as both a report for description and state will arrive.");
}
LOG.debug(
"Applying report with mdib version {}, type {}",
ImpliedValueUtil.getReportMdibVersion(report),
report.getClass().getSimpleName());
reportProcessor.processReport(report);

if (report instanceof WaveformStream
|| report instanceof AbstractMetricReport
|| report instanceof AbstractAlertReport
|| report instanceof AbstractOperationalStateReport
|| report instanceof AbstractComponentReport
|| report instanceof AbstractContextReport
|| report instanceof DescriptionModificationReport) {
LOG.debug(
"Applying report with mdib version {}, type {}",
ImpliedValueUtil.getReportMdibVersion(report),
report.getClass().getSimpleName());
reportProcessor.processReport(report);
} else {
// other reports do not modify the Mdib and hence cannot be passed into
// reportProcessor.processReport().
// simply ignore them.
LOG.debug(
"Ignoring report of type {} with MdibVersion {} as it is not expected to "
+ "change the Mdib anyway.",
report.getClass().getSimpleName(),
ImpliedValueUtil.getReportMdibVersion(report));
}
return storage;
}

Expand Down
Loading

0 comments on commit eeeed0a

Please sign in to comment.