You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ex...@apache.org on 2024/05/07 13:44:53 UTC
(nifi) branch main updated: NIFI-13120 Introduce branch as a concept in Registry Client and VCI
This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new e7567b04e2 NIFI-13120 Introduce branch as a concept in Registry Client and VCI
e7567b04e2 is described below
commit e7567b04e2dc4c3bc4f839c2c0868baaf0d32241
Author: Bryan Bende <bb...@apache.org>
AuthorDate: Tue Apr 30 17:34:20 2024 -0400
NIFI-13120 Introduce branch as a concept in Registry Client and VCI
- Methods for getBranches, getDefaultBranch, and createBranch in flow registry client
- Add branch as a field to all relevant objects
- Add optional branch argument to REST API for retrieving buckets
- Add new REST API for retrieving branches for a given registry client
- Enforce NiFi Registry can only receive default branch
This closes #8726
Signed-off-by: David Handermann <ex...@apache.org>
---
.../apache/nifi/flow/VersionedFlowCoordinates.java | 20 +++-
.../apache/nifi/registry/flow/BucketLocation.java | 54 ++++++++++
.../apache/nifi/registry/flow/FlowLocation.java | 45 ++++++++
.../nifi/registry/flow/FlowRegistryBranch.java | 52 +++++++++
.../nifi/registry/flow/FlowRegistryClient.java | 87 ++++++++++++----
.../nifi/registry/flow/FlowVersionLocation.java | 46 ++++++++
.../apache/nifi/registry/flow/RegisteredFlow.java | 9 ++
.../flow/RegisteredFlowSnapshotMetadata.java | 9 ++
.../flow/NifiRegistryFlowRegistryClient.java | 65 +++++++++---
.../nifi/web/api/dto/FlowRegistryBranchDTO.java | 41 ++++++++
.../nifi/web/api/dto/FlowRegistryClientDTO.java | 13 ++-
.../web/api/dto/VersionControlInformationDTO.java | 10 ++
.../apache/nifi/web/api/dto/VersionedFlowDTO.java | 10 ++
.../web/api/entity/FlowRegistryBranchEntity.java | 37 +++++++
.../web/api/entity/FlowRegistryBranchesEntity.java | 38 +++++++
.../StandardVersionedComponentSynchronizer.java | 2 +
.../apache/nifi/groups/StandardProcessGroup.java | 26 +++--
.../flow/FlowAnalyzingRegistryClientNode.java | 50 +++++----
.../flow/StandardFlowRegistryClientNode.java | 63 +++++++----
.../flow/StandardVersionControlInformation.java | 18 +++-
.../flow/mapping/NiFiRegistryFlowMapper.java | 1 +
.../java/org/apache/nifi/groups/ProcessGroup.java | 3 +-
.../nifi/registry/flow/FlowRegistryClientNode.java | 20 ++--
.../registry/flow/GhostFlowRegistryClient.java | 16 +--
.../registry/flow/VersionControlInformation.java | 5 +
.../controller/service/mock/MockProcessGroup.java | 3 +-
.../org/apache/nifi/web/NiFiServiceFacade.java | 28 ++++-
.../apache/nifi/web/StandardNiFiServiceFacade.java | 116 +++++++++++++++++----
.../java/org/apache/nifi/web/api/FlowResource.java | 48 ++++++++-
.../apache/nifi/web/api/ProcessGroupResource.java | 3 +
.../org/apache/nifi/web/api/VersionsResource.java | 11 +-
.../org/apache/nifi/web/api/dto/DtoFactory.java | 18 ++--
.../org/apache/nifi/web/api/dto/EntityFactory.java | 7 ++
.../org/apache/nifi/web/dao/FlowRegistryDAO.java | 13 ++-
.../nifi/web/dao/impl/StandardFlowRegistryDAO.java | 55 ++++++++--
.../nifi/registry/flow/InMemoryFlowRegistry.java | 23 ++--
.../registry/FileSystemFlowRegistryClient.java | 45 +++++---
37 files changed, 927 insertions(+), 183 deletions(-)
diff --git a/nifi-api/src/main/java/org/apache/nifi/flow/VersionedFlowCoordinates.java b/nifi-api/src/main/java/org/apache/nifi/flow/VersionedFlowCoordinates.java
index d17f1156f0..f96b36d165 100644
--- a/nifi-api/src/main/java/org/apache/nifi/flow/VersionedFlowCoordinates.java
+++ b/nifi-api/src/main/java/org/apache/nifi/flow/VersionedFlowCoordinates.java
@@ -24,6 +24,7 @@ import java.util.Objects;
public class VersionedFlowCoordinates {
private String registryId;
private String storageLocation;
+ private String branch;
private String bucketId;
private String flowId;
private String version;
@@ -47,6 +48,15 @@ public class VersionedFlowCoordinates {
this.storageLocation = storageLocation;
}
+ @Schema(description = "The name of the branch that the flow resides in")
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(final String branch) {
+ this.branch = branch;
+ }
+
@Schema(description = "The UUID of the bucket that the flow resides in")
public String getBucketId() {
return bucketId;
@@ -85,7 +95,7 @@ public class VersionedFlowCoordinates {
@Override
public int hashCode() {
- return Objects.hash(registryId, storageLocation, bucketId, flowId, version);
+ return Objects.hash(registryId, storageLocation, branch, bucketId, flowId, version);
}
@Override
@@ -100,11 +110,15 @@ public class VersionedFlowCoordinates {
return false;
}
- return Objects.equals(storageLocation, other.storageLocation) && Objects.equals(bucketId, other.bucketId) && Objects.equals(flowId, other.flowId) && Objects.equals(version, other.version);
+ return Objects.equals(storageLocation, other.storageLocation)
+ && Objects.equals(branch, other.branch)
+ && Objects.equals(bucketId, other.bucketId)
+ && Objects.equals(flowId, other.flowId)
+ && Objects.equals(version, other.version);
}
@Override
public String toString() {
- return "VersionedFlowCoordinates[bucketId=" + bucketId + ", flowId=" + flowId + ", version=" + version + ", storageLocation=" + storageLocation + "]";
+ return "VersionedFlowCoordinates[branch=" + branch + ", bucketId=" + bucketId + ", flowId=" + flowId + ", version=" + version + ", storageLocation=" + storageLocation + "]";
}
}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/BucketLocation.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/BucketLocation.java
new file mode 100644
index 0000000000..58dddae59c
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/BucketLocation.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.registry.flow;
+
+/**
+ * Information for locating a bucket in a flow registry.
+ */
+public class BucketLocation {
+
+ private String branch;
+ private String bucketId;
+
+ public BucketLocation() {
+
+ }
+
+ public BucketLocation(final String branch, final String bucketId) {
+ this.branch = branch;
+ this.bucketId = bucketId;
+ }
+
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(final String branch) {
+ this.branch = branch;
+ }
+
+ public String getBucketId() {
+ return bucketId;
+ }
+
+ public void setBucketId(final String bucketId) {
+ this.bucketId = bucketId;
+ }
+}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowLocation.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowLocation.java
new file mode 100644
index 0000000000..c30f549df6
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowLocation.java
@@ -0,0 +1,45 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.registry.flow;
+
+/**
+ * Information for locating a flow in a flow registry.
+ */
+public class FlowLocation extends BucketLocation {
+
+ private String flowId;
+
+ public FlowLocation() {
+
+ }
+
+ public FlowLocation(final String branch, final String bucketId, final String flowId) {
+ super(branch, bucketId);
+ this.flowId = flowId;
+ }
+
+ public String getFlowId() {
+ return flowId;
+ }
+
+ public void setFlowId(final String flowId) {
+ this.flowId = flowId;
+ }
+}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryBranch.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryBranch.java
new file mode 100644
index 0000000000..e9d944c2d0
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryBranch.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.registry.flow;
+
+import java.util.Objects;
+
+public class FlowRegistryBranch {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final FlowRegistryBranch that = (FlowRegistryBranch) o;
+ return Objects.equals(name, that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name);
+ }
+}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClient.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClient.java
index d910b4433e..749e5b880f 100644
--- a/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClient.java
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClient.java
@@ -56,6 +56,9 @@ import java.util.Set;
*
*/
public interface FlowRegistryClient extends ConfigurableComponent {
+
+ String DEFAULT_BRANCH_NAME = "main";
+
void initialize(FlowRegistryClientInitializationContext context);
/**
@@ -71,30 +74,76 @@ public interface FlowRegistryClient extends ConfigurableComponent {
*/
boolean isStorageLocationApplicable(FlowRegistryClientConfigurationContext context, String location);
+ /**
+ * Indicates if the registry supports branching.
+ *
+ * If the registry does not supporting branching, then this method should return false and the registry client should use
+ * the default implementations of getBranches and getDefaultBranch.
+ *
+ * If the registry does support branching, then this method should return true and the registry client should use
+ * override getBranches and getDefaultBranch to provide appropriate implementations.
+ *
+ * @param context Configuration context
+ * @return true if the registry supports branching, false otherwise
+ */
+ default boolean isBranchingSupported(final FlowRegistryClientConfigurationContext context) {
+ return false;
+ }
+
+ /**
+ * Get the available branches. Should return at least one branch that matches the response of getDefaultBranch.
+ *
+ * @param context Configuration context
+ * @return the set of available branches
+ *
+ * @throws FlowRegistryException If an issue happens during processing the request.
+ * @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
+ */
+ default Set<FlowRegistryBranch> getBranches(final FlowRegistryClientConfigurationContext context) throws FlowRegistryException, IOException {
+ return Set.of(getDefaultBranch(context));
+ }
+
+ /**
+ * Gets the default branch. Must return a non-null FlowRegistryBranch instance with a non-null name.
+ * The interface provides a default implementation which will return a branch named 'main'.
+ *
+ * @param context Configuration context
+ * @return the default branch
+ *
+ * @throws FlowRegistryException If an issue happens during processing the request.
+ * @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
+ */
+ default FlowRegistryBranch getDefaultBranch(final FlowRegistryClientConfigurationContext context) throws FlowRegistryException, IOException {
+ final FlowRegistryBranch branch = new FlowRegistryBranch();
+ branch.setName(DEFAULT_BRANCH_NAME);
+ return branch;
+ }
+
/**
* Gets the buckets for the specified user.
*
* @param context Configuration context.
+ * @param branch the branch
*
* @return Buckets for this user. In case there are no available buckets for the user the result will be an empty set.
*
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- Set<FlowRegistryBucket> getBuckets(FlowRegistryClientConfigurationContext context) throws FlowRegistryException, IOException;
+ Set<FlowRegistryBucket> getBuckets(FlowRegistryClientConfigurationContext context, String branch) throws FlowRegistryException, IOException;
/**
* Gets the bucket with the given id.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
+ * @param bucketLocation The location of the bucket.
* @return The bucket with the given id.
*
* @throws NoSuchBucketException If there is no bucket in the Registry with the given id.
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- FlowRegistryBucket getBucket(FlowRegistryClientConfigurationContext context, String bucketId) throws FlowRegistryException, IOException;
+ FlowRegistryBucket getBucket(FlowRegistryClientConfigurationContext context, BucketLocation bucketLocation) throws FlowRegistryException, IOException;
/**
* Registers the given RegisteredFlow into the the Flow Registry.
@@ -114,22 +163,20 @@ public interface FlowRegistryClient extends ConfigurableComponent {
* Deletes the specified flow from the Flow Registry.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
- * @param flowId The id of the flow.
+ * @param flowLocation the location of the flow
*
* @return The deleted Flow.
*
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- RegisteredFlow deregisterFlow(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
+ RegisteredFlow deregisterFlow(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
/**
* Retrieves a flow by bucket id and Flow id.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
- * @param flowId The id of the Flow.
+ * @param flowLocation the location of the flow
*
* @return The Flow for the given bucket and Flow id's.
*
@@ -137,28 +184,26 @@ public interface FlowRegistryClient extends ConfigurableComponent {
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- RegisteredFlow getFlow(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
+ RegisteredFlow getFlow(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
/**
* Retrieves the set of all Flows for the specified bucket.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
+ * @param bucketLocation the location of the bucket
*
* @return The set of all Flows from the specified bucket. In case there are no available flows in the bucket the result will be an empty set.
*
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- Set<RegisteredFlow> getFlows(FlowRegistryClientConfigurationContext context, String bucketId) throws FlowRegistryException, IOException;
+ Set<RegisteredFlow> getFlows(FlowRegistryClientConfigurationContext context, BucketLocation bucketLocation) throws FlowRegistryException, IOException;
/**
- * Retrieves the contents of the flow snaphot with the given Bucket id, Flow id, and version, from the Registry.
+ * Retrieves the contents of the flow snapshot with the given Bucket id, Flow id, and version, from the Registry.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
- * @param flowId The id of the Flow.
- * @param version The version to retrieve.
+ * @param flowVersionLocation the location of the flow version
*
* @return The contents of the Flow from the Flow Registry.
*
@@ -166,7 +211,7 @@ public interface FlowRegistryClient extends ConfigurableComponent {
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- RegisteredFlowSnapshot getFlowContents(FlowRegistryClientConfigurationContext context, String bucketId, String flowId, String version) throws FlowRegistryException, IOException;
+ RegisteredFlowSnapshot getFlowContents(FlowRegistryClientConfigurationContext context, FlowVersionLocation flowVersionLocation) throws FlowRegistryException, IOException;
/**
* Adds the given snapshot to the Flow Registry for the given Flow.
@@ -186,27 +231,25 @@ public interface FlowRegistryClient extends ConfigurableComponent {
* Retrieves the set of all versions of the specified flow.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
- * @param flowId The id of the flow.
+ * @param flowLocation the location of the flow
*
* @return The set of all versions of the specified flow. In case there are no available versions for the specified flow the result will be an empty set.
*
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- Set<RegisteredFlowSnapshotMetadata> getFlowVersions(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
+ Set<RegisteredFlowSnapshotMetadata> getFlowVersions(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
/**
* Returns the latest (most recent) version of the Flow in the Flow Registry for the given bucket and Flow.
*
* @param context Configuration context.
- * @param bucketId The id of the bucket.
- * @param flowId The id of the flow.
+ * @param flowLocation the location of the flow
*
* @return an Optional containing the latest version of the flow, or empty if no versions exist for the flow
*
* @throws FlowRegistryException If an issue happens during processing the request.
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
- Optional<String> getLatestVersion(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
+ Optional<String> getLatestVersion(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowVersionLocation.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowVersionLocation.java
new file mode 100644
index 0000000000..e615b6a45d
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/FlowVersionLocation.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.registry.flow;
+
+/**
+ * Information for locating a flow version in a flow registry.
+ */
+public class FlowVersionLocation extends FlowLocation {
+
+ private String version;
+
+ public FlowVersionLocation() {
+
+ }
+
+ public FlowVersionLocation(final String branch, final String bucketId, final String flowId, final String version) {
+ super(branch, bucketId, flowId);
+ this.version = version;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(final String version) {
+ this.version = version;
+ }
+
+}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlow.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlow.java
index 9541eabccd..c8d39d9989 100644
--- a/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlow.java
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlow.java
@@ -20,6 +20,7 @@ public class RegisteredFlow {
private String identifier;
private String name;
private String description;
+ private String branch;
private String bucketIdentifier;
private String bucketName;
private long createdTimestamp;
@@ -40,6 +41,14 @@ public class RegisteredFlow {
return description;
}
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(final String branch) {
+ this.branch = branch;
+ }
+
public String getBucketIdentifier() {
return bucketIdentifier;
}
diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlowSnapshotMetadata.java b/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlowSnapshotMetadata.java
index ea0f0ad75a..5f7864d3f5 100644
--- a/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlowSnapshotMetadata.java
+++ b/nifi-api/src/main/java/org/apache/nifi/registry/flow/RegisteredFlowSnapshotMetadata.java
@@ -17,6 +17,7 @@
package org.apache.nifi.registry.flow;
public class RegisteredFlowSnapshotMetadata {
+ private String branch;
private String bucketIdentifier;
private String flowIdentifier;
private String version;
@@ -24,6 +25,10 @@ public class RegisteredFlowSnapshotMetadata {
private String author;
private String comments;
+ public String getBranch() {
+ return branch;
+ }
+
public String getBucketIdentifier() {
return bucketIdentifier;
}
@@ -48,6 +53,10 @@ public class RegisteredFlowSnapshotMetadata {
return comments;
}
+ public void setBranch(final String branch) {
+ this.branch = branch;
+ }
+
public void setBucketIdentifier(String bucketIdentifier) {
this.bucketIdentifier = bucketIdentifier;
}
diff --git a/nifi-extension-bundles/nifi-flow-registry-client-bundle/nifi-flow-registry-client-services/src/main/java/org/apache/nifi/registry/flow/NifiRegistryFlowRegistryClient.java b/nifi-extension-bundles/nifi-flow-registry-client-bundle/nifi-flow-registry-client-services/src/main/java/org/apache/nifi/registry/flow/NifiRegistryFlowRegistryClient.java
index 98d7eb16ad..0300f0e8f3 100644
--- a/nifi-extension-bundles/nifi-flow-registry-client-bundle/nifi-flow-registry-client-services/src/main/java/org/apache/nifi/registry/flow/NifiRegistryFlowRegistryClient.java
+++ b/nifi-extension-bundles/nifi-flow-registry-client-bundle/nifi-flow-registry-client-services/src/main/java/org/apache/nifi/registry/flow/NifiRegistryFlowRegistryClient.java
@@ -149,7 +149,8 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientConfigurationContext context) throws FlowRegistryException, IOException {
+ public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientConfigurationContext context, final String branch) throws FlowRegistryException, IOException {
+ validateBranch(branch);
try {
final BucketClient bucketClient = getBucketClient(context);
return bucketClient.getAll().stream().map(NifiRegistryUtil::convert).collect(Collectors.toSet());
@@ -159,8 +160,10 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public FlowRegistryBucket getBucket(final FlowRegistryClientConfigurationContext context, final String bucketId) throws FlowRegistryException, IOException {
+ public FlowRegistryBucket getBucket(final FlowRegistryClientConfigurationContext context, final BucketLocation bucketLocation) throws FlowRegistryException, IOException {
+ validateBranch(bucketLocation);
try {
+ final String bucketId = bucketLocation.getBucketId();;
final BucketClient bucketClient = getBucketClient(context);
final Bucket bucket = bucketClient.get(bucketId);
@@ -176,6 +179,7 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
@Override
public RegisteredFlow registerFlow(final FlowRegistryClientConfigurationContext context, final RegisteredFlow flow) throws FlowRegistryException, IOException {
+ validateBranch(flow.getBranch());
try {
final FlowClient flowClient = getFlowClient(context);
@@ -193,8 +197,12 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public RegisteredFlow deregisterFlow(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
+ public RegisteredFlow deregisterFlow(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ validateBranch(flowLocation);
try {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+
final FlowClient flowClient = getFlowClient(context);
return NifiRegistryUtil.convert(flowClient.delete(bucketId, flowId));
} catch (final NiFiRegistryException e) {
@@ -203,8 +211,12 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public RegisteredFlow getFlow(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
+ public RegisteredFlow getFlow(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ validateBranch(flowLocation);
try {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+
final FlowClient flowClient = getFlowClient(context);
final VersionedFlow flow = flowClient.get(bucketId, flowId);
@@ -219,20 +231,25 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Set<RegisteredFlow> getFlows(final FlowRegistryClientConfigurationContext context, final String bucketId) throws FlowRegistryException, IOException {
+ public Set<RegisteredFlow> getFlows(final FlowRegistryClientConfigurationContext context, final BucketLocation bucketLocation) throws FlowRegistryException, IOException {
+ validateBranch(bucketLocation);
try {
final FlowClient flowClient = getFlowClient(context);
- return flowClient.getByBucket(bucketId).stream().map(NifiRegistryUtil::convert).collect(Collectors.toSet());
+ return flowClient.getByBucket(bucketLocation.getBucketId()).stream().map(NifiRegistryUtil::convert).collect(Collectors.toSet());
} catch (final NiFiRegistryException e) {
throw new FlowRegistryException(e.getMessage(), e);
}
}
@Override
- public RegisteredFlowSnapshot getFlowContents(
- final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId, final String version
- ) throws FlowRegistryException, IOException {
+ public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final FlowVersionLocation flowVersionLocation)
+ throws FlowRegistryException, IOException {
+ validateBranch(flowVersionLocation);
try {
+ final String bucketId = flowVersionLocation.getBucketId();
+ final String flowId = flowVersionLocation.getFlowId();
+ final String version = flowVersionLocation.getVersion();
+
final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(context);
final VersionedFlowSnapshot snapshot = snapshotClient.get(bucketId, flowId, Integer.parseInt(version));
@@ -256,6 +273,9 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
final int snapshotVersion = getRegisteredFlowSnapshotVersion(snapshotMetadata, action);
snapshotMetadata.setVersion(String.valueOf(snapshotVersion));
+ final String branch = snapshotMetadata.getBranch();
+ validateBranch(branch);
+
final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(context);
final VersionedFlowSnapshot versionedFlowSnapshot = snapshotClient.create(NifiRegistryUtil.convert(flowSnapshot));
@@ -265,6 +285,7 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
final VersionedFlowCoordinates versionedFlowCoordinates = new VersionedFlowCoordinates();
versionedFlowCoordinates.setRegistryId(getIdentifier());
+ versionedFlowCoordinates.setBranch(branch);
versionedFlowCoordinates.setBucketId(bucketId);
versionedFlowCoordinates.setFlowId(flowId);
versionedFlowCoordinates.setVersion(String.valueOf(version));
@@ -287,10 +308,13 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(
- final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId
- ) throws FlowRegistryException, IOException {
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation)
+ throws FlowRegistryException, IOException {
+ validateBranch(flowLocation);
try {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+
final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(context);
return snapshotClient.getSnapshotMetadata(bucketId, flowId).stream().map(NifiRegistryUtil::convert).collect(Collectors.toSet());
} catch (NiFiRegistryException e) {
@@ -299,8 +323,12 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
+ public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ validateBranch(flowLocation);
try {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+
final int versionCount = (int) getFlowClient(context).get(bucketId, flowId).getVersionCount();
return versionCount == 0 ? Optional.empty() : Optional.of(String.valueOf(versionCount));
} catch (NiFiRegistryException e) {
@@ -332,4 +360,15 @@ public class NifiRegistryFlowRegistryClient extends AbstractFlowRegistryClient {
private static TlsConfiguration createTlsConfigurationFromContext(final FlowRegistryClientConfigurationContext context) {
return new StandardTlsConfiguration(context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class).createTlsConfiguration());
}
+
+ private void validateBranch(final BucketLocation bucketLocation) throws FlowRegistryException {
+ validateBranch(bucketLocation.getBranch());
+ }
+
+ private void validateBranch(final String branch) throws FlowRegistryException {
+ if (branch != null && !DEFAULT_BRANCH_NAME.equals(branch)) {
+ throw new FlowRegistryException("Invalid branch, NiFi Registry client only supports the default branch '" + DEFAULT_BRANCH_NAME + "'");
+ }
+ }
+
}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryBranchDTO.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryBranchDTO.java
new file mode 100644
index 0000000000..f5f7fa48f0
--- /dev/null
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryBranchDTO.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.web.api.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.xml.bind.annotation.XmlType;
+
+/**
+ * Details about a branch in a registry.
+ */
+@XmlType(name = "branch")
+public class FlowRegistryBranchDTO {
+
+ private String name;
+
+ @Schema(description = "The branch name")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryClientDTO.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryClientDTO.java
index f26b3821b4..9018256be2 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryClientDTO.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowRegistryClientDTO.java
@@ -43,6 +43,7 @@ public class FlowRegistryClientDTO {
private Map<String, PropertyDescriptorDTO> descriptors;
private Set<String> sensitiveDynamicPropertyNames;
private Boolean supportsSensitiveDynamicProperties;
+ private Boolean supportsBranching;
private Boolean restricted;
private Boolean deprecated;
@@ -125,8 +126,7 @@ public class FlowRegistryClientDTO {
this.sensitiveDynamicPropertyNames = sensitiveDynamicPropertyNames;
}
- @Schema(description = "Whether the registry client supports sensitive dynamic properties."
- )
+ @Schema(description = "Whether the registry client supports sensitive dynamic properties.")
public Boolean getSupportsSensitiveDynamicProperties() {
return supportsSensitiveDynamicProperties;
}
@@ -135,6 +135,15 @@ public class FlowRegistryClientDTO {
this.supportsSensitiveDynamicProperties = supportsSensitiveDynamicProperties;
}
+ @Schema(description = "Whether the registry client supports branching.")
+ public Boolean getSupportsBranching() {
+ return supportsBranching;
+ }
+
+ public void setSupportsBranching(final Boolean supportsBranching) {
+ this.supportsBranching = supportsBranching;
+ }
+
@Schema(description = "Whether the registry client requires elevated privileges."
)
public Boolean getRestricted() {
diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionControlInformationDTO.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionControlInformationDTO.java
index e29f76ce30..3ccf1c4b06 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionControlInformationDTO.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionControlInformationDTO.java
@@ -33,6 +33,7 @@ public class VersionControlInformationDTO {
private String groupId;
private String registryId;
private String registryName;
+ private String branch;
private String bucketId;
private String bucketName;
private String flowId;
@@ -70,6 +71,15 @@ public class VersionControlInformationDTO {
this.registryName = registryName;
}
+ @Schema(description = "The ID of the branch that the flow is stored in")
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(final String branch) {
+ this.branch = branch;
+ }
+
@Schema(description = "The ID of the bucket that the flow is stored in")
public String getBucketId() {
return bucketId;
diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionedFlowDTO.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionedFlowDTO.java
index 68761a1356..14be45ca60 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionedFlowDTO.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/VersionedFlowDTO.java
@@ -27,6 +27,7 @@ public class VersionedFlowDTO {
public static final String FORCE_COMMIT_ACTION = "FORCE_COMMIT";
private String registryId = "default"; // placeholder for now.
+ private String branch;
private String bucketId;
private String flowId;
private String flowName;
@@ -43,6 +44,15 @@ public class VersionedFlowDTO {
this.registryId = registryId;
}
+ @Schema(description = "The branch where the flow is stored")
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(final String branch) {
+ this.branch = branch;
+ }
+
@Schema(description = "The ID of the bucket where the flow is stored")
public String getBucketId() {
return bucketId;
diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/FlowRegistryBranchEntity.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/FlowRegistryBranchEntity.java
new file mode 100644
index 0000000000..47b95d2198
--- /dev/null
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/FlowRegistryBranchEntity.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.web.api.entity;
+
+import jakarta.xml.bind.annotation.XmlRootElement;
+import org.apache.nifi.web.api.dto.FlowRegistryBranchDTO;
+
+@XmlRootElement(name = "branchEntity")
+public class FlowRegistryBranchEntity extends Entity {
+
+ private FlowRegistryBranchDTO branch;
+
+ public FlowRegistryBranchDTO getBranch() {
+ return branch;
+ }
+
+ public void setBranch(final FlowRegistryBranchDTO branch) {
+ this.branch = branch;
+ }
+}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/FlowRegistryBranchesEntity.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/FlowRegistryBranchesEntity.java
new file mode 100644
index 0000000000..72d7574ed0
--- /dev/null
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/FlowRegistryBranchesEntity.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.apache.nifi.web.api.entity;
+
+import jakarta.xml.bind.annotation.XmlRootElement;
+
+import java.util.Set;
+
+@XmlRootElement(name = "branches")
+public class FlowRegistryBranchesEntity {
+
+ private Set<FlowRegistryBranchEntity> branches;
+
+ public Set<FlowRegistryBranchEntity> getBranches() {
+ return branches;
+ }
+
+ public void setBranches(final Set<FlowRegistryBranchEntity> branches) {
+ this.branches = branches;
+ }
+}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
index c2f78c870f..c3997b3c93 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
@@ -344,6 +344,7 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen
group.disconnectVersionControl(false);
} else {
final String registryId = determineRegistryId(remoteCoordinates);
+ final String branch = remoteCoordinates.getBranch();
final String bucketId = remoteCoordinates.getBucketId();
final String flowId = remoteCoordinates.getFlowId();
final String version = remoteCoordinates.getVersion();
@@ -362,6 +363,7 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen
final VersionControlInformation vci = new StandardVersionControlInformation.Builder()
.registryId(registryId)
.registryName(registryName)
+ .branch(branch)
.bucketId(bucketId)
.bucketName(bucketId)
.flowId(flowId)
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
index eaf2467324..6a6f61f961 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
@@ -81,10 +81,12 @@ import org.apache.nifi.parameter.StandardParameterUpdate;
import org.apache.nifi.processor.DataUnit;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.StandardProcessContext;
+import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.FlowRegistryClientContextFactory;
import org.apache.nifi.registry.flow.FlowRegistryClientNode;
import org.apache.nifi.registry.flow.FlowRegistryException;
import org.apache.nifi.registry.flow.FlowSnapshotContainer;
+import org.apache.nifi.registry.flow.FlowVersionLocation;
import org.apache.nifi.registry.flow.RegisteredFlow;
import org.apache.nifi.registry.flow.RegisteredFlowSnapshot;
import org.apache.nifi.registry.flow.StandardVersionControlInformation;
@@ -3490,6 +3492,7 @@ public final class StandardProcessGroup implements ProcessGroup {
final StandardVersionControlInformation svci = new StandardVersionControlInformation(
versionControlInformation.getRegistryIdentifier(),
versionControlInformation.getRegistryName(),
+ versionControlInformation.getBranch(),
versionControlInformation.getBucketIdentifier(),
versionControlInformation.getFlowIdentifier(),
versionControlInformation.getVersion(),
@@ -3750,8 +3753,9 @@ public final class StandardProcessGroup implements ProcessGroup {
throw new FlowRegistryException(flowRegistry + " cannot currently be used to synchronize with Flow Registry because it is currently validating");
}
+ final FlowVersionLocation flowVersionLocation = new FlowVersionLocation(vci.getBranch(), vci.getBucketIdentifier(), vci.getFlowIdentifier(), vci.getVersion());
final FlowSnapshotContainer registrySnapshotContainer = flowRegistry.getFlowContents(
- FlowRegistryClientContextFactory.getAnonymousContext(), vci.getBucketIdentifier(), vci.getFlowIdentifier(), vci.getVersion(), false);
+ FlowRegistryClientContextFactory.getAnonymousContext(), flowVersionLocation, false);
final RegisteredFlowSnapshot registrySnapshot = registrySnapshotContainer.getFlowSnapshot();
final VersionedProcessGroup registryFlow = registrySnapshot.getFlowContents();
vci.setFlowSnapshot(registryFlow);
@@ -3773,8 +3777,9 @@ public final class StandardProcessGroup implements ProcessGroup {
}
try {
- final RegisteredFlow versionedFlow = flowRegistry.getFlow(FlowRegistryClientContextFactory.getAnonymousContext(), vci.getBucketIdentifier(), vci.getFlowIdentifier());
- final String latestVersion = flowRegistry.getLatestVersion(FlowRegistryClientContextFactory.getAnonymousContext(), vci.getBucketIdentifier(), vci.getFlowIdentifier()).orElse(null);
+ final FlowLocation flowLocation = new FlowLocation(vci.getBranch(), vci.getBucketIdentifier(), vci.getFlowIdentifier());
+ final RegisteredFlow versionedFlow = flowRegistry.getFlow(FlowRegistryClientContextFactory.getAnonymousContext(), flowLocation);
+ final String latestVersion = flowRegistry.getLatestVersion(FlowRegistryClientContextFactory.getAnonymousContext(), flowLocation).orElse(null);
vci.setBucketName(versionedFlow.getBucketName());
vci.setFlowName(versionedFlow.getName());
vci.setFlowDescription(versionedFlow.getDescription());
@@ -4022,11 +4027,12 @@ public final class StandardProcessGroup implements ProcessGroup {
}
@Override
- public void verifyCanSaveToFlowRegistry(final String registryId, final String bucketId, final String flowId, final String saveAction) {
+ public void verifyCanSaveToFlowRegistry(final String registryId, final FlowLocation flowLocation, final String saveAction) {
verifyNoDescendantsWithLocalModifications("be saved to a Flow Registry");
final StandardVersionControlInformation vci = versionControlInfo.get();
if (vci != null) {
+ final String flowId = flowLocation.getFlowId();
if (flowId != null && flowId.equals(vci.getFlowIdentifier())) {
// Flow ID is the same. We want to publish the Process Group as the next version of the Flow.
// In order to do this, we have to ensure that the Process Group is 'current'.
@@ -4040,14 +4046,22 @@ public final class StandardProcessGroup implements ProcessGroup {
// Flow ID matches. We want to publish the Process Group as the next version of the Flow, so we must
// ensure that all other parameters match as well.
+
+ final String branch = flowLocation.getBranch();
+ if (branch != null && !Objects.equals(branch, vci.getBranch())) {
+ throw new IllegalStateException("Cannot update Version Control Information for Process Group with ID " + getIdentifier()
+ + " because the Process Group is currently synchronized with a different Versioned Flow than the one specified in the request.");
+ }
+
+ final String bucketId = flowLocation.getBucketId();
if (!bucketId.equals(vci.getBucketIdentifier())) {
throw new IllegalStateException("Cannot update Version Control Information for Process Group with ID " + getIdentifier()
- + " because the Process Group is currently synchronized with a different Versioned Flow than the one specified in the request.");
+ + " because the Process Group is currently synchronized with a different Versioned Flow than the one specified in the request.");
}
if (!registryId.equals(vci.getRegistryIdentifier())) {
throw new IllegalStateException("Cannot update Version Control Information for Process Group with ID " + getIdentifier()
- + " because the Process Group is currently synchronized with a different Versioned Flow than the one specified in the request.");
+ + " because the Process Group is currently synchronized with a different Versioned Flow than the one specified in the request.");
}
} else if (flowId != null) {
// Flow ID is specified but different. This is not allowed, because Flow ID's are automatically generated,
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/FlowAnalyzingRegistryClientNode.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/FlowAnalyzingRegistryClientNode.java
index 3793f60a19..a099a15e62 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/FlowAnalyzingRegistryClientNode.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/FlowAnalyzingRegistryClientNode.java
@@ -401,13 +401,28 @@ public final class FlowAnalyzingRegistryClientNode implements FlowRegistryClient
}
@Override
- public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientUserContext context) throws FlowRegistryException, IOException {
- return node.getBuckets(context);
+ public boolean isBranchingSupported() {
+ return node.isBranchingSupported();
}
@Override
- public FlowRegistryBucket getBucket(final FlowRegistryClientUserContext context, final String bucketId) throws FlowRegistryException, IOException {
- return node.getBucket(context, bucketId);
+ public Set<FlowRegistryBranch> getBranches(final FlowRegistryClientUserContext context) throws FlowRegistryException, IOException {
+ return node.getBranches(context);
+ }
+
+ @Override
+ public FlowRegistryBranch getDefaultBranch(final FlowRegistryClientUserContext context) throws FlowRegistryException, IOException {
+ return node.getDefaultBranch(context);
+ }
+
+ @Override
+ public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientUserContext context, final String branch) throws FlowRegistryException, IOException {
+ return node.getBuckets(context, branch);
+ }
+
+ @Override
+ public FlowRegistryBucket getBucket(final FlowRegistryClientUserContext context, final BucketLocation bucketLocation) throws FlowRegistryException, IOException {
+ return node.getBucket(context, bucketLocation);
}
@Override
@@ -416,35 +431,34 @@ public final class FlowAnalyzingRegistryClientNode implements FlowRegistryClient
}
@Override
- public RegisteredFlow deregisterFlow(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return node.deregisterFlow(context, bucketId, flowId);
+ public RegisteredFlow deregisterFlow(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return node.deregisterFlow(context, flowLocation);
}
@Override
- public RegisteredFlow getFlow(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return node.getFlow(context, bucketId, flowId);
+ public RegisteredFlow getFlow(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return node.getFlow(context, flowLocation);
}
@Override
- public Set<RegisteredFlow> getFlows(final FlowRegistryClientUserContext context, final String bucketId) throws FlowRegistryException, IOException {
- return node.getFlows(context, bucketId);
+ public Set<RegisteredFlow> getFlows(final FlowRegistryClientUserContext context, final BucketLocation bucketLocation) throws FlowRegistryException, IOException {
+ return node.getFlows(context, bucketLocation);
}
@Override
- public FlowSnapshotContainer getFlowContents(
- final FlowRegistryClientUserContext context, final String bucketId, final String flowId, final String version, final boolean fetchRemoteFlows
- ) throws FlowRegistryException, IOException {
- return node.getFlowContents(context, bucketId, flowId, version, fetchRemoteFlows);
+ public FlowSnapshotContainer getFlowContents(final FlowRegistryClientUserContext context, final FlowVersionLocation flowVersionLocation, final boolean fetchRemoteFlows)
+ throws FlowRegistryException, IOException {
+ return node.getFlowContents(context, flowVersionLocation, fetchRemoteFlows);
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return node.getFlowVersions(context, bucketId, flowId);
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return node.getFlowVersions(context, flowLocation);
}
@Override
- public Optional<String> getLatestVersion(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return node.getLatestVersion(context, bucketId, flowId);
+ public Optional<String> getLatestVersion(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return node.getLatestVersion(context, flowLocation);
}
@Override
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardFlowRegistryClientNode.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardFlowRegistryClientNode.java
index 8d46606349..0fbe4a3119 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardFlowRegistryClientNode.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardFlowRegistryClientNode.java
@@ -192,13 +192,28 @@ public final class StandardFlowRegistryClientNode extends AbstractComponentNode
}
@Override
- public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientUserContext context) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().getBuckets(getConfigurationContext(context)));
+ public boolean isBranchingSupported() {
+ return client.get().getComponent().isBranchingSupported(getConfigurationContext());
}
@Override
- public FlowRegistryBucket getBucket(final FlowRegistryClientUserContext context, final String bucketId) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().getBucket(getConfigurationContext(context), bucketId));
+ public Set<FlowRegistryBranch> getBranches(final FlowRegistryClientUserContext context) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getBranches(getConfigurationContext(context)));
+ }
+
+ @Override
+ public FlowRegistryBranch getDefaultBranch(final FlowRegistryClientUserContext context) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getDefaultBranch(getConfigurationContext(context)));
+ }
+
+ @Override
+ public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientUserContext context, final String branch) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getBuckets(getConfigurationContext(context), branch));
+ }
+
+ @Override
+ public FlowRegistryBucket getBucket(final FlowRegistryClientUserContext context, final BucketLocation bucketLocation) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getBucket(getConfigurationContext(context), bucketLocation));
}
@Override
@@ -207,25 +222,24 @@ public final class StandardFlowRegistryClientNode extends AbstractComponentNode
}
@Override
- public RegisteredFlow deregisterFlow(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().deregisterFlow(getConfigurationContext(context), bucketId, flowId));
+ public RegisteredFlow deregisterFlow(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().deregisterFlow(getConfigurationContext(context), flowLocation));
}
@Override
- public RegisteredFlow getFlow(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().getFlow(getConfigurationContext(context), bucketId, flowId));
+ public RegisteredFlow getFlow(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getFlow(getConfigurationContext(context), flowLocation));
}
@Override
- public Set<RegisteredFlow> getFlows(final FlowRegistryClientUserContext context, final String bucketId) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().getFlows(getConfigurationContext(context), bucketId));
+ public Set<RegisteredFlow> getFlows(final FlowRegistryClientUserContext context, final BucketLocation bucketLocation) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getFlows(getConfigurationContext(context), bucketLocation));
}
@Override
- public FlowSnapshotContainer getFlowContents(
- final FlowRegistryClientUserContext context, final String bucketId, final String flowId, final String version, final boolean fetchRemoteFlows
- ) throws FlowRegistryException, IOException {
- final RegisteredFlowSnapshot flowSnapshot = execute(() -> client.get().getComponent().getFlowContents(getConfigurationContext(context), bucketId, flowId, version));
+ public FlowSnapshotContainer getFlowContents(final FlowRegistryClientUserContext context, final FlowVersionLocation flowVersionLocation, final boolean fetchRemoteFlows)
+ throws FlowRegistryException, IOException {
+ final RegisteredFlowSnapshot flowSnapshot = execute(() -> client.get().getComponent().getFlowContents(getConfigurationContext(context), flowVersionLocation));
final FlowSnapshotContainer snapshotContainer = new FlowSnapshotContainer(flowSnapshot);
if (fetchRemoteFlows) {
@@ -261,13 +275,13 @@ public final class StandardFlowRegistryClientNode extends AbstractComponentNode
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().getFlowVersions(getConfigurationContext(context), bucketId, flowId));
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getFlowVersions(getConfigurationContext(context), flowLocation));
}
@Override
- public Optional<String> getLatestVersion(final FlowRegistryClientUserContext context, final String bucketId, final String flowId) throws FlowRegistryException, IOException {
- return execute(() -> client.get().getComponent().getLatestVersion(getConfigurationContext(context), bucketId, flowId));
+ public Optional<String> getLatestVersion(final FlowRegistryClientUserContext context, final FlowLocation flowLocation) throws FlowRegistryException, IOException {
+ return execute(() -> client.get().getComponent().getLatestVersion(getConfigurationContext(context), flowLocation));
}
@Override
@@ -369,27 +383,29 @@ public final class StandardFlowRegistryClientNode extends AbstractComponentNode
final boolean fetchRemoteFlows) throws FlowRegistryException {
final String storageLocation = coordinates.getStorageLocation();
+ final String branch = coordinates.getBranch();
final String bucketId = coordinates.getBucketId();
final String flowId = coordinates.getFlowId();
final String version = coordinates.getVersion();
+ final FlowVersionLocation flowVersionLocation = new FlowVersionLocation(branch, bucketId, flowId, version);
final List<FlowRegistryClientNode> clientNodes = getRegistryClientsForInternalFlow(storageLocation);
for (final FlowRegistryClientNode clientNode : clientNodes) {
try {
- logger.debug("Attempting to fetch flow for Bucket [{}] Flow [{}] Version [{}] using {}", bucketId, flowId, version, clientNode);
- final FlowSnapshotContainer snapshotContainer = clientNode.getFlowContents(context, bucketId, flowId, version, fetchRemoteFlows);
+ logger.debug("Attempting to fetch flow from Branch [{}] for Bucket [{}] Flow [{}] Version [{}] using {}", branch, bucketId, flowId, version, clientNode);
+ final FlowSnapshotContainer snapshotContainer = clientNode.getFlowContents(context, flowVersionLocation, fetchRemoteFlows);
final RegisteredFlowSnapshot snapshot = snapshotContainer.getFlowSnapshot();
coordinates.setRegistryId(clientNode.getIdentifier());
- logger.debug("Successfully fetched flow for Bucket [{}] Flow [{}] Version [{}] using {}", bucketId, flowId, version, clientNode);
+ logger.debug("Successfully fetched flow from Branch [{}] for Bucket [{}] Flow [{}] Version [{}] using {}", branch, bucketId, flowId, version, clientNode);
return snapshot;
} catch (final Exception e) {
logger.debug("Failed to fetch flow", e);
}
}
- throw new FlowRegistryException(String.format("Could not find any Registry Client that was able to fetch flow with Bucket [%s] Flow [%s] Version [%s] with Storage Location [%s]",
- bucketId, flowId, version, storageLocation));
+ throw new FlowRegistryException(String.format("Could not find any Registry Client that was able to fetch flow with Branch [%s] Bucket [%s] Flow [%s] Version [%s] with Storage Location [%s]",
+ branch, bucketId, flowId, version, storageLocation));
}
private List<FlowRegistryClientNode> getRegistryClientsForInternalFlow(final String storageLocation) {
@@ -409,6 +425,7 @@ public final class StandardFlowRegistryClientNode extends AbstractComponentNode
final String comments,
final String expectedVersion) {
final RegisteredFlowSnapshotMetadata metadata = new RegisteredFlowSnapshotMetadata();
+ metadata.setBranch(flow.getBranch());
metadata.setBucketIdentifier(flow.getBucketIdentifier());
metadata.setFlowIdentifier(flow.getIdentifier());
metadata.setAuthor(extractIdentity(context));
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardVersionControlInformation.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardVersionControlInformation.java
index 6eaae7eec9..9c3f5fd0b2 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardVersionControlInformation.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardVersionControlInformation.java
@@ -26,6 +26,7 @@ public class StandardVersionControlInformation implements VersionControlInformat
private final String registryIdentifier;
private volatile String registryName;
+ private final String branch;
private final String bucketIdentifier;
private volatile String bucketName;
private final String flowIdentifier;
@@ -39,6 +40,7 @@ public class StandardVersionControlInformation implements VersionControlInformat
public static class Builder {
private String registryIdentifier;
private String registryName;
+ private String branch;
private String bucketIdentifier;
private String bucketName;
private String flowIdentifier;
@@ -59,6 +61,11 @@ public class StandardVersionControlInformation implements VersionControlInformat
return this;
}
+ public Builder branch(String branch) {
+ this.branch = branch;
+ return this;
+ }
+
public Builder bucketId(String bucketId) {
this.bucketIdentifier = bucketId;
return this;
@@ -108,6 +115,7 @@ public class StandardVersionControlInformation implements VersionControlInformat
Builder builder = new Builder();
builder.registryId(dto.getRegistryId())
.registryName(dto.getRegistryName())
+ .branch(dto.getBranch())
.bucketId(dto.getBucketId())
.bucketName(dto.getBucketName())
.flowId(dto.getFlowId())
@@ -137,7 +145,7 @@ public class StandardVersionControlInformation implements VersionControlInformat
Objects.requireNonNull(version, "Version must be specified");
final StandardVersionControlInformation svci = new StandardVersionControlInformation(registryIdentifier, registryName,
- bucketIdentifier, flowIdentifier, version, storageLocation, flowSnapshot, status);
+ branch, bucketIdentifier, flowIdentifier, version, storageLocation, flowSnapshot, status);
svci.setBucketName(bucketName);
svci.setFlowName(flowName);
@@ -149,10 +157,11 @@ public class StandardVersionControlInformation implements VersionControlInformat
}
- public StandardVersionControlInformation(final String registryId, final String registryName, final String bucketId, final String flowId, final String version,
+ public StandardVersionControlInformation(final String registryId, final String registryName, final String branch, final String bucketId, final String flowId, final String version,
final String storageLocation, final VersionedProcessGroup snapshot, final VersionedFlowStatus status) {
this.registryIdentifier = registryId;
this.registryName = registryName;
+ this.branch = branch;
this.bucketIdentifier = bucketId;
this.flowIdentifier = flowId;
this.version = version;
@@ -176,6 +185,11 @@ public class StandardVersionControlInformation implements VersionControlInformat
this.registryName = registryName;
}
+ @Override
+ public String getBranch() {
+ return branch;
+ }
+
@Override
public String getBucketIdentifier() {
return bucketIdentifier;
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java
index 6920fe9e97..181514cdc7 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java
@@ -180,6 +180,7 @@ public class NiFiRegistryFlowMapper {
final String storageLocation = versionControlInfo.getStorageLocation();
coordinates.setStorageLocation(storageLocation);
+ coordinates.setBranch(versionControlInfo.getBranch());
coordinates.setBucketId(versionControlInfo.getBucketIdentifier());
coordinates.setFlowId(versionControlInfo.getFlowIdentifier());
coordinates.setVersion(versionControlInfo.getVersion());
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/groups/ProcessGroup.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/groups/ProcessGroup.java
index cff9275922..44d3359c74 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/groups/ProcessGroup.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/groups/ProcessGroup.java
@@ -39,6 +39,7 @@ import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.parameter.ParameterContext;
import org.apache.nifi.parameter.ParameterUpdate;
import org.apache.nifi.processor.Processor;
+import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.VersionControlInformation;
import org.apache.nifi.registry.flow.mapping.FlowMappingOptions;
import org.apache.nifi.remote.RemoteGroupPort;
@@ -1009,7 +1010,7 @@ public interface ProcessGroup extends ComponentAuthorizable, Positionable, Versi
*
* @throws IllegalStateException if the Process Group cannot currently be saved to a Flow Registry
*/
- void verifyCanSaveToFlowRegistry(String registryId, String bucketId, String flowId, String saveAction);
+ void verifyCanSaveToFlowRegistry(String registryId, FlowLocation flowLocation, String saveAction);
/**
* @return the version control information that indicates where this flow is stored in a Flow Registry,
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClientNode.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClientNode.java
index 179f6210cd..bc4b584490 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClientNode.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/FlowRegistryClientNode.java
@@ -36,16 +36,20 @@ public interface FlowRegistryClientNode extends ComponentNode {
boolean isStorageLocationApplicable(String location);
- Set<FlowRegistryBucket> getBuckets(FlowRegistryClientUserContext context) throws FlowRegistryException, IOException;
- FlowRegistryBucket getBucket(FlowRegistryClientUserContext context, String bucketId) throws FlowRegistryException, IOException;
+ boolean isBranchingSupported();
+ Set<FlowRegistryBranch> getBranches(FlowRegistryClientUserContext context) throws FlowRegistryException, IOException;
+ FlowRegistryBranch getDefaultBranch(FlowRegistryClientUserContext context) throws FlowRegistryException, IOException;
+
+ Set<FlowRegistryBucket> getBuckets(FlowRegistryClientUserContext context, String branch) throws FlowRegistryException, IOException;
+ FlowRegistryBucket getBucket(FlowRegistryClientUserContext context, BucketLocation bucketLocation) throws FlowRegistryException, IOException;
RegisteredFlow registerFlow(FlowRegistryClientUserContext context, RegisteredFlow flow) throws FlowRegistryException, IOException;
- RegisteredFlow deregisterFlow(FlowRegistryClientUserContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
+ RegisteredFlow deregisterFlow(FlowRegistryClientUserContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
- RegisteredFlow getFlow(FlowRegistryClientUserContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
- Set<RegisteredFlow> getFlows(FlowRegistryClientUserContext context, String bucketId) throws FlowRegistryException, IOException;
+ RegisteredFlow getFlow(FlowRegistryClientUserContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
+ Set<RegisteredFlow> getFlows(FlowRegistryClientUserContext context, BucketLocation bucketLocation) throws FlowRegistryException, IOException;
- FlowSnapshotContainer getFlowContents(FlowRegistryClientUserContext context, String bucketId, String flowId, String version, boolean fetchRemoteFlows) throws FlowRegistryException, IOException;
+ FlowSnapshotContainer getFlowContents(FlowRegistryClientUserContext context, FlowVersionLocation flowVersionLocation, boolean fetchRemoteFlows) throws FlowRegistryException, IOException;
RegisteredFlowSnapshot registerFlowSnapshot(
FlowRegistryClientUserContext context,
RegisteredFlow flow,
@@ -56,8 +60,8 @@ public interface FlowRegistryClientNode extends ComponentNode {
String expectedVersion, RegisterAction registerAction
) throws FlowRegistryException, IOException;
- Set<RegisteredFlowSnapshotMetadata> getFlowVersions(FlowRegistryClientUserContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
- Optional<String> getLatestVersion(FlowRegistryClientUserContext context, String bucketId, String flowId) throws FlowRegistryException, IOException;
+ Set<RegisteredFlowSnapshotMetadata> getFlowVersions(FlowRegistryClientUserContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
+ Optional<String> getLatestVersion(FlowRegistryClientUserContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;
void setComponent(LoggableComponent<FlowRegistryClient> component);
}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/GhostFlowRegistryClient.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/GhostFlowRegistryClient.java
index c799dfc86a..be6bf55130 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/GhostFlowRegistryClient.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/GhostFlowRegistryClient.java
@@ -83,12 +83,12 @@ public class GhostFlowRegistryClient implements FlowRegistryClient {
}
@Override
- public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientConfigurationContext context) throws FlowRegistryException {
+ public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientConfigurationContext context, final String branch) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@Override
- public FlowRegistryBucket getBucket(final FlowRegistryClientConfigurationContext context, final String bucketId) throws FlowRegistryException {
+ public FlowRegistryBucket getBucket(final FlowRegistryClientConfigurationContext context, final BucketLocation bucketLocation) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@@ -98,22 +98,22 @@ public class GhostFlowRegistryClient implements FlowRegistryClient {
}
@Override
- public RegisteredFlow deregisterFlow(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException {
+ public RegisteredFlow deregisterFlow(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@Override
- public RegisteredFlow getFlow(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException {
+ public RegisteredFlow getFlow(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@Override
- public Set<RegisteredFlow> getFlows(final FlowRegistryClientConfigurationContext context, final String bucketId) throws FlowRegistryException {
+ public Set<RegisteredFlow> getFlows(final FlowRegistryClientConfigurationContext context, final BucketLocation bucketLocation) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@Override
- public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId, final String version)
+ public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final FlowVersionLocation flowVersionLocation)
throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@@ -125,12 +125,12 @@ public class GhostFlowRegistryClient implements FlowRegistryClient {
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException {
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
@Override
- public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws FlowRegistryException {
+ public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws FlowRegistryException {
throw new FlowRegistryException(ERROR_MESSAGE);
}
}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/VersionControlInformation.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/VersionControlInformation.java
index d038fbe34b..7f7388621a 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/VersionControlInformation.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/registry/flow/VersionControlInformation.java
@@ -37,6 +37,11 @@ public interface VersionControlInformation {
*/
String getRegistryName();
+ /**
+ * @return the name of the branch that the flow is tracking to
+ */
+ String getBranch();
+
/**
* @return the unique identifier of the bucket that this flow belongs to
*/
diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/mock/MockProcessGroup.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/mock/MockProcessGroup.java
index 1fcae2df86..f08ec1e873 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/mock/MockProcessGroup.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/mock/MockProcessGroup.java
@@ -48,6 +48,7 @@ import org.apache.nifi.groups.StatelessGroupNode;
import org.apache.nifi.groups.StatelessGroupScheduledState;
import org.apache.nifi.parameter.ParameterContext;
import org.apache.nifi.parameter.ParameterUpdate;
+import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.VersionControlInformation;
import org.apache.nifi.registry.flow.mapping.FlowMappingOptions;
import org.apache.nifi.remote.RemoteGroupPort;
@@ -696,7 +697,7 @@ public class MockProcessGroup implements ProcessGroup {
}
@Override
- public void verifyCanSaveToFlowRegistry(String registryId, String bucketId, String flowId, String action) {
+ public void verifyCanSaveToFlowRegistry(String registryId, FlowLocation flowLocation, String action) {
}
@Override
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
index 424e1a6cb3..b372d5cc83 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
@@ -35,6 +35,7 @@ import org.apache.nifi.flow.VersionedProcessGroup;
import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.parameter.ParameterContext;
import org.apache.nifi.parameter.ParameterGroupConfiguration;
+import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.FlowSnapshotContainer;
import org.apache.nifi.registry.flow.RegisterAction;
import org.apache.nifi.registry.flow.RegisteredFlow;
@@ -107,6 +108,7 @@ import org.apache.nifi.web.api.entity.FlowBreadcrumbEntity;
import org.apache.nifi.web.api.entity.FlowComparisonEntity;
import org.apache.nifi.web.api.entity.FlowConfigurationEntity;
import org.apache.nifi.web.api.entity.FlowEntity;
+import org.apache.nifi.web.api.entity.FlowRegistryBranchEntity;
import org.apache.nifi.web.api.entity.FlowRegistryBucketEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
import org.apache.nifi.web.api.entity.FunnelEntity;
@@ -1492,11 +1494,12 @@ public interface NiFiServiceFacade {
* Deletes the specified Versioned Flow from the specified Flow Registry
*
* @param registryId the ID of the Flow Registry
+ * @param branch the branch for the flow
* @param bucketId the ID of the bucket
* @param flowId the ID of the flow
* @return the VersionedFlow that was deleted
*/
- RegisteredFlow deleteVersionedFlow(String registryId, String bucketId, String flowId);
+ RegisteredFlow deleteVersionedFlow(String registryId, String branch, String bucketId, String flowId);
/**
* Adds the given snapshot to the already existing Versioned Flow, which resides in the given Flow Registry with the given id
@@ -1646,13 +1649,12 @@ public interface NiFiServiceFacade {
*
* @param groupId the ID of the Process Group
* @param registryId the ID of the Flow Registry
- * @param bucketId the ID of the bucket
- * @param flowId the ID of the flow
+ * @param flowLocation the flow location in the registry
* @param saveAction the save action being performed
*
* @throws IllegalStateException if the Process Group cannot be saved to the flow registry with the coordinates specified
*/
- void verifyCanSaveToFlowRegistry(String groupId, String registryId, String bucketId, String flowId, String saveAction);
+ void verifyCanSaveToFlowRegistry(String groupId, String registryId, FlowLocation flowLocation, String saveAction);
/**
* Verifies that the Process Group with the given identifier can have its local modifications reverted to the given VersionedFlowSnapshot
@@ -2393,13 +2395,29 @@ public interface NiFiServiceFacade {
*/
PropertyDescriptorDTO getRegistryClientPropertyDescriptor(final String id, final String property, final boolean sensitive);
+ /**
+ * Returns the default branch for the given registry client.
+ *
+ * @param registryClientId registry client id
+ * @return the default branch
+ */
+ FlowRegistryBranchEntity getDefaultBranch(String registryClientId);
+
+ /**
+ * Returns the branches in the given registry.
+ *
+ * @param registryClientId registry client id
+ * @return the branches
+ */
+ Set<FlowRegistryBranchEntity> getBranches(String registryClientId);
+
/**
* Gets all buckets for a given registry.
*
* @param registryClientId registry client id
* @return the buckets
*/
- Set<FlowRegistryBucketEntity> getBucketsForUser(String registryClientId);
+ Set<FlowRegistryBucketEntity> getBucketsForUser(String registryClientId, String branch);
/**
* Gets the flows for the current user for the specified registry and bucket.
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index 865a93e974..c88dc8818e 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -143,13 +143,17 @@ import org.apache.nifi.prometheus.util.ConnectionAnalyticsMetricsRegistry;
import org.apache.nifi.prometheus.util.JvmMetricsRegistry;
import org.apache.nifi.prometheus.util.NiFiMetricsRegistry;
import org.apache.nifi.prometheus.util.PrometheusMetricsUtil;
+import org.apache.nifi.registry.flow.FlowLocation;
+import org.apache.nifi.registry.flow.FlowRegistryBranch;
import org.apache.nifi.registry.flow.FlowRegistryBucket;
import org.apache.nifi.registry.flow.FlowRegistryClientContextFactory;
import org.apache.nifi.registry.flow.FlowRegistryClientNode;
+import org.apache.nifi.registry.flow.FlowRegistryClientUserContext;
import org.apache.nifi.registry.flow.FlowRegistryException;
import org.apache.nifi.registry.flow.FlowRegistryPermissions;
import org.apache.nifi.registry.flow.FlowRegistryUtil;
import org.apache.nifi.registry.flow.FlowSnapshotContainer;
+import org.apache.nifi.registry.flow.FlowVersionLocation;
import org.apache.nifi.registry.flow.RegisterAction;
import org.apache.nifi.registry.flow.RegisteredFlow;
import org.apache.nifi.registry.flow.RegisteredFlowSnapshot;
@@ -216,6 +220,7 @@ import org.apache.nifi.web.api.dto.FlowAnalysisRuleDTO;
import org.apache.nifi.web.api.dto.FlowAnalysisRuleViolationDTO;
import org.apache.nifi.web.api.dto.FlowConfigurationDTO;
import org.apache.nifi.web.api.dto.FlowFileDTO;
+import org.apache.nifi.web.api.dto.FlowRegistryBranchDTO;
import org.apache.nifi.web.api.dto.FlowRegistryBucketDTO;
import org.apache.nifi.web.api.dto.FlowRegistryClientDTO;
import org.apache.nifi.web.api.dto.FlowSnippetDTO;
@@ -299,6 +304,7 @@ import org.apache.nifi.web.api.entity.FlowBreadcrumbEntity;
import org.apache.nifi.web.api.entity.FlowComparisonEntity;
import org.apache.nifi.web.api.entity.FlowConfigurationEntity;
import org.apache.nifi.web.api.entity.FlowEntity;
+import org.apache.nifi.web.api.entity.FlowRegistryBranchEntity;
import org.apache.nifi.web.api.entity.FlowRegistryBucketEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
import org.apache.nifi.web.api.entity.FunnelEntity;
@@ -2753,6 +2759,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final VersionedFlowCoordinates childCoordinates = childGroup.getVersionedFlowCoordinates();
if (childCoordinates != null) {
final VersionControlInformationDTO childVci = new VersionControlInformationDTO();
+ childVci.setBranch(childCoordinates.getBranch());
childVci.setBucketId(childCoordinates.getBucketId());
childVci.setFlowId(childCoordinates.getFlowId());
verifyImportProcessGroup(childVci, childGroup, group);
@@ -3202,8 +3209,29 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
@Override
- public Set<FlowRegistryBucketEntity> getBucketsForUser(final String registryClientId) {
- return flowRegistryDAO.getBucketsForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId).stream()
+ public FlowRegistryBranchEntity getDefaultBranch(final String registryClientId) {
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ final FlowRegistryBranch branch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
+ final FlowRegistryBranchDTO branchDto = dtoFactory.createBranchDTO(branch);
+ return entityFactory.createBranchEntity(branchDto);
+ }
+
+ @Override
+ public Set<FlowRegistryBranchEntity> getBranches(final String registryClientId) {
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ return flowRegistryDAO.getBranchesForUser(clientUserContext, registryClientId).stream()
+ .filter(Objects::nonNull)
+ .map(branch -> {
+ final FlowRegistryBranchDTO branchDto = dtoFactory.createBranchDTO(branch);
+ return entityFactory.createBranchEntity(branchDto);
+ })
+ .collect(Collectors.toCollection(LinkedHashSet::new));
+ }
+
+ @Override
+ public Set<FlowRegistryBucketEntity> getBucketsForUser(final String registryClientId, final String branch) {
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ return flowRegistryDAO.getBucketsForUser(clientUserContext, registryClientId, branch).stream()
.map(bucket -> {
if (bucket == null) {
return null;
@@ -3222,25 +3250,31 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
return entityFactory.createBucketEntity(dto, permissions);
})
- .collect(Collectors.toSet());
+ .collect(Collectors.toCollection(LinkedHashSet::new));
}
@Override
public Set<VersionedFlowEntity> getFlowsForUser(final String registryClientId, final String bucketId) {
- return flowRegistryDAO.getFlowsForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId, bucketId).stream()
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ final FlowRegistryBranch defaultBranch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
+ return flowRegistryDAO.getFlowsForUser(clientUserContext, registryClientId, defaultBranch.getName(), bucketId).stream()
.map(rf -> createVersionedFlowEntity(registryClientId, rf))
.collect(Collectors.toSet());
}
@Override
public VersionedFlowEntity getFlowForUser(final String registryClientId, final String bucketId, final String flowId) {
- final RegisteredFlow flow = flowRegistryDAO.getFlowForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId, bucketId, flowId);
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ final FlowRegistryBranch defaultBranch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
+ final RegisteredFlow flow = flowRegistryDAO.getFlowForUser(clientUserContext, registryClientId, defaultBranch.getName(), bucketId, flowId);
return createVersionedFlowEntity(registryClientId, flow);
}
@Override
public Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(final String registryClientId, final String bucketId, final String flowId) {
- return flowRegistryDAO.getFlowVersionsForUser(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), registryClientId, bucketId, flowId).stream()
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ final FlowRegistryBranch defaultBranch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
+ return flowRegistryDAO.getFlowVersionsForUser(clientUserContext, registryClientId, defaultBranch.getName(), bucketId, flowId).stream()
.map(md -> createVersionedFlowSnapshotMetadataEntity(registryClientId, md))
.collect(Collectors.toSet());
}
@@ -3274,6 +3308,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final VersionedFlowDTO dto = new VersionedFlowDTO();
dto.setRegistryId(registryId);
+ dto.setBranch(registeredFlow.getBranch());
dto.setBucketId(registeredFlow.getBucketIdentifier());
dto.setFlowId(registeredFlow.getIdentifier());
dto.setFlowName(registeredFlow.getName());
@@ -4987,8 +5022,19 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final Map<String, VersionedParameterContext> parameterContexts = createVersionedParameterContexts(processGroup, parameterProviderReferences);
final String flowId = versionedFlowDto.getFlowId() == null ? UUID.randomUUID().toString() : versionedFlowDto.getFlowId();
+ final String registryId = requestEntity.getVersionedFlow().getRegistryId();
+
+ final String selectedBranch;
+ final String submittedBranch = versionedFlowDto.getBranch();
+ final String currentVciBranch = currentVci == null ? null : currentVci.getBranch();
+ if (submittedBranch == null) {
+ selectedBranch = currentVciBranch == null ? getDefaultBranchName(registryId): currentVciBranch;
+ } else {
+ selectedBranch = submittedBranch;
+ }
final RegisteredFlow versionedFlow = new RegisteredFlow();
+ versionedFlow.setBranch(selectedBranch);
versionedFlow.setBucketIdentifier(versionedFlowDto.getBucketId());
versionedFlow.setCreatedTimestamp(System.currentTimeMillis());
versionedFlow.setDescription(versionedFlowDto.getDescription());
@@ -4997,7 +5043,6 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
versionedFlow.setIdentifier(flowId);
// Add the Versioned Flow and first snapshot to the Flow Registry
- final String registryId = requestEntity.getVersionedFlow().getRegistryId();
final RegisteredFlowSnapshot registeredSnapshot;
final RegisteredFlow registeredFlow;
final boolean registerNewFlow = versionedFlowDto.getFlowId() == null;
@@ -5007,7 +5052,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
if (registerNewFlow) {
registeredFlow = registerVersionedFlow(registryId, versionedFlow);
} else {
- registeredFlow = getVersionedFlow(registryId, versionedFlowDto.getBucketId(), versionedFlowDto.getFlowId());
+ registeredFlow = getVersionedFlow(registryId, selectedBranch, versionedFlowDto.getBucketId(), versionedFlowDto.getFlowId());
}
} catch (final FlowRegistryException e) {
throw new IllegalArgumentException(e.getLocalizedMessage());
@@ -5024,9 +5069,9 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
// then we need to capture the created versioned flow information as a partial successful result.
if (registerNewFlow) {
try {
- flowRegistryDAO
- .getFlowRegistryClient(registryId)
- .deregisterFlow(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), versionedFlowDto.getBucketId(), flowId);
+ final FlowLocation flowLocation = new FlowLocation(selectedBranch, versionedFlowDto.getBucketId(), flowId);
+ final FlowRegistryClientNode flowRegistryClientNode = flowRegistryDAO.getFlowRegistryClient(registryId);
+ flowRegistryClientNode.deregisterFlow(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), flowLocation);
} catch (final IOException | FlowRegistryException e2) {
throw new NiFiCoreException("Failed to remove flow from Flow Registry due to " + e2.getMessage(), e2);
}
@@ -5040,6 +5085,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
// Update the Process Group with the new VersionControlInformation. (Send this to all nodes).
final VersionControlInformationDTO vci = new VersionControlInformationDTO();
+ vci.setBranch(flow.getBranch());
vci.setBucketId(bucket.getIdentifier());
vci.setBucketName(bucket.getName());
vci.setFlowId(flow.getIdentifier());
@@ -5154,26 +5200,27 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupId);
final VersionControlInformation versionControlInfo = processGroup.getVersionControlInformation();
- return getVersionedFlowSnapshot(versionControlInfo.getRegistryIdentifier(), versionControlInfo.getBucketIdentifier(),
+ return getVersionedFlowSnapshot(versionControlInfo.getRegistryIdentifier(), versionControlInfo.getBranch(), versionControlInfo.getBucketIdentifier(),
versionControlInfo.getFlowIdentifier(), versionControlInfo.getVersion(), true);
}
@Override
public FlowSnapshotContainer getVersionedFlowSnapshot(final VersionControlInformationDTO versionControlInfo, final boolean fetchRemoteFlows) {
- return getVersionedFlowSnapshot(versionControlInfo.getRegistryId(), versionControlInfo.getBucketId(), versionControlInfo.getFlowId(),
- versionControlInfo.getVersion(), fetchRemoteFlows);
+ return getVersionedFlowSnapshot(versionControlInfo.getRegistryId(), versionControlInfo.getBranch(), versionControlInfo.getBucketId(),
+ versionControlInfo.getFlowId(), versionControlInfo.getVersion(), fetchRemoteFlows);
}
/**
*
* @param registryId the id of the registry to retrieve the versioned flow from
+ * @param branch the name of the branch within the registry
* @param bucketId the id of the bucket within the registry
* @param flowId the id of the flow within the bucket/registry
* @param flowVersion the version of the flow to retrieve
* @param fetchRemoteFlows indicator to include remote flows when retrieving the flow
* @return a VersionedFlowSnapshot from a registry with the given version
*/
- private FlowSnapshotContainer getVersionedFlowSnapshot(final String registryId, final String bucketId, final String flowId,
+ private FlowSnapshotContainer getVersionedFlowSnapshot(final String registryId, final String branch, final String bucketId, final String flowId,
final String flowVersion, final boolean fetchRemoteFlows) {
final FlowRegistryClientNode flowRegistry = flowRegistryDAO.getFlowRegistryClient(registryId);
if (flowRegistry == null) {
@@ -5181,7 +5228,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
try {
- return flowRegistry.getFlowContents(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), bucketId, flowId, flowVersion, fetchRemoteFlows);
+ final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
+ final String selectedBranch = branch == null ? flowRegistry.getDefaultBranch(clientUserContext).getName() : branch;
+ final FlowVersionLocation flowVersionLocation = new FlowVersionLocation(selectedBranch, bucketId, flowId, flowVersion);
+ return flowRegistry.getFlowContents(clientUserContext, flowVersionLocation, fetchRemoteFlows);
} catch (final FlowRegistryException e) {
logger.error(e.getMessage(), e);
throw new IllegalArgumentException("The Flow Registry with ID " + registryId + " reports that no Flow exists with Bucket "
@@ -5192,14 +5242,15 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
@Override
- public RegisteredFlow deleteVersionedFlow(final String registryId, final String bucketId, final String flowId) {
+ public RegisteredFlow deleteVersionedFlow(final String registryId, final String branch, final String bucketId, final String flowId) {
final FlowRegistryClientNode registry = flowRegistryDAO.getFlowRegistryClient(registryId);
if (registry == null) {
throw new IllegalArgumentException("No Flow Registry exists with ID " + registryId);
}
try {
- return registry.deregisterFlow(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), bucketId, flowId);
+ final FlowLocation flowLocation = new FlowLocation(branch, bucketId, flowId);
+ return registry.deregisterFlow(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), flowLocation);
} catch (final IOException | FlowRegistryException e) {
throw new NiFiCoreException("Failed to remove flow from Flow Registry due to " + e.getMessage(), e);
}
@@ -5269,8 +5320,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
if (registryGroup == null) {
try {
+ final FlowVersionLocation flowVersionLocation = new FlowVersionLocation(versionControlInfo.getBranch(), versionControlInfo.getBucketIdentifier(),
+ versionControlInfo.getFlowIdentifier(), versionControlInfo.getVersion());
final FlowSnapshotContainer flowSnapshotContainer = flowRegistry.getFlowContents(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()),
- versionControlInfo.getBucketIdentifier(), versionControlInfo.getFlowIdentifier(), versionControlInfo.getVersion(), true);
+ flowVersionLocation, true);
final RegisteredFlowSnapshot versionedFlowSnapshot = flowSnapshotContainer.getFlowSnapshot();
registryGroup = versionedFlowSnapshot.getFlowContents();
} catch (final IOException | FlowRegistryException e) {
@@ -5310,13 +5363,30 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
}
- private RegisteredFlow getVersionedFlow(final String registryId, final String bucketId, final String flowId) throws IOException, FlowRegistryException {
+ private String getDefaultBranchName(final String registryId) {
+ final FlowRegistryClientNode registry = flowRegistryDAO.getFlowRegistryClient(registryId);
+ if (registry == null) {
+ throw new ResourceNotFoundException("No Flow Registry exists with ID " + registryId);
+ }
+
+ try {
+ final FlowRegistryBranch defaultBranch = registry.getDefaultBranch(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()));
+ return defaultBranch.getName();
+ } catch (final FlowRegistryException e) {
+ throw new IllegalArgumentException(e.getLocalizedMessage());
+ } catch (final IOException ioe) {
+ throw new IllegalStateException("Failed to communicate with Flow Registry when attempting to get default branch");
+ }
+ }
+
+ private RegisteredFlow getVersionedFlow(final String registryId, final String branch, final String bucketId, final String flowId) throws IOException, FlowRegistryException {
final FlowRegistryClientNode registry = flowRegistryDAO.getFlowRegistryClient(registryId);
if (registry == null) {
throw new ResourceNotFoundException("No Flow Registry exists with ID " + registryId);
}
- return registry.getFlow(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), bucketId, flowId);
+ final FlowLocation flowLocation = new FlowLocation(branch, bucketId, flowId);
+ return registry.getFlow(FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser()), flowLocation);
}
@Override
@@ -5402,9 +5472,9 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
@Override
- public void verifyCanSaveToFlowRegistry(final String groupId, final String registryId, final String bucketId, final String flowId, final String saveAction) {
+ public void verifyCanSaveToFlowRegistry(final String groupId, final String registryId, final FlowLocation flowLocation, final String saveAction) {
final ProcessGroup group = processGroupDAO.getProcessGroup(groupId);
- group.verifyCanSaveToFlowRegistry(registryId, bucketId, flowId, saveAction);
+ group.verifyCanSaveToFlowRegistry(registryId, flowLocation, saveAction);
}
@Override
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
index 6ed92d1d73..c62147a368 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
@@ -90,6 +90,8 @@ import org.apache.nifi.web.api.entity.FlowAnalysisResultEntity;
import org.apache.nifi.web.api.entity.FlowAnalysisRuleTypesEntity;
import org.apache.nifi.web.api.entity.FlowBreadcrumbEntity;
import org.apache.nifi.web.api.entity.FlowConfigurationEntity;
+import org.apache.nifi.web.api.entity.FlowRegistryBranchEntity;
+import org.apache.nifi.web.api.entity.FlowRegistryBranchesEntity;
import org.apache.nifi.web.api.entity.FlowRegistryBucketEntity;
import org.apache.nifi.web.api.entity.FlowRegistryBucketsEntity;
import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
@@ -1866,6 +1868,43 @@ public class FlowResource extends ApplicationResource {
return flowRegistryClientsEntity;
}
+ @GET
+ @Consumes(MediaType.WILDCARD)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("registries/{id}/branches")
+ @Operation(
+ summary = "Gets the branches from the specified registry for the current user",
+ responses = @ApiResponse(content = @Content(schema = @Schema(implementation = FlowRegistryBranchesEntity.class))),
+ security = {
+ @SecurityRequirement(name = "Read - /flow")
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
+ @ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
+ @ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
+ @ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
+ @ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
+ }
+ )
+ public Response getBranches(
+ @Parameter(
+ description = "The registry id.",
+ required = true
+ )
+ @PathParam("id") String id) throws NiFiRegistryException {
+
+ authorizeFlow();
+
+ final Set<FlowRegistryBranchEntity> branches = serviceFacade.getBranches(id);
+
+ final FlowRegistryBranchesEntity flowRegistryBranchesEntity = new FlowRegistryBranchesEntity();
+ flowRegistryBranchesEntity.setBranches(branches);
+
+ return generateOkResponse(flowRegistryBranchesEntity).build();
+ }
+
@GET
@Consumes(MediaType.WILDCARD)
@@ -1892,11 +1931,16 @@ public class FlowResource extends ApplicationResource {
description = "The registry id.",
required = true
)
- @PathParam("id") String id) throws NiFiRegistryException {
+ @PathParam("id") String id,
+ @Parameter(
+ description = "The name of a branch to get the buckets from. If not specified the default branch of the registry client will be used."
+ )
+ @QueryParam("branch") String branch) throws NiFiRegistryException {
authorizeFlow();
- final Set<FlowRegistryBucketEntity> buckets = serviceFacade.getBucketsForUser(id);
+ final String selectedBranch = branch == null ? serviceFacade.getDefaultBranch(id).getBranch().getName() : branch;
+ final Set<FlowRegistryBucketEntity> buckets = serviceFacade.getBucketsForUser(id, selectedBranch);
final SortedSet<FlowRegistryBucketEntity> sortedBuckets = sortBuckets(buckets);
final FlowRegistryBucketsEntity flowRegistryBucketsEntity = new FlowRegistryBucketsEntity();
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java
index a8e993645d..894c114e71 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java
@@ -951,6 +951,9 @@ public class ProcessGroupResource extends FlowUpdateResource<ProcessGroupImportE
versionControlInfo.setStorageLocation(versionedFlowCoordinates.getStorageLocation());
}
}
+ if (flowSnapshot.getSnapshotMetadata() != null && flowSnapshot.getSnapshotMetadata().getBranch() != null && versionControlInfo.getBranch() == null) {
+ versionControlInfo.setBranch(flowSnapshot.getSnapshotMetadata().getBranch());
+ }
// Step 4: Replace parameter contexts if necessary
if (ParameterContextHandlingStrategy.REPLACE.equals(parameterContextHandlingStrategy)) {
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/VersionsResource.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/VersionsResource.java
index 305d95b634..352c9767db 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/VersionsResource.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/VersionsResource.java
@@ -59,6 +59,7 @@ import org.apache.nifi.authorization.user.NiFiUserUtils;
import org.apache.nifi.cluster.manager.NodeResponse;
import org.apache.nifi.controller.flow.FlowManager;
import org.apache.nifi.flow.VersionedProcessGroup;
+import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.FlowRegistryBucket;
import org.apache.nifi.registry.flow.FlowSnapshotContainer;
import org.apache.nifi.registry.flow.RegisteredFlow;
@@ -596,10 +597,9 @@ public class VersionsResource extends FlowUpdateResource<VersionControlInformati
() -> {
final VersionedFlowDTO versionedFlow = requestEntity.getVersionedFlow();
final String registryId = versionedFlow.getRegistryId();
- final String bucketId = versionedFlow.getBucketId();
- final String flowId = versionedFlow.getFlowId();
final String action = versionedFlow.getAction();
- serviceFacade.verifyCanSaveToFlowRegistry(groupId, registryId, bucketId, flowId, action);
+ final FlowLocation flowLocation = new FlowLocation(versionedFlow.getBranch(), versionedFlow.getBucketId(), versionedFlow.getFlowId());
+ serviceFacade.verifyCanSaveToFlowRegistry(groupId, registryId, flowLocation, action);
},
(rev, flowEntity) -> {
// Register the current flow with the Flow Registry.
@@ -689,7 +689,7 @@ public class VersionsResource extends FlowUpdateResource<VersionControlInformati
// flow from the Flow Registry (use best effort; if we can't remove it, just log and move on).
final VersionControlInformationDTO vci = mappingEntity.getVersionControlInformation();
try {
- serviceFacade.deleteVersionedFlow(vci.getRegistryId(), vci.getBucketId(), vci.getFlowId());
+ serviceFacade.deleteVersionedFlow(vci.getRegistryId(), vci.getBranch(), vci.getBucketId(), vci.getFlowId());
} catch (final Exception e) {
logger.error("Created Versioned Flow with ID {} in bucket with ID {} but failed to replicate the Version Control Information to cluster. "
+ "Attempted to delete the newly created (empty) flow from the Flow Registry but failed", vci.getFlowId(), vci.getBucketId(), e);
@@ -705,7 +705,7 @@ public class VersionsResource extends FlowUpdateResource<VersionControlInformati
// flow from the Flow Registry (use best effort; if we can't remove it, just log and move on).
final VersionControlInformationDTO vci = mappingEntity.getVersionControlInformation();
try {
- serviceFacade.deleteVersionedFlow(vci.getRegistryId(), vci.getBucketId(), vci.getFlowId());
+ serviceFacade.deleteVersionedFlow(vci.getRegistryId(), vci.getBranch(), vci.getBucketId(), vci.getFlowId());
} catch (final Exception e) {
logger.error("Created Versioned Flow with ID {} in bucket with ID {} but failed to replicate the Version Control Information to cluster. "
+ "Attempted to delete the newly created (empty) flow from the Flow Registry but failed", vci.getFlowId(), vci.getBucketId(), e);
@@ -1247,6 +1247,7 @@ public class VersionsResource extends FlowUpdateResource<VersionControlInformati
final RegisteredFlowSnapshotMetadata metadata = flowSnapshot.getSnapshotMetadata();
final VersionControlInformationDTO versionControlInfo = new VersionControlInformationDTO();
+ versionControlInfo.setBranch(requestVci.getBranch());
versionControlInfo.setBucketId(metadata.getBucketIdentifier());
versionControlInfo.setBucketName(bucket.getName());
versionControlInfo.setFlowDescription(flow.getDescription());
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java
index 87c77d92a7..095c6190fc 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java
@@ -146,6 +146,7 @@ import org.apache.nifi.provenance.lineage.ComputeLineageSubmission;
import org.apache.nifi.provenance.lineage.LineageEdge;
import org.apache.nifi.provenance.lineage.LineageNode;
import org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode;
+import org.apache.nifi.registry.flow.FlowRegistryBranch;
import org.apache.nifi.registry.flow.FlowRegistryClient;
import org.apache.nifi.registry.flow.FlowRegistryClientNode;
import org.apache.nifi.registry.flow.VersionControlInformation;
@@ -2814,6 +2815,11 @@ public final class DtoFactory {
return dto;
}
+ public FlowRegistryBranchDTO createBranchDTO(final FlowRegistryBranch branch) {
+ final FlowRegistryBranchDTO branchDTO = new FlowRegistryBranchDTO();
+ branchDTO.setName(branch.getName());
+ return branchDTO;
+ }
public VersionControlInformationDTO createVersionControlInformationDto(final ProcessGroup group) {
if (group == null) {
@@ -2829,6 +2835,7 @@ public final class DtoFactory {
dto.setGroupId(group.getIdentifier());
dto.setRegistryId(versionControlInfo.getRegistryIdentifier());
dto.setRegistryName(versionControlInfo.getRegistryName());
+ dto.setBranch(versionControlInfo.getBranch());
dto.setBucketId(versionControlInfo.getBucketIdentifier());
dto.setBucketName(versionControlInfo.getBucketName());
dto.setFlowId(versionControlInfo.getFlowIdentifier());
@@ -4600,6 +4607,7 @@ public final class DtoFactory {
final VersionControlInformationDTO copy = new VersionControlInformationDTO();
copy.setRegistryId(original.getRegistryId());
copy.setRegistryName(original.getRegistryName());
+ copy.setBranch(original.getBranch());
copy.setBucketId(original.getBucketId());
copy.setBucketName(original.getBucketName());
copy.setFlowId(original.getFlowId());
@@ -4880,7 +4888,7 @@ public final class DtoFactory {
final List<Bundle> compatibleBundles = extensionManager.getBundles(flowRegistryClientNode.getCanonicalClassName()).stream().filter(bundle -> {
final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate();
return bundleCoordinate.getGroup().equals(coordinate.getGroup()) && bundleCoordinate.getId().equals(coordinate.getId());
- }).collect(Collectors.toList());
+ }).toList();
final FlowRegistryClientDTO dto = new FlowRegistryClientDTO();
dto.setId(flowRegistryClientNode.getIdentifier());
@@ -4890,18 +4898,14 @@ public final class DtoFactory {
dto.setBundle(createBundleDto(bundleCoordinate));
dto.setAnnotationData(flowRegistryClientNode.getAnnotationData());
dto.setSupportsSensitiveDynamicProperties(flowRegistryClientNode.isSupportsSensitiveDynamicProperties());
+ dto.setSupportsBranching(flowRegistryClientNode.isBranchingSupported());
dto.setRestricted(flowRegistryClientNode.isRestricted());
dto.setDeprecated(flowRegistryClientNode.isDeprecated());
dto.setExtensionMissing(flowRegistryClientNode.isExtensionMissing());
dto.setMultipleVersionsAvailable(compatibleBundles.size() > 1);
// sort a copy of the properties
- final Map<PropertyDescriptor, String> sortedProperties = new TreeMap<>(new Comparator<PropertyDescriptor>() {
- @Override
- public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
- return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
- }
- });
+ final Map<PropertyDescriptor, String> sortedProperties = new TreeMap<>((o1, o2) -> Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName()));
sortedProperties.putAll(flowRegistryClientNode.getRawPropertyValues());
// get the property order from the client
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java
index 2206582053..bcddd63933 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java
@@ -41,6 +41,7 @@ import org.apache.nifi.web.api.entity.AccessPolicySummaryEntity;
import org.apache.nifi.web.api.entity.ActionEntity;
import org.apache.nifi.web.api.entity.AffectedComponentEntity;
import org.apache.nifi.web.api.entity.AllowableValueEntity;
+import org.apache.nifi.web.api.entity.FlowRegistryBranchEntity;
import org.apache.nifi.web.api.entity.FlowRegistryBucketEntity;
import org.apache.nifi.web.api.entity.BulletinEntity;
import org.apache.nifi.web.api.entity.ComponentReferenceEntity;
@@ -827,4 +828,10 @@ public final class EntityFactory {
return entity;
}
+
+ public FlowRegistryBranchEntity createBranchEntity(final FlowRegistryBranchDTO dto) {
+ final FlowRegistryBranchEntity entity = new FlowRegistryBranchEntity();
+ entity.setBranch(dto);
+ return entity;
+ }
}
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java
index f6195d4f01..4f67088a46 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/FlowRegistryDAO.java
@@ -17,6 +17,7 @@
package org.apache.nifi.web.dao;
+import org.apache.nifi.registry.flow.FlowRegistryBranch;
import org.apache.nifi.registry.flow.FlowRegistryBucket;
import org.apache.nifi.registry.flow.FlowRegistryClientNode;
import org.apache.nifi.registry.flow.FlowRegistryClientUserContext;
@@ -38,13 +39,17 @@ public interface FlowRegistryDAO {
Set<FlowRegistryClientNode> getFlowRegistryClientsForUser(FlowRegistryClientUserContext context);
- Set<FlowRegistryBucket> getBucketsForUser(FlowRegistryClientUserContext context, String registry);
+ Set<FlowRegistryBranch> getBranchesForUser(FlowRegistryClientUserContext context, String registryId);
- Set<RegisteredFlow> getFlowsForUser(FlowRegistryClientUserContext context, String registryId, String bucketId);
+ FlowRegistryBranch getDefaultBranchForUser(FlowRegistryClientUserContext context, String registryId);
- RegisteredFlow getFlowForUser(FlowRegistryClientUserContext context, String registryId, String bucketId, String flowId);
+ Set<FlowRegistryBucket> getBucketsForUser(FlowRegistryClientUserContext context, String registryId, String branch);
- Set<RegisteredFlowSnapshotMetadata> getFlowVersionsForUser(FlowRegistryClientUserContext context, String registryId, String bucketId, String flowId);
+ Set<RegisteredFlow> getFlowsForUser(FlowRegistryClientUserContext context, String registryId, String branch, String bucketId);
+
+ RegisteredFlow getFlowForUser(FlowRegistryClientUserContext context, String registryId, String branch, String bucketId, String flowId);
+
+ Set<RegisteredFlowSnapshotMetadata> getFlowVersionsForUser(FlowRegistryClientUserContext context, String branch, String registryId, String bucketId, String flowId);
FlowRegistryClientNode removeFlowRegistry(String registryId);
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java
index 0341f6f7cc..5f4dba8e6d 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardFlowRegistryDAO.java
@@ -19,6 +19,9 @@ package org.apache.nifi.web.dao.impl;
import org.apache.nifi.bundle.BundleCoordinate;
import org.apache.nifi.controller.FlowController;
+import org.apache.nifi.registry.flow.BucketLocation;
+import org.apache.nifi.registry.flow.FlowLocation;
+import org.apache.nifi.registry.flow.FlowRegistryBranch;
import org.apache.nifi.registry.flow.FlowRegistryBucket;
import org.apache.nifi.registry.flow.FlowRegistryClientNode;
import org.apache.nifi.registry.flow.FlowRegistryClientUserContext;
@@ -104,16 +107,44 @@ public class StandardFlowRegistryDAO extends ComponentDAO implements FlowRegistr
}
@Override
- public Set<FlowRegistryBucket> getBucketsForUser(final FlowRegistryClientUserContext context, final String registryId) {
+ public Set<FlowRegistryBranch> getBranchesForUser(final FlowRegistryClientUserContext context, final String registryId) {
try {
final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
+ if (flowRegistry == null) {
+ throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
+ }
+ final Set<FlowRegistryBranch> branches = flowRegistry.getBranches(context);
+ final Set<FlowRegistryBranch> sortedBranches = new TreeSet<>(Comparator.comparing(FlowRegistryBranch::getName));
+ sortedBranches.addAll(branches);
+ return sortedBranches;
+ } catch (final IOException | FlowRegistryException ioe) {
+ throw new NiFiCoreException("Unable to get branches for registry with ID " + registryId + ": " + ioe, ioe);
+ }
+ }
+ @Override
+ public FlowRegistryBranch getDefaultBranchForUser(final FlowRegistryClientUserContext context, final String registryId) {
+ try {
+ final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
+ if (flowRegistry == null) {
+ throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
+ }
+ return flowRegistry.getDefaultBranch(context);
+ } catch (final IOException | FlowRegistryException ioe) {
+ throw new NiFiCoreException("Unable to get default branch for registry with ID " + registryId + ": " + ioe, ioe);
+ }
+ }
+
+ @Override
+ public Set<FlowRegistryBucket> getBucketsForUser(final FlowRegistryClientUserContext context, final String registryId, final String branch) {
+ try {
+ final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
if (flowRegistry == null) {
throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
}
- final Set<FlowRegistryBucket> buckets = flowRegistry.getBuckets(context);
- final Set<FlowRegistryBucket> sortedBuckets = new TreeSet<>((b1, b2) -> b1.getName().compareTo(b2.getName()));
+ final Set<FlowRegistryBucket> buckets = flowRegistry.getBuckets(context, branch);
+ final Set<FlowRegistryBucket> sortedBuckets = new TreeSet<>(Comparator.comparing(FlowRegistryBucket::getName));
sortedBuckets.addAll(buckets);
return sortedBuckets;
} catch (final FlowRegistryException e) {
@@ -124,15 +155,16 @@ public class StandardFlowRegistryDAO extends ComponentDAO implements FlowRegistr
}
@Override
- public Set<RegisteredFlow> getFlowsForUser(final FlowRegistryClientUserContext context, final String registryId, final String bucketId) {
+ public Set<RegisteredFlow> getFlowsForUser(final FlowRegistryClientUserContext context, final String registryId, final String branch, final String bucketId) {
try {
final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
if (flowRegistry == null) {
throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
}
- final Set<RegisteredFlow> flows = flowRegistry.getFlows(context, bucketId);
- final Set<RegisteredFlow> sortedFlows = new TreeSet<>((f1, f2) -> f1.getName().compareTo(f2.getName()));
+ final BucketLocation bucketLocation = new BucketLocation(branch, bucketId);
+ final Set<RegisteredFlow> flows = flowRegistry.getFlows(context, bucketLocation);
+ final Set<RegisteredFlow> sortedFlows = new TreeSet<>(Comparator.comparing(RegisteredFlow::getName));
sortedFlows.addAll(flows);
return sortedFlows;
} catch (final IOException | FlowRegistryException ioe) {
@@ -141,28 +173,31 @@ public class StandardFlowRegistryDAO extends ComponentDAO implements FlowRegistr
}
@Override
- public RegisteredFlow getFlowForUser(final FlowRegistryClientUserContext context, final String registryId, final String bucketId, final String flowId) {
+ public RegisteredFlow getFlowForUser(final FlowRegistryClientUserContext context, final String registryId, final String branch, final String bucketId, final String flowId) {
try {
final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
if (flowRegistry == null) {
throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
}
- return flowRegistry.getFlow(context, bucketId, flowId);
+ final FlowLocation flowLocation = new FlowLocation(branch, bucketId, flowId);
+ return flowRegistry.getFlow(context, flowLocation);
} catch (final IOException | FlowRegistryException ioe) {
throw new NiFiCoreException("Unable to obtain listing of flows for bucket with ID " + bucketId + ": " + ioe, ioe);
}
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersionsForUser(final FlowRegistryClientUserContext context, final String registryId, final String bucketId, final String flowId) {
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersionsForUser(final FlowRegistryClientUserContext context, final String registryId, final String branch,
+ final String bucketId, final String flowId) {
try {
final FlowRegistryClientNode flowRegistry = flowController.getFlowManager().getFlowRegistryClient(registryId);
if (flowRegistry == null) {
throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
}
- final Set<RegisteredFlowSnapshotMetadata> flowVersions = flowRegistry.getFlowVersions(context, bucketId, flowId);
+ final FlowLocation flowLocation = new FlowLocation(branch, bucketId, flowId);
+ final Set<RegisteredFlowSnapshotMetadata> flowVersions = flowRegistry.getFlowVersions(context, flowLocation);
final Set<RegisteredFlowSnapshotMetadata> sortedFlowVersions = new TreeSet<>(Comparator.comparingLong(RegisteredFlowSnapshotMetadata::getTimestamp));
sortedFlowVersions.addAll(flowVersions);
return sortedFlowVersions;
diff --git a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/registry/flow/InMemoryFlowRegistry.java b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/registry/flow/InMemoryFlowRegistry.java
index 3ea57d79a5..492a179b35 100644
--- a/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/registry/flow/InMemoryFlowRegistry.java
+++ b/nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/registry/flow/InMemoryFlowRegistry.java
@@ -51,12 +51,12 @@ public class InMemoryFlowRegistry extends AbstractFlowRegistryClient implements
}
@Override
- public Set<FlowRegistryBucket> getBuckets(FlowRegistryClientConfigurationContext context) {
+ public Set<FlowRegistryBucket> getBuckets(FlowRegistryClientConfigurationContext context, String branch) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
@Override
- public FlowRegistryBucket getBucket(FlowRegistryClientConfigurationContext context, String bucketId) {
+ public FlowRegistryBucket getBucket(FlowRegistryClientConfigurationContext context, BucketLocation bucketLocation) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
@@ -66,12 +66,12 @@ public class InMemoryFlowRegistry extends AbstractFlowRegistryClient implements
}
@Override
- public RegisteredFlow deregisterFlow(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) {
+ public RegisteredFlow deregisterFlow(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
@Override
- public Set<RegisteredFlow> getFlows(FlowRegistryClientConfigurationContext context, String bucketId) {
+ public Set<RegisteredFlow> getFlows(FlowRegistryClientConfigurationContext context, BucketLocation bucketLocation) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
@@ -81,7 +81,10 @@ public class InMemoryFlowRegistry extends AbstractFlowRegistryClient implements
}
@Override
- public RegisteredFlow getFlow(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) {
+ public RegisteredFlow getFlow(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+
final FlowCoordinates flowCoordinates = new FlowCoordinates(bucketId, flowId);
final List<VersionedExternalFlow> snapshots = flowSnapshots.get(flowCoordinates);
@@ -96,12 +99,16 @@ public class InMemoryFlowRegistry extends AbstractFlowRegistryClient implements
}
@Override
- public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId, final String version)
+ public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final FlowVersionLocation flowVersionLocation)
throws FlowRegistryException {
if (context.getNiFiUserIdentity().isPresent()) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
+ final String bucketId = flowVersionLocation.getBucketId();
+ final String flowId = flowVersionLocation.getFlowId();
+ final String version = flowVersionLocation.getVersion();
+
final FlowCoordinates flowCoordinates = new FlowCoordinates(bucketId, flowId);
final List<VersionedExternalFlow> snapshots = flowSnapshots.get(flowCoordinates);
@@ -166,12 +173,12 @@ public class InMemoryFlowRegistry extends AbstractFlowRegistryClient implements
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) {
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
@Override
- public Optional<String> getLatestVersion(FlowRegistryClientConfigurationContext context, String bucketId, String flowId) {
+ public Optional<String> getLatestVersion(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) {
throw new UnsupportedOperationException(USER_SPECIFIC_ACTIONS_NOT_SUPPORTED);
}
diff --git a/nifi-system-tests/nifi-system-test-extensions-bundle/nifi-system-test-extensions/src/main/java/org/apache/nifi/flow/registry/FileSystemFlowRegistryClient.java b/nifi-system-tests/nifi-system-test-extensions-bundle/nifi-system-test-extensions/src/main/java/org/apache/nifi/flow/registry/FileSystemFlowRegistryClient.java
index 282cc15969..f0620605ef 100644
--- a/nifi-system-tests/nifi-system-test-extensions-bundle/nifi-system-test-extensions/src/main/java/org/apache/nifi/flow/registry/FileSystemFlowRegistryClient.java
+++ b/nifi-system-tests/nifi-system-test-extensions-bundle/nifi-system-test-extensions/src/main/java/org/apache/nifi/flow/registry/FileSystemFlowRegistryClient.java
@@ -27,9 +27,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.registry.flow.AbstractFlowRegistryClient;
+import org.apache.nifi.registry.flow.BucketLocation;
+import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.FlowRegistryBucket;
import org.apache.nifi.registry.flow.FlowRegistryClientConfigurationContext;
import org.apache.nifi.registry.flow.FlowRegistryPermissions;
+import org.apache.nifi.registry.flow.FlowVersionLocation;
import org.apache.nifi.registry.flow.RegisterAction;
import org.apache.nifi.registry.flow.RegisteredFlow;
import org.apache.nifi.registry.flow.RegisteredFlowSnapshot;
@@ -109,7 +112,7 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientConfigurationContext context) throws IOException {
+ public Set<FlowRegistryBucket> getBuckets(final FlowRegistryClientConfigurationContext context, final String branch) throws IOException {
final File rootDir = getRootDirectory(context);
final File[] children = rootDir.listFiles();
if (children == null) {
@@ -143,9 +146,9 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public FlowRegistryBucket getBucket(final FlowRegistryClientConfigurationContext context, final String bucketId) {
+ public FlowRegistryBucket getBucket(final FlowRegistryClientConfigurationContext context, final BucketLocation bucketLocation) {
final File rootDir = getRootDirectory(context);
- final File bucketDir = getChildLocation(rootDir, getValidatedBucketPath(bucketId));
+ final File bucketDir = getChildLocation(rootDir, getValidatedBucketPath(bucketLocation.getBucketId()));
return toBucket(bucketDir);
}
@@ -159,9 +162,11 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public RegisteredFlow deregisterFlow(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws IOException {
- final File flowDir = getFlowDirectory(context, bucketId, flowId);
+ public RegisteredFlow deregisterFlow(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws IOException {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+ final File flowDir = getFlowDirectory(context, bucketId, flowId);
final File[] versionDirs = flowDir.listFiles();
final RegisteredFlow flow = new RegisteredFlow();
@@ -176,9 +181,11 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public RegisteredFlow getFlow(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) {
- final File flowDir = getFlowDirectory(context, bucketId, flowId);
+ public RegisteredFlow getFlow(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+ final File flowDir = getFlowDirectory(context, bucketId, flowId);
final File[] versionDirs = flowDir.listFiles();
final RegisteredFlow flow = new RegisteredFlow();
@@ -192,7 +199,8 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Set<RegisteredFlow> getFlows(final FlowRegistryClientConfigurationContext context, final String bucketId) throws IOException {
+ public Set<RegisteredFlow> getFlows(final FlowRegistryClientConfigurationContext context, final BucketLocation bucketLocation) throws IOException {
+ final String bucketId = bucketLocation.getBucketId();
final File rootDir = getRootDirectory(context);
final File bucketDir = getChildLocation(rootDir, getValidatedBucketPath(bucketId));
final File[] flowDirs = bucketDir.listFiles();
@@ -202,7 +210,11 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
final Set<RegisteredFlow> registeredFlows = new HashSet<>();
for (final File flowDir : flowDirs) {
- final RegisteredFlow flow = getFlow(context, bucketId, flowDir.getName());
+ final FlowLocation flowLocation = new FlowLocation();
+ flowLocation.setBucketId(bucketId);
+ flowLocation.setFlowId(flowDir.getName());
+
+ final RegisteredFlow flow = getFlow(context, flowLocation);
registeredFlows.add(flow);
}
@@ -210,7 +222,11 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId, final String version) throws IOException {
+ public RegisteredFlowSnapshot getFlowContents(final FlowRegistryClientConfigurationContext context, final FlowVersionLocation flowVersionLocation) throws IOException {
+ final String bucketId = flowVersionLocation.getBucketId();
+ final String flowId = flowVersionLocation.getFlowId();
+ final String version = flowVersionLocation.getVersion();
+
final File flowDir = getFlowDirectory(context, bucketId, flowId);
final Pattern intPattern = Pattern.compile("\\d+");
final File[] versionFiles = flowDir.listFiles(file -> intPattern.matcher(file.getName()).matches());
@@ -355,7 +371,10 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws IOException {
+ public Set<RegisteredFlowSnapshotMetadata> getFlowVersions(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws IOException {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
+
final File flowDir = getFlowDirectory(context, bucketId, flowId);
final File[] versionDirs = flowDir.listFiles();
if (versionDirs == null) {
@@ -379,7 +398,9 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
}
@Override
- public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationContext context, final String bucketId, final String flowId) throws IOException {
+ public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationContext context, final FlowLocation flowLocation) throws IOException {
+ final String bucketId = flowLocation.getBucketId();
+ final String flowId = flowLocation.getFlowId();
final int latestVersion = getLatestFlowVersionInt(context, bucketId, flowId);
return latestVersion == -1 ? Optional.empty() : Optional.of(String.valueOf(latestVersion));
}