org.springframework.retry.annotation.Backoff Java Examples

The following examples show how to use org.springframework.retry.annotation.Backoff. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JpaDistributionSetTypeManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignOptionalSoftwareModuleTypes(final long dsTypeId,
        final Collection<Long> softwareModulesTypeIds) {

    final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
            .findAllById(softwareModulesTypeIds);

    if (modules.size() < softwareModulesTypeIds.size()) {
        throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
                modules.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
    }

    final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
    checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
    assertSoftwareModuleTypeQuota(dsTypeId, softwareModulesTypeIds.size());

    modules.forEach(type::addOptionalModuleType);

    return distributionSetTypeRepository.save(type);
}
 
Example #2
Source File: JestClientHelper.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Method to use the JEST client to execute an elastic action
 *
 * @param <T> The expected class of the action
 * @param action action
 *
 * @return a jest action result
 */
@Retryable(maxAttempts = 3, value = RestClientException.class, backoff = @Backoff(delay = 5000, multiplier = 2))
public <T extends JestResult> T execute(Action<T> action)
{
    T actionResult = null;
    try
    {
        actionResult = jestClientFactory.getJestClient().execute(action);

        // log the error if the action failed but no exception is thrown
        if (actionResult == null || !actionResult.isSucceeded())
        {
            LOGGER.error("Failed to execute JEST client action. action={}, actionResult={}", action, actionResult);
        }
    }
    catch (final IOException ioException)
    {
        LOGGER.error("Failed to execute JEST client action.", ioException);
        //throw a runtime exception so that the client needs not catch
        throw new RestClientException(ioException.getMessage()); //NOPMD
    }

    return actionResult;
}
 
Example #3
Source File: JpaArtifactManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact create(final ArtifactUpload artifactUpload) {
    final String filename = artifactUpload.getFilename();
    final long moduleId = artifactUpload.getModuleId();

    final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId);

    final Artifact existing = checkForExistingArtifact(filename, artifactUpload.overrideExisting(), softwareModule);

    assertArtifactQuota(moduleId, 1);

    return getOrCreateArtifact(artifactUpload)
            .map(artifact -> storeArtifactMetadata(softwareModule, filename, artifact, existing)).orElse(null);
}
 
Example #4
Source File: JpaSoftwareModuleManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate u) {
    final GenericSoftwareModuleMetadataUpdate update = (GenericSoftwareModuleMetadataUpdate) u;

    // check if exists otherwise throw entity not found exception
    final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(
            update.getSoftwareModuleId(), update.getKey())
                    .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class,
                            update.getSoftwareModuleId(), update.getKey()));

    update.getValue().ifPresent(metadata::setValue);
    update.isTargetVisible().ifPresent(metadata::setTargetVisible);

    touch(metadata.getSoftwareModule());
    return softwareModuleMetadataRepository.save(metadata);
}
 
Example #5
Source File: JpaArtifactManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public boolean clearArtifactBinary(final String sha1Hash, final long moduleId) {
    final long count = localArtifactRepository.countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(sha1Hash,
            tenantAware.getCurrentTenant());
    if (count > 1) {
        // there are still other artifacts that need the binary
        return false;
    }
    try {
        LOG.debug("deleting artifact from repository {}", sha1Hash);
        artifactRepository.deleteBySha1(tenantAware.getCurrentTenant(), sha1Hash);
        return true;
    } catch (final ArtifactStoreException e) {
        throw new ArtifactDeleteFailedException(e);
    }
}
 
Example #6
Source File: HerdApiClientOperations.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Gets BusinessObjectDataKey from SQS message
 *
 * @param client the AWS SQS client
 * @param queueUrl the AWS SQS queue url
 *
 * @return BusinessObjectDataKey
 * @throws IOException if fails to retrieve BusinessObjectDataKey from SQS message
 * @throws ApiException if fails to make API call
 */
