miércoles, 27 de diciembre de 2017

Guice small code receipt and Spark framework

La clase que utiliza el injector
System.setProperty("user","santi");

Injector injector = Guice.createInjector(new GuiceMod());
ConfigurationService config = injector.getInstance(Key.get(ConfigurationService.class, Names.named("config")));
System.out.println(config.getKey("user"));


threadPool(250,15,30000);


Random random= new Random();
long rand = random.nextLong();

System.out.println("Shutdown code: "+rand);
get("/sample",(req,res)-> {
            return "Hello World!!!";
        });

        get("/sd_"+rand,(request, response) -> {
            stop();
            return "";
        });
El modulo

/**
 * Created by santiago on 12/26/17.
 */
public class GuiceMod extends AbstractModule{


    @Override
    protected void configure() {

    }

    @Provides
    @Singleton
    @Named("config")
    public ConfigurationService getConfig(){
        return new ConfigurationImpl();
    }

}


martes, 17 de octubre de 2017

Deploy to Nexus

With the following snippet you can deploy anything to Nexus. mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0 -DgeneratePom=false -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/nexus/content/repositories/releases -DpomFile=pom.xml -Dfile=target/project-1.0.0.jar

Ant as a script director

Hi, this entry on the blog is for using Ant as a scripting integration together with Groovy.

<‍project‍>
<‍property name="groovy.home" value="/home/vagrant/.sdkman/candidates/groovy/current/"/‍>
   <‍property name="groovy.version" value="X.Y.Z"/‍>
   <‍path id="groovy.classpath"‍>
     <‍fileset dir="${groovy.home}/lib"‍>
       <‍include name="**/*.jar"/‍>
     <‍/fileset‍>
   <‍/path‍>
<‍target name="targetSample"‍>
    <‍taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath"/‍>
      
        ant.ant(antfile:'build.xml'){ // you antfile name
           target(name:'targetTest') // your targetName
           property(name:'param1',value:'theParamValue') // your params name and values
        }
        def salutation="Hello World"
        print(salutation)
       <‍/groovy‍>
 <‍/target‍>
<‍target name="targetTest"‍>
        <‍echo‍>Hola mundo Groovy! <‍/echo‍>
<‍/target‍>
<‍/project‍>
Output
Buildfile: /home/vagrant/ant-tests/build.xml

targetSample:

targetTest:
     [echo] Hola mundo Groovy!
Hello World

BUILD SUCCESSFUL
Total time: 1 second

viernes, 8 de septiembre de 2017

Google Analytics from the command line

Use the following command
curl -d "v=1&tid=UA-104039318-1&cid=111&t=pageView&dp=/b/route&ds=web&cd3=GDL-MEX" 
-X POST www.google-analytics.com/collect

How to perform Single sign-on with Nginx

Insert within server section:
 location = /auth {
            internal;
            proxy_pass              http://localhost:8080/auth.jsp;
            proxy_pass_request_body off;
            proxy_set_header        Content-Length "";
            proxy_set_header        X-Original-URI $request_uri;
        }

        location /examples/ {
            auth_request     /auth;
            auth_request_set $userid $upstream_http_userid;
            auth_request_set $role $upstream_http_role;
            proxy_set_header X-UserId $userid;
            proxy_set_header X-Role $role;
            proxy_pass              http://localhost:8080/examples/;
        }

martes, 15 de agosto de 2017

Converting Java to native code with GCJ

I recently discovered the power of gcc in order to create native executables from Java source code. You never know when are you going to need it, but just in case, is good to know that is there:
gcj -c -g -O MyJavaProg.java
gcj --main=MyJavaProg -o MyJavaProg MyJavaProg.o

Jenkins Pipelines.

Hey!!! I know it has been a while since my last post. It has been a very busy period in my life but now I wanted to take back my good habits and start writing posts related with software and infrastructure. Today I will start with Jenkins (the most usefull tool I have found in these days).
pipeline{
    agent any
    stages{
        stage ('logic artifact build'){
            steps{
                echo 'Fase I construyendo artefacto aplicacion'
                echo params.BRANCH
                build job: 'XXXXXX', parameters: [string(name: 'BRANCH', value: params.BRANCH)]
            }
        }
        stage ('build web app'){
            steps{
                echo 'Fase II construiyendo el Web'
                echo params.BRANCH
                build job: 'XXXXXX', parameters: [string(name: 'PARAM_BRANCH', value: params.BRANCH)]
            }
        }
        stage ('resource assembly'){
            steps{
                build 'APACHE_CONFIG'
                build 'PACKAGE_ZIP'
            }    
        }
        
    }
    post{
    always{
        echo 'Pipeline finished'
        echo params.BRANCH
    }
    success{
       echo 'Build was success'
    }
    failure{
       echo 'Build failed'
    }
  }
    
}
This DSL is a very basic PIPELINE job that can handle the construction, resource assembly, and deployment of the application. It's important to give your jobs parameters like branch, environment, etc... so you don't have to have a job for every environment.