Name

addtest

Context

Java type members (Automatically insert Checked)

Pattern

@${testType:newType(org.junit.Test)}
public void test_${name}() {
    ${staticImport:importStatic('org.junit.Assert.*', 'org.hamcrest.Matchers.*')}
}



Name

addlog

Context

Java type members (Automatically insert Checked)

Pattern

private static Logger log = LoggerFactory.getLogger(${enclosing_type}.class);
${imp:import(org.slf4j.Logger, org.slf4j.LoggerFactory)}



Name

addcon

Context

Java type members (Automatically insert Checked)

Pattern

@RequestMapping(value="${uri_name}", method={RequestMethod.GET})
public String ${method_name}(Model model) {
    return "${view_name}";
}
${imp:import(org.springframework.web.bind.annotation.RequestMapping, org.springframework.ui.Model, org.springframework.web.bind.annotation.RequestMethod)}



Name

addspringtest

Context

Java type members (Automatically insert Checked)

Pattern

${imp:import(org.junit.runner.RunWith, org.springframework.test.context.junit4.SpringJUnit4ClassRunner, org.springframework.test.context.ContextConfiguration)}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
        "classpath*:config/spring/context-common.xml",
        "classpath*:config/spring/context-transaction.xml",
        "classpath*:config/spring/context-datasource.xml"
})${cursor}

VIP - 192.168.0.151


1번 서버 - 192.168.0.152

2번 서버 - 192.168.0.153


wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.17.tar.gz

tar xvzf haproxy-1.5.17.tar.gz



uname -r


yum install wget gcc gcc-c++ autoconf automake make openssl openssl-devel pcre-devel zlib


make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1

make install


cp examples/haproxy.init /etc/init.d/haproxy

cp examples/examples.cfg /etc/haproxy/haproxy.cfg


chmod 755 /etc/init.d/haproxy



service haproxy start (or /etc/init.d/haproxy start)




defaults

    mode                    http

    log                     global

    #option                  httplog

    option                  dontlognull

    option http-server-close

    #option forwardfor       except 127.0.0.0/8

    option                  redispatch

    retries                 3

    timeout http-request    10s

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check           10s

    maxconn                 3000


# id

# 101 ~ 200 = HTTP

# 201 ~ 300 = TCP

# 501 ~ 600 = TEST



frontend searchWas

        bind 192.168.0.151:80

        option  httplog

        default_backend searchWas


backend searchWas

        id      101

        stats   enable

        stats   hide-version

        balance roundrobin

        # For Sticky Session

        appsession JSESSIONID len 30 timeout 3h request-learn prefix

        option  httplog

        option  httpchk GET /info.jsp

        option  http-server-close

        option  forwardfor

server search01 192.168.0.101:8080 check inter 2000 fastinter 500 downinter 5000 rise 3 fall 1

server search02 192.168.0.102:8080 check inter 2000 fastinter 500 downinter 5000 rise 3 fall 1


listen aqmp_real 192.168.0.151:5672

        id              201

        mode            tcp

        balance         roundrobin

        timeout client  3h

        timeout server  3h

        option          clitcpka

        server mq11 192.168.0.101:5672 check inter 5s rise 2 fall 3

        server mq21 192.168.0.101:5672 check inter 5s rise 2 fall 3


listen stats 0.0.0.0:40000       #Listen on all IP's on port 9000

    mode http

    balance

    timeout client 5000

    timeout connect 4000

    timeout server 30000


    #This is the virtual URL to access the stats page

    stats uri /haproxy_stats


    #Authentication realm. This can be set to anything. Escape space characters with a backslash.

    stats realm HAProxy\ Statistics


    #The user/pass you want to use. Change this password!

    #stats auth admin:admin


    #This allows you to take down and bring up back end servers.

    #This will produce an error on older versions of HAProxy.

    stats admin if TRUE


yum install keepalived



service rsyslog restart

service keepalived restart

service haproxy restart










[/etc/rsyslog.d/haproxy.conf]

local2.*    /var/log/haproxy.log





1번 서버 [/etc/keepalived/keepalived.conf]

! Configuration File for keepalived

global_defs {

        router_id HAProxy1

}