@Retryable(value = ApiException.class, backoff = @Backoff(delay = 2000, multiplier = 2))
BusinessObjectDataKey getBdataKeySqs(AmazonSQS client, String queueUrl) throws IOException, ApiException
{
    ReceiveMessageRequest receiveMessageRequest =
        new ReceiveMessageRequest().withMaxNumberOfMessages(MAX_NUM_MESSAGES).withQueueUrl(queueUrl).withWaitTimeSeconds(WAIT_TIME_SECS)
            .withVisibilityTimeout(VISIBILITY_TIMEOUT_SECS);

    LOGGER.info("Checking queue");
    ReceiveMessageResult receiveMessageResult = client.receiveMessage(receiveMessageRequest);
    if (receiveMessageResult != null && receiveMessageResult.getMessages() != null && receiveMessageResult.getMessages().size() > 0)
    {
        List<Message> sqsMessageList = receiveMessageResult.getMessages();

        LOGGER.info("Scanning {} messages for {} and {}", sqsMessageList.size(), SEARCH_KEYWORD_1, SEARCH_KEYWORD_2);
        // Get message type BUS_OBJCT_DATA_STTS_CHG
        for (Message sqsMessage : sqsMessageList)
        {
            String receivedMessageBody = sqsMessage.getBody();
            if (receivedMessageBody.contains(SEARCH_KEYWORD_1) && receivedMessageBody.contains(SEARCH_KEYWORD_2))
            {
                LOGGER.info("Received Message: {}", receivedMessageBody);
                return mapJsontoBdataKey(receivedMessageBody).getBusinessObjectDataKey();
            }
        }
    }
    throw new ApiException("No SQS message found in queue: " + queueUrl);
}
 
Example #7
Source File: TextUnitSearcher.java    From mojito with Apache License 2.0 6 votes vote down vote up
/**
 * Search/Build text units.
 *
 * @param searchParameters the search parameter to specify filters and
 * pagination
 * @return the list of text units
 */
@Transactional
@Retryable(
        value = {TextUnitSearcherError.class},
        backoff = @Backoff(delay = 500, multiplier = 2))
public List<TextUnitDTO> search(TextUnitSearcherParameters searchParameters) {
   
    NativeCriteria c = getCriteriaForSearch(searchParameters);

    try {
        logger.debug("Perform query");
        List<TextUnitDTO> resultAsList = c.criteriaResult(new TextUnitDTONativeObjectMapper());
        
        if (logger.isDebugEnabled()) {
            logger.debug("Query done, info: {}", c.getQueryInfo());
        }

        return resultAsList;
    } catch (Exception e) {
        logger.warn("TextUnitSearcher failed to search, exception", e);
        logger.warn("TextUnitSearcher failed to search, query: {}", c.getQueryInfo().toString());
        throw new TextUnitSearcherError(c, "search", e);
    }
}
 
Example #8
Source File: TextUnitSearcher.java    From mojito with Apache License 2.0 6 votes vote down vote up
@Retryable(
        value = {TextUnitSearcherError.class},
        backoff = @Backoff(delay = 500, multiplier = 2))
public TextUnitAndWordCount countTextUnitAndWordCount(TextUnitSearcherParameters searchParameters) throws TextUnitSearcherError {

    NativeCriteria c = getCriteriaForSearch(searchParameters);

    c.setProjection(NativeExps.projection().
            addAggregateProjection("tu.id", "tu_count", NativeProjection.AggregateProjection.COUNT).
            addAggregateProjection("tu.word_count", "tu_word_count", NativeProjection.AggregateProjection.SUM));

    try {
        TextUnitAndWordCount textUnitAndWordCount = c.criteriaResult(new CriteriaResultTransformerTextUnitAndWordCount());
        return textUnitAndWordCount;
    } catch (Exception e) {
        logger.warn("TextUnitSearcher failed to count, query: {}", c.getQueryInfo().toString());
        throw new TextUnitSearcherError(c, "count text unit", e);
    }
}
 
Example #9
Source File: JpaControllerManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action addUpdateActionStatus(final ActionStatusCreate c) {
    final JpaActionStatusCreate create = (JpaActionStatusCreate) c;
    final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
    final JpaActionStatus actionStatus = create.build();

    if (isUpdatingActionStatusAllowed(action, actionStatus)) {
        return handleAddUpdateActionStatus(actionStatus, action);
    }

    LOG.debug("Update of actionStatus {} for action {} not possible since action not active anymore.",
            actionStatus.getStatus(), action.getId());
    return action;
}
 
