Tuesday, January 22, 2013

How to get process id by port number at mac OSX

When some application listening on some port it could be problem to find out which application it is. On mac OSX is problem to get process id by port number because following command doesn't work:
netstat -p
Mac OSX 10.8 and earlier doesn't support switch '-p' in netstat command. However there is simple workaround. There is command 'lsof' which list open files and their process ids. You can list processes which are listening like this:
lsof -i | grep LISTEN
It's useful to see port number instead of service name running on such port. It's better to see :8080 instead of 'http-alt'. It could be done like this:
lsof -i -P | grep LISTEN

Friday, January 18, 2013

Hibernate inconsistent mapping problem

I met following exception during changing hibernate mapping. I'm using hibernate 3.2

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: cz.koroptev.cubiculus.core.model.Brick column: id_shape (should be mapped with insert="false" update="false")
 at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:605)
 at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:627)
 at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:645)
 at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:420)
 at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
 at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
 at cz.koroptev.cubiculus.core.services.impl.HibernateManagerServiceImpl.(HibernateManagerServiceImpl.java:28)
 ... 47 more
Problem was in inconsistent mapping of relations ship between objects 'Shape' and 'Brick'. Object 'Shape' contain set of bricks mapped as:
  <set name="bricks" lazy="true" order-by="id_brick" >
   <key column="id_shape" not-null="true" />
   <one-to-many class="Brick" />
  </set>
and 'Brick' contains mapping to 'Shape'
  <many-to-one name="shape" class="Shape" column="id_shape"
   foreign-key="brick_shape" not-null="false" />
Problem is that in first mapping is column 'id_shape' mapped as not-null="true" and in second is mapped as not-null="false". This lead to mentioned exception.

Tapestry 5 Exception - missing template

Following error appears in application production log:
TP-Processor19 2013.01.17.21.00.08 ERROR core.services.AppModule.extendedRequestExceptionHandler - Processing of request failed with uncaught exception: Embedded component(s) discussion, layout are defined within component class cz.koroptev.cubiculus.core.pages.buildinginstruction.BuildingInstructionLego (or a super-class of BuildingInstructionLego), but are not present in the component template (null).
org.apache.tapestry5.ioc.internal.OperationException: Embedded component(s) discussion, layout are defined within component class cz.koroptev.cubiculus.core.pages.buildinginstruction.BuildingInstructionLego (or a super-class of BuildingInstructionLego), but are not present in the component template (null).
 at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)
 at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)
 at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
 at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl.createAssembler(PageLoaderImpl.java:221)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl.getAssembler(PageLoaderImpl.java:211)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:183)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:178)
 at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
 at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
 at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl.loadPage(PageLoaderImpl.java:177)
 at $PageLoader_69b95d11058ab2.loadPage(Unknown Source)
 at org.apache.tapestry5.internal.services.PageSourceImpl.getPage(PageSourceImpl.java:104)
 at $PageSource_69b95d11058aa7.getPage(Unknown Source)
 at org.apache.tapestry5.internal.services.NonPoolingRequestPageCacheImpl.get(NonPoolingRequestPageCacheImpl.java:82)
 at $RequestPageCache_69b95d11058aa6.get(Unknown Source)
 at $RequestPageCache_69b95d11058aa3.get(Unknown Source)

Strange exception in other words say that it's not possible to find application template for some component. This problem shows just at production server not at my development machine. I'm using Tapestry 5 version 5.3.2.

After some time I found that problem was in directory naming. Templates in maven project are in directory 'src/main/webapps/buildinInstruction'. Name 'buildinInstruction' contains upper case I. When I change it to lower case problem disappears. Problem can't be reproduced at my machine because my Mac OS X use case insensitive file system.

Monday, December 10, 2012

HBase NoServerForRegionException

We have met following error:
12/12/10 12:17:57 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.
12/12/10 12:17:59 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.
12/12/10 12:18:01 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.
12/12/10 12:18:03 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.
12/12/10 12:18:06 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.
12/12/10 12:18:09 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.
12/12/10 12:18:14 INFO ipc.HBaseRPC: Server at xxxxx/172.22.245.48:60020 could not be reached after 1 tries, giving up.

ERROR: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for stats,,99999999999999 after 7 tries.
In other words it means that region server is not reachable. There is closes information about reason why it's not accessible. When you look in HBase master status server should be listed in dead regions server:

Solution is to check connection to region server. When it's correct restart HBase.

Monday, December 3, 2012

Doxia sink Exception