vrrp_script haproxy {

        script "killall -0 haproxy"

        interval 2

        weight 2

}



vrrp_instance VI_1 {

        debug 2

        virtual_router_id 50

        advert_int 1

        priority 101

        state MASTER

        interface eth0

        virtual_ipaddress {

                192.168.0.151 dev eth0

        }


        track_script {

                haproxy

        }


        notify_master "/etc/keepalived/master.sh"

        notify_backup "/etc/keepalived/backup.sh"

}


2번 서버 [/etc/keepalived/keepalived.conf]

! Configuration File for keepalived


global_defs {

        router_id HAProxy2

}


vrrp_script haproxy {

        script "killall -0 haproxy"

        interval 2

        weight 2

}



vrrp_instance VI_1 {

        debug 2

        virtual_router_id 50

        advert_int 1

        priority 100

        state BACKUP

        interface eth0

        virtual_ipaddress {

                192.168.0.151 dev eth0

        }


        track_script {

                haproxy

        }

}




[/etc/rsyslog.conf]


----------------------------


$ModLoad imudp

$UDPServerRun 514


----------------------------




[/etc/sysctl.conf]


----------------------------


# For keepalived - vrrp

net.ipv4.ip_nonlocal_bind=1


----------------------------





yum install rubygems

gem update

gem update --system


gem install haproxyctl


haproxyctl "enable server wasSearch/search01"

haproxyctl "disable server wasSearch/search01"


curl -d "s=search01&action=maint&b=#101" http://192.168.0.151:8080/haproxy_stats

curl -d "s=search01&action=ready&b=#101" http://192.168.0.151:8080/haproxy_stats


[참조] http://bryan.wiki/243

[참조] https://www.percona.com/blog/2014/10/03/haproxy-give-me-some-logs-on-centos-6-5/

apache 2.2.31

mod_jk 1.2.41

  • Activation
    • Active
    • Disabled
    • Stopped

배포 시  Activation 을 Disabled 시켰는데 이미 접속한 사용자들에 대해서는(쿠키?) 계속 들어와서 Stopped 바꾸니 WAS까지 들어온 요청은 처리 하되 그 이후 모든 요청은 막아줌


무중단 배포 시 WAS 중지 전 jkstatus 에서 Stopped 변경 후 약 3초간의 시간을 주고, 소스 배포 후 재기동 시킨 후 다시 Active 시킨다.

Stopped 후 3초, 5초 후 WAS 재기동 테스트 해보았다.


Servlet 처리 시간이 5초 케이스 만들어서  부하 준 상황에서 이중화 구조로 순차 재기동하니 502 에러 발생!!


더 안 전하게 하려면 Stopped 후 대기 시간을 늘리던가

아니면 WAS의 Running Thread 의 갯수를 명확히 파악 할 수있다면 Running Thread 갯수가 0일때까지 대기 후 WAS를 재기동하면 완벽 하겠군요.

웹서버는 직접적으로 관리를 하지 않아 설치 해볼일이 없었는데 테스트 시 필요해서 설치 해봤다.


[환경 2.4.x 케이스] 하단에 2.2.x 케이스도 있음

CentOS release 6.4 (Final) 64Bit

httpd-2.4.18

apr-1.5.2

apr-util-1.5.4

pcre-8.37

tomcat-connectors-1.2.41

tomcat 8.0.30



mkdir download
cd download/
wget http://apache.mirror.cdnetworks.com//httpd/httpd-2.4.18.tar.gz
tar xvzf httpd-2.4.18.tar.gz

wget http://mirror.apache-kr.org/apr/apr-1.5.2.tar.gz
tar xvzf apr-1.5.2.tar.gz

wget http://mirror.apache-kr.org/apr/apr-util-1.5.4.tar.gz
tar xvzf apr-util-1.5.4.tar.gz

mv apr-1.5.2 httpd-2.4.18/srclib/apr
mv apr-util-1.5.4 httpd-2.4.18/srclib/apr-util

wget http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gz/download
tar xvzf pcre-8.37.tar.gz
cd pcre-8.37
./configure --enable-unicode-properties=yes
make && make install

