org.springframework.retry.annotation.Retryable Java Examples

The following examples show how to use org.springframework.retry.annotation.Retryable. 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: 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 #2
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 #3
Source File: RetryService.java    From bswen-project with Apache License 2.0 6 votes vote down vote up
@Retryable
public boolean mayFailMethod() throws Exception {
    retryTimes++;
    log.info("do mayFailMethod "+retryTimes);
    try {
        Thread.sleep(1000);
    }catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    if(retryTimes<3) {
        throw new Exception("failed");
    }else {
        log.info("mayFailMethod success");
        return true;
    }
}
 
Example #4
Source File: TopicFeature.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@Given("I successfully create a new open topic")
@Retryable(value = {StatusRuntimeException.class}, exceptionExpression = "#{message.contains('UNAVAILABLE') || " +
        "message.contains('RESOURCE_EXHAUSTED')}")
public void createNewOpenTopic() throws HederaStatusException {
    testInstantReference = Instant.now();

    TransactionReceipt receipt = topicClient
            .createTopic(topicClient.getSdkClient().getPayerPublicKey(), null);
    assertNotNull(receipt);
    ConsensusTopicId topicId = receipt.getConsensusTopicId();
    assertNotNull(topicId);

    consensusTopicId = topicId;
    mirrorConsensusTopicQuery = new MirrorConsensusTopicQuery()
            .setTopicId(consensusTopicId)
            .setStartTime(Instant.EPOCH);

    log.debug("Set mirrorConsensusTopicQuery with topic: {}, startTime: {}", consensusTopicId, Instant.EPOCH);
}
 
Example #5
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 #6
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 #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: 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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: TopicFeature.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@Given("I successfully create a new topic id")
@Retryable(value = {StatusRuntimeException.class}, exceptionExpression = "#{message.contains('UNAVAILABLE') || " +
        "message.contains('RESOURCE_EXHAUSTED')}")
public void createNewTopic() throws HederaStatusException {
    testInstantReference = Instant.now();

    submitKey = Ed25519PrivateKey.generate();
    Ed25519PublicKey submitPublicKey = submitKey.publicKey;
    log.debug("Topic creation PrivateKey : {}, PublicKey : {}", submitKey, submitPublicKey);

    TransactionReceipt receipt = topicClient
            .createTopic(topicClient.getSdkClient().getPayerPublicKey(), submitPublicKey);
    assertNotNull(receipt);
    ConsensusTopicId topicId = receipt.getConsensusTopicId();
    assertNotNull(topicId);

    consensusTopicId = topicId;
    mirrorConsensusTopicQuery = new MirrorConsensusTopicQuery()
            .setTopicId(consensusTopicId)
            .setStartTime(Instant.EPOCH);

    log.debug("Set mirrorConsensusTopicQuery with topic: {}, startTime: {}", consensusTopicId, Instant.EPOCH);
}
 
Example #15
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 #16
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 #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: 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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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);
}
 
Example #25
Source File: JpaControllerManagement.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 ActionStatus addInformationalActionStatus(final ActionStatusCreate c) {
    final JpaActionStatusCreate create = (JpaActionStatusCreate) c;
    final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
    final JpaActionStatus statusMessage = create.build();
    statusMessage.setAction(action);

    assertActionStatusQuota(action);
    assertActionStatusMessageQuota(statusMessage);

    return actionStatusRepository.save(statusMessage);
}
 
Example #26
Source File: JpaControllerManagement.java    From hawkbit with Eclipse Public License 1.0 5 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 addCancelActionStatus(final ActionStatusCreate c) {
    final JpaActionStatusCreate create = (JpaActionStatusCreate) c;

    final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());

    if (!action.isCancelingOrCanceled()) {
        throw new CancelActionNotAllowedException("The action is not in canceling state.");
    }

    final JpaActionStatus actionStatus = create.build();

    switch (actionStatus.getStatus()) {
    case CANCELED:
    case FINISHED:
        handleFinishedCancelation(actionStatus, action);
        break;
    case ERROR:
    case CANCEL_REJECTED:
        // Cancellation rejected. Back to running.
        action.setStatus(Status.RUNNING);
        break;
    default:
        // information status entry - check for a potential DOS attack
        assertActionStatusQuota(action);
        assertActionStatusMessageQuota(actionStatus);
        break;
    }

    actionStatus.setAction(actionRepository.save(action));
    actionStatusRepository.save(actionStatus);

    return action;
}
 
Example #27
Source File: JpaSoftwareModuleTypeManagement.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> ids) {
    final List<JpaSoftwareModuleType> setsFound = softwareModuleTypeRepository.findAllById(ids);

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

    softwareModuleTypeRepository.deleteAll(setsFound);
}
 
Example #28
Source File: JpaTargetFilterQueryManagement.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 targetFilterQueryId) {
    if (!targetFilterQueryRepository.existsById(targetFilterQueryId)) {
        throw new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId);
    }

    targetFilterQueryRepository.deleteById(targetFilterQueryId);
}
 
Example #29
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 #30
Source File: ServiceCombConfigPropertySource.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
@Retryable(interceptor = "serviceCombConfigRetryInterceptor")
public Map<String, String> loadAllRemoteConfig(ServiceCombConfigProperties serviceCombConfigProperties,
    String project)
    throws RemoteOperationException {
  Map<String, String> remoteConfig = serviceCombConfigClient
      .loadAll(serviceCombConfigProperties, project);
  if (remoteConfig == null) {
    return Collections.emptyMap();
  }
  properties.putAll(remoteConfig);
  return remoteConfig;
}