How to generate SSH Key

An SSH key allows you to establish a secure connection between your computer and GitLab.
Before generating an SSH key, check if your system already has one by running
cat ~/.ssh/id_rsa.pub
If you see a long string starting with ssh-rsa or ssh-dsa, you can skip the ssh-keygen step.
To generate a new SSH key, just open your terminal and use code below. The ssh-keygen command prompts you for a location and filename to store the key pair and for a password. When prompted for the location and filename, you can press enter to use the default.
It is a best practice to use a password for an SSH key, but it is not required and you can skip creating a password by pressing enter. Note that the password you choose here can’t be altered or retrieved.
ssh-keygen -t rsa -C “username@gmail.com”
Use the code below to show your public key.
cat ~/.ssh/id_rsa.pub
Copy-paste the key to the ‘My SSH Keys’ section under the ‘SSH’ tab in your user profile. Please copy the complete key starting with ssh- and ending with your username and host.
Use code below to copy your public key to the clipboard. Depending on your OS you’ll need to use a different command:
Windows:
clip < ~/.ssh/id_rsa.pub
Mac:
pbcopy < ~/.ssh/id_rsa.pub
Linux (requires xclip):
xclip -sel clip < ~/.ssh/id_rsa.pub
Deploy keys allow read-only access to multiple projects with a single SSH key.
This is really useful for cloning repositories to your Continuous Integration (CI) server. By using deploy keys, you don’t have to setup a dummy user account.
If you are a project master or owner, you can add a deploy key in the project settings under the section ‘Deploy Keys’. Press the ‘New Deploy Key’ button and upload a public SSH key. After this, the machine that uses the corresponding private key has read-only access to the project.
You can’t add the same deploy key twice with the ‘New Deploy Key’ option. If you want to add the same key to another project, please enable it in the list that says ‘Deploy keys from projects available to you’. All the deploy keys of all the projects you have access to are available. This project access can happen through being a direct member of the projecti, or through a group. See def accessible_deploy_keys in app/models/user.rb for more information.
Advertisements

Annoying .idea files are commited into repository

IntelliJ is a good developing tool but it will generate a folder called .idea, which contains all your local settings. It is NOT supposed to be pushed to repository. So you need to ignore them by editing your .gitignorre file. Please be noted this is a hidden file, you can do the below within your Git Bash.
(The below not only can be applied to .idea but .setting and .iml files)http://stackoverflow.com/questions/11968531/what-to-gitignore-from-the-idea-folder
vi .gitignore
/target
.idea
*.iml
.classpath
.project
.settings
*.checkstyle
If unfortunately you have already committed those changes do the followings:
$ echo ‘.idea’ >> .gitignore
$ git rm -r –cached .idea
$ git add .gitignore
$ git commit -m ‘(some message stating you added .idea to ignored entries)’
$ git push

Rabbit MQ Server Crash on badmatch

I installed rabbitMQ locally. All of a sudden it stopped working and started to complain badmatch error as follows, since my voice-dm highly depend on it (it seems to me the application keeps trying to connect to rabbitMQ), I’ve tried to terminate the rabbitMQ process in task manager and restart it by using command line “rabbitmq-server.bat start” but the error persist.

=CRASH REPORT==== 11-Jan-2017::08:27:03 ===
crasher:
initial call: application_master:init/4
pid: <0.162.0>
registered_name: []
exception exit: {bad_return,
{{rabbit,start,[normal,[]]},
{‘EXIT’,
{{badmatch,
{error,
{{{badmatch,
{error,
{not_a_dets_file,
“c:/Users/d639174/AppData/Roaming/RabbitMQ/db/RABBIT~3/recovery.dets”}}},
[{rabbit_recovery_terms,open_table,0,
[{file,”src/rabbit_recovery_terms.erl”},
{line,130}]},
{rabbit_recovery_terms,init,1,
[{file,”src/rabbit_recovery_terms.erl”},
{line,111}]},
{gen_server,init_it,6,
[{file,”gen_server.erl”},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,”proc_lib.erl”},{line,239}]}]},
{child,undefined,rabbit_recovery_terms,
{rabbit_recovery_terms,start_link,[]},
transient,4294967295,worker,
[rabbit_recovery_terms]}}}},
[{rabbit_queue_index,start,1,
[{file,”src/rabbit_queue_index.erl”},{line,468}]},
{rabbit_variable_queue,start,1,
[{file,”src/rabbit_variable_queue.erl”},{line,439}]},
{rabbit_priority_queue,start,1,
[{file,”src/rabbit_priority_queue.erl”},{line,92}]},
{rabbit_amqqueue,recover,0,
[{file,”src/rabbit_amqqueue.erl”},{line,236}]},
{rabbit,recover,0,
[{file,”src/rabbit.erl”},{line,654}]},
{rabbit_boot_steps,’-run_step/2-lc$^1/1-1-‘,1,
[{file,”src/rabbit_boot_steps.erl”},{line,49}]},
{rabbit_boot_steps,run_step,2,
[{file,”src/rabbit_boot_steps.erl”},{line,49}]},
{rabbit_boot_steps,’-run_boot_steps/1-lc$^0/1-0-‘,1,
[{file,”src/rabbit_boot_steps.erl”},{line,26}]}]}}}}
in function application_master:init/4 (application_master.erl, line 133)
ancestors: [<0.161.0>]

