1 23 24 package com.sun.enterprise.admin.server.core.mbean.config; 25 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 import java.util.ArrayList ; 29 import java.io.InputStream ; 30 import java.net.InetAddress ; 31 import java.io.BufferedReader ; 32 import java.io.InputStreamReader ; 33 34 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 36 import com.sun.enterprise.config.serverbeans.ServerTags; 37 import com.sun.enterprise.config.ConfigContext; 38 import com.sun.enterprise.config.ConfigException; 39 import com.sun.enterprise.config.serverbeans.Server; 40 import com.sun.enterprise.config.serverbeans.Config; 41 import com.sun.enterprise.config.serverbeans.HttpService; 42 import com.sun.enterprise.config.serverbeans.HttpListener; 43 44 import com.sun.enterprise.instance.InstanceEnvironment; 46 import com.sun.enterprise.instance.ServerManager; 47 48 import com.sun.enterprise.admin.util.HostAndPort; 50 import com.sun.enterprise.admin.common.ObjectNames; 51 import com.sun.enterprise.admin.common.constant.AdminConstants; 52 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 53 import com.sun.enterprise.admin.common.exception.ServerInstanceException; 54 import com.sun.enterprise.admin.common.exception.PortInUseException; 55 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 56 57 import com.sun.enterprise.admin.server.core.mbean.config.Domain2ServerTransformer; 58 import com.sun.enterprise.server.Constants; 59 60 61 67 68 public class ManagedAdminServerInstance extends ConfigMBeanBase 69 { 70 private static final String [][] MAPLIST = 71 { 72 }; 76 77 private static final String [] ATTRIBUTES = 78 { 79 }; 81 82 private static final String [] OPERATIONS = 83 { 84 "applyConfigChanges(), ACTION", 85 "useManualConfigChanges(), ACTION", 86 "getHostAndPort(), INFO", 87 "isApplyNeeded(), INFO", 88 "isRestartNeeded(), INFO" 90 }; 91 92 private static final Logger _logger = Logger.getLogger( 93 AdminConstants.kLoggerName); 94 95 private ManagedServerInstance mDelegate; 96 97 private boolean mRestartNeeded = false; 98 99 public ManagedAdminServerInstance() throws MBeanConfigException 100 { 101 this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS); 102 this.initialize(ObjectNames.kServerInstance, new String []{ServerManager.ADMINSERVER_ID}); 103 } 104 105 116 public boolean applyConfigChanges() throws ServerInstanceException 117 { 118 try { 119 InstanceEnvironment ie = new InstanceEnvironment( 120 ServerManager.ADMINSERVER_ID); 121 initDelegate(); 127 ConfigContext ctx = mDelegate.getConfigContext( 128 ServerManager.ADMINSERVER_ID); 129 ctx.resetConfigChangeList(); 130 mRestartNeeded = true; 131 132 133 if (ManagedServerInstance.PORT_DOMAIN_TO_SERVER) { 134 final String domainXMLPath = ie.getConfigFilePath(); 135 final String serverXMLPath = System.getProperty(Constants.IAS_ROOT) 136 + "/" 137 + ie.getName() 138 + "/config/" 139 + ie.kServerXMLFileName; 140 new Domain2ServerTransformer(domainXMLPath, serverXMLPath).transform(); 141 } 142 143 } catch (ConfigException ce) { 144 _logger.log(Level.INFO, "mbean.config.admin.apply_failed", 145 ce.getLocalizedMessage()); 146 _logger.log(Level.FINEST, ce.getMessage(), ce); 147 throw new ServerInstanceException(ce.getLocalizedMessage()); 148 } 149 return mRestartNeeded; 150 } 151 152 162 public boolean canApplyConfigChanges() 163 { 164 boolean canApply = false; 165 try { 166 initDelegate(); 167 InstanceEnvironment ie = new InstanceEnvironment( 168 ServerManager.ADMINSERVER_ID); 169 178 canApply = true; 179 182 } catch (Exception ex) { 183 _logger.log(Level.INFO, "mbean.config.admin.canapply_failed", 184 ex.getLocalizedMessage()); 185 _logger.log(Level.FINEST, ex.getLocalizedMessage(), ex); 186 } 187 return canApply; 188 } 189 190 195 public boolean useManualConfigChanges() throws ServerInstanceException 196 { 197 try { 198 initDelegate(); 199 InstanceEnvironment ie = 200 new InstanceEnvironment(ServerManager.ADMINSERVER_ID); 201 mDelegate.reloadAfterChange(ie); 205 mRestartNeeded = true; 209 } catch (ConfigException ce) { 210 _logger.log(Level.INFO, "mbean.config.admin.usemanual_failed", 211 ce.getMessage()); 212 _logger.log(Level.FINEST, ce.getMessage(), ce); 213 throw new ServerInstanceException(ce.getLocalizedMessage()); 214 } 215 return mRestartNeeded; 216 } 217 218 224 public boolean isApplyNeeded(boolean check) throws ServerInstanceException { 225 return isApplyNeeded(); 226 } 227 228 234 public boolean isApplyNeeded() throws ServerInstanceException 235 { 236 boolean applyNeeded = false; 237 try 238 { 239 initDelegate(); 240 ConfigContext ctx = mDelegate.getConfigContext( 241 ServerManager.ADMINSERVER_ID); 242 applyNeeded = ctx.isChanged(); 243 } catch (ConfigException ce) { 244 _logger.log(Level.INFO, "mbean.config.admin.applyneeded_failed", 245 ce.getMessage()); 246 _logger.log(Level.FINEST, ce.getMessage(), ce); 247 throw new ServerInstanceException(ce.getLocalizedMessage()); 248 } 249 return applyNeeded; 250 } 251 252 257 public boolean isRestartNeeded() throws ServerInstanceException 258 { 259 return mRestartNeeded; 260 } 261 262 264 public HostAndPort getHostAndPort() throws ServerInstanceException 265 { 266 return getHttpListenerHostPort(); 267 } 268 269 private synchronized void initDelegate() throws ServerInstanceException 270 { 271 if (mDelegate != null) 272 { 273 return; 274 } 275 try 276 { 277 HostAndPort hp = getHttpListenerHostPort(); 278 mDelegate = new ManagedServerInstance(ServerManager.ADMINSERVER_ID, 279 hp, false); 280 } 281 catch (ServerInstanceException sie) 282 { 283 throw sie; 284 } 285 catch (PortInUseException piue) 286 { 287 } 288 catch (Exception e) 289 { 290 throw new ServerInstanceException(e.getLocalizedMessage()); 291 } 292 } 293 294 298 private HostAndPort getHttpListenerHostPort() 299 throws ServerInstanceException 300 { 301 HostAndPort hAndp = null; 302 try 303 { 304 Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG); 306 HttpService https = config.getHttpService(); 307 308 HttpListener[] hlArray = https.getHttpListener(); 309 HttpListener ls = hlArray[0]; 312 for(int i = 0;i<hlArray.length;i++) { 314 if(hlArray[i].isEnabled()) { 315 ls = hlArray[i]; 316 break; 317 } 318 } 319 320 String port = ls.getPort(); 321 int intPort = Integer.parseInt (port); 322 hAndp = new HostAndPort("localhost", intPort); 323 } 324 catch (Exception e) 325 { 326 throw new ServerInstanceException(e.getLocalizedMessage()); 327 } 328 return hAndp; 329 } 330 331 332 } 333 | Popular Tags |