DmMessageProcessor extends AbstractMessageProcessor<IDmClient> { @Override public void processMessage( Message message ) { if( message instanceof MsgNotifMachineDown ) processMsgNotifMachineDown((MsgNotifMachineDown) message ); else if( message instanceof MsgNotifInstanceChanged ) processMsgNotifInstanceChanged((MsgNotifInstanceChanged) message ); else if( message instanceof MsgNotifInstanceRemoved ) processMsgNotifInstanceRemoved((MsgNotifInstanceRemoved) message ); else if( message instanceof MsgNotifHeartbeat ) processMsgNotifHeartbeat((MsgNotifHeartbeat) message ); else if(message instanceof MsgNotifAutonomic) processMsgMonitoringEvent((MsgNotifAutonomic) message ); else if( message instanceof MsgEcho ) this.manager.debugMngr().notifyMsgEchoReceived((MsgEcho) message ); else if( message instanceof MsgNotifLogs ) processMsgNotifLogs((MsgNotifLogs) message ); else this.logger.warning( "The DM got an undetermined message to process: " + message.getClass().getName()); } DmMessageProcessor( Manager manager ); @Override void processMessage( Message message );  }
@Test public void testProcessMsgNotifMachineDown_success() { this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); MsgNotifMachineDown msg = new MsgNotifMachineDown( this.app.getName(), this.app.getMySqlVm().getName()); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, this.app.getMySqlVm().getStatus()); }
@Test public void testProcessMsgNotifMachineDown_invalidApplication() { this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); MsgNotifMachineDown msg = new MsgNotifMachineDown( "app-51", this.app.getMySqlVm()); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); }
@Test public void testProcessMsgNotifMachineDown_invalidInstance() { this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); MsgNotifMachineDown msg = new MsgNotifMachineDown( this.app.getName(), "invalid-path" ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); }
@Test public void testEchoReception() { IDmListener listener = Mockito.mock( IDmListener.class ); this.manager.listenerAppears( listener ); Mockito.verify( listener, Mockito.never()).raw( Mockito.anyString()); MsgEcho msg = new MsgEcho( "hey!" ); this.processor.processMessage( msg ); Mockito.verify( listener ).raw( "hey!" ); }
@Test public void testProcessMsgNotifLogs_success() throws Exception { this.processor.tmpDir = this.folder.newFolder().getAbsolutePath(); Map<String,byte[]> map = new HashMap<>( 2 ); map.put( "karaf.log", new byte[ 0 ]); map.put( "roboconf.log", new byte[ 0 ]); File output = new File( this.processor.tmpDir, "roboconf-logs/app/si" ); Assert.assertFalse( output.exists()); MsgNotifLogs msg = new MsgNotifLogs( "app", "si", map ); this.processor.processMessage( msg ); Assert.assertTrue( output.exists()); Assert.assertEquals( 2, output.listFiles().length ); Assert.assertTrue( new File( output, "karaf.log" ).exists()); Assert.assertTrue( new File( output, "roboconf.log" ).exists()); }
@Test public void testProcessMsgNotifLogs_failure() throws Exception { this.processor.tmpDir = this.folder.newFile().getAbsolutePath(); Map<String,byte[]> map = new HashMap<>( 2 ); map.put( "karaf.log", new byte[ 0 ]); map.put( "roboconf.log", new byte[ 0 ]); File output = new File( this.processor.tmpDir, "roboconf-logs/app/si/" ); Assert.assertFalse( output.exists()); MsgNotifLogs msg = new MsgNotifLogs( "app", "si", map ); this.processor.processMessage( msg ); Assert.assertFalse( output.exists()); }
@Test public void testProcessMsgNotifInstanceChanged_success() { this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); MsgNotifInstanceChanged msg = new MsgNotifInstanceChanged( this.app.getName(), this.app.getMySqlVm()); msg.setNewStatus( InstanceStatus.STOPPING ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.STOPPING, this.app.getMySqlVm().getStatus()); }
@Test public void testProcessMsgNotifInstanceChanged_invalidApplication() { this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); MsgNotifInstanceChanged msg = new MsgNotifInstanceChanged( "app-53", this.app.getMySqlVm()); msg.setNewStatus( InstanceStatus.STOPPING ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); }
@Test public void testProcessMsgNotifInstanceChanged_invalidInstance() throws Exception { this.managerWrapper.addManagedApplication( new ManagedApplication( this.app )); this.app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); MsgNotifInstanceChanged msg = new MsgNotifInstanceChanged( this.app.getName(), new Instance( "invalid instance" )); msg.setNewStatus( InstanceStatus.STOPPING ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); }
@Test public void testProcessMsgNotifInstanceChanged_rootIsNotDeployed() throws Exception { this.managerWrapper.addManagedApplication( new ManagedApplication( this.app )); this.app.getMySqlVm().setStatus( InstanceStatus.NOT_DEPLOYED ); MsgNotifInstanceChanged msg = new MsgNotifInstanceChanged( this.app.getName(), this.app.getMySql()); msg.setNewStatus( InstanceStatus.DEPLOYED_STARTED ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, this.app.getMySql().getStatus()); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, this.app.getMySqlVm().getStatus()); }
@Test public void testProcessMsgNotifInstanceRemoved_success() { String instancePath = InstanceHelpers.computeInstancePath( this.app.getMySql()); int instancesCount = InstanceHelpers.getAllInstances( this.app ).size(); MsgNotifInstanceRemoved msg = new MsgNotifInstanceRemoved( this.app.getName(), this.app.getMySql()); Assert.assertNotNull( InstanceHelpers.findInstanceByPath( this.app, instancePath )); this.processor.processMessage( msg ); Assert.assertNull( InstanceHelpers.findInstanceByPath( this.app, instancePath )); Assert.assertEquals( instancesCount - 1, InstanceHelpers.getAllInstances( this.app ).size()); }
@Test public void testProcessMsgNotifInstanceRemoved_invalidApplication() { String instancePath = InstanceHelpers.computeInstancePath( this.app.getMySql()); int instancesCount = InstanceHelpers.getAllInstances( this.app ).size(); MsgNotifInstanceRemoved msg = new MsgNotifInstanceRemoved( "app-98", this.app.getMySql()); Assert.assertNotNull( InstanceHelpers.findInstanceByPath( this.app, instancePath )); this.processor.processMessage( msg ); Assert.assertNotNull( InstanceHelpers.findInstanceByPath( this.app, instancePath )); Assert.assertEquals( instancesCount, InstanceHelpers.getAllInstances( this.app ).size()); }
@Test public void testProcessMsgNotifInstanceRemoved_invalidInstance() { MsgNotifInstanceRemoved msg = new MsgNotifInstanceRemoved( this.app.getName(), new Instance( "whatever" )); int instancesCount = InstanceHelpers.getAllInstances( this.app ).size(); this.processor.processMessage( msg ); Assert.assertEquals( instancesCount, InstanceHelpers.getAllInstances( this.app ).size()); }
@Test public void testProcessMsgNotifInstanceRemoved_scopedInstance() { this.app.getWar().getComponent().installerName( Constants.TARGET_INSTALLER ); int instancesCount = InstanceHelpers.getAllInstances( this.app ).size(); MsgNotifInstanceRemoved msg = new MsgNotifInstanceRemoved( this.app.getName(), this.app.getWar()); this.processor.processMessage( msg ); Assert.assertEquals( instancesCount, InstanceHelpers.getAllInstances( this.app ).size()); }
@Test public void testMsgNotifHeartbeat_success() { this.app.getMySqlVm().setStatus( InstanceStatus.PROBLEM ); MsgNotifHeartbeat msg = new MsgNotifHeartbeat( this.app.getName(), this.app.getMySqlVm(), "192.168.1.45" ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); }
@Test public void testMsgNotifHeartbeat_mustSendStoredMessages() throws Exception { this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); TestClient msgClient = (TestClient) this.managerWrapper.getInternalMessagingClient(); ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( this.app.getName()); Assert.assertNotNull( ma ); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, this.app.getMySqlVm().getStatus()); Assert.assertNull( ma.getScopedInstanceToAwaitingMessages().get( this.app.getMySqlVm())); Assert.assertEquals( 0, msgClient.allSentMessages.size()); this.manager.messagingMngr().sendMessageSafely( ma, this.app.getMySqlVm(), new MsgCmdGatherLogs()); this.manager.messagingMngr().sendMessageSafely( ma, this.app.getMySqlVm(), new MsgCmdGatherLogs()); this.manager.messagingMngr().sendMessageSafely( ma, this.app.getMySqlVm(), new MsgCmdGatherLogs()); Assert.assertEquals( 3, ma.getScopedInstanceToAwaitingMessages().get( this.app.getMySqlVm()).size()); Assert.assertEquals( 0, msgClient.allSentMessages.size()); MsgNotifHeartbeat msg = new MsgNotifHeartbeat( this.app.getName(), this.app.getMySqlVm(), "192.168.1.45" ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus()); Assert.assertNull( ma.getScopedInstanceToAwaitingMessages().get( this.app.getMySqlVm())); Assert.assertEquals( 3, msgClient.allSentMessages.size()); }
@Test public void testMsgNotifHeartbeat_invalidApplication() { this.app.getMySqlVm().setStatus( InstanceStatus.PROBLEM ); MsgNotifHeartbeat msg = new MsgNotifHeartbeat( "app-98", this.app.getMySqlVm(), "192.168.1.45" ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.PROBLEM, this.app.getMySqlVm().getStatus()); }
@Test public void testMsgNotifHeartbeat_invalidInstance() { this.app.getMySqlVm().setStatus( InstanceStatus.PROBLEM ); MsgNotifHeartbeat msg = new MsgNotifHeartbeat( this.app.getName(), new Instance( "unknown" ), "192.168.1.45" ); this.processor.processMessage( msg ); Assert.assertEquals( InstanceStatus.PROBLEM, this.app.getMySqlVm().getStatus()); }
@Test public void testMsg_unknownMessage() { Message msg = new Message() { private static final long serialVersionUID = 5687202567967616823L; }; this.processor.processMessage( msg ); }