use of org.apache.openejb.NoSuchApplicationException in project tomee by apache.
the class Assembler method destroyApplication.
public void destroyApplication(final String filePath) throws UndeployException, NoSuchApplicationException {
final ReentrantLock l = lock;
l.lock();
try {
final AppInfo appInfo = deployedApplications.remove(filePath);
if (appInfo == null) {
throw new NoSuchApplicationException(filePath);
}
destroyApplication(appInfo);
} finally {
l.unlock();
}
}
use of org.apache.openejb.NoSuchApplicationException in project tomee by apache.
the class Undeploy method main.
public static void main(final String[] args) throws SystemExitException {
final CommandLineParser parser = new PosixParser();
// create the Options
final Options options = new Options();
options.addOption(Undeploy.option("v", "version", "cmd.deploy.opt.version"));
// TODO this message doesn't exist
options.addOption(Undeploy.option("h", "help", "cmd.undeploy.opt.help"));
options.addOption(Undeploy.option("s", "server-url", "url", "cmd.deploy.opt.server"));
CommandLine line = null;
try {
// parse the command line arguments
line = parser.parse(options, args);
} catch (final ParseException exp) {
Undeploy.help(options);
throw new SystemExitException(-1);
}
if (line.hasOption("help")) {
Undeploy.help(options);
return;
} else if (line.hasOption("version")) {
OpenEjbVersion.get().print(System.out);
return;
}
if (line.getArgList().size() == 0) {
System.out.println("Must specify an module id.");
help(options);
return;
}
final Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
if ("auto".equalsIgnoreCase(serverUrl.trim())) {
try {
final File sXml = new File(JavaSecurityManagers.getSystemProperty("openejb.base", "conf/server.xml"));
if (sXml.exists()) {
final QuickServerXmlParser result = QuickServerXmlParser.parse(sXml);
serverUrl = "http://" + result.host() + ":" + result.http() + "/tomee/ejb";
}
} catch (final Throwable e) {
// no-op
}
}
p.put(Context.PROVIDER_URL, serverUrl);
Deployer deployer = null;
try {
final InitialContext ctx = new InitialContext(p);
deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
} catch (final ServiceUnavailableException e) {
System.out.println(e.getCause().getMessage());
System.out.println(Undeploy.messages.format("cmd.deploy.serverOffline"));
throw new SystemExitException(-1);
} catch (final NamingException e) {
System.out.println("DeployerEjb does not exist in server '" + serverUrl + "', check the server logs to ensure it exists and has not been removed.");
throw new SystemExitException(-2);
}
int exitCode = 0;
for (final Object obj : line.getArgList()) {
final String moduleId = (String) obj;
try {
undeploy(moduleId, deployer);
} catch (final DeploymentTerminatedException e) {
System.out.println(e.getMessage());
exitCode++;
} catch (final UndeployException e) {
System.out.println(messages.format("cmd.undeploy.failed", moduleId));
e.printStackTrace(System.out);
exitCode++;
} catch (final NoSuchApplicationException e) {
// TODO make this message
System.out.println(messages.format("cmd.undeploy.noSuchModule", moduleId));
exitCode++;
}
}
if (exitCode != 0) {
throw new SystemExitException(exitCode);
}
}
use of org.apache.openejb.NoSuchApplicationException in project tomee by apache.
the class WebappDeployer method undeploy.
@Override
public void undeploy(final String moduleId) throws UndeployException, NoSuchApplicationException {
try {
final AppInfo appInfo = findAppInfo(moduleId);
if (appInfo != null) {
webappBuilder.undeployWebApps(appInfo);
}
assembler.destroyApplication(moduleId);
final File moduleFile = new File(moduleId);
if (moduleFile.getName().contains(".")) {
// delete matching directory
final File dir = new File(moduleFile.getAbsolutePath().substring(0, moduleFile.getAbsolutePath().lastIndexOf('.')));
if (dir.exists() && dir.isDirectory()) {
delete(dir);
}
} else {
delete(new File(moduleFile + ".war"));
delete(new File(moduleFile + ".ear"));
delete(new File(moduleFile + ".rar"));
}
delete(moduleFile);
} catch (Exception e) {
throw new UndeployException(e);
}
}
use of org.apache.openejb.NoSuchApplicationException in project tomee by apache.
the class Assembler method destroy.
@Override
public void destroy() {
final ReentrantLock l = lock;
l.lock();
try {
final SystemInstance systemInstance = SystemInstance.get();
systemInstance.fireEvent(new ContainerSystemPreDestroy());
try {
EjbTimerServiceImpl.shutdown();
} catch (final Exception e) {
logger.warning("Unable to shutdown scheduler", e);
} catch (final NoClassDefFoundError ncdfe) {
// no-op
}
logger.debug("Undeploying Applications");
final Assembler assembler = this;
final List<AppInfo> deployedApps = new ArrayList<>(assembler.getDeployedApplications());
// if an app relies on the previous one it surely relies on it too at undeploy time
Collections.reverse(deployedApps);
for (final AppInfo appInfo : deployedApps) {
try {
assembler.destroyApplication(appInfo.path);
} catch (final UndeployException e) {
logger.error("Undeployment failed: " + appInfo.path, e);
} catch (final NoSuchApplicationException e) {
// Ignore
}
}
final Iterator<ObjectName> it = containerObjectNames.iterator();
final MBeanServer server = LocalMBeanServer.get();
while (it.hasNext()) {
try {
server.unregisterMBean(it.next());
} catch (final Exception ignored) {
// no-op
}
it.remove();
}
try {
remoteResourceMonitor.unregister();
} catch (final Exception ignored) {
// no-op
}
NamingEnumeration<Binding> namingEnumeration = null;
try {
namingEnumeration = containerSystem.getJNDIContext().listBindings("openejb/Resource");
} catch (final NamingException ignored) {
// no resource adapters were created
}
destroyResourceTree("", namingEnumeration);
try {
containerSystem.getJNDIContext().unbind("java:global");
} catch (final NamingException ignored) {
// no-op
}
systemInstance.removeComponent(OpenEjbConfiguration.class);
systemInstance.removeComponent(JtaEntityManagerRegistry.class);
systemInstance.removeComponent(TransactionSynchronizationRegistry.class);
systemInstance.removeComponent(EjbResolver.class);
systemInstance.removeComponent(ThreadSingletonService.class);
systemInstance.fireEvent(new AssemblerDestroyed());
systemInstance.removeObservers();
if (DestroyableResource.class.isInstance(this.securityService)) {
DestroyableResource.class.cast(this.securityService).destroyResource();
}
if (DestroyableResource.class.isInstance(this.transactionManager)) {
DestroyableResource.class.cast(this.transactionManager).destroyResource();
}
for (final Container c : this.containerSystem.containers()) {
if (DestroyableResource.class.isInstance(c)) {
// TODO: should we use auto closeable there?
DestroyableResource.class.cast(c).destroyResource();
}
}
SystemInstance.reset();
} finally {
l.unlock();
}
}
use of org.apache.openejb.NoSuchApplicationException in project tomee by apache.
the class VmDeploymentManager method undeploy.
@Override
public ProgressObject undeploy(final TargetModuleID[] moduleIdList) {
if (!connected) {
throw new IllegalStateException("Deployment manager is disconnected");
}
UndeployException undeployException = null;
final Set<TargetModuleID> results = new TreeSet<>();
for (final TargetModuleID targetModuleId : moduleIdList) {
try {
getDeployer().undeploy(targetModuleId.getModuleID());
results.add(targetModuleId);
} catch (final UndeployException e) {
if (undeployException == null) {
undeployException = e;
}
} catch (final NoSuchApplicationException e) {
// app was not deployed... this should be ignored by jsr88
}
}
if (undeployException == null) {
return new ProgressObjectImpl(CommandType.UNDEPLOY, results);
} else {
return new ProgressObjectImpl(CommandType.UNDEPLOY, undeployException);
}
}
Aggregations