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

[JBIDE-21590] Wait for server to reconcile project delete #995

Conversation

jcantrill
Copy link
Contributor

Provides a wait for the server to reconcile the project deletion.

cc @mlabuda @fbricon @adietish

* @param project
* @param callIfNotOK - A callback to execite if the job does not return OK status
*/
public static DeleteResourceJob createDeleteProjectJob(final IProject project, Runnable callIfNotOK) {
Copy link
Member

Choose a reason for hiding this comment

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

the Runnable "callIfNotOK" looks abit redundant/duplicate to what IJobChangeListener offers: The one that creates the delete job could attach a job change listener to it and implement #done, inspecting the IStatus that's in the IJobChangeEvent he'll get.

@adietish
Copy link
Member

adietish commented Mar 2, 2016

other than my comments, code seems legit. It even handles multiple invocation from context menu (adapter is set to 'deleting' while it's deleting) and adds tests. Nice!

@jcantrill jcantrill force-pushed the 21590_project_delete_reboot branch from 50840bc to f5185a8 Compare March 2, 2016 21:12
@jcantrill
Copy link
Contributor Author

@adietish made an update but I see THIS event sometimes doesnt work based on the new logic. I'm thinking it would actually be better to have a blocking progress modal that times out after a max time. I noticed another situation the disabled delete doesnt address where i was able to 'expand' a deleted project which threw a different exception. WDYT about making delete project 'blocking' from the context menu?

@adietish
Copy link
Member

adietish commented Mar 3, 2016

@jcantrill Do you know why exactly it doesnt work? Frequently this happens if the listeners gets attached after the job was launched and teminates. But I dont see this being true for your code. Maybe you should add brk-points to the other methods (#sleeping, #scheduled, #awake etc.) to further understand when this wont get into #done.
I believe that the job should terminate itself for a given timeout, at least that seems legit to me in terms of separations of concerns (the thread terminates itself vs gets terminated) - this is imho also the logic in jdk with the deprecation of Thread#stop.
For the case where throwing a different exception was not preventing a concurrent deleting thread I'd think that we then should maybe catch all exceptions?
Blocking seems like a bad idea - but maybe I get you wrong - since this would also block the UI thread, something we want to avoid.
Maybe we should discuss this in more details in bj?

@jcantrill jcantrill force-pushed the 21590_project_delete_reboot branch 3 times, most recently from 75d4579 to f48a2cc Compare March 3, 2016 21:12
@jcantrill
Copy link
Contributor Author

Updated to reduce contention points of using sync blocks.

@@ -88,27 +86,26 @@ public void connectionChanged(IConnection connection, String property, Object ol
&& (oldValue instanceof List)
&& (newValue instanceof List)) {
IOpenShiftConnection openshiftConnection = (IOpenShiftConnection) connection;
String key = getCacheKey(openshiftConnection);
Set<IProjectAdapter> adapters = getOrCreateEntry(key);
Set<IProjectAdapter> adapters = getCacheFor(openshiftConnection);
Copy link
Member

Choose a reason for hiding this comment

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

i see a possible race-condition where 2 threads concurrently query the cache and create entries here since only #getCacheFor is locking the cache but the latter #createEntry isnt.

@jcantrill jcantrill force-pushed the 21590_project_delete_reboot branch from f48a2cc to 83258e8 Compare March 3, 2016 21:54
@adietish
Copy link
Member

adietish commented Mar 3, 2016

@jcantrill looks good now since querying cache and creating a new entry is atomic. Will test tomorrow

sleep = sleep + PROJECT_DELETE_DELAY;
} catch (InterruptedException e1) {
} catch(OpenShiftException ex) {
if(ex.getStatus() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

testing this I see the DeleteResourceJob enlessly looping.
When breaking in I see ex.getStatus() being null it thus wont stop waiting based on the 404 or 403. Furthermore the sleep counter would be increased after Thread.sleep(), but the exception occurrs right after conn.getResource(project), skipping the sleep and sleepcounter increase. The thread will thus loop endlessly given it will never reach the MAX_PROJECT_DELETE_DELAY value.

"ex" is com.openshift.restclient.authorization.ResourceForbiddenException, the message is 'User "adietish@redhat.com" cannot get projects in project "testproj"', status is null.

Copy link
Member

Choose a reason for hiding this comment

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

The actual reason for the missing status is an issue in the client lib:

DefaultClient#createOpenShiftException()

            if(status.getCode() == STATUS_FORBIDDEN) {
                if(StringUtils.isNotBlank(token)) { //truly forbidden
                    return new ResourceForbiddenException(status.getMessage(), e);

The resourceForbiddenException that is being constructed simply wont add the status, it only adds the message.

@jcantrill
Copy link
Contributor Author

This openshift/openshift-restclient-java@62cadab fixed that problem. I will update to add a check against null status to be safe.

@jcantrill
Copy link
Contributor Author

There is a different issue in the total sleep never is advanced because of the exception so you never reach the max value. I will fix here.

@jcantrill jcantrill force-pushed the 21590_project_delete_reboot branch from 83258e8 to 1414eb4 Compare March 4, 2016 14:25
}
}
}
}while(!deleted || sleep > MAX_PROJECT_DELETE_DELAY);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldnt the condition to stop retrying be:

!deleted && sleep < MAX_PROJECT_DELETE_DELAY

?

@jcantrill jcantrill force-pushed the 21590_project_delete_reboot branch from 1414eb4 to 1a6ed80 Compare March 4, 2016 14:46
@jcantrill
Copy link
Contributor Author

merged.

@jcantrill jcantrill closed this Mar 4, 2016
@adietish
Copy link
Member

adietish commented Mar 4, 2016

tested it, it works for me. +1

@jcantrill jcantrill deleted the 21590_project_delete_reboot branch March 4, 2016 15:25
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.

None yet

2 participants