segunda-feira, 30 de janeiro de 2017

Teiid 9.1.2 - Create an UDAF (Teiid User Defined Aggregate Support)

Here are the steps necessary to create an UDAF in Teiid 9.1.2.

Create UDAF

pom.xml

Add this to pom (probably you have to add the jar yourself to your repository. Look for the jar in /modules/system/layers/dv/org/jboss/teiid/api/main/teiid-api-9.1.2.jar. See http://javari.blogspot.pt/2009/10/instalar-um-jar-no-repositorio-maven.html):

<dependencies>
    <dependency>
        <groupId>org.jboss.teiid</groupId>
        <artifactId>teiid-api</artifactId>
        <version>9.1.2</version>
    </dependency>
</dependencies>


Implement UDAF


package my.udaf;

import org.teiid.CommandContext;
import org.teiid.UserDefinedAggregate;


public class MyAggregateFunction implements UserDefinedAggregate{


  public MyAggregateFunction(){

    reset();
  }

  public void addInput(Long val, char separator){

    // Use val (in this case Long) in someway. Example: add it to a list.
  }

  @Override  public void reset(){

    group = new ArrayList<>();
    separator = null;
  }

  @Override  public String getResult(CommandContext commandContext){
    
    // do your work. Use all inputs and return them as you want.
  }
}


Create Artifact

mvn clean install

Create Module

Here are the steps necessary to create a module in Teiid 9.1.2:

Run the following in the server console (in /bin):

./jboss-cli.sh --connect

and run the following commands:

module add --name=module_name --resources=udaf-1.0.jar --dependencies=org.jboss.teiid.api

:reload


Where:
  • module_name  - Name of th module. We will use this name in vdb's;
  • udaf-1.0.jar - Jar being added
  • org.jboss.teiid.api - The udaf jar depends of this module.

Use UDAF in a VDB


<vdb name="MyVdb" version="1">
<description>My VDB</description>


<property name ="lib" value ="module_name "></property>

           <model name="MyAggregateFunction" type="VIRTUAL">
         <metadata type="DDL"><![CDATA[

CREATE VIRTUAL FUNCTION MyAggregateFunction(val long, separator char) RETURNS string OPTIONS (JAVA_CLASS 'my.udaf.MyAggregateFunction', JAVA_METHOD 'addInput', AGGREGATE 'true', "NULL-ON-NULL" 'true', "ALLOWS-DISTINCT" 'true');

]]>
</metadata>
    </model>
   
   

...

<model name="CountryServiceList" type="VIRTUAL"> <metadata type="DDL"><![CDATA[ CREATE VIEW my_view ( column_1 varchar(10), column_2 varchar(10), column_3 varchar(100), ) AS SELECT MyAggregateFunction(DISTINCT column_1, ',') as column_1, column_2 , column_3 FROM my_table GROUP BY column_1 , column_2 ]]> </metadata> </model>

Teiid 9.1.2 Server - Increase Memory

To increase the start and maximum memory that can be used by a Teiid Server (9.1.2) do the following:


  1. vi /bin/standalone.conf
  2. Search for JAVA_OPTS. Add "-Xms2g -Xmx2g" to the beginning . You should have after editing something like this: JAVA_OPTS="-Xms2g -Xmx2g -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=512m -Djava.net.preferIPv4Stack=true"

Install Teiid Designer 11 on Eclipse Neon

Install

Here are the steps to install Teiid Designer 11 on Eclipse Neon
  1. Download eclipse NEON (Java EE. Eclipse for Java Developer will not work!)
  2. Install into Eclipse 4.6 (Neon)
    1. Launch the Help > Install New Software action
    2. Add... the following update site URLs but DO NOT install them. Various dependent plugins required for Teiid Designer will be installed as needed. Make sure “Contact all update sites during install to find required software” is checked.
      1. http://download.jboss.org/jbosstools/targetplatforms/jbtistarget/4.4.1.CR1/jbtis/REPO
      2. http://download.jboss.org/jbosstools/neon/stable/updates/
    3. Install Teiid Designer 11.0 via update site:
      1. http://download.jboss.org/jbosstools/updates/release/neon/integration-stack/teiiddesigner/11.0.0.Final/
    4. Click Install button and continue through restarting Eclipse

PS: When configuring a server, before testing the connections don't forget to START the server first!

Install Teiid 9.1.2 on CentOs 7

Install Teiid 9.1.2 on Cent Os 7

Here are the steps necessary to install Teiid 9.1.2 Server on CentOs 7:

  1. Download Teiid 9.1.2
  2. Extract the zip file to some directory (that will be know from now on as )
  3. Go to
  4. Run ./add-user.sh
  5. Add one user for managment and one user for application
  6. Edit standalone.sh and add (replace the SERVER_OPTS by the following line)
    1. SERVER_OPTS="-b 0.0.0.0 -bmanagement 0.0.0.0"
    2. This will allow access to both frontend and backend from outside the machine where Teiid is installed. If you do not what that management be accessed from outside, then remove the "-bmanagement 0.0.0.0" part.
  7. Configure firewall (on a shell write the following to open Teiid default ports to outside).
    1. firewall-cmd --permanent --zone=public --add-port 9990/tcp
    2. firewall-cmd --permanent --zone=public --add-port 8080/tcp
    3. firewall-cmd --permanent --zone=public --add-port 31000/tcp
    4. firewall-cmd --reload

Start Teiid

cd /bin 
./standalone.sh -c=standalone-teiid.xml


URLs

Teiid will be available at:

http://127.0.0.1:8080
http://127.0.0.1:9990/console

quarta-feira, 25 de janeiro de 2017

Add mysql driver to WildFly 10

Take the following steps to install mysql driver on WildFly 10:


1) Copy the jar into ${WILDFLY_HOME}/bin directory

