Remove target tag to target reference (#1772)
* Remove target tag to target reference it is not used and could lead to extensive memory usage if JPA provider load targets while loading tags Also, remove search field controller id as not meaningful Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Fix review findings --------- Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@@ -28,6 +29,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionStatusRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
|
||||
@@ -44,6 +46,7 @@ import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTypeRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TenantMetaDataRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -203,6 +206,14 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Action.Status.FINISHED));
|
||||
}
|
||||
|
||||
protected Set<TargetTag> getTargetTags(final String controllerId) {
|
||||
return targetRepository
|
||||
.findOne(TargetSpecifications.hasControllerId(controllerId))
|
||||
.map(JpaTarget.class::cast)
|
||||
.map(JpaTarget::getTags)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
}
|
||||
|
||||
private JpaRollout refresh(final Rollout rollout) {
|
||||
return rolloutRepository.findById(rollout.getId()).get();
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
|
||||
assignedTargets.forEach(target -> assertThat(
|
||||
targetTagManagement.findByTarget(PAGE, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
|
||||
getTargetTags(target.getControllerId()).size()).isEqualTo(1));
|
||||
|
||||
final TargetTag findTargetTag = targetTagManagement.getByName("Tag1").orElseThrow(IllegalStateException::new);
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
|
||||
@@ -410,7 +410,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target unAssignTarget = targetManagement.unassignTag("targetId123", findTargetTag.getId());
|
||||
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, unAssignTarget.getControllerId())).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(unAssignTarget.getControllerId())).as("Tag size is wrong")
|
||||
.isEmpty();
|
||||
targetTagManagement.getByName("Tag1").orElseThrow(NoSuchElementException::new);
|
||||
assertThat(targetManagement.findByTag(PAGE, targetTag.getId())).as("Assigned targets are wrong").hasSize(3);
|
||||
@@ -569,7 +569,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
private void checkTargetHasTags(final boolean strict, final Iterable<Target> targets, final TargetTag... tags) {
|
||||
_target: for (final Target tl : targets) {
|
||||
for (final Tag tt : targetTagManagement.findByTarget(PAGE, tl.getControllerId())) {
|
||||
for (final Tag tt : getTargetTags(tl.getControllerId())) {
|
||||
for (final Tag tag : tags) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
continue _target;
|
||||
@@ -588,7 +588,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.getByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : targetTagManagement.findByTarget(PAGE, tl.getControllerId())) {
|
||||
for (final Tag tt : getTargetTags(tl.getControllerId())) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
fail("Target should have no tags");
|
||||
}
|
||||
@@ -719,16 +719,16 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target t11 = targetManagement.getByControllerID(t1.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).doesNotContain(toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.getByControllerID(t2.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t21.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).containsAll(t2Tags);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t21.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).doesNotContain(toArray(t1Tags, TargetTag.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
verifyThrownExceptionBy(() -> targetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
||||
"TargetTag");
|
||||
|
||||
verifyThrownExceptionBy(() -> targetTagManagement.findByTarget(PAGE, NOT_EXIST_ID), "Target");
|
||||
verifyThrownExceptionBy(() -> getTargetTags(NOT_EXIST_ID), "Target");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,7 +237,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetTag toDelete = tags.iterator().next();
|
||||
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent())
|
||||
assertThat(getTargetTags(target.getControllerId()))
|
||||
.contains(toDelete);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// check
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent())
|
||||
assertThat(getTargetTags(target.getControllerId()))
|
||||
.doesNotContain(toDelete);
|
||||
}
|
||||
assertThat(targetTagRepository.findById(toDelete.getId())).as("No tag should be found").isNotPresent();
|
||||
|
||||
Reference in New Issue
Block a user