Search in sources :

Example 1 with FlowComparisonEntity

use of org.apache.nifi.web.api.entity.FlowComparisonEntity 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;
}
Also used : FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) IOException(java.io.IOException) ConciseEvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) ComponentDifferenceDTO(org.apache.nifi.web.api.dto.ComponentDifferenceDTO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) FlowComparisonEntity(org.apache.nifi.web.api.entity.FlowComparisonEntity) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator)

Example 2 with FlowComparisonEntity

use of org.apache.nifi.web.api.entity.FlowComparisonEntity in project nifi by apache.

the class ProcessGroupResource method getLocalModifications.

/**
 * Retrieves a list of local modifications to the Process Group since it was last synchronized with the Flow Registry
 *
 * @param groupId The id of the process group.
 * @return A processGroupEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/local-modifications")
@ApiOperation(value = "Gets a list of local modifications to the Process Group since it was last synchronized with the Flow Registry", response = FlowComparisonEntity.class, authorizations = { @Authorization(value = "Read - /process-groups/{uuid}"), @Authorization(value = "Read - /{component-type}/{uuid} - For all encapsulated components") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getLocalModifications(@ApiParam(value = "The process group id.", required = false) @PathParam("id") final String groupId) throws IOException, NiFiRegistryException {
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final ProcessGroupAuthorizable groupAuthorizable = lookup.getProcessGroup(groupId);
        authorizeProcessGroup(groupAuthorizable, authorizer, lookup, RequestAction.READ, false, false, true, false);
    });
    final FlowComparisonEntity entity = serviceFacade.getLocalModifications(groupId);
    return generateOkResponse(entity).build();
}
Also used : ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) FlowComparisonEntity(org.apache.nifi.web.api.entity.FlowComparisonEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

FlowComparisonEntity (org.apache.nifi.web.api.entity.FlowComparisonEntity)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ProcessGroupAuthorizable (org.apache.nifi.authorization.ProcessGroupAuthorizable)1 ProcessGroup (org.apache.nifi.groups.ProcessGroup)1 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)1 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)1 FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)1 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)1 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)1 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)1 ComparableDataFlow (org.apache.nifi.registry.flow.diff.ComparableDataFlow)1 ConciseEvolvingDifferenceDescriptor (org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor)1 FlowComparator (org.apache.nifi.registry.flow.diff.FlowComparator)1 FlowComparison (org.apache.nifi.registry.flow.diff.FlowComparison)1