Example #10
Source File: JpaRolloutManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) {
    LOGGER.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision);
    final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
    RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL);
    switch (decision) {
    case APPROVED:
        rollout.setStatus(RolloutStatus.READY);
        break;
    case DENIED:
        rollout.setStatus(RolloutStatus.APPROVAL_DENIED);
        break;
    default:
        throw new IllegalArgumentException("Unknown approval decision: " + decision);
    }
    rollout.setApprovalDecidedBy(rolloutApprovalStrategy.getApprovalUser(rollout));
    if (remark != null) {
        rollout.setApprovalRemark(remark);
    }
    return rolloutRepository.save(rollout);
}
 
Example #11
Source File: JpaRolloutManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void pauseRollout(final long rolloutId) {
    final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
    if (RolloutStatus.RUNNING != rollout.getStatus()) {
        throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is "
                + rollout.getStatus().name().toLowerCase());
    }
    // setting the complete rollout only in paused state. This is sufficient
    // due the currently running groups will be completed and new groups are
    // not started until rollout goes back to running state again. The
    // periodically check for running rollouts will skip rollouts in pause
    // state.
    rollout.setStatus(RolloutStatus.PAUSED);
    rolloutRepository.save(rollout);
}
 
Example #12
Source File: JpaRolloutManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long rolloutId) {
    final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
            .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));

    if (jpaRollout == null) {
        throw new EntityNotFoundException(Rollout.class, rolloutId);
    }

    if (RolloutStatus.DELETING == jpaRollout.getStatus()) {
        return;
    }

    jpaRollout.setStatus(RolloutStatus.DELETING);
    rolloutRepository.save(jpaRollout);
}
 
Example #13
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> assignTag(final Collection<Long> dsIds, final long dsTagId) {
    final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(dsIds);

    if (allDs.size() < dsIds.size()) {
        throw new EntityNotFoundException(DistributionSet.class, dsIds,
                allDs.stream().map(DistributionSet::getId).collect(Collectors.toList()));
    }

    final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId)
            .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));

    allDs.forEach(ds -> ds.addTag(distributionSetTag));

    final List<DistributionSet> result = Collections
            .unmodifiableList(allDs.stream().map(distributionSetRepository::save).collect(Collectors.toList()));

    // No reason to save the tag
    entityManager.detach(distributionSetTag);
    return result;
}
 
Example #14
Source File: JpaSystemManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTenant(final String t) {
    final String tenant = t.toUpperCase();
    cacheManager.evictCaches(tenant);
    rolloutStatusCache.evictCaches(tenant);
    tenantAware.runAsTenant(tenant, () -> {
        entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
        tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
        tenantConfigurationRepository.deleteByTenant(tenant);
        targetRepository.deleteByTenant(tenant);
        targetFilterQueryRepository.deleteByTenant(tenant);
        rolloutRepository.deleteByTenant(tenant);
        targetTagRepository.deleteByTenant(tenant);
        distributionSetTagRepository.deleteByTenant(tenant);
        distributionSetRepository.deleteByTenant(tenant);
        distributionSetTypeRepository.deleteByTenant(tenant);
        softwareModuleRepository.deleteByTenant(tenant);
        artifactRepository.deleteByTenant(tenant);
        softwareModuleTypeRepository.deleteByTenant(tenant);
        return null;
    });
}
 
Example #15
Source File: JpaDistributionSetTypeManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignMandatorySoftwareModuleTypes(final long dsTypeId,
        final Collection<Long> softwareModulesTypeIds) {
    final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
            .findAllById(softwareModulesTypeIds);

    if (modules.size() < softwareModulesTypeIds.size()) {
        throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
                modules.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
    }

    final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
    checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
    assertSoftwareModuleTypeQuota(dsTypeId, softwareModulesTypeIds.size());

    modules.forEach(type::addMandatoryModuleType);

    return distributionSetTypeRepository.save(type);
}
 
