Tuesday, October 24, 2017

Friday, September 29, 2017

handle JSON with jansson in C


int main()
{
    printf("Hello jansson...\n");

    const char * data_str = "{\
              \"operation\":\"mark-tier-movement\",\
              \"mark_tier_movement_request\":{\
                  \"mark_tier_movement\":true\
              }\
      }";

    json_t *root;
    json_error_t error;
    root = json_loads(data_str, 0, &error);
    if (!root) {
        printf("error: on line %d: %s\n", error.line, error.text);
        return 1;
    }

    json_t *operation;
    const char *msg_txt;
    operation = json_object_get(root, "operation");
    msg_txt = json_string_value(operation);
    printf("operation is: %s\n", msg_txt);

    return 0;
}

[root@localhost dev]# ./demo
Hello jansson...
operation code: is: mark-tier-movement

Friday, August 25, 2017

Add a new virtual hard disk to your Linux VM

1. log in as root
2. run this command and make note of the sdx entries
[root@localhost ~]# ls -l /dev/sd*
brw-r----- 1 root disk 8,  0 Aug 25 03:46 /dev/sda
brw-r----- 1 root disk 8,  1 Aug 25 10:46 /dev/sda1
brw-r----- 1 root disk 8,  2 Aug 25 03:46 /dev/sda2
brw-r----- 1 root disk 8,  3 Aug 25 03:46 /dev/sda3
brw-r----- 1 root disk 8,  4 Aug 25 10:46 /dev/sda4

3.  Add a new virtual hard disk to your VM from VMware Workstation GUI

4. run this command and you'll see the new entry for your newly added disk
[root@localhost ~]# ls -l /dev/sd*
brw-r----- 1 root disk 8,  0 Aug 25 03:46 /dev/sda
brw-r----- 1 root disk 8,  1 Aug 25 10:46 /dev/sda1
brw-r----- 1 root disk 8,  2 Aug 25 03:46 /dev/sda2
brw-r----- 1 root disk 8,  3 Aug 25 03:46 /dev/sda3
brw-r----- 1 root disk 8,  4 Aug 25 10:46 /dev/sda4
brw-r----- 1 root disk 8, 16 Aug 25 03:46 /dev/sdb

5. check your current file system type, it is ext3 for /
[root@localhost ~]# mount |grep ^/dev
/dev/sda4 on / type ext3 (rw)
/dev/sda2 on /tmp type ext2 (rw)
/dev/sda1 on /boot type ext3 (rw)

6. Check disk size and partition table with fdisk
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          65      522081   83  Linux
/dev/sda2              66         326     2096482+  83  Linux
/dev/sda3             327         587     2096482+  82  Linux swap / Solaris
/dev/sda4             588        2610    16249747+  83  Linux

Disk /dev/sdb: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

7. create an ext3 file system on the whole new disk
$ mkfs -t ext3 /dev/sdb


8. make directory as mount point
$ mkdir /bld

9. edit fstab for a permanent mount
/dev/sdb                 /bld                   ext3    defaults        0 0

10. reboot your VM



RCA: data type is incorrect

QA reported one issue during regression test. He added one Hbase backup configuration via GUI but the backup operation failed. HDFS backup is OK.

Looking into this issue, I found the data type is saved as "HDFS" in the configuration file which should be "HBASE" in the URL. It narrows down the problem.

Looking back to a recent checkin by a team member, I found this:
184:                   if ($scope.editdatamodel.bkCfg.type == "hbase") {
185:                        value = "/" + value;
186:                        basedir.replace("hdfs://", "hbase://");
187:                    }
Look at line 186. Yes, that's the root cause.  The javascript function 'replace' does not search and replace in place. It returns a NEW string.
https://www.w3schools.com/jsref/jsref_replace.asp

Solution:
    basedir = basedir.replace("hdfs://", "hbase://");

Friday, July 28, 2017

Uninstall git which is installed from source

I installed git 2.9.4 from source code via 'configure' and 'make install'. For some reason I need to uninstall it, but it could not be uninstalled with 'make uninstall'.

sudo find /usr/local -depth -iname 'git*' -exec rm -rf {} \;

The above command would delete all git related files.

Failed to start CentOS with GUI

When I came back from vacation, I could not start up my Cloudera Sandbox. It failed with the error message:

problem with the configuration server (/usr/libexec/gconf-sanity-check-2 exited with status 256

To fix it, press CTRL+ALT+F2 to switch to a Linux Terminal and then login with root,  then change the permission of /tmp to 777.

Restart it. All good to go.

Tuesday, June 27, 2017

Run a command with ProcessBuilder in Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Jceks {
    public static void main(String[] args) {
        System.out.println("Hello jceks...");
        System.out.println(Arrays.toString(args));
        try {
            run(args);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void run(String[] command) throws Exception {
        System.out.println(String.join(" ", command));

        int exitCode = 0;
        StringBuilder output = new StringBuilder();
        ProcessBuilder pb = new ProcessBuilder(command);
        pb.redirectErrorStream(true);

        Process p = pb.start();
        exitCode = p.waitFor();

        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = reader.readLine())!= null) {
            output.append(line + "\n");
        }

        System.out.println(output);
    }
}