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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key cache lookup by project id and unique id #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

matt-richardson
Copy link
Contributor

To avoid duplicates when projects are copied.

Fixes #238.

Note: I haven't tested this, as I'm struggling to compile locally. (I'm also not a java developer, so there's a lot of things that I dont know that I dont know 馃槃).

To avoid duplicates when projects are copied.
/**
* A unique key, within this project.
* If a project is copied, then this key may be duplicated.
* Use <code>getCacheKey</code> as a globally unique id for this webhook
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that I wrote this comment made me wonder if we're too fixated on the current use case.
Should this be getGloballyUniqueKey instead? (or something similar)

Copy link
Member

Choose a reason for hiding this comment

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

I think if it's just contained within that class and used only as a key for the cache then the name is ok.
I am working through getting the tests running in the API, so haven't had a chance to build it yet.

I found another few places where we need to update references to the key. I'll push my branch once I get it working.

@netwolfuk
Copy link
Member

I thought there might be some other bit that needed work. I'll take a look later in the week.

image

@netwolfuk
Copy link
Member

netwolfuk commented Apr 7, 2024

BTW, this should work (I am using Java 8).
mvn test package

@matt-richardson
Copy link
Contributor Author

From what I can tell - these are to do with test setup. I didn't get very far with debugging though.

@netwolfuk
Copy link
Member

From what I can tell - these are to do with test setup. I didn't get very far with debugging though.

ah, ok. I'll pull the branch and run it up locally. Not sure when yet.

@matt-richardson
Copy link
Contributor Author

Just pushed a change - I think it should pass the tests.

(When I run it locally, I get a bunch of test failures similar to java.lang.IllegalStateException: @NotNull method webhook/teamcity/settings/entity/WebHookTemplateEntity.getTemplateDescription must not return null. Not sure why it's doing that for me, and not you?)

@netwolfuk
Copy link
Member

netwolfuk commented Apr 8, 2024

Yep, that's fixed all the core tests. Just the REST api ones failing now. But don't spend time on that, as I am in the middle of migrating all that code to rest-api-legacy project.

@matt-richardson
Copy link
Contributor Author

I'm unblocked now - I manually modified the id's in the config, and after restarting teamcity, all the webhooks are showing up in the right place.

Now, it's only future project copies that I'm thinking about, but not expecting that to happen too soon, so no rush.

Good luck with the legacy fun :)

@netwolfuk
Copy link
Member

I'm really sorry. I didn't realise you were blocked by this. D'oh!

@matt-richardson
Copy link
Contributor Author

No stress - I was only "blocked" until I found how the code worked, and even then, it wasn't a biggie - if push came to shove, I could've edited the config directly.

@netwolfuk
Copy link
Member

I thought I had implemented a partial work around where a "save" of the webhook forces a reload on that project's webhooks, but I still have the code here and it never made it into a release.

This would have allowed you to edit plugin-settings and then create a new webhook would would've fixed the ids in the cache map.

But now we know the actual reason for that issue, so that's a win :-)

@@ -53,6 +53,10 @@ public void setup() throws JDOMException, IOException {

projectSettings = new WebHookProjectSettings();
projectSettings.readFrom(ConfigLoaderUtil.getFullConfigElement(new File("src/test/resources/project-settings-test-elastic.xml")).getChild("webhooks"));
projectSettings.getWebHooksConfigs().forEach(c -> {
Copy link
Member

Choose a reason for hiding this comment

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

There is a murky issue with old versions of ASM (which is pulled in by old versions of Jersey) when it comes to Java8 features.
I needed to convert this code to a Java 7 for loop, otherwise the code compiles with a byte code signature of Java8 and ASM can't load it.

I really need to convert to newer ASM lib since tcWebHooks 2.0.0 is now released and I no longer support TeamCity 9 (which ran on Java7).

tcWebHooks 2.0.0 supports 2019.1 and newer only.

Copy link
Member

Choose a reason for hiding this comment

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

@netwolfuk
Copy link
Member

I have it compiled and running. Copying a project works, but does not refresh the cache.
If I edit and save or create a new webhook, the the old webhooks that were copied over show up. However, the ID is the same and so items in the history will be misleading. Eg, if you click the right most icon in a history page, it will show two webhooks since they have the same ID.

I'll look further into the copy event that Pavel mentioned, and look to do a regenerate of the UniqueId on Project copy.

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

Successfully merging this pull request may close these issues.

Webhooks not showing when project is copied
2 participants