Skip to content

Commit

Permalink
Merge branch 'DATAGO-75198-dynamic-config-configpush' into DATAGO-751…
Browse files Browse the repository at this point in the history
…98-configpush-with-dynamic-config
  • Loading branch information
rudraneel-chakraborty committed Jun 17, 2024
2 parents 7dee706 + ff4f15b commit a9aeb7d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.MessagingServiceEntity;
import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.ServiceAssociationsCompositeKey;
import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.ServiceAssociationsEntity;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jakarta.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -74,6 +75,14 @@ public Iterable<MessagingServiceEntity> addMessagingServices(List<MessagingServi
return repository.saveAll(messagingServiceEntities);
}

@Transactional
public void deleteMessagingServiceByIds(Set<String> messagingServiceIds) {
if(CollectionUtils.isEmpty(messagingServiceIds)){
return;
}
repository.deleteAllById(messagingServiceIds);
}

/**
* Retrieves a specific Messaging Service by ID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Objects;

@Service
public class EventBrokerResourceConfigToEventConverter {
public class SolaceResourceConfigurationToEventConverter {
public MessagingServiceEvent mapToMessagingServiceEvent(EventBrokerResourceConfiguration eventBrokerResource) {
Objects.requireNonNull(eventBrokerResource);
MessagingServiceEvent serviceEvent = new MessagingServiceEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration;
import com.solace.maas.ep.common.model.ResourceConfigurationType;
import com.solace.maas.ep.event.management.agent.event.MessagingServiceEvent;
import com.solace.maas.ep.event.management.agent.service.EventBrokerResourceConfigToEventConverter;
import com.solace.maas.ep.event.management.agent.service.SolaceResourceConfigurationToEventConverter;
import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class DynamicResourceConfigurationHelper {

private final MessagingServiceDelegateServiceImpl messagingServiceDelegateService;

private final EventBrokerResourceConfigToEventConverter eventBrokerResourceConfigToEventConverter;
private final SolaceResourceConfigurationToEventConverter solaceResourceConfigurationToEventConverter;

public DynamicResourceConfigurationHelper(MessagingServiceDelegateServiceImpl messagingServiceDelegateService,
EventBrokerResourceConfigToEventConverter eventBrokerResourceConfigToEventConverter) {
SolaceResourceConfigurationToEventConverter solaceResourceConfigurationToEventConverter) {
this.messagingServiceDelegateService = messagingServiceDelegateService;
this.eventBrokerResourceConfigToEventConverter = eventBrokerResourceConfigToEventConverter;
this.solaceResourceConfigurationToEventConverter = solaceResourceConfigurationToEventConverter;
}

public void loadSolaceBrokerResourceConfigurations(List<EventBrokerResourceConfiguration> resources) {
Expand All @@ -33,11 +35,19 @@ public void loadSolaceBrokerResourceConfigurations(List<EventBrokerResourceConfi

List<MessagingServiceEvent> solaceEventBrokerResources = resources.stream()
.filter(resource -> resource.getResourceConfigurationType() == ResourceConfigurationType.SOLACE)
.map(eventBrokerResourceConfigToEventConverter::mapToMessagingServiceEvent)
.map(solaceResourceConfigurationToEventConverter::mapToMessagingServiceEvent)
.toList();

//deleteMessagingServiceByIds will delete existing stale messaging services if exists
messagingServiceDelegateService.deleteMessagingServiceByIds(
solaceEventBrokerResources.stream()
.map(MessagingServiceEvent::getId)
.filter(StringUtils::isNotEmpty)
.collect(Collectors.toSet())
);
messagingServiceDelegateService.addMessagingServices(solaceEventBrokerResources)
.forEach(messagingServiceEntity ->
log.info("Loaded [{}] resource with id: [{}] and name: [{}] from message payload.",
log.debug("Loaded [{}] resource with id: [{}] and name: [{}] from message payload.",
messagingServiceEntity.getType(),
messagingServiceEntity.getId(), messagingServiceEntity.getName()));

Expand Down

0 comments on commit a9aeb7d

Please sign in to comment.