Friday, 26 January 2018

Connect to database from Jenkins Active Choice parameter to retrieve data

We can connect to database and get the data to show in Jenkins job as a parameter.


import groovy.sql.Sql
import java.sql.*

def output = []

def sql = Sql.newInstance("jdbc:oracle:thin:@<host>:<port>:<instance>","<user>","<password>","oracle.jdbc.driver.OracleDriver");
  sql.eachRow("SELECT EMP_ID FROM SCHEMA.EMPLOYEE WHERE EMP_NAME='TEST' AND POSITION LIKE '%Manager'"){ row ->
            output.push(row[0])
  }
 
return output

Make sure you have driver jar present in Jenkins classpath.
Or add the ojdbc7.jar under /usr/java/packages/lib/ext and restart Jenkins service

Auto Refresh specific tab in browser and specific area of Page by Javascript

I had one requirement to auto refresh any page after specif interval and that should show only that part of the page which content I want to see.

Below is the Java script code which has to be added as a bookmark and click that bookmark after opening the page and scroll down to specific part you want to see after each refresh.



javascript:
refresh_interval=prompt("Set Refresh Interval in Seconds [s]");
current_page=location.href;
if(refresh_interval>0) {
  selectedFrame='<frameset cols=\'*\'>\n<frame id="refreshframe" src=\''+current_page+'\'/>';
  selectedFrame+='</frameset>';
  with(document) {
    write(selectedFrame);
    void(close())
  };
  setTimeout('reload()',1000*refresh_interval);
} else {
  location.replace(current_page);
}
function reload() {
  setTimeout('reload()',1000*refresh_interval);
  var frameToSet = document.getElementById('refreshframe');
  frameToSet.contentWindow.location.reload(false);
}



Wednesday, 3 January 2018

How to get port number of a process by pid in Unix


Get the pid by ps -ef | grep <processName>

Get the port in which this process is listening by below command.

netstat -lanpt | grep LISTEN | grep <pid>

Difference between class level and object locking and static object lock

1) Class level locking will lock entire class, so no other thread can access any of other synchronized blocks. 2) Object locking will lo...