@Test public void testCheckStates() { INotificationMngr notificationMngr = Mockito.mock( INotificationMngr.class ); Assert.assertNull( this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); this.ma.checkStates( notificationMngr ); Assert.assertEquals( "1", this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); Mockito.verifyZeroInteractions( notificationMngr ); this.ma.acknowledgeHeartBeat( this.app.getMySqlVm()); Assert.assertNull( this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); for( int i=0; i<=ManagedApplication.THRESHOLD; i++ ) { this.ma.checkStates( notificationMngr ); Assert.assertEquals( String.valueOf( i ), String.valueOf( i+1 ), this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); } Assert.assertEquals( InstanceStatus.PROBLEM, this.app.getMySqlVm().getStatus()); Mockito.verify( notificationMngr ).instance( this.app.getMySqlVm(), this.app, EventType.CHANGED ); Mockito.reset( notificationMngr ); this.app.getMySqlVm().setStatus( InstanceStatus.UNDEPLOYING ); this.ma.checkStates( notificationMngr ); Assert.assertNull( this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); Mockito.verifyZeroInteractions( notificationMngr ); this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYING ); this.ma.checkStates( notificationMngr ); Assert.assertNull( this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); Mockito.verifyZeroInteractions( notificationMngr ); this.app.getMySqlVm().setStatus( InstanceStatus.NOT_DEPLOYED ); this.ma.checkStates( notificationMngr ); Assert.assertNull( this.app.getMySqlVm().data.get( ManagedApplication.MISSED_HEARTBEATS )); Mockito.verifyZeroInteractions( notificationMngr ); }
public void checkStates( INotificationMngr notificationMngr ) { Collection<Instance> scopedInstances = InstanceHelpers.findAllScopedInstances( this.application ); for( Instance scopedInstance : scopedInstances ) { if( scopedInstance.getStatus() == InstanceStatus.NOT_DEPLOYED || scopedInstance.getStatus() == InstanceStatus.DEPLOYING || scopedInstance.getStatus() == InstanceStatus.UNDEPLOYING ) { scopedInstance.data.remove( MISSED_HEARTBEATS ); continue; } String countAs = scopedInstance.data.get( MISSED_HEARTBEATS ); int count = countAs == null ? 0 : Integer.parseInt( countAs ); if( ++ count > THRESHOLD ) { scopedInstance.setStatus( InstanceStatus.PROBLEM ); notificationMngr.instance( scopedInstance, this.application, EventType.CHANGED ); this.logger.severe( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " has not sent heart beats for quite a long time. Status changed to PROBLEM." ); } scopedInstance.data.put( MISSED_HEARTBEATS, String.valueOf( count )); } }
ManagedApplication { public void checkStates( INotificationMngr notificationMngr ) { Collection<Instance> scopedInstances = InstanceHelpers.findAllScopedInstances( this.application ); for( Instance scopedInstance : scopedInstances ) { if( scopedInstance.getStatus() == InstanceStatus.NOT_DEPLOYED || scopedInstance.getStatus() == InstanceStatus.DEPLOYING || scopedInstance.getStatus() == InstanceStatus.UNDEPLOYING ) { scopedInstance.data.remove( MISSED_HEARTBEATS ); continue; } String countAs = scopedInstance.data.get( MISSED_HEARTBEATS ); int count = countAs == null ? 0 : Integer.parseInt( countAs ); if( ++ count > THRESHOLD ) { scopedInstance.setStatus( InstanceStatus.PROBLEM ); notificationMngr.instance( scopedInstance, this.application, EventType.CHANGED ); this.logger.severe( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " has not sent heart beats for quite a long time. Status changed to PROBLEM." ); } scopedInstance.data.put( MISSED_HEARTBEATS, String.valueOf( count )); } } }
ManagedApplication { public void checkStates( INotificationMngr notificationMngr ) { Collection<Instance> scopedInstances = InstanceHelpers.findAllScopedInstances( this.application ); for( Instance scopedInstance : scopedInstances ) { if( scopedInstance.getStatus() == InstanceStatus.NOT_DEPLOYED || scopedInstance.getStatus() == InstanceStatus.DEPLOYING || scopedInstance.getStatus() == InstanceStatus.UNDEPLOYING ) { scopedInstance.data.remove( MISSED_HEARTBEATS ); continue; } String countAs = scopedInstance.data.get( MISSED_HEARTBEATS ); int count = countAs == null ? 0 : Integer.parseInt( countAs ); if( ++ count > THRESHOLD ) { scopedInstance.setStatus( InstanceStatus.PROBLEM ); notificationMngr.instance( scopedInstance, this.application, EventType.CHANGED ); this.logger.severe( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " has not sent heart beats for quite a long time. Status changed to PROBLEM." ); } scopedInstance.data.put( MISSED_HEARTBEATS, String.valueOf( count )); } } ManagedApplication( Application application ); }
ManagedApplication { public void checkStates( INotificationMngr notificationMngr ) { Collection<Instance> scopedInstances = InstanceHelpers.findAllScopedInstances( this.application ); for( Instance scopedInstance : scopedInstances ) { if( scopedInstance.getStatus() == InstanceStatus.NOT_DEPLOYED || scopedInstance.getStatus() == InstanceStatus.DEPLOYING || scopedInstance.getStatus() == InstanceStatus.UNDEPLOYING ) { scopedInstance.data.remove( MISSED_HEARTBEATS ); continue; } String countAs = scopedInstance.data.get( MISSED_HEARTBEATS ); int count = countAs == null ? 0 : Integer.parseInt( countAs ); if( ++ count > THRESHOLD ) { scopedInstance.setStatus( InstanceStatus.PROBLEM ); notificationMngr.instance( scopedInstance, this.application, EventType.CHANGED ); this.logger.severe( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " has not sent heart beats for quite a long time. Status changed to PROBLEM." ); } scopedInstance.data.put( MISSED_HEARTBEATS, String.valueOf( count )); } } ManagedApplication( Application application ); Map<Instance,List<Message>> getScopedInstanceToAwaitingMessages(); Application getApplication(); File getDirectory(); String getName(); Graphs getGraphs(); File getTemplateDirectory(); @Override String toString(); void storeAwaitingMessage( Instance instance, Message msg ); List<Message> removeAwaitingMessages( Instance instance ); void acknowledgeHeartBeat( Instance scopedInstance ); void checkStates( INotificationMngr notificationMngr ); }
ManagedApplication { public void checkStates( INotificationMngr notificationMngr ) { Collection<Instance> scopedInstances = InstanceHelpers.findAllScopedInstances( this.application ); for( Instance scopedInstance : scopedInstances ) { if( scopedInstance.getStatus() == InstanceStatus.NOT_DEPLOYED || scopedInstance.getStatus() == InstanceStatus.DEPLOYING || scopedInstance.getStatus() == InstanceStatus.UNDEPLOYING ) { scopedInstance.data.remove( MISSED_HEARTBEATS ); continue; } String countAs = scopedInstance.data.get( MISSED_HEARTBEATS ); int count = countAs == null ? 0 : Integer.parseInt( countAs ); if( ++ count > THRESHOLD ) { scopedInstance.setStatus( InstanceStatus.PROBLEM ); notificationMngr.instance( scopedInstance, this.application, EventType.CHANGED ); this.logger.severe( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " has not sent heart beats for quite a long time. Status changed to PROBLEM." ); } scopedInstance.data.put( MISSED_HEARTBEATS, String.valueOf( count )); } } ManagedApplication( Application application ); Map<Instance,List<Message>> getScopedInstanceToAwaitingMessages(); Application getApplication(); File getDirectory(); String getName(); Graphs getGraphs(); File getTemplateDirectory(); @Override String toString(); void storeAwaitingMessage( Instance instance, Message msg ); List<Message> removeAwaitingMessages( Instance instance ); void acknowledgeHeartBeat( Instance scopedInstance ); void checkStates( INotificationMngr notificationMngr );  }