JavaEEServiceEngineSUManagerpublic class JavaEEServiceEngineSUManager extends Object implements com.sun.enterprise.jbi.serviceengine.util.JBIConstants, javax.jbi.component.ServiceUnitManagerRepresents JavaEE Service Engine ServiceUnitManager, responsible for
deploy/undeploy/start/stop of JavaEE application packaged inside the service
assembly. |
Fields Summary |
---|
protected static final Logger | logger | private String | className | private com.sun.enterprise.deployment.client.DeploymentFacility | deployer | private String | target | private JBIEndpointManager | epManager | private Set | dummyCompApps |
Constructors Summary |
---|
public JavaEEServiceEngineSUManager()Creates a new instance of JavaEEServiceEngineServiceUnitManager
createDeployer();
epManager = new JBIEndpointManager();
dummyCompApps = new HashSet<String>();
|
Methods Summary |
---|
private java.lang.String | createArchive(java.lang.String dir, java.lang.String archiveName)
String archivePath;
try {
Archivist archivist = ArchivistFactory.getArchivistForArchive(dir);
String pathExtn = ".jar";
if (ModuleType.EAR.equals(archivist.getModuleType())) {
pathExtn = ".ear";
} else if (ModuleType.WAR.equals(archivist.getModuleType())) {
pathExtn = ".war";
} else if (ModuleType.RAR.equals(archivist.getModuleType())) {
pathExtn = ".rar";
}
String workspaceDir =
JavaEEServiceEngineContext.getInstance().
getJBIContext().getWorkspaceRoot();
archivePath = workspaceDir + File.separator + archiveName + pathExtn;
createJar(dir, archivePath);
} catch (IOException ioe) {
logger.log(Level.SEVERE, ioe.getMessage(), ioe);
archivePath = null;
}
return archivePath;
| private void | createDeployer()
deployer = DeploymentFacilityFactory.getLocalDeploymentFacility();
| private void | createJar(java.lang.String sourcePath, java.lang.String destinationPath)
FileArchive source = new FileArchive();
OutputJarArchive destination = new OutputJarArchive();
try {
source.open(sourcePath);
Enumeration entries = source.entries();
destination.create(destinationPath);
while(entries.hasMoreElements()) {
String entry = String.class.cast(entries.nextElement());
InputStream is = null;
OutputStream os = null;
try {
is = source.getEntry(entry);
os = destination.putNextEntry(entry);
ArchivistUtils.copyWithoutClose(is, os);
} finally {
if (is != null) is.close();
if (os != null) destination.closeEntry();
}
}
} finally {
source.close();
destination.close();
}
| public java.lang.String | deploy(java.lang.String suId, java.lang.String suPath)Only deploy the JavaEE application and keep it in 'disable'
state until JBI fires start event.
String methodSig = className + "deploy(String, String)";
logger.log(Level.FINE,
methodSig + " suId = " + suId + ". suPath = " + suPath);
if (!isDAS() || isPrivateMBeanRegistered()) {
logger.log(Level.FINE,
methodSig + " either a non-DAS instance or deployment is done " +
"through private MBean, hence skipping deploy.");
return Util.buildManagementMessage(
"STATUS_MSG",
"deploy",
"SUCCESS",
null,
suId,
null,
null);
}
return doDeploy(suId, suPath, target);
| protected java.lang.String | doDeploy(java.lang.String serviceUnitName, java.lang.String appLocation, java.lang.String target)
String methodSig = className + "doDeploy(String,String,String,String) "; // used for logging.
boolean deploymentSuccessful = true;
String deploymentError = null;
Throwable deploymentException = null;
String archivePath = null;
AbstractArchive arch = null;
try {
if (!isDummyApp(appLocation)) {
if(!(USED_WITH_NON_SOAP_WSDL.equalsIgnoreCase(System.getProperty(USED_WITH)))) {
appLocation = processWSDLs(appLocation);
}
archivePath = (new File(appLocation)).isDirectory()
? createArchive(appLocation, serviceUnitName)
: appLocation;
logger.log(Level.FINE,
methodSig + " appName = " + serviceUnitName + ", archivePath = " +
archivePath + ", target = " + target);
Map deployOptions = getDefaultDeploymentOptions(archivePath,
serviceUnitName,
target);
arch = (new ArchiveFactory()).openArchive(archivePath);
AbstractArchive plan = null;
Target[] targets = deployer.createTargets(new String[]{target});
logger.log(Level.FINE, methodSig + " calling backend deploy");
JESProgressObject progressObject =
deployer.deploy(targets, arch, plan, deployOptions);
DeploymentStatus status = deployer.waitFor(progressObject);
logger.log(Level.FINE,
methodSig + " deployment complete. status = " + status.getStatus());
if (status.getStatus() != DeploymentStatus.SUCCESS) {
deploymentSuccessful = false;
deploymentError = methodSig + status.toString();
deploymentException = status.getStageException();
}
} else {
dummyCompApps.add(serviceUnitName);
}
} catch (Exception ex) {
deploymentSuccessful = false;
deploymentError = methodSig + ex.getMessage();
deploymentException = ex;
} finally {
if(arch != null) {
try {
arch.close();
} catch(Exception ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
if(archivePath != null && (new File(appLocation)).isDirectory() ) {
try {
boolean deleteSuccessful = new File(archivePath).delete();
if(!deleteSuccessful) {
logger.log(Level.SEVERE, "Unable to delete the archive " + archivePath);
}
} catch(Exception ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
if(deploymentSuccessful) {
logger.log(Level.FINE, methodSig + " successfully deployed " + serviceUnitName);
return Util.buildManagementMessage(
"STATUS_MSG",
"deploy",
"SUCCESS",
null,
serviceUnitName,
null,
null);
} else {
logger.log(Level.SEVERE, deploymentError, deploymentException);
return Util.buildManagementMessage(
"EXCEPTION_MSG",
"deploy",
"FAILED",
null,
serviceUnitName,
deploymentError,
deploymentException);
}
| protected void | doStart(java.lang.String serviceUnitName, java.lang.String target)
String methodSig = className + "doStart(String,String) "; // used for logging.
boolean startSuccessful = true;
String startError = null;
Throwable startException = null;
try {
if(!dummyCompApps.contains(serviceUnitName)) {
Target[] targets = deployer.createTargets(new String[]{target});
JESProgressObject progressObject =
deployer.enable(targets, serviceUnitName);
DeploymentStatus status = deployer.waitFor(progressObject);
if (status.getStatus() != DeploymentStatus.SUCCESS) {
startSuccessful = false;
startError = methodSig + status.toString();
startException = status.getStageException();
}
}
} catch (Exception ex) {
startSuccessful = false;
startError = methodSig + ex.getMessage();
startException = ex;
}
if(startSuccessful) {
logger.log(Level.FINE, methodSig + " successfully started " + serviceUnitName);
} else {
logger.log(Level.SEVERE, startError, startException);
}
| protected void | doStop(java.lang.String serviceUnitName, java.lang.String target)
String methodSig = className + "doStop(String,String) "; // used for logging.
boolean stopSuccessful = true;
String stopError = null;
Throwable stopException = null;
try {
if(!dummyCompApps.contains(serviceUnitName)) {
Target[] targets = deployer.createTargets(new String[]{target});
JESProgressObject progressObject =
deployer.disable(targets, serviceUnitName);
DeploymentStatus status = deployer.waitFor(progressObject);
if (status.getStatus() != DeploymentStatus.SUCCESS) {
stopSuccessful = false;
stopError = methodSig + status.toString();
stopException = status.getStageException();
}
}
} catch (Exception ex) {
stopSuccessful = false;
stopError = methodSig + ex.getMessage();
stopException = ex;
}
if(stopSuccessful) {
logger.log(Level.FINE, methodSig + " successfully stopped " + serviceUnitName);
} else {
logger.log(Level.SEVERE, stopError, stopException);
}
| protected java.lang.String | doUnDeploy(java.lang.String serviceUnitName, java.lang.String target)
String methodSig = className + "doUnDeploy(String,String,String) "; // used for logging.
boolean undeploymentSuccessful = true;
String undeploymentError = null;
Throwable undeploymentException = null;
try {
//TODO: clear registries (wsdlCache)
if(!dummyCompApps.remove(serviceUnitName)) {
Target[] targets = deployer.createTargets(new String[]{target});
JESProgressObject progressObject =
deployer.undeploy(targets, serviceUnitName, getUnDeploymentOptions());
DeploymentStatus status = deployer.waitFor(progressObject);
if (status.getStatus() != DeploymentStatus.SUCCESS) {
undeploymentSuccessful = false;
undeploymentError = methodSig + status.toString();
undeploymentException = status.getStageException();
}
}
} catch (Exception ex) {
undeploymentSuccessful = false;
undeploymentError = methodSig + ex.getMessage();
undeploymentException = ex;
}
if(undeploymentSuccessful) {
logger.log(Level.FINE, methodSig + " successfully undeployed " + serviceUnitName);
return Util.buildManagementMessage(
"STATUS_MSG",
"undeploy",
"SUCCESS",
null,
serviceUnitName,
null,
null);
} else {
logger.log(Level.SEVERE, undeploymentError, undeploymentException);
return Util.buildManagementMessage(
"EXCEPTION_MSG",
"undeploy",
"FAILED",
null,
serviceUnitName,
undeploymentError,
undeploymentException);
}
| private void | explodeArchive(java.lang.String src, java.lang.String dest)
File srcFile = new File(src);
File destFile = new File(dest);
if(destFile.exists()) {
DeploymentContext.deleteDirectory(destFile);
destFile.mkdir();
}
Archivist archivist = ArchivistFactory.getArchivistForArchive(srcFile);
try {
ModuleType moduleType = archivist.getModuleType();
if(ModuleType.EAR.equals(moduleType)) {
J2EEModuleExploder.explodeEar(srcFile, destFile);
} else if ( ModuleType.EJB.equals(moduleType) ||
ModuleType.CAR.equals(moduleType) ||
ModuleType.RAR.equals(moduleType) ||
ModuleType.WAR.equals(moduleType) ) {
J2EEModuleExploder.explodeJar(srcFile, destFile);
}
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
| private java.util.Map | getDefaultDeploymentOptions(java.lang.String archivePath, java.lang.String appName, java.lang.String target)
DeploymentProperties deploymentOptions = new DeploymentProperties();
deploymentOptions.setName(appName);
deploymentOptions.setForce(true);
deploymentOptions.setArchiveName(archivePath);
deploymentOptions.setEnable(false);
deploymentOptions.setTarget(target);
deploymentOptions.setExternallyManaged(true);
return deploymentOptions;
| private java.util.Map | getUnDeploymentOptions()
DeploymentProperties undeploymentOptions = new DeploymentProperties();
undeploymentOptions.setExternallyManaged(true);
return undeploymentOptions;
| public void | init(java.lang.String suId, java.lang.String suPath)
String methodSig = className + "init(String, String)";
logger.log(Level.FINE,
methodSig + " suId = " + suId + ". suPath = " + suPath);
try {
if(isDummyApp(suPath))
dummyCompApps.add(suId);
epManager.storeAllEndpoints(suPath, suId);
} catch (Exception e) {
throw new DeploymentException(e);
}
/**
* Start the Java EE app & enable the endpoints in NMR
*/
if (isDAS() && !isPrivateMBeanRegistered()) {
logger.log(Level.FINE,
methodSig +
" either a non-DAS instance or start is done through" +
" private MBean, hence skipping start.");
doStart(suId, target);
}
try {
epManager.startAllEndpoints(suId);
} catch (Exception e) {
throw new DeploymentException(e);
}
| private boolean | isDAS()
try {
return ServerHelper.isDAS(
AdminService.getAdminService().getAdminContext().getAdminConfigContext(),
ApplicationServer.getServerContext().getInstanceName());
} catch (Exception ex) {
logger.log(Level.SEVERE, className + ex.getMessage(), ex);
//better be more restrictive by returning false
return false;
}
| private boolean | isDummyApp(java.lang.String appLocation)Check whether this is a dummy JavaEE application. In such case deployment
will be skipped as the application will be deployed outside of the
composite application.
In a dummy application allowed entries are -
META-INF/jbi.xml and META-INF/MANINFEST.MF.
File app = new File(appLocation);
if(app.isDirectory()) {
for (Object fileObj : FileUtil.getAllFilesAndDirectoriesUnder(app)) {
String path = ((File)fileObj).getPath();
if(!("META-INF"+File.separator+"jbi.xml").equalsIgnoreCase(path) &&
!("META-INF"+File.separator+"MANIFEST.MF").equalsIgnoreCase(path) &&
!"META-INF".equalsIgnoreCase(path))
return false;
}
} else {
ZipFile zipFile = new ZipFile(appLocation);
for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
String entryName = ((ZipEntry)e.nextElement()).getName();
if(!("META-INF/jbi.xml").equalsIgnoreCase(entryName) &&
!("META-INF/MANIFEST.MF").equalsIgnoreCase(entryName) &&
!("META-INF/").equalsIgnoreCase(entryName)) {
return false;
}
}
}
return true;
| private boolean | isPrivateMBeanRegistered()
try {
ComponentContext jbiContext =
JavaEEServiceEngineContext.getInstance().getJBIContext();
ObjectName privateMBeanName =
jbiContext.getMBeanNames().createCustomComponentMBeanName("JavaEEDeployer");
boolean isPrivateMBeanRegistered =
jbiContext.getMBeanServer().isRegistered(privateMBeanName);
logger.log(Level.FINE,
"isPrivateMBeanRegistered = " + isPrivateMBeanRegistered);
return isPrivateMBeanRegistered;
} catch(Exception ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
return false;
}
| private java.lang.String | processWSDLs(java.lang.String appLocation)Convert all the NonSOAP WSDLs under appLocation to SOAP WSDLs.
String newAppLocation;
if(!(new File(appLocation).isDirectory())) {
try {
String workspaceDir =
JavaEEServiceEngineContext.getInstance().
getJBIContext().getWorkspaceRoot();
newAppLocation = workspaceDir + File.separator + "exploded";
explodeArchive(appLocation, newAppLocation);
} catch(Exception ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
return appLocation;
}
} else { // Ideally the appLocation contents should be copied onto newAppLocation.
newAppLocation = appLocation;
}
return
WSDLConverter.convertWSDLs(newAppLocation).isEmpty()
? appLocation
: newAppLocation;
| public void | shutDown(java.lang.String suId)
String methodSig = className + "shutDown(String)";
logger.log(Level.FINE, methodSig + " suId = " + suId);
try {
dummyCompApps.remove(suId);
epManager.removeAllEndpoints(suId);
} catch (Exception e) {
throw new DeploymentException(e);
}
| public void | start(java.lang.String suId)Enable the deployed JavaEE application during the start event.
String methodSig = className + "start(String) :: NO-OP";
logger.log(Level.FINE, methodSig + " suId = " + suId);
| public void | stop(java.lang.String suId)Disable the deployed JavaEE application during the stop event.
String methodSig = className + "stop(String)";
logger.log(Level.FINE, methodSig + " suId = " + suId);
if (isDAS() && !isPrivateMBeanRegistered()) {
logger.log(Level.FINE,
methodSig +
" either a non-DAS instance or deployment is done " +
"through private MBean, hence skipping stop.");
doStop(suId, target);
}
try {
epManager.stopAllEndpoints(suId);
} catch (Exception e) {
throw new DeploymentException(e);
}
| public java.lang.String | undeploy(java.lang.String suId, java.lang.String suPath)
String methodSig = className + "undeploy(String, String)";
logger.log(Level.FINE,
methodSig + " suId = " + suId + ". suPath = " + suPath);
if (!isDAS() || isPrivateMBeanRegistered()) {
logger.log(Level.FINE,
methodSig +
" either a non-DAS instance or undeployment is done" +
" through private MBean, hence skipping undeploy.");
return Util.buildManagementMessage(
"STATUS_MSG",
"undeploy",
"SUCCESS",
null,
suId,
null,
null);
}
return doUnDeploy(suId, target);
|
|