Template template=templates.get(instance.getTemplateName());
instance.setTemplate(template);
if (template!=null)
{
String key=instance.getInstanceKey();
App app = _deployed.get(key);
if (app==null)
deploy.add(instance);
else
deployed.add(key);
}
}
// Look for deployed apps that need to be undeployed
List<String> undeploy = new ArrayList<String>();
for (String key : _deployed.keySet())
{
if (!deployed.contains(key))
undeploy.add(key);
}
// Do the undeploys
for (String key : undeploy)
{
App app = _deployed.remove(key);
if (app!=null)
{
__log.info("Undeploy {}",key);
_deploymentManager.removeApp(app);
}
}
// ready the deploys
for (Instance instance : deploy)
{
String key=instance.getInstanceKey();
OverlayedApp app = new OverlayedApp(_deploymentManager,this,key,instance);
_deployed.put(key,app);
}
// Remove unused Shared stuff
Set<String> sharedKeys = new HashSet<String>(_shared.keySet());
for (OverlayedApp app : _deployed.values())
{
Instance instance = app.getInstance();
sharedKeys.remove(instance.getSharedKey());
}
for (String sharedKey: sharedKeys)
{
__log.debug("Remove "+sharedKey);