Fix rollouts status cache eviction and NPE in UI (#530)
* Fix nullpointer in UI and rollout cache invalidation prob. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Sonar issue and util usage. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Evict cache on tenant delete. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -352,7 +352,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
|
||||
distributionSetFilter);
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return null;
|
||||
}
|
||||
return distributionSetRepository.findOne(SpecificationsBuilder.combineWithAnd(specList));
|
||||
@@ -667,7 +667,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
private Page<JpaDistributionSet> findByCriteriaAPI(final Pageable pageable,
|
||||
final List<Specification<JpaDistributionSet>> specList) {
|
||||
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return distributionSetRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
@@ -166,7 +167,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
List<TotalTargetCountActionStatus> rolloutStatusCountItems = rolloutStatusCache
|
||||
.getRolloutGroupStatus(rolloutGroupId);
|
||||
|
||||
if (rolloutStatusCountItems.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(rolloutStatusCountItems)) {
|
||||
rolloutStatusCountItems = actionRepository.getStatusCountByRolloutGroupId(rolloutGroupId);
|
||||
rolloutStatusCache.putRolloutGroupStatus(rolloutGroupId, rolloutStatusCountItems);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -177,7 +178,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
*/
|
||||
private Page<JpaRollout> findByCriteriaAPI(final Pageable pageable,
|
||||
final List<Specification<JpaRollout>> specList) {
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return rolloutRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
@@ -992,7 +993,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
|
||||
List<TotalTargetCountActionStatus> rolloutStatusCountItems = rolloutStatusCache.getRolloutStatus(rolloutId);
|
||||
|
||||
if (rolloutStatusCountItems.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(rolloutStatusCountItems)) {
|
||||
rolloutStatusCountItems = actionRepository.getStatusCountByRolloutId(rolloutId);
|
||||
rolloutStatusCache.putRolloutStatus(rolloutId, rolloutStatusCountItems);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.cache.TenancyCacheManager;
|
||||
import org.eclipse.hawkbit.repository.RolloutStatusCache;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantStatsManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
@@ -112,6 +113,9 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
@Autowired
|
||||
private PlatformTransactionManager txManager;
|
||||
|
||||
@Autowired
|
||||
private RolloutStatusCache rolloutStatusCache;
|
||||
|
||||
@Override
|
||||
public SystemUsageReport getSystemUsageStatistics() {
|
||||
|
||||
@@ -219,6 +223,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
public void deleteTenant(final String t) {
|
||||
final String tenant = t.toUpperCase();
|
||||
cacheManager.evictCaches(tenant);
|
||||
rolloutStatusCache.evictCaches(tenant);
|
||||
tenantAware.runAsTenant(tenant, () -> {
|
||||
entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
|
||||
tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.data.jpa.domain.Specifications;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -157,7 +158,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
|
||||
private Page<JpaTargetFilterQuery> findTargetFilterQueryByCriteriaAPI(final Pageable pageable,
|
||||
final List<Specification<JpaTargetFilterQuery>> specList) {
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return targetFilterQueryRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -317,7 +318,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private Slice<Target> findByCriteriaAPI(final Pageable pageable, final List<Specification<JpaTarget>> specList) {
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable);
|
||||
}
|
||||
return convertPage(
|
||||
@@ -326,7 +327,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private Long countByCriteriaAPI(final List<Specification<JpaTarget>> specList) {
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return targetRepository.count();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.SimpleTypeConverter;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import cz.jirutka.rsql.parser.RSQLParser;
|
||||
import cz.jirutka.rsql.parser.RSQLParserException;
|
||||
@@ -169,7 +170,7 @@ public final class RSQLUtility {
|
||||
virtualPropertyReplacer);
|
||||
final List<Predicate> accept = rootNode.<List<Predicate>, String> accept(jpqQueryRSQLVisitor);
|
||||
|
||||
if (accept != null && !accept.isEmpty()) {
|
||||
if (!CollectionUtils.isEmpty(accept)) {
|
||||
return cb.and(accept.toArray(new Predicate[accept.size()]));
|
||||
}
|
||||
return cb.conjunction();
|
||||
@@ -652,7 +653,7 @@ public final class RSQLUtility {
|
||||
final List<Predicate> childs = new ArrayList<>();
|
||||
for (final Node node2 : children) {
|
||||
final List<Predicate> accept = node2.accept(this);
|
||||
if (accept != null && !accept.isEmpty()) {
|
||||
if (!CollectionUtils.isEmpty(accept)) {
|
||||
childs.addAll(accept);
|
||||
} else {
|
||||
LOGGER.debug("visit logical node children but could not parse it, ignoring {}", node2);
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.orm.jpa.JpaSystemException;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
@@ -149,7 +150,7 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
|
||||
final int currentTokenEndColumn, final int[] is) {
|
||||
for (final int i : is) {
|
||||
final Collection<String> tokenImage = TokenDescription.getTokenImage(i);
|
||||
if (tokenImage != null && !tokenImage.isEmpty()) {
|
||||
if (!CollectionUtils.isEmpty(tokenImage)) {
|
||||
tokenImage.forEach(image -> listTokens.add(new SuggestToken(currentTokenEndColumn + 1,
|
||||
nextTokenBeginColumn + image.length(), null, image)));
|
||||
}
|
||||
@@ -164,8 +165,8 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
|
||||
.of(FieldNameDescription.toTopSuggestToken(nextTokenBeginColumn - currentTokenImageName.length(),
|
||||
nextTokenBeginColumn + currentTokenImageName.length(), currentTokenImageName));
|
||||
} else if (shouldSuggestDotToken(currentTokenImageName, containsDot)) {
|
||||
return Optional.of(
|
||||
Arrays.asList(new SuggestToken(currentTokenEndColumn, nextTokenBeginColumn + 1, null, ".")));
|
||||
return Optional
|
||||
.of(Arrays.asList(new SuggestToken(currentTokenEndColumn, nextTokenBeginColumn + 1, null, ".")));
|
||||
} else if (shouldSuggestSubTokenFieldNames(currentTokenImageName, containsDot)) {
|
||||
return handleSubtokenSuggestion(currentTokenImageName, nextTokenBeginColumn);
|
||||
}
|
||||
@@ -222,7 +223,7 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
|
||||
builder = builder.substring(0, builder.lastIndexOf("Was expecting"));
|
||||
}
|
||||
|
||||
if (expectedTokens != null && !expectedTokens.isEmpty()) {
|
||||
if (!CollectionUtils.isEmpty(expectedTokens)) {
|
||||
final StringBuilder tokens = new StringBuilder();
|
||||
expectedTokens.stream().forEach(value -> tokens.append(value.getSuggestion() + ","));
|
||||
builder = builder.concat("Was expecting :" + tokens.toString().substring(0, tokens.length() - 1));
|
||||
|
||||
Reference in New Issue
Block a user