Skip to content

Commit

Permalink
[#1651] Add SoftwareModule and DistributionSet unlock (Mgmt) (#1676)
Browse files Browse the repository at this point in the history
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Mar 8, 2024
1 parent 1640025 commit 4d10487
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ public interface DistributionSetManagement
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void lock(final long id);

/**
* Unlocks a distribution set.<br/>
* Use it with extreme care! In general once distribution set is locked
* it shall not be unlocked. Note that it could have been assigned / deployed to targets.
*
* @param id the distribution set id
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void unlock(final long id);

/**
* Retrieves the distribution set for a given action.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ Slice<AssignedSoftwareModule> findAllOrderBySetAssignmentAndModuleNameAscModuleV
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void lock(long id);

/**
* Unlocks a software module.<br/>
* Use it with extreme care! In general once software module is locked
* it shall not be unlocked. Note that it could have been assigned / deployed to targets.
*
* @param id the software module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void unlock(long id);

/**
* Updates a distribution set meta data value if corresponding entry exists.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@ public void lock(final long id) {
}
}

@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void unlock(final long id) {
final JpaDistributionSet distributionSet = getById(id);
if (distributionSet.isLocked()) {
distributionSet.unlock();
distributionSetRepository.save(distributionSet);
}
}

@Override
@Transactional
@Retryable(include = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,20 @@ public void lock(final long id) {
}
}

@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void unlock(final long id) {
final JpaSoftwareModule softwareModule = softwareModuleRepository
.findById(id)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, id));
if (softwareModule.isLocked()) {
softwareModule.unlock();
softwareModuleRepository.save(softwareModule);
}
}

@Override
@Transactional
@Retryable(include = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ public void lock() {
locked = true;
}

public void unlock() {
locked = false;
}

public void setDeleted(final boolean deleted) {
this.deleted = deleted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public void lock() {
locked = true;
}

public void unlock() {
locked = false;
}

/**
* Marks or un-marks this software module as deleted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,30 @@ void lockDistributionSet() {
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(false))
.isTrue();
// assert software modules are locked
assertThat(distributionSet.getModules().size()).isNotEqualTo(0);
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::getModules)
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
}

@Test
@Description("Unlocks a DS.")
void unlockDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(false))
.isTrue();
distributionSetManagement.unlock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(true))
.isFalse();
// assert software modules are not unlocked
assertThat(distributionSet.getModules().size()).isNotEqualTo(0);
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::getModules)
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,20 @@ void lockSoftwareModule() {
.isTrue();
}

@Test
@Description("Unlocks a SM.")
void unlockSoftwareModule() {
final SoftwareModule softwareModule = testdataFactory.createSoftwareModule("sm-1");
softwareModuleManagement.lock(softwareModule.getId());
assertThat(
softwareModuleManagement.get(softwareModule.getId()).map(SoftwareModule::isLocked).orElse(false))
.isTrue();
softwareModuleManagement.unlock(softwareModule.getId());
assertThat(
softwareModuleManagement.get(softwareModule.getId()).map(SoftwareModule::isLocked).orElse(true))
.isFalse();
}

@Test
@Description("Artifacts of a locked SM can't be modified. Expected behaviour is to throw an exception and to do not modify them.")
void lockSoftwareModuleApplied() {
Expand Down

0 comments on commit 4d10487

Please sign in to comment.