Feature event publishing (#884)
* refactored code to use EventPublisherHolder for publishing application events where possible Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * fixed comment Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
2b5b8b4a63
commit
c68c5a6f5b
@@ -15,6 +15,6 @@ spring.cloud.bus.ack.enabled=false
|
|||||||
spring.cloud.bus.trace.enabled=false
|
spring.cloud.bus.trace.enabled=false
|
||||||
spring.cloud.bus.refresh.enabled=false
|
spring.cloud.bus.refresh.enabled=false
|
||||||
# Disable Cloud Bus endpoints
|
# Disable Cloud Bus endpoints
|
||||||
endpoints.spring.cloud.bus.refresh.enabled=false
|
management.endpoint.bus-refresh.enabled=false
|
||||||
endpoints.spring.cloud.bus.env.enabled=false
|
management.endpoint.bus-env.enabled=false
|
||||||
# Spring cloud bus and stream END
|
# Spring cloud bus and stream END
|
||||||
@@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupsValidation;
|
|||||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.integration.support.locks.LockRegistry;
|
import org.springframework.integration.support.locks.LockRegistry;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.scheduling.annotation.AsyncResult;
|
import org.springframework.scheduling.annotation.AsyncResult;
|
||||||
@@ -45,8 +44,6 @@ public abstract class AbstractRolloutManagement implements RolloutManagement {
|
|||||||
|
|
||||||
protected final ApplicationContext context;
|
protected final ApplicationContext context;
|
||||||
|
|
||||||
protected final ApplicationEventPublisher eventPublisher;
|
|
||||||
|
|
||||||
protected final VirtualPropertyReplacer virtualPropertyReplacer;
|
protected final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||||
|
|
||||||
protected final PlatformTransactionManager txManager;
|
protected final PlatformTransactionManager txManager;
|
||||||
@@ -60,15 +57,14 @@ public abstract class AbstractRolloutManagement implements RolloutManagement {
|
|||||||
protected AbstractRolloutManagement(final TargetManagement targetManagement,
|
protected AbstractRolloutManagement(final TargetManagement targetManagement,
|
||||||
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||||
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
||||||
final ApplicationEventPublisher eventPublisher, final VirtualPropertyReplacer virtualPropertyReplacer,
|
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||||
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
|
final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||||
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||||
this.targetManagement = targetManagement;
|
this.targetManagement = targetManagement;
|
||||||
this.deploymentManagement = deploymentManagement;
|
this.deploymentManagement = deploymentManagement;
|
||||||
this.rolloutGroupManagement = rolloutGroupManagement;
|
this.rolloutGroupManagement = rolloutGroupManagement;
|
||||||
this.distributionSetManagement = distributionSetManagement;
|
this.distributionSetManagement = distributionSetManagement;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.eventPublisher = eventPublisher;
|
|
||||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||||
this.txManager = txManager;
|
this.txManager = txManager;
|
||||||
this.tenantAware = tenantAware;
|
this.tenantAware = tenantAware;
|
||||||
|
|||||||
@@ -10,26 +10,28 @@ package org.eclipse.hawkbit.repository.model.helper;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
import org.springframework.cloud.bus.BusProperties;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.cloud.bus.ServiceMatcher;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton bean which holds the event publisher to have to the cache manager
|
* A singleton bean which holds the event publisher and service origin Id in
|
||||||
* in beans not instantiated by spring e.g. JPA entities or
|
* order to publish remote application events. It can be used in beans not
|
||||||
* CacheFieldEntityListener which cannot be autowired.
|
* instantiated by spring e.g. JPA entities which cannot be auto-wired.
|
||||||
*/
|
*/
|
||||||
public final class EventPublisherHolder implements ApplicationContextAware {
|
public final class EventPublisherHolder {
|
||||||
|
|
||||||
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
|
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher eventPublisher;
|
private ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
private String applicationId;
|
@Autowired(required = false)
|
||||||
|
private ServiceMatcher serviceMatcher;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BusProperties bus;
|
||||||
|
|
||||||
private EventPublisherHolder() {
|
private EventPublisherHolder() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,12 +48,11 @@ public final class EventPublisherHolder implements ApplicationContextAware {
|
|||||||
return eventPublisher;
|
return eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the service origin Id coming either from {@link ServiceMatcher}
|
||||||
|
* when available or {@link BusProperties} otherwise.
|
||||||
|
*/
|
||||||
public String getApplicationId() {
|
public String getApplicationId() {
|
||||||
return applicationId;
|
return serviceMatcher != null ? serviceMatcher.getServiceId() : bus.getId();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(final ApplicationContext applicationContext) {
|
|
||||||
applicationId = applicationContext.getBean(BusProperties.class).getId();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,9 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
|||||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link DistributionSet} to {@link Target} assignment strategy as utility for
|
* {@link DistributionSet} to {@link Target} assignment strategy as utility for
|
||||||
@@ -48,20 +47,18 @@ public abstract class AbstractDsAssignmentStrategy {
|
|||||||
|
|
||||||
protected final TargetRepository targetRepository;
|
protected final TargetRepository targetRepository;
|
||||||
protected final AfterTransactionCommitExecutor afterCommit;
|
protected final AfterTransactionCommitExecutor afterCommit;
|
||||||
protected final ApplicationEventPublisher eventPublisher;
|
protected final EventPublisherHolder eventPublisherHolder;
|
||||||
protected final BusProperties bus;
|
|
||||||
protected final ActionRepository actionRepository;
|
protected final ActionRepository actionRepository;
|
||||||
private final ActionStatusRepository actionStatusRepository;
|
private final ActionStatusRepository actionStatusRepository;
|
||||||
private final QuotaManagement quotaManagement;
|
private final QuotaManagement quotaManagement;
|
||||||
|
|
||||||
AbstractDsAssignmentStrategy(final TargetRepository targetRepository,
|
AbstractDsAssignmentStrategy(final TargetRepository targetRepository,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
|
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
|
||||||
final BusProperties bus, final ActionRepository actionRepository,
|
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
|
||||||
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
|
final QuotaManagement quotaManagement) {
|
||||||
this.targetRepository = targetRepository;
|
this.targetRepository = targetRepository;
|
||||||
this.afterCommit = afterCommit;
|
this.afterCommit = afterCommit;
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisherHolder = eventPublisherHolder;
|
||||||
this.bus = bus;
|
|
||||||
this.actionRepository = actionRepository;
|
this.actionRepository = actionRepository;
|
||||||
this.actionStatusRepository = actionStatusRepository;
|
this.actionStatusRepository = actionStatusRepository;
|
||||||
this.quotaManagement = quotaManagement;
|
this.quotaManagement = quotaManagement;
|
||||||
@@ -126,7 +123,8 @@ public abstract class AbstractDsAssignmentStrategy {
|
|||||||
abstract void sendDeploymentEvents(final List<DistributionSetAssignmentResult> assignmentResults);
|
abstract void sendDeploymentEvents(final List<DistributionSetAssignmentResult> assignmentResults);
|
||||||
|
|
||||||
protected void sendTargetUpdatedEvent(final JpaTarget target) {
|
protected void sendTargetUpdatedEvent(final JpaTarget target) {
|
||||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId())));
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
|
.publishEvent(new TargetUpdatedEvent(target, eventPublisherHolder.getApplicationId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,8 +195,8 @@ public abstract class AbstractDsAssignmentStrategy {
|
|||||||
* the action id of the assignment
|
* the action id of the assignment
|
||||||
*/
|
*/
|
||||||
void cancelAssignDistributionSetEvent(final Target target, final Long actionId) {
|
void cancelAssignDistributionSetEvent(final Target target, final Long actionId) {
|
||||||
afterCommit.afterCommit(
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(
|
||||||
() -> eventPublisher.publishEvent(new CancelTargetAssignmentEvent(target, actionId, bus.getId())));
|
new CancelTargetAssignmentEvent(target, actionId, eventPublisherHolder.getApplicationId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
JpaAction createTargetAction(final Map<String, TargetWithActionType> targetsWithActionMap, final JpaTarget target,
|
JpaAction createTargetAction(final Map<String, TargetWithActionType> targetsWithActionMap, final JpaTarget target,
|
||||||
|
|||||||
@@ -76,14 +76,13 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
|||||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
@@ -143,10 +142,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
private EntityFactory entityFactory;
|
private EntityFactory entityFactory;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher eventPublisher;
|
private EventPublisherHolder eventPublisherHolder;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BusProperties bus;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AfterTransactionCommitExecutor afterCommit;
|
private AfterTransactionCommitExecutor afterCommit;
|
||||||
@@ -397,7 +393,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
.status(TargetUpdateStatus.REGISTERED).lastTargetQuery(System.currentTimeMillis())
|
.status(TargetUpdateStatus.REGISTERED).lastTargetQuery(System.currentTimeMillis())
|
||||||
.address(Optional.ofNullable(address).map(URI::toString).orElse(null)).build());
|
.address(Optional.ofNullable(address).map(URI::toString).orElse(null)).build());
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(result, bus.getId())));
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
|
.publishEvent(new TargetPollEvent(result, eventPublisherHolder.getApplicationId())));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (final EntityAlreadyExistsException e) {
|
} catch (final EntityAlreadyExistsException e) {
|
||||||
@@ -453,8 +450,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
|
|
||||||
pollChunks.forEach(chunk -> {
|
pollChunks.forEach(chunk -> {
|
||||||
setLastTargetQuery(tenant, System.currentTimeMillis(), chunk);
|
setLastTargetQuery(tenant, System.currentTimeMillis(), chunk);
|
||||||
chunk.forEach(controllerId -> afterCommit.afterCommit(
|
chunk.forEach(controllerId -> afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
() -> eventPublisher.publishEvent(new TargetPollEvent(controllerId, tenant, bus.getId()))));
|
.publishEvent(new TargetPollEvent(controllerId, tenant, eventPublisherHolder.getApplicationId()))));
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -508,7 +505,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
toUpdate.setAddress(address.toString());
|
toUpdate.setAddress(address.toString());
|
||||||
toUpdate.setLastTargetQuery(System.currentTimeMillis());
|
toUpdate.setLastTargetQuery(System.currentTimeMillis());
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(toUpdate, bus.getId())));
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
|
.publishEvent(new TargetPollEvent(toUpdate, eventPublisherHolder.getApplicationId())));
|
||||||
|
|
||||||
return targetRepository.save(toUpdate);
|
return targetRepository.save(toUpdate);
|
||||||
}
|
}
|
||||||
@@ -678,9 +676,10 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
|
|
||||||
target.setRequestControllerAttributes(true);
|
target.setRequestControllerAttributes(true);
|
||||||
|
|
||||||
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
eventPublisherHolder.getEventPublisher()
|
||||||
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
||||||
JpaTarget.class.getName(), bus.getId()));
|
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
||||||
|
JpaTarget.class.getName(), eventPublisherHolder.getApplicationId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) {
|
private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) {
|
||||||
@@ -1055,8 +1054,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
|
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
|
||||||
afterCommit.afterCommit(
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(
|
||||||
() -> eventPublisher.publishEvent(new CancelTargetAssignmentEvent(target, actionId, bus.getId())));
|
new CancelTargetAssignmentEvent(target, actionId, eventPublisherHolder.getApplicationId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// for testing
|
// for testing
|
||||||
|
|||||||
@@ -67,13 +67,12 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
|||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.data.domain.AuditorAware;
|
import org.springframework.data.domain.AuditorAware;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -138,9 +137,9 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
|||||||
protected JpaDeploymentManagement(final EntityManager entityManager, final ActionRepository actionRepository,
|
protected JpaDeploymentManagement(final EntityManager entityManager, final ActionRepository actionRepository,
|
||||||
final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository,
|
final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository,
|
||||||
final ActionStatusRepository actionStatusRepository, final TargetManagement targetManagement,
|
final ActionStatusRepository actionStatusRepository, final TargetManagement targetManagement,
|
||||||
final AuditorAware<String> auditorProvider, final ApplicationEventPublisher eventPublisher,
|
final AuditorAware<String> auditorProvider, final EventPublisherHolder eventPublisherHolder,
|
||||||
final BusProperties bus, final AfterTransactionCommitExecutor afterCommit,
|
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
final PlatformTransactionManager txManager,
|
||||||
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
||||||
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final Database database) {
|
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final Database database) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
@@ -152,10 +151,10 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
|||||||
this.auditorProvider = auditorProvider;
|
this.auditorProvider = auditorProvider;
|
||||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||||
this.txManager = txManager;
|
this.txManager = txManager;
|
||||||
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher, bus,
|
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisherHolder,
|
||||||
actionRepository, actionStatusRepository, quotaManagement, this::isMultiAssignmentsEnabled);
|
actionRepository, actionStatusRepository, quotaManagement, this::isMultiAssignmentsEnabled);
|
||||||
offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher,
|
offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit,
|
||||||
bus, actionRepository, actionStatusRepository, quotaManagement);
|
eventPublisherHolder, actionRepository, actionStatusRepository, quotaManagement);
|
||||||
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
||||||
this.quotaManagement = quotaManagement;
|
this.quotaManagement = quotaManagement;
|
||||||
this.systemSecurityContext = systemSecurityContext;
|
this.systemSecurityContext = systemSecurityContext;
|
||||||
|
|||||||
@@ -55,10 +55,9 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
|||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
@@ -103,9 +102,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
|
|
||||||
private final NoCountPagingRepository criteriaNoCountDao;
|
private final NoCountPagingRepository criteriaNoCountDao;
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final EventPublisherHolder eventPublisherHolder;
|
||||||
|
|
||||||
private final BusProperties bus;
|
|
||||||
|
|
||||||
private final TenantAware tenantAware;
|
private final TenantAware tenantAware;
|
||||||
|
|
||||||
@@ -125,9 +122,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
final DistributionSetTypeManagement distributionSetTypeManagement, final QuotaManagement quotaManagement,
|
final DistributionSetTypeManagement distributionSetTypeManagement, final QuotaManagement quotaManagement,
|
||||||
final DistributionSetMetadataRepository distributionSetMetadataRepository,
|
final DistributionSetMetadataRepository distributionSetMetadataRepository,
|
||||||
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
|
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
|
||||||
final NoCountPagingRepository criteriaNoCountDao, final ApplicationEventPublisher eventPublisher,
|
final NoCountPagingRepository criteriaNoCountDao, final EventPublisherHolder eventPublisherHolder,
|
||||||
final BusProperties bus, final TenantAware tenantAware,
|
final TenantAware tenantAware, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final VirtualPropertyReplacer virtualPropertyReplacer,
|
|
||||||
final SoftwareModuleRepository softwareModuleRepository,
|
final SoftwareModuleRepository softwareModuleRepository,
|
||||||
final DistributionSetTagRepository distributionSetTagRepository,
|
final DistributionSetTagRepository distributionSetTagRepository,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final Database database) {
|
final AfterTransactionCommitExecutor afterCommit, final Database database) {
|
||||||
@@ -141,8 +137,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
||||||
this.actionRepository = actionRepository;
|
this.actionRepository = actionRepository;
|
||||||
this.criteriaNoCountDao = criteriaNoCountDao;
|
this.criteriaNoCountDao = criteriaNoCountDao;
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisherHolder = eventPublisherHolder;
|
||||||
this.bus = bus;
|
|
||||||
this.tenantAware = tenantAware;
|
this.tenantAware = tenantAware;
|
||||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||||
this.softwareModuleRepository = softwareModuleRepository;
|
this.softwareModuleRepository = softwareModuleRepository;
|
||||||
@@ -283,9 +278,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
distributionSetRepository.deleteByIdIn(toHardDelete);
|
distributionSetRepository.deleteByIdIn(toHardDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> distributionSetIDs.forEach(
|
afterCommit.afterCommit(() -> distributionSetIDs.forEach(dsId -> eventPublisherHolder.getEventPublisher()
|
||||||
dsId -> eventPublisher.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(),
|
.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(), dsId,
|
||||||
dsId, JpaDistributionSet.class.getName(), bus.getId()))));
|
JpaDistributionSet.class.getName(), eventPublisherHolder.getApplicationId()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -79,9 +79,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
@@ -158,21 +156,20 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RolloutStatusCache rolloutStatusCache;
|
private RolloutStatusCache rolloutStatusCache;
|
||||||
|
|
||||||
private final BusProperties bus;
|
private final EventPublisherHolder eventPublisherHolder;
|
||||||
|
|
||||||
private final Database database;
|
private final Database database;
|
||||||
|
|
||||||
JpaRolloutManagement(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
JpaRolloutManagement(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||||
final RolloutGroupManagement rolloutGroupManagement,
|
final RolloutGroupManagement rolloutGroupManagement,
|
||||||
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
||||||
final BusProperties bus, final ApplicationEventPublisher eventPublisher,
|
final EventPublisherHolder eventPublisherHolder, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||||
final TenantAware tenantAware, final LockRegistry lockRegistry, final Database database,
|
final Database database, final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||||
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
|
||||||
super(targetManagement, deploymentManagement, rolloutGroupManagement, distributionSetManagement, context,
|
super(targetManagement, deploymentManagement, rolloutGroupManagement, distributionSetManagement, context,
|
||||||
eventPublisher, virtualPropertyReplacer, txManager, tenantAware, lockRegistry, rolloutApprovalStrategy);
|
virtualPropertyReplacer, txManager, tenantAware, lockRegistry, rolloutApprovalStrategy);
|
||||||
|
this.eventPublisherHolder = eventPublisherHolder;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.bus = bus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -322,8 +319,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void publishRolloutGroupCreatedEventAfterCommit(final RolloutGroup group, final Rollout rollout) {
|
private void publishRolloutGroupCreatedEventAfterCommit(final RolloutGroup group, final Rollout rollout) {
|
||||||
afterCommit.afterCommit(() -> eventPublisher
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(
|
||||||
.publishEvent(new RolloutGroupCreatedEvent(group, rollout.getId(), context.getId())));
|
new RolloutGroupCreatedEvent(group, rollout.getId(), eventPublisherHolder.getApplicationId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCreateRollout(final JpaRollout rollout) {
|
private void handleCreateRollout(final JpaRollout rollout) {
|
||||||
@@ -942,9 +939,9 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
|||||||
final List<Long> groupIds = rollout.getRolloutGroups().stream().map(RolloutGroup::getId)
|
final List<Long> groupIds = rollout.getRolloutGroups().stream().map(RolloutGroup::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> groupIds.forEach(rolloutGroupId -> eventPublisher
|
afterCommit.afterCommit(() -> groupIds.forEach(rolloutGroupId -> eventPublisherHolder.getEventPublisher()
|
||||||
.publishEvent(new RolloutGroupDeletedEvent(tenantAware.getCurrentTenant(), rolloutGroupId,
|
.publishEvent(new RolloutGroupDeletedEvent(tenantAware.getCurrentTenant(), rolloutGroupId,
|
||||||
JpaRolloutGroup.class.getName(), bus.getId()))));
|
JpaRolloutGroup.class.getName(), eventPublisherHolder.getApplicationId()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hardDeleteRollout(final JpaRollout rollout) {
|
private void hardDeleteRollout(final JpaRollout rollout) {
|
||||||
@@ -961,8 +958,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
|||||||
final List<Long> actionIds = StreamSupport.stream(iterable.spliterator(), false).map(Action::getId)
|
final List<Long> actionIds = StreamSupport.stream(iterable.spliterator(), false).map(Action::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
actionRepository.deleteByIdIn(actionIds);
|
actionRepository.deleteByIdIn(actionIds);
|
||||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
new RolloutUpdatedEvent(rollout, EventPublisherHolder.getInstance().getApplicationId())));
|
.publishEvent(new RolloutUpdatedEvent(rollout, eventPublisherHolder.getApplicationId())));
|
||||||
} catch (final RuntimeException e) {
|
} catch (final RuntimeException e) {
|
||||||
LOGGER.error("Exception during deletion of actions of rollout {}", rollout, e);
|
LOGGER.error("Exception during deletion of actions of rollout {}", rollout, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,10 +62,9 @@ import org.eclipse.hawkbit.repository.model.TargetMetadata;
|
|||||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
@@ -109,9 +108,7 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
|
|
||||||
private final NoCountPagingRepository criteriaNoCountDao;
|
private final NoCountPagingRepository criteriaNoCountDao;
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final EventPublisherHolder eventPublisherHolder;
|
||||||
|
|
||||||
private final BusProperties bus;
|
|
||||||
|
|
||||||
private final TenantAware tenantAware;
|
private final TenantAware tenantAware;
|
||||||
|
|
||||||
@@ -127,7 +124,7 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
final DistributionSetRepository distributionSetRepository,
|
final DistributionSetRepository distributionSetRepository,
|
||||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||||
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
|
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
|
||||||
final ApplicationEventPublisher eventPublisher, final BusProperties bus, final TenantAware tenantAware,
|
final EventPublisherHolder eventPublisherHolder, final TenantAware tenantAware,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final Database database) {
|
final Database database) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
@@ -139,8 +136,7 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
||||||
this.targetTagRepository = targetTagRepository;
|
this.targetTagRepository = targetTagRepository;
|
||||||
this.criteriaNoCountDao = criteriaNoCountDao;
|
this.criteriaNoCountDao = criteriaNoCountDao;
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisherHolder = eventPublisherHolder;
|
||||||
this.bus = bus;
|
|
||||||
this.tenantAware = tenantAware;
|
this.tenantAware = tenantAware;
|
||||||
this.afterCommit = afterCommit;
|
this.afterCommit = afterCommit;
|
||||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||||
@@ -190,7 +186,8 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
|
|
||||||
// TargetUpdatedEvent is not sent within the touch() method due to the
|
// TargetUpdatedEvent is not sent within the touch() method due to the
|
||||||
// "lastModifiedAt" field being ignored in JpaTarget
|
// "lastModifiedAt" field being ignored in JpaTarget
|
||||||
eventPublisher.publishEvent(new TargetUpdatedEvent(updatedTarget, bus.getId()));
|
eventPublisherHolder.getEventPublisher()
|
||||||
|
.publishEvent(new TargetUpdatedEvent(updatedTarget, eventPublisherHolder.getApplicationId()));
|
||||||
|
|
||||||
return createdMetadata;
|
return createdMetadata;
|
||||||
}
|
}
|
||||||
@@ -239,7 +236,8 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
final JpaTargetMetadata matadata = targetMetadataRepository.save(updatedMetadata);
|
final JpaTargetMetadata matadata = targetMetadataRepository.save(updatedMetadata);
|
||||||
// target update event is set to ignore "lastModifiedAt" field so it is
|
// target update event is set to ignore "lastModifiedAt" field so it is
|
||||||
// not send automatically within the touch() method
|
// not send automatically within the touch() method
|
||||||
eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId()));
|
eventPublisherHolder.getEventPublisher()
|
||||||
|
.publishEvent(new TargetUpdatedEvent(target, eventPublisherHolder.getApplicationId()));
|
||||||
return matadata;
|
return matadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +253,8 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
targetMetadataRepository.deleteById(metadata.getId());
|
targetMetadataRepository.deleteById(metadata.getId());
|
||||||
// target update event is set to ignore "lastModifiedAt" field so it is
|
// target update event is set to ignore "lastModifiedAt" field so it is
|
||||||
// not send automatically within the touch() method
|
// not send automatically within the touch() method
|
||||||
eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId()));
|
eventPublisherHolder.getEventPublisher()
|
||||||
|
.publishEvent(new TargetUpdatedEvent(target, eventPublisherHolder.getApplicationId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -354,10 +353,12 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
|
|
||||||
targetRepository.deleteByIdIn(targetIDs);
|
targetRepository.deleteByIdIn(targetIDs);
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> targets.forEach(target -> eventPublisher.publishEvent(
|
afterCommit
|
||||||
new TargetDeletedEvent(tenantAware.getCurrentTenant(), target.getId(), target.getControllerId(),
|
.afterCommit(() -> targets.forEach(target -> eventPublisherHolder.getEventPublisher()
|
||||||
Optional.ofNullable(target.getAddress()).map(URI::toString).orElse(null),
|
.publishEvent(new TargetDeletedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
||||||
JpaTarget.class.getName(), bus.getId()))));
|
target.getControllerId(),
|
||||||
|
Optional.ofNullable(target.getAddress()).map(URI::toString).orElse(null),
|
||||||
|
JpaTarget.class.getName(), eventPublisherHolder.getApplicationId()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -466,7 +467,8 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
|
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
|
||||||
}
|
}
|
||||||
if (!StringUtils.isEmpty(filterParams.getFilterBySearchText())) {
|
if (!StringUtils.isEmpty(filterParams.getFilterBySearchText())) {
|
||||||
specList.add(TargetSpecifications.likeIdOrNameOrDescriptionOrAttributeValue(filterParams.getFilterBySearchText()));
|
specList.add(TargetSpecifications
|
||||||
|
.likeIdOrNameOrDescriptionOrAttributeValue(filterParams.getFilterBySearchText()));
|
||||||
}
|
}
|
||||||
if (isHasTagsFilterActive(filterParams)) {
|
if (isHasTagsFilterActive(filterParams)) {
|
||||||
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),
|
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),
|
||||||
@@ -795,9 +797,10 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
|
|
||||||
target.setRequestControllerAttributes(true);
|
target.setRequestControllerAttributes(true);
|
||||||
|
|
||||||
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
eventPublisherHolder.getEventPublisher()
|
||||||
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
||||||
JpaTarget.class.getName(), bus.getId()));
|
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
||||||
|
JpaTarget.class.getName(), eventPublisherHolder.getApplicationId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
|||||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@@ -43,10 +42,10 @@ import com.google.common.collect.Lists;
|
|||||||
public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||||
|
|
||||||
OfflineDsAssignmentStrategy(final TargetRepository targetRepository,
|
OfflineDsAssignmentStrategy(final TargetRepository targetRepository,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
|
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
|
||||||
final BusProperties bus, final ActionRepository actionRepository,
|
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
|
||||||
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
|
final QuotaManagement quotaManagement) {
|
||||||
super(targetRepository, afterCommit, eventPublisher, bus, actionRepository, actionStatusRepository,
|
super(targetRepository, afterCommit, eventPublisherHolder, actionRepository, actionStatusRepository,
|
||||||
quotaManagement);
|
quotaManagement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -35,8 +35,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
|||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -47,14 +46,13 @@ import com.google.common.collect.Lists;
|
|||||||
*/
|
*/
|
||||||
public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||||
|
|
||||||
private final Supplier<Boolean> multiAssignmentsConfig;
|
private final BooleanSupplier multiAssignmentsConfig;
|
||||||
|
|
||||||
OnlineDsAssignmentStrategy(final TargetRepository targetRepository,
|
OnlineDsAssignmentStrategy(final TargetRepository targetRepository,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
|
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
|
||||||
final BusProperties bus, final ActionRepository actionRepository,
|
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
|
||||||
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement,
|
final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig) {
|
||||||
final Supplier<Boolean> multiAssignmentsConfig) {
|
super(targetRepository, afterCommit, eventPublisherHolder, actionRepository, actionStatusRepository,
|
||||||
super(targetRepository, afterCommit, eventPublisher, bus, actionRepository, actionStatusRepository,
|
|
||||||
quotaManagement);
|
quotaManagement);
|
||||||
this.multiAssignmentsConfig = multiAssignmentsConfig;
|
this.multiAssignmentsConfig = multiAssignmentsConfig;
|
||||||
}
|
}
|
||||||
@@ -185,8 +183,9 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
distributionSetId, actions, bus.getId(), actions.get(0).isMaintenanceWindowAvailable())));
|
.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId, actions,
|
||||||
|
eventPublisherHolder.getApplicationId(), actions.get(0).isMaintenanceWindowAvailable())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPendingCancellations(final Target target) {
|
private boolean hasPendingCancellations(final Target target) {
|
||||||
@@ -204,12 +203,12 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
|||||||
* of the targets the event refers to
|
* of the targets the event refers to
|
||||||
*/
|
*/
|
||||||
private void sendMultiActionEvent(final String tenant, final List<String> controllerIds) {
|
private void sendMultiActionEvent(final String tenant, final List<String> controllerIds) {
|
||||||
afterCommit.afterCommit(
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
() -> eventPublisher.publishEvent(new MultiActionEvent(tenant, bus.getId(), controllerIds)));
|
.publishEvent(new MultiActionEvent(tenant, eventPublisherHolder.getApplicationId(), controllerIds)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMultiAssignmentsEnabled() {
|
private boolean isMultiAssignmentsEnabled() {
|
||||||
return multiAssignmentsConfig.get();
|
return multiAssignmentsConfig.getAsBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Action> filterCancellations(final List<Action> actions) {
|
private static Stream<Action> filterCancellations(final List<Action> actions) {
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
|||||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder;
|
import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder;
|
||||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||||
import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle;
|
import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle;
|
||||||
@@ -100,9 +101,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||||
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
@@ -443,15 +442,14 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
|||||||
final DistributionSetTypeManagement distributionSetTypeManagement, final QuotaManagement quotaManagement,
|
final DistributionSetTypeManagement distributionSetTypeManagement, final QuotaManagement quotaManagement,
|
||||||
final DistributionSetMetadataRepository distributionSetMetadataRepository,
|
final DistributionSetMetadataRepository distributionSetMetadataRepository,
|
||||||
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
|
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
|
||||||
final NoCountPagingRepository criteriaNoCountDao, final ApplicationEventPublisher eventPublisher,
|
final NoCountPagingRepository criteriaNoCountDao, final EventPublisherHolder eventPublisherHolder,
|
||||||
final BusProperties bus, final TenantAware tenantAware,
|
final TenantAware tenantAware, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final VirtualPropertyReplacer virtualPropertyReplacer,
|
|
||||||
final SoftwareModuleRepository softwareModuleRepository,
|
final SoftwareModuleRepository softwareModuleRepository,
|
||||||
final DistributionSetTagRepository distributionSetTagRepository,
|
final DistributionSetTagRepository distributionSetTagRepository,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final JpaProperties properties) {
|
final AfterTransactionCommitExecutor afterCommit, final JpaProperties properties) {
|
||||||
return new JpaDistributionSetManagement(entityManager, distributionSetRepository, distributionSetTagManagement,
|
return new JpaDistributionSetManagement(entityManager, distributionSetRepository, distributionSetTagManagement,
|
||||||
systemManagement, distributionSetTypeManagement, quotaManagement, distributionSetMetadataRepository,
|
systemManagement, distributionSetTypeManagement, quotaManagement, distributionSetMetadataRepository,
|
||||||
targetFilterQueryRepository, actionRepository, criteriaNoCountDao, eventPublisher, bus, tenantAware,
|
targetFilterQueryRepository, actionRepository, criteriaNoCountDao, eventPublisherHolder, tenantAware,
|
||||||
virtualPropertyReplacer, softwareModuleRepository, distributionSetTagRepository, afterCommit,
|
virtualPropertyReplacer, softwareModuleRepository, distributionSetTagRepository, afterCommit,
|
||||||
properties.getDatabase());
|
properties.getDatabase());
|
||||||
|
|
||||||
@@ -510,12 +508,12 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
|||||||
final DistributionSetRepository distributionSetRepository,
|
final DistributionSetRepository distributionSetRepository,
|
||||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||||
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
|
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
|
||||||
final ApplicationEventPublisher eventPublisher, final BusProperties bus, final TenantAware tenantAware,
|
final EventPublisherHolder eventPublisherHolder, final TenantAware tenantAware,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final JpaProperties properties) {
|
final JpaProperties properties) {
|
||||||
return new JpaTargetManagement(entityManager, quotaManagement, targetRepository, targetMetadataRepository,
|
return new JpaTargetManagement(entityManager, quotaManagement, targetRepository, targetMetadataRepository,
|
||||||
rolloutGroupRepository, distributionSetRepository, targetFilterQueryRepository, targetTagRepository,
|
rolloutGroupRepository, distributionSetRepository, targetFilterQueryRepository, targetTagRepository,
|
||||||
criteriaNoCountDao, eventPublisher, bus, tenantAware, afterCommit, virtualPropertyReplacer,
|
criteriaNoCountDao, eventPublisherHolder, tenantAware, afterCommit, virtualPropertyReplacer,
|
||||||
properties.getDatabase());
|
properties.getDatabase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,12 +618,11 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
|||||||
RolloutManagement rolloutManagement(final TargetManagement targetManagement,
|
RolloutManagement rolloutManagement(final TargetManagement targetManagement,
|
||||||
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||||
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
||||||
final BusProperties bus, final ApplicationEventPublisher eventPublisher,
|
final EventPublisherHolder eventPublisherHolder, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||||
final TenantAware tenantAware, final LockRegistry lockRegistry, final JpaProperties properties,
|
final JpaProperties properties, final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||||
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
|
||||||
return new JpaRolloutManagement(targetManagement, deploymentManagement, rolloutGroupManagement,
|
return new JpaRolloutManagement(targetManagement, deploymentManagement, rolloutGroupManagement,
|
||||||
distributionSetManagement, context, bus, eventPublisher, virtualPropertyReplacer, txManager,
|
distributionSetManagement, context, eventPublisherHolder, virtualPropertyReplacer, txManager,
|
||||||
tenantAware, lockRegistry, properties.getDatabase(), rolloutApprovalStrategy);
|
tenantAware, lockRegistry, properties.getDatabase(), rolloutApprovalStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,14 +667,13 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
|||||||
final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository,
|
final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository,
|
||||||
final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository,
|
final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository,
|
||||||
final TargetManagement targetManagement, final AuditorAware<String> auditorProvider,
|
final TargetManagement targetManagement, final AuditorAware<String> auditorProvider,
|
||||||
final ApplicationEventPublisher eventPublisher, final BusProperties bus,
|
final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit,
|
||||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||||
final PlatformTransactionManager txManager,
|
|
||||||
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
||||||
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware,
|
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware,
|
||||||
final JpaProperties properties) {
|
final JpaProperties properties) {
|
||||||
return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository,
|
return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository,
|
||||||
actionStatusRepository, targetManagement, auditorProvider, eventPublisher, bus, afterCommit,
|
actionStatusRepository, targetManagement, auditorProvider, eventPublisherHolder, afterCommit,
|
||||||
virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
|
virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
|
||||||
systemSecurityContext, tenantAware, properties.getDatabase());
|
systemSecurityContext, tenantAware, properties.getDatabase());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ public abstract class AbstractIntegrationTest {
|
|||||||
protected ServiceMatcher serviceMatcher;
|
protected ServiceMatcher serviceMatcher;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher eventPublisher;
|
protected ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule();
|
public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule();
|
||||||
@@ -230,9 +230,8 @@ public abstract class AbstractIntegrationTest {
|
|||||||
|
|
||||||
protected DistributionSetAssignmentResult assignDistributionSet(final long dsID, final String controllerId,
|
protected DistributionSetAssignmentResult assignDistributionSet(final long dsID, final String controllerId,
|
||||||
final ActionType actionType) {
|
final ActionType actionType) {
|
||||||
return deploymentManagement.assignDistributionSet(dsID,
|
return deploymentManagement.assignDistributionSet(dsID, Collections.singletonList(
|
||||||
Collections.singletonList(new TargetWithActionType(controllerId, actionType,
|
new TargetWithActionType(controllerId, actionType, RepositoryModelConstants.NO_FORCE_TIME)));
|
||||||
RepositoryModelConstants.NO_FORCE_TIME)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.bus.BusProperties;
|
import org.springframework.cloud.bus.BusProperties;
|
||||||
|
import org.springframework.cloud.bus.ServiceMatcher;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -93,6 +94,9 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher eventPublisher;
|
private ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private ServiceMatcher serviceMatcher;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BusProperties bus;
|
private BusProperties bus;
|
||||||
|
|
||||||
@@ -194,9 +198,10 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
|||||||
result = FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(),
|
result = FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(),
|
||||||
requestResponseContextHolder.getHttpServletResponse(),
|
requestResponseContextHolder.getHttpServletResponse(),
|
||||||
requestResponseContextHolder.getHttpServletRequest(),
|
requestResponseContextHolder.getHttpServletRequest(),
|
||||||
(length, shippedSinceLastEvent, total) -> eventPublisher
|
(length, shippedSinceLastEvent,
|
||||||
.publishEvent(new DownloadProgressEvent(tenantAware.getCurrentTenant(), statusId,
|
total) -> eventPublisher.publishEvent(new DownloadProgressEvent(
|
||||||
shippedSinceLastEvent, bus.getId())));
|
tenantAware.getCurrentTenant(), statusId, shippedSinceLastEvent,
|
||||||
|
serviceMatcher != null ? serviceMatcher.getServiceId() : bus.getId())));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user