Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend logic that marks DistributionSet as complete #838

Merged

Conversation

smy4kor
Copy link
Contributor

@smy4kor smy4kor commented May 9, 2019

A DistributionSet (DS) can only be assigned to a target, when it is marked as complete.
A DS is marked as complete, when all requirements of the selected DS-Type are fulfilled.
A DS-Type determines which SoftwareModules (SM) of which SM-Type can be (optional) or have to be (required) contained.

When specifying a DS-Type that contains only optional SMs, a DS is marked as complete even without any SM assigned. This shall be changed.

A DS shall be only considered as complete, when:

SMs of the required SM-Types are assigned
At least one SM is assigned, in case all SM-Types are optional

@schabdo schabdo added this to the 0.3.0M3 milestone May 9, 2019
@hawkbit-bot
Copy link

SonarQube analysis reported 1 issue

  • MAJOR 1 major

Watch the comments in this conversation to review them.

DistributionSets without SoftwareModules shall not be marked as
complete, when no Software Module is assigned

Signed-off-by: Ravindranath Sandeep (INST-IOT/ESW-Imb) <Sandeep.Ravindranath@bosch-si.com>
@smy4kor smy4kor force-pushed the bugfix_incomplete_distribution_set branch from d353523 to fde5b94 Compare May 9, 2019 15:41
@schabdo schabdo modified the milestones: 0.3.0M3, 0.3.0M4 May 21, 2019
@@ -209,8 +210,12 @@ public void setKey(final String key) {

@Override
public boolean checkComplete(final DistributionSet distributionSet) {
return distributionSet.getModules().stream().map(SoftwareModule::getType).collect(Collectors.toList())
.containsAll(getMandatoryModuleTypes());
List<SoftwareModuleType> smTypes = distributionSet.getModules().stream().map(SoftwareModule::getType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be simplified:

final Set<SoftwareModuleType> mandatoryModuleTypes = getMandatoryModuleTypes();
return distributionSet.getModules().stream().map(SoftwareModule::getType).allMatch(type -> mandatoryModuleTypes.contains(type));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work in 1 specific case. When distributionSet.getModules() is empty and mandatoryModuleTypes is also empty then allMatch returns true. I just tried it.

I guess that allMatch assumes true and looks for a false. And in above, no iteration happens.

Copy link
Contributor

@a-sayyed a-sayyed Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, we can avoid that by adding:

        if (distributionSet.getModules().isEmpty()) {
            return false;
        }

before the stream call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asume you are referring to something like this:

 if (distributionSet.getModules().isEmpty()) {
            return false;
        }
        final Set<SoftwareModuleType> mandatoryModuleTypes = getMandatoryModuleTypes();
        return distributionSet.getModules().stream().map(SoftwareModule::getType)
                .allMatch(type -> mandatoryModuleTypes.contains(type));

This has a problem. It returns false even when I assign a software module to this type. In theory, this is a case where a DS type has no mandatory SM type. But it has a SM assigned. So it must be marked complete right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question, why do we need to change the original implementation?

Copy link
Contributor Author

@smy4kor smy4kor Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its for 2 reasons:

  • An incomplete DS should not be visible in deployment view.
  • If all software modules are removed from a given DS, then this DS should be marked incomplete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now I got it.
Maybe a good idea here is to introduce some unit tests? specially if a Model class has some logic like this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can maybe use the DistributionSetTypeManagementTest test, and test the different use cases where this method is called, here it's called in constructor, addModule, and removeModule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @stefbehl to add the test cases later as an improvement. The tests will be added in the next sprint.

@laverman laverman modified the milestones: 0.3.0M4, 0.3.0M5 Jun 7, 2019
@stefbehl stefbehl merged commit effb1e2 into eclipse:master Jul 1, 2019
@stefbehl stefbehl deleted the bugfix_incomplete_distribution_set branch July 1, 2019 08:24
@schabdo schabdo changed the title fix the logic that marks distributionSet as complete Extend logic that marks DistributionSet as complete Jul 29, 2019
AmmarBikic pushed a commit to bosch-io/hawkbit that referenced this pull request Oct 2, 2020
DistributionSets without SoftwareModules shall not be marked as complete, when no Software Module is assigned

Signed-off-by: Ravindranath Sandeep (INST-IOT/ESW-Imb) <Sandeep.Ravindranath@bosch-si.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants