Index Changes
This is version 2. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]
ESB Console Home

Test Installation Service In Java

package org.glassfish.extended.management.sample.impl.installation;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.openesb.extended.management.api.administration.ExtendedAdministrationService;
import org.glassfish.openesb.extended.management.api.installation.ExtendedInstallationService;
import org.glassfish.openesb.extended.management.api.runtime.ExtendedRuntimeManagementService;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClient;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClientFactory;
import org.glassfish.openesb.extended.management.common.ExtendedManagementRemoteException;
import org.glassfish.openesb.extended.management.common.jbi.ManagementRemoteExceptionProcessor;
import com.sun.esb.management.common.ManagementRemoteException;
import org.glassfish.openesb.management.ServerConnectionFactory;

/**
 * @author gopalan
 */
public class TestExtendedInstallationServiceImpl {

    /**
     * 
     */
    public TestExtendedInstallationServiceImpl() {
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        String hostName = ServerConnectionFactory.LOCALHOST,
                userName = ServerConnectionFactory.ADMIN_USERNAME,
                password = ServerConnectionFactory.ADMINADMIN_PASSWORD;
        int portNumber = ServerConnectionFactory.RMI_ADMIN_PORT;
        String targetName = ServerConnectionFactory.SERVER_TARGET;
        ExtendedManagementClient client = null;
        ExtendedAdministrationService administrationService = null;
        ExtendedRuntimeManagementService runtimeManagementService = null;
        ExtendedInstallationService installationService = null;
        boolean isJBIRuntimeEnabled = false;
        String result = null;
        boolean isTargetUp = false;
        boolean componentInstalled = false;
        String engine = "";
        String library = "";
        String dataPath = "";
        String componentZipFilePath = "";
        String libraryZipFilePath = "";

        engine = "sun-bpel-engine";
        library = "sun-saxon-library";
        dataPath = ".";
        componentZipFilePath = dataPath + "/data/sun-bpel-engine-1.0-M8.jar";
        libraryZipFilePath = dataPath + "/data/sun-saxon-library-1.0-M8.jar";

        try {
            client = ExtendedManagementClientFactory.getInstance(hostName, portNumber, userName, password);
        } catch (ExtendedManagementRemoteException ex) {
            Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        administrationService = client.getService(ExtendedAdministrationService.class);
        if (administrationService != null) {
            try {
                isJBIRuntimeEnabled = administrationService.isJBIRuntimeEnabled();
            } catch (ManagementRemoteException ex) {
                Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
            if (true == isJBIRuntimeEnabled) {
                System.out.println("The JBI Framework is Enabled");

                runtimeManagementService = client.getService(ExtendedRuntimeManagementService.class);
                if (runtimeManagementService != null) {
                    try {
                        isTargetUp = runtimeManagementService.isTargetUp(targetName);
                    } catch (ExtendedManagementRemoteException ex) {
                        Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    System.out.println("The target is " + targetName + (isTargetUp ? " Up." : " Down."));
                    try {
                        componentInstalled = administrationService.isJBIComponentInstalled(engine, targetName);
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    if (componentInstalled) {
                        try {
                            result = runtimeManagementService.stopComponent(engine, targetName);
                        } catch (ManagementRemoteException ex) {
                            Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        result = ManagementRemoteExceptionProcessor.processTaskResult(result);
                        System.out.println("Stop " + engine + ". Result: " + result);
                        try {
                            result = runtimeManagementService.shutdownComponent(engine, targetName);
                        } catch (ManagementRemoteException ex) {
                            Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        result = ManagementRemoteExceptionProcessor.processTaskResult(result);
                        System.out.println("Shutdown " + engine + ". Result: " + result);
                    }

                    installationService = client.getService(ExtendedInstallationService.class);

                    if (installationService != null) {
                        try {
                            result = installationService.uninstallSharedLibrary(library, targetName);
                        } catch (ManagementRemoteException ex) {
                            Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        try {
                            result = installationService.installSharedLibrary(libraryZipFilePath, targetName);
                        } catch (ManagementRemoteException ex) {
                            Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (componentInstalled) {
                            try {
                                result = installationService.uninstallComponent(engine, targetName);
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            result = ManagementRemoteExceptionProcessor.processTaskResult(result);
                            System.out.println("Uninstall " + engine + ". Result: " + result);
                        }
                        try {
                            result = installationService.installComponent(componentZipFilePath, targetName);
                        } catch (ManagementRemoteException ex) {
                            Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        result = ManagementRemoteExceptionProcessor.processTaskResult(result);
                        System.out.println("Install " + engine + ". Result: " + result);
                    } else {
                        System.out.println("Could not obtain the Installation Service.");
                    }
                    try {
                        result = runtimeManagementService.startComponent(engine, targetName);
                    } catch (ManagementRemoteException ex) {
                        Logger.getLogger(TestExtendedInstallationServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    result = ManagementRemoteExceptionProcessor.processTaskResult(result);
                    System.out.println("Start " + engine + ". Result: " + result);
                } else {
                    System.out.println("Could not obtain the Runtime Service.");
                }
            } else {
                System.out.println("JBI Runtime is NOT Enabled.");
            }
        } else {
            System.out.println("Could not obtain the Administration Service.");
        }
    }
}




Number of visits: 9

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 09-Oct-09 04:48 AM, -0700 by Gopalan Suresh Raj