vendredi 4 mai 2018

Install nodeJs using script


curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - 

sudo apt install -y nodejs                                                                

nodejs -v                                                                                         
v10.0.0 


That's it :-)

Find and remove obsolete PPA repositories



It happens sometimes , when running the update command

 sudo apt-get update


That we face some errors like :




This clearly indicates obsolete PPA repositories,To delete them, just run the following command :

1. List the obsolete PPA repositories  :

 sudo apt-get update | grep "Failed"
 E: The repository 'http://ppa.launchpad.net/colingille/freshlight/ubuntu bionic Release'    
 E: The repository 'http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu bionic  Release'    


2. Find the files containing ths obsolete PPA repository in the sources.list.d :


 - 2.1 PPA repo : http://ppa.launchpad.net/colingille/freshlight/ubuntu


 grep -rnw '/etc/apt/sources.list.d' \
  -e 'http://ppa.launchpad.net/colingille/freshlight/ubuntu bionic'




/etc/apt/sources.list.d/colingille-ubuntu-freshlight-bionic.list:1:deb http://ppa.launchpad.net/colingille/freshlight/ubuntu bionic main
/etc/apt/sources.list.d/colingille-ubuntu-freshlight-bionic.list:2:# deb-src http://ppa.launchpad.net/colingille/freshlight/ubuntu bionic main
/etc/apt/sources.list.d/colingille-ubuntu-freshlight-bionic.list.save:1:deb http://ppa.launchpad.net/colingille/freshlight/ubuntu bionic main
/etc/apt/sources.list.d/colingille-ubuntu-freshlight-bionic.list.save:2:# deb-src http://ppa.launchpad.net/colingille/freshlight/ubuntu bionic main

Comment or delete the PPA repository in the different listed files.


jeudi 7 décembre 2017

Docker : De Zéro à Z

Intro

En à peine 2 ans, l'outil libre et open source Docker a connu une ascension fulgurante dans le monde du développement logiciel.
Massivement adopté par les professionnels , celui-ci a su concilier le cycle de vie des applications et leurs infrastructures.

Mais au fait, c'est quoi Docker ? C'est la réponse que j'essaierai de développer tant du point de vue technique que fonctionnel dans cette présentation.

Après un rapide survol des deux univers ( dev & ops ), j'expliquerai ce que Docker nous apporte de plus, je détaillerai son installation , sa facilité de prise en main en me basant sur des cas d'utilisations concrets ( voting-app, WordPress.. ) .
Nous verrons ensuite que Docker a juste inventé de nouveaux cas d'usages mais pas la technologie, je parlerai alors brièvement des cgroups et des namespaces, puis expliquerai le concept des volumes , l'orchestration de déploiement, le clustering, le networking, et pour finir, quelques notions sur la sécurité.

mercredi 19 avril 2017

The Checker Framework


The Checker Framework enhances Java’s type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The frameWork comes with a nice feature Nullness Checker that detect NullPointerException at compiletime


For Maven Project, just add the following depencies & plugin in the pom.xml
      
<dependencies> <!-- annotations from the Checker Framework: nullness, interning, locking, ... --> <dependency> <groupId>org.checkerframework</groupId> <artifactId>checker-qual</artifactId> <version>2.1.10</version> </dependency> <dependency> <groupId>org.checkerframework</groupId> <artifactId>checker</artifactId> <version>2.1.10</version> </dependency> <!-- The Type Annotations compiler. Uncomment if using Java 7 or annotations in comments. --> <!-- <dependency> <groupId>org.checkerframework</groupId> <artifactId>compiler</artifactId> <version>2.1.10</version> </dependency> --> <!-- The annotated JDK to use (change to jdk7 if using Java 7). --> <dependency> <groupId>org.checkerframework</groupId> <artifactId>jdk8</artifactId> <version>2.1.10</version> </dependency> </dependencies>

 <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.1</version>
    <configuration>
        <!-- Change source and target to 1.7 if using Java 7 -->
        <source>1.8</source>
        <target>1.8</target>
        <fork>true</fork>
        <annotationProcessors>
           <!-- Add all the checkers you want to enable here -->
           <annotationProcessor>
              org.checkerframework.checker.nullness.NullnessChecker
           </annotationProcessor>
        </annotationProcessors>
        <compilerArgs>
             <!-- location of the annotated JDK, which comes from a Maven dependency -->
             <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
             <!-- Uncomment the following line to use the type annotations compiler. -->
             <arg>-J-Xbootclasspath/p:${typeAnnotationsJavac}</arg> 
        </compilerArgs>
    </configuration>
 </plugin>



