use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class StandardNiFiServiceFacade method createControllerService.
@Override
public ControllerServiceEntity createControllerService(final Revision revision, final String groupId, final ControllerServiceDTO controllerServiceDTO) {
controllerServiceDTO.setParentGroupId(groupId);
final NiFiUser user = NiFiUserUtils.getNiFiUser();
// request claim for component to be created... revision already verified (version == 0)
final RevisionClaim claim = new StandardRevisionClaim(revision);
final RevisionUpdate<ControllerServiceDTO> snapshot;
if (groupId == null) {
// update revision through revision manager
snapshot = revisionManager.updateRevision(claim, user, () -> {
// Unfortunately, we can not use the createComponent() method here because createComponent() wants to obtain the read lock
// on the group. The Controller Service may or may not have a Process Group (it won't if it's controller-scoped).
final ControllerServiceNode controllerService = controllerServiceDAO.createControllerService(controllerServiceDTO);
final ControllerServiceDTO dto = dtoFactory.createControllerServiceDto(controllerService);
controllerFacade.save();
final FlowModification lastMod = new FlowModification(revision.incrementRevision(revision.getClientId()), user.getIdentity());
return new StandardRevisionUpdate<>(dto, lastMod);
});
} else {
snapshot = revisionManager.updateRevision(claim, user, () -> {
final ControllerServiceNode controllerService = controllerServiceDAO.createControllerService(controllerServiceDTO);
final ControllerServiceDTO dto = dtoFactory.createControllerServiceDto(controllerService);
controllerFacade.save();
final FlowModification lastMod = new FlowModification(revision.incrementRevision(revision.getClientId()), user.getIdentity());
return new StandardRevisionUpdate<>(dto, lastMod);
});
}
final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(controllerService);
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(controllerServiceDTO.getId()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
}
use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class StandardNiFiServiceFacade method getProcessGroupBulletins.
private List<BulletinEntity> getProcessGroupBulletins(final ProcessGroup group) {
final List<Bulletin> bulletins = new ArrayList<>(bulletinRepository.findBulletinsForGroupBySource(group.getIdentifier()));
for (final ProcessGroup descendantGroup : group.findAllProcessGroups()) {
bulletins.addAll(bulletinRepository.findBulletinsForGroupBySource(descendantGroup.getIdentifier()));
}
List<BulletinEntity> bulletinEntities = new ArrayList<>();
for (final Bulletin bulletin : bulletins) {
bulletinEntities.add(entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), authorizeBulletin(bulletin)));
}
return pruneAndSortBulletins(bulletinEntities, BulletinRepository.MAX_BULLETINS_PER_COMPONENT);
}
use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class StandardNiFiServiceFacade method updateInputPort.
@Override
public PortEntity updateInputPort(final Revision revision, final PortDTO inputPortDTO) {
final Port inputPortNode = inputPortDAO.getPort(inputPortDTO.getId());
final RevisionUpdate<PortDTO> snapshot = updateComponent(revision, inputPortNode, () -> inputPortDAO.updatePort(inputPortDTO), port -> dtoFactory.createPortDto(port));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(inputPortNode);
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getInputPortStatus(inputPortNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(inputPortNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
}
use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class BulletinMergerTest method mergeBulletins.
@Test
public void mergeBulletins() throws Exception {
final BulletinEntity bulletinEntity1 = createBulletin("This is bulletin 1");
final BulletinEntity bulletinEntity2 = createBulletin("This is bulletin 2");
final BulletinEntity unauthorizedBulletin = new BulletinEntity();
unauthorizedBulletin.setId(bulletinId++);
unauthorizedBulletin.setTimestamp(new Date());
unauthorizedBulletin.setCanRead(false);
final BulletinEntity copyOfBulletin1 = createBulletin("This is bulletin 1");
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);
final Map<NodeIdentifier, List<BulletinEntity>> nodeMap = new HashMap<>();
nodeMap.put(node1, new ArrayList<>());
nodeMap.put(node2, new ArrayList<>());
nodeMap.get(node1).add(bulletinEntity1);
nodeMap.get(node1).add(bulletinEntity2);
nodeMap.get(node1).add(unauthorizedBulletin);
nodeMap.get(node2).add(copyOfBulletin1);
final List<BulletinEntity> bulletinEntities = BulletinMerger.mergeBulletins(nodeMap, nodeMap.size());
assertEquals(bulletinEntities.size(), 3);
assertTrue(bulletinEntities.contains(copyOfBulletin1));
assertEquals(copyOfBulletin1.getNodeAddress(), ALL_NODES_MESSAGE);
assertTrue(bulletinEntities.contains(bulletinEntity2));
assertTrue(bulletinEntities.contains(unauthorizedBulletin));
}
use of org.apache.nifi.web.api.entity.BulletinEntity in project nifi by apache.
the class ControllerBulletinsEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(ControllerBulletinsEntity clientEntity, Map<NodeIdentifier, ControllerBulletinsEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
final Map<NodeIdentifier, List<BulletinEntity>> bulletinDtos = new HashMap<>();
final Map<NodeIdentifier, List<BulletinEntity>> controllerServiceBulletinDtos = new HashMap<>();
final Map<NodeIdentifier, List<BulletinEntity>> reportingTaskBulletinDtos = new HashMap<>();
for (final Map.Entry<NodeIdentifier, ControllerBulletinsEntity> entry : entityMap.entrySet()) {
final NodeIdentifier nodeIdentifier = entry.getKey();
final ControllerBulletinsEntity entity = entry.getValue();
final String nodeAddress = nodeIdentifier.getApiAddress() + ":" + nodeIdentifier.getApiPort();
// consider the bulletins if present and authorized
if (entity.getBulletins() != null) {
entity.getBulletins().forEach(bulletin -> {
if (bulletin.getNodeAddress() == null) {
bulletin.setNodeAddress(nodeAddress);
}
bulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
});
}
if (entity.getControllerServiceBulletins() != null) {
entity.getControllerServiceBulletins().forEach(bulletin -> {
if (bulletin.getNodeAddress() == null) {
bulletin.setNodeAddress(nodeAddress);
}
controllerServiceBulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
});
}
if (entity.getReportingTaskBulletins() != null) {
entity.getReportingTaskBulletins().forEach(bulletin -> {
if (bulletin.getNodeAddress() == null) {
bulletin.setNodeAddress(nodeAddress);
}
reportingTaskBulletinDtos.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
});
}
}
clientEntity.setBulletins(BulletinMerger.mergeBulletins(bulletinDtos, entityMap.size()));
clientEntity.setControllerServiceBulletins(BulletinMerger.mergeBulletins(controllerServiceBulletinDtos, entityMap.size()));
clientEntity.setReportingTaskBulletins(BulletinMerger.mergeBulletins(reportingTaskBulletinDtos, entityMap.size()));
// sort the bulletins
Collections.sort(clientEntity.getBulletins(), BULLETIN_COMPARATOR);
Collections.sort(clientEntity.getControllerServiceBulletins(), BULLETIN_COMPARATOR);
Collections.sort(clientEntity.getReportingTaskBulletins(), BULLETIN_COMPARATOR);
// prune the response to only include the max number of bulletins
if (clientEntity.getBulletins().size() > MAX_BULLETINS_FOR_CONTROLLER) {
clientEntity.setBulletins(clientEntity.getBulletins().subList(0, MAX_BULLETINS_FOR_CONTROLLER));
}
if (clientEntity.getControllerServiceBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
clientEntity.setControllerServiceBulletins(clientEntity.getControllerServiceBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
}
if (clientEntity.getReportingTaskBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
clientEntity.setReportingTaskBulletins(clientEntity.getReportingTaskBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
}
}
Aggregations