AWS Glacier CLI Command

Archived some of my files in Glacier for cold storage, jot down some note which I think useful.

To Download

Response as below, “InProgress” indicate it’s currently retrieving your vault information.

OK, tried few hours later and it showed “Succeeded”, go on…

Get archive list with command below which will lead to output written in archive.json.

Then create a json file with sample content below indicate which archive to download (I use download.json in this case)

Then execute command below:

You get response as:

Check the status job status:

Come back few hours/minutes, check the status and it’s now turn to “Succeeded”

Finally you can download your file with command below:

To Upload

To Delete

 

Credit to: softwaredevelopmentstuff.com & madboa.com

 

Docker: exec user process caused “no such file or directory”

Have no idea why Docker showing this (un-friendly) error message.
In fact, it caused by the bash script file created in Windows having different line ending and cannot run properly in Linux container.

Here is the fix using Notepad++.
First show the linefeed symbol.

You will see this.

Convert the linefeed from Windows to Unix.

You will get this, and save it 🙂

 

Weird Spring Boot Behavior

Encountered a weird behavior when running my Spring Boot + JSF (PrimeFaces) application in Docker container (using java -jar xxx.jar as ENTRYPOINT). It keep complaining “xhtml Not Found in ExternalContext as a Resource” when I access the page, in fact that runs well either using java -jar command or mvn spring:run in host machine.

After some hard time,  manage to figure out why…….. phew….
… it was caused by wrong jar packaging structure, and correct structure should look as below:

Credit to BalusC @ stackoverflow

 

MSSQL Configuration Tips

Happened to me hence jot down here for future reference, perhaps helpful to you also 🙂

Try to configure the TCP port as below from Sql Server Configuration Manager:

Try to configure as below from Microsoft SQL Server Management Studio:

 

Java 8 File to String in One Line

 

 

Pragmatic Java Application Test

Has been a while, I was thinking to blog this out but “lazy” bugs keep biting me 🙁 so I didn’t manage to do it. Until yesterday, I was looking for some related info but I hardly recall what I did previously. Phew… so decided to jot down here.

Typically software application should at least perform 2 types of automate tests which are unit test and integration test. For me… the distinction between these two are pretty straight forward:

Unit Test Integration Test
Test on smallest unit of application such as method / function Test on combination of few units in application to prove they run nicely with external resource (if there is any)
Cheap to run, fast to run (normally less than a minute) Slower compared with unit test (normally few minutes or more)
NOT depends on external resources such as database, third party services, disk access Normally involve database, disk access, other services
Mock the input of unit test if necessary Use the real service / resource
Maven Plugin Usage
Class name normally suffix with “Test”, for eg: TaxCalculatorTest (Maven Surefire plugin automatically include these wildcard patterns) Class name normally suffix with “IT”, for eg: TaxCalculationServiceIT (Maven Failsafe plugin automatically include these wildcard patterns)
Using Maven Surefire Plugin Using Maven Failsafe Plugin
Run during “test” phase in default Maven lifecycle Run during “integration-test” phase in default Maven lifecycle
Minimal sample Maven configuration:
Minimal sample Maven configuration:
Command to execute:
Command to execute:
Report generated in <PROJECT>/target/surefire-reports Report generated in <PROJECT>/target/failsafe-reports

By viewing the status report generated by surefire & failsafe plugin doesn’t create much insight, but we can make use of Jacoco plugin to create code coverage report as below.
Here are minimal sample Maven configuration for Jacoco:

Jacoco coverage reports generated at <PROJECT>/target/site/* when we run mvn verify (bind to maven verify phase). To view the coverage reports, simply open <PROJECT>/target/site/jacoco/index.html with browser.

Yay ! we have now cover first part of test (automate unit + integration test), and if you notice, we done all steps manually (run maven command, open report from target folder) just to get the report display.

Moreover, we just able to view the coverage report locally, how if we want to share with other team members or to make it public accessible.
And…….. How can we automate the whole process ?

Da.. Dang !! We have Jenkins (Continuous Integration) + SonarQube (Continuous Code Quality Inspection) to help us 🙂

Setting up Jenkins is pretty straight forward, just follow steps from Jenkins Guided Tour or Installing Jenkins. We should able to see something as below if Jenkins setup successfully and  launch in browser.
Let’s continue with SonarQube setup by following “Get Started in Two Minutes” guide from it’s official site. And if nothing goes wrong, we should able to bring up SonarQube console via browser as below:
Until this stage, you might feel a little tired or sleepy, it’s okie to refresh yourself with a cup of coffee 🙂

To allow Jenkins to work with SonarQube, we might need a little setup as below.

  1. Install SonarQube Scanner for Jenkins.
  2. Generate authentication token from SonarQube and store it somewhere as steps below for subsequent Jenkins configuration use.
  3. Goto Manage Jenkins –> Configure System, There should have SonarQube configuration module available.
    Just configure it by click on Add SonarQube, and fill in necessary information (sample below), then Save it.
  4. After setting up Jenkins – SonarQube, the next step is to add a Post Build Steps (SonarQube Scanner) for your Jenkins job as below:
    Note: Sample analysis parameter added above are very minimal, refer Analysis Parameter or Code Coverage by Unit Tests for Java Project for more parameter available.
  5. Rerun your Jenkins job after configuration, and you will see the analysis report generated in SonarQube as below.
  6. Yay !!!! We can now have beautiful test coverage report generate upon each code commit (of course, we need to configure Jenkins job to trigger build on each code commit to make these “magic” happen).
 

Java Runtime Class Reload

Some call it hot deploy, some refer to runtime class reload/redefine, but whatsoever….
It is just mechanism to reload compiled class file during jvm runtime, to avoid ordinary java development life cycle of “code change -> build -> deploy”, which will significantly save lot’s of wait time (especially when you have multiple modules dependency project).

Both open source project: HotSwapAgent and Spring-Loaded works pretty well for me, but if you are looking for commercial product, JRebel will be the choice.

 

Windows Multiple Tab Terminal

I have been using Cygwin quite sometime for my development task before ubuntu bash on Windows. Even Windows can group similar program into single task bar icon but open different type of console still occupying task bar spaces and most importantly, it doesn’t look nice since all of them are console for me.

non-multitab

so I use Console to manage it.

console2

Everything working fine except it cannot maximize by clicking on the top right maximize icon, until I found ConEmu which solve my problem and I’m start using it from now on. Of course maximize the windows is just one of the highlight here and many more configuration is available.

multitab-terminal

If you notice from the image, I open Ubuntu Bash, PowerShell, Cygwin, Git Bash and Command Prompt in different tab 🙂