Following exception appears during site generating.
[INFO] Skipped "About" report, file "index.html" already exists for the English version.
[INFO] Generating "Distribution Management" report.
[WARNING] Deprecated API called - not org.apache.maven.doxia.sink.Sink instance and no SinkFactory available. Please update this plugin.
[INFO] Generating "Issue Tracking" report.
[WARNING] Deprecated API called - not org.apache.maven.doxia.sink.Sink instance and no SinkFactory available. Please update this plugin.
[INFO] Generating "Project Team" report.
[WARNING] Deprecated API called - not org.apache.maven.doxia.sink.Sink instance and no SinkFactory available. Please update this plugin.
[INFO] Generating "Dependency Management" report.
[WARNING] Deprecated API called - not org.apache.maven.doxia.sink.Sink instance and no SinkFactory available. Please update this plugin.
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] 1
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.ArrayIndexOutOfBoundsException: 1
 at org.apache.maven.doxia.module.xhtml.XhtmlSink.tableCell(XhtmlSink.java:791)
 at org.apache.maven.doxia.module.xhtml.XhtmlSink.tableHeaderCell(XhtmlSink.java:777)
 at org.apache.maven.reporting.AbstractMavenReportRenderer.tableHeaderCell(AbstractMavenReportRenderer.java:267)
 at org.apache.maven.reporting.AbstractMavenReportRenderer.tableHeader(AbstractMavenReportRenderer.java:356)
 at org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer.renderDependenciesForScope(DependencyManagementRenderer.java:203)
 at org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer.renderDependenciesForAllScopes(DependencyManagementRenderer.java:158)
 at org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer.renderSectionProjectDependencies(DependencyManagementRenderer.java:149)
 at org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer.renderBody(DependencyManagementRenderer.java:135)
 at org.apache.maven.reporting.AbstractMavenReportRenderer.render(AbstractMavenReportRenderer.java:79)
 at org.apache.maven.report.projectinfo.DependencyManagementReport.executeReport(DependencyManagementReport.java:112)
 at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:190)
 at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:144)
 at org.apache.maven.plugins.site.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:139)
 at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderModule(DefaultSiteRenderer.java:269)
 at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:101)
 at org.apache.maven.plugins.site.SiteMojo.renderLocale(SiteMojo.java:133)
 at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:100)
 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
 at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
 at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
 at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
 at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Problem is in maven project info plugin version. When version is 2.1 or lover problem disappears.

Plugin could be configured like this:
<project>
  ...
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.1</version>
        ...
      </plugin>
      ...
    </plugins>
  </reporting>
  ...
</project>

Root of the problem is in version of module doxia-sink-api module which is different in both versions of project info plugin version. In version 1.1 is doxia-sink-api-1.0-alpha-11 and in version 2.2 is doxia-sink-api-1.2.

When you have in pom file dependency on javadoc plugin which itself contains dependency on doxia-sink-api-1.0-alpha-11 than in runtime doxia-sink-api version in project-info-plugin is overridden by version of doxia-sink-api from java doc plugin. So another solution is to upgrade java doc plugin or maven site plugin.

Maven - slow generating "Dependencies" report.

sometimes we have encountered very slow generating of maven site at first glance process was slow down by generating dependency report.
[INFO] Skipped "About" report, file "index.html" already exists for the English version.
[INFO] Generating "Issue Tracking" report.
[INFO] Generating "Project Team" report.
[INFO] Generating "Dependency Management" report.
[INFO] Generating "Dependencies" report.
[ERROR] Unable to determine if resource cglib:cglib:jar:2.0.2:compile exists in http://repo1.maven.org/maven2
[ERROR] Unable to determine if resource commons-collections:commons-collections:jar:2.1.1:compile exists in http://repo1.maven.org/maven2
[ERROR] Unable to determine if resource commons-logging:commons-logging:jar:1.0.4:compile exists in http://repo1.maven.org/maven2
[ERROR] Unable to determine if resource cz.xxxxx.xxx.xxx:xxx:jar:1.0.0:compile exists in http://repo1.maven.org/maven2
Problem is in maven dependency plugin. Which try to locate in which repository is artefact located. When there is no valid internet connection (e.g. you use firewall) problem could appears.
If it's your problem there is few ways how to fix it:

1. add runtime property

dependency.locations.enabled=false in commando line like this:
mvn -Ddependency.locations.enabled=false site

2. change pom.xml

or in pom.xml in plugin configuration:
<project>
  ...
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <dependencyLocationsEnabled>
            false
          </dependencyLocationsEnabled>
        </configuration>
      </plugin>
      ...
    </plugins>
  </reporting>
  ...
</project>

3. Run site goal in offline mode

Even build site in offline mode like this:
mvn -o site
In that case you'll see following message in logs:
[WARNING] The parameter 'dependencyLocationsEnabled' is ignored in offline mode.

Wednesday, November 28, 2012

DbUnit teardown exception

Recently new problem appears in JUnit test logs:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Cannot truncate a table referenced in a foreign key constraint (`cub_test`.`api_month_stat`, CONSTRAINT `api_month_stat_access` FOREIGN KEY (`id_api_access`) REFERENCES `cub_test`.`api_access` (`id_api_access`))
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.Util.getInstance(Util.java:381)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
 at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:734)
 at com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:1006)
 at org.dbunit.database.statement.SimpleStatement.executeBatch(SimpleStatement.java:66)
 at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:122)
 at org.dbunit.operation.TruncateTableOperation.execute(TruncateTableOperation.java:84)
 at org.dbunit.AbstractDatabaseTester.executeOperation(AbstractDatabaseTester.java:179)
 at org.dbunit.AbstractDatabaseTester.onTearDown(AbstractDatabaseTester.java:82)
 at org.dbunit.DatabaseTestCase.tearDown(DatabaseTestCase.java:146)

When I tried to perform manually tear down operation truncate on table following problem appears:
mysql> truncate table api_access;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (`cub_test`.`api_month_stat`, CONSTRAINT `api_month_stat_access` FOREIGN KEY (`id_api_access`) REFERENCES `cub_test`.`api_access` (`id_api_access`))
mysql> 
Problem is closely described at http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html. In our case was solution to use "DELETE_ALL" as tear down operation. Tear down operation define what happen when test is executed. It could loo like:
    @Override
    protected DatabaseOperation getTearDownOperation() throws Exception {
 return DatabaseOperation.DELETE_ALL;
    }