Example #16
Source File: JpaDistributionSetTypeManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long typeId) {

    final JpaDistributionSetType toDelete = distributionSetTypeRepository.findById(typeId)
            .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, typeId));

    if (distributionSetRepository.countByTypeId(typeId) > 0) {
        toDelete.setDeleted(true);
        distributionSetTypeRepository.save(toDelete);
    } else {
        distributionSetTypeRepository.deleteById(typeId);
    }
}
 
Example #17
Source File: JpaSoftwareModuleTypeManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long typeId) {
    final JpaSoftwareModuleType toDelete = softwareModuleTypeRepository.findById(typeId)
            .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, typeId));

    if (softwareModuleRepository.countByType(toDelete) > 0
            || distributionSetTypeRepository.countByElementsSmType(toDelete) > 0) {
        toDelete.setDeleted(true);
        softwareModuleTypeRepository.save(toDelete);
    } else {
        softwareModuleTypeRepository.delete(toDelete);
    }
}
 
Example #18
Source File: JpaTargetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target unAssignTag(final String controllerID, final long targetTagId) {
    final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerID);

    final TargetTag tag = targetTagRepository.findById(targetTagId)
            .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));

    target.removeTag(tag);

    final Target result = targetRepository.save(target);

    // No reason to save the tag
    entityManager.detach(tag);
    return result;
}
 
Example #19
Source File: JpaTargetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<Target> assignTag(final Collection<String> controllerIds, final long tagId) {

    final List<JpaTarget> allTargets = targetRepository
            .findAll(TargetSpecifications.byControllerIdWithTagsInJoin(controllerIds));

    if (allTargets.size() < controllerIds.size()) {
        throw new EntityNotFoundException(Target.class, controllerIds,
                allTargets.stream().map(Target::getControllerId).collect(Collectors.toList()));
    }

    final JpaTargetTag tag = targetTagRepository.findById(tagId)
            .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagId));

    allTargets.forEach(target -> target.addTag(tag));

    final List<Target> result = Collections
            .unmodifiableList(allTargets.stream().map(targetRepository::save).collect(Collectors.toList()));

    // No reason to save the tag
    entityManager.detach(tag);
    return result;
}
 
Example #20
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet assignSoftwareModules(final long setId, final Collection<Long> moduleIds) {

    final Collection<JpaSoftwareModule> modules = softwareModuleRepository.findByIdIn(moduleIds);

    if (modules.size() < moduleIds.size()) {
        throw new EntityNotFoundException(SoftwareModule.class, moduleIds,
                modules.stream().map(SoftwareModule::getId).collect(Collectors.toList()));
    }

    assertDistributionSetIsNotAssignedToTargets(setId);

    final JpaDistributionSet set = findDistributionSetAndThrowExceptionIfNotFound(setId);

    assertSoftwareModuleQuota(setId, modules.size());

    modules.forEach(set::addModule);

    return distributionSetRepository.save(set);
}
 
Example #21
Source File: JpaTargetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetMetadata updateMetadata(final String controllerId, final MetaData md) {

    // check if exists otherwise throw entity not found exception
    final JpaTargetMetadata updatedMetadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId,
            md.getKey()).orElseThrow(
                    () -> new EntityNotFoundException(TargetMetadata.class, controllerId, md.getKey()));
    updatedMetadata.setValue(md.getValue());
    // touch it to update the lock revision because we are modifying the
    // target indirectly
    final JpaTarget target = touch(controllerId);
    final JpaTargetMetadata matadata = targetMetadataRepository.save(updatedMetadata);
    // target update event is set to ignore "lastModifiedAt" field so it is
    // not send automatically within the touch() method
    eventPublisherHolder.getEventPublisher()
            .publishEvent(new TargetUpdatedEvent(target, eventPublisherHolder.getApplicationId()));
    return matadata;
}
 
Example #22
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetMetadata> createMetaData(final long dsId, final Collection<MetaData> md) {

    md.forEach(meta -> checkAndThrowIfDistributionSetMetadataAlreadyExists(
            new DsMetadataCompositeKey(dsId, meta.getKey())));

    assertMetaDataQuota(dsId, md.size());

    final JpaDistributionSet set = touch(dsId);

    return Collections.unmodifiableList(md.stream()
            .map(meta -> distributionSetMetadataRepository
                    .save(new JpaDistributionSetMetadata(meta.getKey(), set, meta.getValue())))
            .collect(Collectors.toList()));
}
 