2) Execute ./jboss-cli.sh -- connect

4) Write the following on the shell (adapt to your needs):

module add -–name=com.mysql –-resources=mysql-connector-java-5.1.40.jar –-dependencies=javax.api,javax.transaction.api


5)  Write the following on the shell

/subsystem=datasources/jdbc-driver=mysql:add(driver-name="mysql",driver-module-name="com.mysql",driver-class-name=com.mysql.cj.jdbc.Driver)


6) Write:

:reload

quarta-feira, 18 de janeiro de 2017

Teiid Designer - NullPointerException when trying to execute VDB

Having Teiid Designer 11 installed in Eclipse Neon (Eclipse IDE for Java Developers version),  when trying to Execute VDB, the following error occurred:



Error: Could not connect to XXX - xxx.xxx.xxx.xxx - Teiid Connection.
Detailed error: Error creating SQL Model Connection connection to XXX- xxx.xxx.xxx.xxx - Teiid Connection. (Error: null)
Exception Stack Trace:
  java.lang.NullPointerException
at org.eclipse.datatools.connectivity.sqm.internal.core.util.DatabaseProviderHelper.getCatalogDatabase(DatabaseProviderHelper.java:37) ...



The solution is easy: Install Eclipse IDE for Java EE Developers instead. And it will work.

PS: The same problem can arise when trying to create a Data Source in eclipse. The solution is the same.

segunda-feira, 17 de agosto de 2015

JBehave : java.lang.NoClassDefFoundError: org/apache/log4j/Priority

Quando se executa um teste JBehave, surge o seguinte erro:

 java.lang.NoClassDefFoundError: org/apache/log4j/Priority

ou

java.lang.NoClassDefFoundError: Could not initialize class freemarker.template.Configuration


A solução é bastante simples: Adiciona no pom.xml a dependência para o log4j.


<plugin>
  <groupid>org.jbehave</groupid>
  <artifactid>jbehave-maven-plugin</artifactid>
  <version>${jbehave.core.version}</version>
  <configuration> ... </configuration>
  <executions> ...  </executions>
  <dependencies>
     <dependency> 
        <groupid>log4j</groupid> 
        <artifactid>log4j</artifactid> 
        <version>1.2.17</version> 
     </dependency>
  </dependencies>
</plugin>


 E o problema fica resolvido.

Exemplo de um stacktrace mais completo com o problema:


 [WARNING] Failed to run embeddable XptoStories java.lang.NoClassDefFoundError: org/apache/log4j/Priority at freemarker.log._Log4JLoggerFactory.getLogger(_Log4JLoggerFactory.java:67) at freemarker.log.Logger.getLogger(Logger.java:284) at freemarker.template.utility.SecurityUtilities.(SecurityUtilities.java:66) at freemarker.ext.beans.BeansWrapper.(BeansWrapper.java:147) at freemarker.template.ObjectWrapper.(ObjectWrapper.java:81) at freemarker.core.Configurable.(Configurable.java:161) at freemarker.template.Configuration.(Configuration.java:195) at freemarker.template.Configuration.(Configuration.java:172) at org.jbehave.core.reporters.FreemarkerProcessor.configuration(FreemarkerProcessor.java:30) at org.jbehave.core.reporters.FreemarkerProcessor.process(FreemarkerProcessor.java:21) at org.jbehave.core.reporters.TemplateableViewGenerator.write(TemplateableViewGenerator.java:270) at org.jbehave.core.reporters.TemplateableViewGenerator.createReports(TemplateableViewGenerator.java:222) at org.jbehave.core.reporters.TemplateableViewGenerator.generateReportsView(TemplateableViewGenerator.java:112) at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:256) at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:244) at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:220) at ... at org.jbehave.core.embedder.Embedder.runAsEmbeddables(Embedder.java:128) at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:18) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) 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.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:242) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) ... 40 more