use of org.apache.nifi.web.api.dto.RevisionDTO in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method create.
@Nonnull
@Override
public ProcessGroupDTO create(@Nonnull String parentProcessGroupId, @Nonnull String name) {
final ProcessGroupEntity entity = new ProcessGroupEntity();
final ProcessGroupDTO processGroup = new ProcessGroupDTO();
processGroup.setName(name);
entity.setComponent(processGroup);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
try {
return client.post(BASE_PATH + parentProcessGroupId + "/process-groups", entity, ProcessGroupEntity.class).getComponent();
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(parentProcessGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
}
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.
the class StandardNiFiServiceFacade method registerFlowWithFlowRegistry.
@Override
public VersionControlComponentMappingEntity registerFlowWithFlowRegistry(final String groupId, final StartVersionControlRequestEntity requestEntity) {
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
final VersionControlInformation currentVci = processGroup.getVersionControlInformation();
final int expectedVersion = currentVci == null ? 1 : currentVci.getVersion() + 1;
// Create a VersionedProcessGroup snapshot of the flow as it is currently.
final InstantiatedVersionedProcessGroup versionedProcessGroup = createFlowSnapshot(groupId);
final VersionedFlowDTO versionedFlowDto = requestEntity.getVersionedFlow();
final String flowId = versionedFlowDto.getFlowId() == null ? UUID.randomUUID().toString() : versionedFlowDto.getFlowId();
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setBucketIdentifier(versionedFlowDto.getBucketId());
versionedFlow.setCreatedTimestamp(System.currentTimeMillis());
versionedFlow.setDescription(versionedFlowDto.getDescription());
versionedFlow.setModifiedTimestamp(versionedFlow.getCreatedTimestamp());
versionedFlow.setName(versionedFlowDto.getFlowName());
versionedFlow.setIdentifier(flowId);
// Add the Versioned Flow and first snapshot to the Flow Registry
final String registryId = requestEntity.getVersionedFlow().getRegistryId();
final VersionedFlowSnapshot registeredSnapshot;
final VersionedFlow registeredFlow;
String action = "create the flow";
try {
// first, create the flow in the registry, if necessary
if (versionedFlowDto.getFlowId() == null) {
registeredFlow = registerVersionedFlow(registryId, versionedFlow);
} else {
registeredFlow = getVersionedFlow(registryId, versionedFlowDto.getBucketId(), versionedFlowDto.getFlowId());
}
action = "add the local flow to the Flow Registry as the first Snapshot";
// add first snapshot to the flow in the registry
registeredSnapshot = registerVersionedFlowSnapshot(registryId, registeredFlow, versionedProcessGroup, versionedFlowDto.getComments(), expectedVersion);
} catch (final NiFiRegistryException e) {
throw new IllegalArgumentException(e.getLocalizedMessage());
} catch (final IOException ioe) {
throw new IllegalStateException("Failed to communicate with Flow Registry when attempting to " + action);
}
final Bucket bucket = registeredSnapshot.getBucket();
final VersionedFlow flow = registeredSnapshot.getFlow();
// Update the Process Group with the new VersionControlInformation. (Send this to all nodes).
final VersionControlInformationDTO vci = new VersionControlInformationDTO();
vci.setBucketId(bucket.getIdentifier());
vci.setBucketName(bucket.getName());
vci.setFlowId(flow.getIdentifier());
vci.setFlowName(flow.getName());
vci.setFlowDescription(flow.getDescription());
vci.setGroupId(groupId);
vci.setRegistryId(registryId);
vci.setRegistryName(getFlowRegistryName(registryId));
vci.setVersion(registeredSnapshot.getSnapshotMetadata().getVersion());
vci.setState(VersionedFlowState.UP_TO_DATE.name());
final Map<String, String> mapping = dtoFactory.createVersionControlComponentMappingDto(versionedProcessGroup);
final Revision groupRevision = revisionManager.getRevision(groupId);
final RevisionDTO groupRevisionDto = dtoFactory.createRevisionDTO(groupRevision);
final VersionControlComponentMappingEntity entity = new VersionControlComponentMappingEntity();
entity.setVersionControlInformation(vci);
entity.setProcessGroupRevision(groupRevisionDto);
entity.setVersionControlComponentMapping(mapping);
return entity;
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.
the class StandardNiFiServiceFacade method createAccessPolicyEntity.
private AccessPolicyEntity createAccessPolicyEntity(final AccessPolicy accessPolicy) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(accessPolicy.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizableLookup.getAccessPolicyById(accessPolicy.getIdentifier()));
final ComponentReferenceEntity componentReference = createComponentReferenceEntity(accessPolicy.getResource());
return entityFactory.createAccessPolicyEntity(dtoFactory.createAccessPolicyDto(accessPolicy, accessPolicy.getGroups().stream().map(mapUserGroupIdToTenantEntity()).collect(Collectors.toSet()), accessPolicy.getUsers().stream().map(mapUserIdToTenantEntity()).collect(Collectors.toSet()), componentReference), revision, permissions);
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.
the class StandardNiFiServiceFacade method getProcessorDiagnostics.
@Override
public ProcessorDiagnosticsEntity getProcessorDiagnostics(final String id) {
final ProcessorNode processor = processorDAO.getProcessor(id);
final ProcessorStatus processorStatus = controllerFacade.getProcessorStatus(id);
// Generate Processor Diagnostics
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final ProcessorDiagnosticsDTO dto = controllerFacade.getProcessorDiagnostics(processor, processorStatus, bulletinRepository, serviceId -> createControllerServiceEntity(serviceId, user));
// Filter anything out of diagnostics that the user is not authorized to see.
final List<JVMDiagnosticsSnapshotDTO> jvmDiagnosticsSnaphots = new ArrayList<>();
final JVMDiagnosticsDTO jvmDiagnostics = dto.getJvmDiagnostics();
jvmDiagnosticsSnaphots.add(jvmDiagnostics.getAggregateSnapshot());
// filter controller-related information
final boolean canReadController = authorizableLookup.getController().isAuthorized(authorizer, RequestAction.READ, user);
if (!canReadController) {
for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
snapshot.setControllerDiagnostics(null);
}
}
// filter system diagnostics information
final boolean canReadSystem = authorizableLookup.getSystem().isAuthorized(authorizer, RequestAction.READ, user);
if (!canReadSystem) {
for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
snapshot.setSystemDiagnosticsDto(null);
}
}
final boolean canReadFlow = authorizableLookup.getFlow().isAuthorized(authorizer, RequestAction.READ, user);
if (!canReadFlow) {
for (final JVMDiagnosticsSnapshotDTO snapshot : jvmDiagnosticsSnaphots) {
snapshot.setFlowDiagnosticsDto(null);
}
}
// filter connections
final Predicate<ConnectionDiagnosticsDTO> connectionAuthorized = connectionDiagnostics -> {
final String connectionId = connectionDiagnostics.getConnection().getId();
return authorizableLookup.getConnection(connectionId).getAuthorizable().isAuthorized(authorizer, RequestAction.READ, user);
};
// Filter incoming connections by what user is authorized to READ
final Set<ConnectionDiagnosticsDTO> incoming = dto.getIncomingConnections();
final Set<ConnectionDiagnosticsDTO> filteredIncoming = incoming.stream().filter(connectionAuthorized).collect(Collectors.toSet());
dto.setIncomingConnections(filteredIncoming);
// Filter outgoing connections by what user is authorized to READ
final Set<ConnectionDiagnosticsDTO> outgoing = dto.getOutgoingConnections();
final Set<ConnectionDiagnosticsDTO> filteredOutgoing = outgoing.stream().filter(connectionAuthorized).collect(Collectors.toSet());
dto.setOutgoingConnections(filteredOutgoing);
// Filter out any controller services that are referenced by the Processor
final Set<ControllerServiceDiagnosticsDTO> referencedServices = dto.getReferencedControllerServices();
final Set<ControllerServiceDiagnosticsDTO> filteredReferencedServices = referencedServices.stream().filter(csDiagnostics -> {
final String csId = csDiagnostics.getControllerService().getId();
return authorizableLookup.getControllerService(csId).getAuthorizable().isAuthorized(authorizer, RequestAction.READ, user);
}).map(csDiagnostics -> {
// Filter out any referencing components because those are generally not relevant from this context.
final ControllerServiceDTO serviceDto = csDiagnostics.getControllerService().getComponent();
if (serviceDto != null) {
serviceDto.setReferencingComponents(null);
}
return csDiagnostics;
}).collect(Collectors.toSet());
dto.setReferencedControllerServices(filteredReferencedServices);
final Revision revision = revisionManager.getRevision(id);
final RevisionDTO revisionDto = dtoFactory.createRevisionDTO(revision);
final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(processor);
final List<BulletinEntity> bulletins = bulletinRepository.findBulletinsForSource(id).stream().map(bulletin -> dtoFactory.createBulletinDto(bulletin)).map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissionsDto.getCanRead())).collect(Collectors.toList());
final ProcessorStatusDTO processorStatusDto = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processor.getIdentifier()));
return entityFactory.createProcessorDiagnosticsEntity(dto, revisionDto, permissionsDto, processorStatusDto, bulletins);
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.
the class StandardNiFiServiceFacade method createOutputPortEntity.
private PortEntity createOutputPortEntity(final Port port, final NiFiUser user) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(port.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port, user);
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getOutputPortStatus(port.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(port.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createPortEntity(dtoFactory.createPortDto(port), revision, permissions, status, bulletinEntities);
}
Aggregations