Example #23
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetMetadata updateMetaData(final long dsId, final MetaData md) {

    // check if exists otherwise throw entity not found exception
    final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(dsId,
            md.getKey()).orElseThrow(
                    () -> new EntityNotFoundException(DistributionSetMetadata.class, dsId, md.getKey()));
    toUpdate.setValue(md.getValue());
    // touch it to update the lock revision because we are modifying the
    // DS indirectly
    touch(dsId);
    return distributionSetMetadataRepository.save(toUpdate);
}
 
Example #24
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet unAssignTag(final long dsId, final long dsTagId) {
    final JpaDistributionSet set = (JpaDistributionSet) getWithDetails(dsId)
            .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, dsId));

    final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId)
            .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));

    set.removeTag(distributionSetTag);

    final JpaDistributionSet result = distributionSetRepository.save(set);

    // No reason to save the tag
    entityManager.detach(distributionSetTag);
    return result;
}
 
Example #25
Source File: JpaTargetManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<Target> create(final Collection<TargetCreate> targets) {
    return targets.stream().map(this::create).collect(Collectors.toList());
}
 
Example #26
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> create(final Collection<DistributionSetCreate> creates) {
    return creates.stream().map(this::create).collect(Collectors.toList());
}
 
Example #27
Source File: JpaDistributionSetManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> distributionSetIDs) {
    final List<DistributionSet> setsFound = get(distributionSetIDs);

    if (setsFound.size() < distributionSetIDs.size()) {
        throw new EntityNotFoundException(DistributionSet.class, distributionSetIDs,
                setsFound.stream().map(DistributionSet::getId).collect(Collectors.toList()));
    }

    final List<Long> assigned = distributionSetRepository
            .findAssignedToTargetDistributionSetsById(distributionSetIDs);
    assigned.addAll(distributionSetRepository.findAssignedToRolloutDistributionSetsById(distributionSetIDs));

    // soft delete assigned
    if (!assigned.isEmpty()) {
        final Long[] dsIds = assigned.toArray(new Long[assigned.size()]);
        distributionSetRepository.deleteDistributionSet(dsIds);
        targetFilterQueryRepository.unsetAutoAssignDistributionSetAndActionType(dsIds);
    }

    // mark the rest as hard delete
    final List<Long> toHardDelete = distributionSetIDs.stream().filter(setId -> !assigned.contains(setId))
            .collect(Collectors.toList());

    // hard delete the rest if exists
    if (!toHardDelete.isEmpty()) {
        targetFilterQueryRepository
                .unsetAutoAssignDistributionSetAndActionType(toHardDelete.toArray(new Long[toHardDelete.size()]));
        // don't give the delete statement an empty list, JPA/Oracle cannot
        // handle the empty list
        distributionSetRepository.deleteByIdIn(toHardDelete);
    }

    afterCommit.afterCommit(() -> distributionSetIDs.forEach(dsId -> eventPublisherHolder.getEventPublisher()
            .publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(), dsId,
                    JpaDistributionSet.class.getName(), eventPublisherHolder.getApplicationId()))));
}
 
Example #28
Source File: JpaSoftwareModuleManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata createMetaData(final SoftwareModuleMetadataCreate c) {

    final JpaSoftwareModuleMetadataCreate create = (JpaSoftwareModuleMetadataCreate) c;
    final Long moduleId = create.getSoftwareModuleId();
    assertSoftwareModuleExists(moduleId);
    assertMetaDataQuota(moduleId, 1);

    return saveMetadata(create);
}
 
Example #29
Source File: JpaSoftwareModuleManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long moduleId) {
    delete(Arrays.asList(moduleId));
}
 
Example #30
Source File: JpaDistributionSetTypeManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType unassignSoftwareModuleType(final long dsTypeId, final long softwareModuleTypeId) {
    final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);

    checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);

    type.removeModuleType(softwareModuleTypeId);

    return distributionSetTypeRepository.save(type);
}