if (!isOffline(connection)) {
if (!(commandArgs instanceof InstallBundleCommandArgs)) {
throw new DeploymentSyntaxException("CommandArgs has the type [" + commandArgs.getClass() + "]; expected [" + InstallBundleCommandArgs.class + "]");
}
InstallBundleCommandArgs recordBundleCommandArgs = (InstallBundleCommandArgs) commandArgs;
File bundleFile = new File(recordBundleCommandArgs.getArgs()[0]);
if(!bundleFile.exists() || !bundleFile.isFile() || !bundleFile.canRead()) {
throw new DeploymentException("File does not exist or not a normal file or not readable. "+bundleFile);
}
DeploymentManager dmgr = connection.getDeploymentManager();
if(dmgr instanceof GeronimoDeploymentManager) {
GeronimoDeploymentManager mgr = (GeronimoDeploymentManager) dmgr;
boolean start = recordBundleCommandArgs.isStart();
int startLevel = recordBundleCommandArgs.getStartLevel();
String groupId = recordBundleCommandArgs.getGroupId();
try {
long bundleId = mgr.recordInstall(bundleFile, groupId, startLevel);
if ( bundleId > 0 ){
consoleReader.printString(DeployUtils.reformat("Installed and recorded bundle: " + bundleId, 4, 72));
if (start){
if(mgr instanceof RemoteDeploymentManager) {
MBeanServerConnection mbsc = ((RemoteDeploymentManager) mgr).getJMXConnector().getMBeanServerConnection();
try {
FrameworkMBean frameworkMBean = getFrameworkMBean(mbsc);
frameworkMBean.startBundle(bundleId);
consoleReader.printString(DeployUtils.reformat("Started bundle: " + bundleId, 4, 72));
} catch (Exception e) {
throw new DeploymentException("Unable to start bundle.", e);
}
}else {
consoleReader.printString(DeployUtils.reformat("Currently the start option only support JMX connection.", 4, 72));
}
}
}else {
consoleReader.printString(DeployUtils.reformat("Bundle installation failed, so did not record bundle.", 4, 72));
}
} catch (Exception e) {
throw new DeploymentException("Unable to record bundle "+recordBundleCommandArgs.getArgs()[0], e);
}
} else {
throw new DeploymentException("Unable to record bundle using " + dmgr.getClass().getName() + " deployment manager");
}