1 23 24 package com.sun.enterprise.admin.server.core; 25 26 import java.io.BufferedReader ; 27 import java.io.File ; 28 import java.io.FileNotFoundException ; 29 import java.io.InputStream ; 30 import java.io.InputStreamReader ; 31 import java.io.IOException ; 32 import java.net.InetAddress ; 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 35 import java.util.Collection ; 36 import java.util.Enumeration ; 37 import java.util.Iterator ; 38 import java.util.logging.Level ; 39 import java.util.logging.Logger ; 40 import java.util.Properties ; 41 import java.util.StringTokenizer ; 42 import java.util.Vector ; 43 44 import javax.enterprise.deploy.shared.ModuleType ; 45 import javax.management.MBeanException ; 46 import javax.management.MBeanInfo ; 47 import javax.management.MBeanRegistration ; 48 import javax.management.MBeanServer ; 49 import javax.management.ObjectName ; 50 51 import com.sun.enterprise.admin.AdminContext; 52 import com.sun.enterprise.admin.common.constant.AdminConstants; 53 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 54 import com.sun.enterprise.admin.common.constant.DeploymentConstants; 55 import com.sun.enterprise.admin.common.exception.AFException; 56 import com.sun.enterprise.admin.common.exception.AFJDBCResourceException; 57 import com.sun.enterprise.admin.common.exception.AFResourceException; 58 import com.sun.enterprise.admin.common.exception.AFRuntimeStoreException; 59 import com.sun.enterprise.admin.common.exception.ControlException; 60 import com.sun.enterprise.admin.common.exception.DeploymentException; 61 import com.sun.enterprise.admin.common.exception.IllegalStateException; 62 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 63 import com.sun.enterprise.admin.common.exception.PortInUseException; 64 import com.sun.enterprise.admin.common.exception.ServerInstanceException; 65 import com.sun.enterprise.admin.common.InitConfFileBean; 66 import com.sun.enterprise.admin.common.MBeanServerFactory; 67 import com.sun.enterprise.admin.common.ObjectNameHelper; 68 import com.sun.enterprise.admin.common.ObjectNames; 69 import com.sun.enterprise.admin.common.RequestID; 70 import com.sun.enterprise.admin.common.ServerInstanceStatus; 71 import com.sun.enterprise.admin.common.Status; 72 import com.sun.enterprise.admin.event.AdminEvent; 73 import com.sun.enterprise.admin.event.AdminEventCache; 74 import com.sun.enterprise.admin.event.AdminEventListenerException; 75 import com.sun.enterprise.admin.event.AdminEventMulticaster; 76 import com.sun.enterprise.admin.event.AdminEventResult; 77 import com.sun.enterprise.admin.event.ApplicationDeployEvent; 78 import com.sun.enterprise.admin.event.BaseDeployEvent; 79 import com.sun.enterprise.admin.event.ConfigChangeEvent; 80 import com.sun.enterprise.admin.event.EventBuilder; 81 import com.sun.enterprise.admin.event.EventContext; 82 import com.sun.enterprise.admin.event.EventStack; 83 import com.sun.enterprise.admin.event.ModuleDeployEvent; 84 import com.sun.enterprise.admin.event.ResourceDeployEvent; 85 import com.sun.enterprise.admin.server.core.AdminService; 86 import com.sun.enterprise.admin.server.core.channel.AdminChannel; 87 import com.sun.enterprise.admin.server.core.channel.RMIClient; 88 import com.sun.enterprise.admin.server.core.ManualChangeManager; 89 import com.sun.enterprise.admin.server.core.mbean.config.Domain2ServerTransformer; 90 import com.sun.enterprise.admin.util.ArgChecker; 91 import com.sun.enterprise.admin.util.Assert; 92 import com.sun.enterprise.admin.util.ExceptionUtil; 93 import com.sun.enterprise.admin.util.HostAndPort; 94 import com.sun.enterprise.admin.util.StringValidator; 95 import com.sun.enterprise.config.ConfigBean; 96 import com.sun.enterprise.config.ConfigBeansFactory; 97 import com.sun.enterprise.config.ConfigContext; 98 import com.sun.enterprise.config.ConfigContext; 99 import com.sun.enterprise.config.ConfigException; 100 import com.sun.enterprise.config.ConfigFactory; 101 import com.sun.enterprise.config.ConfigFactory; 102 import com.sun.enterprise.config.serverbeans.*; 103 import com.sun.enterprise.config.serverbeans.Applications; 104 import com.sun.enterprise.config.serverbeans.J2eeApplication; 105 import com.sun.enterprise.config.serverbeans.JavaConfig; 106 import com.sun.enterprise.config.serverbeans.ServerTags; 107 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 108 import com.sun.enterprise.connectors.ConnectorRuntime; 109 import com.sun.enterprise.connectors.util.JmsRaMapping; 110 import com.sun.enterprise.deployment.backend.*; 111 import com.sun.enterprise.instance.InstanceDefinition; 112 import com.sun.enterprise.instance.InstanceEnvironment; 113 import com.sun.enterprise.instance.InstanceEnvironment; 114 import com.sun.enterprise.instance.ServerManager; 115 import com.sun.enterprise.security.auth.realm.BadRealmException; 116 import com.sun.enterprise.security.auth.realm.file.FileRealm; 117 import com.sun.enterprise.security.auth.realm.NoSuchRealmException; 118 import com.sun.enterprise.security.auth.realm.NoSuchUserException; 119 import com.sun.enterprise.security.util.IASSecurityException; 120 import com.sun.enterprise.server.Constants; 121 import com.sun.enterprise.util.i18n.StringManager; 122 import com.sun.enterprise.util.net.NetUtils; 123 124 import com.sun.enterprise.admin.server.core.AdminService; 125 import com.sun.enterprise.admin.AdminContext; 126 127 129 130 public class DeploymentNotificationHelper 131 { 132 public static final Logger sLogger = 133 Logger.getLogger(AdminConstants.kLoggerName); 134 135 private static final int CONFIG_CHANGED = 7; 136 137 private static StringManager localStrings = 139 StringManager.getManager( DeploymentNotificationHelper.class ); 140 141 145 146 154 155 162 163 170 176 177 178 185 public static boolean multicastEvent(int eventType, String entityName, 186 String moduleType , boolean cascade, boolean forceDeploy, int loadUnloadAction, String targetName) throws DeploymentException 187 { 188 AdminEvent event = null; 190 EventBuilder builder = new EventBuilder(); 191 192 EventStack stack = EventContext.getEventStackFromThreadLocal(); 194 ConfigContext ctx = stack.getConfigContext(); 195 stack.setTarget(targetName); 196 stack.setConfigChangeList(ctx.getConfigChangeList()); 197 198 try{ 199 if (eventType == BaseDeployEvent.APPLICATION_DEPLOYED) 200 { 201 event = builder.createApplicationDeployEvent( 202 BaseDeployEvent.DEPLOY, entityName, false, forceDeploy, 203 loadUnloadAction); 204 } 205 else if (eventType == BaseDeployEvent.APPLICATION_UNDEPLOYED) 206 { 207 event = builder.createApplicationDeployEvent( 208 BaseDeployEvent.UNDEPLOY, entityName, cascade, forceDeploy, loadUnloadAction); 209 } 210 else if (eventType == BaseDeployEvent.APPLICATION_REDEPLOYED) 211 { 212 event = builder.createApplicationDeployEvent( 213 BaseDeployEvent.REDEPLOY, entityName, false, forceDeploy, 214 loadUnloadAction); 215 } 216 else if (eventType == BaseDeployEvent.MODULE_DEPLOYED) 217 { 218 event = builder.createModuleDeployEvent( 219 BaseDeployEvent.DEPLOY, entityName, moduleType, cascade, forceDeploy); 220 } 221 else if (eventType == BaseDeployEvent.MODULE_UNDEPLOYED) 222 { 223 event = builder.createModuleDeployEvent( 224 BaseDeployEvent.UNDEPLOY, entityName, moduleType, cascade, forceDeploy); 225 } 226 else if (eventType == BaseDeployEvent.MODULE_REDEPLOYED) 227 { 228 event = builder.createModuleDeployEvent( 229 BaseDeployEvent.REDEPLOY, entityName, moduleType); 230 } 231 else if (eventType == BaseDeployEvent.APPLICATION_ENABLE) 232 { 233 event = builder.createApplicationDeployEvent( 234 BaseDeployEvent.ENABLE, entityName, false, forceDeploy, 235 loadUnloadAction); 236 } 237 else if (eventType == BaseDeployEvent.APPLICATION_DISABLE) 238 { 239 event = builder.createApplicationDeployEvent( 240 BaseDeployEvent.DISABLE, entityName, false, forceDeploy, 241 loadUnloadAction); 242 } 243 else if(eventType == BaseDeployEvent.MODULE_ENABLE) 244 { 245 event = builder.createModuleDeployEvent( 246 BaseDeployEvent.ENABLE, entityName, moduleType, false, forceDeploy); 247 } 248 else if(eventType == BaseDeployEvent.MODULE_DISABLE) 249 { 250 event = builder.createModuleDeployEvent( 251 BaseDeployEvent.DISABLE, entityName, moduleType, false, forceDeploy); 252 } 253 else if(eventType == BaseDeployEvent.APPLICATION_REFERENCED) 254 { 255 event = builder.createApplicationDeployEvent( 256 BaseDeployEvent.ADD_REFERENCE, entityName, false, forceDeploy, loadUnloadAction); 257 } 258 else if(eventType == BaseDeployEvent.APPLICATION_UNREFERENCED) 259 { 260 event = builder.createApplicationDeployEvent( 261 BaseDeployEvent.REMOVE_REFERENCE, entityName, false, forceDeploy, loadUnloadAction); 262 } 263 else if (eventType == CONFIG_CHANGED) 264 { 265 event = builder.createConfigChangeEvent(targetName, null); 266 } 267 else 268 { 269 String msg = 270 localStrings.getString( "admin.server.core.mbean.config.no_such_event", 271 new Integer (eventType) ); 272 throw new RuntimeException ( msg ); 273 } 274 } catch (ConfigException ex) { 275 DeploymentException de = new DeploymentException(ex.getMessage()); 276 de.initCause(ex); 277 throw de; 278 } 279 280 if (targetName != null) { 282 event.setTargetDestination(targetName); 283 } 284 285 if (event instanceof ApplicationDeployEvent 286 || event instanceof ModuleDeployEvent) { 287 AdminEventCache.populateConfigChange(getConfigContext(), event); 288 } 289 290 if (sLogger.isLoggable(Level.FINEST)) { 291 sLogger.log(Level.FINEST, "mbean.event_sent", event.getEventInfo()); 292 } else { 293 sLogger.log(Level.FINE, "mbean.send_event", event.toString()); 294 } 295 296 AdminEventResult multicastResult = 297 AdminEventMulticaster.multicastEvent(event); 298 sLogger.log(Level.FINE, "mbean.event_res", 299 multicastResult.getResultCode()); 300 sLogger.log(Level.FINE, "mbean.event_reply", 301 multicastResult.getAllMessagesAsString()); 302 boolean eventSuccess = true; 303 308 AdminEventListenerException ale = null; 311 ale = multicastResult.getFirstAdminEventListenerException(); 312 if (ale != null) { 313 sLogger.log(Level.WARNING, "mbean.event_failed", 314 ale.getMessage()); 315 DeploymentException de = 316 new DeploymentException(ale.getMessage()); 317 de.initCause(ale); 318 throw de; 319 } 320 return eventSuccess; 321 } 322 323 private static ConfigContext getConfigContext() { 324 AdminContext adminContext = 325 AdminService.getAdminService().getAdminContext(); 326 return adminContext.getAdminConfigContext(); 327 } 328 } 329 | Popular Tags |