use of com.redhat.service.bridge.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method getProcessor.
@Transactional
@Override
public Processor getProcessor(String processorId, String bridgeId, String customerId) {
Bridge bridge = bridgesService.getBridge(bridgeId, customerId);
Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(processorId, bridge.getId(), bridge.getCustomerId());
if (processor == null) {
throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on Bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
}
return processor;
}
use of com.redhat.service.bridge.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method doDeleteProcessor.
@Transactional
protected Processor doDeleteProcessor(String bridgeId, String processorId, String customerId) {
Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(processorId, bridgeId, customerId);
if (processor == null) {
throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
}
processor.setStatus(ManagedResourceStatus.DEPROVISION);
LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for deletion", processor.getId(), processor.getBridge().getCustomerId(), processor.getBridge().getId());
connectorService.deleteConnectorEntity(processor);
return processor;
}
use of com.redhat.service.bridge.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method updateProcessorStatus.
@Transactional
@Override
public Processor updateProcessorStatus(ProcessorDTO processorDTO) {
Bridge bridge = bridgesService.getBridge(processorDTO.getBridgeId());
Processor p = processorDAO.findById(processorDTO.getId());
if (p == null) {
throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist for Bridge '%s' for customer '%s'", bridge.getId(), bridge.getCustomerId(), processorDTO.getCustomerId()));
}
p.setStatus(processorDTO.getStatus());
p.setModifiedAt(ZonedDateTime.now());
if (processorDTO.getStatus().equals(ManagedResourceStatus.DELETED)) {
processorDAO.deleteById(processorDTO.getId());
}
if (processorDTO.getStatus().equals(ManagedResourceStatus.READY) && Objects.isNull(p.getPublishedAt())) {
p.setPublishedAt(ZonedDateTime.now());
}
// Update metrics
meterRegistry.counter("manager.processor.status.change", Collections.singletonList(Tag.of("status", processorDTO.getStatus().toString()))).increment();
return p;
}
use of com.redhat.service.bridge.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method deleteProcessor.
@Override
public void deleteProcessor(String bridgeId, String processorId, String customerId) {
Processor processor = doDeleteProcessor(bridgeId, processorId, customerId);
workManager.schedule(processor);
}
use of com.redhat.service.bridge.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithConnector.
@ParameterizedTest
@MethodSource("srcHandleWorkProvisioningWithKnownResourceWithConnector")
void handleWorkProvisioningWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = new Processor();
processor.setStatus(status);
ConnectorEntity connector = new ConnectorEntity();
connector.setStatus(ManagedResourceStatus.ACCEPTED);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
when(processorDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(processor)).thenReturn(processor);
when(connectorsDAO.findByProcessorId(processor.getId())).thenReturn(connector);
doAnswer((i) -> {
// Emulate ConnectorWorker completing work
connector.setStatus(connectorStatusWhenComplete);
return connector;
}).when(connectorWorker).handleWork(any(Work.class));
worker.handleWork(work);
assertThat(processor.getDependencyStatus()).isEqualTo(connectorStatusWhenComplete);
verify(connectorWorker).handleWork(workArgumentCaptor.capture());
Work connectorWork = workArgumentCaptor.getValue();
assertThat(connectorWork).isNotNull();
assertThat(connectorWork.getId()).isEqualTo(work.getId());
assertThat(connectorWork.getManagedResourceId()).isEqualTo(connector.getId());
assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
verify(workManager, times(isWorkComplete ? 1 : 0)).complete(any(Work.class));
}
Aggregations