Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -144,6 +144,17 @@ public interface DistributionSetManagement
|
|||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||||
void lock(final long id);
|
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.
|
* Retrieves the distribution set for a given action.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -336,6 +336,17 @@ public interface SoftwareModuleManagement
|
|||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||||
void lock(long id);
|
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.
|
* Updates a distribution set meta data value if corresponding entry exists.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -710,6 +710,18 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@Retryable(include = {
|
@Retryable(include = {
|
||||||
|
|||||||
@@ -633,6 +633,20 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@Retryable(include = {
|
@Retryable(include = {
|
||||||
|
|||||||
@@ -268,6 +268,10 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
|||||||
locked = true;
|
locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unlock() {
|
||||||
|
locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDeleted(final boolean deleted) {
|
public void setDeleted(final boolean deleted) {
|
||||||
this.deleted = deleted;
|
this.deleted = deleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,10 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
|||||||
locked = true;
|
locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unlock() {
|
||||||
|
locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks or un-marks this software module as deleted.
|
* Marks or un-marks this software module as deleted.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1008,6 +1008,30 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
|
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
|
||||||
.orElse(false))
|
.orElse(false))
|
||||||
.isTrue();
|
.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
|
@Test
|
||||||
|
|||||||
@@ -839,6 +839,20 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
.isTrue();
|
.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
|
@Test
|
||||||
@Description("Artifacts of a locked SM can't be modified. Expected behaviour is to throw an exception and to do not modify them.")
|
@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() {
|
void lockSoftwareModuleApplied() {
|
||||||
|
|||||||
Reference in New Issue
Block a user