1 23 24 package com.sun.enterprise.deployment.client; 25 26 import com.sun.appserv.management.base.XTypes; 27 import com.sun.appserv.management.client.AppserverConnectionSource; 28 import com.sun.appserv.management.client.ConnectionSource; 29 import com.sun.appserv.management.client.ProxyFactory; 30 import com.sun.appserv.management.client.TLSParams; 31 import com.sun.appserv.management.config.*; 32 import com.sun.appserv.management.config.DomainConfig; 33 import com.sun.appserv.management.deploy.DeploymentMgr; 34 import com.sun.appserv.management.util.misc.SetUtil; 35 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration; 36 import com.sun.enterprise.deployapi.ProgressObjectImpl; 37 import com.sun.enterprise.deployapi.SunTarget; 38 import com.sun.enterprise.deployapi.SunTargetModuleID; 39 import com.sun.enterprise.deployment.backend.DeploymentStatus; 40 import com.sun.enterprise.deployment.client.JESProgressObject; 41 import com.sun.enterprise.deployment.deploy.shared.Archive; 42 import com.sun.enterprise.deployment.util.DeploymentProperties; 43 import com.sun.enterprise.deployment.util.DOLUtils; 44 import com.sun.enterprise.util.i18n.StringManager; 45 46 import java.io.*; 47 import java.net.URL ; 48 import java.util.*; 49 50 import javax.enterprise.deploy.shared.CommandType ; 51 import javax.enterprise.deploy.spi.Target ; 52 import javax.enterprise.deploy.spi.TargetModuleID ; 53 import javax.net.ssl.X509TrustManager; 54 55 62 public class DeploymentFacilityImpl implements DeploymentFacility { 63 64 protected ConnectionSource dasConnection = null; 65 protected ServerConnectionIdentifier serverId = null; 66 protected SunTarget domain = null; 67 protected Boolean localConnection = Boolean.FALSE; 68 69 private static final String DAS = "server"; 70 private static StringManager localStrings = StringManager.getManager(DeploymentFacilityImpl.class); 71 72 public DeploymentFacilityImpl() {} 73 74 78 public boolean connect(ServerConnectionIdentifier targetDAS) { 79 try { 80 TLSParams tlsParams = null; 81 if (targetDAS.isSecure()) { 82 X509TrustManager trustManager = 83 (X509TrustManager)targetDAS.getConnectionEnvironment(). 84 get(DefaultConfiguration.TRUST_MANAGER_PROPERTY_NAME); 85 tlsParams = new TLSParams(trustManager, null); 86 } 87 88 dasConnection = new AppserverConnectionSource( 89 AppserverConnectionSource.PROTOCOL_HTTP, 90 targetDAS.getHostName(), targetDAS.getHostPort(), 91 targetDAS.getUserName(), targetDAS.getPassword(), 92 tlsParams, null); 93 } catch (IllegalArgumentException illEx) { 94 return false; 95 } 96 serverId = targetDAS; 97 domain = new SunTarget(targetDAS); 98 domain.setConnectionSource(dasConnection); 99 domain.setTargetType(TargetType.DOMAIN); 100 return true; 101 } 102 103 107 public boolean isConnected() { 108 if(dasConnection == null) { 109 return false; 110 } 111 return true; 112 } 113 114 118 public boolean disconnect() { 119 dasConnection = null; 120 return true; 121 } 122 123 138 public JESProgressObject deploy(Target[] targets, Archive source, Archive deploymentPlan, Map deploymentOptions) { 139 if(!isConnected()) { 140 throw new IllegalStateException (localStrings.getString("enterprise.deployment.client.disconnected_state")); 141 } 142 143 SunTarget[] targetList = getSunTargets(targets); 144 ProgressObjectImpl progressObject = new DeployAction(targetList); 145 Object args[] = new Object [8]; 146 args[0] = dasConnection; 147 args[1] = source; 148 args[2] = deploymentPlan; 149 args[3] = (deploymentOptions == null) ? new HashMap() : DeploymentProperties.propsToMap((Properties)deploymentOptions); 150 args[4] = targetList; 151 args[5] = domain; 152 args[6] = localConnection; 153 args[7] = serverId; 154 progressObject.setCommand(CommandType.DISTRIBUTE, args); 155 Thread newThread = new Thread (progressObject); 156 newThread.start(); 157 return progressObject; 158 } 159 160 165 public JESProgressObject undeploy(Target[] targets, String moduleID) { 167 return(undeploy(targets, moduleID, null)); 168 } 169 170 public JESProgressObject undeploy(Target[] targets, String moduleID, Map options) { 171 if(!isConnected()) { 172 throw new IllegalStateException (localStrings.getString("enterprise.deployment.client.disconnected_state")); 173 } 174 SunTarget[] targetList = getSunTargets(targets); 175 ProgressObjectImpl progressObject = new UndeployAction(targetList); 176 Object args[] = new Object [6]; 177 args[0] = dasConnection; 178 args[1] = moduleID; 179 args[2] = (options == null) ? new HashMap() : DeploymentProperties.propsToMap((Properties)options); 180 args[3] = targetList; 181 args[4] = domain; 182 args[5] = localConnection; 183 progressObject.setCommand(CommandType.UNDEPLOY, args); 184 Thread newThread = new Thread (progressObject); 185 newThread.start(); 186 return progressObject; 187 } 188 189 192 public JESProgressObject enable(Target[] targets, String moduleID) { 193 return(changeState(targets, moduleID, CommandType.START)); 194 } 195 196 199 public JESProgressObject disable(Target[] targets, String moduleID) { 200 return(changeState(targets, moduleID, CommandType.STOP)); 201 } 202 203 private JESProgressObject changeState(Target[] targets, String moduleID, CommandType cmd) { 204 if(!isConnected()) { 205 throw new IllegalStateException (localStrings.getString("enterprise.deployment.client.disconnected_state")); 206 } 207 SunTarget[] targetList = getSunTargets(targets); 208 ProgressObjectImpl progressObject = new ChangeStateAction(targetList); 209 Object args[] = new Object [5]; 210 args[0] = dasConnection; 211 args[1] = targetList; 212 args[2] = moduleID; 213 args[3] = cmd; 214 args[4] = domain; 215 progressObject.setCommand(cmd, args); 216 Thread newThread = new Thread (progressObject); 217 newThread.start(); 218 return progressObject; 219 } 220 221 224 public JESProgressObject createAppRef(Target[] targets, String moduleID, Map options) { 225 return(doApplicationReferenceAction(targets, moduleID, options, CommandType.DISTRIBUTE)); 226 } 227 228 231 public JESProgressObject deleteAppRef(Target[] targets, String moduleID, Map options) { 232 return(doApplicationReferenceAction(targets, moduleID, options, CommandType.UNDEPLOY)); 233 } 234 235 private JESProgressObject doApplicationReferenceAction(Target[] targets, String moduleID, Map options, CommandType cmd) { 236 if(!isConnected()) { 237 throw new IllegalStateException (localStrings.getString("enterprise.deployment.client.disconnected_state")); 238 } 239 SunTarget[] targetList = getSunTargets(targets); 240 ProgressObjectImpl progressObject = new ApplicationReferenceAction(targetList); 241 Object args[] = new Object [5]; 242 args[0] = dasConnection; 243 args[1] = targetList; 244 args[2] = moduleID; 245 args[3] = cmd; 246 args[4] = (options == null) ? new HashMap() : DeploymentProperties.propsToMap((Properties)options); 247 progressObject.setCommand(cmd, args); 248 Thread newThread = new Thread (progressObject); 249 newThread.start(); 250 return progressObject; 251 } 252 253 256 public TargetModuleID[] listAppRefs(String [] targets) throws IOException { 257 if(!isConnected()) { 258 throw new IllegalStateException (localStrings.getString("enterprise.deployment.client.disconnected_state")); 259 } 260 Vector tmpVector = new Vector(); 261 DomainConfig domainCfg = ProxyFactory.getInstance(dasConnection).getDomainRoot().getDomainConfig(); 262 Map serverProxies = domainCfg.getStandaloneServerConfigMap(); 263 Map clusterProxies = domainCfg.getClusterConfigMap(); 264 Map clusteredServerProxies = domainCfg.getClusteredServerConfigMap(); 265 for(int i=0; i<targets.length; i++) { 266 Set proxySet = null; 267 if(serverProxies.get(targets[i]) != null) { 268 StandaloneServerConfig tgtProxy = 269 (StandaloneServerConfig)domainCfg.getContainee( 270 XTypes.STANDALONE_SERVER_CONFIG, targets[i]); 271 proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG); 272 } else if(clusterProxies.get(targets[i]) != null) { 273 ClusterConfig tgtProxy = 274 (ClusterConfig)domainCfg.getContainee( 275 XTypes.CLUSTER_CONFIG, targets[i]); 276 proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG); 277 } else if(clusteredServerProxies.get(targets[i]) != null) { 278 ClusteredServerConfig tgtProxy = 279 (ClusteredServerConfig)domainCfg.getContainee( 280 XTypes.CLUSTERED_SERVER_CONFIG, targets[i]); 281 proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG); 282 } else if(TargetType.DOMAIN.equals(targets[i])) { 283 StandaloneServerConfig tgtProxy = 284 (StandaloneServerConfig)domainCfg.getContainee( 285 XTypes.STANDALONE_SERVER_CONFIG, DAS); 286 proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG); 287 } else { 288 return null; 289 } 290 Object [] appRefs = proxySet.toArray(); 291 for(int k=0; k<appRefs.length; k++) { 292 SunTarget aTarget = new SunTarget(serverId); 293 aTarget.setAppServerInstance(targets[i]); 294 aTarget.setConnectionSource(dasConnection); 295 DeployedItemRefConfig item = (DeployedItemRefConfig) appRefs[k]; 296 SunTargetModuleID tgtId = new SunTargetModuleID(item.getRef(), aTarget); 297 tmpVector.add(tgtId); 298 } 299 } 300 SunTargetModuleID[] result = new SunTargetModuleID[tmpVector.size()]; 301 return (TargetModuleID[]) tmpVector.toArray(result); 302 } 303 304 307 private SunTarget[] getSunTargets(Target[] givenTargets) throws IllegalArgumentException { 308 SunTarget[] result = new SunTarget[givenTargets.length]; 309 for(int i=0; i<givenTargets.length; i++) { 310 if(givenTargets[i] instanceof SunTarget) { 311 result[i] = new SunTarget((SunTarget)givenTargets[i]); 312 } else { 313 throw new IllegalArgumentException (localStrings.getString("enterprise.deployment.client.notASunTarget", 314 givenTargets[i].getClass().getName())); 315 } 316 } 317 return result; 318 } 319 320 336 public String downloadFile(File location, String moduleID, String moduleURI) 337 throws IOException { 338 if(!isConnected()) { 339 throw new IllegalStateException ( 340 localStrings.getString("enterprise.deployment.client.disconnected_state")); 341 } 342 343 return DeploymentClientUtils.downloadClientStubs( 344 moduleID, location.getAbsolutePath(), dasConnection); 345 } 346 347 354 public DeploymentStatus waitFor(JESProgressObject po) { 355 DeploymentStatus status = null; 356 do { 357 try { 358 Thread.currentThread().sleep(100); 359 } catch (InterruptedException ie) { 360 } 362 status = po.getCompletedStatus(); 363 } while(status == null); 364 return status; 365 } 366 367 public Target[] createTargets(String [] targets ) { 368 if(!isConnected()) { 369 throw new IllegalStateException (localStrings.getString("enterprise.deployment.client.disconnected_state")); 370 } 371 Target[] targetsArray = new Target[targets.length]; 372 Map serverProxies = null; 373 Map clusterProxies = null; 374 375 try { 376 for(int i=0; i<targets.length; i++) { 378 379 if(TargetType.DOMAIN.equals(targets[i])) { 381 SunTarget dom = new SunTarget(serverId); 383 dom.setAppServerInstance(TargetType.DOMAIN); 384 dom.setConnectionSource(dasConnection); 385 dom.setTargetType(TargetType.DOMAIN); 386 targetsArray[i] = dom; 387 continue; 388 } 389 if(DAS.equals(targets[i])) { 391 SunTarget serv = new SunTarget(serverId); 393 serv.setAppServerInstance(DAS); 394 serv.setConnectionSource(dasConnection); 395 serv.setTargetType(TargetType.STAND_ALONE_SERVER); 396 targetsArray[i] = serv; 397 continue; 398 } 399 if(serverProxies == null || clusterProxies == null) { 401 DomainConfig domainCfg = ProxyFactory.getInstance(dasConnection).getDomainRoot().getDomainConfig(); 402 serverProxies = domainCfg.getStandaloneServerConfigMap(); 403 clusterProxies = domainCfg.getClusterConfigMap(); 404 } 405 if(serverProxies.get(targets[i]) != null) { 407 SunTarget aTarget = new SunTarget(serverId); 408 aTarget.setAppServerInstance(targets[i]); 409 aTarget.setConnectionSource(dasConnection); 410 aTarget.setTargetType(TargetType.STAND_ALONE_SERVER); 411 targetsArray[i] = aTarget; 412 continue; 413 } 414 if(clusterProxies.get(targets[i]) != null) { 416 SunTarget aTarget = new SunTarget(serverId); 417 aTarget.setAppServerInstance(targets[i]); 418 aTarget.setConnectionSource(dasConnection); 419 aTarget.setTargetType(TargetType.CLUSTER); 420 targetsArray[i] = aTarget; 421 continue; 422 } 423 return null; 425 } 426 } catch (Throwable ex) { 427 return null; 428 } 429 return targetsArray; 430 } 431 } 432 | Popular Tags |