how to run application of spring batch using CommandLineJobRunner - spring-batch

I am creating an application using spring batch in which i am reading data from database and populate it in a file placed in D drive. My application does not have any errors but when i run my app, the console does not show any exceptions. In fact, the console is blank completely. I am not able to figure out if the app is actually getting executed or not.
I am using CommandLineJobRunner class for executing my job.
All your comments would be of great help.
Thanks

Reading data from database and populate it in a file placed in D drive
I am not able to figure out if the app is actually getting executed or not
Did you check the D drive? Is the file there? Was it populated as expected?
As a rule of thumb => write a test, that would make sure the file is there on the D drive, and that it has all the data expected. But as a start, you can just check it manually.
As to your question => The reason that you do not see anything, is most likely related to the logging misconfiguration.
If you use log4j / slf4j / etc, make sure to place a default (for a start) lo4j.properties / lo4j.xml file in your class path [e.g. root of your project]. If you use logback, make sure a logback.xml is in your classpath with (for a start) default configuration:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<logger name="org.root.level.package" level="debug"/>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

Did you develop your application using an IDE like Eclipse? If so, you might try debugging your code so that you can find out the reason why your application is not working as you expected it to be.

Related

Enable logging in Scalardb

How do I enable logging in Scalardb? Does it support logback? The ScalarDB logic in my application is throwing NullPointerException. I want to enable traces to understand where the problem might be.
Scalar DB uses slfj4 so various logging frameworks such as logback and log4j can be used.
https://github.com/scalar-labs/scalardb/blob/master/build.gradle
You need to build your application with such logging frameworks and configure
them properly.
For more information regarding slf4j, please refer to slf4j site.
This seem to work - <logger name="com.scalar" level="DEBUG" additivity="true"> <appender-ref ref="STDOUT"/> </logger>

log4j2 enabling debug for specific classes from environment variable

we are deploying a Java web application in JBoss 7.. 3 EAP.
We need to enable set the debug level for some specific classes (i.e. org.mycompany.mypackage).
As described here:
https://logging.apache.org/log4j/2.x/manual/configuration.html
just setting the environment variable
LOG4J_DEBUG
the log level is set to debug for whole system.
We wonder if there is a way to do it for specific classes/packages
Thank in advance
r.
The LOG4J_DEBUG environment variable does not enable debug logging for your application. It enables debug logging for the internals of Log4j 2. You set the default logging level for your applicaton by specifying a level on the Root Logger.
<Loggers>
<Root leve="info">
<Appender-Ref ref="Console"/>
</Root>
</Loggers>
You could change this so that the default level can be set from an environment variable by doing:
<Loggers>
<Root leve="${env:DEFAULT_LEVEL:-INFO}">
<Appender-Ref ref="Console"/>
</Root>
</Loggers>
The way to set the logging level for specific classes or Packages is to use a log4j configuration file as described in that same section. If you want the levels to be configured via environment variables then you can do that by doing something like:
<Logger name="com.mycorp.myservice.dao" level="${env:DAO_LEVEL:-WARN}"\>
This will use a default value of WARN if the environment variable named DAO_LEVEL is not present.

Eclipse not compiling .jsp file to _jsp.java and _jsp.class to Catalina

