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;
    }

Hibernate problem

We have met following problem in JUnit logs:
2012.11.28.22.42.45 ERROR hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table api_access (id_api_access integer not null, id_user integer not null, month_limit integer, api_key varchar(250), primary key (id_api_access)) type=InnoDB
2012.11.28.22.42.45 ERROR hibernate.tool.hbm2ddl.SchemaUpdate - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 1
Problem is that hibernate use invalid dialect. In hibernate configuration property hibernate.dialect should have value org.hibernate.dialect.MySQL5InnoDBDialect.

Tuesday, November 20, 2012

How to display code listing at blogger.com

I found few articles about adding syntax highlighting to blogger.com. All of them was based on Java Script library SyntaxHighlighter. All post describe old version of SyntaxHighlighter. Because I had to play little bit with here is short guide how to use it.
First go to blog administration interface. Than choose "Template" and "Edit HTML". Than adjust HTML template just before closing head tag as it's on next snippet:
<head>

    ...

    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>

    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>

    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>

</head>

Adjust HTML template before closing body tag as it's on next snippet:
</body>

   ...

   <script type='text/javascript'>
       SyntaxHighlighter.all()
   </script>

</body>

Now close and save HTML template. Open new post and switch to "HTML" editing. Write post with following content:
<pre class="brush:java">
public void hello(final String name){  
    System.out.println("Hello " + name);  
}
</pre>

If is everything fine than you should see:
public void hello(final String name){  
    System.out.println("Hello " + name);  
}


When XML or HTML have to be displayed and highlighted it have to written in post with HTML entities. To find proper tool try google search for "encode html to entities".

How to use public maven repository

Nexus started provide maven repository for free.  It's also for non-opensource projects.

All information how to participate are at https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-7a.1.POMandsettingsconfig

Carefully go through all steps. For releasing in staging repository you artifacts have to be signed. There is also nice article how to do that at https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven


Tuesday, October 16, 2012

How to access remote JVM with JMX console

JMX console allows monitor and partially adjust properties or running JVM. Accessed JVM could be at localhost where is JMX console started or could be remote. When you start JMX console by command jconsole following screen will appear:
When remote JVM should be accessed than remote JVM have to be ready for this.

Let's configure JVM to provide JMX remote access and protect access by name and password. JVM have to be started with following parameters:
JAVA_OPTS=${JAVA_OPTS}" -Dcom.sun.management.jmxremote=true"
JAVA_OPTS=${JAVA_OPTS}" -Dcom.sun.management.jmxremote.port=9999"
JAVA_OPTS=${JAVA_OPTS}" -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS=${JAVA_OPTS}" -Dcom.sun.management.jmxremote.password.file=/home/.../jmxremote.password"
JAVA_OPTS=${JAVA_OPTS}" -Dcom.sun.management.jmxremote.access.file=/home/../jmxremote.access"
JAVA_OPTS=${JAVA_OPTS}" "
export JAVA_OPTS

At remote machine, where will be JVM started have to be accessible file jmxremote.password:
#content of file jmxremote.password

honza somePassword
And file jmxremote.access
# content of file jmxremote.access

honza readwrite

When this files are created and accessible by JVM running with previously listed parameters than remote JVM should be accessible from console.


Possible problems

When following error occurs:
jmx error: Password file read access must be restricted

You have to adjust access rights for both files in this way:
chmod 600 jmxremote.access
chmod 600 jmxremote.password

Additional info

Nice description could be found in file password.properties which is part of JDK 1.5.
# password.properties

# Password file for Remote JMX API authentication. This file defines
# the different roles and their passwords.

# The file format for the password file is syntactically the same as
# the Properties file format. The syntax is described in the Javadoc
# for java.util.Properties.load.

# A typical password file has multiple lines, where each line is blank,
# a comment (like this one), or a password entry.

# A password entry consists of a role name and an associated password.
# The role name is any string that does not itself contain spaces or
# tabs. The password is again any string that does not contain spaces
# or tabs. Note that passwords appear in the clear in this file, so it
# is a good idea not to use valuable passwords.

# A given role should have at most one entry in this file. If a role
# has no entry, it has no access.
# If multiple entries are found for the same role name, then the last
# one is used.

# In a typical installation, this file can be read by anybody on the
# local machine, and possibly by people on other machines.
# For security, you should either restrict the access to this file,
# or specify another, less accessible file in the management config
# file as described above.

# Role and password used for authentication by the RMI connector in
# this example.
#
username password