For more details : https://checkerframework.org/manual/



That's all :-)



lundi 26 décembre 2016

Top N frequent words in a file - using Parallel Stream

Bellow, the simplest way to get Top N frequent words in a file using Parallel Streams :

  package org.service ;

  import java.util.Map ;
  import java.util.List ;
  import java.util.Arrays ;
  import java.nio.file.Path ;
  import java.io.IOException ;
  import java.nio.file.Paths ;
  import java.nio.file.Files ;
  import static java.util.Comparator.comparing ;
  import static java.util.stream.Collectors.toList ;
  import static java.util.stream.Collectors.counting ;
  import static java.util.stream.Collectors.groupingBy ;

  /**
   *
   * @author ryahiaoui
  */
  
  public class Counter {
    
    
    private static List<String> getTopNFrequentWords( Path path, int rank ) throws IOException {
        
      return Files.lines(path)
                  .parallel()
                  .flatMap( line -> Arrays.asList ( line.split("\\b")).stream() )
                  .collect( groupingBy( w-> w, counting() ) )
                  .entrySet()
                  .stream()
                  .sorted( comparing ( Map.Entry< String, Long>::getValue).reversed() )
                  .limit( rank )
                  .map( Map.Entry::getKey )
                  .collect( toList() ) ;
    }
    
    public static void main(String[] args) throws IOException {
        
        // Top 10 most frequent words 
        
        String path = "/testFile.txt" ;
        
        List<String> mostFrequentWords = getTopNFrequentWords ( Paths.get(path), 10 ) ;
        
        System.out.println( " mostFrequentWords = " + mostFrequentWords ) ;
    }
    
  }




That's all :-)


mercredi 21 décembre 2016

Jshell in Netbeans with Java 8


Now, it's possible to use Jshell in Netbeans 8.2 with java 8 ( Yes, I said JAVA 8 :-) )

Just need to follow the following steps :

1- Go to http://deadlock.netbeans.org/job/prototypes-repl9

2- Copy the link of the file updates.xml, you should have something like :
   
 http://deadlock.netbeans.org/job/prototypes-repl9/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml

3- Open Netbeans, go to Tools/Pluging/Settings


     


4- Add a new center using the link copied in the step 2

















5 - Go to Available Plugins and looks for Java Shell Support + Netbeans Jshell Library  
     then install them

























To open JShell in Netbeans, do ( Ctrl+I ) and search for java Shell , open the window,
you should have something like this
































That's all :-)




vendredi 16 décembre 2016

RAML-API-CONSOLE

Software development life cycle ( SDLC )

development_lifecycle

REST- API

 Resource               /planes:
  
 Verbes                   get:
                          post:
                          put:
                          patch:
                          delete:
      
 Identifiant             /planes/{id}:
                           get:
                           post:
                           put:
                           patch:
                           delete:
    
 Résultat                responses:
                          200:
                            body:
                              application/json:
                                example: |
                                  {
                                    "B-777" : "Hello World"
                                  }

REST API Interface complexity

rest-api

Spec Driven Development

Spec Driven Development consists on creating concise spec that can be used to describe your application’s interactions in a pragmatic way… more 
  • Contexte :
  • Contract First : Documentation before code
  • Documentation managed as source code
  • Human readable docmentation



# RAML Approach

sdd

RAML-SPEC

Restful API Modeling Language
RAML™ is a YAML-based language that describes RESTful APIs. Together with the YAML specification, this specification provides all the information necessary to describe RESTful APIs; to create API client-code and API server-code generators; and to create API user documentation from RAML API definitions… more 

raml

RAML- Tutorial

