InstancesMngrImpl implements IInstancesMngr { @Override public void restoreInstanceStates( ManagedApplication ma, TargetHandler targetHandler ) { for( Instance scopedInstance : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { try { String machineId = scopedInstance.data.get( Instance.MACHINE_ID ); if( machineId == null ) { DmUtils.markScopedInstanceAsNotDeployed( scopedInstance, ma, this.notificationMngr, this ); releaseLockedTargets( ma.getApplication(), scopedInstance ); continue; } String scopedInstancePath = InstanceHelpers.computeInstancePath( scopedInstance ); TargetProperties targetProperties = this.targetsMngr.findTargetProperties( ma.getApplication(), scopedInstancePath ); targetProperties.asMap().putAll( scopedInstance.data ); TargetHandler readTargetHandler = null; try { readTargetHandler = this.targetHandlerResolver.findTargetHandler( targetProperties.asMap()); } catch( Exception e ) { } if( readTargetHandler == null || ! Objects.equals( targetHandler.getTargetId(), readTargetHandler.getTargetId())) continue; TargetHandlerParameters parameters = parameters( ma, scopedInstance, targetProperties ); if( ! targetHandler.isMachineRunning( parameters, machineId )) { DmUtils.markScopedInstanceAsNotDeployed( scopedInstance, ma, this.notificationMngr, this ); releaseLockedTargets( ma.getApplication(), scopedInstance ); } else { this.messagingMngr.sendMessageDirectly( ma, scopedInstance, new MsgCmdSendInstances()); } } catch( Exception e ) { this.logger.severe( "Could not request states for agent " + scopedInstance.getName() + " (I/O exception)." ); Utils.logException( this.logger, e ); } } } InstancesMngrImpl(
			IMessagingMngr messagingMngr,
			INotificationMngr notificationMngr,
			ITargetsMngr targetsMngr,
			IRandomMngr randomMngr,
			ITargetConfigurator targetConfigurator ); void setTargetHandlerResolver( ITargetHandlerResolver targetHandlerResolver ); void setRuleBasedHandler( IAutonomicMngr autonomicMngr ); void setDmDomain( String dmDomain ); @Override void addInstance( ManagedApplication ma, Instance parentInstance, Instance instance ); @Override void instanceWasUpdated( Instance instance, ManagedApplication ma ); @Override void removeInstance( ManagedApplication ma, Instance instance ); @Override void removeInstance( ManagedApplication ma, Instance instance, boolean immediate ); @Override void restoreInstanceStates( ManagedApplication ma, TargetHandler targetHandler ); @Override void resynchronizeAgents( ManagedApplication ma ); @Override void changeInstanceState( ManagedApplication ma, Instance instance, InstanceStatus newStatus ); @Override void deployAndStartAll( ManagedApplication ma, Instance instance ); @Override void stopAll( ManagedApplication ma, Instance instance ); @Override void undeployAll( ManagedApplication ma, Instance instance );  }
@Test public void testRestoreInstances_noMachineId() throws Exception { IInstancesMngr mngr = new InstancesMngrImpl( null, null, null, null, null ); TestApplication app = new TestApplication(); app.setDirectory( this.folder.newFolder()); ManagedApplication ma = new ManagedApplication( app ); TargetHandler targetHandler = Mockito.mock( TargetHandler.class ); mngr.restoreInstanceStates( ma, targetHandler ); Mockito.verifyZeroInteractions( targetHandler ); }