TargetManagement over RepositoryManagement (#2599)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -13,7 +13,6 @@ import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupBuilder;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -24,21 +23,13 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Validated
|
||||
public class JpaEntityFactory implements EntityFactory {
|
||||
|
||||
private final TargetBuilder targetBuilder;
|
||||
private final RolloutBuilder rolloutBuilder;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
public JpaEntityFactory(
|
||||
final TargetBuilder targetBuilder, final RolloutBuilder rolloutBuilder) {
|
||||
this.targetBuilder = targetBuilder;
|
||||
public JpaEntityFactory(final RolloutBuilder rolloutBuilder) {
|
||||
this.rolloutBuilder = rolloutBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetBuilder target() {
|
||||
return targetBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatusBuilder actionStatus() {
|
||||
return new JpaActionStatusBuilder();
|
||||
|
||||
@@ -36,14 +36,12 @@ import org.eclipse.hawkbit.repository.RolloutStatusCache;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryption;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionSecretsStore;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionService;
|
||||
import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManager;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManagerHolder;
|
||||
@@ -56,7 +54,6 @@ import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoActionCleanup;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoCleanupScheduler;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.CleanupTask;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.cluster.DistributedLockRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.cluster.LockProperties;
|
||||
import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager;
|
||||
@@ -73,7 +70,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
|
||||
@@ -99,8 +96,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||
@@ -300,11 +297,6 @@ public class JpaRepositoryConfiguration {
|
||||
return e -> e instanceof TargetPollEvent && !repositoryProperties.isPublishTargetPollEvent();
|
||||
}
|
||||
|
||||
@Bean
|
||||
TargetBuilder targetBuilder(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
return new JpaTargetBuilder(targetTypeManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param distributionSetManagement for loading {@link Rollout#getDistributionSet()}
|
||||
* @return RolloutBuilder bean
|
||||
@@ -391,7 +383,7 @@ public class JpaRepositoryConfiguration {
|
||||
RolloutExecutor rolloutExecutor(
|
||||
final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository,
|
||||
final RolloutTargetGroupRepository rolloutTargetGroupRepository,
|
||||
final RolloutRepository rolloutRepository, final TargetManagement targetManagement,
|
||||
final RolloutRepository rolloutRepository, final TargetManagement<? extends Target> targetManagement,
|
||||
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||
final RolloutManagement rolloutManagement, final QuotaManagement quotaManagement,
|
||||
final RolloutGroupEvaluationManager evaluationManager, final RolloutApprovalStrategy rolloutApprovalStrategy,
|
||||
@@ -424,8 +416,8 @@ public class JpaRepositoryConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
EntityFactory entityFactory(final TargetBuilder targetBuilder, final RolloutBuilder rolloutBuilder) {
|
||||
return new JpaEntityFactory(targetBuilder, rolloutBuilder);
|
||||
EntityFactory entityFactory(final RolloutBuilder rolloutBuilder) {
|
||||
return new JpaEntityFactory(rolloutBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +456,8 @@ public class JpaRepositoryConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
AutoAssignExecutor autoAssignExecutor(
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement, final TargetManagement targetManagement,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetManagement<? extends Target> targetManagement,
|
||||
final DeploymentManagement deploymentManagement,
|
||||
final PlatformTransactionManager transactionManager, final ContextAware contextAware) {
|
||||
return new AutoAssignChecker(targetFilterQueryManagement, targetManagement, deploymentManagement, transactionManager, contextAware);
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Slf4j
|
||||
public class AutoAssignChecker extends AbstractAutoAssignExecutor {
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
|
||||
/**
|
||||
* Instantiates a new auto assign checker
|
||||
@@ -51,7 +51,7 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
|
||||
*/
|
||||
public AutoAssignChecker(
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final TargetManagement<? extends Target> targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final PlatformTransactionManager transactionManager, final ContextAware contextAware) {
|
||||
super(targetFilterQueryManagement, deploymentManagement, transactionManager, contextAware);
|
||||
this.targetManagement = targetManagement;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link Target}.
|
||||
*/
|
||||
public class JpaTargetBuilder implements TargetBuilder {
|
||||
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
|
||||
public JpaTargetBuilder(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetUpdate update(final String controllerId) {
|
||||
return new JpaTargetUpdate(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetCreate create() {
|
||||
return new JpaTargetCreate(targetTypeManagement);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractTargetUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Create/build implementation.
|
||||
*/
|
||||
public class JpaTargetCreate extends AbstractTargetUpdateCreate<TargetCreate> implements TargetCreate {
|
||||
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
|
||||
JpaTargetCreate(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
super(null);
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaTarget build() {
|
||||
final JpaTarget target = new JpaTarget(controllerId, securityToken);
|
||||
|
||||
if (!ObjectUtils.isEmpty(name)) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
if (targetTypeId != null) {
|
||||
final TargetType targetType = targetTypeManagement.get(targetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
|
||||
target.setTargetType(targetType);
|
||||
}
|
||||
|
||||
target.setDescription(description);
|
||||
target.setAddress(address);
|
||||
target.setUpdateStatus(getStatus().orElse(TargetUpdateStatus.UNKNOWN));
|
||||
getLastTargetQuery().ifPresent(target::setLastTargetQuery);
|
||||
target.setGroup(getGroup().orElse(null));
|
||||
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractTargetUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
|
||||
public class JpaTargetUpdate extends AbstractTargetUpdateCreate<TargetUpdate> implements TargetUpdate {
|
||||
|
||||
JpaTargetUpdate(final String controllerId) {
|
||||
super(controllerId);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
@@ -105,6 +106,7 @@ import org.eclipse.hawkbit.tenancy.configuration.ControllerPollProperties;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.PollingTime;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -666,13 +668,15 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
}
|
||||
|
||||
private Target createTarget(final String controllerId, final URI address, final String name, final String type) {
|
||||
|
||||
log.debug("Creating target for thing ID \"{}\".", controllerId);
|
||||
JpaTarget jpaTarget = (JpaTarget) entityFactory.target().create()
|
||||
.controllerId(controllerId).description("Plug and Play target: " + controllerId)
|
||||
.name((StringUtils.hasText(name) ? name : controllerId)).status(TargetUpdateStatus.REGISTERED)
|
||||
.lastTargetQuery(System.currentTimeMillis())
|
||||
.address(Optional.ofNullable(address).map(URI::toString).orElse(null)).build();
|
||||
final JpaTarget jpaTarget = new JpaTarget();
|
||||
jpaTarget.setControllerId(controllerId);
|
||||
jpaTarget.setDescription("Plug and Play target: " + controllerId);
|
||||
jpaTarget.setName((StringUtils.hasText(name) ? name : controllerId));
|
||||
jpaTarget.setSecurityToken(SecurityTokenGeneratorHolder.getInstance().generateToken());
|
||||
jpaTarget.setUpdateStatus(TargetUpdateStatus.REGISTERED);
|
||||
jpaTarget.setLastTargetQuery(System.currentTimeMillis());
|
||||
jpaTarget.setAddress(Optional.ofNullable(address).map(URI::toString).orElse(null));
|
||||
|
||||
if (StringUtils.hasText(type)) {
|
||||
var targetTypeOptional = getTargetType(type);
|
||||
@@ -770,7 +774,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
@SuppressWarnings("java:S3776") // it's just complex
|
||||
private Target updateTarget(final JpaTarget toUpdate, final URI address, final String name, final String type) {
|
||||
if (isStoreEager(toUpdate, address, name, type) || !queue.offer(new TargetPoll(toUpdate))) {
|
||||
if (isAddressChanged(toUpdate.getAddress(), address)) {
|
||||
if (isAddressChanged(IpUtil.addressToUri(toUpdate.getAddress()), address)) {
|
||||
toUpdate.setAddress(address.toString());
|
||||
}
|
||||
if (isNameChanged(toUpdate.getName(), name)) {
|
||||
@@ -804,16 +808,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
}
|
||||
|
||||
private boolean isStoreEager(final JpaTarget toUpdate, final URI address, final String name, final String type) {
|
||||
return repositoryProperties.isEagerPollPersistence() || isAddressChanged(toUpdate.getAddress(), address)
|
||||
return repositoryProperties.isEagerPollPersistence() || isAddressChanged(IpUtil.addressToUri(toUpdate.getAddress()), address)
|
||||
|| isNameChanged(toUpdate.getName(), name) || isTypeChanged(toUpdate.getTargetType(), type)
|
||||
|| isStatusUnknown(toUpdate.getUpdateStatus());
|
||||
}
|
||||
|
||||
private void handleFinishedCancelation(final JpaActionStatus actionStatus, final JpaAction action) {
|
||||
// in case of successful cancellation we also report the success at
|
||||
// the canceled action itself.
|
||||
actionStatus.addMessage(
|
||||
RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully.");
|
||||
// in case of successful cancellation we also report the success at the canceled action itself.
|
||||
actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished successfully.");
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,16 +41,12 @@ import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
@@ -96,12 +92,12 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Validated
|
||||
@Service
|
||||
@ConditionalOnBooleanProperty(prefix = "hawkbit.jpa", name = { "enabled", "target-management" }, matchIfMissing = true)
|
||||
public class JpaTargetManagement implements TargetManagement {
|
||||
public class JpaTargetManagement
|
||||
extends AbstractJpaRepositoryManagement<JpaTarget, TargetManagement.Create, TargetManagement.Update, TargetRepository, TargetFields>
|
||||
implements TargetManagement<JpaTarget> {
|
||||
|
||||
private final EntityManager entityManager;
|
||||
private final JpaDistributionSetManagement distributionSetManagement;
|
||||
private final QuotaManagement quotaManagement;
|
||||
private final TargetRepository targetRepository;
|
||||
private final TargetTypeRepository targetTypeRepository;
|
||||
private final RolloutGroupRepository rolloutGroupRepository;
|
||||
private final TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
@@ -109,17 +105,17 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
private final TenantAware tenantAware;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
protected JpaTargetManagement(final EntityManager entityManager,
|
||||
protected JpaTargetManagement(
|
||||
final TargetRepository jpaRepository, final EntityManager entityManager,
|
||||
final JpaDistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement,
|
||||
final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository,
|
||||
final TargetTypeRepository targetTypeRepository,
|
||||
final RolloutGroupRepository rolloutGroupRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final TargetTagRepository targetTagRepository,
|
||||
final TenantAware tenantAware) {
|
||||
this.entityManager = entityManager;
|
||||
super(jpaRepository, entityManager);
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.quotaManagement = quotaManagement;
|
||||
this.targetRepository = targetRepository;
|
||||
this.targetTypeRepository = targetTypeRepository;
|
||||
this.rolloutGroupRepository = rolloutGroupRepository;
|
||||
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
||||
@@ -130,39 +126,32 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public long countByAssignedDistributionSet(final long distributionSetId) {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException((distributionSetId));
|
||||
return targetRepository.count(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
|
||||
return jpaRepository.count(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByFilters(final FilterParams filterParams) {
|
||||
final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByInstalledDistributionSet(final long distributionSetId) {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException((distributionSetId));
|
||||
return targetRepository.count(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
|
||||
return jpaRepository.count(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByInstalledOrAssignedDistributionSet(final long distributionSetId) {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException((distributionSetId));
|
||||
return targetRepository.exists(TargetSpecifications.hasInstalledOrAssignedDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByRsql(final String rsql) {
|
||||
return JpaManagementHelper.countBySpec(
|
||||
targetRepository,
|
||||
List.of(RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class)));
|
||||
return jpaRepository.exists(TargetSpecifications.hasInstalledOrAssignedDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByRsqlAndUpdatable(String rsql) {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class));
|
||||
return targetRepository.count(AccessController.Operation.UPDATE, combineWithAnd(specList));
|
||||
return jpaRepository.count(AccessController.Operation.UPDATE, combineWithAnd(specList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,21 +159,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.isCompatibleWithDistributionSetType(distributionSetIdTypeId));
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByRsqlAndCompatibleAndUpdatable(String rsql, Long distributionSetIdTypeId) {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.isCompatibleWithDistributionSetType(distributionSetIdTypeId));
|
||||
return targetRepository.count(AccessController.Operation.UPDATE, combineWithAnd(specList));
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByFailedInRollout(final String rolloutId, final Long dsTypeId) {
|
||||
final List<Specification<JpaTarget>> specList = List.of(TargetSpecifications.failedActionsForRollout(rolloutId));
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -195,48 +176,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return countByRsql(targetFilterQuery.getQuery());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return targetRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target create(final TargetCreate c) {
|
||||
final JpaTargetCreate create = (JpaTargetCreate) c;
|
||||
return targetRepository.save(AccessController.Operation.CREATE, create.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public List<Target> create(final Collection<TargetCreate> targets) {
|
||||
final List<JpaTarget> targetList = targets.stream().map(JpaTargetCreate.class::cast).map(JpaTargetCreate::build).toList();
|
||||
return Collections.unmodifiableList(targetRepository.saveAll(AccessController.Operation.CREATE, targetList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final Collection<Long> ids) {
|
||||
final List<JpaTarget> targets = targetRepository.findAllById(ids);
|
||||
if (targets.size() < ids.size()) {
|
||||
throw new EntityNotFoundException(Target.class, ids,
|
||||
targets.stream().map(Target::getId).filter(id -> !ids.contains(id)).toList());
|
||||
}
|
||||
targetRepository.deleteAll(targets);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void deleteByControllerID(final String controllerId) {
|
||||
targetRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId));
|
||||
jpaRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,7 +190,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
final Long distSetTypeId = jpaDistributionSet.getType().getId();
|
||||
|
||||
return targetRepository
|
||||
return jpaRepository
|
||||
.findAllWithoutCount(
|
||||
AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
@@ -261,7 +206,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
final Long distSetTypeId = jpaDistributionSet.getType().getId();
|
||||
|
||||
return targetRepository.count(
|
||||
return jpaRepository.count(
|
||||
AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
@@ -272,7 +217,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Slice<Target> findByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(
|
||||
final Collection<Long> groups, final String rsql, final DistributionSetType dsType, final Pageable pageable) {
|
||||
return targetRepository
|
||||
return jpaRepository
|
||||
.findAllWithoutCount(AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
@@ -285,7 +230,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(
|
||||
final String rsql, final Collection<Long> groups, final DistributionSetType dsType) {
|
||||
return targetRepository.count(AccessController.Operation.UPDATE,
|
||||
return jpaRepository.count(AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.isNotInRolloutGroups(groups),
|
||||
@@ -297,7 +242,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
TargetSpecifications.failedActionsForRollout(rolloutId),
|
||||
TargetSpecifications.isNotInRolloutGroups(groups));
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,13 +250,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
TargetSpecifications.failedActionsForRollout(rolloutId),
|
||||
TargetSpecifications.isNotInRolloutGroups(groups));
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findByRsqlAndNoOverridingActionsAndNotInRolloutAndCompatibleAndUpdatable(
|
||||
final long rolloutId, final String rsql, final DistributionSetType distributionSetType, final Pageable pageable) {
|
||||
return targetRepository
|
||||
return jpaRepository
|
||||
.findAllWithoutCount(AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
@@ -323,7 +268,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public long countByActionsInRolloutGroup(final long rolloutGroupId) {
|
||||
return targetRepository.count(TargetSpecifications.isInActionRolloutGroup(rolloutGroupId));
|
||||
return jpaRepository.count(TargetSpecifications.isInActionRolloutGroup(rolloutGroupId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,7 +278,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasNoActionInRolloutGroup(group)), pageable);
|
||||
jpaRepository, List.of(TargetSpecifications.hasNoActionInRolloutGroup(group)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -341,7 +286,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository,
|
||||
jpaRepository,
|
||||
List.of(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId())), pageable);
|
||||
}
|
||||
|
||||
@@ -353,28 +298,28 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> getByControllerID(final Collection<String> controllerIDs) {
|
||||
return Collections.unmodifiableList(targetRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs)));
|
||||
public List<Target> getByControllerId(final Collection<String> controllerIDs) {
|
||||
return Collections.unmodifiableList(jpaRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Target> getByControllerID(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId).map(Target.class::cast);
|
||||
public Optional<Target> getByControllerId(final String controllerId) {
|
||||
return jpaRepository.findByControllerId(controllerId).map(Target.class::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target getWithDetails(final String controllerId, final String detailsKey) {
|
||||
return targetRepository.getWithDetailsByControllerId(controllerId, "Target." + detailsKey);
|
||||
return jpaRepository.getWithDetailsByControllerId(controllerId, "Target." + detailsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findByFilters(final FilterParams filterParams, final Pageable pageable) {
|
||||
final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -382,7 +327,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())), pageReq);
|
||||
jpaRepository, List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())), pageReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -393,26 +338,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findByUpdateStatus(final TargetUpdateStatus status, final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasTargetUpdateStatus(status)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findAll(final Pageable pageable) {
|
||||
return targetRepository.findAllWithoutCount(pageable).map(Target.class::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findByRsql(final String rsql, final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(
|
||||
targetRepository,
|
||||
List.of(RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class)), pageable
|
||||
);
|
||||
jpaRepository, List.of(TargetSpecifications.hasTargetUpdateStatus(status)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -421,7 +353,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
|
||||
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(
|
||||
targetRepository, List.of(RsqlUtility.getInstance().buildRsqlSpecification(
|
||||
jpaRepository, List.of(RsqlUtility.getInstance().buildRsqlSpecification(
|
||||
targetFilterQuery.getQuery(), TargetFields.class)), pageable
|
||||
);
|
||||
}
|
||||
@@ -429,7 +361,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Page<Target> findByTag(final long tagId, final Pageable pageable) {
|
||||
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.hasTag(tagId)), pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, List.of(TargetSpecifications.hasTag(tagId)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,7 +372,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.hasTag(tagId));
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -460,7 +392,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
targetsWithoutSameType.forEach(target -> target.setTargetType(type));
|
||||
|
||||
final TargetTypeAssignmentResult result = new TargetTypeAssignmentResult(
|
||||
targetsWithSameType.size(), targetRepository.saveAll(targetsWithoutSameType), Collections.emptyList(), type);
|
||||
targetsWithSameType.size(), jpaRepository.saveAll(targetsWithoutSameType), Collections.emptyList(), type);
|
||||
|
||||
// no reason to persist the type
|
||||
entityManager.detach(type);
|
||||
@@ -481,7 +413,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
// set new target type to null for all targets
|
||||
allTargets.forEach(target -> target.setTargetType(null));
|
||||
|
||||
return new TargetTypeAssignmentResult(0, Collections.emptyList(), targetRepository.saveAll(allTargets), null);
|
||||
return new TargetTypeAssignmentResult(0, Collections.emptyList(), jpaRepository.saveAll(allTargets), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -508,7 +440,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return target;
|
||||
} else {
|
||||
target.addTag(tag);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -535,7 +467,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return updateTag(controllerIds, targetTagId, notFoundHandler, (tag, target) -> {
|
||||
if (target.getTags().contains(tag)) {
|
||||
target.removeTag(tag);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
} else {
|
||||
return target;
|
||||
}
|
||||
@@ -549,7 +481,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Target unassignType(final String controllerId) {
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
|
||||
target.setTargetType(null);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -559,12 +491,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Target assignType(final String controllerId, final Long targetTypeId) {
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
|
||||
|
||||
targetRepository.getAccessController().ifPresent(acm ->
|
||||
jpaRepository.getAccessController().ifPresent(acm ->
|
||||
acm.assertOperationAllowed(AccessController.Operation.UPDATE, target));
|
||||
|
||||
final JpaTargetType targetType = getTargetTypeByIdAndThrowIfNotFound(targetTypeId);
|
||||
target.setTargetType(targetType);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -572,16 +504,16 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
if (withSubgroups) {
|
||||
// search for eq(group) and like(group%)
|
||||
return JpaManagementHelper
|
||||
.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.eqOrSubTargetGroup(group)), pageable);
|
||||
.findAllWithCountBySpec(jpaRepository, List.of(TargetSpecifications.eqOrSubTargetGroup(group)), pageable);
|
||||
} else {
|
||||
return JpaManagementHelper
|
||||
.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.eqTargetGroup(group)), pageable);
|
||||
.findAllWithCountBySpec(jpaRepository, List.of(TargetSpecifications.eqTargetGroup(group)), pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findGroups() {
|
||||
return targetRepository.findDistinctGroups();
|
||||
return jpaRepository.findDistinctGroups();
|
||||
}
|
||||
|
||||
|
||||
@@ -618,40 +550,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target update(final TargetUpdate u) {
|
||||
final JpaTargetUpdate update = (JpaTargetUpdate) u;
|
||||
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(update.getControllerId());
|
||||
|
||||
update.getName().ifPresent(target::setName);
|
||||
update.getDescription().ifPresent(target::setDescription);
|
||||
update.getAddress().ifPresent(target::setAddress);
|
||||
update.getSecurityToken().ifPresent(target::setSecurityToken);
|
||||
if (update.getTargetTypeId() != null) {
|
||||
final TargetType targetType = getTargetTypeByIdAndThrowIfNotFound(update.getTargetTypeId());
|
||||
target.setTargetType(targetType);
|
||||
}
|
||||
|
||||
return targetRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Target> get(final long id) {
|
||||
return targetRepository.findById(id).map(Target.class::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(targetRepository.findAll(TargetSpecifications.hasIdIn(ids)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByControllerId(final String controllerId) {
|
||||
return targetRepository.exists(TargetSpecifications.hasControllerId(controllerId));
|
||||
return jpaRepository.exists(TargetSpecifications.hasControllerId(controllerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -669,7 +570,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
final Specification<JpaTarget> combinedSpecification = Objects
|
||||
.requireNonNull(SpecificationsBuilder.combineWithAnd(specList));
|
||||
return targetRepository.exists(AccessController.Operation.UPDATE, combinedSpecification);
|
||||
return jpaRepository.exists(AccessController.Operation.UPDATE, combinedSpecification);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -689,7 +590,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void requestControllerAttributes(final String controllerId) {
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
|
||||
targetRepository.getAccessController()
|
||||
jpaRepository.getAccessController()
|
||||
.ifPresent(acm -> acm.assertOperationAllowed(AccessController.Operation.UPDATE, target));
|
||||
target.setRequestControllerAttributes(true);
|
||||
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() ->
|
||||
@@ -708,7 +609,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Page<Target> findByControllerAttributesRequested(final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasRequestControllerAttributesTrue()), pageable);
|
||||
jpaRepository, List.of(TargetSpecifications.hasRequestControllerAttributesTrue()), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -725,7 +626,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
metadata.put(key, value);
|
||||
|
||||
targetRepository.save(target);
|
||||
jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -745,7 +646,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
metadata.putAll(md);
|
||||
|
||||
assertMetadataQuota(target.getId(), metadata.size());
|
||||
targetRepository.save(target);
|
||||
jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -771,7 +672,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
throw new EntityNotFoundException("Target metadata", controllerId + ":" + key);
|
||||
}
|
||||
|
||||
targetRepository.save(target);
|
||||
jpaRepository.save(target);
|
||||
}
|
||||
|
||||
private Map<String, String> getMap(final String controllerId, final MapAttribute<JpaTarget, String, String> mapAttribute) {
|
||||
@@ -817,7 +718,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private JpaTarget getByControllerIdAndThrowIfNotFound(final String controllerId) {
|
||||
return targetRepository.getByControllerId(controllerId);
|
||||
return jpaRepository.getByControllerId(controllerId);
|
||||
}
|
||||
|
||||
private JpaTargetType getTargetTypeByIdAndThrowIfNotFound(final long id) {
|
||||
@@ -862,7 +763,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
private List<JpaTarget> findTargetsByInSpecification(final Collection<String> controllerIds, final Specification<JpaTarget> specification) {
|
||||
return ListUtils.partition(new ArrayList<>(controllerIds), Constants.MAX_ENTRIES_IN_STATEMENT).stream()
|
||||
.map(ids -> targetRepository.findAll(TargetSpecifications.hasControllerIdIn(ids).and(specification)))
|
||||
.map(ids -> jpaRepository.findAll(TargetSpecifications.hasControllerIdIn(ids).and(specification)))
|
||||
.flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
@@ -872,10 +773,10 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final JpaTargetTag tag = targetTagRepository.findById(targetTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
|
||||
final List<JpaTarget> targets = controllerIds.size() == 1 ?
|
||||
targetRepository.findByControllerId(controllerIds.iterator().next())
|
||||
jpaRepository.findByControllerId(controllerIds.iterator().next())
|
||||
.map(List::of)
|
||||
.orElseGet(Collections::emptyList) :
|
||||
targetRepository
|
||||
jpaRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithTagsInJoin(controllerIds));
|
||||
if (targets.size() < controllerIds.size()) {
|
||||
final Collection<String> notFound = notFound(controllerIds, targets);
|
||||
@@ -886,7 +787,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
}
|
||||
|
||||
targetRepository.getAccessController()
|
||||
jpaRepository.getAccessController()
|
||||
.ifPresent(acm -> acm.assertOperationAllowed(AccessController.Operation.UPDATE, targets));
|
||||
|
||||
try {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -54,7 +53,6 @@ import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.MapAttributeConverter;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
@@ -101,6 +99,8 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Column(name = "controller_id", length = Target.CONTROLLER_ID_MAX_SIZE, updatable = false, nullable = false)
|
||||
@Size(min = 1, max = Target.CONTROLLER_ID_MAX_SIZE)
|
||||
@NotNull
|
||||
@@ -115,6 +115,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
private String securityToken;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Column(name = "address", length = Target.ADDRESS_MAX_SIZE)
|
||||
@Size(max = Target.ADDRESS_MAX_SIZE)
|
||||
private String address;
|
||||
@@ -212,18 +213,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
|
||||
private List<RolloutTargetGroup> rolloutTargetGroup;
|
||||
|
||||
public JpaTarget(final String controllerId, final String securityToken) {
|
||||
this.controllerId = controllerId;
|
||||
// truncate controller ID to max name length (if too big)
|
||||
setName(controllerId != null && controllerId.length() > NAME_MAX_SIZE ? controllerId.substring(0, NAME_MAX_SIZE) : controllerId);
|
||||
this.securityToken = ObjectUtils.isEmpty(securityToken) ? SecurityTokenGeneratorHolder.getInstance().generateToken() : securityToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControllerId() {
|
||||
return controllerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSecurityToken() {
|
||||
final SystemSecurityContext systemSecurityContext = SystemSecurityContextHolder.getInstance().getSystemSecurityContext();
|
||||
@@ -233,22 +222,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ipAddress
|
||||
*/
|
||||
@Override
|
||||
public URI getAddress() {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return URI.create(address);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
log.warn("Invalid address provided. Cloud not be configured to URI", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled before this method returns {@code null}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.acm;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.CREATE_ROLLOUT;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.READ_REPOSITORY;
|
||||
@@ -27,7 +28,9 @@ import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.AutoAssignDistributionSetUpdate;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignChecker;
|
||||
@@ -59,10 +62,10 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyTargetReadOperations() {
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
final Target hiddenTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
runAs(withUser("user", READ_TARGET + "/controllerId==" + permittedTarget.getControllerId()), () -> {
|
||||
// verify targetManagement#findAll
|
||||
@@ -78,15 +81,15 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
.map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement.getByControllerID(permittedTarget.getControllerId())).isPresent();
|
||||
assertThat(targetManagement.getByControllerId(permittedTarget.getControllerId())).isPresent();
|
||||
final String hiddenTargetControllerId = hiddenTarget.getControllerId();
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerID(hiddenTargetControllerId))
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerId(hiddenTargetControllerId))
|
||||
.as("Missing read permissions for hidden target.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
// verify targetManagement#getByControllerId
|
||||
assertThat(targetManagement
|
||||
.getByControllerID(Arrays.asList(permittedTarget.getControllerId(), hiddenTargetControllerId))
|
||||
.getByControllerId(List.of(permittedTarget.getControllerId(), hiddenTargetControllerId))
|
||||
.stream().map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#get
|
||||
@@ -94,8 +97,8 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.get(hiddenTarget.getId())).isEmpty();
|
||||
|
||||
// verify targetManagement#get
|
||||
assertThat(targetManagement.get(Arrays.asList(permittedTarget.getId(), hiddenTarget.getId())).stream()
|
||||
.map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
final List<Long> withHidden = List.of(permittedTarget.getId(), hiddenTarget.getId());
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> targetManagement.get(withHidden));
|
||||
|
||||
// verify targetManagement#getControllerAttributes
|
||||
assertThat(targetManagement.getControllerAttributes(permittedTarget.getControllerId())).isEmpty();
|
||||
@@ -121,14 +124,14 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyTagFilteringAndManagement() {
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
final Target readOnlyTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
final String readOnlyTargetControllerId = readOnlyTarget.getControllerId();
|
||||
|
||||
final Target hiddenTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device03").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device03").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
final Long myTagId = targetTagManagement.create(TargetTagManagement.Create.builder().name("myTag").build()).getId();
|
||||
|
||||
@@ -200,9 +203,9 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.lock(ds);
|
||||
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
final String hiddenTargetControllerId = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED))
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build())
|
||||
.getControllerId();
|
||||
|
||||
runAs(withUser("user", READ_TARGET + "/controllerId==" + permittedTarget.getControllerId()), () ->
|
||||
@@ -240,9 +243,9 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.lock(secondDs);
|
||||
|
||||
final Target manageableTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
final Target readOnlyTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
runAs(withUser("user",
|
||||
READ_TARGET + "/controllerId==" + manageableTarget.getControllerId() + " or controllerId==" + readOnlyTarget.getControllerId(),
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
@@ -427,7 +428,7 @@ class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest {
|
||||
private void verifyThatTargetsHaveDistributionSetAssignment(final DistributionSet set, final List<Target> targets, final int count) {
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).toList();
|
||||
|
||||
final Slice<Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
final Page<? extends Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
assertThat(targetsAll).as("Count of targets").hasSize(count);
|
||||
|
||||
for (final Target target : targetsAll) {
|
||||
@@ -452,7 +453,7 @@ class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest {
|
||||
private void verifyThatTargetsNotHaveDistributionSetAssignment(final List<Target> targets) {
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).toList();
|
||||
|
||||
final Slice<Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
final Page<? extends Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
|
||||
for (final Target target : targetsAll) {
|
||||
if (targetIds.contains(target.getId())) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
|
||||
@@ -80,7 +81,7 @@ class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void targetUpdateEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = testdataFactory.createTarget("12345");
|
||||
targetManagement.update(entityFactory.target().update(createdTarget.getControllerId()).name("updateName"));
|
||||
targetManagement.update(TargetManagement.Update.builder().id(createdTarget.getId()).name("updateName").build());
|
||||
|
||||
final TargetUpdatedEvent targetUpdatedEvent = eventListener.waitForEvent(TargetUpdatedEvent.class);
|
||||
assertThat(targetUpdatedEvent).isNotNull();
|
||||
|
||||
@@ -749,13 +749,10 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetPollEvent.class, count = 2) })
|
||||
void findOrRegisterTargetIfItDoesNotExistWithExistingTypeAndUpdateToNonExistingType() {
|
||||
createTargetType("knownTargetTypeName");
|
||||
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST,
|
||||
null, "knownTargetTypeName");
|
||||
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST,
|
||||
null, "unknownTargetTypeName");
|
||||
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST, null, "knownTargetTypeName");
|
||||
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST, null, "unknownTargetTypeName");
|
||||
assertThat(target.getId()).as("Target should be the same").isEqualTo(sameTarget.getId());
|
||||
assertThat(sameTarget.getTargetType().getName()).as("Target type should be unchanged")
|
||||
.isEqualTo("knownTargetTypeName");
|
||||
assertThat(sameTarget.getTargetType().getName()).as("Target type should be unchanged").isEqualTo("knownTargetTypeName");
|
||||
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
||||
}
|
||||
|
||||
@@ -1109,7 +1106,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING)));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(actionRepository.findById(action.getId()))
|
||||
.hasValueSatisfying(a -> assertThat(a.getStatus()).isEqualTo(Status.FINISHED));
|
||||
@@ -1141,7 +1138,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING)));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
// however, additional action status has been stored
|
||||
assertThat(actionStatusRepository.findAll(PAGE).getNumberOfElements()).isEqualTo(4);
|
||||
assertThat(controllerManagement.findActionStatusByAction(action.getId(), PAGE).getNumberOfElements()).isEqualTo(4);
|
||||
@@ -1168,7 +1165,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
});
|
||||
|
||||
// verify that audit information has not changed
|
||||
final Target targetVerify = targetManagement.getByControllerID(controllerId).get();
|
||||
final Target targetVerify = targetManagement.getByControllerId(controllerId).get();
|
||||
assertThat(targetVerify.getCreatedBy()).isEqualTo(target.getCreatedBy());
|
||||
assertThat(targetVerify.getCreatedAt()).isEqualTo(target.getCreatedAt());
|
||||
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(target.getLastModifiedBy());
|
||||
@@ -1730,7 +1727,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
testdataFactory.createTarget();
|
||||
assignDistributionSet(dsId, DEFAULT_CONTROLLER_ID);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
return deploymentManagement.findActiveActionsByTarget(DEFAULT_CONTROLLER_ID, PAGE).getContent().get(0).getId();
|
||||
@@ -1740,7 +1737,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet(dsName);
|
||||
final Long dsId = ds.getId();
|
||||
assignDistributionSet(dsId, defaultControllerId, DOWNLOAD_ONLY);
|
||||
assertThat(targetManagement.getByControllerID(defaultControllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.getByControllerId(defaultControllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
final Long id = deploymentManagement.findActiveActionsByTarget(defaultControllerId, PAGE).getContent().get(0).getId();
|
||||
assertThat(id).isNotNull();
|
||||
@@ -1749,7 +1746,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Long assignDs(final Long dsId, final String defaultControllerId, final Action.ActionType actionType) {
|
||||
assignDistributionSet(dsId, defaultControllerId, actionType);
|
||||
assertThat(targetManagement.getByControllerID(defaultControllerId).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(defaultControllerId).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
final Long id = deploymentManagement.findActiveActionsByTarget(defaultControllerId, PAGE).getContent().get(0)
|
||||
@@ -1817,7 +1814,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Long actionId, final String controllerId,
|
||||
final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus,
|
||||
final Action.Status expectedActionStatus, final boolean actionActive) {
|
||||
final TargetUpdateStatus targetStatus = targetManagement.getByControllerID(controllerId).get().getUpdateStatus();
|
||||
final TargetUpdateStatus targetStatus = targetManagement.getByControllerId(controllerId).get().getUpdateStatus();
|
||||
assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus);
|
||||
final Action action = deploymentManagement.findAction(actionId).get();
|
||||
assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus);
|
||||
|
||||
@@ -350,7 +350,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("target has update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
@@ -368,7 +368,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addCancelActionStatus(entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong ds").contains(dsFirst);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
@@ -381,7 +381,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong assigned ds")
|
||||
.contains(dsInstalled);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
@@ -417,7 +417,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong assigned ds").contains(dsSecond);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
@@ -432,7 +432,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712"))
|
||||
.as("wrong installed ds")
|
||||
.contains(dsInstalled);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong target info update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
@@ -449,7 +449,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
Action assigningAction = assignSet(target, ds);
|
||||
@@ -470,7 +470,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong assigned ds")
|
||||
.contains(dsInstalled);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
void forceQuitNotAllowedThrowsException() {
|
||||
final Action action = prepareFinishedUpdate("4712", "installed", true);
|
||||
// verify initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
final Target target = action.getTarget();
|
||||
@@ -1098,23 +1098,24 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actions).as("Actions should be initiated by current user")
|
||||
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
||||
|
||||
final Iterable<Target> allFoundTargets = targetManagement.findAll(PAGE).getContent();
|
||||
final Iterable<? extends Target> allFoundTargets = targetManagement.findAll(PAGE).getContent();
|
||||
|
||||
// get final updated version of targets
|
||||
savedDeployedTargets = targetManagement.getByControllerID(savedDeployedTargets.stream().map(Target::getControllerId).toList());
|
||||
savedDeployedTargets = targetManagement.getByControllerId(savedDeployedTargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets)
|
||||
Assertions.<Target>assertThat(allFoundTargets).as("founded targets are wrong")
|
||||
.containsAll(savedDeployedTargets)
|
||||
.containsAll(savedNakedTargets);
|
||||
assertThat(savedDeployedTargets).as("saved target are wrong").doesNotContain(toArray(savedNakedTargets, Target.class));
|
||||
assertThat(savedNakedTargets).as("saved target are wrong").doesNotContain(toArray(savedDeployedTargets, Target.class));
|
||||
|
||||
for (final Target myt : savedNakedTargets) {
|
||||
final Target t = targetManagement.getByControllerID(myt.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(myt.getControllerId()).get();
|
||||
assertThat(deploymentManagement.countActionsByTarget(t.getControllerId())).as("action should be empty").isZero();
|
||||
}
|
||||
|
||||
for (final Target myt : savedDeployedTargets) {
|
||||
final Target t = targetManagement.getByControllerID(myt.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(myt.getControllerId()).get();
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(t.getControllerId(), PAGE).getContent();
|
||||
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
|
||||
assertThat(t.getUpdateStatus()).as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
@@ -1267,7 +1268,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(dsC.getId());
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should not be null").isNotPresent();
|
||||
assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
}
|
||||
|
||||
@@ -1278,12 +1279,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify, that dsA is deployed correctly
|
||||
for (final Target t_ : updatedTsDsA) {
|
||||
final Target t = targetManagement.getByControllerID(t_.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(t_.getControllerId()).get();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()))
|
||||
.as("assigned ds is wrong").contains(dsA);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds is wrong").contains(dsA);
|
||||
assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId(), PAGE))
|
||||
.as("no actions should be active").isEmpty();
|
||||
@@ -1298,7 +1299,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
findActionsByDistributionSet(pageRequest, dsA.getId()).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerID(deployResWithDsB
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerId(deployResWithDsB
|
||||
.getDeployedTargets().stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").usingElementComparator(controllerIdComparator())
|
||||
@@ -1306,12 +1307,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
|
||||
|
||||
for (final Target t_ : deployed2DS) {
|
||||
final Target t = targetManagement.getByControllerID(t_.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(t_.getControllerId()).get();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId())).as("assigned ds is wrong")
|
||||
.contains(dsA);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should be null").isNotPresent();
|
||||
assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
}
|
||||
@@ -1419,7 +1420,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.toList();
|
||||
implicitLock(dsA);
|
||||
Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get();
|
||||
Target targ = targetManagement.getByControllerId(targs.iterator().next().getControllerId()).get();
|
||||
|
||||
// checking the revisions of the created entities
|
||||
// verifying that the revision of the object and the revision within the
|
||||
@@ -1445,7 +1446,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
|
||||
|
||||
targ = targetManagement.getByControllerID(targ.getControllerId()).get();
|
||||
targ = targetManagement.getByControllerId(targ.getControllerId()).get();
|
||||
|
||||
assertEquals(0, deploymentManagement.findActiveActionsByTarget(targ.getControllerId(), PAGE).getTotalElements(),
|
||||
"active target actions are wrong");
|
||||
@@ -1468,7 +1469,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertEquals(1, deploymentManagement.findActiveActionsByTarget(targ.getControllerId(), PAGE).getTotalElements(),
|
||||
"active actions are wrong");
|
||||
assertEquals(TargetUpdateStatus.PENDING,
|
||||
targetManagement.getByControllerID(targ.getControllerId()).get().getUpdateStatus(),
|
||||
targetManagement.getByControllerId(targ.getControllerId()).get().getUpdateStatus(),
|
||||
"target status is wrong");
|
||||
assertEquals(dsB, deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get(),
|
||||
"wrong assigned ds");
|
||||
@@ -1609,8 +1610,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
||||
for (int i = 0; i < quotaManagement.getMaxTargetDistributionSetAssignmentsPerManualAssignment(); i++) {
|
||||
final Target target = testdataFactory.createTarget("test-target-" + i, "test-target-" + i,
|
||||
targetType.getId());
|
||||
final Target target = testdataFactory.createTarget("test-target-" + i, "test-target-" + i, targetType);
|
||||
final DeploymentRequest deployment = DeploymentManagement
|
||||
.deploymentRequest(target.getControllerId(), ds.getId()).build();
|
||||
deploymentRequests.add(deployment);
|
||||
@@ -1619,8 +1619,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
deploymentManagement.assignDistributionSets(deploymentRequests);
|
||||
implicitLock(ds);
|
||||
|
||||
final List<Target> content = targetManagement.findAll(Pageable.unpaged()).getContent();
|
||||
|
||||
final List<? extends Target> content = targetManagement.findAll(Pageable.unpaged()).getContent();
|
||||
content.stream().map(JpaTarget.class::cast)
|
||||
.forEach(jpaTarget -> assertThat(jpaTarget.getAssignedDistributionSet()).isEqualTo(ds));
|
||||
}
|
||||
@@ -1633,8 +1632,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("test-ds");
|
||||
final TargetType targetType1 = testdataFactory.createTargetType("test-type1", Set.of(ds.getType()));
|
||||
final TargetType targetType2 = testdataFactory.createTargetType("test-type2", Set.of(ds.getType()));
|
||||
final Target target1 = testdataFactory.createTarget("test-target1", "test-target1", targetType1.getId());
|
||||
final Target target2 = testdataFactory.createTarget("test-target2", "test-target2", targetType2.getId());
|
||||
final Target target1 = testdataFactory.createTarget("test-target1", "test-target1", targetType1);
|
||||
final Target target2 = testdataFactory.createTarget("test-target2", "test-target2", targetType2);
|
||||
|
||||
final DeploymentRequest deployment1 = DeploymentManagement.deploymentRequest(target1.getControllerId(), ds.getId()).build();
|
||||
final DeploymentRequest deployment2 = DeploymentManagement.deploymentRequest(target2.getControllerId(), ds.getId()).build();
|
||||
@@ -1660,7 +1659,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("test-ds");
|
||||
final DistributionSetType dsType = testdataFactory.findOrCreateDistributionSetType("test-ds-type", "dsType");
|
||||
final TargetType targetType = testdataFactory.createTargetType("target-type", Set.of(dsType));
|
||||
final Target target = testdataFactory.createTarget("test-target", "test-target", targetType.getId());
|
||||
final Target target = testdataFactory.createTarget("test-target", "test-target", targetType);
|
||||
|
||||
final DeploymentRequest deploymentRequest = DeploymentManagement.deploymentRequest(target.getControllerId(), ds.getId()).build();
|
||||
final List<DeploymentRequest> deploymentRequests = List.of(deploymentRequest);
|
||||
@@ -1676,7 +1675,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
void verifyDSAssignmentFailsForTargetsWithTargetTypesThatAreNotCompatibleWithAnyDs() {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("test-ds");
|
||||
final TargetType emptyTargetType = testdataFactory.createTargetType("target-type", Set.of());
|
||||
final Target targetWithEmptyType = testdataFactory.createTarget("test-target", "test-target", emptyTargetType.getId());
|
||||
final Target targetWithEmptyType = testdataFactory.createTarget("test-target", "test-target", emptyTargetType);
|
||||
|
||||
final DeploymentRequest deploymentRequestWithEmptyType = DeploymentManagement
|
||||
.deploymentRequest(targetWithEmptyType.getControllerId(), ds.getId()).build();
|
||||
@@ -1702,7 +1701,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
implicitLock(ds);
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(target.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId())).as("wrong assigned ds")
|
||||
.contains(ds);
|
||||
|
||||
@@ -717,7 +717,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
implicitLock(ds);
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).orElseThrow().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(target.getControllerId()).orElseThrow().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
final Optional<DistributionSet> assignedDistributionSet = deploymentManagement
|
||||
.getAssignedDistributionSet(target.getControllerId());
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Set;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -90,7 +91,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
targAs = assignTag(targAs, targTagX);
|
||||
|
||||
final Target targSpecialName = targetManagement
|
||||
.update(entityFactory.target().update(targAs.get(0).getControllerId()).name("targ-A-special"));
|
||||
.update(TargetManagement.Update.builder().id(targAs.get(0).getId()).name("targ-A-special").build());
|
||||
|
||||
final String targetDsBIdPref = "targ-B";
|
||||
List<Target> targBs = testdataFactory.createTargets(100, targetDsBIdPref,
|
||||
@@ -134,58 +135,58 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final List<TargetUpdateStatus> both = List.of(TargetUpdateStatus.UNKNOWN, TargetUpdateStatus.PENDING);
|
||||
|
||||
// get final updated version of targets
|
||||
targAs = targetManagement.getByControllerID(targAs.stream().map(Target::getControllerId).toList());
|
||||
targBs = targetManagement.getByControllerID(targBs.stream().map(Target::getControllerId).toList());
|
||||
targCs = targetManagement.getByControllerID(targCs.stream().map(Target::getControllerId).toList());
|
||||
targAs = targetManagement.getByControllerId(targAs.stream().map(Target::getControllerId).toList());
|
||||
targBs = targetManagement.getByControllerId(targBs.stream().map(Target::getControllerId).toList());
|
||||
targCs = targetManagement.getByControllerId(targCs.stream().map(Target::getControllerId).toList());
|
||||
|
||||
// try to find several targets with different filter settings
|
||||
verifyThat1TargetHasNameAndId("targ-A-special", targSpecialName.getControllerId());
|
||||
verifyThatRepositoryContains500Targets();
|
||||
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs);
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.getByControllerID(assignedC).get());
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.getByControllerId(assignedC).get());
|
||||
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
|
||||
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
|
||||
verifyThat3TargetsHaveDSAssigned(setA, targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.getByControllerID(assignedA).get());
|
||||
verifyThat3TargetsHaveDSAssigned(setA, targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.getByControllerId(assignedA).get());
|
||||
List<Target> expected = concat(targAs, targBs, targCs, targDs);
|
||||
expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
expected.removeAll(targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat496TargetsAreInStatusUnknown(unknown, expected);
|
||||
expected = concat(targBs, targCs);
|
||||
expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
expected.removeAll(targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
|
||||
verifyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
|
||||
expected = concat(targAs);
|
||||
expected.remove(targetManagement.getByControllerID(assignedA).get());
|
||||
expected.remove(targetManagement.getByControllerId(assignedA).get());
|
||||
verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected);
|
||||
expected = concat(targBs);
|
||||
expected.remove(targetManagement.getByControllerID(assignedB).get());
|
||||
expected.remove(targetManagement.getByControllerId(assignedB).get());
|
||||
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
|
||||
verifyThat4TargetsAreInStatusPending(pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC, assignedE)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC, assignedE)));
|
||||
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
|
||||
targetManagement.getByControllerID(assignedA).get());
|
||||
targetManagement.getByControllerId(assignedA).get());
|
||||
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.getByControllerID(assignedB).get());
|
||||
targetManagement.getByControllerId(assignedB).get());
|
||||
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat200targetsWithGivenTagAreInStatusPendingOrUnknown(targTagW, both, concat(targBs, targCs));
|
||||
verifyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
|
||||
targetManagement.getByControllerID(installedC).get());
|
||||
verifyThat1TargetHasTypeAndDSAssigned(targetTypeX, setB, targetManagement.getByControllerID(assignedE).get());
|
||||
targetManagement.getByControllerId(installedC).get());
|
||||
verifyThat1TargetHasTypeAndDSAssigned(targetTypeX, setB, targetManagement.getByControllerId(assignedE).get());
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(setA,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(installedSet,
|
||||
targetManagement.getByControllerID(Collections.singletonList(installedC)));
|
||||
targetManagement.getByControllerId(Collections.singletonList(installedC)));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTypeAssigned(targetTypeX, targEs);
|
||||
verifyThat400TargetsContainsGivenTextAndHaveNoTypeAssigned(concat(targAs, targBs, targCs, targDs));
|
||||
|
||||
expected = concat(targBs, targCs);
|
||||
expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
expected.removeAll(targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat198TargetsAreInStatusUnknownAndOverdue(unknown, expected);
|
||||
}
|
||||
|
||||
@@ -201,7 +202,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
assignedtargets = targetManagement.getByControllerID(assignedtargets.stream().map(Target::getControllerId).toList());
|
||||
assignedtargets = targetManagement.getByControllerId(assignedtargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(targetManagement.findByAssignedDistributionSet(assignedSet.getId(), PAGE))
|
||||
.as("Contains the assigned targets").containsAll(assignedtargets)
|
||||
@@ -245,7 +246,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
installedtargets = targetManagement.getByControllerID(installedtargets.stream().map(Target::getControllerId).toList());
|
||||
installedtargets = targetManagement.getByControllerId(installedtargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(targetManagement.findByInstalledDistributionSet(installedSet.getId(), PAGE))
|
||||
.as("Contains the assigned targets").containsAll(installedtargets)
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
@@ -87,15 +89,6 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
assertPermissions(() -> targetManagement.countByRsqlAndCompatible("controllerId==id", 1L), List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void countByRsqlAndCompatibleAndUpdatablePermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.countByRsqlAndCompatibleAndUpdatable("controllerId==id", 1L),
|
||||
List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@@ -117,7 +110,7 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.create(entityFactory.target().create().controllerId("controller").name("name")),
|
||||
assertPermissions(() -> targetManagement.create(Create.builder().controllerId("controller").name("name").build()),
|
||||
List.of(SpPermission.CREATE_TARGET));
|
||||
}
|
||||
|
||||
@@ -126,7 +119,7 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createCollectionPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.create(List.of(entityFactory.target().create().controllerId("controller").name("name"))),
|
||||
assertPermissions(() -> targetManagement.create(List.of(Create.builder().controllerId("controller").name("name").build())),
|
||||
List.of(SpPermission.CREATE_TARGET));
|
||||
}
|
||||
|
||||
@@ -258,15 +251,15 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void getByControllerCollectionIDPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.getByControllerID(List.of("controllerId")), List.of(SpPermission.READ_TARGET));
|
||||
assertPermissions(() -> targetManagement.getByControllerId(List.of("controllerId")), List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void getByControllerIDPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.getByControllerID("controllerId"), List.of(SpPermission.READ_TARGET));
|
||||
void getByControllerIdPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.getByControllerId("controllerId"), List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +409,7 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void updatePermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.update(entityFactory.target().update("controllerId")), List.of(SpPermission.UPDATE_TARGET));
|
||||
assertPermissions(() -> targetManagement.update(Update.builder().id(1L).build()), List.of(SpPermission.UPDATE_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,14 +28,15 @@ import java.util.Set;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.SpRole;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
@@ -77,6 +78,7 @@ import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
@@ -96,7 +98,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
assertThat(targetManagement.getByControllerID(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(targetManagement.getByControllerId(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(targetManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(targetManagement.getMetadata(target.getControllerId()).get(NOT_EXIST_ID)).isNull();
|
||||
}
|
||||
@@ -150,7 +152,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
verifyThrownExceptionBy(() -> targetManagement.unassignTag(List.of(NOT_EXIST_ID), tag.getId()), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.unassignTag(List.of(target.getControllerId()), NOT_EXIST_IDL), "TargetTag");
|
||||
verifyThrownExceptionBy(() -> targetManagement.update(entityFactory.target().update(NOT_EXIST_ID)), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.update(Update.builder().id(NOT_EXIST_IDL).build()), "Target");
|
||||
|
||||
verifyThrownExceptionBy(() -> targetManagement.createMetadata(NOT_EXIST_ID, Map.of("123", "123")), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.deleteMetadata(NOT_EXIST_ID, "xxx"), "Target");
|
||||
@@ -166,7 +168,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void getTargetSecurityTokenOnlyWithCorrectPermission() throws Exception {
|
||||
final Target createdTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token"));
|
||||
.create(Create.builder().controllerId("targetWithSecurityToken").securityToken("token").build());
|
||||
|
||||
// retrieve security token only with READ_TARGET_SEC_TOKEN permission
|
||||
final String securityTokenWithReadPermission = SecurityContextSwitch.getAs(
|
||||
@@ -203,11 +205,9 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void createTargetThatViolatesUniqueConstraintFails() {
|
||||
final TargetCreate targetCreate = entityFactory.target().create().controllerId("123");
|
||||
final Create targetCreate = Create.builder().controllerId("123").build();
|
||||
targetManagement.create(targetCreate);
|
||||
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreate));
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class).isThrownBy(() -> targetManagement.create(targetCreate));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,10 +237,10 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 5) })
|
||||
void assignAndUnassignTargetsToTag() {
|
||||
final List<String> assignTarget = new ArrayList<>();
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId123")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1234")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1235")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1236")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId123").build()).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId1234").build()).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId1235").build()).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId1236").build()).getControllerId());
|
||||
|
||||
final TargetTag targetTag = targetTagManagement.create(TargetTagManagement.Create.builder().name("Tag1").build());
|
||||
|
||||
@@ -273,7 +273,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetDeletedEvent.class, count = 12),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 6) })
|
||||
void deleteAndCreateTargets() {
|
||||
Target target = targetManagement.create(entityFactory.target().create().controllerId("targetId123"));
|
||||
Target target = targetManagement.create(Create.builder().controllerId("targetId123").build());
|
||||
assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1);
|
||||
targetManagement.delete(Collections.singletonList(target.getId()));
|
||||
assertThat(targetManagement.count()).as("target count is wrong").isZero();
|
||||
@@ -287,7 +287,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Long> targets = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
target = targetManagement.create(entityFactory.target().create().controllerId("" + i));
|
||||
target = targetManagement.create(Create.builder().controllerId("" + i).build());
|
||||
targets.add(target.getId());
|
||||
targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId());
|
||||
}
|
||||
@@ -312,7 +312,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
|
||||
@Expect(type = TargetAttributesRequestedEvent.class, count = 1),
|
||||
@Expect(type = TargetPollEvent.class, count = 1) })
|
||||
void findTargetByControllerIDWithDetails() {
|
||||
void findTargetByControllerIdWithDetails() {
|
||||
final DistributionSet testDs1 = testdataFactory.createDistributionSet("test");
|
||||
final DistributionSet testDs2 = testdataFactory.createDistributionSet("test2");
|
||||
|
||||
@@ -342,7 +342,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(testDs2.getId(), "4711");
|
||||
implicitLock(testDs2);
|
||||
|
||||
Target target = targetManagement.getByControllerID("4711").orElseThrow(IllegalStateException::new);
|
||||
Target target = targetManagement.getByControllerId("4711").orElseThrow(IllegalStateException::new);
|
||||
// read data
|
||||
|
||||
assertThat(targetManagement.countByAssignedDistributionSet(testDs1.getId())).as("Target count is wrong")
|
||||
@@ -386,7 +386,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void createTargetDuplicate() {
|
||||
final TargetCreate targetCreate = entityFactory.target().create().controllerId("4711");
|
||||
final Create targetCreate = Create.builder().controllerId("4711").build();
|
||||
targetManagement.create(targetCreate);
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||
.as("Target already exists")
|
||||
@@ -414,23 +414,18 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
Awaitility.await().until(() -> System.currentTimeMillis() > createdAt + 1);
|
||||
|
||||
savedTarget = targetManagement.update(
|
||||
entityFactory.target().update(savedTarget.getControllerId()).description("changed description"));
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
savedTarget = targetManagement.update(Update.builder().id(savedTarget.getId()).description("changed description").build());
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt").isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt").isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
modifiedAt = savedTarget.getLastModifiedAt();
|
||||
|
||||
final Target foundTarget = targetManagement.getByControllerID(savedTarget.getControllerId())
|
||||
final Target foundTarget = targetManagement.getByControllerId(savedTarget.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(foundTarget).as("The target should not be null").isNotNull();
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
|
||||
.isEqualTo(foundTarget.getControllerId());
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId").isEqualTo(foundTarget.getControllerId());
|
||||
assertThat(savedTarget).as("Target compared with saved target").isEqualTo(foundTarget);
|
||||
assertThat(createdAt).as("CreatedAt compared with saved createdAt").isEqualTo(foundTarget.getCreatedAt());
|
||||
assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(foundTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt").isEqualTo(foundTarget.getLastModifiedAt());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,7 +439,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetDeletedEvent.class, count = 51) })
|
||||
void bulkTargetCreationAndDelete() {
|
||||
final String myCtrlID = "myCtrlID";
|
||||
List<Target> firstList = testdataFactory.createTargets(100, myCtrlID, "first description");
|
||||
List<? extends Target> firstList = testdataFactory.createTargets(100, myCtrlID, "first description");
|
||||
|
||||
final Target extra = testdataFactory.createTarget("myCtrlID-00081XX");
|
||||
|
||||
@@ -459,7 +454,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// lastModifiedAt
|
||||
firstList = firstList.stream()
|
||||
.map(t -> targetManagement.update(
|
||||
entityFactory.target().update(t.getControllerId()).name(t.getName().concat("\tchanged"))))
|
||||
Update.builder().id(t.getId()).name(t.getName().concat("\tchanged")).build()))
|
||||
.toList();
|
||||
|
||||
// verify that all entries are found
|
||||
@@ -490,17 +485,17 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.deleteByControllerID(extra.getControllerId());
|
||||
|
||||
final int numberToDelete = 50;
|
||||
final Collection<Target> targetsToDelete = firstList.subList(0, numberToDelete);
|
||||
final Collection<? extends Target> targetsToDelete = firstList.subList(0, numberToDelete);
|
||||
final Target[] deletedTargets = toArray(targetsToDelete, Target.class);
|
||||
final List<Long> targetsIdsToDelete = targetsToDelete.stream().map(Target::getId).toList();
|
||||
|
||||
targetManagement.delete(targetsIdsToDelete);
|
||||
|
||||
final List<Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent();
|
||||
final List<? extends Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent();
|
||||
assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of split list")
|
||||
.isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown());
|
||||
|
||||
assertThat(targetsLeft).as("Not all undeleted found").doesNotContain(deletedTargets);
|
||||
Assertions.<Target>assertThat(targetsLeft).as("Not all undeleted found").doesNotContain(deletedTargets);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,14 +518,14 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<? extends TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Collections.singletonList(t2.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t11 = targetManagement.getByControllerID(t1.getControllerId())
|
||||
final Target t11 = targetManagement.getByControllerId(t1.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).doesNotContain(toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.getByControllerID(t2.getControllerId())
|
||||
final Target t21 = targetManagement.getByControllerId(t2.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(getTargetTags(t21.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).containsAll(t2Tags);
|
||||
@@ -707,7 +702,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.findOrRegisterTargetIfItDoesNotExist(knownTargetControllerId, new URI("http://127.0.0.1"));
|
||||
|
||||
SecurityContextSwitch.getAs(SecurityContextSwitch.withUser("bumlux", "READ_TARGET"), () -> {
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownTargetControllerId)
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownTargetControllerId)
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(findTargetByControllerID).isNotNull();
|
||||
assertThat(findTargetByControllerID.getPollStatus()).isNotNull();
|
||||
@@ -729,7 +724,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
testdataFactory.createTargets(25, "target-id-B", "first description");
|
||||
|
||||
final Slice<Target> foundTargets = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final Page<? extends Target> foundTargets = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final long foundTargetsCount = targetManagement.countByRsql(rsqlFilter);
|
||||
|
||||
assertThat(targetManagement.count()).as("Total targets").isEqualTo(50L);
|
||||
@@ -749,8 +744,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget("test" + i);
|
||||
}
|
||||
|
||||
final List<Target> foundDs = targetManagement.get(searchIds);
|
||||
|
||||
final List<? extends Target> foundDs = targetManagement.get(searchIds);
|
||||
assertThat(foundDs).hasSize(3);
|
||||
|
||||
final List<Long> collect = foundDs.stream().map(Target::getId).toList();
|
||||
@@ -769,7 +763,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownControllerId)).isFalse();
|
||||
|
||||
targetManagement.requestControllerAttributes(knownControllerId);
|
||||
final Target updated = targetManagement.getByControllerID(knownControllerId).get();
|
||||
final Target updated = targetManagement.getByControllerId(knownControllerId).get();
|
||||
|
||||
assertThat(target.isRequestControllerAttributes()).isFalse();
|
||||
assertThat(targetManagement.findByControllerAttributesRequested(PAGE).getContent()).contains(updated);
|
||||
@@ -892,7 +886,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<? extends TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 2);
|
||||
assertThat(targetTypes).hasSize(2);
|
||||
// create a target
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetTypes.get(0).getId());
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetTypes.get(0));
|
||||
// initial opt lock revision must be one
|
||||
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound).isPresent();
|
||||
@@ -900,8 +894,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetFound.get().getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
|
||||
// update the target type
|
||||
final TargetUpdate targetUpdate = entityFactory.target().update(target.getControllerId())
|
||||
.targetType(targetTypes.get(1).getId());
|
||||
final Update targetUpdate = Update.builder().id(target.getId()).targetType(targetTypes.get(1)).build();
|
||||
targetManagement.update(targetUpdate);
|
||||
|
||||
// opt lock revision must be changed
|
||||
@@ -1033,7 +1026,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetType targetType = testdataFactory.findOrCreateTargetType("targettype");
|
||||
assertThat(targetType).isNotNull();
|
||||
// create a target
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetType.getId());
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetType);
|
||||
// initial opt lock revision must be one
|
||||
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound).isPresent();
|
||||
@@ -1089,7 +1082,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String controllerId2 = "target2";
|
||||
createTargetWithMetadata(controllerId1, 2);
|
||||
final TargetType type = testdataFactory.createTargetType("type1", Set.of());
|
||||
createTargetWithTargetTypeAndMetadata(controllerId2, type.getId(), 2);
|
||||
createTargetWithTargetTypeAndMetadata(controllerId2, type, 2);
|
||||
|
||||
assertThat(targetManagement.count()).as("Total targets").isEqualTo(2);
|
||||
|
||||
@@ -1148,7 +1141,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void matchesFilterWrongType() {
|
||||
final TargetType type = testdataFactory.createTargetType("type", Set.of());
|
||||
final Target target = testdataFactory.createTarget("target", "target", type.getId());
|
||||
final Target target = testdataFactory.createTarget("target", "target", type);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||
|
||||
assertThat(targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(target.getControllerId(),
|
||||
@@ -1263,155 +1256,138 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidDescription(final Target target) {
|
||||
final TargetCreate targetCreateTooLong = entityFactory.target().create().controllerId("a")
|
||||
.description(randomString(513));
|
||||
final Create targetCreateTooLong = Create.builder().controllerId("a").description(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long description should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLong));
|
||||
|
||||
final TargetCreate targetCreateInvalidHtml = entityFactory.target().create().controllerId("a").description(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvalidHtml = Create.builder().controllerId("a").description(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateTooLong = entityFactory.target().update(target.getControllerId())
|
||||
.description(randomString(513));
|
||||
final Update targetUpdateTooLong = Update.builder().id(target.getId()).description(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long description should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateTooLong));
|
||||
|
||||
final TargetUpdate targetUpdateInvalidHtml = entityFactory.target().update(target.getControllerId()).description(INVALID_TEXT_HTML);
|
||||
final Update targetUpdateInvalidHtml = Update.builder().id(target.getId()).description(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateInvalidHtml));
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidName(final Target target) {
|
||||
final TargetCreate targetCreateTooLong = entityFactory.target().create().controllerId("a")
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
|
||||
final Create targetCreateTooLong = Create.builder().controllerId("a").name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long name should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLong));
|
||||
|
||||
final TargetCreate targetCreateInvalidHtml = entityFactory.target().create().controllerId("a").name(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvalidHtml = Create.builder().controllerId("a").name(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateTooLong = entityFactory.target().update(target.getControllerId())
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
|
||||
final Update targetUpdateTooLong = Update.builder().id(target.getId()).name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateTooLong));
|
||||
|
||||
final TargetUpdate targetUpdateInvalidHtml = entityFactory.target().update(target.getControllerId()).name(INVALID_TEXT_HTML);
|
||||
final Update targetUpdateInvalidHtml = Update.builder().id(target.getId()).name(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateEmpty = entityFactory.target().update(target.getControllerId()).name("");
|
||||
final Update targetUpdateEmpty = Update.builder().id(target.getId()).name("").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too short name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateEmpty));
|
||||
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidSecurityToken(final Target target) {
|
||||
final TargetCreate targetCreateTooLong = entityFactory.target().create().controllerId("a")
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1));
|
||||
final Create targetCreateTooLong = Create.builder()
|
||||
.controllerId("a").securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long token should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLong));
|
||||
|
||||
final TargetCreate targetCreateInvalidTextHtml = entityFactory.target().create().controllerId("a").securityToken(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvalidTextHtml = Create.builder().controllerId("a").securityToken(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvalidTextHtml));
|
||||
|
||||
final TargetUpdate targetUpdateTooLong = entityFactory.target().update(target.getControllerId())
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1));
|
||||
final Update targetUpdateTooLong = Update.builder().id(target.getId())
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateTooLong));
|
||||
|
||||
final TargetUpdate targetUpdateInvalidHtml = entityFactory.target().update(target.getControllerId()).securityToken(INVALID_TEXT_HTML);
|
||||
final Update targetUpdateInvalidHtml = Update.builder().id(target.getId()).securityToken(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateEmpty = entityFactory.target().update(target.getControllerId()).securityToken("");
|
||||
final Update targetUpdateEmpty = Update.builder().id(target.getId()).securityToken("").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too short token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateEmpty));
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidAddress(final Target target) {
|
||||
final TargetCreate targetCreate = entityFactory.target().create().controllerId("a").address(randomString(513));
|
||||
final Create targetCreate = Create.builder().controllerId("a").address(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long address should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreate));
|
||||
|
||||
final TargetCreate targetCreate2 = entityFactory.target().create().controllerId("a");
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid should not be created")
|
||||
.isThrownBy(() -> targetCreate2.address(INVALID_TEXT_HTML));
|
||||
|
||||
final TargetUpdate targetUpdate = entityFactory.target().update(target.getControllerId()).address(randomString(513));
|
||||
final Update targetUpdate = Update.builder().id(target.getId()).address(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long address should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdate));
|
||||
|
||||
final TargetUpdate targetUpdate2 = entityFactory.target().update(target.getControllerId());
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid address should not be updated")
|
||||
.isThrownBy(() -> targetUpdate2.address(INVALID_TEXT_HTML));
|
||||
}
|
||||
|
||||
private void createTargetWithInvalidControllerId() {
|
||||
final TargetCreate targetCreateEmpty = entityFactory.target().create().controllerId("");
|
||||
final Create targetCreateEmpty = Create.builder().controllerId("").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with empty controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateEmpty));
|
||||
|
||||
final TargetCreate targetCreateNull = entityFactory.target().create().controllerId(null);
|
||||
final Create targetCreateNull = Create.builder().controllerId(null).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with null controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateNull));
|
||||
|
||||
final TargetCreate targetCreateTooLongControllerId = entityFactory.target().create()
|
||||
.controllerId(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1));
|
||||
final Create targetCreateTooLongControllerId = Create.builder()
|
||||
.controllerId(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLongControllerId));
|
||||
|
||||
final TargetCreate targetCreateInvaidTextHtml = entityFactory.target().create().controllerId(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvaidTextHtml = Create.builder().controllerId(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvaidTextHtml));
|
||||
|
||||
final TargetCreate targetCreateEmptyTrim = entityFactory.target().create().controllerId(" ");
|
||||
final Create targetCreateEmptyTrim = Create.builder().controllerId(" ").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateEmptyTrim));
|
||||
|
||||
final TargetCreate targetCreateContainingSpace = entityFactory.target().create().controllerId("a b");
|
||||
final Create targetCreateContainingSpace = Create.builder().controllerId("a b").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateContainingSpace));
|
||||
|
||||
final TargetCreate targetCreateEmptyTrim2 = entityFactory.target().create().controllerId(" ");
|
||||
final Create targetCreateEmptyTrim2 = Create.builder().controllerId(" ").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateEmptyTrim2));
|
||||
|
||||
final TargetCreate targetCreateContainingSpaces = entityFactory.target().create().controllerId("aaa bbb");
|
||||
final Create targetCreateContainingSpaces = Create.builder().controllerId("aaa bbb").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateContainingSpaces));
|
||||
|
||||
}
|
||||
|
||||
private Target createTargetWithAttributes(final String controllerId) {
|
||||
final Map<String, String> testData = new HashMap<>();
|
||||
testData.put("test1", "testdata1");
|
||||
|
||||
targetManagement.create(entityFactory.target().create().controllerId(controllerId));
|
||||
targetManagement.create(Create.builder().controllerId(controllerId).build());
|
||||
final Target target = controllerManagement.updateControllerAttributes(controllerId, testData, null);
|
||||
|
||||
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong").isEqualTo(testData);
|
||||
@@ -1448,7 +1424,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void checkTargetHasNotTags(final Iterable<Target> targets, final TargetTag... tags) {
|
||||
for (final Target tl : targets) {
|
||||
targetManagement.getByControllerID(tl.getControllerId()).get();
|
||||
targetManagement.getByControllerId(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : getTargetTags(tl.getControllerId())) {
|
||||
@@ -1485,8 +1461,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
return target;
|
||||
}
|
||||
|
||||
private Target createTargetWithTargetTypeAndMetadata(final String controllerId, final long targetTypeId, final int count) {
|
||||
final Target target = testdataFactory.createTarget(controllerId, controllerId, targetTypeId);
|
||||
private Target createTargetWithTargetTypeAndMetadata(final String controllerId, final TargetType targetType, final int count) {
|
||||
final Target target = testdataFactory.createTarget(controllerId, controllerId, targetType);
|
||||
|
||||
for (int index = 1; index <= count; index++) {
|
||||
insertMetadata("key" + index, controllerId + "-value" + index, target);
|
||||
@@ -1514,7 +1490,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void validateFoundTargetsByRsql(final String rsqlFilter, final String... controllerIds) {
|
||||
final Slice<Target> foundTargetsByMetadataAndControllerId = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final Page<? extends Target> foundTargetsByMetadataAndControllerId = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final long foundTargetsByMetadataAndControllerIdCount = targetManagement.countByRsql(rsqlFilter);
|
||||
|
||||
assertThat(foundTargetsByMetadataAndControllerId.getNumberOfElements())
|
||||
|
||||
@@ -133,7 +133,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
List<Target> result = assignTag(groupA, tag);
|
||||
assertThat(result)
|
||||
.containsAll(
|
||||
targetManagement.getByControllerID(groupA.stream().map(Target::getControllerId).toList()))
|
||||
targetManagement.getByControllerId(groupA.stream().map(Target::getControllerId).toList()))
|
||||
.size().isEqualTo(20);
|
||||
assertThat(targetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream().map(Target::getControllerId).sorted()
|
||||
.toList())
|
||||
@@ -144,7 +144,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
result = assignTag(groupAB, tag);
|
||||
assertThat(result)
|
||||
.containsAll(
|
||||
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
targetManagement.getByControllerId(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
.size().isEqualTo(40);
|
||||
assertThat(targetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream().map(Target::getControllerId).sorted()
|
||||
.toList())
|
||||
@@ -153,7 +153,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
// toggle A+B -> both unassigned
|
||||
result = unassignTag(groupAB, tag);
|
||||
assertThat(result)
|
||||
.containsAll(targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
.containsAll(targetManagement.getByControllerId(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
.size().isEqualTo(40);
|
||||
assertThat(targetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent()).isEmpty();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.EntityInterceptor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
@@ -59,7 +60,7 @@ class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target targetToBeCreated = testdataFactory.createTarget("targetToBeCreated");
|
||||
|
||||
final Target loadedTarget = targetManagement.getByControllerID(targetToBeCreated.getControllerId()).get();
|
||||
final Target loadedTarget = targetManagement.getByControllerId(targetToBeCreated.getControllerId()).get();
|
||||
assertThat(postLoadEntityListener.getEntity()).isNotNull();
|
||||
assertThat(postLoadEntityListener.getEntity()).isEqualTo(loadedTarget);
|
||||
}
|
||||
@@ -105,9 +106,8 @@ class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void executeUpdateAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
final Target updateTarget = targetManagement.update(
|
||||
entityFactory.target()
|
||||
.update(addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated").getControllerId())
|
||||
.name("New"));
|
||||
Update.builder().id(addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated").getId())
|
||||
.name("New").build());
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(updateTarget);
|
||||
|
||||
@@ -13,6 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
@@ -39,8 +40,7 @@ class RsqlActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
@BeforeEach
|
||||
void setupBeforeTest() {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("daA");
|
||||
target = (JpaTarget) targetManagement
|
||||
.create(entityFactory.target().create().controllerId("targetId123").description("targetId123"));
|
||||
target = (JpaTarget) targetManagement.create(Create.builder().controllerId("targetId123").description("targetId123").build());
|
||||
|
||||
action = newJpaAction(dsA, false, null);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
@@ -31,7 +32,7 @@ import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* Feature: Component Tests - Repository<br/>
|
||||
@@ -67,20 +68,14 @@ class RsqlTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
targetTagManagement.create(TargetTagManagement.Create.builder().name("Tag4").build());
|
||||
|
||||
target = targetManagement.create(
|
||||
entityFactory.target().create()
|
||||
.controllerId("targetId123")
|
||||
.name("targetName123")
|
||||
.description("targetDesc123"));
|
||||
Create.builder().controllerId("targetId123").name("targetName123").description("targetDesc123").build());
|
||||
target = controllerManagement.updateControllerAttributes(target.getControllerId(), Map.of("revision", "1.1"), null);
|
||||
target = controllerManagement.findOrRegisterTargetIfItDoesNotExist(target.getControllerId(), LOCALHOST);
|
||||
targetManagement.createMetadata(target.getControllerId(), Map.of("metaKey", "metaValue"));
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
targetManagement.assignType(target.getControllerId(), targetType1.getId());
|
||||
|
||||
target2 = targetManagement.create(
|
||||
entityFactory.target().create()
|
||||
.controllerId("targetId1234")
|
||||
.description("targetId1234"));
|
||||
target2 = targetManagement.create(Create.builder().controllerId("targetId1234").description("targetId1234").build());
|
||||
target2 = controllerManagement.updateControllerAttributes(target2.getControllerId(), Map.of("revision", "1.2"), null);
|
||||
targetManagement.assignType(target2.getControllerId(), targetType2.getId());
|
||||
targetManagement.createMetadata(target2.getControllerId(), Map.of("metaKey", "value"));
|
||||
@@ -435,7 +430,7 @@ class RsqlTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsql, final long expectedTargets) {
|
||||
final Slice<Target> findTargetPage = targetManagement.findByRsql(rsql, PAGE);
|
||||
final Page<? extends Target> findTargetPage = targetManagement.findByRsql(rsql, PAGE);
|
||||
assertThat(findTargetPage).isNotNull();
|
||||
assertThat(findTargetPage.getNumberOfElements()).isEqualTo(expectedTargets);
|
||||
assertThat(targetManagement.countByRsql(rsql)).isEqualTo(expectedTargets);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
/**
|
||||
@@ -53,10 +54,10 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
createTargetForTenant(knownControllerId, anotherTenant);
|
||||
|
||||
// ensure both tenants see their target
|
||||
final Slice<Target> findTargetsForTenant = findTargetsForTenant(tenant);
|
||||
final Page<? extends Target> findTargetsForTenant = findTargetsForTenant(tenant);
|
||||
assertThat(findTargetsForTenant).hasSize(1);
|
||||
assertThat(findTargetsForTenant.getContent().get(0).getTenant().toUpperCase()).isEqualTo(tenant.toUpperCase());
|
||||
final Slice<Target> findTargetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
final Page<? extends Target> findTargetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(findTargetsForAnotherTenant).hasSize(1);
|
||||
assertThat(findTargetsForAnotherTenant.getContent().get(0).getTenant().toUpperCase())
|
||||
.isEqualTo(anotherTenant.toUpperCase());
|
||||
@@ -74,12 +75,12 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
createTargetForTenant(controllerAnotherTenant, anotherTenant);
|
||||
|
||||
// find all targets for current tenant "mytenant"
|
||||
final Slice<Target> findTargetsAll = targetManagement.findAll(PAGE);
|
||||
final Page<? extends Target> findTargetsAll = targetManagement.findAll(PAGE);
|
||||
// no target has been created for "mytenant"
|
||||
assertThat(findTargetsAll).isEmpty();
|
||||
|
||||
// find all targets for anotherTenant
|
||||
final Slice<Target> findTargetsForTenant = findTargetsForTenant(anotherTenant);
|
||||
final Page<? extends Target> findTargetsForTenant = findTargetsForTenant(anotherTenant);
|
||||
// another tenant should have targets
|
||||
assertThat(findTargetsForTenant).hasSize(1);
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
// ok
|
||||
}
|
||||
|
||||
Slice<Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
Page<? extends Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(targetsForAnotherTenant).hasSize(1);
|
||||
|
||||
// ensure another tenant can delete the target
|
||||
@@ -184,7 +185,7 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
return runAsTenant(tenant, () -> testdataFactory.createTarget(controllerId));
|
||||
}
|
||||
|
||||
private Slice<Target> findTargetsForTenant(final String tenant) throws Exception {
|
||||
private Page<? extends Target> findTargetsForTenant(final String tenant) throws Exception {
|
||||
return runAsTenant(tenant, () -> targetManagement.findAll(PAGE));
|
||||
}
|
||||
|
||||
@@ -195,8 +196,8 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
private DistributionSet createDistributionSetForTenant(final String tenant) throws Exception {
|
||||
return runAsTenant(tenant, () -> testdataFactory.createDistributionSet());
|
||||
private void createDistributionSetForTenant(final String tenant) throws Exception {
|
||||
runAsTenant(tenant, () -> testdataFactory.createDistributionSet());
|
||||
}
|
||||
|
||||
private Slice<? extends DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user