Thursday 28 February 2019

Installing MariaDB 10 on CentOS 7

I have always used the stock install of MariaDB that came with CentOS 7, but I noticed recently that it is still only on 5.5 (at the time of writing, 5.5.60).

I never had any issues with it, until I tried to upgrade my Liferay CMS system. Apparently there are definite changes that are not incorporated into the 5.5.

I wished to moved to 10.3, which is the latest stable branch, and I can apparently do that (as indicated on the mariadb website1) by creating a MariaDB repository for DNF and then installing as usual.

Of course, first uninstall the 5.5 version.

References

[1] MariaDB - Installing MariaDB 10 on CentOS 7 / RHEL 7
https://mariadb.com/resources/blog/installing-mariadb-10-on-centos-7-rhel-7/
MariaDB - Moving to MariaDB Backup
https://mariadb.com/resources/blog/moving-to-mariadb-backup/

Thursday 21 February 2019

Backup & Restore of Payara Server

How do I backup and restore my domain in Payara (or glassfish for that matter.)

$ ./asadmin backup-domain --backupDir ~/mmud_backups/payara_backups domain1

It ends up in ~/mmud_backups/payara_backups/domain1/domain1_2019_01_27_v00001.zip

$ ./asadmin restore-domain --filename ~/mmud_backups/payara_backups/domain1/domain1_2019_01_27_v00001.zip --backupdir ~/mmud_backups/payara_backups domain1
Restored the domain (domain1) to ~/payara5/glassfish/domains/domain1
Command restore-domain executed successfully.

References

Payara - Backup & Restore of Payara Server
https://blog.payara.fish/backup-restore-of-payara-server
Payara - How to upgrade Payara Server 5
https://blog.payara.fish/how-to-upgrade-payara-server-5-reloaded

Thursday 14 February 2019

Nginx - Redirecting to HTTPS

For automatic http->https redirection it is recommended to use Apache or Nginx in front of Payara to do the redirection, see [1].

I decided on using nginx for this2 3 4.

Before nginx, it looks like this:

$ curl -s -D - http://www.mrbear.org -o /dev/null
HTTP/1.1 200 OK
Server: Payara Server  5.184 #badassfish
X-Powered-By: Servlet/4.0 JSP/2.3 (Payara Server  5.184 #badassfish Java/Oracle Corporation/1.8)
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN

Configuration is found in /etc/nginx/nginx.conf.

I changed it into something very simple:

server {
      listen      80 default;
      access_log off;
      error_log off;
      return      301 https://$server_name$request_uri;
}

Double checking:

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Enabling automatic start and also starting nginx.

# systemctl enable nginx
# systemctl start nginx

So, let's try seeing what the webserver now responds with:

$ curl -s -D - http://www.mrbear.org -o /dev/null
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.2
Date: Mon, 28 Jan 2019 16:28:59 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://www.mrbear.org/

$ curl -s -D - http://www.mrbear.org/this/is/some/url.jsf -o /dev/null
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.2
Date: Mon, 28 Jan 2019 16:31:06 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://www.mrbear.org/this/is/some/url.jsf

References

[1] Payara - How to Secure Payara Server with Apache
https://blog.payara.fish/how-to-secure-payara-server-with-apache
[2] How To Nginx Redirect All HTTP Request To HTTPS Rewrite 301 Rules
https://www.cyberciti.biz/faq/linux-unix-nginx-redirect-all-http-to-https/
[3] How to do an Nginx redirect
https://bjornjohansen.no/nginx-redirect
[4] Creating NGINX Rewrite Rules
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
DigitalOcean - How To Install Nginx on CentOS 7
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

Thursday 7 February 2019

Angular App Upgrade

For simple Angular1 apps, it just might make more sense to rewrite them, than to upgrade them.

This might seem easier as I haven't done anything with my Angular app lately, it's still on Angular 4 (4.0.0) and Angular 7 (7.2.0) is out by now.

Added benefit is that I see firsthand the different changes, and I can blog about it.

Let's see what has changed, and how I am going to replace certain elements.

General setup

Creating the App

Start by creating the application.

$ ng new my-app

Bootstrap

Adding bootstrap can be done using [2].

$ npm install bootstrap --save

Added the bootstrap css to the styles in angular.json.

"styles": [
  "src/styles.css",
  "node_modules/bootstrap/dist/css/bootstrap.min.css"
],

I am not planning on using NgBootstrap2, I think it's just a wrapper.

Material Icons

I need me some icons4, without getting *everything*.

$ npm install --save material-icons

Added the icons css to the styles in angular.json.

"styles": [
  "src/styles.css",
  "node_modules/bootstrap/dist/css/bootstrap.min.css",
  "node_modules/material-icons/iconfont/material-icons.css"
],

Miscellaneous settings

I usually make some small changes in the angular.json. These are documented here.

"outputPath": "../webapp",

Components and Services

It's possible to generate a skeleton for components and services we wish to design.

$ ng generate component errors
$ ng generate service player

JSON-typescript-mapper

I used to use the json-typescript-mapper as displayed below, as it helps to convert a incoming json response into a real live TypeScript class. It works by adding approproate @JsonProperty annotations.

I have since removed this, as I find that the new Angular has the possibility of getting a "Typed" JSON response.

Although, since at the bottom is it still JavaScript, it means I cannot have any business logic in my "JSON" TypeScript classes, as per the usual the casting of type A to type B is simply ducktyping in action.

I do run the risk of creating an anemic entity model, though.

$ npm install --save json-typescript-mapper

The Differences

This is the important part.

Angular CLI
It seems I originally built the app using CLI version 1.0.6. Now I am using 7.2.1.
Generating code
It is now possible to generate guard, interface and enum with the CLI.
angular.json
The file angular.json is new, and replacing the old .xxxx
test files moved to src directory
Test files are now in /e2e/src/app.e2e-spec.ts
creating docs
Need to remember that the old file had a way to generate docs.In scripts of the package.json
"docs": "npm run typedoc -- --options typedoc.json --exclude '**/*.spec.ts' ./src/",
"typedoc": "typedoc"
Tslint and TypeScript syntax
  • TsLint says: single quotes are better than double quotes.
  • always use the === instead of ==, unless you're sure.
  • most of the stuff I use locally should be const instead of let
  • tslint actually complains sometimes if I am specific. For example with error: boolean = false;
Http
The HttpModule has been replaced/renamed to HttpClientModule and is moved from @angular/http to @angular/common/http.
Injectable annotation
has a new "providedIn" property.
REST service calls

The calling of a rest service has been simplified, from:

public updateGuild(guild: Guild): Observable<any> {
  let headers = new Headers({
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  });
  let options = new RequestOptions({ headers: headers });
  return this.http.put(this.getGuildUrl(), guild, options)
    .catch((n) => this.handleError(n));
}
To:
public updateGuild(guild: Guild): Observable<any> {
  return this.http.put(this.getGuildUrl(), guild);
}

Luckily the actual code didn't need much changing.

Build and Release

Building for production

$ ng build --prod --base-href "/karchanpersonal/"

Miscellaneous

Dates

For some reason, the dates returned by the Rest services are in a format that is not recognised by JavaScript.

2010-03-03T05:54:09Z[UTC]

The [UTC] at the end is weird.

An ugly hack that removed the [UTC] with string.replace works.

References

[1] Angular
https://angular.io/
[2] Adding Bootstrap to Angular
https://www.talkingdotnet.com/add-bootstrap-4-to-angular-6-application/
[3] NgBootstrap - Getting started
https://ng-bootstrap.github.io/#/getting-started
[4] NPM - Material Icons
https://www.npmjs.com/package/material-icons