Skip to content

Commit

Permalink
Merge pull request #6 from Agomik/shared-bounded-context-smell
Browse files Browse the repository at this point in the history
Shared bounded context added
  • Loading branch information
Agomik authored Dec 5, 2023
2 parents 32f9270 + 4744ce4 commit 8435cc9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
11 changes: 8 additions & 3 deletions microfreshener/core/analyser/builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .analyser import MicroToscaAnalyser
from .costants import SMELL_WOBBLY_SERVICE_INTERACTION_SMELL, SMELL_SHARED_PERSISTENCY, SMELL_SINGLE_LAYER_TEAMS, \
SMELL_MULTIPLE_SERVICES_IN_ONE_CONTAINER, SMELL_ESB_MISUSE, SMELL_TIGHTLY_COUPLED_TEAMS
SMELL_MULTIPLE_SERVICES_IN_ONE_CONTAINER, SMELL_ESB_MISUSE, SMELL_TIGHTLY_COUPLED_TEAMS, SMELL_SHARED_BOUNDED_CONTEXT
from .sniffer import EndpointBasedServiceInteractionSmellSniffer, NoApiGatewaySmellSniffer, \
WobblyServiceInteractionSmellSniffer, SharedPersistencySmellSniffer, SingleLayerTeamsSmellSniffer, \
MultipleServicesInOneContainerSmellSniffer, TightlyCoupledTeamsSmellSniffer
MultipleServicesInOneContainerSmellSniffer, TightlyCoupledTeamsSmellSniffer, SharedBoundedContextSmellSniffer

from .constant import SMELL_ENDPOINT_BASED_SERVICE_INTERACTION, SMELL_NO_API_GATEWAY

Expand Down Expand Up @@ -31,6 +31,8 @@ def add_smell(self, smell: str):
self.analyser.add_group_smell_sniffer(SingleLayerTeamsSmellSniffer(self.micro_model))
elif smell == SMELL_TIGHTLY_COUPLED_TEAMS or smell == 8:
self.analyser.add_group_smell_sniffer(TightlyCoupledTeamsSmellSniffer(self.micro_model))
elif smell == SMELL_SHARED_BOUNDED_CONTEXT or smell == 9:
self.analyser.add_group_smell_sniffer(SharedBoundedContextSmellSniffer(self.micro_model))
else:
raise ValueError('Smell {} not recognized'.format(smell))
return self
Expand All @@ -52,6 +54,8 @@ def ignore_smell_for_node(self, node, smell:int):
self.analyser.add_group_smell_sniffer(SingleLayerTeamsSmellSniffer(self.micro_model))
elif smell == SMELL_TIGHTLY_COUPLED_TEAMS:
self.analyser.add_group_smell_sniffer(TightlyCoupledTeamsSmellSniffer(self.micro_model))
elif smell == SMELL_SHARED_BOUNDED_CONTEXT:
self.analyser.add_group_smell_sniffer(SharedBoundedContextSmellSniffer(self.micro_model))
else:
raise ValueError('Smell {} not recognized'.format(smell))
return self
Expand All @@ -61,9 +65,10 @@ def add_all_sniffers(self):
self.analyser.add_node_smell_sniffer(WobblyServiceInteractionSmellSniffer())
self.analyser.add_node_smell_sniffer(SharedPersistencySmellSniffer())
self.analyser.add_node_smell_sniffer(MultipleServicesInOneContainerSmellSniffer())
self.analyser.add_group_smell_sniffer(NoApiGatewaySmellSniffer(self.micro_model))
self.analyser.add_group_smell_sniffer(SingleLayerTeamsSmellSniffer(self.micro_model))
self.analyser.add_group_smell_sniffer(TightlyCoupledTeamsSmellSniffer(self.micro_model))
self.analyser.add_group_smell_sniffer(NoApiGatewaySmellSniffer(self.micro_model))
self.analyser.add_group_smell_sniffer(SharedBoundedContextSmellSniffer(self.micro_model))
return self

def build(self):
Expand Down
8 changes: 4 additions & 4 deletions microfreshener/core/analyser/costants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SMELLS_NAME = SMELL_ENDPOINT_BASED_SERVICE_INTERACTION, SMELL_WOBBLY_SERVICE_INTERACTION_SMELL, SMELL_SHARED_PERSISTENCY, SMELL_NO_API_GATEWAY, SMELL_SINGLE_LAYER_TEAMS, SMELL_MULTIPLE_SERVICES_IN_ONE_CONTAINER, SMELL_ESB_MISUSE, SMELL_TIGHTLY_COUPLED_TEAMS =\
"Endpoint-based-service-interaction", "Wobbly-service-interaction", "Shared-persistency", "No-api-gateway", "Single-layer-teams", "Multiple-services-in-one-container", "ESB-misuse", "Tightly-coupled-teams"
SMELLS_NAME = SMELL_ENDPOINT_BASED_SERVICE_INTERACTION, SMELL_WOBBLY_SERVICE_INTERACTION_SMELL, SMELL_SHARED_PERSISTENCY, SMELL_NO_API_GATEWAY, SMELL_SINGLE_LAYER_TEAMS, SMELL_MULTIPLE_SERVICES_IN_ONE_CONTAINER, SMELL_ESB_MISUSE, SMELL_TIGHTLY_COUPLED_TEAMS, SMELL_SHARED_BOUNDED_CONTEXT =\
"Endpoint-based-service-interaction", "Wobbly-service-interaction", "Shared-persistency", "No-api-gateway", "Single-layer-teams", "Multiple-services-in-one-container", "ESB-misuse", "Tightly-coupled-teams", "Shared-bounded-context"

REFACTORING_NAMES = REFACTORING_ADD_SERVICE_DISCOVERY, REFACTORING_ADD_MESSAGE_ROUTER, REFACTORING_ADD_MESSAGE_BROKER, REFACTORING_ADD_CIRCUIT_BREAKER, REFACTORING_USE_TIMEOUT, REFACTORING_MERGE_SERVICES, REFACTORING_SPLIT_DATABASE, REFACTORING_ADD_DATA_MANAGER, REFACTORING_ADD_API_GATEWAY, REFACTORING_SPLIT_SERVICES, REFACTORING_SPLIT_TEAMS_BY_SERVICE, REFACTORING_SPLIT_TEAMS_BY_COUPLING =\
"Add-service-discovery", "Add-message-router", "Add-message-broker", "Add-circuit-breaker", "Use-timeout", "Merge-service", "Split-Datastore", "Add-data-manager", "Add-api-gateway", "Split-service-in-two-pods", "Split-teams-by-service", "Split-teams-by-coupling"
REFACTORING_NAMES = REFACTORING_ADD_SERVICE_DISCOVERY, REFACTORING_ADD_MESSAGE_ROUTER, REFACTORING_ADD_MESSAGE_BROKER, REFACTORING_ADD_CIRCUIT_BREAKER, REFACTORING_USE_TIMEOUT, REFACTORING_MERGE_SERVICES, REFACTORING_SPLIT_DATABASE, REFACTORING_ADD_DATA_MANAGER, REFACTORING_ADD_API_GATEWAY, REFACTORING_SPLIT_SERVICES, REFACTORING_SPLIT_TEAMS_BY_SERVICE, REFACTORING_SPLIT_TEAMS_BY_COUPLING, REFACTORING_MERGE_TEAMS =\
"Add-service-discovery", "Add-message-router", "Add-message-broker", "Add-circuit-breaker", "Use-timeout", "Merge-service", "Split-Datastore", "Add-data-manager", "Add-api-gateway", "Split-service-in-two-pods", "Split-teams-by-service", "Split-teams-by-coupling", "Merge-teams"
20 changes: 18 additions & 2 deletions microfreshener/core/analyser/smell.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..model import Relationship
from ..model import nodes
from .costants import SMELL_ENDPOINT_BASED_SERVICE_INTERACTION, SMELL_NO_API_GATEWAY, SMELL_SHARED_PERSISTENCY, SMELL_WOBBLY_SERVICE_INTERACTION_SMELL, SMELL_SINGLE_LAYER_TEAMS, SMELL_MULTIPLE_SERVICES_IN_ONE_CONTAINER, SMELL_TIGHTLY_COUPLED_TEAMS
from .costants import REFACTORING_ADD_SERVICE_DISCOVERY, REFACTORING_ADD_MESSAGE_ROUTER, REFACTORING_ADD_MESSAGE_BROKER, REFACTORING_ADD_CIRCUIT_BREAKER, REFACTORING_USE_TIMEOUT, REFACTORING_MERGE_SERVICES, REFACTORING_SPLIT_DATABASE, REFACTORING_ADD_DATA_MANAGER, REFACTORING_ADD_API_GATEWAY, REFACTORING_SPLIT_SERVICES, REFACTORING_SPLIT_TEAMS_BY_SERVICE, REFACTORING_SPLIT_TEAMS_BY_COUPLING
from .costants import SMELL_ENDPOINT_BASED_SERVICE_INTERACTION, SMELL_NO_API_GATEWAY, SMELL_SHARED_PERSISTENCY, SMELL_WOBBLY_SERVICE_INTERACTION_SMELL, SMELL_SINGLE_LAYER_TEAMS, SMELL_MULTIPLE_SERVICES_IN_ONE_CONTAINER, SMELL_TIGHTLY_COUPLED_TEAMS, SMELL_SHARED_BOUNDED_CONTEXT
from .costants import REFACTORING_ADD_SERVICE_DISCOVERY, REFACTORING_ADD_MESSAGE_ROUTER, REFACTORING_ADD_MESSAGE_BROKER, REFACTORING_ADD_CIRCUIT_BREAKER, REFACTORING_USE_TIMEOUT, REFACTORING_MERGE_SERVICES, REFACTORING_SPLIT_DATABASE, REFACTORING_ADD_DATA_MANAGER, REFACTORING_ADD_API_GATEWAY, REFACTORING_SPLIT_SERVICES, REFACTORING_SPLIT_TEAMS_BY_SERVICE, REFACTORING_SPLIT_TEAMS_BY_COUPLING, REFACTORING_MERGE_TEAMS
class Smell(object):

def __init__(self, name):
Expand Down Expand Up @@ -174,4 +174,20 @@ def to_dict(self):
sup_dict = super(TightlyCoupledTeamsSmell, self).to_dict()
return {**sup_dict, **{"refactorings": [
{"name": REFACTORING_SPLIT_TEAMS_BY_COUPLING, "description": "Split the teams by coupling."},
]}}

class SharedBoundedContextSmell(GroupSmell):
name: str = SMELL_SHARED_BOUNDED_CONTEXT

def __init__(self, group):
super(SharedBoundedContextSmell, self).__init__(self.name, group)

def __str__(self):
return 'SharedBoundedContext({})'.format(super(SharedBoundedContextSmell, self).__str__())

def to_dict(self):
sup_dict = super(SharedBoundedContextSmell, self).to_dict()
return {**sup_dict, **{"refactorings": [
{"name": REFACTORING_SPLIT_DATABASE, "description": "Split the database among the user teams."},
{"name": REFACTORING_MERGE_TEAMS, "description": "Merge the teams."},
]}}
26 changes: 25 additions & 1 deletion microfreshener/core/analyser/sniffer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from abc import ABCMeta, abstractmethod
from .smell import NodeSmell, SingleLayerTeamsSmell, EndpointBasedServiceInteractionSmell, NoApiGatewaySmell, TightlyCoupledTeamsSmell, \
WobblyServiceInteractionSmell, SharedPersistencySmell, MultipleServicesInOneContainerSmell
WobblyServiceInteractionSmell, SharedPersistencySmell, MultipleServicesInOneContainerSmell, SharedBoundedContextSmell
from ..model import Service, Datastore, CommunicationPattern, MessageRouter, Compute
from ..model.type import MICROTOSCA_NODES_MESSAGE_ROUTER
from ..model import MicroToscaModel
Expand Down Expand Up @@ -189,3 +189,27 @@ def snif(self, group: Team) -> TightlyCoupledTeamsSmell:
if group not in most_interacting_squads:
smell.addNodeCause(node)
return smell

class SharedBoundedContextSmellSniffer(GroupSmellSniffer):

def __str__(self):
return 'SharedBoundedContextSmellSniffer({})'.format(super(GroupSmellSniffer, self).__str__())


@visitor(Team)
def snif(self, group: Team) -> SharedBoundedContextSmell:
smell = SharedBoundedContextSmell(group)
for node in group.members:
if(isinstance(node, Datastore)):
for relationship in node.incoming_interactions:
source_node = relationship.source
source_squad = self.micro_model.squad_of(source_node)
if source_squad is not None and source_squad != group:
smell.addLinkCause(relationship)
elif(isinstance(node, Service)):
for relationship in node.interactions:
target_node = relationship.target
target_squad = self.micro_model.squad_of(target_node)
if target_squad is not None and target_squad != group:
smell.addLinkCause(relationship)
return smell

0 comments on commit 8435cc9

Please sign in to comment.