Search in sources :

Example 1 with AlreadyExistingItemException

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

the class BridgesServiceImpl method createBridge.

@Override
@Transactional
public Bridge createBridge(String customerId, String organisationId, String owner, 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.setOrganisationId(organisationId);
    bridge.setOwner(owner);
    bridge.setShardId(shardService.getAssignedShardId(bridge.getId()));
    // Ensure we connect the ErrorHandler Action to the ErrorHandler back-channel
    Action errorHandler = bridgeRequest.getErrorHandler();
    bridge.setDefinition(new BridgeDefinition(Objects.nonNull(errorHandler) ? errorHandler : null));
    // Bridge and Work creation should always be in the same transaction
    bridgeDAO.persist(bridge);
    workManager.schedule(bridge);
    metricsService.onOperationStart(bridge, MetricsOperation.PROVISION);
    LOGGER.info("Bridge with id '{}' has been created for customer '{}'", bridge.getId(), bridge.getCustomerId());
    return bridge;
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge) AlreadyExistingItemException(com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException) Transactional(javax.transaction.Transactional)

Example 2 with AlreadyExistingItemException

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

the class ProcessorServiceImpl method doCreateProcessor.

private Processor doCreateProcessor(Bridge bridge, String customerId, String owner, ProcessorType processorType, ProcessorRequest processorRequest) {
    String bridgeId = bridge.getId();
    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();
    newProcessor.setType(processorType);
    newProcessor.setName(processorRequest.getName());
    newProcessor.setSubmittedAt(ZonedDateTime.now());
    newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    newProcessor.setBridge(bridge);
    newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
    newProcessor.setOwner(owner);
    Set<BaseFilter> requestedFilters = processorRequest.getFilters();
    String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
    Action resolvedAction = processorType == ProcessorType.SOURCE ? resolveSource(processorRequest.getSource(), customerId, bridge.getId(), newProcessor.getId()) : resolveAction(processorRequest.getAction(), customerId, bridge.getId(), newProcessor.getId());
    ProcessorDefinition definition = processorType == ProcessorType.SOURCE ? new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, processorRequest.getSource(), resolvedAction) : new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, processorRequest.getAction(), resolvedAction);
    newProcessor.setDefinition(definition);
    // Processor, Connector and Work should always be created in the same transaction
    processorDAO.persist(newProcessor);
    connectorService.createConnectorEntity(newProcessor);
    workManager.schedule(newProcessor);
    metricsService.onOperationStart(newProcessor, MetricsOperation.PROVISION);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
    return newProcessor;
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) AlreadyExistingItemException(com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException)

Aggregations

AlreadyExistingItemException (com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException)2 Action (com.redhat.service.smartevents.infra.models.gateways.Action)2 BridgeDefinition (com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition)1 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)1 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)1 Bridge (com.redhat.service.smartevents.manager.models.Bridge)1 Processor (com.redhat.service.smartevents.manager.models.Processor)1 Transactional (javax.transaction.Transactional)1