miércoles, junio 26, 2013

Construyendo archivos .ear para deployar aplicaciones en un java application server



El .ear es un .zip con extensión .ear, que se puede crear con un programa para hacer .zip común y corriente, el truco esta en la estructura de archivos que debe tener:

META-INF
META-INF/application.xml
META-INF/MANIFEST.MF

se debe incluir un archivo META-INF/application.xml
con un contenido donde especificamos las apps y modulos a desplegar, cuyas rutas () son relativas al contenido del .ear


<!--xml version="1.0" encoding="UTF-8"?--> <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Application_ID" version="1.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"> <display-name>APPNAME_LABEL_FOR_APPSERVER</display-name> <module> <web> <web-uri>WEBAPP.war</web-uri> <context-root>/WEB_EXPOSED_PATH</context-root> </web> </module> </application>

viernes, junio 21, 2013

Proporcionar soporte a equipos remotos linux

Una forma sencilla para compartir el escritorio de máquinas con linux, windows o mac, y conectarse, es TeamViewer, funciona incluso cuando estamos detras de firewalls.


Otra opción, libre es VNC.

Para hacer conección, en este caso cuando a quien queremos ayudar esta detras de firewall y no lo puede remediar, es (ejectar los comandos desde la linea de comandos ej. xterm ó gnome-terminal ó konsole):

1. abrir el vncviewer en nuestro equipo en modo listen (nuestro equipo debe tener un puerto abierto en internet por default se usa el 5500)

vncviewer -listen

2. le proporcionamos a la persona que vamos a ayudar nuestro IP público donde esta escuchando nuestro vncviewer, ej. 74.125.225.238

3. el cliente al que vamos a ayudar en su equipo linux abre el servidor de vnc para la sesión de X principal (debe tener instalado el paquete x11vnc (sudo apt-get install x11vnc) )

x11vnc -connect 74.125.225.238

con esto comparte su escritorio para que podamos ayudarlo, en cualquier momento puede quitarnos el control interrumpiendo el programa (ctrl+c)

jueves, junio 06, 2013

PHP script to generate DB

La idea de este script php es generar un sql DDL para generar algunas bastantes tablas en una base sql.
<?php

header('Content-Type: text/plain; charset=utf-8');

$no_tablas = 40;
$type_a = explode('|','int|varchar(20)|char(5)|decimal(10,2)|date|time');

for($i=1; $i<=$no_tablas; $i++){
 $no_campos = rand(3,12);
 $foreign = (rand(0,1))? true: false;
 $foreign_str = '';
 $campos = array();
 $campos[] = "\tid int not null primary key";
 for($j=1; $j<=$no_campos; $j++){
  $ctype = $type_a[ rand(0,count($type_a)-1) ];
  if ($foreign && $ctype=='int' && $foreign_str==''){
   $dest_tbl = "tabla_".rand(1,$i-1);
   $foreign_str = "\tforeign_key (campo_$j) references $dest_tbl(id)";
   $nullable = 'not null';
  } else {
   $nullable = (rand(0,1)==1) ? 'not null': '';
  }
  $campos[] = "\tcampo_$j $ctype $nullable";
 }
 $campos_str = join(",\n",$campos);

 echo <<<EOF
create table tabla_$i (
$campos_str
$foreign_str
);


EOF;
}

?>
Una muestra del archivo de salida, es algo así:
create table tabla_1 (
 id int not null primary key,
 campo_1 varchar(20) ,
 campo_2 date not null,
 campo_3 time not null,
 campo_4 char(5) not null,
 campo_5 char(5) ,
 campo_6 date not null,
 campo_7 date not null,
 campo_8 int not null,
 campo_9 char(5) not null,
 campo_10 date not null
 foreign_key (campo_8) references tabla_1(id)
);

create table tabla_2 (
 id int not null primary key,
 campo_1 time ,
 campo_2 varchar(20) ,
 campo_3 date not null,
 campo_4 time ,
 campo_5 char(5) ,
 campo_6 decimal(10,2) ,
 campo_7 time 

);

create table tabla_3 (
 id int not null primary key,
 campo_1 varchar(20) ,
 campo_2 varchar(20) not null,
 campo_3 time ,
 campo_4 time ,
 campo_5 int ,
 campo_6 time not null,
 campo_7 char(5) ,
 campo_8 time ,
 campo_9 decimal(10,2) ,
 campo_10 date 

);

Comparación de programas de compresión vs versión paralela.

Comparación de los programas de compresión, tiempos y tamaños, se usan versión mono y versión paralela.

gzip

pv TABLA_QYDTTK4_F130604.TXT | gzip > TABLA_QYDTTK4_F130604.txt.gz
1.04GiB 0:00:45 [23.5MiB/s] [====================================================>] 100%
pv TABLA_QYDTTK4_F130604.TXT | pigz > TABLA_QYDTTK4_F130604.txt.pig.gz
1.04GiB 0:00:04 [ 236MiB/s] [====================================================>] 100%

