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

refactor(web): Convert web module to Java #841

Merged
merged 26 commits into from
May 28, 2020

Conversation

robzienert
Copy link
Member

When you're on a roll, you're on a roll.

This is the entire module.

return serviceAccountDAO.all();
}

ServiceAccount createServiceAccount(ServiceAccount serviceAccount) {
public ServiceAccount createServiceAccount(ServiceAccount serviceAccount) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These two methods were being accessed despite being out of scope.

@@ -36,6 +36,7 @@ dependencies {
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "com.netflix.spinnaker.fiat:fiat-api:$fiatVersion"
implementation "com.netflix.spinnaker.fiat:fiat-core:$fiatVersion"
implementation "com.netflix.spinnaker.kork:kork-artifacts"
Copy link
Member Author

Choose a reason for hiding this comment

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

Groovy was referencing artifacts it didn't have access to.

UntypedUtils.setProperty(notification, it, UntypedUtils.getProperty(global, it));
}
});
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@ajordens Here's the global notifications. Maybe we can delete?

(a, b) ->
SearchUtils.score(b, normalizedAttributes)
- SearchUtils.score(a, normalizedAttributes))
.collect(Collectors.toCollection(LinkedHashSet::new));
Copy link
Member Author

Choose a reason for hiding this comment

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

I broke this monstrosity up into a few blocks and methods. I'm happy to break it up further.

Copy link
Contributor

Choose a reason for hiding this comment

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

yikes... but yeah it looks like you captured the original essencé d'groovy - nice job

if (!UntypedUtils.hasProperty(notification, it)) {
UntypedUtils.setProperty(notification, it, new ArrayList<>());
}
UntypedUtils.setProperty(notification, it, UntypedUtils.getProperty(global, it));
Copy link
Contributor

@cfieber cfieber May 28, 2020

Choose a reason for hiding this comment

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

I think this needs to be:

Suggested change
UntypedUtils.setProperty(notification, it, UntypedUtils.getProperty(global, it));
((List<?>) UntypedUtils.getProperty(notification, it)).addAll((List<?>) UntypedUtils.getProperty(global, it)));

Otherwise it will replace the list instead of adding to it

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops. Right you are.

Copy link
Contributor

@ezimanyi ezimanyi left a comment

Choose a reason for hiding this comment

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

This is great! 💯 🏅 🏆 ☕


Set<Application> results =
new HashSet<>(
pageSize == null
Copy link
Contributor

Choose a reason for hiding this comment

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

This ternary looks inverted

@RequestParam(value = "prefix", required = false) final String prefix,
@RequestParam(value = "ids", required = false) Collection<String> ids,
@RequestParam(value = "refresh", required = false) Boolean refresh) {
if (prefix == null && (ids != null && !ids.isEmpty())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might be incorrect; we'll throw an exception here if prefix == null but ids is a non-empty collection. Should this be prefix == null && ( ids == null || ids.isEmpty())?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we do the same check on ids later too, maybe we should just do an Optional.ofNullable(ids).orElseGet(ArrayList::new) at the beginning to simplify 🤷

@RequestParam(value = "pageSize", required = false) Integer pageSize,
@RequestParam Map<String, String> params) {
params.remove("pageSize");
Set<Project> projects =
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this cast safe? Seems like we should either have the interface .all() return a Set or convert the result of projectDao.all() to a Set instead of just casting.

Copy link
Member Author

Choose a reason for hiding this comment

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

IntelliJ didn't complain about it so I figured it would be OK, but I've wrapped projectDAO.all() into new HashSet<>(projectDAO.all()) to be safe. Since all() is defined by ItemDAO<T>, I'm not comfortable in changing the signature of the method without affecting other places.

COMMA_SPLITTER.splitToList(normalizedAttributes.get("applications"));
// TODO(rz): LOL converting Groovy with elvis operators everywhere. :grimacing:
// Do you know what's going on here? I certainly don't. Good thing there's tests?
items =
Copy link
Contributor

Choose a reason for hiding this comment

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

😭

new FuzzySearch(project, it.getKey(), it.getValue()))))
.collect(Collectors.toSet()));

return new TreeSet<>(items)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to make a TreeSet here instead of just doing items.stream()?

Copy link
Member Author

Choose a reason for hiding this comment

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

The signature was a Set, although I don't know why. The code was doing sorting on it, so I needed some implementation of SortedSet, which landed me on TreeSet - maybe this is the wrong implementation.

Alternatively I could change all of this to a List and just distinct on the stream before doing the sort? Kinda like this instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I totally understand the result being a LinkedHashSet as we do seem to need it sorted...though I kind of like your idea better of making it a List with distinct.

I meant more that I think the following would be equivalent:

items.stream().sort()
new TreeSet<>(items).stream().sort()

so I wasn't sure it was wrapped right before calling .stream().

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh boy, yeah ok, now I see what you're saying I missed the LinkedHashSet 🤦 .

This is now a List.

if (p1.getIndex() == null && p2.getIndex() != null) {
return 1;
}
if (!p1.getIndex().equals(p2.getIndex())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this introduces a new NPE if both indexes are null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha. Right you are. I guess this NPE has existed since... 2014. Will fix, good catch.

@PathVariable(value = "application") String application,
@RequestParam(required = false, value = "refresh", defaultValue = "true") boolean refresh) {
List<Pipeline> pipelines =
(List<Pipeline>) pipelineDAO.getPipelinesByApplication(application, refresh);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this cast safe? If all implementations really do return this as a List should we change the type on the interface? If not should we create a list from the collection here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to changing the interface to a list, but I think I'll try evaluating / taking that on as part of a separate PR.

Copy link
Contributor

@cfieber cfieber left a comment

Choose a reason for hiding this comment

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

had one comment that I think is different behavior but otherwise LGTM, thanks again for doing this

can we update any of the gradle builds to disable the compileGroovy task for the modules that have been cut over at this point?

@robzienert
Copy link
Member Author

@cfieber Taking a pass to remove compileGroovy is on the agenda once all this is merged!

@robzienert robzienert added the ready to merge Approved and ready for merge label May 28, 2020
@mergify mergify bot added the auto merged label May 28, 2020
@clanesf
Copy link

clanesf commented Sep 25, 2020

Thank you for the fix in Application create to actually check if fiat is enabled before attempting to make the role/sync call! Yet another reason to upgrade to 1.21!

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.

5 participants