After reading the logs under C:\Users\d639174\AppData\Roaming\RabbitMQ\log (this is described in the command line)

screen-shot-2017-01-29-at-3-20-35-pm

I think it is complaining there is something wrong with the recovery.dets file as shown in follows:

Screen Shot 2017-01-29 at 3.22.12 pm.png

I opened the location of this file and renamed it to recovery.dets_del
Then restart the service by running the command line “rabbitmq-server.bat start” the problem has been fixed and a new recovery.dets file is created

 

Code Coverage is defferent between Jacoco and IntelliJ

Q: The code coverage, in our sonarlint server, for my microservice is very low. In some classes the code coverage is kept to 0% even if I am 100% sure my test cases have covered all the code(when I run it locally in IntelliJ it is 100% code coverage, it should not have such a big gap.)
A: According to https://github.com/powermock/powermock/issues/422 it seems like Jacoco is not very friend with PowerMock. Unfortunately my test cases are using PowerMock (since I can test private method through Powermock)
After switch from Powermock to Mockito, my problem fixed.

MockServer in Webservice

It is normal sometimes we will face such situation: your implementation is ready however your downstream system is still unknown i.e. it has not been deployed, it has not been developed whatever in one word not-ready! What can you do to do an integration test? The answer is mock it.
We use mock server as a mock tool. A maven configuration is as follows:
<plugin>
                <groupId>org.mock-server</groupId>
                <artifactId>mockserver-maven-plugin</artifactId>
                <version>3.10.4</version>
                <configuration>
                    <skip>false</skip>
                    <serverPort>57333</serverPort>
                    <logLevel>ERROR</logLevel>
                    <pipeLogToConsole>true</pipeLogToConsole>
                </configuration>
                <executions>
                    <execution>
                        <iFold>start-mork-server</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-mock-server</id>
                        <phase>test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Configuration:

Folder Structure:

The configuration is per each downstream system/service. It is a folder with one “service.json” file and resource files (in subfolders).
All paths in the “service.json” are relative to the parent folder of the “service.json”.

folder structure.png

Service configuration file:

The service configuration contains “provider” name and a list of “Interactions”.
Each “interaction” has

  1. “request” where some values are variables
  2. “response” with default response parameters
  3. “switch” – list of variables (from request) – OPTIONAL
  4. “responses” – a map, where the keys are made from the variables and expected variable values, while the map values are “response” objects, whose values override the default response properties. – OPTIONAL

The order is important. It allows to define a default response by setting the most generic request matching conditions at the end.

Schema:

{
  “title”: “Service”,
  “description”: “Mock service configuration”,
  “required”: [
    “provider”,
    “interactions”
  ],
  “additionalProperties”: false,
  “properties”: {
    “provider”: {
      “type”: “string”
    },
    “interactions”: {
      “type”: “array”,
      “items”: {
        “$ref”: “#/definitions/interaction”
      }
    }
  },
  “definitions”: {
    “props”: {
      “type”: “object”,
      “patternProperties”: {
        “.+”: {
          “type”: “string”,
          “pattern”: “(^\\$\\{[^/]+\\}$)|(^[^\\$]{1}.*$)”
        }
      },
      “additionalProperties”: false
    },
    “response”: {
      “type”: “object”,
      “properties”: {
        “status”: {
          “type”: “integer”
        },
        “headers”: {
          “$ref”: “#/definitions/props”
        },
        “body”: {
          “type”: “string”
        },
        “latency”: {
          “type”: “integer”
        }
      }
    },
    “interaction”: {
      “type”: “object”,
      “properties”: {
        “request”: {
          “type”: “object”,
          “required”: true,
          “properties”: {
            “method”: {
              “type”: “array”,
              “items”: {
                “type”: “string”
              }
            },
            “path”: {
              “type”: “string”
            },
            “query”: {
              “$ref”: “#/definitions/props”
            },
            “cookies”: {
              “$ref”: “#/definitions/props”
            },
            “headers”: {
              “$ref”: “#/definitions/props”
            },
            “body”: {
              “type”: “object”,
              “properties”: {
                “regex”: {
                  “type”: “string”,
                  “pattern”: “(^\\$\\{[^/]+\\}$)|(^[^\\$]{1}.*$)”
                },
                “json”: {}
              }
            }
          },
          “required”: [
            “method”,
            “path”
          ]
        },
        “response”: {
          “$ref”: “#/definitions/response”
        },
        “switch”: {
          “type”: “array”,
          “items”: {
            “type”: “string”
          }
        },
        “responses”: {
          “type”: “object”,
          “additionalProperties”: {
            “$ref”: “#/definitions/response”
          }
        }
      },
      “additionalProperties”: false
    }
  }
}

Switch:

The purpose of these feature is to make the configuration more compact and easier to read. Without switch the configuration would look like a request –> response map, where the request and response are concrete values.
With switch we can mark some parts of the request as variables and move the corresponding list of values (n-tuple) to a switch key.

switch.png

Sample:

{
“request”: {
“method”: [
“POST”
],
“path”: “/myserice/mypath1/mypath2”,
“body”: {
“regex”:”myId\”:\”[0-9]{10,}”
}
},
“response”: {
“status”: 422,
“latency”:500,
“headers”:{
“Content-type”:”application/json;charset=UTF-8″
},
“body”: “data/response_422.json”
}
}

This tells you when it goes to URL Path/myserice/mypath1/mypath2 with any TEN digits myId  then it will give you a response with content as data/response_422.json

Statement Handling Literal string with Single Quote (‘) in where clause criteria

In simple query using JDBC Statement, NOT PreparedStatement, you will get a SQL exception in statement like this one

select customer.* from t_customer_table customer
where customer.last_name = ‘O’Reilly’;

You can workaround this by replace the single quote inside the criteria value by two consecutive single quotes (”). Not this is no a double quote, but 2 single quotes.

select customer.* from t_customer_table customer
where customer.last_nam = ‘O”Reilly’;

Please keep in mind it is always highly recommenced to use prepared statement with parameters, then you would need this workaround. But in case you don’t don’t want to that, this solution comes in handy.

jar sequence in pom.xml

I am working in a very complex env.
The file I needed, ServiceInstanceServiceTypeEnum.class is unfortunately included in THREE different jars.
That file is changed by the related team. However the change is only reflected in one of the three jars (let’s say they are called A.jar, B.jar and C.jar). The changed class is only included in C.jar.
Unfortunately my code only pick up the ServiceInstanceServiceTypeEnum class in A.jar which does not contain the changes.
I do not think it is a good design to include a file in different jars. But I am not the designer.
Actually if the related team can help me to include their changes in A.jar and B.jar too, it will not be an issue. But for some reason they can not do that.
Solution:
Change the sequence of those THREE jars in pom.xml and make C.jar the first one.
This may lead to some other unknown issue, but I think this is the only thing I can do at this stage.

Exceptions during installation of SoapUi

When I try to install SoapUI for Linux it complains:

Unpacking JRE …
Preparing JRE …
Starting Installer …
java.lang.NoClassDefFoundError: java.awt.Container
at com.install4j.runtime.installer.frontend.headless.AbstractHeadlessScreenExecutor.init(Unknown Source)
at com.install4j.runtime.installer.frontend.headless.ConsoleScreenExecutor.<init>(Unknown Source)

It appears that the installer can’t find a class in the WT library. I can’t see how how that can be possible. Does anyone know what is causing this, and how I may fix it?

[System Information]

java version “1.6.0_45”
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

Solution:

This seemed to fix the problem:

sudo apt-get install ia32-libs

The ia32-libs package is longer present in Ubuntu 12.04 repositories for a 64bit system. The ia32-libs package was a hack to get 32-bit packages installed on a 64-bit installation. Since Ubuntu version 11.10 (Oneiric), Multi Arch has been added. One of the objectives for it is removing the ia32-libs package. You can install the 32-bit libraries of a package with:

sudo apt-get install ia32-libs