Check for old versions of applications using parallel deployment that are now unused (have no active sessions) and undeploy any that are found.
()
| 1690 | * and undeploy any that are found. |
| 1691 | */ |
| 1692 | public void checkUndeploy() { |
| 1693 | synchronized (host) { |
| 1694 | if (deployed.size() < 2) { |
| 1695 | return; |
| 1696 | } |
| 1697 | |
| 1698 | // Need ordered set of names |
| 1699 | SortedSet<String> sortedAppNames = new TreeSet<>(deployed.keySet()); |
| 1700 | |
| 1701 | Iterator<String> iter = sortedAppNames.iterator(); |
| 1702 | |
| 1703 | ContextName previous = new ContextName(iter.next(), false); |
| 1704 | do { |
| 1705 | ContextName current = new ContextName(iter.next(), false); |
| 1706 | |
| 1707 | if (current.getPath().equals(previous.getPath())) { |
| 1708 | // Current and previous are same path - current will always |
| 1709 | // be a later version |
| 1710 | Context previousContext = (Context) host.findChild(previous.getName()); |
| 1711 | Context currentContext = (Context) host.findChild(current.getName()); |
| 1712 | if (previousContext != null && currentContext != null && currentContext.getState().isAvailable() && |
| 1713 | tryAddServiced(previous.getName())) { |
| 1714 | try { |
| 1715 | Manager manager = previousContext.getManager(); |
| 1716 | if (manager != null) { |
| 1717 | int sessionCount; |
| 1718 | if (manager instanceof DistributedManager) { |
| 1719 | sessionCount = ((DistributedManager) manager).getActiveSessionsFull(); |
| 1720 | } else { |
| 1721 | sessionCount = manager.getActiveSessions(); |
| 1722 | } |
| 1723 | if (sessionCount == 0) { |
| 1724 | if (log.isInfoEnabled()) { |
| 1725 | log.info(sm.getString("hostConfig.undeployVersion", previous.getName())); |
| 1726 | } |
| 1727 | DeployedApplication app = deployed.get(previous.getName()); |
| 1728 | String[] resources = app.redeployResources.keySet().toArray(new String[0]); |
| 1729 | // Version is unused - undeploy it completely |
| 1730 | // The -1 is a 'trick' to ensure all redeploy |
| 1731 | // resources are removed |
| 1732 | undeploy(app); |
| 1733 | deleteRedeployResources(app, resources, -1, true); |
| 1734 | } |
| 1735 | } |
| 1736 | } finally { |
| 1737 | removeServiced(previous.getName()); |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | previous = current; |
| 1742 | } while (iter.hasNext()); |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * Add a new Context to be managed by us. Entry point for the admin webapp, and other JMX Context controllers. |
no test coverage detected