Friday, August 29, 2014
Postgresql JDBC enum and stored procedure
CallableStatement cs = conn.prepareCall("{call
sp_dummy(?::enum_result)}");
cs.setString(1, jobResult.toString());
cs.execute();
Thursday, August 28, 2014
Maven simple java application
Saturday, August 23, 2014
Work Breakdown Structure
Estimating using Work Breakdown Structure
- Setting up Development, Test, and Production environments - 8 hours
- Creating the Login screen - 4 hours
- Creating the Landing Page - 2 days
- Developing the XYZ Page - 12 hours
- etc., etc., etc.
WBS accuracy
Use feedback to improve WBS estimates
Don't forget acceptance testing
WBS estimate
Thursday, August 21, 2014
Jersey Maven setup Log4j2
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.1</version>
</dependency>
2. Add log4j configuration file to path: src/main/webapp/WEB-INF/classes
(create the classes folder manually)
3. Code:
Logger logger = LogManager.getLogger();
logger.info("info!!!!!!!!!!!!!!");
Serialize Object to Json indented string with Jersey
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
2. Code:
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
String rJson = "";
try {
rJson = mapper.writeValueAsString(request);
System.out.println(rJson);
} catch (JsonProcessingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Wednesday, August 20, 2014
Tomcat 7 connection pool with JNDI datasource and postgreSQL
<Context> <Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/mydb" username="myuser" password="mypasswd" maxActive="20" maxIdle="10" maxWait="-1"/> </Context>
2. Web application's web.xml
<resource-ref> <description>postgreSQL Datasource example</description> <res-ref-name>jdbc/postgres</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
2. Code
Connection conn = null;
try {
InitialContext cxt = new InitialContext();
DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/postgres" );
conn = ds.getConnection();
...
...
while(rs.next()) {
...
...
}
rs.close();
}
conn.close();
} catch (NamingException e1) {
e1.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
};
Maven Postgresql JDBC
http://mvnrepository.com/artifact/org.postgresql/postgresql/9.3-1100-jdbc41
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
2. Coding:
Connection conn = null;
try
{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://THE_HOST/THE_DATABASE";
conn = DriverManager.getConnection(url,"THE_USER", "THE_PASSWORD");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT id, subject, permalink
FROM blogs ORDER BY id");
while ( rs.next() )
{
Blog blog = new Blog();
blog.id = rs.getInt ("id");
blog.subject = rs.getString ("subject");
blog.permalink = rs.getString ("permalink");
listOfBlogs.add(blog);
}
rs.close();
st.close();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
catch (SQLException e)
{
e.printStackTrace();
System.exit(2);
}
Monday, August 18, 2014
System server requirements
System hardware requirements | ||||
CPU | File I/O | Database I/O | RAM | |
Management Web App | High | Low | High | Mid |
Scoring Web App | Low | Low to Mid | Mid | Mid |
Workers | High | High | Mid | High |
PostgreSQL | Mid | High | N/A | High |
DWH | N/A | N/A | High | N/A |
ETL | High | Low to Mid | Mid | High |
CRM | Mid | Low | Mid | Mid |
Analytics Engine | High | Low | Mid | High |
System Server Requirements | ||||
File Server | Database Server | Web Server | Processing Server | |
Functionalities | SFTP, NFS | DWH, Operation DB | Web based application, CRM, … | Workers, ETL, Analysis Engine, … |
CPU | Low (E3-1230v2 or existing) | Mid to High (E5-2420 dual / E52620 dual) | Mid (E3-1230v2/existing server) | High (E3-1230v2/existing server) |
RAM | 16G or above | 32G or above | 16G or above | 16G or above |
RAID | RAID 1/5/6 | RAID 10 | NO RAID / RAID 1 | NO RAID |
RAID Controller | Dell H710p or equivalent | Dell H710p or equivalent | N/A | N/A |
HDD | TBD | 1TB x 4 | 500GB | 500GB |
Quantity | x1 | x1 | xN | xN |
Public IPs | x1 | N/A | x2 | N/A |
Region | All | All | All | All |
Scalability | Add drive for increase storage capacity. Can add new server as required. | Single server can support up to 3 to 5 years. Can add new server as required. | Scale Horizontally by adding new server as required. | Scale Horizontally by adding new server as required. |
New Server Price | 20K (Dell R220) to 40K (Dell R520) | 50K+ HKD (Dell R520/R720) | 12K HKD (Dell R220) | 12K HKD (Dell R220) |
Servers Allocation | ||||
Live site | ||||
File Server | Database Server | Web Server | Processing Server | |
New server Dell R220/R520 | New server Dell R520/R720 | HK | ||
20K/40K+ HKD - Stage 2+ | 50K+ HKD - Stage 2 | existing server #1 - Management | ||
Support both all regions | existing server #2 - Scoring | |||
Database for Management, Scoring, Worker, DWH, etc. | Dell R210 - Workers, ETL, SFTP | |||
UK | ||||
existing #3 - Management | ||||
existing #4 - Scoring | ||||
=R220, R210 #2 in Stage 1 | = existing servers, R210 and R220 servers in Stage 1 | Dell R220 #2 (12K HKD - Stage 1) - Worker, SFTP | =R210, R220 #2 in Stage 1 | |
Standby site | ||||
File Server | Database Server | Web Server | Processing Server | |
New server Dell R220 RAID 1 | New server Dell R220 with RAID 1 | HK | ||
~20K HKD - Stage 3 | (* Use low to mid-range standby server) | R220 #3 (12K HKD - Stage 1.5) - Management, Scoring, SFTP, … | ||
~20K HKD - Stage 3 | 1 x VM #1 (2K HKD - Stage 1.5) Worker | |||
UK | ||||
R220 #3 (12K HKD - Stage 1.5) - Management, Scoring, SFTP, … | ||||
=R220 #3, R220 #4, VM #1, VM #2 in Stage 1.5 | =R220 #3, R220 #4, VM #1, VM #2 in Stage 1.5 | 1 x VM #2 (2K HKD - Stage 1.5) Worker | =VM #1, VM #2 in Stage 1.5 |
Thursday, August 14, 2014
Linux, Ubuntu log files location
log message to this file
=> /var/log/dmesg : Linux kernel ring buffer log
=> /var/log/dpkg.log : All binary package log includes package
installation and other information
=> /var/log/faillog : User failed login log file
=> /var/log/kern.log : Kernel log file
=> /var/log/lpr.log : Printer log file
=> /var/log/mail.* : All mail server message log files
=> /var/log/mysql.* : MySQL server log file
=> /var/log/user.log : All userlevel logs
=> /var/log/xorg.0.log : X.org log file
=> /var/log/apache2/* : Apache web server log files directory
=> /var/log/lighttpd/* : Lighttpd web server log files directory
=> /var/log/fsck/* : fsck command log
=> /var/log/apport.log : Application crash report / log file
=> /var/log/messages : General log messages
=> /var/log/boot : System boot log
=> /var/log/debug : Debugging log messages
=> /var/log/auth.log : User login and authentication logs
Tuesday, August 12, 2014
Using pg_prove with pgTap
#> create extension pgtap;
>\q
>pg_prove -d my_database some_test_file.sql
install pg_prove for pgtap
>sudo ./Build
>sudo ./Build installdeps
>sudo ./Build test
>sudo ./Build install
DONE
Check Ubuntu ethernet interface speed.
Wednesday, August 6, 2014
Measure the bandwidth between 2 servers
> sudo apt-get install iperf
Computer A:
> iperf -s
Computer B:
> iperf -c address_of_computer_A
Ubuntu Server reconfigure timezone
>more /etc/timezone
>sudo dpkg-reconfigure tzdata
>sudo service cron stop
>sudo service cron start