http://raml.org/developers/raml-200-tutorial
/songs:
  description: Collection of available songs in Jukebox
  get:
    description: Get a list of songs based on the song title.
    queryParameters:
      songTitle:
        description: "The title of the song to search "
        required: true
        minLength: 3
        type: string
        example: "Get L"
    responses:
      200:
        body:
          application/json:
            example: |
              "songs": [
                  {
                    "songId": "550e8400-e29b-41d4-a716-446655440000",
                    "songTitle": "Get Lucky"
                  },
                  {
                    "songId": "550e8400-e29b-41d4-a716-446655440111",
                    "songTitle": "Loose yourself to dance"
                  },
                  {
                    "songId": "550e8400-e29b-41d4-a716-446655440222",
                    "songTitle": "Gio sorgio by Moroder"
                  }
                  ]
  /{songId}:
    description: Song entity
    get:
      description: Get the song with `songId = {songId}`
      responses:
        200:
          body:
            application/json:
              example: |
                {
                  "songId": "550e8400-e29b-41d4-a716-446655440000",
                  "songTitle": "Get Lucky",
                  "duration": "6:07",
                  "artist": {
                    "artistId": "110e8300-e32b-41d4-a716-664400445500"
                    "artistName": "Daft Punk",
                    "imageURL": "http://travelhymns.com/random-access-memories1.jpg"
                  },
                  "album": {
                    "albumId": "183100e3-0e2b-4404-a716-66104d440550",
                    "albumName": "Random Access Memories",
                    "imageURL": "http://upload.wikimedia.org/Random_Access_Memories.jpg"
                  }
                }
        404:
          body:
            application/json:
              example: |
                {"message": "Song not found"}
    /file-content:
      description: The file to be reproduced by the client
      get:
        description: Get the file content
        responses:
          200:
      post:
  post:

1) Writing Spec ( creating RAML files ) :

api-designer

  npm install -g api-designer

  api-designer

Atom + api-workbench

atome_api-workench

2) Generate documentation :

api-console

  • Build Image
  docker build -t api-console .
  • Run
    1. Using Simple file simple.raml
docker run --name my-api-console_1 -p 9000:9000 -d  api-console
http://localhost:9000/index.html?raml=apis/simple.raml 
    2. Using Docker Volume
docker run --name my-api-console_1 -p 9000:9000 -d -v $(pwd)/raml-files:/data/dist/apis api-console
  http://localhost:9000/index.html?raml=apis/planes.raml 

  http://localhost:9000/index.html?raml=apis/planes/api-plane.raml

raml2html

A simple RAML to HTML documentation generator, written for Node.js
  raml2html -i simple.raml -o example.html

  raml2html -i raml-files/planes/api-plane.raml -o api-plane-doc.html

3) Simulate API

osprey-mock-service

Generate an API mock service from a RAML definition using Osprey.
  osprey-mock-service -f simple.raml -p 8000 --cors

  osprey-mock-service -f raml-files/planes/api-plane.raml -p 8000 --cors

4) Validate Spec

abao

Abao is a command-line tool for testing API documentation written in RAML format.
  abao simple.raml --server http://localhost:8000/v1
      
  abao raml-files/planes/api-plane.raml --server http://localhost:8000/v1

raml-mockup Validation + Mock service ( BONUS ** )

https://www.npmjs.com/package/raml-mockup
  raml-mockup simple.raml -p 5000 -w

  raml-mockup raml-files/planes/api-plane.raml -p 5000 -w

     ----------------------------------------------------------------------
     
  raml-mockup raml-files/planes/api-plane.raml -p 8000 -w
     
  abao raml-files/planes/api-plane.raml --server http://localhost:8000
     
     ----------------------------------------------------------------------

5) BUILD

1- JAVA

Maven Plugin ( raml for jax-rs )

Maven plug-in generates JAX-RS annotated interfaces and supporting classes based on one or multiple RAML files

