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
|
// check if exists otherwise throw entity not found exception
|
||||||
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(
|
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(
|
||||||
update.getSoftwareModuleId(), update.getKey())
|
update.getSoftwareModuleId(), update.getKey())
|
||||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class,
|
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, update.getSoftwareModuleId(), update.getKey()));
|
||||||
update.getSoftwareModuleId(), update.getKey()));
|
|
||||||
|
|
||||||
update.getValue().ifPresent(metadata::setValue);
|
update.getValue().ifPresent(metadata::setValue);
|
||||||
update.isTargetVisible().ifPresent(metadata::setTargetVisible);
|
update.isTargetVisible().ifPresent(metadata::setTargetVisible);
|
||||||
|
|
||||||
JpaManagementHelper.touch(entityManager, softwareModuleRepository,
|
JpaManagementHelper.touch(entityManager, softwareModuleRepository, metadata.getSoftwareModule());
|
||||||
(JpaSoftwareModule) metadata.getSoftwareModule());
|
|
||||||
return softwareModuleMetadataRepository.save(metadata);
|
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.repository.report.model.SystemUsageReportWithTenants;
|
||||||
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.persistence.config.PersistenceUnitProperties;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.cache.interceptor.KeyGenerator;
|
import org.springframework.cache.interceptor.KeyGenerator;
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -140,7 +138,6 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
|
||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public void deleteTenant(final String t) {
|
public void deleteTenant(final String t) {
|
||||||
@@ -151,8 +148,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
|||||||
final String tenant = t.toUpperCase();
|
final String tenant = t.toUpperCase();
|
||||||
cacheManager.evictCaches(tenant);
|
cacheManager.evictCaches(tenant);
|
||||||
rolloutStatusCache.evictCaches(tenant);
|
rolloutStatusCache.evictCaches(tenant);
|
||||||
tenantAware.runAsTenant(tenant, () -> {
|
tenantAware.runAsTenant(tenant, () -> DeploymentHelper.runInNewTransaction(txManager, "deleteTenant", status -> {
|
||||||
entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
|
|
||||||
tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
|
tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
|
||||||
tenantConfigurationRepository.deleteByTenant(tenant);
|
tenantConfigurationRepository.deleteByTenant(tenant);
|
||||||
targetRepository.deleteByTenant(tenant);
|
targetRepository.deleteByTenant(tenant);
|
||||||
@@ -167,7 +163,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
|||||||
artifactRepository.deleteByTenant(tenant);
|
artifactRepository.deleteByTenant(tenant);
|
||||||
softwareModuleTypeRepository.deleteByTenant(tenant);
|
softwareModuleTypeRepository.deleteByTenant(tenant);
|
||||||
return null;
|
return null;
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -292,13 +288,16 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DistributionSetType createStandardSoftwareDataSetup() {
|
private DistributionSetType createStandardSoftwareDataSetup() {
|
||||||
final SoftwareModuleType app = softwareModuleTypeRepository
|
final SoftwareModuleType app = softwareModuleTypeRepository.save(
|
||||||
.save(new JpaSoftwareModuleType(org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_KEY,
|
new JpaSoftwareModuleType(
|
||||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_NAME, "Application Addons",
|
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_KEY,
|
||||||
Integer.MAX_VALUE));
|
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_NAME,
|
||||||
final SoftwareModuleType os = softwareModuleTypeRepository.save(new JpaSoftwareModuleType(
|
"Application Addons", Integer.MAX_VALUE));
|
||||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_KEY,
|
final SoftwareModuleType os = softwareModuleTypeRepository.save(
|
||||||
org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_NAME, "Core firmware or operation system", 1));
|
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
|
// make sure the module types get their IDs
|
||||||
entityManager.flush();
|
entityManager.flush();
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
* {@link Artifact} repository.
|
* {@link Artifact} repository.
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public interface LocalArtifactRepository
|
public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifact> {
|
||||||
extends BaseEntityRepository<JpaArtifact> {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts artifacts size where the related software module is not
|
* Counts artifacts size where the related software module is not deleted/archived.
|
||||||
* deleted/archived.
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* No access control applied.
|
* No access control applied.
|
||||||
*
|
*
|
||||||
@@ -47,8 +45,7 @@ public interface LocalArtifactRepository
|
|||||||
Long countBySoftwareModuleDeleted(boolean deleted);
|
Long countBySoftwareModuleDeleted(boolean deleted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts current elements based on the sha1 and tenant, as well as having the
|
* Counts current elements based on the sha1 and tenant, as well as having the {@link SoftwareModule} property 'deleted' with value 'false'
|
||||||
* {@link SoftwareModule} property 'deleted' with value 'false'
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* No access control applied
|
* No access control applied
|
||||||
*
|
*
|
||||||
@@ -56,8 +53,7 @@ public interface LocalArtifactRepository
|
|||||||
* @param tenant the current tenant\
|
* @param tenant the current tenant\
|
||||||
* @return the count of the elements
|
* @return the count of the elements
|
||||||
*/
|
*/
|
||||||
long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(
|
long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(@Param("sha1") String sha1, @Param("tenant") String tenant);
|
||||||
@Param("sha1") String sha1, @Param("tenant") String tenant);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for a {@link Artifact} based on given gridFsFileName.
|
* Searches for a {@link Artifact} based on given gridFsFileName.
|
||||||
@@ -84,4 +80,4 @@ public interface LocalArtifactRepository
|
|||||||
* @return list of {@link Artifact}.
|
* @return list of {@link Artifact}.
|
||||||
*/
|
*/
|
||||||
Optional<Artifact> findFirstByFilenameAndSoftwareModuleId(String filename, Long softwareModuleId);
|
Optional<Artifact> findFirstByFilenameAndSoftwareModuleId(String filename, Long softwareModuleId);
|
||||||
}
|
}
|
||||||
@@ -21,12 +21,10 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* repository for operations on {@link TenantMetaData} entity.
|
* Repository for operations on {@link TenantMetaData} entity.
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public interface TenantMetaDataRepository
|
public interface TenantMetaDataRepository extends PagingAndSortingRepository<JpaTenantMetaData, Long>, CrudRepository<JpaTenantMetaData, Long> {
|
||||||
extends PagingAndSortingRepository<JpaTenantMetaData, Long>,
|
|
||||||
CrudRepository<JpaTenantMetaData, Long> {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search {@link TenantMetaData} by tenant name.
|
* Search {@link TenantMetaData} by tenant name.
|
||||||
@@ -47,4 +45,4 @@ public interface TenantMetaDataRepository
|
|||||||
@Modifying
|
@Modifying
|
||||||
@Query("DELETE FROM JpaTenantMetaData t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
@Query("DELETE FROM JpaTenantMetaData t WHERE UPPER(t.tenant) = UPPER(:tenant)")
|
||||||
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
void deleteByTenantIgnoreCase(@Param("tenant") String tenant);
|
||||||
}
|
}
|
||||||
@@ -33,11 +33,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||||||
@Feature("Component Tests - Repository")
|
@Feature("Component Tests - Repository")
|
||||||
@Story("System Management")
|
@Story("System Management")
|
||||||
@ExtendWith(DisposableSqlTestDatabaseExtension.class)
|
@ExtendWith(DisposableSqlTestDatabaseExtension.class)
|
||||||
public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
class SystemManagementTest extends AbstractJpaIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in")
|
@Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in")
|
||||||
public void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception {
|
void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception {
|
||||||
assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(1);
|
assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(1);
|
||||||
|
|
||||||
createTestTenantsForSystemStatistics(2, 0, 0, 0);
|
createTestTenantsForSystemStatistics(2, 0, 0, 0);
|
||||||
@@ -47,7 +47,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that getSystemUsageStatisticsWithTenants returns the usage of all tenants and not only the first 1000 (max page size).")
|
@Description("Ensures that getSystemUsageStatisticsWithTenants returns the usage of all tenants and not only the first 1000 (max page size).")
|
||||||
public void systemUsageReportCollectsStatisticsOfManyTenants() throws Exception {
|
void systemUsageReportCollectsStatisticsOfManyTenants() throws Exception {
|
||||||
// Prepare tenants
|
// Prepare tenants
|
||||||
createTestTenantsForSystemStatistics(1050, 0, 0, 0);
|
createTestTenantsForSystemStatistics(1050, 0, 0, 0);
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Checks that the system report calculates correctly the artifact size of all tenants in the system. It ignores deleted software modules with their artifacts.")
|
@Description("Checks that the system report calculates correctly the artifact size of all tenants in the system. It ignores deleted software modules with their artifacts.")
|
||||||
public void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception {
|
void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception {
|
||||||
// Prepare tenants
|
// Prepare tenants
|
||||||
createTestTenantsForSystemStatistics(2, 1234, 0, 0);
|
createTestTenantsForSystemStatistics(2, 1234, 0, 0);
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Checks that the system report calculates correctly the targets size of all tenants in the system")
|
@Description("Checks that the system report calculates correctly the targets size of all tenants in the system")
|
||||||
public void systemUsageReportCollectsTargetsOfAllTenants() throws Exception {
|
void systemUsageReportCollectsTargetsOfAllTenants() throws Exception {
|
||||||
// Prepare tenants
|
// Prepare tenants
|
||||||
createTestTenantsForSystemStatistics(2, 0, 100, 0);
|
createTestTenantsForSystemStatistics(2, 0, 100, 0);
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Checks that the system report calculates correctly the actions size of all tenants in the system")
|
@Description("Checks that the system report calculates correctly the actions size of all tenants in the system")
|
||||||
public void systemUsageReportCollectsActionsOfAllTenants() throws Exception {
|
void systemUsageReportCollectsActionsOfAllTenants() throws Exception {
|
||||||
// Prepare tenants
|
// Prepare tenants
|
||||||
createTestTenantsForSystemStatistics(2, 0, 20, 2);
|
createTestTenantsForSystemStatistics(2, 0, 20, 2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user