20250828 cleanup (#2639)

* Cleanup

* Refactor artifact management
This commit is contained in:
Avgustin Marinov
2025-09-02 16:08:14 +03:00
committed by GitHub
parent 4f0a8893c7
commit 2a636328a0
305 changed files with 2253 additions and 4566 deletions

View File

@@ -13,8 +13,8 @@ import java.io.InputStream;
import jakarta.servlet.http.HttpServletRequest;
import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNoLongerExistsException;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
import org.eclipse.hawkbit.artifact.exception.ArtifactBinaryNoLongerExistsException;
import org.eclipse.hawkbit.artifact.model.ArtifactStream;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
@@ -38,7 +38,8 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
private final ArtifactManagement artifactManagement;
public MgmtDownloadArtifactResource(final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement, final ArtifactManagement artifactManagement) {
public MgmtDownloadArtifactResource(final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
final ArtifactManagement artifactManagement) {
this.softwareModuleManagement = softwareModuleManagement;
this.artifactManagement = artifactManagement;
}
@@ -60,7 +61,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
final Artifact artifact = module.getArtifact(artifactId)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId));
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted());
final ArtifactStream file = artifactManagement.getArtifactStream(artifact.getSha1Hash(), module.getId(), module.isEncrypted());
final HttpServletRequest request = RequestResponseContextHolder.getHttpServletRequest();
final String ifMatch = request.getHeader(HttpHeaders.IF_MATCH);
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {

View File

@@ -106,10 +106,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
@Override
public ResponseEntity<MgmtRolloutResponseBody> getRollout(final Long rolloutId) {
final Rollout findRolloutById = rolloutManagement.getWithDetailedStatus(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
return ResponseEntity.ok(MgmtRolloutMapper.toResponseRollout(findRolloutById, true));
return ResponseEntity.ok(MgmtRolloutMapper.toResponseRollout(rolloutManagement.getWithDetailedStatus(rolloutId), true));
}
@Override
@@ -238,8 +235,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
public ResponseEntity<MgmtRolloutGroupResponseBody> getRolloutGroup(final Long rolloutId, final Long groupId) {
findRolloutOrThrowException(rolloutId);
final RolloutGroup rolloutGroup = rolloutGroupManagement.getWithDetailedStatus(groupId)
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutId));
final RolloutGroup rolloutGroup = rolloutGroupManagement.getWithDetailedStatus(groupId);
if (!Objects.equals(rolloutId, rolloutGroup.getRollout().getId())) {
throw new EntityNotFoundException(RolloutGroup.class, groupId);
}
@@ -273,8 +269,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
@Override
public ResponseEntity<MgmtRolloutResponseBody> retryRollout(final Long rolloutId) {
final Rollout rolloutForRetry = rolloutManagement.find(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
final Rollout rolloutForRetry = rolloutManagement.get(rolloutId);
if (rolloutForRetry.isDeleted()) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
}

View File

@@ -22,7 +22,6 @@ import java.util.Optional;
import jakarta.validation.ValidationException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
import org.eclipse.hawkbit.audit.AuditLog;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
@@ -39,6 +38,8 @@ import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.artifact.model.ArtifactHashes;
import org.eclipse.hawkbit.artifact.urlresolver.ArtifactUrlResolver;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.ArtifactUpload;
@@ -65,7 +66,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
private final ArtifactManagement artifactManagement;
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
private final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement;
private final ArtifactUrlHandler artifactUrlHandler;
private final ArtifactUrlResolver artifactUrlHandler;
private final MgmtSoftwareModuleMapper mgmtSoftwareModuleMapper;
private final SystemManagement systemManagement;
@@ -73,7 +74,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final ArtifactManagement artifactManagement,
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement,
final ArtifactUrlHandler artifactUrlHandler,
final ArtifactUrlResolver artifactUrlHandler,
final MgmtSoftwareModuleMapper mgmtSoftwareModuleMapper,
final SystemManagement systemManagement) {
this.artifactManagement = artifactManagement;
@@ -98,14 +99,17 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
try (final InputStream in = file.getInputStream()) {
final Artifact result = artifactManagement.create(new ArtifactUpload(in, softwareModuleId, fileName,
md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(),
sha256Sum == null ? null : sha256Sum.toLowerCase(), false, file.getContentType(), file.getSize()));
final Artifact result = artifactManagement.create(new ArtifactUpload(
in, file.getContentType(), file.getSize(),
new ArtifactHashes(
sha1Sum == null ? null : sha1Sum.toLowerCase(),
md5Sum == null ? null : md5Sum.toLowerCase(),
sha256Sum == null ? null : sha256Sum.toLowerCase()),
softwareModuleId, fileName, false));
final MgmtArtifact reponse = MgmtSoftwareModuleMapper.toResponse(result);
MgmtSoftwareModuleMapper.addLinks(result, reponse);
return ResponseEntity.status(HttpStatus.CREATED).body(reponse);
final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(result);
MgmtSoftwareModuleMapper.addLinks(result, response);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
} catch (final IOException e) {
log.error("Failed to store artifact", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);

View File

@@ -20,8 +20,8 @@ import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemStatistics
import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemTenantServiceUsage;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemManagementRestApi;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.report.model.SystemUsageReportWithTenants;
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
import org.eclipse.hawkbit.repository.model.report.SystemUsageReportWithTenants;
import org.eclipse.hawkbit.repository.model.report.TenantUsage;
import org.springframework.cache.CacheManager;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;

View File

@@ -108,7 +108,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<MgmtTarget> getTarget(final String targetId) {
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
final Target findTarget = targetManagement.getByControllerId(targetId);
// to single response include poll status
final MgmtTarget response = MgmtTargetMapper.toResponse(findTarget, tenantConfigHelper, null);
MgmtTargetMapper.addTargetLinks(response);
@@ -142,11 +142,10 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
@AuditLog(entity = "Target", type = AuditLog.Type.UPDATE, description = "Update Target")
public ResponseEntity<MgmtTarget> updateTarget(final String targetId, final MgmtTargetRequestBody targetRest) {
if (targetRest.getRequestAttributes() != null && !Boolean.TRUE.equals(targetRest.getRequestAttributes())) {
if (targetRest.getRequestAttributes() != null && !targetRest.getRequestAttributes()) {
return ResponseEntity.badRequest().build();
}
final Target targetToUpdate = targetManagement.getByControllerId(targetId)
.orElseThrow(() -> new EntityNotFoundException(Target.class, targetId));
final Target targetToUpdate = targetManagement.getByControllerId(targetId);
final TargetType targetType = Optional.ofNullable(targetRest.getTargetType())
.map(targetTypeId -> {
if (targetTypeId == -1L) {
@@ -211,7 +210,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity<PagedList<MgmtAction>> getActionHistory(
final String targetId, final String rsqlParam,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
findTargetWithExceptionIfNotFound(targetId);
targetManagement.getByControllerId(targetId);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeActionSortParam(sortParam));
final Slice<Action> activeActions;
@@ -331,7 +330,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity<PagedList<MgmtActionStatus>> getActionStatusList(
final String targetId, final Long actionId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Target target = findTargetWithExceptionIfNotFound(targetId);
final Target target = targetManagement.getByControllerId(targetId);
final Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
@@ -350,7 +349,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(final String targetId) {
final MgmtDistributionSet distributionSetRest = deploymentManagement.getAssignedDistributionSet(targetId)
final MgmtDistributionSet distributionSetRest = deploymentManagement.findAssignedDistributionSet(targetId)
.map(ds -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(ds);
MgmtDistributionSetMapper.addLinks(ds, response);
@@ -375,7 +374,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
return ResponseEntity.ok(mgmtDistributionSetMapper
.toResponse(deploymentManagement.offlineAssignedDistributionSets(offlineAssignments)));
}
findTargetWithExceptionIfNotFound(targetId);
targetManagement.getByControllerId(targetId);
final List<DeploymentRequest> deploymentRequests = dsAssignments.stream().map(dsAssignment -> {
final boolean isConfirmationRequired = dsAssignment.getConfirmationRequired() == null
@@ -392,19 +391,14 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet(final String targetId) {
final MgmtDistributionSet distributionSetRest = deploymentManagement.getInstalledDistributionSet(targetId)
return deploymentManagement.findInstalledDistributionSet(targetId)
.map(set -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(set);
MgmtDistributionSetMapper.addLinks(set, response);
return response;
}).orElse(null);
if (distributionSetRest == null) {
return ResponseEntity.noContent().build();
}
return ResponseEntity.ok(distributionSetRest);
})
.map(distributionSetRest -> ResponseEntity.ok(distributionSetRest))
.orElseGet(() -> ResponseEntity.noContent().build());
}
@Override
@@ -467,11 +461,6 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
return new ResponseEntity<>(HttpStatus.OK);
}
private Target findTargetWithExceptionIfNotFound(final String targetId) {
return targetManagement.getByControllerId(targetId)
.orElseThrow(() -> new EntityNotFoundException(Target.class, targetId));
}
private <T, R> R getNullIfEmpty(final T object, final Function<T, R> extractMethod) {
return object == null ? null : extractMethod.apply(object);
}

View File

@@ -20,6 +20,9 @@ import java.util.stream.Collectors;
import jakarta.validation.ValidationException;
import org.eclipse.hawkbit.artifact.urlresolver.ArtifactUrl;
import org.eclipse.hawkbit.artifact.urlresolver.ArtifactUrlResolver;
import org.eclipse.hawkbit.artifact.urlresolver.ArtifactUrlResolver.DownloadDescriptor;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifactHash;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
@@ -33,10 +36,6 @@ import org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResource;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.artifact.urlhandler.ApiType;
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrl;
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
import org.eclipse.hawkbit.repository.artifact.urlhandler.URLPlaceholder;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -157,13 +156,13 @@ public final class MgmtSoftwareModuleMapper {
}
public static void addLinks(final Artifact artifact, final MgmtArtifact response,
final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) {
final ArtifactUrlResolver artifactUrlHandler, final SystemManagement systemManagement) {
final List<ArtifactUrl> urls = artifactUrlHandler.getUrls(
new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(),
systemManagement.getTenantMetadata().getId(), null, null,
new URLPlaceholder.SoftwareData(artifact.getSoftwareModule().getId(), artifact.getFilename(),
artifact.getId(), artifact.getSha1Hash())), ApiType.MGMT, null);
urls.forEach(entry -> response.add(Link.of(entry.getRef()).withRel(entry.getRel()).expand()));
new DownloadDescriptor(
systemManagement.getTenantMetadata().getTenant(), null,
artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getSha1Hash()),
ArtifactUrlResolver.ApiType.MGMT, null);
urls.forEach(entry -> response.add(Link.of(entry.ref()).withRel(entry.rel()).expand()));
}
private SoftwareModuleManagement.Create fromRequest(

View File

@@ -331,9 +331,9 @@ public final class MgmtTargetMapper {
if (pollStatus != null) {
final MgmtPollStatus pollStatusRest = new MgmtPollStatus();
pollStatusRest.setLastRequestAt(
Date.from(pollStatus.getLastPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
Date.from(pollStatus.lastPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
pollStatusRest.setNextExpectedRequestAt(
Date.from(pollStatus.getNextPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
Date.from(pollStatus.nextPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
pollStatusRest.setOverdue(pollStatus.isOverdue());
targetRest.setPollStatus(pollStatusRest);
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize;
@@ -858,7 +859,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.version("anotherVersion").requiredMigrationStep(true).build());
// load also lazy stuff
set = distributionSetManagement.getWithDetails(set.getId()).get();
set = distributionSetManagement.getWithDetails(set.getId());
assertThat(distributionSetManagement.findAll(PAGE)).hasSize(1);
@@ -943,11 +944,11 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
testdataFactory.generateDistributionSet("three", "three", standardDsType, List.of(os, jvm, ah), true));
final DistributionSet one = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==one", PAGE).getContent().get(0).getId()).orElseThrow();
.getWithDetails(distributionSetManagement.findByRsql("name==one", PAGE).getContent().get(0).getId());
final DistributionSet two = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==two", PAGE).getContent().get(0).getId()).orElseThrow();
.getWithDetails(distributionSetManagement.findByRsql("name==two", PAGE).getContent().get(0).getId());
final DistributionSet three = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==three", PAGE).getContent().get(0).getId()).orElseThrow();
.getWithDetails(distributionSetManagement.findByRsql("name==three", PAGE).getContent().get(0).getId());
assertThat((Object) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsets/" + one.getId());
@@ -1702,11 +1703,11 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
.isNull();
assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.STOPPING,
assertThat(rolloutManagement.get(rollout.getId()).getStatus()).isIn(RolloutStatus.STOPPING,
RolloutStatus.STOPPED);
//then enforce executor to stop the rollout and check
rolloutHandler.handleAll();
assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.STOPPED);
assertThat(rolloutManagement.get(rollout.getId()).getStatus()).isIn(RolloutStatus.STOPPED);
for (final Target target : targets) {
assertThat(targetManagement.find(target.getId()).get().getUpdateStatus())
@@ -1735,17 +1736,16 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
.isNull();
assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.DELETING,
RolloutStatus.DELETED);
assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet()).isNull();
final Long rolloutId = rollout.getId();
assertThat(rolloutManagement.get(rolloutId).getStatus()).isIn(RolloutStatus.DELETING, RolloutStatus.DELETED);
//then enforce executor to stop the rollout and check
rolloutHandler.handleAll();
// assert rollout is deleted
assertThat(rolloutManagement.find(rollout.getId())).isEmpty();
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> rolloutManagement.get(rolloutId));
for (final Target target : targets) {
assertThat(targetManagement.find(target.getId()).get().getUpdateStatus())
assertThat(targetManagement.get(target.getId()).getUpdateStatus())
.isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 100))
.getNumberOfElements()).isEqualTo(1);
@@ -1769,11 +1769,10 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.RUNNING);
assertThat(rolloutManagement.get(rollout.getId()).getStatus()).isIn(RolloutStatus.RUNNING);
for (final Target target : targets) {
assertThat(targetManagement.find(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.get(target.getId()).getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 100))
.getNumberOfElements()).isEqualTo(1);
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 100))

View File

@@ -30,13 +30,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionFactory;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
@@ -74,6 +74,7 @@ import org.springframework.data.domain.Sort.Direction;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
/**
@@ -238,9 +239,10 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final List<Target> allTargets = new ArrayList<>(successTargets);
allTargets.addAll(failedTargets);
postRollout("rolloutToBeRetried", 1, dsA.getId(), "id==retryRolloutTarget*", 10, Action.ActionType.FORCED);
final long rolloutToBeRetriedId = postRollout("rolloutToBeRetried", 1, dsA.getId(), "id==retryRolloutTarget*", 10,
Action.ActionType.FORCED);
Rollout rollout = rolloutManagement.getByName("rolloutToBeRetried").orElseThrow();
Rollout rollout = rolloutManagement.get(rolloutToBeRetriedId);
// no scheduler so invoke here
rolloutHandler.handleAll();
@@ -265,13 +267,18 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
}
}
//retry rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", rollout.getId()))
// retry rollout
final MvcResult result = mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().is(201));
.andExpect(status().is(201))
.andReturn();
final long rolloutRetryId = OBJECT_MAPPER
.readerFor(MgmtRolloutResponseBody.class)
.<MgmtRolloutResponseBody> readValue(result.getResponse().getContentAsString())
.getId();
//search for _retried suffix
Rollout retriedRollout = rolloutManagement.getByName(rollout.getName() + "_retry").orElseThrow();
Rollout retriedRollout = rolloutManagement.get(rolloutRetryId);
//assert 4 targets involved
rolloutHandler.handleAll();
@@ -303,8 +310,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
void retryNotFinishedRolloutShouldNotBeAllowed() throws Exception {
final DistributionSet dsA = testdataFactory.createDistributionSet("");
testdataFactory.createTargets("retryRolloutTarget-", 10);
postRollout("rolloutToBeRetried", 1, dsA.getId(), "id==retryRolloutTarget*", 10, Action.ActionType.FORCED);
Rollout rollout = rolloutManagement.getByName("rolloutToBeRetried").orElseThrow();
final long rolloutToBeRetried = postRollout("rolloutToBeRetried", 1, dsA.getId(), "id==retryRolloutTarget*", 10,
Action.ActionType.FORCED);
Rollout rollout = rolloutManagement.get(rolloutToBeRetried);
// no scheduler so invoke here
rolloutHandler.handleAll();
rolloutManagement.start(rollout.getId());
@@ -1072,7 +1080,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final DistributionSet dsA = testdataFactory.createDistributionSetLocked("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout1 = createRollout("rollout1", 4, dsA, "controllerId==rollout*",false);
final Rollout rollout1 = createRollout("rollout1", 4, dsA, "controllerId==rollout*", false);
final Rollout rollout2 = createRollout("rollout2", 1, dsA, "controllerId==rollout*", false);
rolloutManagement.start(rollout1.getId());
@@ -1946,7 +1954,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
private void awaitRunningState(final Long rolloutId) {
awaitRollout().until(() -> SecurityContextSwitch
.callAsPrivileged(() -> rolloutManagement.find(rolloutId).orElseThrow(NoSuchElementException::new))
.callAsPrivileged(() -> rolloutManagement.get(rolloutId))
.getStatus().equals(RolloutStatus.RUNNING));
}
@@ -1966,22 +1974,21 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
}
private void assertStatusIs(final Rollout rollout, final RolloutStatus expected) {
final Optional<Rollout> updatedRollout = rolloutManagement.find(rollout.getId());
assertThat(updatedRollout).get().extracting(Rollout::getStatus).isEqualTo(expected);
assertThat(rolloutManagement.get(rollout.getId()).getStatus()).isEqualTo(expected);
}
private void postRollout(final String name, final int groupSize, final Long distributionSetId,
private long postRollout(final String name, final int groupSize, final Long distributionSetId,
final String targetFilterQuery, final int targets, final Action.ActionType type) throws Exception {
postRollout(name, groupSize, distributionSetId, targetFilterQuery, targets, type, null, null);
return postRollout(name, groupSize, distributionSetId, targetFilterQuery, targets, type, null, null);
}
private void postRollout(final String name, final int groupSize, final Long distributionSetId,
private long postRollout(final String name, final int groupSize, final Long distributionSetId,
final String targetFilterQuery, final int targets, final Action.ActionType type, final Long startTime,
final Long forceTime) throws Exception {
postRollout(name, groupSize, distributionSetId, targetFilterQuery, targets, type, startTime, forceTime, false, null, 0);
return postRollout(name, groupSize, distributionSetId, targetFilterQuery, targets, type, startTime, forceTime, false, null, 0);
}
private void postRollout(final String name, final int groupSize, final Long distributionSetId,
private long postRollout(final String name, final int groupSize, final Long distributionSetId,
final String targetFilterQuery, final int targets, final Action.ActionType type, final Long startTime,
final Long forceTime, boolean isDynamic, String dynamicGroupSuffix, int dynamicGroupTargetsCount) throws Exception {
final String actionType = MgmtRestModelMapper.convertActionType(type).getName();
@@ -1989,7 +1996,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
new RolloutGroupConditionBuilder().withDefaults().build(), null, actionType, null, startTime, forceTime,
null, isDynamic, dynamicGroupSuffix, dynamicGroupTargetsCount);
mvc.perform(post("/rest/v1/rollouts").content(rollout).contentType(MediaType.APPLICATION_JSON)
final MvcResult result = mvc.perform(post("/rest/v1/rollouts").content(rollout).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
@@ -2004,10 +2011,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux")))
.andExpect(jsonPath("$.lastModifiedAt", not(equalTo(0))))
.andExpect(jsonPath("$.totalTargets", equalTo(targets)))
.andExpect(startTime != null ? jsonPath("$.startAt", equalTo(startTime.intValue()))
: jsonPath("$.startAt").doesNotExist())
.andExpect(forceTime != null ? jsonPath("$.forcetime", equalTo(forceTime.intValue()))
: jsonPath("$.forcetime", equalTo(0)))
.andExpect(startTime != null ? jsonPath("$.startAt", equalTo(startTime.intValue())) : jsonPath("$.startAt").doesNotExist())
.andExpect(forceTime != null ? jsonPath("$.forcetime", equalTo(forceTime.intValue())) : jsonPath("$.forcetime", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.notstarted", equalTo(targets)))
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(0)))
@@ -2019,8 +2024,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$._links.pause.href", allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/pause"))))
.andExpect(jsonPath("$.dynamic", equalTo(isDynamic)))
.andExpect(jsonPath("$._links.resume.href", allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/resume"))))
.andExpect(jsonPath(
"$._links.groups.href", allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))));
.andExpect(jsonPath("$._links.groups.href", allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))))
.andReturn();
return OBJECT_MAPPER
.readerFor(MgmtRolloutResponseBody.class)
.<MgmtRolloutResponseBody> readValue(result.getResponse().getContentAsString())
.getId();
}
private Rollout createRollout(
@@ -2039,7 +2048,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// Run here, because Scheduler is disabled during tests
rolloutHandler.handleAll();
return rolloutManagement.find(rollout.getId()).orElseThrow(NoSuchElementException::new);
return rolloutManagement.get(rollout.getId());
}
private void triggerNextGroupAndExpect(final Rollout rollout, final ResultMatcher expect) throws Exception {

View File

@@ -31,13 +31,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import com.jayway.jsonpath.JsonPath;
import org.apache.commons.io.IOUtils;
import org.eclipse.hawkbit.artifact.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.artifact.exception.FileSizeQuotaExceededException;
import org.eclipse.hawkbit.artifact.exception.StorageQuotaExceededException;
import org.eclipse.hawkbit.artifact.model.ArtifactStream;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
@@ -47,13 +50,9 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifactHash;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.FileSizeQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.StorageQuotaExceededException;
import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.ArtifactUpload;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -94,6 +93,8 @@ import org.springframework.web.bind.annotation.RestController;
"hawkbit.server.security.dos.maxArtifactStorage=500000" })
class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTest {
private LocalArtifactRepository localArtifactRepository;
@BeforeEach
public void assertPreparationOfRepo() {
assertThat(softwareModuleManagement.findAll(PAGE)).as("no softwaremodule should be founded").isEmpty();
@@ -145,7 +146,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(5);
artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));
artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), null, 0, null, sm.getId(), "file1", false));
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts", sm.getId())
.param("representation", MgmtRepresentationMode.FULL.toString())
@@ -515,8 +516,10 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.providedFilename", equalTo("customFilename")))
.andExpect(status().isCreated())
.andDo(result -> {
final MgmtArtifact mgmtArtifact = OBJECT_MAPPER.readerFor(MgmtArtifact.class).readValue(result.getResponse().getContentAsString());
assertThat(artifactManagement.loadArtifactBinary(mgmtArtifact.getHashes().getSha1(), sm.getId(), sm.isEncrypted())).isNotNull();
final MgmtArtifact mgmtArtifact = OBJECT_MAPPER.readerFor(MgmtArtifact.class)
.readValue(result.getResponse().getContentAsString());
assertThat(artifactManagement.getArtifactStream(mgmtArtifact.getHashes().getSha1(), sm.getId(),
sm.isEncrypted())).isNotNull();
});
}
@@ -687,9 +690,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
final Artifact artifact2 = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file2", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file2", false));
downloadAndVerify(sm, random, artifact);
downloadAndVerify(sm, random, artifact2);
@@ -707,7 +710,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
.create(new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
// perform test
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
@@ -722,11 +725,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.hashes.sha256", equalTo(artifact.getSha256Hash())))
.andExpect(jsonPath("$.providedFilename", equalTo("file1")))
.andExpect(jsonPath("$._links.download.href",
equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s/download"
.formatted(sm.getId(), artifact.getId()))))
equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s/download".formatted(sm.getId(), artifact.getId()))))
.andExpect(jsonPath("$._links.self.href",
equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s".formatted(sm.getId(),
artifact.getId()))));
equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s".formatted(sm.getId(), artifact.getId()))));
}
/**
@@ -742,7 +743,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
.create(new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
// perform test
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
@@ -806,9 +807,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
final Artifact artifact2 = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file2", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file2", false));
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
@@ -844,9 +845,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
.create(new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
final Artifact artifact2 = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file2", false, artifactSize));
.create(new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file2", false));
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId())
.param("representation", MgmtRepresentationMode.FULL.toString())
@@ -910,7 +911,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// SM does not exist
artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
.create(new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
@@ -954,10 +955,10 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final long moduleId = sm.getId();
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), moduleId, "file1", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, moduleId, "file1", false));
final byte[] random2 = randomBytes(artifactSize);
artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random2), moduleId, "file2", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random2), null, artifactSize, null, moduleId, "file2", false));
// check repo before delete
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(1);
@@ -974,7 +975,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final boolean encrypted = sm.isEncrypted();
final String sha1Hash = artifact.getSha1Hash();
assertThatExceptionOfType(ArtifactBinaryNotFoundException.class)
.isThrownBy(() -> artifactManagement.loadArtifactBinary(sha1Hash, moduleId, encrypted));
.isThrownBy(() -> artifactManagement.getArtifactStream(sha1Hash, moduleId, encrypted));
assertThat(softwareModuleManagement.find(moduleId).get().getArtifacts())
.as("After delete artifact should available for marked as deleted sm's").hasSize(1);
}
@@ -1344,14 +1345,14 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, sm.getId(), "file1", false));
assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremoudle size is wrong").hasSize(1);
final Long smId = sm.getId();
final String sha1Hash = artifact.getSha1Hash();
final boolean encrypted = sm.isEncrypted();
assertThat(artifactManagement.loadArtifactBinary(sha1Hash, smId, encrypted)).isNotNull();
assertThat(artifactManagement.getArtifactStream(sha1Hash, smId, encrypted)).isNotNull();
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId()))
.andDo(MockMvcResultPrinter.print())
@@ -1359,7 +1360,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
assertThat(softwareModuleManagement.findAll(PAGE)).as("After delete no softwarmodule should be available").isEmpty();
assertThatExceptionOfType(EntityNotFoundException.class) // sm doesn't exists
.isThrownBy(() -> artifactManagement.loadArtifactBinary(sha1Hash, smId, encrypted));
.isThrownBy(() -> artifactManagement.getArtifactStream(sha1Hash, smId, encrypted));
}
/**
@@ -1376,12 +1377,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final Long appTypeSmId = appTypeSm.getId();
final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), appTypeSmId, "file1", false, artifactSize));
new ArtifactUpload(new ByteArrayInputStream(random), null, artifactSize, null, appTypeSmId, "file1", false));
assertThat(softwareModuleManagement.count()).isEqualTo(3);
final String sha1Hash = artifact.getSha1Hash();
final boolean encrypted = appTypeSm.isEncrypted();
assertThat(artifactManagement.loadArtifactBinary(sha1Hash, appTypeSmId, encrypted)).isNotNull();
assertThat(artifactManagement.getArtifactStream(sha1Hash, appTypeSmId, encrypted)).isNotNull();
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId))
.andDo(MockMvcResultPrinter.print())
@@ -1399,7 +1400,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
assertThat(softwareModuleManagement.count()).isEqualTo(2);
assertThatExceptionOfType(ArtifactBinaryNotFoundException.class)
.isThrownBy(() -> artifactManagement.loadArtifactBinary(sha1Hash, appTypeSmId, encrypted));
.isThrownBy(() -> artifactManagement.getArtifactStream(sha1Hash, appTypeSmId, encrypted));
}
/**
@@ -1526,19 +1527,13 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
}
private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
final DbArtifact artifact = artifactManagement
.loadArtifactBinary(
softwareModuleManagement.find(
sm.getId()).orElseThrow().getArtifacts().get(0).getSha1Hash(), sm.getId(), sm.isEncrypted());
// binary
try (final InputStream fileInputStream = artifact.getFileInputStream()) {
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream),
"Wrong artifact content");
try (final ArtifactStream artifact = artifactManagement.getArtifactStream(
softwareModuleManagement.find(sm.getId()).orElseThrow().getArtifacts().get(0).getSha1Hash(), sm.getId(), sm.isEncrypted())) {
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), artifact), "Wrong artifact content");
// hashes
assertThat(artifact.getSha1Hash()).as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random));
}
// hashes
final DbArtifactHash hash = artifact.getHashes();
assertThat(hash.getSha1()).as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random));
// metadata
assertThat(softwareModuleManagement.find(sm.getId()).orElseThrow().getArtifacts().get(0).getFilename())
.as("wrong metadata of the filename").isEqualTo("origFilename");

View File

@@ -538,8 +538,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
// action has not been cancelled confirmed from controller, so DS
// remains assigned until
// confirmation
assertThat(deploymentManagement.getAssignedDistributionSet(tA.getControllerId())).isPresent();
assertThat(deploymentManagement.getInstalledDistributionSet(tA.getControllerId())).isNotPresent();
assertThat(deploymentManagement.findAssignedDistributionSet(tA.getControllerId())).isPresent();
assertThat(deploymentManagement.findInstalledDistributionSet(tA.getControllerId())).isNotPresent();
}
/**
@@ -619,7 +619,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId))
.andExpect(status().isOk());
assertThat(targetManagement.getByControllerId(knownControllerId)).isNotPresent();
assertThat(targetManagement.findByControllerId(knownControllerId)).isNotPresent();
}
/**
@@ -667,9 +667,10 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.description", equalTo(knownNewDescription)))
.andExpect(jsonPath("$.name", equalTo(knownNameNotModify)));
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
assertThat(findTargetByControllerID.getDescription()).isEqualTo(knownNewDescription);
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
assertThat(targetManagement.getByControllerId(knownControllerId)).satisfies(findTargetByControllerID -> {
assertThat(findTargetByControllerID.getDescription()).isEqualTo(knownNewDescription);
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
});
}
/**
@@ -691,8 +692,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
assertThat(findTargetByControllerID.getDescription()).isEqualTo("old description");
assertThat(targetManagement.getByControllerId(knownControllerId).getDescription()).isEqualTo("old description");
}
/**
@@ -716,9 +716,10 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.securityToken", equalTo(knownNewToken)))
.andExpect(jsonPath("$.name", equalTo(knownNameNotModify)));
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
assertThat(findTargetByControllerID.getSecurityToken()).isEqualTo(knownNewToken);
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
assertThat(targetManagement.getByControllerId(knownControllerId)).satisfies(findTargetByControllerID -> {
assertThat(findTargetByControllerID.getSecurityToken()).isEqualTo(knownNewToken);
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
});
}
/**
@@ -742,9 +743,10 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.address", equalTo(knownNewAddress)))
.andExpect(jsonPath("$.name", equalTo(knownNameNotModify)));
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
assertThat(findTargetByControllerID.getAddress()).hasToString(knownNewAddress);
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
assertThat(targetManagement.getByControllerId(knownControllerId)).satisfies(findTargetByControllerID -> {
assertThat(findTargetByControllerID.getAddress()).hasToString(knownNewAddress);
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
});
}
/**
@@ -1027,7 +1029,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("[0].controllerId", equalTo(randomString)))
.andExpect(jsonPath("[0].name", equalTo(expectedTargetName)));
assertThat(targetManagement.getByControllerId(randomString).get().getName()).isEqualTo(expectedTargetName);
assertThat(targetManagement.getByControllerId(randomString).getName()).isEqualTo(expectedTargetName);
}
/**
@@ -1638,8 +1640,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("total", equalTo(1)));
implicitLock(set);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
target = targetManagement.getByControllerId(target.getControllerId()).get();
assertThat(deploymentManagement.findAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
target = targetManagement.getByControllerId(target.getControllerId());
// repeating DS assignment leads again to OK
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + target.getControllerId() + "/assignedDS")
@@ -1651,7 +1653,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("total", equalTo(1)));
// ...but does not change the target
assertThat(targetManagement.getByControllerId(target.getControllerId()).get()).isEqualTo(target);
assertThat(targetManagement.findByControllerId(target.getControllerId()).get()).isEqualTo(target);
}
/**
@@ -1683,7 +1685,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("total", equalTo(1)));
implicitLock(set);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
assertThat(deploymentManagement.findAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
assertThat(
actionRepository
@@ -1716,7 +1718,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("total", equalTo(1)));
implicitLock(set);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
assertThat(deploymentManagement.findAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
final Slice<Action> actions = deploymentManagement.findActionsByTarget("targetExist", PageRequest.of(0, 100));
assertThat(actions).isNotEmpty().filteredOn(a -> a.getDistributionSet().equals(set))
.extracting(Action::getActionType).containsOnly(ActionType.DOWNLOAD_ONLY);
@@ -1741,9 +1743,9 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("total", equalTo(1)));
implicitLock(set);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
assertThat(deploymentManagement.getInstalledDistributionSet(target.getControllerId()).get()).isEqualTo(set);
target = targetManagement.getByControllerId(target.getControllerId()).get();
assertThat(deploymentManagement.findAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
assertThat(deploymentManagement.findInstalledDistributionSet(target.getControllerId()).get()).isEqualTo(set);
target = targetManagement.getByControllerId(target.getControllerId());
assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
// repeating DS assignment leads again to OK
@@ -1757,7 +1759,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("total", equalTo(1)));
// ...but does not change the target
assertThat(targetManagement.getByControllerId(target.getControllerId()).get()).isEqualTo(target);
assertThat(targetManagement.getByControllerId(target.getControllerId())).isEqualTo(target);
}
@Test
@@ -1780,7 +1782,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
assertThat(findActiveActionsByTarget).hasSize(1);
assertThat(findActiveActionsByTarget.get(0).getActionType()).isEqualTo(ActionType.TIMEFORCED);
assertThat(findActiveActionsByTarget.get(0).getForcedTime()).isEqualTo(forceTime);
assertThat(deploymentManagement.getAssignedDistributionSet("fsdfsd").get()).isEqualTo(set);
assertThat(deploymentManagement.findAssignedDistributionSet("fsdfsd").get()).isEqualTo(set);
}
/**
@@ -2038,7 +2040,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
knownControllerAttrs.put("b.2", "2");
testdataFactory.createTarget(knownTargetId);
controllerManagement.updateControllerAttributes(knownTargetId, knownControllerAttrs, null);
assertThat(targetManagement.getByControllerId(knownTargetId).orElseThrow().isRequestControllerAttributes()).isFalse();
assertThat(targetManagement.getByControllerId(knownTargetId).isRequestControllerAttributes()).isFalse();
verifyAttributeUpdateCanBeRequested(knownTargetId);
verifyRequestAttributesAttributeIsOptional(knownTargetId);
@@ -2539,8 +2541,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("[0].controllerId", equalTo("targetcontroller")))
.andExpect(jsonPath("[0].targetType", equalTo(targetTypes.get(0).getId().intValue())));
assertThat(targetManagement.getByControllerId("targetcontroller").get().getTargetType().getId())
.isEqualTo(targetTypes.get(0).getId());
assertThat(targetManagement.getByControllerId("targetcontroller").getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
}
/**
@@ -2610,8 +2611,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(targetManagement.getByControllerId(targetControllerId).get().getTargetType().getId())
.isEqualTo(targetType.getId());
assertThat(targetManagement.getByControllerId(targetControllerId).getTargetType().getId()).isEqualTo(targetType.getId());
}
/**
@@ -2669,7 +2669,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertThat(targetManagement.getByControllerId(targetControllerId).get().getTargetType()).isNull();
assertThat(targetManagement.getByControllerId(targetControllerId).getTargetType()).isNull();
}
@Test
@@ -2873,12 +2873,11 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
}
private Target assertTarget(final String controllerId, final String name, final String description) {
final Optional<Target> target1 = targetManagement.getByControllerId(controllerId);
assertThat(target1).isPresent();
final Target t = target1.get();
assertThat(t.getName()).isEqualTo(name);
assertThat(t.getDescription()).isEqualTo(description);
return t;
final Target target = targetManagement.getByControllerId(controllerId);
assertThat(target).isNotNull();
assertThat(target.getName()).isEqualTo(name);
assertThat(target.getDescription()).isEqualTo(description);
return target;
}
private void getActions(final boolean withExternalRef) throws Exception {
@@ -2986,7 +2985,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(targetManagement.getByControllerId(knownTargetId).orElseThrow().isRequestControllerAttributes()).isTrue();
assertThat(targetManagement.getByControllerId(knownTargetId).isRequestControllerAttributes()).isTrue();
}
private void verifyRequestAttributesAttributeIsOptional(final String knownTargetId) throws Exception {
@@ -3006,7 +3005,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
assertThat(targetManagement.getByControllerId(knownTargetId).orElseThrow().isRequestControllerAttributes()).isTrue();
assertThat(targetManagement.getByControllerId(knownTargetId).isRequestControllerAttributes()).isTrue();
}
private String getCreateTargetsListJsonString(final String controllerId, final String name, final String description) {
@@ -3048,7 +3047,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
// verify active action
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE);
assertThat(actionsByTarget.getContent()).hasSize(1);
return targetManagement.getByControllerId(tA.getControllerId()).get();
return targetManagement.getByControllerId(tA.getControllerId());
}
private void setupTargetWithMetadata(final String knownControllerId, final String knownKey, final String knownValue) {

View File

@@ -722,7 +722,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
for (int index = 0; index < size; index++) {
String name = "TestTypePOST" + index;
final TargetType created = targetTypeManagement.getByName(name).get();
final TargetType created = findTargetTypeByName(name);
assertThat(JsonPath.compile("$[ ?(@.name=='" + name + "') ].id")
.read(mvcResult.getResponse().getContentAsString()).toString()).contains(String.valueOf(created.getId()));

View File

@@ -30,7 +30,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<artifactId>hawkbit-artifact-fs</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>