Skip to content

Commit

Permalink
Merge pull request #538 from vincent-zurczak/master
Browse files Browse the repository at this point in the history
Messaging rework
  • Loading branch information
Pierre-Yves Gibello committed Jan 8, 2016
2 parents 814f164 + 4e45b57 commit 6fb82c0
Show file tree
Hide file tree
Showing 316 changed files with 6,894 additions and 3,060 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: java
sudo: false

# ENV variables
env:
- ROBOCONF_IT_TIMEOUT=60000

# Test several JDK
jdk:
- oraclejdk7
Expand Down
7 changes: 3 additions & 4 deletions build-logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# logs entries during builds. #
############################################

handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler
handlers= java.util.logging.ConsoleHandler

.level = WARNING
java.util.logging.FileHandler.level = WARNING
java.util.logging.ConsoleHandler.level = WARNING
.level = SEVERE
java.util.logging.ConsoleHandler.level = SEVERE
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ public void reset( Instance associatedInstance, String eventId, String fileConte
this.logger.severe( "Invalid content for the 'file' handler in the agent's monitoring." );

} else {
// Back to defaults
this.fileLocation = fileContent;
this.notifyIfNotExists = false;
this.deleteIfExists = false;

// Update defaults if necessary
if( this.fileLocation.toLowerCase().startsWith( DELETE_IF_EXISTS )) {
this.deleteIfExists = true;
this.fileLocation = this.fileLocation.substring( DELETE_IF_EXISTS.length()).trim();

} else if( this.fileLocation.toLowerCase().startsWith( NOTIFY_IF_NOT_EXISTS )) {
this.notifyIfNotExists = true;
this.fileLocation = this.fileLocation.substring( NOTIFY_IF_NOT_EXISTS.length()).trim();

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.List;
import java.util.Map;

import junit.framework.Assert;
import org.junit.Assert;
import net.roboconf.agent.monitoring.api.IMonitoringHandler;
import net.roboconf.agent.monitoring.internal.file.FileHandler;
import net.roboconf.agent.monitoring.internal.nagios.NagiosHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
package net.roboconf.agent.monitoring.internal;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import junit.framework.Assert;
import org.junit.Assert;
import net.roboconf.agent.monitoring.api.IMonitoringHandler;
import net.roboconf.agent.monitoring.internal.MonitoringTask.MonitoringHandlerRun;
import net.roboconf.agent.monitoring.internal.file.FileHandler;
Expand All @@ -44,12 +45,14 @@
import net.roboconf.core.model.beans.Instance.InstanceStatus;
import net.roboconf.core.model.helpers.InstanceHelpers;
import net.roboconf.core.utils.Utils;
import net.roboconf.messaging.api.internal.client.test.TestClientAgent;
import net.roboconf.messaging.api.internal.client.test.TestClientFactory;
import net.roboconf.messaging.api.business.IAgentClient;
import net.roboconf.messaging.api.messages.Message;
import net.roboconf.messaging.api.messages.from_agent_to_dm.MsgNotifAutonomic;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

/**
* @author Vincent Zurczak - Linagora
Expand All @@ -58,18 +61,19 @@ public class MonitoringTaskTest {

private static final List<IMonitoringHandler> HANDLERS = new ArrayList<> ();
static {
HANDLERS.add( new FileHandler());
HANDLERS.add( new NagiosHandler());
HANDLERS.add( new RestHandler());
HANDLERS.add( new FileHandler());
HANDLERS.add( new NagiosHandler());
HANDLERS.add( new RestHandler());
}

private TestClientAgent messagingClient;
private IAgentClient messagingClient;
private MyAgentInterface agentInterface;


@Before
public void initializeMessagingClient() {
this.messagingClient = (TestClientAgent) new TestClientFactory().createAgentClient(null);
public void initializeMessagingClient() throws Exception {

this.messagingClient = Mockito.mock( IAgentClient.class );
this.agentInterface = new MyAgentInterface( this.messagingClient );
}

Expand Down Expand Up @@ -100,17 +104,17 @@ public void testExtractRuleSections_file() throws Exception {
MonitoringHandlerRun bean = handlers.get( 0 );
Assert.assertEquals( "file", bean.handlerName );
Assert.assertEquals( "myRuleName-1", bean.eventId );
Assert.assertTrue( bean.rawRulesText.contains( "/tmp/ta-daaaaa" ));
Assert.assertTrue( bean.rawRulesText.contains( "%TMP%/rbcf-test/ta-daaaaa" ));

bean = handlers.get( 1 );
Assert.assertEquals( "file", bean.handlerName );
Assert.assertEquals( "myRuleName-2", bean.eventId );
Assert.assertTrue( bean.rawRulesText.contains( "/tmp/ta-daaaaa-2" ));
Assert.assertTrue( bean.rawRulesText.contains( "%TMP%/rbcf-test/ta-daaaaa-2" ));

bean = handlers.get( 2 );
Assert.assertEquals( "file", bean.handlerName );
Assert.assertEquals( "myRuleName", bean.eventId );
Assert.assertTrue( bean.rawRulesText.contains( "/tmp/a-directory-to-not-delete" ));
Assert.assertTrue( bean.rawRulesText.contains( "%TMP%/rbcf-test/a-directory-to-not-delete" ));
}


Expand Down Expand Up @@ -257,11 +261,11 @@ public void testExtractRuleSections_unknownParser() throws Exception {
public void testWholeChain_instancesStarted() throws Exception {

testTheCommonChain( InstanceStatus.DEPLOYED_STARTED, "/file-events.conf" );
ArgumentCaptor<Message> msgCapture = ArgumentCaptor.forClass( Message.class );
Mockito.verify( this.messagingClient, Mockito.times( 1 )).sendMessageToTheDm( msgCapture.capture());
Assert.assertEquals( MsgNotifAutonomic.class, msgCapture.getValue().getClass());

Assert.assertEquals( 1, this.messagingClient.messagesForTheDm.size());
Assert.assertEquals( MsgNotifAutonomic.class, this.messagingClient.messagesForTheDm.get( 0 ).getClass());

MsgNotifAutonomic msg = (MsgNotifAutonomic) this.messagingClient.messagesForTheDm.get( 0 );
MsgNotifAutonomic msg = (MsgNotifAutonomic) msgCapture.getValue();
Assert.assertEquals( this.agentInterface.getApplicationName(), msg.getApplicationName());
Assert.assertEquals( "myRuleName", msg.getEventId());
Assert.assertEquals( "/" + this.agentInterface.getScopedInstance().getName(), msg.getScopedInstancePath());
Expand All @@ -273,34 +277,34 @@ public void testWholeChain_instancesStarted() throws Exception {
public void testWholeChain_instancesNotStarted() throws Exception {

testTheCommonChain( InstanceStatus.DEPLOYED_STOPPED, "/file-events.conf" );
Assert.assertEquals( 0, this.messagingClient.messagesForTheDm.size());
Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class ));
}


@Test
public void testWholeChain_noHandler() throws Exception {

testTheCommonChain( InstanceStatus.DEPLOYED_STARTED, "/unknown-events.conf" );
Assert.assertEquals( 0, this.messagingClient.messagesForTheDm.size());
Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class ));
}


@Test
public void testWholeChain_messagingError() throws Exception {

this.messagingClient.failMessageSending.set( true );
Mockito.doThrow( new IOException( "For test" )).when( this.messagingClient ).sendMessageToTheDm( Mockito.any( Message.class ));
testTheCommonChain( InstanceStatus.DEPLOYED_STARTED, "/file-events.conf" );
Assert.assertEquals( 0, this.messagingClient.messagesForTheDm.size());
// No exception is thrown
}


@Test
public void testWholeChain_noModelYet() throws Exception {

Assert.assertEquals( 0, this.messagingClient.messagesForTheDm.size());
Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class ));
MonitoringTask task = new MonitoringTask( this.agentInterface, HANDLERS );
task.run();
Assert.assertEquals( 0, this.messagingClient.messagesForTheDm.size());
Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class ));
}


Expand All @@ -321,17 +325,22 @@ private void testTheCommonChain( InstanceStatus status, String file ) throws Exc
Assert.assertTrue( dir.mkdirs());

File f = TestUtils.findTestFile( file );
File measureFile = new File( dir, childInstance.getComponent().getName() + ".measures" );
String tmpDirLocation = System.getProperty( "java.io.tmpdir" ).replace( "\\", "/" ).replaceAll( "/?$", "" );
String updatedContent = Utils.readFileContent( f ).replace( "%TMP%", tmpDirLocation );

Assert.assertFalse( measureFile.exists());
Utils.copyStream( f, measureFile );
File measureFile = new File( dir, childInstance.getComponent().getName() + ".measures" );
Utils.writeStringInto( updatedContent, measureFile );
Assert.assertTrue( measureFile.exists());

// Run the task
Assert.assertEquals( 0, this.messagingClient.messagesForTheDm.size());
Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class ));
MonitoringTask task = new MonitoringTask( this.agentInterface, HANDLERS );
task.run();

Utils.deleteFilesRecursively( dir );
Assert.assertFalse( dir.exists());

File temporaryDirectory = new File( tmpDirLocation, "rbcf-test" );
Utils.deleteFilesRecursively( temporaryDirectory );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import java.io.File;

import junit.framework.Assert;
import org.junit.Assert;
import net.roboconf.messaging.api.messages.from_agent_to_dm.MsgNotifAutonomic;

import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import java.io.IOException;

import junit.framework.Assert;
import org.junit.Assert;

import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import junit.framework.Assert;
import org.junit.Assert;
import net.roboconf.messaging.api.messages.from_agent_to_dm.MsgNotifAutonomic;

import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import junit.framework.Assert;
import org.junit.Assert;
import net.roboconf.agent.monitoring.internal.rest.RestHandler.LocalHostnameVerifier;
import net.roboconf.agent.monitoring.internal.rest.RestHandler.LocalX509TrustManager;
import net.roboconf.messaging.api.messages.from_agent_to_dm.MsgNotifAutonomic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@

import net.roboconf.agent.AgentMessagingInterface;
import net.roboconf.core.model.beans.Instance;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.internal.client.test.TestClientAgent;
import net.roboconf.messaging.api.business.IAgentClient;

/**
* @author Vincent Zurczak - Linagora
*/
public class MyAgentInterface implements AgentMessagingInterface {

private final TestClientAgent messagingClient;
private final IAgentClient messagingClient;
private Instance scopedInstance;


/**
* Constructor.
* @param messagingClient
*/
public MyAgentInterface( TestClientAgent messagingClient ) {
public MyAgentInterface( IAgentClient messagingClient ) {
this.messagingClient = messagingClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

# Notify the DM if a file exists and delete it.
[EVENT file myRuleName-1]
Delete if exists /tmp/ta-daaaaa
Delete if exists %TMP%/rbcf-test/ta-daaaaa

# Notify the DM if a file exists.
[EVENT file myRuleName-2]
/tmp/ta-daaaaa-2
%TMP%/rbcf-test/ta-daaaaa-2

# Notify the DM if a file does NOT exist.
[EVENT file myRuleName]
Notify if not exists /tmp/a-directory-to-not-delete
Notify if not exists %TMP%/rbcf-test/a-directory-to-not-delete
8 changes: 7 additions & 1 deletion core/roboconf-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,20 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.roboconf</groupId>
<artifactId>roboconf-messaging-rabbitmq</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package net.roboconf.agent;

import net.roboconf.core.model.beans.Instance;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.business.IAgentClient;

/**
* @author Pierre-Yves Gibello - Linagora
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
import net.roboconf.core.model.helpers.InstanceHelpers;
import net.roboconf.core.model.helpers.VariableHelpers;
import net.roboconf.core.utils.Utils;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.client.ListenerCommand;
import net.roboconf.messaging.api.AbstractMessageProcessor;
import net.roboconf.messaging.api.business.IAgentClient;
import net.roboconf.messaging.api.business.ListenerCommand;
import net.roboconf.messaging.api.messages.Message;
import net.roboconf.messaging.api.messages.from_agent_to_agent.MsgCmdAddImport;
import net.roboconf.messaging.api.messages.from_agent_to_agent.MsgCmdRemoveImport;
Expand All @@ -64,7 +65,6 @@
import net.roboconf.messaging.api.messages.from_dm_to_agent.MsgCmdSendInstances;
import net.roboconf.messaging.api.messages.from_dm_to_agent.MsgCmdSetScopedInstance;
import net.roboconf.messaging.api.messages.from_dm_to_dm.MsgEcho;
import net.roboconf.messaging.api.processors.AbstractMessageProcessor;
import net.roboconf.plugin.api.PluginException;
import net.roboconf.plugin.api.PluginInterface;

Expand Down Expand Up @@ -127,7 +127,7 @@ public AgentMessageProcessor( Agent agent ) {


/*
* @see net.roboconf.messaging.api.client.AbstractMessageProcessor
* @see net.roboconf.messaging.api.business.AbstractMessageProcessor
* #processMessage(net.roboconf.messaging.api.messages.Message)
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import net.roboconf.core.model.helpers.ImportHelpers;
import net.roboconf.core.model.helpers.InstanceHelpers;
import net.roboconf.core.utils.Utils;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.client.ListenerCommand;
import net.roboconf.messaging.api.business.IAgentClient;
import net.roboconf.messaging.api.business.ListenerCommand;
import net.roboconf.messaging.api.messages.from_agent_to_dm.MsgNotifInstanceChanged;
import net.roboconf.plugin.api.PluginException;
import net.roboconf.plugin.api.PluginInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import net.roboconf.core.model.beans.Instance;
import net.roboconf.core.model.beans.Instance.InstanceStatus;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.business.IAgentClient;
import net.roboconf.plugin.api.PluginException;
import net.roboconf.plugin.api.PluginInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import net.roboconf.core.model.beans.Instance;
import net.roboconf.core.model.beans.Instance.InstanceStatus;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.business.IAgentClient;
import net.roboconf.plugin.api.PluginException;
import net.roboconf.plugin.api.PluginInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import net.roboconf.core.model.beans.Instance;
import net.roboconf.core.model.beans.Instance.InstanceStatus;
import net.roboconf.messaging.api.client.IAgentClient;
import net.roboconf.messaging.api.business.IAgentClient;
import net.roboconf.plugin.api.PluginException;
import net.roboconf.plugin.api.PluginInterface;

Expand Down
Loading

0 comments on commit 6fb82c0

Please sign in to comment.