Search in sources :

Example 1 with AlreadyExistingItemException

use of com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesServiceImpl method createBridge.

@Transactional
@Override
public Bridge createBridge(String customerId, BridgeRequest bridgeRequest) {
    if (bridgeDAO.findByNameAndCustomerId(bridgeRequest.getName(), customerId) != null) {
        throw new AlreadyExistingItemException(String.format("Bridge with name '%s' already exists for customer with id '%s'", bridgeRequest.getName(), customerId));
    }
    Bridge bridge = bridgeRequest.toEntity();
    bridge.setStatus(ManagedResourceStatus.ACCEPTED);
    bridge.setSubmittedAt(ZonedDateTime.now(ZoneOffset.UTC));
    bridge.setCustomerId(customerId);
    bridge.setShardId(shardService.getAssignedShardId(bridge.getId()));
    bridgeDAO.persist(bridge);
    rhoasService.createTopicAndGrantAccessFor(getBridgeTopicName(bridge), RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    LOGGER.info("Bridge with id '{}' has been created for customer '{}'", bridge.getId(), bridge.getCustomerId());
    return bridge;
}
Also used : Bridge(com.redhat.service.bridge.manager.models.Bridge) AlreadyExistingItemException(com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException) Transactional(javax.transaction.Transactional)

Example 2 with AlreadyExistingItemException

use of com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method createProcessor.

@Override
public Processor createProcessor(String bridgeId, String customerId, ProcessorRequest processorRequest) {
    /* We cannot deploy Processors to a Bridge that is not Available */
    Bridge bridge = bridgesService.getReadyBridge(bridgeId, customerId);
    if (processorDAO.findByBridgeIdAndName(bridgeId, processorRequest.getName()) != null) {
        throw new AlreadyExistingItemException("Processor with name '" + processorRequest.getName() + "' already exists for bridge with id '" + bridgeId + "' for customer '" + customerId + "'");
    }
    Processor newProcessor = new Processor();
    Set<BaseFilter> requestedFilters = processorRequest.getFilters();
    String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
    BaseAction requestedAction = processorRequest.getAction();
    ActionProvider actionProvider = actionProviderFactory.getActionProvider(requestedAction.getType());
    BaseAction resolvedAction = actionProviderFactory.resolve(requestedAction, bridge.getId(), customerId, newProcessor.getId());
    newProcessor.setName(processorRequest.getName());
    newProcessor.setSubmittedAt(ZonedDateTime.now());
    newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    newProcessor.setBridge(bridge);
    newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
    ProcessorDefinition definition = new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, requestedAction, resolvedAction);
    newProcessor.setDefinition(definitionToJsonNode(definition));
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
    createProcessorConnectorEntity(newProcessor, actionProvider, resolvedAction);
    workManager.schedule(newProcessor);
    return newProcessor;
}
Also used : ActionProvider(com.redhat.service.bridge.actions.ActionProvider) Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) AlreadyExistingItemException(com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)

Aggregations

AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)2 Bridge (com.redhat.service.bridge.manager.models.Bridge)2 ActionProvider (com.redhat.service.bridge.actions.ActionProvider)1 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)1 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)1 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)1 Processor (com.redhat.service.bridge.manager.models.Processor)1 Transactional (javax.transaction.Transactional)1