use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class StandardNiFiServiceFacade method getLocalModifications.
@Override
public FlowComparisonEntity getLocalModifications(final String processGroupId) {
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupId);
final VersionControlInformation versionControlInfo = processGroup.getVersionControlInformation();
if (versionControlInfo == null) {
throw new IllegalStateException("Process Group with ID " + processGroupId + " is not under Version Control");
}
final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(versionControlInfo.getRegistryIdentifier());
if (flowRegistry == null) {
throw new IllegalStateException("Process Group with ID " + processGroupId + " is tracking to a flow in Flow Registry with ID " + versionControlInfo.getRegistryIdentifier() + " but cannot find a Flow Registry with that identifier");
}
final VersionedFlowSnapshot versionedFlowSnapshot;
try {
versionedFlowSnapshot = flowRegistry.getFlowContents(versionControlInfo.getBucketIdentifier(), versionControlInfo.getFlowIdentifier(), versionControlInfo.getVersion(), true, NiFiUserUtils.getNiFiUser());
} catch (final IOException | NiFiRegistryException e) {
throw new NiFiCoreException("Failed to retrieve flow with Flow Registry in order to calculate local differences due to " + e.getMessage(), e);
}
final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper();
final VersionedProcessGroup localGroup = mapper.mapProcessGroup(processGroup, controllerFacade.getControllerServiceProvider(), flowRegistryClient, true);
final VersionedProcessGroup registryGroup = versionedFlowSnapshot.getFlowContents();
final ComparableDataFlow localFlow = new StandardComparableDataFlow("Local Flow", localGroup);
final ComparableDataFlow registryFlow = new StandardComparableDataFlow("Versioned Flow", registryGroup);
final Set<String> ancestorServiceIds = getAncestorGroupServiceIds(processGroup);
final FlowComparator flowComparator = new StandardFlowComparator(registryFlow, localFlow, ancestorServiceIds, new ConciseEvolvingDifferenceDescriptor());
final FlowComparison flowComparison = flowComparator.compare();
final Set<ComponentDifferenceDTO> differenceDtos = dtoFactory.createComponentDifferenceDtos(flowComparison);
final FlowComparisonEntity entity = new FlowComparisonEntity();
entity.setComponentDifferences(differenceDtos);
return entity;
}
use of org.apache.nifi.groups.ProcessGroup 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.groups.ProcessGroup in project nifi by apache.
the class StandardNiFiServiceFacade method getSiteToSiteDetails.
@Override
public ControllerDTO getSiteToSiteDetails() {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
if (user == null) {
throw new WebApplicationException(new Throwable("Unable to access details for current user."));
}
// serialize the input ports this NiFi has access to
final Set<PortDTO> inputPortDtos = new LinkedHashSet<>();
final Set<RootGroupPort> inputPorts = controllerFacade.getInputPorts();
for (final RootGroupPort inputPort : inputPorts) {
if (isUserAuthorized(user, inputPort)) {
final PortDTO dto = new PortDTO();
dto.setId(inputPort.getIdentifier());
dto.setName(inputPort.getName());
dto.setComments(inputPort.getComments());
dto.setState(inputPort.getScheduledState().toString());
inputPortDtos.add(dto);
}
}
// serialize the output ports this NiFi has access to
final Set<PortDTO> outputPortDtos = new LinkedHashSet<>();
for (final RootGroupPort outputPort : controllerFacade.getOutputPorts()) {
if (isUserAuthorized(user, outputPort)) {
final PortDTO dto = new PortDTO();
dto.setId(outputPort.getIdentifier());
dto.setName(outputPort.getName());
dto.setComments(outputPort.getComments());
dto.setState(outputPort.getScheduledState().toString());
outputPortDtos.add(dto);
}
}
// get the root group
final ProcessGroup rootGroup = processGroupDAO.getProcessGroup(controllerFacade.getRootGroupId());
final ProcessGroupCounts counts = rootGroup.getCounts();
// create the controller dto
final ControllerDTO controllerDTO = new ControllerDTO();
controllerDTO.setId(controllerFacade.getRootGroupId());
controllerDTO.setInstanceId(controllerFacade.getInstanceId());
controllerDTO.setName(controllerFacade.getName());
controllerDTO.setComments(controllerFacade.getComments());
controllerDTO.setInputPorts(inputPortDtos);
controllerDTO.setOutputPorts(outputPortDtos);
controllerDTO.setInputPortCount(inputPortDtos.size());
controllerDTO.setOutputPortCount(outputPortDtos.size());
controllerDTO.setRunningCount(counts.getRunningCount());
controllerDTO.setStoppedCount(counts.getStoppedCount());
controllerDTO.setInvalidCount(counts.getInvalidCount());
controllerDTO.setDisabledCount(counts.getDisabledCount());
// determine the site to site configuration
controllerDTO.setRemoteSiteListeningPort(controllerFacade.getRemoteSiteListeningPort());
controllerDTO.setRemoteSiteHttpListeningPort(controllerFacade.getRemoteSiteListeningHttpPort());
controllerDTO.setSiteToSiteSecure(controllerFacade.isRemoteSiteCommsSecure());
return controllerDTO;
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class StandardNiFiServiceFacade method getProcessGroupFlow.
@Override
public ProcessGroupFlowEntity getProcessGroupFlow(final String groupId) {
// get all identifiers for every child component
final Set<String> identifiers = new HashSet<>();
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
processGroup.getProcessors().stream().map(proc -> proc.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getConnections().stream().map(conn -> conn.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getInputPorts().stream().map(port -> port.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getOutputPorts().stream().map(port -> port.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getProcessGroups().stream().map(group -> group.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getRemoteProcessGroups().stream().map(remoteGroup -> remoteGroup.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getRemoteProcessGroups().stream().flatMap(remoteGroup -> remoteGroup.getInputPorts().stream()).map(remoteInputPort -> remoteInputPort.getIdentifier()).forEach(id -> identifiers.add(id));
processGroup.getRemoteProcessGroups().stream().flatMap(remoteGroup -> remoteGroup.getOutputPorts().stream()).map(remoteOutputPort -> remoteOutputPort.getIdentifier()).forEach(id -> identifiers.add(id));
// read lock on every component being accessed in the dto conversion
final ProcessGroupStatus groupStatus = controllerFacade.getProcessGroupStatus(groupId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroup);
return entityFactory.createProcessGroupFlowEntity(dtoFactory.createProcessGroupFlowDto(processGroup, groupStatus, revisionManager, this::getProcessGroupBulletins), permissions);
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class StandardNiFiServiceFacade method verifyCanUpdate.
@Override
public void verifyCanUpdate(final String groupId, final VersionedFlowSnapshot proposedFlow, final boolean verifyConnectionRemoval, final boolean verifyNotDirty) {
final ProcessGroup group = processGroupDAO.getProcessGroup(groupId);
group.verifyCanUpdate(proposedFlow, verifyConnectionRemoval, verifyNotDirty);
}
Aggregations