./configure \
--prefix=/usr/local/tomcat/apache-2.4.18 \
--enable-so \
--enable-rewrite \
--enable-proxy \
--enable-ssl \
--enable-mods-shared=all \
--enable-modules=shared \
--enable-mpms-shared=all \
--with-included-apr \
--with-included-apr-util
make && make install
/usr/local/tomcat/apache-2.4.18/bin/httpd -V
chown root:sys /usr/local/tomcat/apache-2.4.18/bin/httpd
chmod +s /usr/local/tomcat/apache-2.4.18/bin/httpd
/usr/local/tomcat/apache-2.4.18/httpd.conf
	ServerName localhost // 주석 해제 및 설정	
	LoadModule slotmem_shm_module modules/mod_slotmem_shm.so // 주석 해제


/usr/local/tomcat/apache-2.4.18/bin/httpd -k start
/usr/local/tomcat/apache-2.4.18/bin/httpd -k stop

wget http://apache.tt.co.kr/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz
tar xvzf tomcat-connectors-1.2.41-src.tar.gz 
cd tomcat-connectors-1.2.41-src/native
./configure --with-apxs=/usr/local/tomcat/apache-2.4.18/bin/apxs
make && make install
ls -l /usr/local/tomcat/apache-2.4.18/modules/mod_jk.so

cp 톰켓롬/bin/tomcat-native.tar.gz .
tar xvzf tomcat-native.tar.gz
cd tomcat-native-1.1.33-src/jni/native

./configure --with-apr=/usr/local/tomcat/apache-2.4.18/bin/apr-1-config --prefix=/usr/local/tomcat/apache-tomcat-8.0.30
make && make install

톰캣 설정
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
export LD_LIBRARY_PATH


Include conf/extra/mod_jk.conf	

vi /usr/local/tomcat/apache-2.4.18/conf/httpd.conf
	# Virtual hosts
	Include conf/extra/httpd-vhosts.conf					// 주석 해제	
	# Various default settings
	Include conf/extra/httpd-default.conf					// 주석 해제
	Include conf/extra/mod_jk.conf	

	
vi vi /usr/local/tomcat/apache-2.4.18/conf/extra/mod_jk.conf	
	# -----------------------------------------
	#       DAK TEST Apache Httpd WebServer
	#
	#       contact : ddakker@ddakker.com
	# -----------------------------------------

	# Load mod_jk module
	# Update this path to match your modules location
	LoadModule jk_module          modules/mod_jk.so

	# Where to find workers.properties
	# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
	JkWorkersFile conf/extra/workers.properties

	# Where to put jk logs
	# Update this path to match your logs directory location (put mod_jk.log next to access_log)
	JkLogFile     "|logs/mod_jk.log logs/mod_jk.log_%m%d%Y"

	JkShmFile     logs/mod_jk.shm

	# Set the jk log level [debug/error/info]
	JkLogLevel    info

	# Select the log format
	JkLogStampFormat "[%Y-%m-%d %H:%M:%S] "
	# JkOptions indicate to send SSL KEY SIZE,
	JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories +ForwardURICompatUnparsed

	# JkRequestLogFormat set the request format
	JkRequestLogFormat     "%w %V %T %R %s %U"

	# Send everything for context /examples to worker named worker1 (ajp13)
	JkMount  /jkstatus* jkstatus

	<location /jkstatus>
		JkMount jkstatus
		Order Deny,Allow
		Allow from 127.0.0.1
		Allow from 192
		Deny from all
	</location>

vi /usr/local/tomcat/apache-2.4.18/conf/extra/workers.properties
	# -----------------------------------------
	#       DAK TEST Apache Httpd WebServer
	#
	#       contact : ddakker@naver.com
	# -----------------------------------------

	worker.list=jkstatus,testcluster

	# Templates
	worker.template.type=ajp13
	worker.template.maintain=60
	worker.template.lbfactor=1
	worker.template.ping_mode=A
	worker.template.ping_timeout=2000
	worker.template.prepost_timeout=2000
	worker.template.socket_timeout=300
	worker.template.socket_connect_timeout=2000
	worker.template.socket_keepalive=true
	worker.template.connection_pool_timeout=300
	worker.template.connect_timeout=10000
	worker.template.recovery_options=7
	
	
	
	worker.testcluster11.reference=worker.template
	worker.testcluster11.host=192.168.0.2
	worker.testcluster11.port=9401
	
	worker.testcluster21.reference=worker.template
	worker.testcluster21.host=192.168.0.3
	worker.testcluster21.port=9401
	
	
	# -------- LB ------------
	
	
	worker.testcluster.type=lb
	worker.testcluster.method=Session
	worker.testcluster.sticky_session=True
	worker.testcluster.balance_workers=testcluster11,testcluster21
	
	
	
	worker.jkstatus.type=status
	
