Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Sunday, 7 February 2016

Improve your Local Env with Docker+Jenkins+Selenium to achieve Continuous Delirery

The path to Continuous Delivery (CD) happens to have stable execution results of automated test, so will be ideal if the developers could pass the automated test on their local machine before they integrate their code with the base code. But  if we want to execute the automated test on the developer local machine we have to be aware of:
  1. The executions of the tests must be not intrusive, allowing the developers to focus on other tasks while the tests are executing.
  2. The solution must be easily adaptable to changes, for example, if new tests suites are available or disabled,  this doesn't have to be an overhead work for the developers to synchronize with their local environment.
Sometimes these points are difficult to accomplish, i.e. if we have more than 500 automated functional test to be tested with a real browser (e.g. Firefox).  

Knowing the global solution explained in my previous post, it's easy with Docker and Jenkins to have a template that could build a "private platform" where execute 'locally'  all the  tests (unit, integrated, functional...)

You can see the simplified solution in the next diagram:

As you can see on the diagram, the solution is based on Docker compose which builds Jenkins in a Docker container: a Jenkins Master and n-slaves Jenkins  (depending on configuration parameters). It will execute the test with Selenium/Firefox, where the test live in the local filesystem of the host. In this case, for convenience and not to overload the developers' machines, we won't test on IE  (but we could use a Vagrant virtual-machine with Windows and IE)...

The key points of this kind of configuration are:
  • Run Automated Test in background.
  • Light GUI containers to run Firefox with Selenium.
  • Parallel execution of the tests. 
  • Easy installation and updates.
  • We can see the visual errors of the navigation in the pdfs generated by the framework of test (see previous post)

Some Technical details of the solution

Docker-Compose

With Docker-Compose we have a simplified configuration for the developer:
# Jenkins Master
jenkins:
  image: s2obcn/jenkins
  container_name: jenkins
  ports:
   - "8090:8080"
   - "50000"
  volumes:
        - /home/s2o/vDocker/jenkins:/jenkins
  env_file:
    - jenkins-master.env
# Jenkins Slave
slave:
  image: s2obcn/jenkins-swarm
  links:
    - jenkins:jenkins
  volumes:
      - /home/s2o/vDocker/jenkins_shared/workspace:/opt/jenkins/workspace
  env_file:
    - jenkins-slave.env

Jenkins docker image with swarm plugin

Speed up the execution of the tests by running them in parallel, grouping the tests by suites and executing any suite by a different job. A second level of parallelisms is splitting the execution of the jobs by different Jenkins slaves.
RUN wget --no-check-certificate --directory-prefix=${SWARM_HOME} \
      http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/plugins/swarm-client/${SWARM_VERSION}/swarm-client-${SWARM_VERSION}-jar-with-dependencies.jar  && \
    mv ${SWARM_HOME}/swarm-client-${SWARM_VERSION}-jar-with-dependencies.jar ${SWARM_HOME}/swarm-client-jar-with-dependencies.jar && \
    mkdir -p ${SWARM_WORKDIR} && \
    mkdir -p ${SWARM_WORKDIR}/workspace/{TEST_PROJECT} && \
    chown -R jenkins:jenkins ${SWARM_HOME} && \
    chown -R jenkins:jenkins ${SWARM_WORKDIR} && \
    chmod +x ${SWARM_HOME}/swarm-client-jar-with-dependencies.jar

Docker with the correct Firefox configuration

To get a custom profile with Firefox the best way is execute Firefox, change the configuration as needed and save the current profile for the next executions.
  • Now I get Firefox running within a docker container and rendered by the local X Server, so in this way it can be easy configured:
docker run -it --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /home/s2o/tmp/a:/opt/jenkins s2obcn/jenkins-swarm bash

Sharing local IDE workspace with Jenkins Job workspace

  • The test, to be executed, will be loaded from an SCM or shared from a local FS. The trick here is to share the workspace between all the jobs/Jenkins.

Naming conventions (Jenkins with Job DSL Plugin)

  • The jobs to execute will have the same name of the suites to execute. 
  • We can build/update the jobs in the local Jenkins with the plugin Job DSL




Sunday, 4 October 2009

Developing Portlets using Eclipse. Part II


As I told you, the architecture that I use for these post, has iBATIS for it's persistence layer.

The main reason for use this framework was that iBatis give you the flexibility of write your own optimized sql code, and an easy way to call directly to a sql procedure. Not to mention, the existence of iBator, the code generator for iBatis :)

Spring will be a pivotal piece for the application, the reason for use of this framework it's as simple as I want to sleep as a baby. Some of the things that I want accomplish with spring is to have transparency over my data-source connection, jms..,, to make uncouple implementations from each other...

Well, the first interaction between ibatis and spring it's done in the configuration files, the next example show you how to make a configuration that also makes the application container independent.

Extract from applicationContext.xml:
<!-- obtain datasource  -->   
<jee:jndi-lookup id="dataSourceWebProd" jndi-name="jdbc/webProd" cache="true" resource-ref="true" lookup-on-startup="false" proxy-interface="javax.sql.DataSource"/>

<!-- map iBatis to datasource  -->   
<bean id="sqlMapBaseWeb" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
 <property name="configLocation"><value>classpath:/config/sqlmap-configWebProd.xml</value></property>
 <property name="dataSource"><ref bean="dataSourceWebProd" /></property>
