WebSphere® Application Server 관리
API(Application Programming Interface) 및 JMX(Java™ Management
Extensions)를 활용하는 관리 클라이언트 프로그램을 개발할 수 있습니다.
이 태스크 정보
제품 관리 API는 구성을 업데이트할 수 있는 기능 뿐만 아니라 분배 시스템의
조작 측면에 대한 제어를 제공합니다.
AdminClient 인터페이스에 대한 정보는 API(Application Programming Interface) 문서를 참조하십시오.
MBean 조작 예를 참조하십시오. MBean 프로그래밍에 대한 정보는
MBean Java
API 문서를 참조하십시오.이 Information Center에서 를 클릭하십시오.
이 예에서는
사용자 제품에 사용할 수 없는 NodeAgent MBean을 가져와 사용하는 방법을 설명합니다.
그러나 NodeAgent MBean을 가져다 놓는 방법에 대한 설명은 사용자 제품에 사용할 수 있는
다른 MBean에 대해 수행하는 조치와 유사합니다.
프로시저
- AdminClient 인스턴스를 작성하십시오.
관리 클라이언트 프로그램은
기본 설치의 Application Server에서 실행 중인 AdminService 오브젝트에 대한 메소드를 호출해야 합니다.
AdminClient 클래스는 지원되는
JMX(Java
Management Extensions) 커넥터 중 하나를 통해 원격 AdminService 오브젝트에 프록시를 제공합니다.
- 다음 예제는 SOAP(Simple Object Access Protocol) 커넥터에 대한
AdminClient 인스턴스를 작성하는 방법을 표시합니다.
Properties connectProps = new Properties();
connectProps.setProperty(
AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost");
connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8879");
connectProps.setProperty(AdminClient.USERNAME, "test2");
connectProps.setProperty(AdminClient.PASSWORD, "user24test");
AdminClient adminClient = null;
try
{
adminClient = AdminClientFactory.createAdminClient(connectProps);
}
catch (ConnectorException e)
{
System.out.println("Exception creating admin client: " + e);
}
- 특성 오브젝트를 설정하십시오.
예제에서는
서버를 시작하는 데 필요한 특성이 있는 특성 오브젝트를 설정합니다. 이 경우에는
SOAP 커넥터를 사용하여 서버에 연결하십시오. 커넥터 유형의 경우,
AdminClient.CONNECTOR_TYPE_SOAP 값을 사용하십시오.
![[AIX Solaris HP-UX Linux Windows]](../images/dist.gif)
간단히, 서버와 동일한 시스템에서 클라이언트 프로그램을 실행하십시오. 호스트 이름으로
localhost를 사용합니다. 로컬 호스트 대신 원격 호스트에 액세스하려면
해당 호스트에 대해 네트워크 분석 가능 이름을 사용하십시오.
- 서버 SOAP 커넥터가 청취 중인 포트 번호를 설정하십시오.
단일 서버 설치에서는 Application Server SOAP 커넥터의
기본 포트 번호가 8880입니다.
- 연결 특성이 설정된 후, AdminClientFactory 클래스 및
Properties 오브젝트를 사용하여 사용자가 선택한 서버에 연결된
AdminClient 오브젝트를 작성하십시오.
원하는 프로토콜 및 보안 환경 같은 요소에 따라,
다른 특성을 설정해야 할 수도 있습니다.
예를 들어, 애플리케이션 클라이언트 프로그램에 보안을 사용하려면
javax.net.ssl.* 특성을 포함하십시오. AdminClient 인터페이스, javax.net.ssl.* 특성 및 추가 작성 예제에 대한 자세한 정보는
API(Application Programming Interface) 문서에서 AdminClient 인터페이스를 참조하십시오.
- 다음 예제는 RMI(Remote Method Invocation) 커넥터에 대한
AdminClient 인스턴스를 작성하는 방법을 표시합니다. 일부 명령은 인쇄를 위해
여러 줄로 표시됩니다.
Properties connectProps = new Properties();
connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_RMI);
connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost");
connectProps.setProperty(AdminClient.CONNECTOR_PORT, "2809");
connectProps.setProperty(AdminClient.USERNAME, "test2");
connectProps.setProperty(AdminClient.PASSWORD, "user24test");
System.setProperty("com.ibm.CORBA.ConfigURL",
"file:C:/AA/cf010839.26/profiles/AppSrv02/properties/sas.client.props");
System.setProperty("com.ibm.SSL.ConfigURL",
"file:C:/AA/cf010839.26/profiles/AppSrv02/properties/ssl.client.props");
AdminClient adminClient = null;
try
{
adminClient = AdminClientFactory.createAdminClient(connectProps);
}
catch (ConnectorException e)
{
System.out.println("Exception creating admin client: " + e);
}
지원된 구성: 서블릿 및 JSP(JavaServer Pages) 파일 내에서와 같이
애플리케이션 서버에서 실행하는 애플리케이션 코드 내에서 createAdminClient 메소드를
사용하는 경우, CACHE_DISABLED 특성을 true로 설정해야 합니다.
예를 들어 다음과 같습니다.
connectProps.setProperty(AdminClient.CACHE_DISABLED, "true");
sptcfg
- 특성 오브젝트를 설정하십시오.
예제에서는
서버를 시작하는 데 필요한 특성이 있는 특성 오브젝트를 설정합니다. 이 경우에는
RMI(Remote Method Invocation) 커넥터를 사용하여 서버에 연결하십시오. 커넥터 유형의 경우,
AdminClient.CONNECTOR_TYPE_RMI 값을 사용하십시오.
![[AIX Solaris HP-UX Linux Windows]](../images/dist.gif)
간단히, 서버와 동일한 시스템에서 클라이언트 프로그램을 실행하십시오. 호스트 이름으로
localhost를 사용합니다. 로컬 호스트 대신 원격 호스트에 액세스하려면
해당 호스트에 대해 네트워크 분석 가능 이름을 사용하십시오.
- 서버 RMI 커넥터가 청취 중인 포트 번호를 설정하십시오.
단일 서버 설치의 경우,
애플리케이션 서버 RMI 커넥터의 기본 포트 번호는 2809입니다.
WebSphere Application Server, Network Deployment 설치에서는 배치 관리자 RMI 커넥터의 기본 포트 번호가 9809입니다.
- 연결 특성이 설정된 후, AdminClientFactory 클래스 및
Properties 오브젝트를 사용하여 사용자가 선택한 서버에 연결된
AdminClient 오브젝트를 작성하십시오.
원하는 프로토콜 및 보안 환경 같은 요소에 따라,
다른 특성을 설정해야 할 수도 있습니다.
예를 들어, 애플리케이션 클라이언트 프로그램에 보안을 사용하려면
ssl.client.props 파일 및 sas.client.props 파일을 지정하도록 시스템 특성을
설정해야 합니다. 로컬 시스템에서 실행하는 경우, 실제 위치로 지정할 수 있습니다.
원격 시스템에서 실행하는 경우, 서버 시스템에서 이러한 특성 파일을 복사한 후
파일을 배치할 경로를 지정하여 원하는 위치에 배치할 수 있습니다.
sas.client.props 파일 내에 사용자 이름 및 비밀번호를 지정할 수 있습니다.
이 경우, com.ibm.CORBA.loginSource=properties를 지정하십시오.
클라이언트 프로그램 내에 사용자 이름 및 비밀번호를 설정하려면 sas.client.props
파일에 com.ibm.CORBA.loginSource=none을 지정하십시오.
- MBean을 찾으십시오.
AdminClient 인스턴스를 가져오면, 이 인스턴스를 사용하여 관리 서버 및
Application Server에서 관리되는 자원에 액세스할 수 있습니다. 각
관리 자원은 자원에 액세스할 수 있는 AdminService에 MBean을
등록합니다. MBean은 MBean을 식별하는 ObjectName 인스턴스로
표시됩니다. ObjectName 인스턴스는 도메인 이름 및 미정렬된 하나 이상의 키 특성 세트로 구성됩니다.
도메인 이름의 구문은 다음과 같습니다.
[domainName]:property=value[,property=value]*
WebSphere Application Server의 경우,
도메인 이름은 WebSphere이고, 관리를 위해 정의된 키 특성은 다음과 같습니다. 표 1. 키 특성 설명. 키 특성은 유형, 이름, 셀, 노드 및 프로세스를 포함합니다. | 키 특성 |
설명 |
| 유형 |
MBean 유형(예: Server, TraceService, JVM(Java Virtual Machine)) |
| 이름 |
개별 MBean 인스턴스의
이름 ID. |
| 셀 |
MBean이 실행 중인 셀의 이름 |
| node |
MBean이 실행 중인 노드의 이름 |
| process |
MBean이 실행 중인 프로세스의 이름 |
WebSphere Application Server의 일부 MBean은 추가 키
특성을 사용합니다. 키 특성이 없는 MBean은 WebSphere Application Server
프로세스에서 MBean 서버에 등록될 수 있습니다. 그러나 이러한 MBean은
제품이 추가하는 분산된 개선사항(예: 요청 라우팅, 분산된 이벤트 알림 등)에
사용될 수 없습니다.
ObjectName 인스턴스에 대한
전체 키 특성 세트를 알고 있으면 해당 세트를 사용하여 키 특성이 식별하는 MBean을 찾을 수 있습니다. 그러나 모든 키 특성을 알 필요 없이 MBean을 찾을 수 있으면 일반적으로
더 실용적이고 편리합니다. 일치시켜야 할 필요가 없는 키 특성에 대해서는
와일드카드 문자 별표(
*)를 사용하십시오. 다음 표는
단일 또는 여러 MBean과 일치하는 와일드카드 키 특성이 있는 오브젝트 이름의
몇 가지 예제를 제공합니다.
표 2. 와일드카드 키 특성이 있는 오브젝트 이름 예제. 별표(*)를 포함하여 와일드카드 키 특성을 지정하십시오. | 오브젝트 이름 |
설명 |
| *:type=Server,* |
Server 유형의 모든 MBean |
| *:node=Node1,type=Server,* |
Node1에 있는 Server 유형의 모든 MBean |
| *:type=JVM,process=server1,node=Node1,* |
Node1 노드의 server1이라는 서버에 있는 JVM MBean |
| *:process=server1,* |
server1이란 이름이 지정된 모든 서버에 있는 모든 MBean |
| *:process=server1,node=Node1,* |
Node1의 server1이라는 서버에 있는 모든 MBean |
키 특성과 일치하는 오브젝트로 MBean을 조회하여 찾을 수 있습니다. 다음 예제는
노드 MyNode의 노드 에이전트에 대한 MBean을 찾는 방법을 보여줍니다.
String nodeName = "MyNode";
String query = "WebSphere:type=NodeAgent,node=" + nodeName + ",*";
ObjectName queryName = new ObjectName(query);
ObjectName nodeAgent = null;
Set s = adminClient.queryNames(queryName, null);
if (!s.isEmpty())
nodeAgent = (ObjectName)s.iterator().next();
else
System.out.println("노드 에이전트 MBean was not found");
- 유형 및 노드의 키 특성을 지정하는 조회 문자열을 사용하여
ObjectName 인스턴스를 빌드하십시오.
나머지 키 특성에 와일드카드를 사용하면,
이 패턴은 MyNode 노드에 있는 NodeAgent 유형의 모든 MBean에 대해
오브젝트 이름을 일치시킵니다. 노드당 하나의 노드 에이전트만 있으므로
원하는 MBean을 식별하는 데 있어 이 정보면 충분합니다.
- 이 ObjectName 인스턴스를 AdminClient 인터페이스의
queryNames 메소드에 제공하십시오.
AdminClient 인터페이스는
AdminService 인터페이스에 원격 호출을 수행하여 조회와 일치하는
MBean 오브젝트 이름 세트를 얻습니다. 이 메소드에 대한 널 두 번째 매개변수는
첫 번째 매개변수에서 ObjectName 패턴에 일치하는 MBean을 통해
추가 조회로 사용할 수 있는 조회 표현식(QueryExp) 오브젝트입니다.
- 첫 번째 요소(이 경우에는 유일한 요소)를 가져오려면
세트 반복기를 사용하십시오.
해당 요소는 노드 에이전트의 MBean ObjectName 인스턴스입니다.
- MBean을 사용하십시오.
특정 MBean가 수행할 수 있는 사항은
MBean의 관리 인터페이스에 따라 다릅니다. MBean이 다음을 선언할 수 있습니다.
- 확보하거나 설정할 수 있는 속성
- 호출할 수 있는 조작
- 리스너를 등록할 수 있는 알림
WebSphere Application Server에서
제공하는 MBean의 경우, MBean API 문서에서 MBean이 지원하는 인터페이스에 대한 정보를
찾을 수 있습니다. 다음 예제는 이전에 찾은
NodeAgent MBean에서 사용 가능한 조작 중 하나를 호출합니다. 다음 예제는 MyServer Application Server를 시작합니다. String opName = "launchProcess";
String signature[] = { "java.lang.String" };
String params[] = { "MyServer" };
try
{
adminClient.invoke(nodeAgent, opName, params, signature);
}
catch (Exception e)
{
System.out.println("Exception invoking launchProcess: " + e);
}
AdminClient.invoke 메소드는 MBean에서 조작을 호출하는
일반적인 수단입니다. 매개변수는 다음과 같습니다.
- 대상 MBean의 오브젝트 이름, nodeAgent
- 조작의 이름, opName
- 조작 매개변수가 포함된 오브젝트 배열, params
- 조작 서명이 포함된 문자열 배열, signature
예제에서 launchProcess 조작은 시작할 서버를 식별하는 문자열인
단일 매개변수를 가지고 있습니다.
호출 메소드는 오브젝트 인스턴스를 리턴하고,
호출 코드는 이것을 사용하여 호출된 조작의 올바른 리턴 유형으로
캐스트됩니다. launchProcess 조작은 이 예제의 리턴 값을 무시할 수 있도록
무효로 선언됩니다.
- 이벤트에 등록하십시오.
또한 JMX API는 자원 관리 외에, 특정 관리 이벤트에 대한
애플리케이션 모니터링도 지원합니다. 예를 들어, 일부 이벤트는 서버가 시작할 때 알림을 내보냅니다. 이러한 알림에 대해 관리 애플리케이션은 리스너로 등록됩니다. WebSphere Application Server는 JMX 알림 모델의 완전한 구현을 제공하며,
분산 환경에서 알림을 수신할 수 있도록 추가 기능을 제공합니다.
제품 MBean에서 생성한 전체 알림 목록은 MBean API 문서의 com.ibm.websphere.management.NotificationConstants 클래스를
참조하십시오.
다음 예제는
ObjectName 노드 에이전트를 사용하여 MBean에서 생성된 이벤트 알림에 대해 오브젝트가
등록되는 방식을 보여줍니다.
adminClient.addNotificationListener(nodeAgent, this, null, null);
이 예제에서 첫 번째 매개변수는 노드 에이전트 MBean에 대한 ObjectName입니다.
두 번째 매개변수는 리스너 오브젝트를 식별하며, 이것은 NotificationListener
인터페이스를 구현해야 합니다. 이 경우, 호출 오브젝트는
리스너입니다. 세 번째 매개변수는 수신할 알림을 나타내는 데
사용할 수 있는 필터입니다. 이 값을 null로 그대로 두면,
이 MBean으로부터 모든 알림을 수신합니다. 마지막 매개변수는 알림을 생성할 때
JMX API가 사용자에게 되돌아가도록 설정하는 데 사용할 수 있는
핸드백 오브젝트입니다.
Application Server가 제공하는 다른 향상된 기능으로,
한 번의 호출로 여러 MBean의 알림 리스너로 등록할 수 있는 기능이 있습니다. 이 등록은 표준
JMX addNotificationListener 메소드의 확장인 AdminClient 인터페이스의
addNotificationListenerExtended 메소드를 통해 수행됩니다. 이 확장 메소드를 사용하면 현재 활성 상태가 아닌
MBean에 대해서도 등록할 수 있습니다. 관리 클라이언트 프로그램의 지속 시간 동안 중지했다가 다시 시작할 수 있는
이벤트를 자원에서 모니터하려는 경우 이 등록이 중요합니다.
- 이벤트를 처리하십시오.
오브젝트는 NotificationListener 인터페이스로 정의하고 이벤트 수신자가 구현해야 하는
handleNotification 메소드를 통해 JMX 이벤트 알림을 수신합니다. 다음 예제는 이벤트 수신자가 수신하는 알림을 보고하는
handleNotification 메소드 구현입니다.
public void handleNotification(Notification n, Object handback)
{
System.out.println("***************************************************");
System.out.println("* Notification received at " + new Date().toString());
System.out.println("* type = " + ntfyObj.getType());
System.out.println("* message = " + ntfyObj.getMessage());
System.out.println("* source = " + ntfyObj.getSource());
System.out.println(
"* seqNum = " + Long.toString(ntfyObj.getSequenceNumber()));
System.out.println("* timeStamp = " + new Date(ntfyObj.getTimeStamp()));
System.out.println("* userData = " + ntfyObj.getUserData());
System.out.println("***************************************************");
}
결과
관리 클라이언트는 MBean에서 생성되는 이벤트 알림을 처리할 수
있습니다.
문제점 방지: 클라이언트가 RMI 또는 JSR160RMI 커넥터를
통해 알림 리스너를 등록하고 ORB 스레드가 실행을 중지하지 않아 JVM(Java Virtual Machine)이
종료되지 않는 경우,
System.exit() 문을 클라이언트 프로그램에
추가하십시오. ORB는 클라이언트에 알림을 전파할 스레드를 시작합니다. 기본 스레드에
System.exit() 문이 없으면 이 스레드가 클라이언트 기본 스레드와
함께 자동으로 종료하지 않습니다.
클라이언트 프로그램에서 ORB 스레드 및 기본 스레드를 통해 처리를 중지할 위치에
System.exit() 문을 배치하십시오. 예를 들어, 클라이언트 프로그램 기본
try 블록의
catch 또는
finally 절에
System.exit() 문을 배치하십시오.
gotcha
예제: 관리 클라이언트 프로그램
이 예에서는 해당 제품에 사용할 수 없는
노드 에이전트 서버에 연결하는 방법을 설명합니다. 그러나 호스트 및 포트 값을 변경하여
해당 서버에 연결할 수 있습니다. 노드 에이전트 서버 참조의 서버를
대체하십시오. 해당 제품에 대해 NodeAgent MBean을 사용할 수 없으므로
queryNames 문자열을 대체하여 다른 MBean을 검색하십시오.
컨텐츠를
AdminClientExample.java 파일에 복사하십시오. 노드 이름 및
서버 이름을 구성에 적합한 값으로 변경한 후,
WebSphere Application Server 관리 Java API를 사용한 사용자 정의 Java 관리 클라이언트 프로그램 작성의
지시사항에 따라 컴파일한 후 실행할 수 있습니다.
import java.util.Date;
import java.util.Properties;
import java.util.Set;
import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;
import com.ibm.websphere.management.exception.ConnectorException;
public class AdminClientExample implements NotificationListener
{
private AdminClient adminClient;
private ObjectName nodeAgent;
private long ntfyCount = 0;
public static void main(String[] args)
{
AdminClientExample ace = new AdminClientExample();
// Create an AdminClient
ace.createAdminClient();
// Find a NodeAgent MBean
ace.getNodeAgentMBean("ellington");
// Invoke launchProcess
ace.invokeLaunchProcess("server1");
// Register for NodeAgent events
ace.registerNotificationListener();
// Run until interrupted
ace.countNotifications();
}
private void createAdminClient()
{
// Set up a Properties object for the JMX connector attributes
Properties connectProps = new Properties();
connectProps.setProperty(
AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost");
connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8879");
// Get an AdminClient based on the connector properties
try
{
adminClient = AdminClientFactory.createAdminClient(connectProps);
}
catch (ConnectorException e)
{
System.out.println("Exception creating admin client: " + e);
System.exit(-1);
}
System.out.println("Connected to DeploymentManager");
}
private void getNodeAgentMBean(String nodeName)
{
// Query for the ObjectName of the NodeAgent MBean on the given node
try
{
String query = "WebSphere:type=NodeAgent,node=" + nodeName + ",*";
ObjectName queryName = new ObjectName(query);
Set s = adminClient.queryNames(queryName, null);
if (!s.isEmpty())
nodeAgent = (ObjectName)s.iterator().next();
else
{
System.out.println("노드 에이전트 MBean was not found");
System.exit(-1);
}
}
catch (MalformedObjectNameException e)
{
System.out.println(e);
System.exit(-1);
}
catch (ConnectorException e)
{
System.out.println(e);
System.exit(-1);
}
System.out.println("Found NodeAgent MBean for node " + nodeName);
}
private void invokeLaunchProcess(String serverName)
{
// Use the launchProcess operation on the NodeAgent MBean to start
// the given server
String opName = "launchProcess";
String signature[] = { "java.lang.String" };
String params[] = { serverName };
boolean launched = false;
try
{
Boolean b = (Boolean)adminClient.invoke(
nodeAgent, opName, params, signature);
launched = b.booleanValue();
if (launched)
System.out.println(serverName + " was launched");
else
System.out.println(serverName + " was not launched");
}
catch (Exception e)
{
System.out.println("Exception invoking launchProcess: " + e);
}
}
private void registerNotificationListener()
{
// Register this object as a listener for notifications from the
// NodeAgent MBean. Don't use a filter and don't use a handback
// object.
try
{
adminClient.addNotificationListener(nodeAgent, this, null, null);
System.out.println("Registered for event notifications");
}
catch (InstanceNotFoundException e)
{
System.out.println(e);
e.printStackTrace();
}
catch (ConnectorException e)
{
System.out.println(e);
e.printStackTrace();
}
}
public void handleNotification(Notification ntfyObj, Object handback)
{
// Each notification that the NodeAgent MBean generates will result in
// this method being called
ntfyCount++;
System.out.println("***************************************************");
System.out.println("* Notification received at " + new Date().toString());
System.out.println("* type = " + ntfyObj.getType());
System.out.println("* message = " + ntfyObj.getMessage());
System.out.println("* source = " + ntfyObj.getSource());
System.out.println(
"* seqNum = " + Long.toString(ntfyObj.getSequenceNumber()));
System.out.println("* timeStamp = " + new Date(ntfyObj.getTimeStamp()));
System.out.println("* userData = " + ntfyObj.getUserData());
System.out.println("***************************************************");
}
private void countNotifications()
{
// Run until killed
try
{
while (true)
{
Thread.currentThread().sleep(60000);
System.out.println(ntfyCount + " notification have been received");
}
}
catch (InterruptedException e)
{
}
}
}