-
Notifications
You must be signed in to change notification settings - Fork 55
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
[JBIDE-21590] Wait for server to reconcile project delete #995
Conversation
* @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) { |
There was a problem hiding this comment.
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.
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! |
50840bc
to
f5185a8
Compare
@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? |
@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. |
75d4579
to
f48a2cc
Compare
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); |
There was a problem hiding this comment.
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.
f48a2cc
to
83258e8
Compare
@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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This openshift/openshift-restclient-java@62cadab fixed that problem. I will update to add a check against null status to be safe. |
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. |
83258e8
to
1414eb4
Compare
} | ||
} | ||
} | ||
}while(!deleted || sleep > MAX_PROJECT_DELETE_DELAY); |
There was a problem hiding this comment.
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
?
1414eb4
to
1a6ed80
Compare
merged. |
tested it, it works for me. +1 |
Provides a wait for the server to reconcile the project deletion.
cc @mlabuda @fbricon @adietish