1 23 24 25 package com.sun.enterprise.jbi.serviceengine.install; 26 27 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException; 28 import com.sun.enterprise.server.ApplicationServer; 29 import com.sun.logging.LogDomains; 30 import java.io.File ; 31 import java.io.FileInputStream ; 32 import java.io.IOException ; 33 import java.net.URI ; 34 import java.util.Properties ; 35 import java.util.logging.Level ; 36 import java.util.logging.Logger ; 37 import javax.management.ObjectName ; 38 39 40 41 48 public class InstallerImpl implements Installer { 49 50 51 56 private static final String ADD_COMPONENT_OPERATION="addComponent"; 57 58 61 private static final String INSTALL_COMPONENT_OPERATION="installComponent"; 62 63 67 private static final String REMOVE_COMPONENT_OPERATION="removeComponent"; 68 69 73 private static final String UNINSTALL_COMPONENT_OPERATION="uninstallComponent"; 74 75 78 private static final String START_COMPONENT_OPERATION="startComponent"; 79 80 83 private static final String STOP_COMPONENT_OPERATION="stopComponent"; 84 85 86 private String componentName = null; 87 private String SE_BUNDLE = "lib/addons/jbi/appserv-jbise.jar"; 88 89 private String JBI_FOLDER = "jbi"; 90 91 private MBeanHelper mbeanHelper; 92 93 private String jbiInstanceName; 94 95 private boolean jbiInstalled = false; 96 97 100 private static Logger logger = 101 LogDomains.getLogger(LogDomains.SERVER_LOGGER); 102 103 104 public InstallerImpl(MBeanHelper mbeanHelper) { 105 this.mbeanHelper = mbeanHelper; 106 String installationRoot = 107 ApplicationServer.getServerContext().getInstallRoot(); 108 String jbiInstallationDir = installationRoot + File.separator + JBI_FOLDER; 109 boolean mbeanRegistered = false; 110 try { 111 mbeanRegistered = mbeanHelper.isMBeanRegistered(MBeanHelper.ESB_INSTALLATION_SERVICE); 112 } catch(ServiceEngineException ex) { 113 logger.log(Level.SEVERE, ex.getMessage(), ex); 114 } 115 jbiInstalled = new File (jbiInstallationDir).exists() && mbeanRegistered; 116 } 117 118 public boolean isJBIInstalled() { 119 return jbiInstalled; 120 } 121 122 public void setComponentName(String componentName) { 123 this.componentName = componentName; 124 } 125 126 127 132 public String install(String zipFilePath) throws ServiceEngineException { 133 String result = null; 135 if(zipFilePath == null) { 136 zipFilePath = getServiceEngineBundle(); 137 log(Level.FINE, "Java EE Service Engine Bundle :" , zipFilePath); 138 try { 139 140 ObjectName objName = mbeanHelper.getObjectName( 141 MBeanHelper.ESB_INSTALLATION_SERVICE); 142 143 log(Level.FINEST, "installation_service_log_name" , objName.toString()); 144 145 result = (String )mbeanHelper.invokeMBeanOperation(objName, 146 ADD_COMPONENT_OPERATION, new Object []{zipFilePath}, 147 new String [] {"java.lang.String"}); 148 149 log(Level.FINEST, " Status of addComponent ", result ); 150 151 result = (String )mbeanHelper.invokeMBeanOperation(objName, 152 INSTALL_COMPONENT_OPERATION, 153 new Object []{componentName}, 154 new String [] {"java.lang.String"}); 155 156 log(Level.FINEST, " Status of installComponent ", result ); 157 } catch(Exception e) { 158 log(Level.SEVERE, 159 "Error occurred during installation of Java EE Service Engine", 160 e.getMessage()); 161 } 162 } 163 return result; 164 165 } 166 167 170 public void start() throws ServiceEngineException { 171 try { 172 ObjectName objName = mbeanHelper.getObjectName( 173 MBeanHelper.ESB_LIFECYCLE_SERVICE); 174 175 log(Level.FINEST, "lifecycle_service_obj_name" , objName.toString()); 176 177 String result = (String )mbeanHelper.invokeMBeanOperation(objName, 178 START_COMPONENT_OPERATION, new Object []{componentName}, 179 new String [] {"java.lang.String"}); 180 log(Level.FINEST, "Start Component Status", result); 181 } catch(Exception e) { 182 log(Level.SEVERE, 183 "Error occurred during startup of Java EE Service Engine", 184 e.getMessage()); 185 } 186 } 187 188 189 193 public boolean isComponentInstalled() { 194 try { 195 String domainDir = ApplicationServer.getServerContext().getInstanceEnvironment().getInstancesRoot(); 196 String fs = File.separator; 197 String javaeeSEDir = domainDir + fs + "jbi" + fs + "engines" + fs + "JavaEEServiceEngine"; 198 if(!(new File (javaeeSEDir).exists())) { 199 return false; 200 } 201 } catch(Exception e) { 202 log(Level.WARNING, "Exception occurred while getting component by name", e.getMessage()); 203 return false; 204 } 205 206 return true; 207 } 208 209 212 public void stop() throws ServiceEngineException { 213 try { 214 215 ObjectName objName = mbeanHelper.getObjectName( 216 MBeanHelper.ESB_LIFECYCLE_SERVICE); 217 218 log(Level.FINEST, "lifecycle_service_obj_name" , objName.toString()); 219 220 String result = (String )mbeanHelper.invokeMBeanOperation(objName, 221 STOP_COMPONENT_OPERATION, new Object []{componentName}, 222 new String [] {"java.lang.String"}); 223 log(Level.FINEST, "Start Component Status", result); 224 } catch(Exception e) { 225 log(Level.SEVERE, 226 "Error occurred during stopping of Java EE Service Engine", 227 e.getMessage()); 228 } 229 230 } 231 232 235 public void uninstall() throws ServiceEngineException { 236 try { 237 238 ObjectName objName = mbeanHelper.getObjectName( 239 MBeanHelper.ESB_INSTALLATION_SERVICE); 240 241 log(Level.FINEST, "installation_service_log_name" , objName.toString()); 242 243 String result = (String )mbeanHelper.invokeMBeanOperation(objName, 244 UNINSTALL_COMPONENT_OPERATION, new Object []{componentName}, 245 new String [] {"java.lang.String"}); 246 247 log(Level.FINEST, " Status of uninstallComponent ", result ); 248 249 result = (String )mbeanHelper.invokeMBeanOperation(objName, 250 REMOVE_COMPONENT_OPERATION, 251 new Object []{componentName}, 252 new String [] {"java.lang.String"}); 253 254 log(Level.FINEST, " Status of removeComponent ", result ); 255 } catch(Exception e) { 256 log(Level.SEVERE, 257 "Error occurred during uninstallation of Java EE Service Engine", 258 e.getMessage()); 259 } 260 } 261 262 private String getServiceEngineBundle() { 263 264 String seBundle = System.getProperty("com.sun.aas.installRoot") + 265 File.separator + SE_BUNDLE; 266 return seBundle; 267 } 268 269 270 private void log(Level level, String property, String logString) { 271 logger.log(level,property,logString); 272 } 273 274 } 275 | Popular Tags |