1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Set ; 26 import java.util.Map ; 27 import java.util.Iterator ; 28 29 import java.io.Serializable ; 30 31 import javax.management.ObjectName ; 32 import javax.management.AttributeList ; 33 import javax.management.RuntimeOperationsException ; 34 35 import com.sun.appserv.management.base.Util; 36 import com.sun.appserv.management.base.XTypes; 37 import com.sun.appserv.management.util.jmx.JMXUtil; 38 import com.sun.appserv.management.util.misc.MapUtil; 39 import com.sun.appserv.management.util.misc.GSetUtil; 40 import com.sun.appserv.management.util.misc.TypeCast; 41 42 import com.sun.enterprise.management.support.oldconfig.OldApplicationsConfigMBean; 43 44 import com.sun.appserv.management.deploy.DeploymentStatus; 45 import com.sun.appserv.management.deploy.DeploymentSupport; 46 47 import com.sun.appserv.management.config.DeployedItemRefConfigCR; 48 49 52 public class DeployedItemRefConfigFactory extends ConfigFactory 53 { 54 private final OldApplicationsConfigMBean mOldApplicationsConfigMBean; 55 56 public 57 DeployedItemRefConfigFactory( 58 final ConfigFactoryCallback callbacks) 59 { 60 super( callbacks ); 61 62 mOldApplicationsConfigMBean = getOldConfigProxies().getOldApplicationsConfigMBean(); 63 } 64 65 private final Set <String > LEGAL_OPTIONAL_KEYS = 66 GSetUtil.newUnmodifiableStringSet( 67 DeployedItemRefConfigCR.ENABLED_KEY, 68 DeployedItemRefConfigCR.VIRTUAL_SERVERS_KEY, 69 DeployedItemRefConfigCR.LB_ENABLED_KEY, 70 DeployedItemRefConfigCR.DISABLE_TIMEOUT_IN_MINUTES_KEY ); 71 72 protected Set <String > 73 getLegalOptionalCreateKeys() 74 { 75 return( LEGAL_OPTIONAL_KEYS ); 76 } 77 78 79 protected Map <String ,String > 80 getParamNameOverrides() 81 { 82 return( MapUtil.newMap( CONFIG_NAME_KEY, "ref" ) ); 83 } 84 85 public ObjectName create( 86 final String referencedApplicationName, 87 final Map <String ,String > optional ) 88 { 89 trace( "DeployedItemRefConfigFactory.create: creating using: "); 90 91 final Map <String ,String > params = initParams( referencedApplicationName, null, optional ); 92 93 trace( "params as processed: " + stringify( params ) ); 94 95 final ObjectName amxName = createNamedChild( referencedApplicationName, params ); 96 97 return( amxName ); 98 } 99 100 public ObjectName create( 101 final String referencedApplicationName, 102 final boolean enabled, 103 final String virtualServers, 104 final boolean lbEnabled, 105 final int disableTimeoutInMinutes) 106 { 107 final Map <String ,String > optionalParams = new java.util.HashMap <String ,String >(); 108 putNonNull( optionalParams, DeployedItemRefConfigCR.ENABLED_KEY,Boolean.toString(enabled)); 109 putNonNull( optionalParams, DeployedItemRefConfigCR.VIRTUAL_SERVERS_KEY,virtualServers); 110 putNonNull( optionalParams, DeployedItemRefConfigCR.LB_ENABLED_KEY,Boolean.toString(lbEnabled)); 111 putNonNull( optionalParams, DeployedItemRefConfigCR.DISABLE_TIMEOUT_IN_MINUTES_KEY,Integer.toString(disableTimeoutInMinutes)); 112 113 final ObjectName amxName = create(referencedApplicationName, optionalParams); 114 return( amxName ); 115 } 116 117 118 public ObjectName 119 create(final String referencedApplicationName) 120 { 121 return create(referencedApplicationName, null); 122 } 123 124 125 public void 126 internalRemove( final ObjectName objectName ) 127 { 128 final String containerName = getFactoryContainer().getName(); 129 130 mOldApplicationsConfigMBean.deleteApplicationReferenceAndReturnStatusAsMap( 131 containerName, Util.getName( objectName ), null ); 132 } 133 134 protected ObjectName 135 createOldChildConfig( final AttributeList translatedAttrs ) 136 { 137 trace( "createOldChildConfig: attrs: " + stringify( translatedAttrs ) ); 138 139 final String REF_KEY = "ref"; 140 141 final Map <String ,String > attributeMap = JMXUtil.attributeListToStringMap( translatedAttrs ); 142 143 String appRef = null; 144 try 145 { 146 appRef = attributeMap.remove( REF_KEY ); 147 } 148 catch ( UnsupportedOperationException uoe ) 149 { 150 assert false; 151 } 152 assert appRef != null; 153 154 final String target = getFactoryContainer().getName(); 155 assert target != null; 156 157 final ObjectName on = createApplicationRef( appRef, target, attributeMap ); 158 159 return on; 160 } 161 162 private ObjectName 163 createApplicationRef( final String ref, final String target, final Map <String ,String > optional ) 164 { 165 Map <String ,Serializable > m = TypeCast.checkMap( 166 mOldApplicationsConfigMBean. 167 createApplicationReferenceAndReturnStatusAsMap( target, ref, optional ), 168 String .class, 169 Serializable .class ); 170 checkDeploymentStatusForExceptions( m ); 171 172 final String targetJ2EEType = getFactoryContainer().getJ2EEType(); 173 174 ObjectName on = null; 175 if ( XTypes.STANDALONE_SERVER_CONFIG.equals( targetJ2EEType ) ) 176 { 177 on = getOldConfigProxies().getOldServerMBean( target ). 178 getApplicationRefByRef( ref ); 179 } 180 else if ( XTypes.CLUSTER_CONFIG.equals( targetJ2EEType ) ) 181 { 182 on = getOldConfigProxies().getOldClusterMBean( target ). 183 getApplicationRefByRef( ref ); 184 } 185 else 186 { 187 throw new RuntimeException ( 188 "Application refs can be created only on clusters and standalone servers" ); 189 } 190 191 return on; 192 } 193 194 private void 195 checkDeploymentStatusForExceptions( Map <String ,Serializable > m ) 196 { 197 DeploymentStatus status = DeploymentSupport.mapToDeploymentStatus( m ); 198 Throwable t = status.getStageThrowable(); 199 final Iterator <DeploymentStatus> it = status.getSubStagesList().iterator(); 200 while ( ( t == null ) && ( it.hasNext() ) ) 201 { 202 status = it.next(); 203 t = status.getThrowable(); 204 } 205 if ( null != t ) 206 { 207 throw new RuntimeException ( status.getStageStatusMessage() ); 208 } 209 } 210 } 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | Popular Tags |