vi httpd-vhosts.conf
	NameVirtualHost *:80


	# Vhost - Tomcat Service
	Include conf/extra/vhost-tomcat.conf

vi vhost-tomcat.conf
	<virtualhost *:80>
		DocumentRoot "/data/webroot/test-cluster/webapp"

		ServerName testcluster.ddakker.pe.kr
		ServerAlias cluster.ddakker.pe.kr

		#ErrorLog "|/usr/sbin/cronolog /usr/local/tomcat/apache2/logs/cluster.ddakker.pe.kr-error_log.%m%d%Y"
		#CustomLog "|/usr/sbin/cronolog/usr/local/tomcat/apache2/logs/cluster.ddakker.pe.kr-access_log.%m%d%Y" combined
		DirectoryIndex /index.html /index.jsp

		JkUnMount   /*.js   testcluster
		JkUnMount   /*.css  testcluster
		JkUnMount   /*.jpg  testcluster
		JkUnMount   /*.png  testcluster
		JkUnMount   /*.gif  testcluster
		JkUnMount   /*.htm  testcluster
		JkUnMount   /*.html testcluster
		JkUnMount   /*.ico  testcluster
		JkUnMount   /*.eot  testcluster
		JkUnMount   /*.woff testcluster
		JkMount     /*      testcluster
		JkMount  /jkstatus* jkstatus

		<directory "/data/webroot/test-cluster/webapp">
                		Options FollowSymLinks
				AllowOverride None
				<ifversion < 2.3>
					Order allow,deny
					Allow from all
				</ifversion>
				<ifversion >= 2.3>
					Require all granted
				</ifversion>
		</directory>
	</VirtualHost>

	




[환경 2.2.x 케이스]

CentOS release 6.4 (Final) 64Bit

httpd-2.2.31

tomcat-connectors-1.2.41



wget http://apache.mirror.cdnetworks.com/httpd/httpd-2.2.31.tar.gz
tar xvzf httpd-2.2.31.tar.gz
cd httpd-2.2.31
./configure --prefix=/usr/local/tomcat/apache2
make
make install

chown root:sys /usr/local/tomcat/apache2/bin/httpd
chmod +s /usr/local/tomcat/apache2/bin/httpd

/usr/local/tomcat/apache2/bin/httpd -k start
/usr/local/tomcat/apache2/bin/httpd -k stop

wget http://apache.tt.co.kr/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz
tar xvzf tomcat-connectors-1.2.41-src.tar.gz 
cd tomcat-connectors-1.2.41-src/native
./configure --with-apxs=/usr/local/tomcat/apache2/bin/apxs
make
make install

ls -l /usr/local/tomcat/apache2/modules/mod_jk.so
cd /usr/local/tomcat/apache2/conf
vi httpd.conf
	# Virtual hosts
	Include conf/extra/httpd-vhosts.conf
	
	# Various default settings
	Include conf/extra/httpd-default.conf
	
	Include conf/extra/mod_jk.conf	

vi /extra/mod_jk.conf	
	# -----------------------------------------
	#       DAK TEST Apache Httpd WebServer
	#
	#       contact : ddakker@ddakker.com
	# -----------------------------------------

	#LoadModule jk_module modules/mod_jk.so
	#
	#	JkWorkersFile    conf/extra/workers.properties
	#	JkLogFile        logs/mod_jk.log
	#	JkLogLevel       info
	#
	# Load mod_jk module
	# Update this path to match your modules location
	LoadModule jk_module          modules/mod_jk.so

	# Where to find workers.properties
	# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
	JkWorkersFile conf/extra/workers.properties

	# Where to put jk logs
	# Update this path to match your logs directory location (put mod_jk.log next to access_log)
	JkLogFile     "|logs/mod_jk.log logs/mod_jk.log_%m%d%Y"

	JkShmFile     logs/mod_jk.shm

	# Set the jk log level [debug/error/info]
	JkLogLevel    info

	# Select the log format
	JkLogStampFormat "[%Y-%m-%d %H:%M:%S] "
	# JkOptions indicate to send SSL KEY SIZE,
	JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories +ForwardURICompatUnparsed

	# JkRequestLogFormat set the request format
	JkRequestLogFormat     "%w %V %T %R %s %U"

	# Send everything for context /examples to worker named worker1 (ajp13)
	JkMount  /jkstatus* jkstatus

	<location /jkstatus>
		JkMount jkstatus
		Order Deny,Allow
		Allow from 127.0.0.1
		Allow from 192
		Deny from all
	</location>
	
vi extra/workers.properties
	# -----------------------------------------
	#       DAK TEST Apache Httpd WebServer
	#
	#       contact : ddakker@naver.com
	# -----------------------------------------

	worker.list=jkstatus,testcluster

	# Templates
	worker.template.type=ajp13
	worker.template.maintain=60
	worker.template.lbfactor=1
	worker.template.ping_mode=A
	worker.template.ping_timeout=2000
	worker.template.prepost_timeout=2000
	worker.template.socket_timeout=300
	worker.template.socket_connect_timeout=2000
	worker.template.socket_keepalive=true
	worker.template.connection_pool_timeout=300
	worker.template.connect_timeout=10000
	worker.template.recovery_options=7
	
	
	
	worker.testcluster11.reference=worker.template
	worker.testcluster11.host=192.168.0.2
	worker.testcluster11.port=9401
	
	worker.testcluster21.reference=worker.template
	worker.testcluster21.host=192.168.0.3
	worker.testcluster21.port=9401
	
	
	# -------- LB ------------
	
	
	worker.testcluster.type=lb
	worker.testcluster.method=Session
	worker.testcluster.sticky_session=True
	worker.testcluster.balance_workers=testcluster11,testcluster21
	
	
	
	worker.jkstatus.type=status
	
vi httpd-vhosts.conf
	NameVirtualHost *:80


	# Vhost - Tomcat Service
	Include conf/extra/vhost-tomcat.conf

vi vhost-tomcat.conf
	<virtualhost *:80>
		DocumentRoot "/data/webroot/test-cluster/webapp"

		ServerName testcluster.ddakker.pe.kr
		ServerAlias cluster.ddakker.pe.kr

		#ErrorLog "|/usr/sbin/cronolog /usr/local/tomcat/apache2/logs/cluster.ddakker.pe.kr-error_log.%m%d%Y"
		#CustomLog "|/usr/sbin/cronolog/usr/local/tomcat/apache2/logs/cluster.ddakker.pe.kr-access_log.%m%d%Y" combined
		DirectoryIndex /index.html /index.jsp

		JkUnMount   /*.js   testcluster
		JkUnMount   /*.css  testcluster
		JkUnMount   /*.jpg  testcluster
		JkUnMount   /*.png  testcluster
		JkUnMount   /*.gif  testcluster
		JkUnMount   /*.htm  testcluster
		JkUnMount   /*.html testcluster
		JkUnMount   /*.ico  testcluster
		JkUnMount   /*.eot  testcluster
		JkUnMount   /*.woff testcluster
		JkMount     /*      testcluster
		JkMount  /jkstatus* jkstatus

		<directory "/data/webroot/test-cluster/webapp">
                		Options FollowSymLinks
				AllowOverride None
				<ifversion < 2.3>
					Order allow,deny
					Allow from all
				</ifversion>
				<ifversion >= 2.3>
					Require all granted
				</ifversion>
		</directory>

	</virtualhost>

vi /usr/local/tomcat/webroot/test-cluster/webapp/index.html
	

index.html

vi /usr/local/tomcat/webroot/test-cluster/webapp/info.jsp <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@page import="java.net.InetAddress"%> <% String serverIP = ""; try{ serverIP = InetAddress.getLocalHost().getHostAddress(); serverIP = serverIP.substring(serverIP.lastIndexOf(".")+1); }catch(Exception e){} String info = request.getServerName() + ", " + serverIP + ", " + System.getProperty("jvmRoute"); out.print(info); //System.out.println(info); %> vi /etc/hosts 127.0.0.1 localhost testcluster.ddakker.pe.kr wget http://testcluster.ddakker.pe.kr/index.html wget http://testcluster.ddakker.pe.kr/info.jsp wget http://testcluster.ddakker.pe.kr/jkstatus



[tomcat & tomcat-native 만 설치]

wget http://mirror.apache-kr.org/apr/apr-1.5.2.tar.gz
tar xvzf apr-1.5.2.tar.gz
./configure
make & make install

wget http://mirror.apache-kr.org/apr/apr-util-1.5.4.tar.gz
tar xvzf apr-util-1.5.4.tar.gz
./configure --with-apr=/usr/local/apr
make & make install

tar xvzf tomcat-native.tar.gz
./configure --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

LD_LIBRARY_PATH=/usr/local/apr/lib
export LD_LIBRARY_PATH

json-lib, com.fasterxml.jackson 둘의 차이점을 비교해본다.

별다른 옵션 없는 심플한 상황이다.

json-lib의 경우 Object형의 NULL 변환에 문제가 있어보인다.


[JsonTest .java]

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

public class JsonTest {
	@Test
	public void test_jsonlib_BeanCase() {
		try {
			TestBean inBean = new TestBean();
			inBean.setA("a Value");
			inBean.setB("");
			inBean.setC(null);
			//inBean.setD();
			
			inBean.setInt11(1);
			//inBean.setInt12();
			inBean.setInt21(1);
			inBean.setInt21(null);
			
			inBean.setBool11(true);
			//inBean.setBool12();
			inBean.setBool21(true);
			inBean.setBool21(null);
			
			JSONObject jsonObj = JSONObject.fromObject( JSONSerializer.toJSON(inBean) );
			String jsonStr = jsonObj.toString();
			System.out.println("jsonStr: " + jsonStr);
			
			jsonObj = (JSONObject) JSONObject.fromObject(jsonStr);
			TestBean outBean = (TestBean) JSONObject.toBean(jsonObj, TestBean.class);
			System.out.println(outBean);
			
			assertEquals(inBean.getA(), outBean.getA());
			assertEquals(inBean.getB(), outBean.getB());
			//assertEquals(inBean.getC(), outBean.getC());				// 문제 소지
			//assertEquals(inBean.getD(), outBean.getD());				// 문제 소지
			
			assertEquals(outBean.getC(), "");
			assertEquals(outBean.getD(), "");
			
			assertEquals(inBean.getInt11(), outBean.getInt11());
			assertEquals(inBean.getInt12(), outBean.getInt12());
			//assertEquals(inBean.getInt21(), outBean.getInt21());		// 문제 소지(아예 변환 안됨)
			//assertEquals(inBean.getInt22(), outBean.getInt22());		// 문제 소지(아예 변환 안됨)
			assertEquals(outBean.getInt21(), new Integer(0));
			assertEquals(outBean.getInt22(), new Integer(0));
			
			assertEquals(inBean.isBool11(), outBean.isBool11());
			assertEquals(inBean.isBool12(), outBean.isBool12());
			//assertEquals(inBean.getBool21(), outBean.getBool21());	// 문제 소지(아예 변환 안됨)
			//assertEquals(inBean.getBool22(), outBean.getBool22());	// 문제 소지(아예 변환 안됨)
			assertEquals(outBean.getBool21(), new Boolean(false));
			assertEquals(outBean.getBool22(), new Boolean(false));
		} catch (Exception e) {
			System.err.println("-- e: " + e);
		}
		
	}
	
	@Test
	public void test_jackson_BeanCase() {
		try {
			ObjectMapper jacksonMapper = new ObjectMapper();
			
			TestBean inBean = new TestBean();
			inBean.setA("a Value");
			inBean.setB("");
			inBean.setC(null);
			//inBean.setD();
			
			inBean.setInt11(1);
			//inBean.setInt12();
			inBean.setInt21(1);
			inBean.setInt21(null);
			
			inBean.setBool11(true);
			//inBean.setBool12();
			inBean.setBool21(true);
			inBean.setBool21(null);
			System.out.println(inBean);
			
			String jsonStr = jacksonMapper.writeValueAsString(inBean);
			System.out.println("jsonStr: " + jsonStr);
			TestBean outBean = jacksonMapper.readValue(jsonStr, TestBean.class);
			
			assertEquals(inBean.getA(), outBean.getA());
			assertEquals(inBean.getB(), outBean.getB());
			assertEquals(inBean.getC(), outBean.getC());
			assertEquals(inBean.getD(), outBean.getD());
			assertEquals(outBean.getC(), null);
			assertEquals(outBean.getD(), null);
			
			assertEquals(inBean.getInt11(), outBean.getInt11());
			assertEquals(inBean.getInt12(), outBean.getInt12());
			assertEquals(inBean.getInt21(), outBean.getInt21());
			assertEquals(inBean.getInt22(), outBean.getInt22());
			
			assertEquals(inBean.isBool11(), outBean.isBool11());
			assertEquals(inBean.isBool12(), outBean.isBool12());
			assertEquals(inBean.getBool21(), outBean.getBool21());
			assertEquals(inBean.getBool22(), outBean.getBool22());
		} catch (IOException e) {
			System.err.println("-- e: " + e);
		}
	}
}

[TestBean.java]

import lombok.Getter;
import lombok.Setter;

@Setter @Getter
public class TestBean {
	String a;
	String b;
	String c;
	String d;
	
	int int11;
	int int12;
	Integer int21;
	Integer int22;
	
	boolean bool11;
	boolean bool12;
	Boolean bool21;
	Boolean bool22;
}

[build.gradle]

sourceCompatibility='1.7'

dependencies {
    //compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    //compile 'org.apache.maven.plugins:maven-war-plugin:+'
    
    compile 'net.sf.json-lib:json-lib:2.4:jdk15@jar'
    compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.6.4'
    
    compile 'commons-lang:commons-lang:2.6'
    compile 'commons-logging:commons-logging:1.2'
    compile 'commons-collections:commons-collections:3.2.2'
    compile 'commons-beanutils:commons-beanutils:1.9.2'
    compile 'net.sf.ezmorph:ezmorph:1.0.6'
    
    testCompile 'junit:junit:4.11'
	testCompile 'org.hamcrest:hamcrest-all:1.3'
}


import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.StringUtils;

// 자연수 + 공백
assertFalse(StringUtils.isNumeric(null));
assertTrue (StringUtils.isNumeric(""));
assertFalse(StringUtils.isNumeric("  "));
assertTrue (StringUtils.isNumeric("0"));
assertTrue (StringUtils.isNumeric("123"));
assertFalse(StringUtils.isNumeric("12 3"));
assertFalse(StringUtils.isNumeric("ab2c"));
assertFalse(StringUtils.isNumeric("12-3"));
assertFalse(StringUtils.isNumeric("12.3"));
assertFalse(StringUtils.isNumeric("-123"));
assertFalse(StringUtils.isNumeric("+123"));

// 자연수
assertFalse(NumberUtils.isDigits(null));
assertFalse(NumberUtils.isDigits(""));
assertFalse(NumberUtils.isDigits("  "));
assertTrue (NumberUtils.isDigits("0"));
assertTrue (NumberUtils.isDigits("123"));
assertFalse(NumberUtils.isDigits("12 3"));
assertFalse(NumberUtils.isDigits("ab2c"));
assertFalse(NumberUtils.isDigits("12-3"));
assertFalse(NumberUtils.isDigits("12.3"));
assertFalse(NumberUtils.isDigits("-123"));
assertFalse(NumberUtils.isDigits("+123"));

// 정수 + 실수 (+ 앞에 붙으면 안됨)
assertFalse(NumberUtils.isNumber(null));
assertFalse(NumberUtils.isNumber(""));
assertFalse(NumberUtils.isNumber("  "));
assertTrue (NumberUtils.isNumber("0"));
assertTrue (NumberUtils.isNumber("123"));
assertFalse(NumberUtils.isNumber("12 3"));
assertFalse(NumberUtils.isNumber("ab2c"));
assertFalse(NumberUtils.isNumber("12-3"));
assertTrue (NumberUtils.isNumber("12.3"));
assertTrue (NumberUtils.isNumber("-123"));
assertFalse(NumberUtils.isNumber("+123"));
	
		...
		
		...
	

	...

	
		
	
	
	
		
        
	

	

	
		
			
			
		
	

	...

Cluster 된 개별 WAS들이 모두 정상적으로 가동되고 있는지 모니터링 화면에서 표현해보자.


기준은 각 WAS의 Memory MBean 정보를 활용해서 WAS가 정상적인지도 체크 하고, 현재 Memory 상황은 어떤지 파악도 함께 할 수 있게 해본다.


[각각의 WAS Agent] -> vertx Net-> [모니터링 서버] -> vertx SockJs -> [Client Broswer] 방향으로 Memory 정보를 보낸다.



장애판단 기준은 WAS Agent에서 현재 5초 기준으로 모니터링 서버쪽으로 보내주고 있다.

그에 따라 Client Borswer 부분에서는 해당 정보가 (5초*1.5) 이후에도 정보가 오지 않으면 서버가 내려갔다고 판단한다.


또한 이 정보를 DB화 하여, Memory 증가량을 파악하고, GC 이후에도 Memory 가 부족하지는 않은지 판단해본다.






[MonitorAgent.java]

import java.lang.instrument.Instrumentation;
import java.util.Timer;

import pe.kr.ddakker.monitor.agent.timer.MBeanTimer;

public class MonitorAgent {
	Timer timer = new Timer("ddakker Agent Timer", true);
    Instrumentation instrumentation;
    static MonitorAgent monitorAgent;
    public static boolean isDebug = false;
	
	public static void premain(String args, Instrumentation instrumentation) throws Exception {
		
		//instrumentation.addTransformer(new TomcatTransformer());
		monitorAgent = new MonitorAgent(instrumentation);
		monitorAgent.start();
	}

	public final void start(boolean isRequest, boolean isMBean) {
		MBeanTimer mBeanTimer = new MBeanTimer();
        timer.scheduleAtFixedRate(mBeanTimer, 5000, 5000);
	}
}


[MBeanTimer.java]

import java.lang.management.ManagementFactory;
import java.util.TimerTask;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;

import pe.kr.ddakker.monitor.agent.send.VertxClient;

public class MBeanTimer extends TimerTask {
	public void run() {
		try {
			ObjectName om = new ObjectName("java.lang:type=Memory");
			
			MBeanServer connection = ManagementFactory.getPlatformMBeanServer();
			
			
			Object attrValue = connection.getAttribute(om, "HeapMemoryUsage");
			
			long max = Long.parseLong(((CompositeData)attrValue).get("max").toString());
			long used = Long.parseLong(((CompositeData)attrValue).get("used").toString());
			long heapUsedPercent = Math.round((used*1.0 / max*1.0) * 100.0);
			
			String msg = "{name: '" + System.getProperty("jvmRoute") + "', heapUsedPercent: '" + heapUsedPercent + "', time: '" + System.currentTimeMillis() + "'}";
			msg = "{result: '0000', grp: 'grp_was', msg: '성공', data: " + msg + "}";
			
			VertxClient.send(msg);
		} catch (Exception e) {
			System.err.println();
		}

	}

}


slf4j + logback 환경에서 이니지스 결재 모듈(INIpay50.jar) 사용 시 이니시스 로깅에 문제가 발생한다.


이니시스측에서도 log4j 를 사용하라고 권고한 상황..


하지만 쓰고 싶다면...


'org.slf4j:log4j-over-slf4j' 부분을 exclude 하면 된다.



※ 'org.slf4j:log4j-over-slf4j' 는 기존 라이브러리가 log4j를 사용하고 있을때, slf4j로 넘겨주는 역할은 하는거란다.


Gradle 에서 jar를 생성할때 의존된 jar들 포함시켜서 말고 싶을때가 있다.


https://github.com/musketyr/gradle-fatjar-plugin


buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
    }
}

apply plugin: 'eu.appsatori.fatjar'

+ Recent posts