FileDocCategorySizeDatePackage
InstallerImpl.javaAPI DocGlassfish v2 API14519Fri May 04 22:30:24 BST 2007com.sun.enterprise.jbi.serviceengine.install

InstallerImpl

public class InstallerImpl extends Object implements Installer
Installs Java EE Service Engine on a CAS installation. In openESB world, an instance could either be a CAS or a non CAS ESB member. Java EE Servijece Engine is installed on a instance only if the instance is CAS. All components installed on CAS are installed on a non CAS ESB member by the CAS.
author
Manishaa Umbar

Fields Summary
private static final String
ADD_COMPONENT_OPERATION
addComponent operation of ESB installation MBean adds the component to ESB's registry and repository. By adding a component, component becomes installable.
private static final String
INSTALL_COMPONENT_OPERATION
Install a already added component in ESB environment
private static final String
REMOVE_COMPONENT_OPERATION
removeComponent operation of ESB installation MBean removes the component from ESB's registry and repository.
private static final String
UNINSTALL_COMPONENT_OPERATION
UnInstalls already added component in ESB environment. By uninstalling a component, component becomes removable from the registry and repository of CAS.
private static final String
START_COMPONENT_OPERATION
Starts the component
private static final String
STOP_COMPONENT_OPERATION
Stops the component
private static final String
IS_ENGINE_OPERATION
Checks if an engine with provided name exists in openESB . This operation is used to find out if Service Engine is installed or not
private static final String
IS_CAS_OPERATION
Determines whether the jbi instance is CAS instance
private String
componentName
private String
SE_BUNDLE
private String
JBI_INSTANCE_NAME
private String
JBI_FOLDER
private String
JBI_ENV_PROPERTIES
private MBeanHelper
mbeanHelper
private String
jbiInstanceName
private boolean
casInstallation
private boolean
jbiInstalled
private static Logger
logger
Internal handle to the logger instance
Constructors Summary
public InstallerImpl(MBeanHelper mbeanHelper)
Creates a new instance of CASInstallerImpl

    
           
       
        this.mbeanHelper = mbeanHelper;
        String installationRoot =
                ApplicationServer.getServerContext().getInstallRoot();
        String jbiInstallationDir = installationRoot + File.separator + JBI_FOLDER;
        jbiInstalled = (new File(jbiInstallationDir).exists() &&
                (getJBIInstanceName() != null));
        if(jbiInstalled)
            casInstallation = isCASInstallation();
    
Methods Summary
private java.lang.StringgetJBIInstanceName()

        if(jbiInstanceName == null) {
            try{
                String installRoot = ApplicationServer.getServerContext().getInstallRoot();
                String jbiEnvProperties = installRoot + JBI_ENV_PROPERTIES;
                
                Properties jbiEnv = new Properties();
                logger.fine("JBI Env properties :" + jbiEnvProperties);
                jbiEnv.load(new FileInputStream(jbiEnvProperties));
                jbiInstanceName = jbiEnv.getProperty(JBI_INSTANCE_NAME);
                
                logger.fine("JBI Instance name " + jbiInstanceName);
            } catch (IOException ioe) {
                logger.log(Level.SEVERE, "IOException during reading of jbi env properties " + ioe.getMessage());
            }
        }
        return jbiInstanceName;
    
private java.lang.StringgetServiceEngineBundle()

        
        String seBundle = System.getProperty("com.sun.aas.installRoot") + 
                    File.separator + SE_BUNDLE;
        return seBundle;
    
public java.lang.Stringinstall(java.lang.String zipFilePath)
Installs the service engine and starts it

param
zipFilePath packaged 208 compliant service engine bundle

        //Use InstallationServiceMBean to install new component
        String result = null;
        if(zipFilePath == null) {
            zipFilePath = getServiceEngineBundle();
            if(casInstallation) {
                log(Level.FINE, "Java EE Service Engine Bundle :" , zipFilePath);
                try {
                    
                    ObjectName objName = mbeanHelper.getObjectName(
                            MBeanHelper.ESB_INSTALLATION_SERVICE);
                    
                    log(Level.FINEST, "installation_service_log_name" , objName.toString());
                    
                    result = (String)mbeanHelper.invokeMBeanOperation(objName,
                            ADD_COMPONENT_OPERATION, new Object[]{zipFilePath},
                            new String[] {"java.lang.String"});
                            
                    log(Level.FINEST, " Status of addComponent ", result );
                            
                    result = (String)mbeanHelper.invokeMBeanOperation(objName,
                                    INSTALL_COMPONENT_OPERATION,
                                    new Object[]{componentName,
                                            java.util.Arrays.asList(new String[]{jbiInstanceName}),
                                                    new Properties()},
                                    new String[] {"java.lang.String", "java.util.List","java.util.Properties"});
                                    
                    log(Level.FINEST, " Status of installComponent ", result );
                } catch(Exception e) {
                    log(Level.SEVERE,
                            "Error occurred during installation of Java EE Service Engine",
                            e.getMessage());
                }
            }
        }
        return result;
        
    