</bean> 

<bean id="aliascuentasDAO" class="es.struts2PortletTemplate.dao.WebProd.AliascuentasDAOImpl">
 <property name="sqlMapClient">
  <ref bean="sqlMapWebProd"/>
 </property>
</bean>
<bean id="informesServicio" class="es.struts2PortletTemplate.miGestion.informes.service.InformesServiceImpl">
 <property name="aliascuentasDAO">
  <ref bean="aliascuentasDAO"/>
 </property>
</bean>

sqlmap-configWebProd.xml:
<settings cachemodelsenabled="true" enhancementenabled="true" usestatementnamespaces="true">
    <sqlmap resource="es/struts2PortletTemplate/dao/WebProd/sqlMap/WebProd_dbo_aliasCuentas_SqlMap.xml">
</sqlmap></settings>

And of course, you may well decide to use the Spring Framework's declarative transactions offer...
<bean id="txManagerWebProd" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name="dataSource" ref="dataSourceWebProd"/>
</bean>
<tx:advice id="txAdviceWebProd" transaction-manager="txManagerWebProd">
 <tx:attributes>
  <tx:method name="get*" read-only="true"/>
  <tx:method name="find*" read-only="true"/>
  <tx:method name="view*" read-only="true"/>
  <tx:method name="save*" propagation="REQUIRED"/>
  <tx:method name="*" propagation="REQUIRED"/>
 </tx:attributes>
</tx:advice>

Saturday, 12 September 2009

Easy developing and debuging portlets with eclipse WTP

This little entry is just to show you how quickly I have my new environment up and running. As I told you in my firt post, I develop the portlets with:

Eclipse with WTP
JetSpeed 2.2.0

And I will use Struts2 (Struts 2.1.7) portltes (JSR 168)...

The next log it's from a start up of the jetSpeed in debug mode.

INFO: JetspeedContainerServlet: attemping to start Portlet Application at: /Struts2PortletTemplate
12-Sep-2009 01:49:02 org.apache.catalina.core.ApplicationContext log
INFO: JetspeedContainerServlet: started Portlet Application at: /Struts2PortletTemplate
12-Sep-2009 01:49:03 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
12-Sep-2009 01:49:04 org.apache.catalina.core.ApplicationContext log
INFO: JetspeedContainerServlet: starting initialization of Portlet Application at: j2-admin
JetspeedContainerServlet: starting initialization of Portlet Application at: j2-admin12-Sep-2009 01:49:04 org.apache.catalina.core.ApplicationContext log
INFO: JetspeedContainerServlet: Could not yet start portlet application at: j2-admin. Starting back ground thread to start when the portal comes online.

12-Sep-2009 01:49:04 org.apache.catalina.core.ApplicationContext log
INFO: JetspeedContainerServlet: initialization done for Portlet Application at: j2-admin
JetspeedContainerServlet: initialization done for Portlet Application at: j2-admin
12-Sep-2009 01:49:04 org.apache.catalina.core.ApplicationContext log
INFO: JetspeedContainerServlet: attemping to start Portlet Application at: /j2-admin
12-Sep-2009 01:49:05 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
12-Sep-2009 01:49:05 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
12-Sep-2009 01:49:05 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/267  config=null
12-Sep-2009 01:49:05 org.apache.catalina.startup.Catalina start
INFO: Server startup in 14474 ms
12-Sep-2009 01:49:06 org.apache.catalina.core.ApplicationContext log
INFO: JetspeedContainerServlet: started Portlet Application at: /j2-admin


It takes only 14474 ms
can you do this with websphere?? ;)

Wednesday, 19 August 2009

Developing Portlets using Eclipse. Part I

On this entries I will show you how to develop portlets, create and debug portlets, in Eclipse with the WTP plugin and Jetspeed-2 . Lately I will deploy those portlets for the Websphere Portal 6.1.

Some frameworks that I will use:
The environmentLocations that I use to use with Linux:
  • /data/eclipse/eclipseWTP -> here's the eclipse.exe
  • /data/eclipse/eXtra/Jetspeed-2.2.0 -> for Jetspeed
  • /data/workspace/groupA -> for development
Locations that I use to use with Windows:
  • c:\eclipse\eclipseWTP -> here's the eclipse.exe
  • c:\eclipse\eXtra\Jetspeed-2.2.0 -> for Jetspeed
  • c:\apps\workspace\groupA -> for developement
OK, now it's time to configure our eclipse:
  • Add a new server runtime. In eclipse "Preferences/Sever/Runtime Enviroment", add "Apache Tomcat v6.0" and use the installation of the Jetspeed as "Tomcat installation directory "/data/eclipse/eXtra/Jetspeed-2.2.0".
  • Configure the new server. Here's the most important thing, just after we create the new server, we have to edit the server configuration and then "use Tomcat installation" (the default could be "use workspace") and change the "deploy path" to point where we had the "webapps" in our Jetspeed installation "/data/eclipse/eXtra/Jetspeed-2.2.0/webapps". Also we have to change the timeout to start the server.

The portlet

In eclipse, create a new Dynamic Web Project with target runtime: "Jetspeed 2.2.0". Project name: Struts2PortletTemplate :)
OK, now change the project properties, in "Java build path"... I like this "Struts2PortletTemplate/WebContent/WEB-INF/classes" as the output folder.

This will be the web.xml: