Skip to content

Commit

Permalink
Merge pull request #192 from SolaceProducts/moodiRealist/DATAGO-80317…
Browse files Browse the repository at this point in the history
…-optional-bean

[DATAGO-80317] fix issues blocking standalone mode from executing.
  • Loading branch information
moodiRealist authored Jul 17, 2024
2 parents 9573772 + 301ffc4 commit 9d52d97
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@Component
@Slf4j
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:false}== false && ${event-portal.managed:false} == false")
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:true}== false && ${event-portal.managed:false} == false")
public class CommandLogStreamingProcessor {

public static final String ANY = "*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
Expand All @@ -39,16 +40,18 @@ public class ScanManager {
private final ScanService scanService;
private final String runtimeAgentId;
private final String orgId;
private final ScanStatusPublisher scanStatusPublisher;
// This is an optional dependency since it is not available in standalone mode.
// If the bean is not present, the publisher will not be used.
private final Optional<ScanStatusPublisher> scanStatusPublisherOpt;

@Autowired
public ScanManager(MessagingServiceDelegateServiceImpl messagingServiceDelegateService,
ScanService scanService,
EventPortalProperties eventPortalProperties,
ScanStatusPublisher scanStatusPublisher) {
Optional<ScanStatusPublisher> scanStatusPublisher) {
this.messagingServiceDelegateService = messagingServiceDelegateService;
this.scanService = scanService;
this.scanStatusPublisher = scanStatusPublisher;
this.scanStatusPublisherOpt = scanStatusPublisher;
runtimeAgentId = eventPortalProperties.getRuntimeAgentId();
orgId = eventPortalProperties.getOrganizationId();
}
Expand Down Expand Up @@ -116,6 +119,11 @@ public String scan(ScanRequestBO scanRequestBO) {

public void handleError(Exception e, ScanCommandMessage message){

if( scanStatusPublisherOpt.isEmpty()){
return;
}
ScanStatusPublisher scanStatusPublisher = scanStatusPublisherOpt.get();

List<String> scanTypeNames = message.getScanTypes().stream().map(ScanType::name).toList();

ScanStatusMessage response = new ScanStatusMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Slf4j
@Component
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:false}== false && ${event-portal.managed:false} == false")
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:true}== false && ${event-portal.managed:false} == false")
public class CommandMessageHandler extends SolaceDirectMessageHandler<CommandMessage> {

private final CommandMessageProcessor commandMessageProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Slf4j
@Component
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:false}== false && ${event-portal.managed:false} == false")
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:true}== false && ${event-portal.managed:false} == false")
public class DiscoveryMessageHandler extends SolaceDirectMessageHandler<MOPMessage> {

public DiscoveryMessageHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Slf4j
@Component
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:false}== false && ${event-portal.managed:false} == false")
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:true}== false && ${event-portal.managed:false} == false")
public class ScanCommandMessageHandler extends SolaceDirectMessageHandler<ScanCommandMessage> {

private final ScanCommandMessageProcessor scanCommandMessageProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@Slf4j
@Service
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:false}== false && ${event-portal.managed:false} == true")
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:true}== false && ${event-portal.managed:false} == true")
public class SolacePersistentMessageHandler extends BaseSolaceMessageHandler implements MessageReceiver.MessageHandler,
ApplicationListener<ApplicationReadyEvent> {
private final Map<String, Class> cachedJSONDecoders = new HashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@Slf4j
@Component
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:false}== false && ${event-portal.managed:false} == false")
@ConditionalOnExpression("${event-portal.gateway.messaging.standalone:true}== false && ${event-portal.managed:false} == false")
public class StartImportScanCommandMessageHandler extends SolaceDirectMessageHandler<ScanDataImportMessage> {

private final ProducerTemplate producerTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.springframework.test.context.ActiveProfiles;

import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -37,7 +39,7 @@ class ScanManagerHandleErrorTest {
private ScanStatusPublisher scanStatusPublisher;

@Test
void testScanManagerHandleError(){
void testScanManagerConnectedHandleError(){
when(eventPortalProperties.getOrganizationId()).thenReturn("orgId");
when(eventPortalProperties.getRuntimeAgentId()).thenReturn("runtimeAgentId");

Expand All @@ -47,13 +49,30 @@ void testScanManagerHandleError(){
messagingServiceDelegateService,
scanService,
eventPortalProperties,
scanStatusPublisher
Optional.of(scanStatusPublisher)
);
scanManagerUnderTest.handleError(mockEx,createScanCommandMessage());
verify(scanStatusPublisher, times(1)).sendOverallScanStatus(any(),any());
}

@Test
void testScanManagerStandaloneHandleError(){
when(eventPortalProperties.getOrganizationId()).thenReturn("orgId");
when(eventPortalProperties.getRuntimeAgentId()).thenReturn("runtimeAgentId");

RuntimeException mockEx = new RuntimeException("Mock Exception");

ScanManager scanManagerUnderTest = new ScanManager(
messagingServiceDelegateService,
scanService,
eventPortalProperties,
Optional.empty()
);
// should just do "nothing" and not throw an exception when scanStatusPublisher is not present
assertDoesNotThrow(() ->
scanManagerUnderTest.handleError(mockEx, createScanCommandMessage()));

}

private ScanCommandMessage createScanCommandMessage(){
return new ScanCommandMessage(
Expand Down

0 comments on commit 9d52d97

Please sign in to comment.