private booleanisCASInstallation()

        try {
            
            ObjectName objName = mbeanHelper.getObjectName(jbiInstanceName,
                    MBeanHelper.FRAMEWORK);
            log(Level.FINEST, "Framework MBean Object" , objName.toString());
            
            Boolean result = (Boolean)mbeanHelper.invokeMBeanOperation(objName,
                    IS_CAS_OPERATION, null,new String[] {});
                    
            return result.booleanValue();
        } catch(Exception e) {
            log(Level.SEVERE,
                    "Error occurred during checking if the instance is CAS or not",
                    e.getMessage());
        }
        //Should never reach here
        return false;
    
public booleanisComponentInstalled()
Checks if the compoenent specified by componentName is installed or not

        if(casInstallation) {
            try {
                ObjectName objName = mbeanHelper.getObjectName(MBeanHelper.ESB_INSTALLATION_SERVICE);
                String result = (String)mbeanHelper.invokeMBeanOperation(objName,
                                "getComponentInfo",
                                new Object[]{componentName},
                                new String[] {"java.lang.String"});
                if(result == null || result.trim().length() == 0) {
                    return false;
                }
                /*
                String domainDir = ApplicationServer.getServerContext().getInstanceEnvironment().getInstancesRoot();
                String fs = File.separator;
                String javaeeSEDir = domainDir + fs + "jbi" + fs + "engines" + fs + "JavaEEServiceEngine";
                if(!(new File(javaeeSEDir).exists())) {
                    return false;
                }
                */
            } catch(Exception e) {
                log(Level.WARNING, "Exception occurred while getting component by name", e.getMessage());
                return false;
            }
        }
        
        return true;
    
public booleanisJBIInstalled()

        return jbiInstalled;
    
private voidlog(java.util.logging.Level level, java.lang.String property, java.lang.String logString)

        logger.log(level,property,logString);
    
public voidsetComponentName(java.lang.String componentName)

        this.componentName = componentName;
    
public voidstart()
Starts the component with provided name

        if(casInstallation) {
            try {
                ObjectName objName = mbeanHelper.getObjectName(
                        MBeanHelper.ESB_LIFECYCLE_SERVICE);
                
                log(Level.FINEST, "lifecycle_service_obj_name" , objName.toString());
                
                String result = (String)mbeanHelper.invokeMBeanOperation(objName,
                        START_COMPONENT_OPERATION, new Object[]{componentName},
                        new String[] {"java.lang.String"});
                        log(Level.FINEST, "Start Component Status", result);
            } catch(Exception e) {
                log(Level.SEVERE,
                        "Error occurred during startup of Java EE Service Engine",
                        e.getMessage());
            }
        }
    
public voidstop()
Stops the component with provided name

        if(casInstallation) {
            try {
                
                ObjectName objName = mbeanHelper.getObjectName(
                        MBeanHelper.ESB_LIFECYCLE_SERVICE);
                
                log(Level.FINEST, "lifecycle_service_obj_name" , objName.toString());
                
                String result = (String)mbeanHelper.invokeMBeanOperation(objName,
                        STOP_COMPONENT_OPERATION, new Object[]{componentName},
                        new String[] {"java.lang.String"});
                        log(Level.FINEST, "Start Component Status", result);
            } catch(Exception e) {
                log(Level.SEVERE,
                        "Error occurred during stopping of Java EE Service Engine",
                        e.getMessage());
            }
        }
        
    
public voiduninstall()
Uninstalls the component with provided name

        if(casInstallation) {
            try {
                
                ObjectName objName = mbeanHelper.getObjectName(
                        MBeanHelper.ESB_INSTALLATION_SERVICE);
                
                log(Level.FINEST, "installation_service_log_name" , objName.toString());
                
                String result = (String)mbeanHelper.invokeMBeanOperation(objName,
                        UNINSTALL_COMPONENT_OPERATION, new Object[]{componentName},
                        new String[] {"java.lang.String"});
                        
                        log(Level.FINEST, " Status of uninstallComponent ", result );
                        
                        result = (String)mbeanHelper.invokeMBeanOperation(objName,
                                REMOVE_COMPONENT_OPERATION,
                                new Object[]{componentName},
                                new String[] {"java.lang.String"});
                                
                                log(Level.FINEST, " Status of removeComponent ", result );
            } catch(Exception e) {
                log(Level.SEVERE,
                        "Error occurred during uninstallation of Java EE Service Engine",
                        e.getMessage());
            }
        }