I have a file_B.jsp that is quite happily referenced to in the web.xml file
<action name="File_B" helper-class="name.of.helper.fileHelper">
<result name="default" web-page="/path/to/jsp/directory/file_B.jsp" screen-name="File B" screen-id="file_b" />
</action>
And it is safely within C:\Users\myDirectory\workspace\webusr\WebContent\WEB-INF\conf\sub\directory
[Trust me - there are several dozens of other jsp files mapped out this way :-) ]
But come runtime the browser throws up a 404.
I checked in the directories under Catalina and there is no file_B_jsp.java nor file_B_jsp.class.
Now, I know the mistake I made. I did a copy/pasta from file_A.jsp (80% of the code and structure is the same).
I did a simple test and had eclipse make a NewFile.jsp and changed web.xml to
<action name="File_B" helper-class="name.of.helper.fileHelper">
<result name="default" web-page="/path/to/jsp/directory/NewFile.jsp" screen-name="File B" screen-id="file_b" />
and sure enough the browser could find it. And there were a NewFile_jsp.java and NewFile_jsp.class inside Catalina
So I copied the code from the file_B.jsp. Deleted the file_B.jsp, had eclipse make a new file_B.jsp and pasted the code back in. Put web.xml back to pointing to the file_B.jsp. Stopped the server. Cleaned it and started it again.
But still the browser says 404, as there is still no file_B_jsp.java nor file_B_jsp.class.
I absolutely need to have file_B.jsp named "file_B.jsp". The whole system is based on this naming convention (decades old legacy at an electrical power company)
What file inside of eclipse needs to be manually edited? Or can I just make a new Tomcat server on the development machine?
It seems some inside eclipse was misaligned. Either building a new server or running yet another clean or switching out of the workspace and switching back into the workspace got eclipse to start compiling the file_B_jsp.java and file_B_jsp.class inside of Catalina.

ANT - speed improvements to existing script

I've built a set of generic deployment scripts which work great for the majority of our stuff. We've just however introduced our largest project to the setup and we're now finding times are far too varied and long for our liking.
The project size as it stands is 33,226files at a size of 400Mb plus. Times are currently taking between 13mins & 55mins (the last deployments time) depending on certain decisions made by ANT ( more below ).
In terms of the steps we currently do the following on x2 servers:-
1) ANT exports the project from SVN to both servers (made up of 3 parts).
2) It begins to shutdown the Web Services on Server #1.
This was the workaround we put in to stop Windows (2003) file locking failing the deployment.
3) ANT runs a "move" task on the current version (all parts) into temporary folders & moves the exported new version into its place.
4) Customised deployment code is run - one part being to move permanant features from the temporary folder into the new (i.e system files / Web Server Admin tools).
5) Delete the temporary folder.
6) Bring the Web Services back online
... rinse and repeat for the 2nd server steps 2 -> 6.
7) Save the ANT logs.
The main issue I'm having is that the ANT move task seems to make one of two decisions. It either:
a) Very simply swaps the versions over and moves on - taking a minute or two to handling it or
b) Goes through some kind of integrity check that it moves every file and folder from one place to the other. This floods the logs and takes a fair length of time to complete. Hence the 40+ minutes extra added on.
I can't find anything online that explains what causes ANT/OS to make that decision. Option A would be the ideal full-time situation.
I've tried copy, delete separately. I've tried the sync task. All seem to have this slow performance.
So really I'm asking what others with more experienced than me do with deployments of this scale. Do you have any hints / tips on how I could improve / speed this process up? Any ideas what the move is doing and if there is maybe a better way of doing all this?
Thanks a lot,
James
Thanks for the input all.
Just to add an answer to this one I've made the following changes which seem to have knocked a few minutes of it.
The first one was I've changed how the swapping happens off the back of the comment I mentioned before. It seems that ANT will try and do the following :-
"If the target directory does not already exist, Ant will do a rename of the directory. But if the target directory exists, it instead does a copy into the directory and delete from the source directory instead."
I think what's happened is ANT is trying to put the new version in before the old version has been completely removed. So instead of trying to rename the old I've now moved it into a temporary folder and deleted this at the end of the build. That seems to have stabled things on that front.
A few other things I've added to make ANT a bit smart :-)
1) I've set it up so ANT will not deploy any part of the build that is the same as what currently exists. So if part 1 is selected and that's on the Test environment already then it's removed from the build and SVN exports.
2) With the service shutdown / startup I've got ANT reading the response that comes back. If a service tells it that it's already started when calls, as sometimes happens if a service relies on others Windows automatically boots them up, then I've told ANT to hang around and move onto the next one.
Little steps like that seem to have improved things by a fair bit. I'd like to still try and get more out of them but these certaintly have given them a big step.
Thanks again,
James
even we faced this problem of auto deployment script taking longer time in our organization. So initially we had our script running in sequential like cleaning, stopping tomcats, updating, starting tomcats and making sure that all webapps are properly deployed.
So we have done following things like:
1. parallely cleaning and stopping all tomcats
2. do svn swith
3. parallely start all tomcats
4. make sure all webapps are deployed properly using jmx
here is the piece of code :
<target name="all_clean_parallel">
<parallel>
<antcall target="x1_clean"/>
<antcall target="x2_clean"/>
<antcall target="x3_clean"/>
</parallel>
</target>
<target name="all_start_parallel">
<parallel>
<antcall target="x1_start"/>
<antcall target="x2_start"/>
<antcall target="x3_start"/>
</parallel>
</target>
And the piece of code to check whether webapp is deployed propely or not with jmx help :
<macrodef name="mStatus">
<attribute name="aModule" />
<attribute name="aHost" default="localhost"/>
<attribute name="aPort" default="9012"/>
<attribute name="aMaxWait" default="240"/>
<attribute name="aTomcat" default=""/>
<attribute name="aState" default="1"/>
<sequential>
<waitfor maxwait="#{aMaxWait}" maxwaitunit="second" timeoutproperty="#{aHost}.#{aTomcat}.#{aModule}.#{aPort}.server.timeout" >
<and>
<jmx:equals
host="#{aHost}"
port="#{aPort}"
ref="#{aHost}.#{aTomcat}.#{aModule}.#{aPort}"
name="Catalina:j2eeType=WebModule,name=//localhost/#{aModule},J2EEApplication=none,J2EEServer=none"
attribute="state"
value="#{aState}"
/>
</and>
</waitfor>
<if>
<equals arg1="${#{aHost}.#{aTomcat}.#{aModule}.#{aPort}.server.timeout}" arg2="true" />
<then>
<var name="failBuild" value="true"/>
<echo message="*************************Host.Tomcat.Module = #{aHost}.#{aTomcat}.#{aModule} is not deployed into the tomcat" />
</then>
<else>
<echo message="#{aHost}.#{aModule} is deployed into the tomcat" />
</else>
</if>
</sequential>

