Fix tranasaction behavior in delete tenant (#2136)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -474,14 +474,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
// check if exists otherwise throw entity not found exception
|
||||
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(
|
||||
update.getSoftwareModuleId(), update.getKey())
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class,
|
||||
update.getSoftwareModuleId(), update.getKey()));
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, update.getSoftwareModuleId(), update.getKey()));
|
||||
|
||||
update.getValue().ifPresent(metadata::setValue);
|
||||
update.isTargetVisible().ifPresent(metadata::setTargetVisible);
|
||||
|
||||
JpaManagementHelper.touch(entityManager, softwareModuleRepository,
|
||||
(JpaSoftwareModule) metadata.getSoftwareModule());
|
||||
JpaManagementHelper.touch(entityManager, softwareModuleRepository, metadata.getSoftwareModule());
|
||||
return softwareModuleMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,8 @@ import org.eclipse.hawkbit.repository.report.model.SystemUsageReport;
|
||||
import org.eclipse.hawkbit.repository.report.model.SystemUsageReportWithTenants;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -140,7 +138,6 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void deleteTenant(final String t) {
|
||||
@@ -151,8 +148,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
final String tenant = t.toUpperCase();
|
||||
cacheManager.evictCaches(tenant);
|
||||
rolloutStatusCache.evictCaches(tenant);
|
||||
tenantAware.runAsTenant(tenant, () -> {
|
||||
entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
|
||||
tenantAware.runAsTenant(tenant, () -> DeploymentHelper.runInNewTransaction(txManager, "deleteTenant", status -> {
|
||||
tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
|
||||
tenantConfigurationRepository.deleteByTenant(tenant);
|
||||
targetRepository.deleteByTenant(tenant);
|
||||
@@ -167,7 +163,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
artifactRepository.deleteByTenant(tenant);
|
||||
softwareModuleTypeRepository.deleteByTenant(tenant);
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,13 +288,16 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
}
|
||||
|
||||
private DistributionSetType createStandardSoftwareDataSetup() {
|
||||
final SoftwareModuleType app = softwareModuleTypeRepository
|
||||
.save(new JpaSoftwareModuleType(org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_KEY,
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_NAME, "Application Addons",
|
||||
Integer.MAX_VALUE));
|
||||
final SoftwareModuleType os = softwareModuleTypeRepository.save(new JpaSoftwareModuleType(
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_KEY,
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_NAME, "Core firmware or operation system", 1));
|
||||
final SoftwareModuleType app = softwareModuleTypeRepository.save(
|
||||
new JpaSoftwareModuleType(
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_KEY,
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_NAME,
|
||||
"Application Addons", Integer.MAX_VALUE));
|
||||
final SoftwareModuleType os = softwareModuleTypeRepository.save(
|
||||
new JpaSoftwareModuleType(
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_KEY,
|
||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_NAME,
|
||||
"Core firmware or operation system", 1));
|
||||
|
||||
// make sure the module types get their IDs
|
||||
entityManager.flush();
|
||||
|
||||
@@ -22,12 +22,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* {@link Artifact} repository.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public interface LocalArtifactRepository
|
||||
extends BaseEntityRepository<JpaArtifact> {
|
||||
public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifact> {
|
||||
|
||||
/**
|
||||
* Counts artifacts size where the related software module is not
|
||||
* deleted/archived.
|
||||
* Counts artifacts size where the related software module is not deleted/archived.
|
||||
* <p/>
|
||||
* No access control applied.
|
||||
*
|
||||
@@ -47,8 +45,7 @@ public interface LocalArtifactRepository
|
||||
Long countBySoftwareModuleDeleted(boolean deleted);
|
||||
|
||||
/**
|
||||
* Counts current elements based on the sha1 and tenant, as well as having the
|
||||
* {@link SoftwareModule} property 'deleted' with value 'false'
|
||||
* Counts current elements based on the sha1 and tenant, as well as having the {@link SoftwareModule} property 'deleted' with value 'false'
|
||||
* <p/>
|
||||
* No access control applied
|
||||
*
|
||||
@@ -56,8 +53,7 @@ public interface LocalArtifactRepository
|
||||
* @param tenant the current tenant\
|
||||
* @return the count of the elements
|
||||
*/
|
||||
long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(
|
||||
@Param("sha1") String sha1, @Param("tenant") String tenant);
|
||||
long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(@Param("sha1") String sha1, @Param("tenant") String tenant);
|
||||
|
||||
/**
|
||||
* Searches for a {@link Artifact} based on given gridFsFileName.
|
||||
@@ -84,4 +80,4 @@ public interface LocalArtifactRepository
|
||||
* @return list of {@link Artifact}.
|
||||
*/
|
||||
Optional<Artifact> findFirstByFilenameAndSoftwareModuleId(String filename, Long softwareModuleId);
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,10 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* repository for operations on {@link TenantMetaData} entity.
|
||||
* Repository for operations on {@link TenantMetaData} entity.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public interface TenantMetaDataRepository
|
||||
extends PagingAndSortingRepository<JpaTenantMetaData, Long>,
|
||||
CrudRepository<JpaTenantMetaData, Long> {
|
||||
public interface TenantMetaDataRepository extends PagingAndSortingRepository<JpaTenantMetaData, Long>, CrudRepository<JpaTenantMetaData, Long> {
|
||||
|
||||
/**
|
||||
* Search {@link TenantMetaData} by tenant name.
|
||||
@@ -47,4 +45,4 @@ public interface TenantMetaDataRepository
|
||||
@Modifying
|
||||
@Query("DELETE FROM JpaTenantMetaData t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user