/** * Changes the log level. * @param message the incoming message * @throws IOException if something went wrong */ private void processChangeLogLevel( MsgCmdChangeLogLevel message ) throws IOException { AgentUtils.changeRoboconfLogLevel( message.getLogLevel(), this.agent.karafEtc ); }
/** * Updates the probe configuration of a given instance. * @param message the incoming message * @throws IOException if something went wrong */ private void processUpdateProbeConfiguration( MsgCmdUpdateProbeConfiguration message ) throws IOException { Instance inst = InstanceHelpers.findInstanceByPath( this.scopedInstance, message.getInstancePath()); if( inst == null ) this.logger.warning( "Instance " + message.getInstancePath() + " could not be found. Probe configuration will not be updated." ); else AgentUtils.copyInstanceResources( inst, message.getProbeResources()); }
@Test public void testToString() { MsgCmdRemoveInstance msg1 = new MsgCmdRemoveInstance( "/path" ); Assert.assertEquals( "MsgCmdRemoveInstance", msg1.toString()); MsgCmdResynchronize msg2 = new MsgCmdResynchronize(); Assert.assertEquals( "MsgCmdResynchronize", msg2.toString()); } }
dmClient.sendMessageToAgent( app, rootInstance, new MsgCmdSetScopedInstance( rootInstance )); Thread.sleep( getDelay()); Assert.assertEquals( 1, agentMessages.size()); dmClient.sendMessageToAgent( app, rootInstance, new MsgCmdRemoveInstance( rootInstance )); Thread.sleep( getDelay()); Assert.assertEquals( 2, agentMessages.size()); dmClient.sendMessageToAgent( app, rootInstance, new MsgCmdChangeInstanceState( rootInstance, InstanceStatus.DEPLOYED_STARTED )); Thread.sleep( getDelay()); Assert.assertEquals( 3, agentMessages.size()); dmClient.sendMessageToAgent( app, rootInstance, new MsgCmdChangeInstanceState( rootInstance, InstanceStatus.DEPLOYED_STARTED )); Thread.sleep( getDelay()); Assert.assertEquals( 3, agentMessages.size());
@Test public void testPublish() throws Exception { TestClient client = new TestClient(); MessagingContext ctx = new MessagingContext( RecipientKind.DM, "domain", "app1" ); Assert.assertEquals( 0, client.ctxToMessages.size()); client.publish( ctx, new MsgCmdSendInstances()); client.publish( ctx, new MsgCmdSendInstances()); Assert.assertEquals( 1, client.ctxToMessages.size()); List<Message> messages = client.ctxToMessages.get( ctx ); Assert.assertEquals( 2, client.messagesForTheDm.size()); Assert.assertEquals( 2, messages.size()); Assert.assertEquals( MsgCmdSendInstances.class, messages.get( 0 ).getClass()); Assert.assertEquals( MsgCmdSendInstances.class, messages.get( 1 ).getClass()); Assert.assertEquals( 0, client.messagesForAgents.size()); ctx = new MessagingContext( RecipientKind.AGENTS, "domain", "app1" ); client.publish( ctx, new MsgCmdResynchronize()); Assert.assertEquals( 1, client.messagesForAgents.size()); Assert.assertEquals( MsgCmdResynchronize.class, client.messagesForAgents.get( 0 ).getClass()); }
/** * Deploys an instance. * @param msg the message to process * @throws IOException if an error occurred with the messaging or while manipulating the file system * @throws PluginException if something went wrong with the plug-in */ void processMsgChangeInstanceState( MsgCmdChangeInstanceState msg ) throws IOException, PluginException { PluginInterface plugin; Instance instance = InstanceHelpers.findInstanceByPath( this.scopedInstance, msg.getInstancePath()); if( instance == null ) this.logger.severe( "No instance matched " + msg.getInstancePath() + " on the agent. Request to deploy it is dropped." ); else if( instance.getParent() == null ) this.logger.severe( "No action on the root instance is permitted." ); else if(( plugin = this.agent.findPlugin( instance )) == null ) this.logger.severe( "No plug-in was found to deploy " + msg.getInstancePath() + "." ); else AbstractLifeCycleManager .build( instance, this.agent.getApplicationName(), this.messagingClient) .changeInstanceState( instance, plugin, msg.getNewState(), msg.getFileNameToFileContent()); }
@Test public void testMessage_resynchronize() throws Exception { MsgCmdResynchronize msg = new MsgCmdResynchronize(); checkBasics( msg, MsgCmdResynchronize.class ); }
@Test public void testMessage_changeInstanceState() throws Exception { MsgCmdChangeInstanceState msg = new MsgCmdChangeInstanceState( "/o/mp/k", InstanceStatus.DEPLOYED_STARTED ); checkBasics( msg, MsgCmdChangeInstanceState.class ); msg = new MsgCmdChangeInstanceState((String) null, InstanceStatus.NOT_DEPLOYED ); checkBasics( msg, MsgCmdChangeInstanceState.class ); msg = new MsgCmdChangeInstanceState( new Instance( "test" ), InstanceStatus.NOT_DEPLOYED ); checkBasics( msg, MsgCmdChangeInstanceState.class ); Map<String,byte[]> fileNameToFileContent = new HashMap<> (); fileNameToFileContent.put( "readme.txt", new byte[ 90 ]); msg = new MsgCmdChangeInstanceState( "/oops", InstanceStatus.NOT_DEPLOYED, fileNameToFileContent ); checkBasics( msg, MsgCmdChangeInstanceState.class ); msg = new MsgCmdChangeInstanceState((Instance) null, InstanceStatus.NOT_DEPLOYED, fileNameToFileContent ); checkBasics( msg, MsgCmdChangeInstanceState.class ); }
@Test public void testMessage_removeInstance() throws Exception { MsgCmdRemoveInstance msg = new MsgCmdRemoveInstance( "/inst1" ); checkBasics( msg, MsgCmdRemoveInstance.class ); msg = new MsgCmdRemoveInstance( new Instance( "root" )); checkBasics( msg, MsgCmdRemoveInstance.class ); }
@Test public void testMessage_changeBinding() throws Exception { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( "tpl", new HashSet<>( Arrays.asList( "app" ))); checkBasics( msg, MsgCmdChangeBinding.class ); msg = new MsgCmdChangeBinding( "tpl", new HashSet<>( Arrays.asList( "app1", "app2" ))); checkBasics( msg, MsgCmdChangeBinding.class ); }
@Test public void testMessage_restoreInstance() throws Exception { MsgCmdSendInstances msg = new MsgCmdSendInstances(); checkBasics( msg, MsgCmdSendInstances.class ); }
@Test public void testMessage_updateProbeConfiguration() throws Exception { MsgCmdUpdateProbeConfiguration msg = new MsgCmdUpdateProbeConfiguration( "/inst", null ); checkBasics( msg, MsgCmdUpdateProbeConfiguration.class ); msg = new MsgCmdUpdateProbeConfiguration( new Instance( "inst" ), new HashMap<String,byte[]>( 0 )); checkBasics( msg, MsgCmdUpdateProbeConfiguration.class ); }
@Test public void testMessage_setRootInstance() throws Exception { MsgCmdSetScopedInstance msg = new MsgCmdSetScopedInstance( new Instance( "instance1" )); checkBasics( msg, MsgCmdSetScopedInstance.class ); Map<String,String> map1 = new HashMap<> (); map1.put( "test", "t1" ); map1.put( "another", "t2" ); Map<String,Set<String>> map2 = new HashMap<> (); Set<String> appNames = new LinkedHashSet<> (); appNames.add( "app1" ); appNames.add( "app2" ); map2.put( "app_prefix", appNames ); Map<String,byte[]> map3 = new HashMap<> (); map3.put("script", "toto".getBytes( "UTF-8" )); msg = new MsgCmdSetScopedInstance( new Instance( "instance1" ), map1, map2, map3 ); checkBasics( msg, MsgCmdSetScopedInstance.class ); }
@Test public void testMessage_addInstance() throws Exception { Instance child = new Instance( "child" ).channel( "channel 4" ).status( InstanceStatus.DEPLOYED_STOPPED ); child.component( new Component( "comp_child" ).installerName( "whatever" )); MsgCmdAddInstance msg = new MsgCmdAddInstance( child ); checkBasics( msg, MsgCmdAddInstance.class ); Instance root = new Instance( "root" ).status( InstanceStatus.DEPLOYED_STARTED ).channel( "channel1" ).channel( "channel2" ); root.component( new Component( "comp_root" ).installerName( "whatever" )); InstanceHelpers.insertChild( root, child ); msg = new MsgCmdAddInstance( child ); checkBasics( msg, MsgCmdAddInstance.class ); msg = new MsgCmdAddInstance( new Instance( "instance without component" )); checkBasics( msg, MsgCmdAddInstance.class ); }
@Test public void testMessage_gatherLogs() throws Exception { MsgCmdGatherLogs msg = new MsgCmdGatherLogs(); checkBasics( msg, MsgCmdGatherLogs.class ); }
@Test public void testMessage_changeLogLevel() throws Exception { MsgCmdChangeLogLevel msg = new MsgCmdChangeLogLevel( Level.FINER ); checkBasics( msg, MsgCmdChangeLogLevel.class ); }
dmClient.sendMessageToAgent( app1, app1_root1, new MsgCmdSetScopedInstance( app1_root1 )); dmClient.sendMessageToAgent( app2, app2_root, new MsgCmdSetScopedInstance( app2_root )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdSetScopedInstance( app1_root2, null, null, null )); dmClient.sendMessageToAgent( app2, app2_root, new MsgCmdRemoveInstance( app2_root )); dmClient.sendMessageToAgent( app2, app2_root, new MsgCmdChangeInstanceState( app2_root, InstanceStatus.DEPLOYED_STOPPED )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdRemoveInstance( app1_root2 )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdRemoveInstance( app1_root2 )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdChangeInstanceState( app1_root2, InstanceStatus.NOT_DEPLOYED )); dmClient.sendMessageToAgent( app1, app1_root1, new MsgCmdRemoveInstance( app1_root1 )); dmClient.sendMessageToAgent( app1, app1_root1, new MsgCmdSetScopedInstance( app1_root1 ));
@Override public void resynchronizeAgents( ManagedApplication ma ) throws IOException { this.messagingMngr.checkMessagingConfiguration(); this.logger.fine( "Resynchronizing agents in " + ma.getName() + "..." ); for( Instance rootInstance : ma.getApplication().getRootInstances()) { if( rootInstance.getStatus() == InstanceStatus.DEPLOYED_STARTED ) this.messagingMngr.sendMessageDirectly( ma, rootInstance, new MsgCmdResynchronize()); } this.logger.fine( "Requests were sent to resynchronize agents in " + ma.getName() + "." ); }
@Test public void testClearMessages() { TestClient client = new TestClient(); List<Message> messages = new ArrayList<> (); messages.add( new MsgCmdRemoveInstance( "/root" )); client.ctxToMessages.put( new MessagingContext( RecipientKind.DM, "domain", "app" ), messages ); client.messagesForAgents.add( new MsgCmdRemoveInstance( "/root1" )); client.messagesForTheDm.add( new MsgCmdRemoveInstance( "/root2" )); client.allSentMessages.add( new MsgCmdRemoveInstance( "/root2" )); client.clearMessages(); Assert.assertEquals( 0, client.messagesForAgents.size()); Assert.assertEquals( 0, client.messagesForTheDm.size()); Assert.assertEquals( 0, client.ctxToMessages.size()); Assert.assertEquals( 0, client.allSentMessages.size()); } }
@Test public void testProcessing() throws Exception { // The message is processed... this.processor.start(); this.processor.storeMessage( new MsgCmdResynchronize()); Thread.sleep( 1000 ); this.processor.stopProcessor(); Assert.assertEquals( 0, this.processor.getMessageQueue().size()); }