Is there Any Way to Enforce RuntimeUnenhancedClasses in EE Configuration

I just spent a half hour debugging some new code that's not broken because I forgot to check (again!) my logs for this dreaded message:
WARN openjpa.Enhance - Creating subclass for ...
I'm running OpenJPA 2.1.0 inside an OpenEJB 3.2 snapshot build, Java 1.6.0_25, and Eclipse Helios. My entities are enhanced using the ant PCEnhancerTask.
My META-INF/openjpa.xml contains
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />
Is there anyway with this EE configuration to have OpenJPA enforce the RuntimeUnenhancedClasses option as it does in an SE configuration?
I suspect my 'real' problem stems from an Eclipse svn update that sometimes touches my JPA entity source, causing a build that overwrites my enhanced classes.
It's frustrating how often I run a unit test from the IDE that fails in some weird way, and I go digging through my code looking for a problem when all I need to do is run the enhancer.
Put the <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" /> META-INF/persistence.xml.
Looks like we're logging this action on debug level (maybe it should be info level), but OpenEJB will set that property to the default as it was in OpenJPA 1.x so that apps that worked with OpenEJB 3.1.x/OpenJPA 1.x will still work without modification in 3.2.x. If the property is already set in the persistence.xml it will never be overridden, so setting it there will have the effect you want.
Open to suggestions on how to save others in the same boat some time in the future. Seems either looking in the openjpa.xml file and seeing the property set already or issuing the log message on info would do it -- or both.
It sounds like for whatever reason your properties aren't being picked up when running in the container.
I have a number of possible solutions:
Try setting your properties in META-INF/persistence.xml. I assume you have these properties in the openjpa.xml file for a reason, but it might help us figure out where the real problem is.
Set -Dopenjpa.RuntimeUnenhancedClasses=false as a JVM property. This will apply to all PUs for a given JVM.
Move to a version of OpenJPA that is >= 2.0.0. RuntimeUnenhancedClasses was turned off as the default behavior in that release.