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

Modularisation Part1 #1954

Merged
merged 33 commits into from
Mar 19, 2020
Merged

Modularisation Part1 #1954

merged 33 commits into from
Mar 19, 2020

Conversation

lucidd
Copy link
Member

@lucidd lucidd commented Feb 25, 2020

What does this PR change?

This PR contains the first batch of changes for modernizing our codebase better. This PR contains:

  • introducing an interface for all salt (non ssh) operations.

  • removing some low level salt calls with higher level methods.

  • marking future methods to be refined as deprecated.

  • first batch of salt dependent classes changed to have non static method and take dependencies though constructor.

  • pushing instantiation of of components to the entry points (xml rpc, router, salt reactor).

  • no logic should have been changed during this.

  • TODO: double check synchronized methods since multiple instances will change behavior here.

GUI diff

No difference.

  • DONE

Documentation

  • No documentation needed: no user visible changes

  • DONE

Test coverage

  • No tests: covered by existing tests

  • DONE

Links

Fixes #
Tracks # add downstream PR, if any

  • DONE

Changelogs

If you don't need a changelog check, please mark this checkbox:

  • No changelog needed

If you uncheck the checkbox after the PR is created, you will need to re-run changelog_test (see below)

Re-run a test

If you need to re-run a test, please mark the related checkbox, it will be unchecked automatically once it has re-run:

  • Re-run test "changelog_test"
  • Re-run test "backend_unittests_pgsql"
  • Re-run test "java_lint_checkstyle"
  • Re-run test "java_pgsql_tests"
  • Re-run test "ruby_rubocop"
  • Re-run test "schema_migration_test_oracle"
  • Re-run test "schema_migration_test_pgsql"
  • Re-run test "susemanager_unittests"
  • Re-run test "javascript_lint"
  • Re-run test "spacecmd_unittests"

@lucidd lucidd force-pushed the salt-interface-uyuni branch 6 times, most recently from 18646cb to 8efbf86 Compare March 2, 2020 16:18
@lucidd lucidd force-pushed the salt-interface-uyuni branch from 8efbf86 to c8cbafa Compare March 4, 2020 10:20
Copy link
Member

@renner renner left a comment

Choose a reason for hiding this comment

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

I have been deploying this patch and running some tests on a local environment, everything good so far! 👍

@lucidd lucidd force-pushed the salt-interface-uyuni branch 2 times, most recently from 79dc74a to fb7a408 Compare March 9, 2020 12:52
@github-actions github-actions bot added the API label Mar 10, 2020
@lucidd lucidd force-pushed the salt-interface-uyuni branch 2 times, most recently from e2c368a to b1922b2 Compare March 10, 2020 15:00
Copy link
Contributor

@admd admd left a comment

Choose a reason for hiding this comment

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

Thank you @lucidd for the effort. I like the direction we are going in. I have just left some small nitpicks, the rest looks good.

@lucidd lucidd force-pushed the salt-interface-uyuni branch from 7318c81 to 4b1f634 Compare March 12, 2020 12:45
Copy link
Contributor

@moio moio left a comment

Choose a reason for hiding this comment

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

Hey @lucidd, thanks for all the work here, I think it goes towards the right direction.

I left the bulk of comments inline, many are just nitpicks.

Final notes here: please review this PR's description, it seems like some sections were just marked DONE with no changes in the text (eg. "Test coverage" - I do not really see new Cucumber tests). In particular:

  • what is the intention when it comes to backporting this to downstream branches, is there any?
  • is there an intention to run the Cucumber testsuite against this branch before merging?

Look forward to see this merged soon.

* HandlerFactory prepopulated with unit test handlers.
* @return HandlerFactory for unit tests.
*/
public static HandlerFactory mockHandlers() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicks:

  • method name: as this returns a Factory (rather than a Collection of Handlers), shouldn't these be named something like getTestHandlerFactory/getDefaultHandlerFactory instead of mockHandlers/defaultHandlers?
  • shouldn't mockHandlers ideally live in unit test code only? Are there cons with that?

Copy link
Member Author

@lucidd lucidd Mar 17, 2020

Choose a reason for hiding this comment

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

I'm not really happy with the naming overall here after the refactoring but i did not want to make too many changes in this PR. I adopted the names you suggest for now but i guess a follow up PR can just focus on finding more fitting names for those classes.

Also moved the mocking to a test utils class.

public BaseHandler getHandler(String handlerName) {
return (BaseHandler)factory.getObject(handlerName);
public Optional<BaseHandler> getHandler(String handlerName) {
return Optional.ofNullable(handlers.get(handlerName));
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if returning Optional is the right choice here, as I see that basically all call sites immediately use get() on the result.

How about instead throwing an unchecked, descriptive Exception here that will result in something like "handlerName not found" in logs, instead of NPE, whenever handlers.get yields null - thereby avoiding the Optional wrapping?

What do you think, what would be pros and cons?

Copy link
Member Author

Choose a reason for hiding this comment

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

looking at the invocations there is really only 1 place that looks up a handler by user input. I added a orElseThrow there with a descriptive message. All the other invocations are either in tests or by using only values from getKeys. Optimally we should probably change this method to return a Set<Tuple2<String, BaseHandler>> so there is no need for an unsafe get.

@@ -330,6 +330,6 @@ else if (toolsChannel == null) {
* @param saltServiceIn The SaltService
*/
public void setSaltService(SaltService saltServiceIn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be dead code now (as it should be!)

Consider removing.

}

/**
* {@inheritDoc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I'd suggest to either have this tag on all public methods or just remove it everywhere.

@lucidd lucidd force-pushed the salt-interface-uyuni branch 2 times, most recently from 558a7b6 to 55681dd Compare March 17, 2020 10:45
@lucidd lucidd force-pushed the salt-interface-uyuni branch from 55681dd to 0f8f85a Compare March 19, 2020 16:35
@lucidd lucidd merged commit 0f8f85a into master Mar 19, 2020
@lucidd lucidd deleted the salt-interface-uyuni branch March 19, 2020 17:02
@moio
Copy link
Contributor

moio commented Mar 20, 2020

@lucidd is there any plan to downstream this to 4.1?

@lucidd
Copy link
Member Author

lucidd commented Mar 20, 2020

@moio its already backported to 4.0 https://github.com/SUSE/spacewalk/pull/11009 is there anything else to be done for 4.1?

@moio
Copy link
Contributor

moio commented Mar 20, 2020

@moio its already backported to 4.0 SUSE/spacewalk#11009 is there anything else to be done for 4.1?

Oops, my bad, I wrote 4.1 but meant 4.0. Good that's already backported, I had missed that PR. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants