Skip to content
Snippets Groups Projects
Commit 5ec76a6b authored by Kasper Marstal's avatar Kasper Marstal
Browse files

Merge branch 'ELASTIX-9-blueprints' into develop

parents 1d0b6432 a8b1808d
No related branches found
No related tags found
No related merge requests found
#ifndef __Blueprint_h
#define __Blueprint_h
#include "boost/graph/graph_traits.hpp"
#include "boost/graph/directed_graph.hpp"
#include "itkObjectFactory.h"
#include "itkDataObject.h"
#include "elxMacro.h"
#include "elxComponentDescriptor.h"
#include "boost/graph/graph_traits.hpp"
#include "boost/graph/directed_graph.hpp"
namespace elx {
template< class TComponentDescriptor >
class Blueprint : public itk::DataObject
{
public:
elxNewMacro( Blueprint, itk::DataObject );
typedef TComponentDescriptor ComponentDescriptorType;
typedef typename TComponentDescriptor::ComponentNameType ComponentNameType;
typedef std::string ParameterKeyType;
typedef std::vector< std::string > ParameterValueType;
typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType;
// Component parameter map that sits on a node in the graph
// and holds component configuration settings
struct ComponentPropertyType {
ParameterMapType parameterMap;
};
// Component parameter map that sits on an edge in the graph
// and holds component configuration settings
struct ConnectionPropertyType {
ParameterMapType parameterMap;
};
typedef boost::adjacency_list< boost::vecS,
boost::vecS,
boost::directedS,
ComponentDescriptorType > GraphType;
typedef typename boost::graph_traits< GraphType >::vertex_descriptor ComponentType;
typedef typename boost::graph_traits< GraphType >::vertex_iterator ComponentIterator, ComponentIteratorEnd;
typedef boost::vertex_index_t ComponentIndexType;
typedef typename boost::property_map< GraphType, ComponentIndexType >::type ComponentIndexMapType;
typedef typename boost::graph_traits< GraphType >::edge_descriptor ConnectionDescriptorType;
typedef typename boost::graph_traits< GraphType >::edge_iterator ConnectionIterator, ConnectionIteratorEnd;
typedef typename boost::graph_traits< GraphType >::in_edge_iterator InputIterator, InputIteratorEnd;
typedef typename boost::graph_traits< GraphType >::out_edge_iterator OutputIterator, OutputIteratorEnd;
int TestFunction( void );
bool AddComponent( ComponentDescriptorType component );
bool SetComponent( ComponentIndexType componentIndex, ComponentDescriptorType component );
ComponentDescriptorType GetComponent( ComponentIndexType componentIndex );
bool RemoveComponent( ComponentDescriptorType component );
bool SetConnection( ComponentIndexType upstream, ComponentIndexType downstream );
ConnectionDescriptorType GetConnection( ConnectionDescriptorType Connection );
bool RemoveConnection( ConnectionDescriptorType connection );
void PrintGraph( void );
ComponentPropertyType,
ConnectionPropertyType > GraphType;
typedef boost::graph_traits< GraphType >::vertex_descriptor ComponentIndexType;
typedef boost::graph_traits< GraphType >::vertex_iterator ComponentIteratorType;
typedef std::pair< ComponentIteratorType, ComponentIteratorType > ComponentIteratorPairType;
typedef boost::graph_traits< GraphType >::edge_descriptor ConnectionIndexType;
typedef boost::graph_traits< GraphType >::edge_iterator ConnectionIteratorType;
typedef std::pair< ConnectionIteratorType, ConnectionIteratorType > ConnectionIteratorPairType;
typedef boost::graph_traits< GraphType >::in_edge_iterator InputIteratorType;
typedef std::pair< InputIteratorType, InputIteratorType > InputIteratorPairType;
typedef boost::graph_traits< GraphType >::out_edge_iterator OutputIteratorType;
typedef std::pair< OutputIteratorType, OutputIteratorType > OutputIteratorPairType;
// Interface for managing components
ComponentIndexType AddComponent( void );
ComponentIndexType AddComponent( ParameterMapType parameterMap );
ParameterMapType GetComponent( ComponentIndexType index );
void SetComponent( ComponentIndexType, ParameterMapType parameterMap );
// TODO: Let user delete component. Before we do this, we need a proper way of
// checking that a vertex exist. Otherwise a call to GetComponent() on
// a deleted vertex will result in segfault. It is not really a in issue
// _before_ release since typically we (the developers) will use blueprint
// interface procedurally.
// void DeleteComponent( ComponentIndexType );
ComponentIteratorPairType GetComponentIterator( void ) {
return boost::vertices( this->m_Graph );
}
// Interface for managing connections between components in which we
// deliberately avoid using connection indexes, but instead force
// the user to think in terms of components (which is conceptually simpler)
bool AddConnection( ComponentIndexType upstream, ComponentIndexType downstream );
bool AddConnection( ComponentIndexType upstream, ComponentIndexType downstream, ParameterMapType parameterMap );
ParameterMapType GetConnection( ComponentIndexType upstream, ComponentIndexType downstream );
bool SetConnection( ComponentIndexType upstream, ComponentIndexType downstream, ParameterMapType parameterMap );
bool DeleteConnection( ComponentIndexType upstream, ComponentIndexType downstream );
bool ConnectionExists( ComponentIndexType upstream, ComponentIndexType downstream );
// Returns iterator for all connections in the graph
ConnectionIteratorPairType GetConnectionIterator( void ) {
return boost::edges(this->m_Graph);
}
// Returns the outgoing connections from a component in the graph,
// i.e. all components that reads data from given component
OutputIteratorPairType GetOutputIterator( const ComponentIndexType index ) {
return boost::out_edges( index, this->m_Graph );
}
void WriteBlueprint( const std::string filename );
private:
ConnectionIndexType GetConnectionIndex( ComponentIndexType upsteam, ComponentIndexType downstream );
GraphType m_Graph;
......
#ifndef __ComponentDescriptor_h
#define __ComponentDescriptor_h
#include "elxMacro.h"
#include "itkObjectFactory.h"
#include "itkDataObject.h"
namespace elx {
class ComponentDescriptor : public itk::DataObject
{
public:
elxNewMacro( ComponentDescriptor, itk::DataObject );
// Identifier to find component in the component database
typedef std::string ComponentNameType;
ComponentDescriptor( void ) { this->SetComponentName( ComponentNameType() ); }
ComponentDescriptor( const ComponentNameType componentName );
// TODO: Setter should validate ComponentName exists in ComponentDatabase
itkSetMacro( ComponentName, ComponentNameType );
itkGetMacro( ComponentName, ComponentNameType );
private:
ComponentNameType m_ComponentName;
};
}
#endif // __ComponentDescriptor_h
#ifndef __Blueprint_hxx
#define __Blueprint_hxx
#ifndef __Blueprint_cxx
#define __Blueprint_cxx
#include <boost/graph/graphviz.hpp>
#include "boost/graph/graphviz.hpp"
#include "elxBlueprint.h"
namespace elx {
/*
Blueprint< ComponentDescriptor >::ComponentDescriptorType
Blueprint< ComponentDescriptor >
::AddComponent( ComponentDescriptorType component )
Blueprint::ComponentIndexType
Blueprint
::AddComponent( void )
{
// TODO: Check that the component is in the ComponentDatabase
this->Modified();
return this->m_Graph->add_vertex( component );
ComponentIndexType index = boost::add_vertex( this->m_Graph );
// Return component index so component can retrieved at a later time
return index;
}
bool
Blueprint< ComponentDescriptor >
::SetComponent( ComponentDescriptorType component )
Blueprint::ComponentIndexType
Blueprint
::AddComponent( ParameterMapType parameterMap )
{
this->Modified();
ComponentIndexType index = boost::add_vertex( this->m_Graph );
this->m_Graph[index].parameterMap = parameterMap;
// Return component index so component can retrieved at a later time
return index;
}
Blueprint::ParameterMapType
Blueprint
::GetComponent( ComponentIndexType index )
{
this->Modified();
return this->m_Graph->remove_vertex( connection );
return this->m_Graph[ index ].parameterMap;
}
void
Blueprint
::SetComponent( ComponentIndexType index, ParameterMapType parameterMap )
{
this->Modified();
this->m_Graph[ index ].parameterMap = parameterMap;
}
// TODO: See explanation in elxBlueprint.h
// void
// Blueprint
// ::DeleteComponent( const ComponentIndexType index )
// {
// this->Modified();
//
// clear_vertex( index, this->m_Graph );
// remove_vertex( index, this->m_Graph );
// }
bool
Blueprint< ComponentDescriptor >
::RemoveComponent( ComponentDescriptorType component )
Blueprint
::AddConnection( ComponentIndexType upstream, ComponentIndexType downstream )
{
this->Modified();
return this->m_Graph->remove_vertex( connection );
if( this->ConnectionExists( upstream, downstream) ) {
return false;
}
// Adds directed connection from upstream component to downstream component
return boost::add_edge( upstream, downstream, this->m_Graph ).second;
}
bool
Blueprint< ComponentDescriptor >
::AddConnection( ComponentDescriptorType upsteam, ComponentDescriptorType downstream )
Blueprint
::AddConnection( ComponentIndexType upstream, ComponentIndexType downstream, ParameterMapType parameterMap )
{
this->Modified();
if( !this->ConnectionExists( upstream, downstream ) ) {
ConnectionIndexType index = boost::add_edge( upstream, downstream, this->m_Graph ).first;
this->m_Graph[ index ].parameterMap = parameterMap;
return true;
}
// If the connection does not exist don't do anything because previous settings
// will be overwritten. If the user do want to overwrite current settings,
// she should use SetConnection() instead where the intent is explicit.
return false;
}
Blueprint::ParameterMapType
Blueprint
::GetConnection( ComponentIndexType upstream, ComponentIndexType downstream )
{
this->Modified();
return this->m_Graph->add_edge( upstream, downstream );
return this->m_Graph[ this->GetConnectionIndex( upstream, downstream ) ].parameterMap;
}
ConnectionDescriptorType
Blueprint< ComponentDescriptor >
::GetConnection( ConnectionDescriptorType Connection )
bool
Blueprint
::SetConnection( ComponentIndexType upstream, ComponentIndexType downstream, ParameterMapType parameterMap )
{
this->Modified();
if( !this->ConnectionExists( upstream, downstream ) ) {
return this->AddConnection( upstream, downstream, parameterMap );
} else {
this->m_Graph[ this->GetConnectionIndex( upstream, downstream ) ].parameterMap = parameterMap;
return true;
}
}
void
Blueprint< ComponentDescriptor >
::RemoveConnection( ConnectionType connection )
bool
Blueprint
::DeleteConnection( ComponentIndexType upstream, ComponentIndexType downstream )
{
this->Modified();
this->m_Graph->remove_edge( connection );
if( this->ConnectionExists( upstream, downstream ) ) {
this->m_Graph.remove_edge( this->GetConnectionIndex( upstream, downstream ) );
}
return !this->ConnectionExists( upstream, downstream );
}
void
Blueprint< ComponentDescriptor >
::PrintGraph( void )
bool
Blueprint
::ConnectionExists( ComponentIndexType upstream, ComponentIndexType downstream )
{
// TODO: Link to graphviz library
// boost::write_graphviz(std::cout, this->m_Graph);
std::cout << "Printed graph" << std::endl;
return boost::edge( upstream, downstream, this->m_Graph).second;
}
*/
template<>
int
Blueprint< ComponentDescriptor >
::TestFunction( void )
{ return 0; }
Blueprint::ConnectionIndexType
Blueprint
::GetConnectionIndex( ComponentIndexType upstream, ComponentIndexType downstream )
{
// This function is part of the internal API and should fail hard if we use it incorrectly
if( !this->ConnectionExists( upstream, downstream ) ) {
itkExceptionMacro( "Blueprint does not contain connection from component " << upstream << " to " << downstream );
}
return boost::edge( upstream, downstream, this->m_Graph).first;
}
void
Blueprint
::WriteBlueprint( const std::string filename )
{
std::ofstream dotfile( filename.c_str() );
boost::write_graphviz( dotfile, this->m_Graph );
}
} // namespace elx
#endif // __Blueprint_hxx
\ No newline at end of file
#endif // __Blueprint_cxx
#ifndef __ComponentDescriptor_cxx
#define __ComponentDescriptor_cxx
#include "elxComponentDescriptor.h"
// TODO: Need enum for component name?
namespace elx {
ComponentDescriptor
::ComponentDescriptor( const ComponentNameType componentName )
{
this->SetComponentName( componentName );
}
} // namespace elx
#endif // __ComponentDescriptor_cxx
\ No newline at end of file
......@@ -4,10 +4,9 @@ set( ${MODULE}_INCLUDE_DIRS
)
set( ${MODULE}_SOURCE_FILES
${CMAKE_SOURCE_DIR}/${MODULE_PATH}/Blueprints/src/elxComponentDescriptor.cxx
${CMAKE_SOURCE_DIR}/${MODULE_PATH}/Blueprints/src/elxBlueprint.cxx
)
set( ${MODULE}_LIBRARIES
elxModuleCore
)
\ No newline at end of file
${MODULE}
)
......@@ -68,12 +68,6 @@ set( TEST_LIBRARIES
# Unit tests
add_subdirectory( Unit )
# Benchmarks
option( ELASTIX_BUILD_BENCHMARKING "Enable building benchmarks." OFF )
if( ${ELASTIX_BUILD_BENCHMARKING} )
add_subdirectory( Benchmark )
endif()
# ---------------------------------------------------------------------
# Configure dashboard
mark_as_advanced( ELASTIX_BUILD_DASHBOARD )
......
......@@ -15,10 +15,6 @@ set( ELASTIX_DASHBOARD_LOGSTASH_RSA_PRIVATE_KEY "elxLogstash.key" )
mark_as_advanced( ELASTIX_DASHBOARD_VOLUME )
if( NOT EXISTS "${ELASTIX_DASHBOARD_VOLUME}" )
message( STATUS
"ELASTIX_DASHBOARD_VOLUME points to the folder ${CMAKE_BINARY_DIR}/Testing/Dashboard/Data in your build directory. In production you should point this variable to a safe directory outside the build tree."
)
set( ELASTIX_DASHBOARD_VOLUME "${ELASTIX_DASHBOARD_BINARY_DIR}/Data" )
file( MAKE_DIRECTORY "${ELASTIX_DASHBOARD_VOLUME}" )
endif()
......@@ -46,4 +42,9 @@ configure_file(
configure_file(
${ELASTIX_DASHBOARD_SOURCE_DIR}/elxLogstashForwarder.json.in
${ELASTIX_DASHBOARD_BINARY_DIR}/elxLogstashForwarder.json
)
\ No newline at end of file
)
# ---------------------------------------------------------------------
# SSL certificates
# Use the following OpenSSL command to generate a test certificate and key if needed
# openssl req -subj '/CN=*/' -x509 -batch -nodes -days 9999 -newkey rsa:2048 -keyout elxLogstash.key -out elxLogstash.crt
-----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xCfc2iwx90m56ZahbFnMh1y1i/NVqD0y3xUyJN0kt6zIT3j+BR1
-----END RSA PRIVATE KEY-----
#include "elxBlueprint.h"
#include "elxComponentDescriptor.h"
#include "gtest/gtest.h"
namespace elx {
TEST( Blueprint, Instantiation )
class BlueprintTest : public ::testing::Test {
public:
typedef Blueprint::Pointer BlueprintPointerType;
typedef Blueprint::ComponentIndexType ComponentIndexType;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef Blueprint::ParameterValueType ParameterValueType;
virtual void SetUp() {
parameterMap["ComponentName"] = ParameterValueType(1, "TestName");
}
ParameterMapType parameterMap;
};
TEST_F( BlueprintTest, AddComponent )
{
BlueprintPointerType blueprint;
EXPECT_NO_THROW( blueprint = Blueprint::New() );
ComponentIndexType index0;
EXPECT_NO_THROW( index0 = blueprint->AddComponent() );
ComponentIndexType index1;
EXPECT_NO_THROW( index1 = blueprint->AddComponent( parameterMap ) );
}
TEST_F( BlueprintTest, GetComponent )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index = blueprint->AddComponent( parameterMap );
ParameterMapType parameterMapTest;
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
}
TEST_F( BlueprintTest, SetComponent )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index = blueprint->AddComponent( parameterMap );
ParameterMapType parameterMapTest;
EXPECT_NO_THROW( blueprint->SetComponent( index, parameterMap ) );
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
}
// TODO: The final line segfaults because GetComponent does not check that the index actually
// actually exist. How can we do that? See also explanation in elxBlueprint.h
// TEST_F( BlueprintTest, DeleteComponent )
// {
// BlueprintPointerType blueprint = Blueprint::New();
// ComponentIndexType index = blueprint->AddComponent( parameterMap );
//
// ParameterMapType parameterMapTest;
// EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
// EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
//
// EXPECT_NO_THROW( blueprint->DeleteComponent( index ) );
// EXPECT_ANY_THROW( parameterMapTest = blueprint->GetComponent( index ) );
// }
TEST_F( BlueprintTest, AddConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
ComponentIndexType index2 = blueprint->AddComponent();
// Connection should not exist
EXPECT_FALSE( blueprint->ConnectionExists( index0, index1 ) );
// Connection should be added
EXPECT_TRUE( blueprint->AddConnection( index0, index1 ) );
// Connection should exist
EXPECT_TRUE( blueprint->ConnectionExists( index0, index1 ) );
// Another connection between same components should not be added
// (user should use SetComponent() instead)
EXPECT_FALSE( blueprint->AddConnection( index0, index1 ) );
// Connection should be empty
ParameterMapType parameterMapTest0;
EXPECT_NO_THROW( parameterMapTest0 = blueprint->GetConnection( index0, index1 ) );
EXPECT_EQ( 0u, parameterMapTest0.size() );
// Connection with properties should be added. Testing if properties was
// properly set requires a call to GetConnection() which is the responsibility
// of the next test.
ParameterMapType parameterMapTest1;
EXPECT_TRUE( blueprint->AddConnection( index1, index2, parameterMap ) );
// It is not be possible to add connection between components that do not exist
// because you do not have necessary indexes
}
TEST_F( BlueprintTest, GetConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
ParameterMapType parameterMapTest0;
EXPECT_TRUE( blueprint->AddConnection( index0, index1, parameterMap ) );
EXPECT_NO_THROW( parameterMapTest0 = blueprint->GetConnection( index0, index1 ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest0["ComponentName"] );
}
TEST_F( BlueprintTest, SetConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
blueprint->AddConnection( index0, index1, parameterMap );
ParameterMapType parameterMapTest0;
parameterMapTest0 = blueprint->GetConnection( index0, index1 );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest0["ComponentName"] );
ParameterMapType parameterMapTest1;
parameterMapTest1["ComponentName"] = ParameterValueType(1, "OtherName");
EXPECT_TRUE( blueprint->SetConnection( index0, index1, parameterMapTest1 ) );
ParameterMapType parameterMapTest2;
EXPECT_NO_THROW( parameterMapTest2 = blueprint->GetConnection( index0, index1 ) );
EXPECT_EQ( parameterMapTest1["ComponentName"], parameterMapTest2["ComponentName"] );
}
TEST_F( BlueprintTest, DeleteConnection )
{
typedef Blueprint< ComponentDescriptor > BlueprintType;
BlueprintType::Pointer blueprint;
EXPECT_NO_THROW( blueprint = BlueprintType::New() );
BlueprintPointerType blueprint = Blueprint::New();
typedef BlueprintType::ComponentDescriptorType ComponentDescriptorType;
ComponentDescriptorType::Pointer componentDescriptor;
EXPECT_NO_THROW( componentDescriptor = ComponentDescriptorType::New() );
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
blueprint->AddConnection( index0, index1 );
// Connection should exist
EXPECT_TRUE( blueprint->ConnectionExists( index0, index1 ) );
// Connection be deleted
EXPECT_TRUE( blueprint->DeleteConnection( index0, index1 ) );
// Connection should not exist
EXPECT_FALSE( blueprint->ConnectionExists( index0, index1 ) );
}
TEST_F( BlueprintTest, WriteBlueprint )
{
BlueprintPointerType blueprint = Blueprint::New();
typedef ComponentDescriptorType::ComponentNameType ComponentNameType;
ComponentNameType componentName;
EXPECT_NO_THROW( componentName = ComponentNameType("Metric") );
EXPECT_NO_THROW( componentDescriptor->SetComponentName( componentName ) );
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
ComponentIndexType index2 = blueprint->AddComponent();
ComponentIndexType index3 = blueprint->AddComponent();
EXPECT_NO_THROW( blueprint->TestFunction() );
blueprint->AddConnection( index0, index1 );
blueprint->AddConnection( index0, index2 );
blueprint->AddConnection( index2, index3 );
ASSERT_TRUE( true );
EXPECT_NO_THROW( blueprint->WriteBlueprint( "blueprint.dot" ) );
}
} // namespace elx
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment