AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { @Override public void notifyContainerCompleted(ContainerId containerId) { if (containerId != null) { String containerIdStr = containerId.toString(); if (getComponentInstanceData().containsKey(containerIdStr)) { getComponentInstanceData().remove(containerIdStr); log.info("Removing container specific data for {}", containerIdStr); publishComponentInstanceData(); } if (this.allocatedPorts.containsKey(containerIdStr)) { Map<String, String> portsByContainerId = getAllocatedPorts(containerIdStr); this.allocatedPorts.remove(containerIdStr); for(String portName : portsByContainerId.keySet()) { getAllocatedPorts().remove(portName); } } String componentName = null; synchronized (this.componentStatuses) { for (String label : getComponentStatuses().keySet()) { if (label.startsWith(containerIdStr)) { componentName = getRoleName(label); log.info("Removing component status for label {}", label); getComponentStatuses().remove(label); } } } tags.releaseTag(componentName, containerIdStr); synchronized (this.containerExportsMap) { Set<String> containerExportSets = containerExportsMap.get(containerIdStr); if (containerExportSets != null) { for (String containerExportStr : containerExportSets) { String[] parts = containerExportStr.split(":"); Map<String, List<ExportEntry>> exportGroup = getCurrentExports(parts[0]); List<ExportEntry> exports = exportGroup.get(parts[1]); List<ExportEntry> exportToRemove = new ArrayList<ExportEntry>(); for (ExportEntry export : exports) { if (containerIdStr.equals(export.getContainerId())) { exportToRemove.add(export); } } exports.removeAll(exportToRemove); } log.info("Removing container exports for {}", containerIdStr); containerExportsMap.remove(containerIdStr); } } } } AgentProviderService(); @Override String getHumanName(); @Override List<ProviderRole> getRoles(); @Override Configuration loadProviderConfigurationInformation(File confDir); @Override void validateInstanceDefinition(AggregateConf instanceDefinition); @Override void initializeApplicationConfiguration(
      AggregateConf instanceDefinition, SliderFileSystem fileSystem,
      String roleGroup); @Override void buildContainerLaunchContext(ContainerLauncher launcher,
                                          AggregateConf instanceDefinition,
                                          Container container,
                                          ProviderRole providerRole,
                                          SliderFileSystem fileSystem,
                                          Path generatedConfPath,
                                          MapOperations resourceComponent,
                                          MapOperations appComponent,
                                          Path containerTmpDirPath); @Override void rebuildContainerDetails(List<Container> liveContainers,
                                      String applicationId, Map<Integer, ProviderRole> providerRoleMap); @Override boolean isSupportedRole(String role); @Override RegistrationResponse handleRegistration(Register registration); @Override HeartBeatResponse handleHeartBeat(HeartBeat heartBeat); @Override Map<String, MonitorDetail> buildMonitorDetails(ClusterDescription clusterDesc); @Override void applyInitialRegistryDefinitions(URL amWebURI,
      URL agentOpsURI,
      URL agentStatusURI,
      ServiceRecord serviceRecord); @Override void notifyContainerCompleted(ContainerId containerId); void setInUpgradeMode(boolean inUpgradeMode); void addUpgradeContainers(Set<String> upgradeContainers); void setAppStopInitiated(boolean appStopInitiated); Map<String, String> buildProviderStatus();  }
@Test public void testNotifyContainerCompleted() throws IOException { AgentProviderService aps = createAgentProviderService(new Configuration()); AgentProviderService mockAps = Mockito.spy(aps); doNothing().when(mockAps).publishApplicationInstanceData(anyString(), anyString(), anyCollection()); ContainerId cid = new MockContainerId(1); String id = cid.toString(); ContainerId cid2 = new MockContainerId(2); mockAps.getAllocatedPorts().put("a", "100"); mockAps.getAllocatedPorts(id).put("a", "100"); mockAps.getAllocatedPorts(id).put("b", "101"); mockAps.getAllocatedPorts("cid2").put("c", "102"); mockAps.getComponentInstanceData().put("cid2", new HashMap<String, String>()); mockAps.getComponentInstanceData().put(id, new HashMap<String, String>()); mockAps.getComponentStatuses().put("cid2_HM", new ComponentInstanceState("HM", cid2, "aid")); mockAps.getComponentStatuses().put(id + "_HM", new ComponentInstanceState("HM", cid, "aid")); Assert.assertNotNull(mockAps.getComponentInstanceData().get(id)); Assert.assertNotNull(mockAps.getComponentInstanceData().get("cid2")); Assert.assertNotNull(mockAps.getComponentStatuses().get(id + "_HM")); Assert.assertNotNull(mockAps.getComponentStatuses().get("cid2_HM")); Assert.assertEquals(mockAps.getAllocatedPorts().size(), 1); Assert.assertEquals(mockAps.getAllocatedPorts(id).size(), 2); Assert.assertEquals(mockAps.getAllocatedPorts("cid2").size(), 1); mockAps.notifyContainerCompleted(new MockContainerId(1)); Assert.assertEquals(mockAps.getAllocatedPorts().size(), 0); Assert.assertEquals(mockAps.getAllocatedPorts(id).size(), 0); Assert.assertEquals(mockAps.getAllocatedPorts("cid2").size(), 1); Assert.assertNull(mockAps.getComponentInstanceData().get(id)); Assert.assertNotNull(mockAps.getComponentInstanceData().get("cid2")); Assert.assertNull(mockAps.getComponentStatuses().get(id + "_HM")); Assert.assertNotNull(mockAps.getComponentStatuses().get("cid2_HM")); }