public RegistryDTO createRegistryDto(FlowRegistry registry) { final RegistryDTO dto = new RegistryDTO(); dto.setDescription(registry.getDescription()); dto.setId(registry.getIdentifier()); dto.setName(registry.getName()); dto.setUri(registry.getURL()); return dto; }
private VersionedFlow getVersionedFlow(final String registryId, final String bucketId, final String flowId) throws IOException, NiFiRegistryException { final FlowRegistry registry = flowRegistryClient.getFlowRegistry(registryId); if (registry == null) { throw new ResourceNotFoundException("No Flow Registry exists with ID " + registryId); } return registry.getVersionedFlow(bucketId, flowId, NiFiUserUtils.getNiFiUser()); }
registry.setDescription(description); } else { throw new IllegalArgumentException("Cannot create Flow Registry with URI of " + registryUrl
@Override public void addFlowRegistry(final FlowRegistry registry) { final boolean duplicateName = registryById.values().stream() .anyMatch(reg -> reg.getName().equals(registry.getName())); if (duplicateName) { throw new IllegalStateException("Cannot add Flow Registry because a Flow Registry already exists with the name " + registry.getName()); } final FlowRegistry existing = registryById.putIfAbsent(registry.getIdentifier(), registry); if (existing != null) { throw new IllegalStateException("Cannot add Flow Registry " + registry + " because a Flow Registry already exists with the ID " + registry.getIdentifier()); } }
@Override public RegistryClientEntity updateRegistryClient(Revision revision, RegistryDTO registryDTO) { final RevisionClaim revisionClaim = new StandardRevisionClaim(revision); final NiFiUser user = NiFiUserUtils.getNiFiUser(); final FlowRegistry registry = registryDAO.getFlowRegistry(registryDTO.getId()); final RevisionUpdate<FlowRegistry> revisionUpdate = revisionManager.updateRevision(revisionClaim, user, () -> { final boolean duplicateName = registryDAO.getFlowRegistries().stream() .anyMatch(reg -> reg.getName().equals(registryDTO.getName()) && !reg.getIdentifier().equals(registryDTO.getId())); if (duplicateName) { throw new IllegalStateException("Cannot update Flow Registry because a Flow Registry already exists with the name " + registryDTO.getName()); } registry.setDescription(registryDTO.getDescription()); registry.setName(registryDTO.getName()); registry.setURL(registryDTO.getUri()); controllerFacade.save(); final Revision updatedRevision = revisionManager.getRevision(revision.getComponentId()).incrementRevision(revision.getClientId()); final FlowModification lastModification = new FlowModification(updatedRevision, user.getIdentity()); return new StandardRevisionUpdate<>(registry, lastModification); }); final FlowRegistry updatedReg = revisionUpdate.getComponent(); return createRegistryClientEntity(updatedReg); }
final VersionedFlowSnapshot registrySnapshot = flowRegistry.getFlowContents(vci.getBucketIdentifier(), vci.getFlowIdentifier(), vci.getVersion(), false); final VersionedProcessGroup registryFlow = registrySnapshot.getFlowContents(); vci.setFlowSnapshot(registryFlow); final VersionedFlow versionedFlow = flowRegistry.getVersionedFlow(vci.getBucketIdentifier(), vci.getFlowIdentifier()); final int latestVersion = (int) versionedFlow.getVersionCount(); vci.setBucketName(versionedFlow.getBucketName()); vci.setFlowName(versionedFlow.getName()); vci.setFlowDescription(versionedFlow.getDescription()); vci.setRegistryName(flowRegistry.getName());
default String getFlowRegistryId(String registryUrl) { if (registryUrl.endsWith("/")) { registryUrl = registryUrl.substring(0, registryUrl.length() - 1); } for (final String registryClientId : getRegistryIdentifiers()) { final FlowRegistry registry = getFlowRegistry(registryClientId); String registryClientUrl = registry.getURL(); if (registryClientUrl.endsWith("/")) { registryClientUrl = registryClientUrl.substring(0, registryClientUrl.length() - 1); } if (registryClientUrl.equals(registryUrl)) { return registryClientId; } } return null; }
@Override public String getFlowRegistryName(final String flowRegistryId) { final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(flowRegistryId); return flowRegistry == null ? flowRegistryId : flowRegistry.getName(); }
@Override public VersionedFlowSnapshot getVersionedFlowSnapshot(final VersionControlInformationDTO versionControlInfo, final boolean fetchRemoteFlows) { final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(versionControlInfo.getRegistryId()); if (flowRegistry == null) { throw new ResourceNotFoundException("Could not find any Flow Registry registered with identifier " + versionControlInfo.getRegistryId()); } final VersionedFlowSnapshot snapshot; try { snapshot = flowRegistry.getFlowContents(versionControlInfo.getBucketId(), versionControlInfo.getFlowId(), versionControlInfo.getVersion(), fetchRemoteFlows, NiFiUserUtils.getNiFiUser()); } catch (final NiFiRegistryException | IOException e) { logger.error(e.getMessage(), e); throw new IllegalArgumentException("The Flow Registry with ID " + versionControlInfo.getRegistryId() + " reports that no Flow exists with Bucket " + versionControlInfo.getBucketId() + ", Flow " + versionControlInfo.getFlowId() + ", Version " + versionControlInfo.getVersion()); } return snapshot; }
private RegistryClientEntity createRegistryClientEntity(final FlowRegistry flowRegistry) { if (flowRegistry == null) { return null; } final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(flowRegistry.getIdentifier())); final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizableLookup.getController()); final RegistryDTO dto = dtoFactory.createRegistryDto(flowRegistry); return entityFactory.createRegistryClientEntity(dto, revision, permissions); }
@Override public VersionedFlow deleteVersionedFlow(final String registryId, final String bucketId, final String flowId) { final FlowRegistry registry = flowRegistryClient.getFlowRegistry(registryId); if (registry == null) { throw new IllegalArgumentException("No Flow Registry exists with ID " + registryId); } try { return registry.deleteVersionedFlow(bucketId, flowId, NiFiUserUtils.getNiFiUser()); } catch (final IOException | NiFiRegistryException e) { throw new NiFiCoreException("Failed to remove flow from Flow Registry due to " + e.getMessage(), e); } }
@Override public Set<Bucket> getBucketsForUser(final String registryId, final NiFiUser user) { try { final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId); if (flowRegistry == null) { throw new IllegalArgumentException("The specified registry id is unknown to this NiFi."); } final Set<Bucket> buckets = flowRegistry.getBuckets(user); final Set<Bucket> sortedBuckets = new TreeSet<>((b1, b2) -> b1.getName().compareTo(b2.getName())); sortedBuckets.addAll(buckets); return sortedBuckets; } catch (final IOException | NiFiRegistryException ioe) { throw new NiFiCoreException("Unable to obtain listing of buckets: " + ioe, ioe); } }
coordinates.setRegistryUrl(registry.getURL()); coordinates.setBucketId(versionControlInfo.getBucketIdentifier()); coordinates.setFlowId(versionControlInfo.getFlowIdentifier());
@Override public String getRegistryName() { final String registryId = versionControlInformation.getRegistryIdentifier(); final FlowRegistry registry = flowController.getFlowRegistryClient().getFlowRegistry(registryId); return registry == null ? registryId : registry.getName(); }
versionedFlowSnapshot = flowRegistry.getFlowContents(versionControlInfo.getBucketIdentifier(), versionControlInfo.getFlowIdentifier(), versionControlInfo.getVersion(), true, NiFiUserUtils.getNiFiUser()); } catch (final IOException | NiFiRegistryException e) {
private void addFlowRegistries(final Element parentElement, final FlowRegistryClient registryClient) { for (final String registryId : registryClient.getRegistryIdentifiers()) { final FlowRegistry flowRegistry = registryClient.getFlowRegistry(registryId); final Element registryElement = parentElement.getOwnerDocument().createElement("flowRegistry"); parentElement.appendChild(registryElement); addStringElement(registryElement, "id", flowRegistry.getIdentifier()); addStringElement(registryElement, "name", flowRegistry.getName()); addStringElement(registryElement, "url", flowRegistry.getURL()); addStringElement(registryElement, "description", flowRegistry.getDescription()); } }
default String getFlowRegistryId(String registryUrl) { if (registryUrl.endsWith("/")) { registryUrl = registryUrl.substring(0, registryUrl.length() - 1); } for (final String registryClientId : getRegistryIdentifiers()) { final FlowRegistry registry = getFlowRegistry(registryClientId); String registryClientUrl = registry.getURL(); if (registryClientUrl.endsWith("/")) { registryClientUrl = registryClientUrl.substring(0, registryClientUrl.length() - 1); } if (registryClientUrl.equals(registryUrl)) { return registryClientId; } } return null; }
final String registryName = flowRegistry == null ? registryId : flowRegistry.getName();
final VersionedFlowSnapshot snapshot = flowRegistry.getFlowContents(bucketId, flowId, version, true, user); final VersionedProcessGroup contents = snapshot.getFlowContents();
@Override public ProcessGroup updateVersionControlInformation(final VersionControlInformationDTO versionControlInformation, final Map<String, String> versionedComponentMapping) { final String groupId = versionControlInformation.getGroupId(); final ProcessGroup group = locateProcessGroup(flowController, groupId); final String registryId = versionControlInformation.getRegistryId(); final FlowRegistry flowRegistry = flowController.getFlowRegistryClient().getFlowRegistry(registryId); final String registryName = flowRegistry == null ? registryId : flowRegistry.getName(); final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper(flowController.getExtensionManager()); final VersionedProcessGroup flowSnapshot = mapper.mapProcessGroup(group, flowController.getControllerServiceProvider(), flowController.getFlowRegistryClient(), false); final StandardVersionControlInformation vci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation) .registryName(registryName) .flowSnapshot(flowSnapshot) .build(); group.setVersionControlInformation(vci, versionedComponentMapping); group.onComponentModified(); return group; }