* RAML to JAX-RS

   <plugin>
    <groupId>org.raml.plugins</groupId>
    <artifactId>raml-jaxrs-maven-plugin</artifactId>
    <version>1.3.4</version>
    <configuration>
        <!-- Use sourcePaths if you want to provide a single RAML file or a list of RAML files -->
        <sourceDirectory>${basedir}/raml</sourceDirectory>
        <!-- Optionally configure outputDirectory if you don't like the default value: --> 
        <!-- ${project.build.directory}/generated-sources/raml-JAX-RS -->
        <!-- Replace with your package name -->
        <basePackageName>com.acme.api</basePackageName>
        <!-- Valid values: 1.1 2.0 -->
        <jaxrsVersion>2.0</jaxrsVersion>
        <useJsr303Annotations>false</useJsr303Annotations>
        <!-- Valid values: jackson1 jackson2 gson none -->
        <jsonMapper>jackson2</jsonMapper>
        <removeOldOutput>true</removeOldOutput>
        <!-- Optionally set extensions to a list of fully qualified names of classes
        that implement org.raml.jaxrs.codegen.core.ext.GeneratorExtension -->
        <!-- for example:
        <extensions>
            <param>com.abc.AuthorizationAnnotationExtension</param>
            <param>com.abc.ParameterFilterExtension</param>
        </extensions>
        Custom annotator for json schema to pojo convertor
        <customAnnotator>com.abc.MyCustomAnnotator</customAnnotator>
        -->
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
</plugin>

* JAX-RS to RAML

<plugin>
    <groupId>org.raml.plugins</groupId>
    <artifactId>jaxrs-raml-maven-plugin</artifactId>
    <version>1.3.4</version>
    <configuration>
      <sourcePaths>
          <param>${basedir}/src/main/java/contacts/Contact.java</param>
          <param>${basedir}/src/main/java/contacts/ContactAttrs.java</param>
          <param>${basedir}/src/main/java/contacts/Contacts.java</param>
      </sourcePaths>
      <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
      <outputFile>${project.build.directory}/generated-sources/jaxrs-raml/example.raml</outputFile>
        <removeOldOutput>true</removeOldOutput>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate-raml</goal>
            </goals>
            <phase>process-classes</phase>
        </execution>
    </executions>
</plugin>

* Deploy webService using maven project including RAML to JAX-RS plugin

  http://localhost:8080/raml-planes-api/resources/planes

  http://localhost:8080/raml-planes-api/resources/planes/10

2- PHP - CLI

RAML PHP Client Generator

CLI example generated for api-plane.raml
 raml-php-generator raml-files/planes/api-plane.raml -o api-client-php
<?php

namespace SampleApi                     ;

require_once "vendor/autoload.php"      ;

const TEMPLATE_REGEXP = '/{([^{}]+)}/'  ;

use GuzzleHttp\Psr7\Request; use GuzzleHttp\Client as HttpClient        ;

$options = [
'baseUri' => 'http://localhost:8080/raml-planes-api/resources/planes' ] ;

$client = new Client($options)                                          ;

$planes = $client->resources->planes->get(null, $options)->getBody()    ;

$planeByID = $client->resources->planes->id(10)->get(null, $options)->getBody() ;

echo "\n"                                                  ;
echo " All Planes : ----------------------------- "        ;
echo "\n \n"                                               ;
echo "  $planes "                                          ;
echo "\n \n"                                               ;
echo " Plane by ID : ----------------------------- "       ;
echo "\n \n "                                              ;
echo "  $planeByID "                                       ;
echo "\n \n"                                               ;
echo " ------------------------------------------ "        ;

?>

Microrest.php ( PHP HTTP server )

Microrest is a Silex provider to setting up a REST API on top of a relational database, based on a
YAML (RAML) configuration file… more


Features :

RAML-Merge

RAML Merge lets you merge in any included RAML files (!include) into a single RAML file via the command line.
  php ramlMerge.php raml-files/planes/api-plane.raml > api-plane-full.raml

RAML - SWAGGER : Pros and Cons

* Swagger

- Pros: Heavily adopted, large community of users and supporters, support multiple languages
- Cons: Lacks advanced constructs for metadata

* RAML

- Pros: Supports advanced constructs, decent adoption, human readable format, high industry backing
- Cons: Lacks code-level tooling, still unproven long-term