Methods Summary |
---|
private void | cleanupAppAndRequest(java.io.File f)
boolean logFine = sLogger.isLoggable(Level.FINE);
/*
* Clean up the application file or directory.
*/
if (f.isDirectory()) {
if (logFine) {
sLogger.fine("Deleting autodeployed directory " + f.getAbsolutePath() + " by request");
}
FileUtils.liquidate(f);
} else {
if (logFine) {
sLogger.fine("Deleting autodeployed file " + f.getAbsolutePath() + " by request");
}
FileUtils.deleteFile(f);
}
/*
* Remove the undeploy request file.
*/
File requestFile = AutoDeployedFilesManager.appToUndeployRequestFile(f);
if (logFine) {
sLogger.fine("Deleting autodeploy request file " + requestFile.getAbsolutePath());
}
FileUtils.deleteFile(requestFile);
|
protected void | deleteAllMarks(java.io.File f)
try {
getDeployedFile(f).delete();
getDeployFailedFile(f).delete();
getUndeployedFile(f).delete();
getUndeployFailedFile(f).delete();
} catch (Exception e) {
//ignore
}
|
protected int | deploy(java.io.File deployablefile, java.io.File autodeployDir, java.lang.String name)Deploy any type of module.
int status=DEPLOY_FAILURE;
if(cancelDeployment) {
return status;
}
String file=deployablefile.getAbsolutePath();
status = retryManager.testFileAsArchive(file);
if (status != DEPLOY_SUCCESS) {
return status;
}
JBIAutoDeployer jad = JBIAutoDeployer.getInstance();
String msg = localStrings.getString(
"enterprise.deployment.autodeploy.selecting_file",
deployablefile.getAbsolutePath());
sLogger.log(Level.INFO, msg);
if (jad.isJbiArchive(deployablefile)) {
return deployJbiArchive(deployablefile);
} else {
return deployJavaEEArchive(deployablefile, autodeployDir, name);
}
|
public void | deployAll(java.io.File autoDeployDir)do deployment for all the deployable components in autoDeployDir dir.
deployAll(autoDeployDir, false);
|
public void | deployAll(java.io.File autoDeployDir, boolean includeSubDir)do deployment for all the deployable components in autoDeployDir dir.
//create with default scanner
if(directoryScanner==null) {
directoryScanner=new AutoDeployDirectoryScanner();
}
//set target to default
if(this.targetInstance == null) {
setTarget(getDefaultTarget());
}
File [] files= null;
//get me all deployable entities
files= directoryScanner.getAllDeployableModules(autoDeployDir, includeSubDir);
/*
*The following pattern appears in each of the sections below, even though
*it is described in detail only once here. This can be improved
*once autodeploy is converted to use the DeploymentFacility.
*
*To support slowly-copied files, the deployApplication (and deployWarmodule, and
*deployRarModule and deployEjbModule) methods return
* DEPLOY_SUCCESS if the file was successfully autodeployed
* DEPLOY_FAILURE if the file failed to be autodeployed
* DEPLOY_PENDING if the file needs to be tried again later
*
*The marker files should be updated only if the result is success or
*failure. So for each file of each type, make a separate decision
*about whether to record the result or not based on the result of
*the deploy* method. Note that the boolean is initialized to true
*so that if an exception is thrown, the file's marker files will be
*updated.
*/
if(files != null) {
for (int i=0; ((i < files.length) && !cancelDeployment);i++) {
boolean okToRecordResult = true;
try {
okToRecordResult = (deploy(files[i], autoDeployDir,
getNameFromFilePath(autoDeployDir,
files[i])) != DEPLOY_PENDING);
} catch (AutoDeploymentException ae) {
//ignore and move to next file
} finally {
if(renameOnSuccess && okToRecordResult)
directoryScanner.deployedEntity(autoDeployDir, files[i]);
}
}
}
|
public void | deployAll(java.io.File autoDeployDir, boolean verify, boolean jspPreCompilation)do deployment for all the deployable components in autoDeployDir dir.
this.verify= new Boolean(verify);
this.jspPreCompilation=new Boolean(jspPreCompilation);
deployAll(autoDeployDir);
|
int | deployJavaEEArchive(java.io.File deployablefile, java.io.File autodeployDir, java.lang.String name)Deploy a Java EE archive.
int status=DEPLOY_FAILURE;
// if it's redeploy, first undeploy, then deploy
if (isModuleDeployed(name)) {
boolean result =
undeployApplication(deployablefile, autodeployDir, name);
if (!result) {
return DEPLOY_FAILURE;
}
}
Properties props = getDeployActionProperties(deployablefile,name);
String[] signature = new String[]{"java.util.Properties"};
Object[] params = new Object[]{props};
//invoke
if (invokeDeploymentService(deployablefile, AutoDeployConstants.DEPLOY_METHOD,params,signature)) {
status = DEPLOY_SUCCESS;
} else {
status = DEPLOY_FAILURE;
}
return status;
|
int | deployJbiArchive(java.io.File file)Deploy a JBI archive.
int returnStatus=DeploymentStatus.FAILURE;
try {
JBIAutoDeployer jad = JBIAutoDeployer.getInstance();
JBIDeployer jd = jad.getDeployer();
String saName = jad.getServiceAssemblyName(file);
jd.deploy(getMBeanServer(), file, saName);
returnStatus = DeploymentStatus.SUCCESS;
return DEPLOY_SUCCESS;
} catch (Exception e) {
while (e instanceof MBeanException) {
e = ((MBeanException)e).getTargetException();
}
String msg = localStrings.getString
("enterprise.deployment.autodeploy.invocation_exception",file);
AutoDeploymentException ae;
ae=new AutoDeploymentException(msg, e);
sLogger.log(Level.INFO, ae.getMessage());
throw ae;
} finally {
markFileAfterDeployment(file, returnStatus);
}
|
public void | disableRenameOnSuccess()If an archive is successfully autodeployed, file will not be
renamed to archive_deployed
renameOnSuccess = false;
|
public void | enableRenameOnSuccess()If an archive is successfully autodeployed will be renamed
to archive_deployed
// FIXME - Mahesh
renameOnSuccess = true;
|
private com.sun.enterprise.config.ConfigContext | getConfigContext()
/*InstanceEnvironment instanceEnvironment =
new InstanceEnvironment(instanceName);
String fileUrl = instanceEnvironment.getConfigFilePath();
ConfigContext configContext =
ConfigFactory.createConfigContext(fileUrl);*/
ServerContext serverContext = AdminService.getAdminService().getContext();
ConfigContext context = serverContext.getConfigContext();
return context;
|
private java.lang.String | getDefaultTarget()
try{
ConfigContext confContext = getConfigContext();
Domain domain = (Domain)confContext.getRootConfigBean();
Servers svrs = domain.getServers();
Server[] svrArr = svrs.getServer();
int size = svrArr.length;
String targetName = null;
/*I am putting this logic specific for TP, as its decided to deploy directly
*to instsnce, and not DAS. It need to be changed to next release
*/
for(int i = 0 ; i< size; i++) {
if(!svrArr[i].getName().equals("")) {
targetName = svrArr[i].getName();
break;
}
}
if(targetName == null) {
sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentFailure",
new Object[] {"Target server not found"});
throw new AutoDeploymentException("Target Server not found");
}
return targetName;
}catch(Exception ex) {
return null;
}
|
private java.lang.String | getDefaultVirtualServer(java.lang.String instanceName)
String virtualServer=null;
try {
ConfigContext context = getConfigContext();
//Domain domain = (Domain)context.getRootConfigBean();
//HttpService service = getHttpService(domain,instanceName);
HttpService service = ServerBeansFactory.getHttpServiceBean(context);
if(service !=null){
HttpListener[] hlArray = service.getHttpListener();
//check not needed since there should always be atleast 1 httplistener
//if you don't find one, use first one.
HttpListener ls = null;
if(hlArray != null && hlArray.length > 0){
ls=hlArray[0];
//default is the first one that is enabled.
for(int i = 0;i<hlArray.length;i++) {
if(hlArray[i].isEnabled()) {
ls = hlArray[i];
break;
}
}
}
if(ls!=null)
virtualServer = ls.getDefaultVirtualServer();
}
} catch(ConfigException e){
String msg = localStrings.getString("enterprise.deployment.autodeploy.unable_to_get_virtualserver");
sLogger.log(Level.WARNING, msg+e.getMessage());
} catch(Exception e){String msg = localStrings.getString("enterprise.deployment.autodeploy.unable_to_get_virtualserver");
sLogger.log(Level.WARNING, msg+e.getMessage());
}
return virtualServer;
|
protected java.util.Properties | getDeployActionProperties(java.io.File deployablefile, java.lang.String ID)
DeploymentProperties dProps = new DeploymentProperties();
dProps.setArchiveName(deployablefile.getAbsolutePath());
dProps.setName(ID);
dProps.setEnable(enabled.booleanValue());
dProps.setVirtualServers(getDefaultVirtualServer(targetInstance));
dProps.setForce(forceDeploy.booleanValue());
dProps.setVerify(verify.booleanValue());
dProps.setPrecompileJSP(jspPreCompilation.booleanValue());
dProps.setResourceAction(DeploymentProperties.RES_DEPLOYMENT);
dProps.setResourceTargetList("server");
return (Properties)dProps;
|
protected java.io.File | getDeployFailedFile(java.io.File f)
String absPath = f.getAbsolutePath();
File ret = new File(absPath + AutoDeployConstants.DEPLOY_FAILED);
return ret;
|
protected java.io.File | getDeployedFile(java.io.File f)
String absPath = f.getAbsolutePath();
File ret = new File(absPath + AutoDeployConstants.DEPLOYED);
return ret;
|
private javax.management.ObjectName | getMBean(java.lang.String instanceName)
ObjectName mbean=null;
try {
mbean = new ObjectName("com.sun.appserv:type=applications,category=config");
} catch(Exception e) {
sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentFailure",
new Object[] {e.getMessage()});
}
return mbean;
|
final javax.management.ObjectName | getMBeanName()get the MBean Name.
bnevins 9/16/03
if(mbeanName == null)
throw new AutoDeploymentException("Internal Error: mbeanName is null");
return mbeanName;
|
final javax.management.MBeanServer | getMBeanServer()get the MBeanServer. Initialize it if neccessary.
Note that the 'final' allows the compiler to inline
the method. So this will be just as fast as accessing the variable
directly.
bnevins 9/16/03
if(mbs == null)
mbs = MBeanServerFactory.getMBeanServer();
return mbs;
|
static java.lang.String | getNameFromFilePath(java.io.File autodeployDir, java.io.File filePath) //creating module name as file name
File parent = filePath.getParentFile();
String moduleName = null;
while (!parent.getAbsolutePath().equals(autodeployDir.getAbsolutePath())) {
if (moduleName==null) {
moduleName = parent.getName();
} else {
moduleName = parent.getName()+"_"+moduleName;
}
parent = parent.getParentFile();
}
if (moduleName==null) {
moduleName = filePath.getName();
} else {
moduleName = moduleName + "_" + filePath.getName();
}
int toIndex = moduleName.lastIndexOf('.");
if (toIndex > 0) {
moduleName = moduleName.substring(0, toIndex);
}
return moduleName;
|
protected java.util.Properties | getUndeployActionProperties(java.lang.String name)
DeploymentProperties dProps = new DeploymentProperties();
dProps.setName(name);
dProps.setResourceAction(DeploymentProperties.RES_UNDEPLOYMENT);
dProps.setResourceTargetList("server");
return (Properties)dProps;
|
protected java.io.File | getUndeployFailedFile(java.io.File f)
String absPath = f.getAbsolutePath();
File ret = new File(absPath + AutoDeployConstants.UNDEPLOY_FAILED);
return ret;
|
protected java.io.File | getUndeployedFile(java.io.File f)
String absPath = f.getAbsolutePath();
File ret = new File(absPath + AutoDeployConstants.UNDEPLOYED);
return ret;
|
void | init()setup the required internal variables
// this sets 'mbs'
getMBeanServer();
if(targetInstance == null) {
// side effect -- this also sets mbeanName...
setTarget(getDefaultTarget());
}
|
boolean | invokeDeploymentService(java.io.File deployablefile, java.lang.String action, java.lang.Object[] params, java.lang.String[] signature)
String file=deployablefile.getAbsolutePath();
boolean status=false;
int returnStatus = DeploymentStatus.FAILURE;
//invoke
try {
Object result=getMBeanServer().invoke(getMBeanName(),action, params,signature);
returnStatus = parseResult(result);
} catch (Exception e) {
while (e instanceof MBeanException) {
e = ((MBeanException)e).getTargetException();
}
returnStatus = DeploymentStatus.FAILURE;
String msg = localStrings.getString
("enterprise.deployment.autodeploy.invocation_exception",file);
AutoDeploymentException ae;
ae=new AutoDeploymentException(msg, e);
sLogger.log(Level.INFO, ae.getMessage());
throw ae;
} finally {
status = markFileAfterDeployment(deployablefile, returnStatus);
}
return status;
|
private boolean | invokeUndeploymentService(java.lang.String appFile, java.lang.String action, java.lang.Object[] params, java.lang.String[] signature)
boolean status=false;
int returnStatus = DeploymentStatus.FAILURE;
//invoke
try {
Object result=getMBeanServer().invoke(getMBeanName(),action, params,signature);
returnStatus = parseResult(result);
} catch (Exception e) {
while (e instanceof MBeanException) {
e = ((MBeanException)e).getTargetException();
}
returnStatus = DeploymentStatus.FAILURE;
String msg = localStrings.getString("enterprise.deployment.autodeploy.invocation_exception",appFile);
AutoDeploymentException ae;
ae=new AutoDeploymentException(msg, e);
sLogger.log(Level.INFO, ae.getMessage());
throw ae;
} finally {
if(returnStatus == DeploymentStatus.SUCCESS) {
status = true;
String msg = localStrings.getString("enterprise.deployment.autodeploy.successfully_autoundeployed",appFile);
sLogger.log(Level.INFO, msg);
} else if (returnStatus == DeploymentStatus.WARNING) {
status = true;
String msg = localStrings.getString("enterprise.deployment.autodeploy.warning_autoundeployed",appFile);
sLogger.log(Level.INFO, msg);
} else if (returnStatus == DeploymentStatus.FAILURE) {
status = false;
String msg = localStrings.getString("enterprise.deployment.autodeploy.autoundeploy_failed",appFile);
sLogger.log(Level.INFO, msg);
}
}
return status;
|
public boolean | isCancelled()get cancel flag value
return cancelDeployment;
|
private boolean | isModuleDeployed(java.lang.String moduleID)
if (moduleID == null) {
return false;
}
try {
String[] signature = new String[] {"java.lang.String"};
Object[] params = new Object[] {moduleID};
Object result = getMBeanServer().invoke(getMBeanName(),
"getModuleType", params, signature);
if (result != null) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
|
protected void | markDeployFailed(java.io.File f)
try {
deleteAllMarks(f);
getDeployFailedFile(f).createNewFile();
} catch (Exception e) {
//ignore
}
|
protected void | markDeployed(java.io.File f)
try {
deleteAllMarks(f);
getDeployedFile(f).createNewFile();
} catch (Exception e) {
//ignore
}
|
private boolean | markFileAfterDeployment(java.io.File file, int returnStatus)
String msg = null;
boolean status = false;
if(returnStatus == DeploymentStatus.SUCCESS) {
if(renameOnSuccess) {
markDeployed(file);
}
status = true;
msg = localStrings.getString("enterprise.deployment.autodeploy.successfully_autodeployed",file);
sLogger.log(Level.INFO, msg);
} else if (returnStatus == DeploymentStatus.WARNING) {
if(renameOnSuccess) {
markDeployed(file);
}
status = true;
msg = localStrings.getString("enterprise.deployment.autodeploy.warning_autodeployed",file);
sLogger.log(Level.INFO, msg);
} else if (returnStatus == DeploymentStatus.FAILURE) {
markDeployFailed(file);
status = false;
msg = localStrings.getString("enterprise.deployment.autodeploy.autodeploy_failed",file);
sLogger.log(Level.INFO, msg);
}
return status;
|
protected void | markUndeployFailed(java.io.File f)
try {
deleteAllMarks(f);
getUndeployFailedFile(f).createNewFile();
} catch (Exception e) {
//ignore
}
|
protected void | markUndeployed(java.io.File f)
try {
deleteAllMarks(f);
getUndeployedFile(f).createNewFile();
} catch (Exception e) {
//ignore
}
|
protected int | parseResult(java.lang.Object result)
if(result!=null && result instanceof DeploymentStatus) {
DeploymentStatus status = (DeploymentStatus) result;
if (status.getStatus()>DeploymentStatus.WARNING) {
return DeploymentStatus.SUCCESS;
} else {
// ok we got either a warning or an error.
// parse the deployment status and retrieve failure/warning msg
ByteArrayOutputStream bos =
new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(bos);
DeploymentStatus.parseDeploymentStatus(status, pw);
byte[] statusBytes = bos.toByteArray();
String statusString = new String(statusBytes);
if (status.getStatus()==DeploymentStatus.WARNING) {
// warning, let's log and continue
String msg = localStrings.getString(
"enterprise.deployment.warning_occured", statusString);
sLogger.log(Level.WARNING, msg);
return DeploymentStatus.WARNING;
} else if (status.getStatus()==DeploymentStatus.FAILURE) {
sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentFailure",
new Object[] {statusString});
return DeploymentStatus.FAILURE;
}
}
}
return DeploymentStatus.FAILURE;
|
public void | setCancel(boolean value)set cancel flag, which will ensure that only if there is any current deployment is in process,
it will be completed but the deployer will not do any more deployment.
cancelDeployment=value;
|
public void | setDirectoryScanner(DirectoryScanner ds)set DirectoryScanner which will be used for filtering out deployeble component
directoryScanner=ds;
|
public void | setJspPreCompilation(boolean jspPreCompilation)Set whether this AutoDeployer should precompile JSPs or not.
this.jspPreCompilation = new Boolean(jspPreCompilation);
|
public void | setTarget(java.lang.String target)set target server where the autual deployment will be done
this.targetInstance = target;
mbeanName = getMBean(targetInstance);
|
public void | setVerify(boolean verify)Set whether this AutoDeployer should verify or not.
this.verify = new Boolean(verify);
|
public void | undeployAll(java.io.File autoDeployDir)do undeployment for all deleted applications in autoDeployDir dir.
//create with default scanner
if(directoryScanner==null) {
directoryScanner=new AutoDeployDirectoryScanner();
}
if(mbs == null) {
mbs = getMBeanServer();
}
//set target to default
if(this.targetInstance == null) {
setTarget(getDefaultTarget());
}
File[] apps= null;
//get me all apps
apps= directoryScanner.getAllFilesForUndeployment(autoDeployDir);
//deploying all applications
if(apps !=null) {
for (int i=0; i< apps.length && !cancelDeployment;i++) {
try {
boolean stat = this.undeployApplication(apps[i], autoDeployDir,
getNameFromFilePath(autoDeployDir, apps[i]));
/*
* Before managing the marker file for the app, see if
* the autodeployer is responsible for deleting this app
* file and, if so, delete it.
*/
if (undeployedByRequestFile(apps[i])) {
cleanupAppAndRequest(apps[i]);
}
if (stat)
markUndeployed(apps[i]);
else
markUndeployFailed(apps[i]);
} catch (AutoDeploymentException ae) {
//ignore and move to next file
markUndeployFailed(apps[i]);
} finally {
// Mark the application as undeployed both in the case of success & failure.
directoryScanner.undeployedEntity(autoDeployDir, apps[i]);
}
}
}
/////////end for apps
|
private boolean | undeployApplication(java.io.File applicationFile, java.io.File autodeployDir, java.lang.String name)
JBIAutoDeployer jad = JBIAutoDeployer.getInstance();
String saName = jad.getServiceAssemblyName(applicationFile, autodeployDir);
if (saName == null) {
return undeployJavaEEArchive(applicationFile, name);
} else {
return undeployJbiArchive(saName);
}
|
private boolean | undeployJavaEEArchive(java.io.File applicationFile, java.lang.String name)Undeploy a Java EE archive.
boolean status = false;
Properties props = getUndeployActionProperties(name);
String[] signature = new String[]{"java.util.Properties"};
Object[] params = new Object[]{props};
sLogger.log(Level.INFO, "Autoundeploying application :" + name);
status = invokeUndeploymentService(applicationFile.getAbsolutePath(), AutoDeployConstants.UNDEPLOY_METHOD,params,signature);;
return status;
|
private boolean | undeployJbiArchive(java.lang.String saName)Undeploy a JBI archive.
try {
sLogger.log(Level.INFO, "Autoundeploying application :" + saName);
JBIAutoDeployer jad = JBIAutoDeployer.getInstance();
JBIDeployer jd = jad.getDeployer();
jd.undeploy(getMBeanServer(), saName);
String msg = localStrings.getString
("enterprise.deployment.autodeploy.successfully_autoundeployed",
saName);
sLogger.log(Level.INFO, msg);
return true;
} catch (Exception e) {
while (e instanceof MBeanException) {
e = ((MBeanException)e).getTargetException();
}
String msg = localStrings.getString(
"enterprise.deployment.autodeploy.autoundeploy_failed",saName);
sLogger.log(Level.INFO, msg);
msg = localStrings.getString(
"enterprise.deployment.autodeploy.invocation_exception",saName);
AutoDeploymentException ae;
ae=new AutoDeploymentException(msg, e);
sLogger.log(Level.INFO, ae.getMessage());
throw ae;
}
|
private boolean | undeployedByRequestFile(java.io.File f)
return f instanceof AutoDeployedFilesManager.UndeployRequestedFile;
|