bzip2

pv TABLA_QYDTTK4_F130604.TXT | bzip2 > TABLA_QYDTTK4_F130604.txt.bz2
1.04GiB 0:04:55 [3.59MiB/s] [====================================================>] 100%
pv TABLA_QYDTTK4_F130604.TXT | lbzip2 > TABLA_QYDTTK4_F130604.txt.lbzip2.bz2
1.04GiB 0:00:07 [ 134MiB/s] [====================================================>] 100%
pv TABLA_QYDTTK4_F130604.TXT | pbzip2 > TABLA_QYDTTK4_F130604.txt.pbzip2.bz2
1.04GiB 0:00:26 [39.3MiB/s] [====================================================>] 100%

xz

pv TABLA_QYDTTK4_F130604.TXT | xz > TABLA_QYDTTK4_F130604.txt.xz
1.04GiB 0:11:02 [ 1.6MiB/s] [====================================================>] 100%
pv TABLA_QYDTTK4_F130604.TXT | pxz > TABLA_QYDTTK4_F130604.txt.pxz.xz
1.04GiB 0:01:06 [15.9MiB/s] [====================================================>] 100%
pv TABLA_QYDTTK4_F130604.TXT | pixz > TABLA_QYDTTK4_F130604.txt.pixz.xz
1.04GiB 0:00:58 [18.1MiB/s] [====================================================>] 100%

human readable sizes

-rw-r--r-- 1 jobs jobs 1.1G jun  5 06:28 TABLA_QYDTTK4_F130604.TXT
-rw-r--r-- 1 jobs jobs  86M jun  5 13:11 TABLA_QYDTTK4_F130604.rar
-rw-r--r-- 1 jobs jobs 101M jun  6 11:23 TABLA_QYDTTK4_F130604.txt.gz
-rw-r--r-- 1 jobs jobs 101M jun  6 11:31 TABLA_QYDTTK4_F130604.txt.pig.gz
-rw-r--r-- 1 jobs jobs  80M jun  6 11:29 TABLA_QYDTTK4_F130604.txt.bz2
-rw-r--r-- 1 jobs jobs  80M jun  6 12:16 TABLA_QYDTTK4_F130604.txt.lbzip2.bz2
-rw-r--r-- 1 jobs jobs  80M jun  6 12:21 TABLA_QYDTTK4_F130604.txt.pbzip2.bz2
-rw-r--r-- 1 jobs jobs  63M jun  6 12:02 TABLA_QYDTTK4_F130604.txt.pixz.xz
-rw-r--r-- 1 jobs jobs  63M jun  6 11:55 TABLA_QYDTTK4_F130604.txt.pxz.xz
-rw-r--r-- 1 jobs jobs  63M jun  6 11:49 TABLA_QYDTTK4_F130604.txt.xz

sizes, more detail

-rw-r--r-- 1 jobs jobs 1112120271 jun  5 06:28 TABLA_QYDTTK4_F130604.TXT
-rw-r--r-- 1 jobs jobs   90148917 jun  5 13:11 TABLA_QYDTTK4_F130604.rar

-rw-r--r-- 1 jobs jobs  105128200 jun  6 11:23 TABLA_QYDTTK4_F130604.txt.gz
-rw-r--r-- 1 jobs jobs  105153673 jun  6 11:31 TABLA_QYDTTK4_F130604.txt.pig.gz

-rw-r--r-- 1 jobs jobs   82889350 jun  6 11:29 TABLA_QYDTTK4_F130604.txt.bz2
-rw-r--r-- 1 jobs jobs   83134496 jun  6 12:16 TABLA_QYDTTK4_F130604.txt.lbzip2.bz2
-rw-r--r-- 1 jobs jobs   82913562 jun  6 12:21 TABLA_QYDTTK4_F130604.txt.pbzip2.bz2

-rw-r--r-- 1 jobs jobs   65921560 jun  6 12:02 TABLA_QYDTTK4_F130604.txt.pixz.xz
-rw-r--r-- 1 jobs jobs   65884988 jun  6 11:55 TABLA_QYDTTK4_F130604.txt.pxz.xz
-rw-r--r-- 1 jobs jobs   65667608 jun  6 11:49 TABLA_QYDTTK4_F130604.txt.xz

Notas:
Se uso un archivo de texto de 1.04 Gb, en una workstation con 64Gb de RAM usando /dev/shm, sistema operativo Gentoo, y el software se compilo del repositorio.

extract specific lines from text file

For the example we use to variables L1 for the first line number, L2 for the last line number.

L1=21
L2=33
FILE=x.txt

awk method:

awk -e "NR>=$L1&&NR<=$L2{print \$0}" $FILE

sed method:

sed -n "$L1,$L2 p" $FILE

head + tail method:

head -n $L2 $FILE | tail -n $(($L2-$L1+1))