Saturday, January 9, 2016

Installing Unbreakable Enterprise Kernel 4 on Oracle Linux 7

As announced here the Unbreakable Enterprise Kernel 4 is now available for Oracle Linux 6 & 7.
I was actually building a baseline APEX VM based on my personal preferences late last year.
To safe others and me the searching here is a quick writeup of the steps involved.

Start by making UEK4 repository for Oracle Linux 7 known to yum.
Use your favorite editor to edit the file /etc/yum.repos.d/public-yum-ol7.repo.
Then either add below lines to the file or replace the ones for ol7_UEKR3 with them.
Actually you cn copy the repository ol7_UEKR3 and just replace every 3 with a 4.
[ol7_UEKR4]
name=Latest Unbreakable Enterprise Kernel Release 4 for Oracle Linux $releasever ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR4/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
Now run yum update and verify that you actually get the version 4.
Depending on your internet connection's bandwidth this is a good time to grab a coffee.
You should at least see below line, otherwise you won't get the new kernel.
kernel-uek                      x86_64             4.1.12-32.el7uek                    ol7_UEKR4               43 M
Review the output from yum and then confirm with y.
Wait until yum has downloaded and installed all pending packages.
After everything has been installed reboot to activated the new kernel.

If you're running the system within VirtualBox like I do remember to reinstall the VirtualBox Guest Additions. You need to do this every time you boot into another kernel because they are compiled against the currently active kernel.
In the VirtualBox VM window go to Devices->Insert Guest Additions CD image.
Then mount the cdrom device if it isn't mounted automatically, then reinstall the additions.
[root@ol7db12c ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@ol7db12c ~]# /media/cdrom/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.12 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 5.0.12 of VirtualBox Guest Additions...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module[  OK  ]
Building the shared folder support module[  OK  ]
Building the OpenGL support module[  OK  ]
Doing non-kernel setup of the Guest Additions[  OK  ]
Starting the VirtualBox Guest Additions [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.

Have fun with the new kernel!

Friday, January 8, 2016

Coloring Cells in an Interactive Report

This is a quick post on something that came up on slack this week.
The task was basically to highlight certain cells in an interactive report based on the values in another column. While the highlighting feature in the interactive report is great that's one thing you can't do with it. You have the choice of highlighting the whole row or the cell in the column on which you based the condition. Another situation where the builtin highlighting isn't enough is when you need some complex conditions involving more than one column.

Took some iterations, but here's one solution to this.
I'll first outline the building blocks and then explain how they work together including some failed attempts on the way getting to this.
Interactive Report Query:
SELECT empno,
       ename,
       job,
       mgr,
       hiredate,
       sal,
       comm,
       deptno,
       CASE WHEN sal <= 1500 THEN 'data-style="background-color:green"' 
            WHEN sal > 1500 AND sal <= 3000 THEN 'data-style="background-color:orange"'
            WHEN sal > 3000 THEN 'data-style="background-color:red"'
            ELSE NULL
       END css_style
  FROM emp

Then set the css_style column to hidden and set the "HTML Expression" attribute on the column you want colored to something like the following.
Note: I use the SAL column here, but you can really use any column.
HTML Expression of column SAL:
<span #CSS_STYLE#>#SAL#</span>

The last bit is some JavaScript code which you put into a dynamic action firing on event "After Refresh" for the interactive report region. Make sure to also set "Fire On Page Load" to yes, otherwise you have no coloring after page load.
JavaScript Code:
apex.jQuery("span[data-style]").each(
  function()
  { 
    apex.jQuery(this).
      parent().attr( 'style'
                   , apex.jQuery(this).attr('data-style')
                   ); 
  }
);

If you don't want to read the full story you can stop reading here and have a look at the example app to be found at https://apex.oracle.com/pls/apex/f?p=83537.

Still reading?
Let's take a look at how we got to a working solution and how it does it's magic.

In the query we are laying the foundation by adding a column which computes the needed style for us. You might wonder why there is "data-style" instead of simply "style". Let me show you how the report would look if you would just be applying a style to the span element.
Just styling the span element

This doesn't look good and the reason is that the span element is an inline element only using the space it needs and not filling all available space as block elements do. Next try would be setting the span element to behave like a block element by adding display: block to the style definition.
Styling the span element with added display:block
A bit better, but this still isn't coloring the whole cell. To keep it short there where some other tries using some CSS-Wizardry which didn't work out too good either.
Back to the "data-style" thing. You are allowed to add your own custom attributes to HTML elements if you prefix them with "data-". Browsers will ignore them but from JavaScript or in this case jQuery you can access and utilize those attributes.
Let's have a closer look at the JavaScript code and walk through the logic.
  1. Select all span elements which have an attribute called data-style
    apex.jQuery("span[data-style]")
  2. Loop through the jQuery array and call an anonymous function for each item
    .each( function() {
  3. Find the current item's parent element (that's the for the cell)
    apex.jQuery(this).parent()
  4. Set the parent's style attribute using the span's data-style attribute
    .attr('style', apex.jQuery(this).attr('data-style'))
Finally we had something which looks very much like the inbuilt highlighting:


So long folks, this post actually got longer than I expected.

Happy IR-Hacking :-)