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
Add support for @ShouldThrowException(DefinitionException.class) #33
Add support for @ShouldThrowException(DefinitionException.class) #33
Conversation
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
br = new BufferedReader(new InputStreamReader(new FileInputStream(messagesFile))); | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
if (line.contains("CWWKZ0002E: An exception occurred while starting the application " + applicationName + ".") |
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 assume the text for this message is internationalized; do you think we an restrict this only to the error code without the message or find out what the message should be for the currently active locale?
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.
Good point.
while ((line = br.readLine()) != null) { | ||
if (line.contains("CWWKZ0002E: An exception occurred while starting the application " + applicationName + ".") | ||
&& (line.contains("org.jboss.weld.exceptions.DefinitionException") || line.contains("javax.enterprise.inject.spi.DefinitionException"))) { | ||
System.out.println("############DEBUG found CWWKZ0002E for application: " + applicationName); |
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.
We will have to change these to be written to the logger only in log.finest()
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.
OK.
} | ||
} catch (IOException e) { | ||
System.err.println("Exception while reading messages.log" + e.toString()); | ||
e.printStackTrace(); |
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 think it might make sense here to throw a DeploymentException in this case; or do you think this can be safely ignored and just logged?
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 think you are right.
br.close(); | ||
} catch (Exception e) { | ||
System.err.println("Exception while closing bufferedreader " + e.toString()); | ||
e.printStackTrace(); |
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 think it might make sense here to throw a DeploymentException in this case; or do you think this can be safely ignored and just logged?
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.
Again - I agree.
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 will add some more commits, thanks a lot for reviewing. :-)
@@ -856,6 +860,37 @@ public void undeploy(Descriptor descriptor) throws DeploymentException { | |||
|
|||
} | |||
|
|||
private void checkForDefinitionExceptions(String applicationName) | |||
{ | |||
String messagesFile = containerConfiguration.getWlpHome() + "/usr/servers/" + containerConfiguration.getServerName() + "/logs/messages.log"; |
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 log location seems to be defined by the attributes logDirectory
and messageFileName
or the respective properties as defined in the knowledge center at https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_logging.html
Do you think it would be easy to retrieve these? Alternatively we could also introduce a new configuration parameter for the wlp-managed-85 container implementation and rely on the developer to provide it.
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.
Good suggestion, I will investigate further. I also had another idea to explore if the DefinitionException is nested inside the client observed DeploymentException - and if that might be a better way to detect it. This is why I prefixed the PR as "WIP" as guided by the jboss jira web-page to stand for "Work In Progress" :-) The main reason why I posted the PR now is that I don't want Open Liberty development to be using changed versions of teh container internally without opening them up to upstream. But I agree that this PR should be improved.
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 think I can use the System property values (perhaps set in the bootstrap.properties file) of com.ibm.ws.logging.log.directory and com.ibm.ws.logging.message.file.name or, if these are not set, to use the default values. The default value for the logging directory is "By default, logDirectory is set to the LOG_DIR environment variable. The LOG_DIR environment variable is set to WLP_OUTPUT_DIR/serverName/logs by default." WLP_OUTPUT_DIR can be set in the environment. "If this environment variable is not specified, ${server.output.dir} is the same as ${server.config.dir}."
(https://www.ibm.com/support/knowledgecenter/en/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_admin_customvars.html)
Then....
server.config.dir is documented at https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_dirs.html as
wlp.install.dir/usr/${wlp.user.dir}/servers/<server_name>/[server specific]${server.config.dir}. Perhaps this will all look clearer in Java!
If might be clearer and less brittle over the long term to let Liberty work out the values and then use something like:
Object serverName = new InitialContext().lookup("com.ibm.ws.logging.message.file.name");
To get the resulting value but this may be hard to do from the container code so not sure I can find a way to do this.
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 also need to replace the Weld DefinitionException with the javax.enterprise.inject.spi.DefinitionException (its parent)
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
@gpoul Hi Gerhard do you have a preference for indentation. The existing file has a bit of a mixture and there is also https://github.com/jboss/ide-config#readme which has: I am happy to fit in with anything you like and happy just either My own slight preference would be to follow https://github.com/jboss/ide-config#readme |
@hutchig yes, we're indeed supposed to be following that guideline you found. If you're reformatting existing code, please just make sure to make that a separate commit or PR to make it easier to review, because otherwise everything gets marked as changed. |
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
@hutchig Can you please just confirm whether you've addressed everything you wanted to address? I'd like to get this merged soon. Oh, and sorry for the delay. :( |
Apologies I do have some more commits to push in and I am planned in to address these (by co-incidence) on Monday. I had missunderstood that container can pass back a wrapped exception that can be picked up by a @ShouldThrow. I have the new code:
(and have rebased to "liberty-managed" structure but just need to do some more testing ) |
that is perfectly fine; we were planning on making a final release this
month and I want your PR to be part of that.
…On Fri, Mar 9, 2018 at 4:15 PM Gordon Hutchison ***@***.***> wrote:
Apologies I do have some more commits to push in and I am planned in to
address these (by co-incidence) on Monday. I had missunderstood that
container can pass back a wrapped exception that can be picked up by a
@shouldthrow. I have the new code:
private void throwWrappedExceptionIfFoundInLog(String applicationName) throws IOException, DeploymentException
{
BufferedReader br = null;
String messagesFile = null;
try {
messagesFile = getLogsDirectory() + "/messages.log";
br = new BufferedReader(new InputStreamReader(new FileInputStream(messagesFile)));
String line;
while ((line = br.readLine()) != null) {
if (line.contains("CWWKZ0002") && line.contains("DefinitionException") && line.contains(applicationName)) {
log.finest("DefinitionException found in line" + line + " of file " + messagesFile );
DefinitionException cause = new javax.enterprise.inject.spi.DefinitionException(line);
throw new DeploymentException( "Failed to deploy " + applicationName + " on " + containerConfiguration.getServerName(), cause );
} else {
if ( line.contains("DeploymentException") && line.contains(applicationName)) {
log.finest("DeploymentException found in line" + line + " of file " + messagesFile );
javax.enterprise.inject.spi.DeploymentException cause = new javax.enterprise.inject.spi.DeploymentException(line);
throw new DeploymentException( "Failed to deploy " + applicationName + " on " + containerConfiguration.getServerName(), cause );
}
}
}
} catch (IOException e) {
log.warning("Exception while reading messages.log: " + messagesFile + e.toString());
throw e;
} finally {
if (br != null) {
br.close();
}
}
}
(and have rebased to "liberty-managed" structure but just need to do some
more testing )
If I was finshed by early next week would that be OK?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#33 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJ3WmgDhp6UF5Gx1VIIGrBc1XoADZYRks5tcpx0gaJpZM4Qg3Bl>
.
|
and thanks for the rebase, btw :)
…On Mon, Mar 12, 2018 at 7:45 AM Gerhard Poul ***@***.***> wrote:
that is perfectly fine; we were planning on making a final release this
month and I want your PR to be part of that.
On Fri, Mar 9, 2018 at 4:15 PM Gordon Hutchison ***@***.***>
wrote:
> Apologies I do have some more commits to push in and I am planned in to
> address these (by co-incidence) on Monday. I had missunderstood that
> container can pass back a wrapped exception that can be picked up by a
> @shouldthrow. I have the new code:
>
> private void throwWrappedExceptionIfFoundInLog(String applicationName) throws IOException, DeploymentException
> {
> BufferedReader br = null;
> String messagesFile = null;
>
> try {
> messagesFile = getLogsDirectory() + "/messages.log";
> br = new BufferedReader(new InputStreamReader(new FileInputStream(messagesFile)));
> String line;
> while ((line = br.readLine()) != null) {
> if (line.contains("CWWKZ0002") && line.contains("DefinitionException") && line.contains(applicationName)) {
> log.finest("DefinitionException found in line" + line + " of file " + messagesFile );
> DefinitionException cause = new javax.enterprise.inject.spi.DefinitionException(line);
> throw new DeploymentException( "Failed to deploy " + applicationName + " on " + containerConfiguration.getServerName(), cause );
> } else {
> if ( line.contains("DeploymentException") && line.contains(applicationName)) {
> log.finest("DeploymentException found in line" + line + " of file " + messagesFile );
> javax.enterprise.inject.spi.DeploymentException cause = new javax.enterprise.inject.spi.DeploymentException(line);
> throw new DeploymentException( "Failed to deploy " + applicationName + " on " + containerConfiguration.getServerName(), cause );
> }
> }
> }
> } catch (IOException e) {
> log.warning("Exception while reading messages.log: " + messagesFile + e.toString());
> throw e;
> } finally {
> if (br != null) {
> br.close();
> }
> }
> }
>
> (and have rebased to "liberty-managed" structure but just need to do some
> more testing )
> If I was finshed by early next week would that be OK?
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <#33 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAJ3WmgDhp6UF5Gx1VIIGrBc1XoADZYRks5tcpx0gaJpZM4Qg3Bl>
> .
>
|
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
I will remove the WIP prefix from the title of the PR and remove and add you as a reviewer when I have finished (this round of) my changes. |
…ation testing to do Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
…ception Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
@hutchig I think we're missing some pom.xml change as my local build fails with the same issue you can see in the automated builds that the "package javax.enterprise.inject.spi does not exist" |
I got it to work locally by adding this:
but I'd like to know which ones is the right version and dependency :) |
Otherwise I went through the changes and it looks good to me and I'll merge the change when we figured out the missing dependency. |
Apologies - yes I missed the pom as I had changed gradle co-ordinates for my personal version and forgot the extra dependency - I will just go and get the diff now. Apologies. |
I had
|
I will just do another commit now.... |
Another topic on my 'things to look at' list is the dependency
Under Java 9. Thanks so much for being the steward of this software which enables |
Signed-off-by: Gordon Hutchison <Gordon.Hutchison@gmail.com>
@hutchig feel free to open an issue on this project to track the Java 9 support work; unless there is a ticket in OpenLiberty, though... but you might also want to link them then... The only thing we use from the tools.jar is the Java Attach API; I think this might be useful, but it will require some investigation and testing: https://stackoverflow.com/questions/35240134/declare-maven-dependency-on-tools-jar-to-work-on-jdk-9 |
Thanks for the link Gerhard, I will investigate. |
Signed-off-by: Gordon Hutchison Gordon.Hutchison@gmail.com
Short description of what this resolves:
Attempts to pass wrapped Definition Exceptions to the client
Changes proposed in this pull request:
The log is examined and if wrapped DefinitionExceptions are found
they client is informed.
Fixes: #2153
@gpoul Gerhard - I think this is ready. Happy to make any other changes etc. :-)