NIFIREG-11 Creating metadata classes in provider API to decouple data model -Fixing equals method of VersionedFlowSnapshotMetadata and adding BucketItemType
This closes #6. Project: http://git-wip-us.apache.org/repos/asf/nifi-registry/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi-registry/commit/88cae4f1 Tree: http://git-wip-us.apache.org/repos/asf/nifi-registry/tree/88cae4f1 Diff: http://git-wip-us.apache.org/repos/asf/nifi-registry/diff/88cae4f1 Branch: refs/heads/master Commit: 88cae4f15f25c02cc5a7d834eb0df438c152e681 Parents: 7dd88eb Author: Bryan Bende <[email protected]> Authored: Thu Aug 24 10:24:08 2017 -0400 Committer: Bryan Bende <[email protected]> Committed: Fri Aug 25 15:08:39 2017 -0400 ---------------------------------------------------------------------- .../org/apache/nifi/registry/bucket/Bucket.java | 32 +-- .../apache/nifi/registry/bucket/BucketItem.java | 105 ++++++++ .../nifi/registry/bucket/BucketItemType.java | 26 ++ .../nifi/registry/bucket/BucketObject.java | 55 ---- .../nifi/registry/flow/VersionedFlow.java | 80 +----- .../registry/flow/VersionedFlowSnapshot.java | 58 +---- .../flow/VersionedFlowSnapshotMetadata.java | 116 +++++++++ .../registry/provider/MockMetadataProvider.java | 40 +-- nifi-registry-provider-api/pom.xml | 5 - .../nifi/registry/metadata/BucketMetadata.java | 51 ++++ .../nifi/registry/metadata/FlowMetadata.java | 69 +++++ .../registry/metadata/FlowSnapshotMetadata.java | 54 ++++ .../registry/metadata/MetadataProvider.java | 25 +- .../metadata/StandardBucketMetadata.java | 131 ++++++++++ .../registry/metadata/StandardFlowMetadata.java | 174 +++++++++++++ .../metadata/StandardFlowSnapshotMetadata.java | 136 ++++++++++ .../metadata/FileSystemMetadataProvider.java | 39 ++- .../nifi/registry/metadata/MetadataHolder.java | 101 ++++---- .../TestFileSystemMetadataProvider.java | 256 ++++++++++--------- nifi-registry-web-api/pom.xml | 10 +- .../nifi/registry/web/api/BucketResource.java | 2 +- 21 files changed, 1137 insertions(+), 428 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/Bucket.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/Bucket.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/Bucket.java index d24e797..2797213 100644 --- a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/Bucket.java +++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/Bucket.java @@ -18,11 +18,10 @@ package org.apache.nifi.registry.bucket; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import org.apache.nifi.registry.flow.VersionedFlow; -import java.util.HashMap; -import java.util.Map; import java.util.Objects; -import java.util.UUID; +import java.util.Set; @ApiModel(value = "bucket") public class Bucket { @@ -31,7 +30,7 @@ public class Bucket { private String name; private long createdTimestamp; private String description; - private Map<String, BucketObject> bucketObjectMap = new HashMap<>(); + private Set<VersionedFlow> versionedFlows; @ApiModelProperty("The id of the bucket. This is set by the server at creation time.") public String getIdentifier() { @@ -69,28 +68,13 @@ public class Bucket { this.description = description; } - /** - * Add a new object version to this bucket. - * - * Note that this method has a potential side effect. - * If a BucketObject ID is not set, a random UUID string will be set. - * - * @param object The object to add to this bucket. - */ - public void addObject(BucketObject object) { - if(object.getIdentifier() == null) { - object.setIdentifier(UUID.randomUUID().toString()); - } - - this.bucketObjectMap.put(object.getIdentifier(), object); - } - - protected Map<String, BucketObject> getBucketObjectMap() { - return bucketObjectMap; + @ApiModelProperty("The versioned flows in the bucket.") + public Set<VersionedFlow> getVersionedFlows() { + return versionedFlows; } - protected void setBucketObjectMap(Map<String, BucketObject> bucketObjectMap) { - this.bucketObjectMap = bucketObjectMap; + public void setVersionedFlows(Set<VersionedFlow> versionedFlows) { + this.versionedFlows = versionedFlows; } @Override http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItem.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItem.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItem.java new file mode 100644 index 0000000..eec4fee --- /dev/null +++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItem.java @@ -0,0 +1,105 @@ +/* + * 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.bucket; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +@ApiModel("bucketItem") +public class BucketItem { + + private String identifier; + private String name; + private String bucketIdentifier; + private long createdTimestamp; + private long modifiedTimestamp; + private BucketItemType type; + + @ApiModelProperty("An ID to uniquely identify this object.") + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + @ApiModelProperty("The name of the item.") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @ApiModelProperty("The identifier of the bucket this items belongs to.") + public String getBucketIdentifier() { + return bucketIdentifier; + } + + public void setBucketIdentifier(String bucketIdentifier) { + this.bucketIdentifier = bucketIdentifier; + } + + @ApiModelProperty("The timestamp of when the item was created.") + public long getCreatedTimestamp() { + return createdTimestamp; + } + + public void setCreatedTimestamp(long createdTimestamp) { + this.createdTimestamp = createdTimestamp; + } + + @ApiModelProperty("The timestamp of when the item was last modified.") + public long getModifiedTimestamp() { + return modifiedTimestamp; + } + + public void setModifiedTimestamp(long modifiedTimestamp) { + this.modifiedTimestamp = modifiedTimestamp; + } + + @ApiModelProperty("The type of item.") + public BucketItemType getType() { + return type; + } + + public void setType(BucketItemType type) { + this.type = type; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.identifier); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + final BucketItem other = (BucketItem) obj; + return Objects.equals(this.identifier, other.identifier); + } +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItemType.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItemType.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItemType.java new file mode 100644 index 0000000..d1966ae --- /dev/null +++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketItemType.java @@ -0,0 +1,26 @@ +/* + * 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.bucket; + +/** + * Type of item in a bucket. + */ +public enum BucketItemType { + + FLOW; + +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketObject.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketObject.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketObject.java deleted file mode 100644 index bd3a9d9..0000000 --- a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/bucket/BucketObject.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.bucket; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -import java.util.Objects; - -@ApiModel("bucketObject") -public abstract class BucketObject { - - private String identifier; - - @ApiModelProperty("An ID to uniquely identify this object.") - public String getIdentifier() { - return identifier; - } - - public void setIdentifier(String id) { - this.identifier = id; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.identifier); - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - - final BucketObject other = (BucketObject) obj; - return Objects.equals(this.identifier, other.identifier); - } -} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlow.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlow.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlow.java index 4b8a910..d1b1108 100644 --- a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlow.java +++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlow.java @@ -18,12 +18,9 @@ package org.apache.nifi.registry.flow; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import org.apache.nifi.registry.bucket.BucketObject; +import org.apache.nifi.registry.bucket.BucketItem; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.SortedSet; /** * <p> @@ -35,42 +32,10 @@ import java.util.Map; * @see VersionedFlowSnapshot */ @ApiModel(value = "versionedFlow") -public class VersionedFlow extends BucketObject { +public class VersionedFlow extends BucketItem { - private String name; - private long createdTimestamp; - private long modifiedTimestamp; private String description; - private int currentMaxVersion = 0; - private ArrayList<VersionedFlowSnapshot> snapshots = new ArrayList<>(); - private Map<Integer, VersionedFlowSnapshot> snapshotsByVersion = new HashMap<>(); // TODO, could use a third-party collection type that supports primitive keys. - - @ApiModelProperty("The name of the flow.") - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @ApiModelProperty("The timestamp of when the flow was first created.") - public long getCreatedTimestamp() { - return createdTimestamp; - } - - public void setCreatedTimestamp(long timestamp) { - this.createdTimestamp = timestamp; - } - - @ApiModelProperty("The timestamp of when the flow was last modified, e.g., when a new version was saved.") - public long getModifiedTimestamp() { - return modifiedTimestamp; - } - - public void setModifiedTimestamp(long modifiedTimestamp) { - this.modifiedTimestamp = modifiedTimestamp; - } + private SortedSet<VersionedFlowSnapshotMetadata> snapshotMetadata; @ApiModelProperty("A description of the flow.") public String getDescription() { @@ -81,40 +46,13 @@ public class VersionedFlow extends BucketObject { this.description = description; } - public List<VersionedFlowSnapshot> getSnapshots() { - return snapshots; + @ApiModelProperty("The metadata for each snapshot of this flow.") + public SortedSet<VersionedFlowSnapshotMetadata> getSnapshotMetadata() { + return snapshotMetadata; } - public VersionedFlowSnapshot getSnapshot(int version) { - return snapshotsByVersion.get(Integer.valueOf(version)); - } - - /** - * Add a new snapshot version to this VersionedFlow. - * - * Note that this method has potential side effects. - * If a snapshot version number is not a positive integer, - * a new version number will be set as the current max version number + 1. - * - * @param snapshot The snapshot to add to this versionedFlow - */ - public void addVersionedFlowSnapshot(VersionedFlowSnapshot snapshot) { - if (snapshot == null) { - return; - } - - int snapshotVersion = snapshot.getVersion(); - if (snapshotVersion < 1) { - snapshotVersion = ++currentMaxVersion; - snapshot.setVersion(snapshotVersion); - } else if (snapshotsByVersion.containsKey(Integer.valueOf(snapshotVersion))) { - throw new IllegalStateException("Unable to add snapshot to VersionedFlow with duplicate version number '" + snapshotVersion + "'."); - } else { - currentMaxVersion = (snapshotVersion > currentMaxVersion) ? snapshotVersion : currentMaxVersion; - } - - snapshots.add(snapshot); - snapshotsByVersion.put(Integer.valueOf(snapshotVersion), snapshot); + public void setSnapshotMetadata(SortedSet<VersionedFlowSnapshotMetadata> snapshotMetadata) { + this.snapshotMetadata = snapshotMetadata; } } http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshot.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshot.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshot.java index a1500a4..c3b368c 100644 --- a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshot.java +++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshot.java @@ -32,56 +32,17 @@ import java.util.Objects; */ @ApiModel(value = "versionedFlowSnapshot") public class VersionedFlowSnapshot { - private String flowIdentifier; - private String flowName; - private int version; - private long timestamp; - private String comments; - private VersionedProcessGroup flowContents; - - @ApiModelProperty("The identifier of the flow this snapshot belongs to") - public String getFlowIdentifier() { - return flowIdentifier; - } - - public void setFlowIdentifier(String flowIdentifier) { - this.flowIdentifier = flowIdentifier; - } - - @ApiModelProperty("The name of the flow this snapshot belongs to") - public String getFlowName() { - return flowName; - } - - public void setFlowName(String flowName) { - this.flowName = flowName; - } - @ApiModelProperty("The version of this snapshot of the flow") - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } - - @ApiModelProperty("The timestamp when the flow was saved") - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } + private VersionedFlowSnapshotMetadata snapshotMetadata; + private VersionedProcessGroup flowContents; - @ApiModelProperty("The comments provided by the user when creating the snapshot") - public String getComments() { - return comments; + @ApiModelProperty("The metadata for this snapshot") + public VersionedFlowSnapshotMetadata getSnapshotMetadata() { + return snapshotMetadata; } - public void setComments(String comments) { - this.comments = comments; + public void setSnapshotMetadata(VersionedFlowSnapshotMetadata snapshotMetadata) { + this.snapshotMetadata = snapshotMetadata; } @ApiModelProperty("The contents of the versioned flow") @@ -95,7 +56,7 @@ public class VersionedFlowSnapshot { @Override public int hashCode() { - return Objects.hash(this.flowIdentifier, Integer.valueOf(this.version)); + return Objects.hash(this.snapshotMetadata); } @Override @@ -108,6 +69,7 @@ public class VersionedFlowSnapshot { } final VersionedFlowSnapshot other = (VersionedFlowSnapshot) obj; - return Objects.equals(this.flowIdentifier, other.flowIdentifier) && Objects.equals(this.version, other.version); + return Objects.equals(this.snapshotMetadata, other.snapshotMetadata); } + } http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java new file mode 100644 index 0000000..4cd3de9 --- /dev/null +++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java @@ -0,0 +1,116 @@ +/* + * 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 io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +/** + * The metadata information about a VersionedFlowSnapshot. This class implements Comparable in order + * to sort based on the snapshot version in ascending order. + */ +@ApiModel(value = "versionedFlowSnapshot") +public class VersionedFlowSnapshotMetadata implements Comparable<VersionedFlowSnapshotMetadata> { + + private String bucketIdentifier; + private String flowIdentifier; + private String flowName; + private int version; + private long timestamp; + private String comments; + + @ApiModelProperty("The identifier of the bucket this snapshot belongs to.") + public String getBucketIdentifier() { + return bucketIdentifier; + } + + public void setBucketIdentifier(String bucketIdentifier) { + this.bucketIdentifier = bucketIdentifier; + } + + @ApiModelProperty("The identifier of the flow this snapshot belongs to.") + public String getFlowIdentifier() { + return flowIdentifier; + } + + public void setFlowIdentifier(String flowIdentifier) { + this.flowIdentifier = flowIdentifier; + } + + @ApiModelProperty("The name of the flow this snapshot belongs to.") + public String getFlowName() { + return flowName; + } + + public void setFlowName(String flowName) { + this.flowName = flowName; + } + + @ApiModelProperty("The version of this snapshot of the flow.") + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + @ApiModelProperty("The timestamp when the flow was saved.") + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + @ApiModelProperty("The comments provided by the user when creating the snapshot.") + public String getComments() { + return comments; + } + + public void setComments(String comments) { + this.comments = comments; + } + + @Override + public int compareTo(final VersionedFlowSnapshotMetadata o) { + return o == null ? -1 : Integer.compare(version, o.version); + } + + @Override + public int hashCode() { + return Objects.hash(this.flowIdentifier, Integer.valueOf(this.version)); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + final VersionedFlowSnapshotMetadata other = (VersionedFlowSnapshotMetadata) obj; + + return Objects.equals(this.flowIdentifier, other.flowIdentifier) + && Objects.equals(this.version, other.version); + } +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-framework/src/test/java/org/apache/nifi/registry/provider/MockMetadataProvider.java ---------------------------------------------------------------------- diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/provider/MockMetadataProvider.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/provider/MockMetadataProvider.java index 06d3e1a..781f348 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/provider/MockMetadataProvider.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/provider/MockMetadataProvider.java @@ -16,9 +16,9 @@ */ package org.apache.nifi.registry.provider; -import org.apache.nifi.registry.bucket.Bucket; -import org.apache.nifi.registry.flow.VersionedFlow; -import org.apache.nifi.registry.flow.VersionedFlowSnapshot; +import org.apache.nifi.registry.metadata.BucketMetadata; +import org.apache.nifi.registry.metadata.FlowMetadata; +import org.apache.nifi.registry.metadata.FlowSnapshotMetadata; import org.apache.nifi.registry.metadata.MetadataProvider; import java.util.Map; @@ -38,22 +38,17 @@ public class MockMetadataProvider implements MetadataProvider { } @Override - public Bucket createBucket(Bucket bucket) { + public BucketMetadata createBucket(BucketMetadata bucket) { return null; } @Override - public Bucket getBucket(String bucketIdentifier) { + public BucketMetadata getBucket(String bucketIdentifier) { return null; } @Override - public Set<Bucket> getBuckets() { - return null; - } - - @Override - public Bucket updateBucket(Bucket bucket) { + public BucketMetadata updateBucket(BucketMetadata bucket) { return null; } @@ -63,42 +58,47 @@ public class MockMetadataProvider implements MetadataProvider { } @Override - public VersionedFlow createFlow(String bucketIdentifier, VersionedFlow flow) { + public Set<BucketMetadata> getBuckets() { return null; } @Override - public VersionedFlow getFlow(String flowIdentifier) { + public FlowMetadata createFlow(String bucketIdentifier, FlowMetadata flow) { return null; } @Override - public Set<VersionedFlow> getFlows() { + public FlowMetadata getFlow(String flowIdentifier) { return null; } @Override - public Set<VersionedFlow> getFlows(String bucketId) { + public FlowMetadata updateFlow(FlowMetadata versionedFlow) { return null; } @Override - public VersionedFlow updateFlow(VersionedFlow versionedFlow) { - return null; + public void deleteFlow(String flowIdentifier) { + } @Override - public void deleteFlow(String flowIdentifier) { + public Set<FlowMetadata> getFlows() { + return null; + } + @Override + public Set<FlowMetadata> getFlows(String bucketId) { + return null; } @Override - public VersionedFlowSnapshot createFlowSnapshot(VersionedFlowSnapshot flowSnapshot) { + public FlowSnapshotMetadata createFlowSnapshot(FlowSnapshotMetadata flowSnapshot) { return null; } @Override - public VersionedFlowSnapshot getFlowSnapshot(String flowIdentifier, Integer version) { + public FlowSnapshotMetadata getFlowSnapshot(String flowIdentifier, Integer version) { return null; } http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/pom.xml b/nifi-registry-provider-api/pom.xml index eba6cfa..294eac4 100644 --- a/nifi-registry-provider-api/pom.xml +++ b/nifi-registry-provider-api/pom.xml @@ -26,11 +26,6 @@ <dependencies> <dependency> - <groupId>org.apache.nifi.registry</groupId> - <artifactId>nifi-registry-data-model</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/BucketMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/BucketMetadata.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/BucketMetadata.java new file mode 100644 index 0000000..7d10da5 --- /dev/null +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/BucketMetadata.java @@ -0,0 +1,51 @@ +/* + * 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.metadata; + +import java.util.Set; + +/** + * The metadata for a bucket, along with the metadata about any objects stored in the bucket, such as flows. + */ +public interface BucketMetadata { + + /** + * @return the identifier of this bucket + */ + String getIdentifier(); + + /** + * @return the name of this bucket + */ + String getName(); + + /** + * @return the timestamp of when this bucket was created + */ + long getCreatedTimestamp(); + + /** + * @return the description of this bucket + */ + String getDescription(); + + /** + * @return the metadata about the flows that are part of this bucket + */ + Set<FlowMetadata> getFlowMetadata(); + +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowMetadata.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowMetadata.java new file mode 100644 index 0000000..0aebb63 --- /dev/null +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowMetadata.java @@ -0,0 +1,69 @@ +/* + * 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.metadata; + +import java.util.Set; + +/** + * The metadata about a flow, including the metadata about any of it's snapshots. + */ +public interface FlowMetadata { + + /** + * @return the identifier of this flow + */ + String getIdentifier(); + + /** + * @return the name of this flow + */ + String getName(); + + /** + * @return the identifier of the bucket this flow belongs to + */ + String getBucketIdentifier(); + + /** + * @return the timestamp this flow was created + */ + long getCreatedTimestamp(); + + /** + * @return the timestamp this flow was modified + */ + long getModifiedTimestamp(); + + /** + * @return the description of this flow + */ + String getDescription(); + + /** + * @return the metadata for the snapshots of this flow + */ + Set<FlowSnapshotMetadata> getSnapshotMetadata(); + + /** + * Get the snapshot for the given version. + * + * @param version the version of a snapshot + * @return the snapshot for the given version, or null if one doesn't exist + */ + FlowSnapshotMetadata getSnapshot(int version); + +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowSnapshotMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowSnapshotMetadata.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowSnapshotMetadata.java new file mode 100644 index 0000000..98cb666 --- /dev/null +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/FlowSnapshotMetadata.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.metadata; + +/** + * The metadata for a flow snapshot. + */ +public interface FlowSnapshotMetadata { + + /** + * @return the identifier of the bucket this snapshot belongs to + */ + String getBucketIdentifier(); + + /** + * @return the identifier of the flow this snapshot belongs to + */ + String getFlowIdentifier(); + + /** + * @return the name of the flow this snapshot belongs to + */ + String getFlowName(); + + /** + * @return the version of this snapshot + */ + int getVersion(); + + /** + * @return the timestamp of when this snapshot was created + */ + long getCreatedTimestamp(); + + /** + * @return the comments for this snapshot + */ + String getComments(); + +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/MetadataProvider.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/MetadataProvider.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/MetadataProvider.java index 558f7aa..727aae0 100644 --- a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/MetadataProvider.java +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/MetadataProvider.java @@ -16,9 +16,6 @@ */ package org.apache.nifi.registry.metadata; -import org.apache.nifi.registry.bucket.Bucket; -import org.apache.nifi.registry.flow.VersionedFlow; -import org.apache.nifi.registry.flow.VersionedFlowSnapshot; import org.apache.nifi.registry.provider.Provider; import java.util.Set; @@ -37,7 +34,7 @@ public interface MetadataProvider extends Provider { * @param bucket the bucket to create * @return the created bucket */ - Bucket createBucket(Bucket bucket); + BucketMetadata createBucket(BucketMetadata bucket); /** * Retrieves the bucket with the given id. @@ -45,7 +42,7 @@ public interface MetadataProvider extends Provider { * @param bucketIdentifier the id of the bucket to retrieve * @return the bucket with the given id, or null if it does not exist */ - Bucket getBucket(String bucketIdentifier); + BucketMetadata getBucket(String bucketIdentifier); /** * Updates the given bucket, only the name and description should be allowed to be updated. @@ -53,7 +50,7 @@ public interface MetadataProvider extends Provider { * @param bucket the updated bucket to save * @return the updated bucket, or null if no bucket with the given id exists */ - Bucket updateBucket(Bucket bucket); + BucketMetadata updateBucket(BucketMetadata bucket); /** * Deletes the bucket with the given identifier if one exists. @@ -67,7 +64,7 @@ public interface MetadataProvider extends Provider { * * @return the set of all buckets */ - Set<Bucket> getBuckets(); + Set<BucketMetadata> getBuckets(); /** * Creates a versioned flow in the given bucket. @@ -77,7 +74,7 @@ public interface MetadataProvider extends Provider { * @return the created versioned flow * @throws IllegalStateException if no bucket with the given identifier exists */ - VersionedFlow createFlow(String bucketIdentifier, VersionedFlow flow); + FlowMetadata createFlow(String bucketIdentifier, FlowMetadata flow); /** * Retrieves the versioned flow with the given id. @@ -85,7 +82,7 @@ public interface MetadataProvider extends Provider { * @param flowIdentifier the identifier of the flow to retrieve * @return the versioned flow with the given id, or null if no flow with the given id exists */ - VersionedFlow getFlow(String flowIdentifier); + FlowMetadata getFlow(String flowIdentifier); /** * Updates the given versioned flow, only the name and description should be allowed to be updated. @@ -93,7 +90,7 @@ public interface MetadataProvider extends Provider { * @param versionedFlow the updated versioned flow to save * @return the updated versioned flow */ - VersionedFlow updateFlow(VersionedFlow versionedFlow); + FlowMetadata updateFlow(FlowMetadata versionedFlow); /** * Deletes the versioned flow with the given identifier if one exists. @@ -107,7 +104,7 @@ public interface MetadataProvider extends Provider { * * @return the set of all versioned flows */ - Set<VersionedFlow> getFlows(); + Set<FlowMetadata> getFlows(); /** * Retrieves all the versioned flows for the given bucket. @@ -115,7 +112,7 @@ public interface MetadataProvider extends Provider { * @param bucketId the id of the bucket to retrieve flow for * @return the set of versioned flows for the given bucket, or an empty set if none exist */ - Set<VersionedFlow> getFlows(String bucketId); + Set<FlowMetadata> getFlows(String bucketId); /** * Creates a versioned flow snapshot. @@ -124,7 +121,7 @@ public interface MetadataProvider extends Provider { * @return the created snapshot * @throws IllegalStateException if the versioned flow specified by flowSnapshot.getFlowIdentifier() does not exist */ - VersionedFlowSnapshot createFlowSnapshot(VersionedFlowSnapshot flowSnapshot); + FlowSnapshotMetadata createFlowSnapshot(FlowSnapshotMetadata flowSnapshot); /** * Retrieves the snapshot for the given flow identifier and snapshot version. @@ -133,7 +130,7 @@ public interface MetadataProvider extends Provider { * @param version the version of the snapshot * @return the versioned flow snapshot for the given flow identifier and version, or null if none exists */ - VersionedFlowSnapshot getFlowSnapshot(String flowIdentifier, Integer version); + FlowSnapshotMetadata getFlowSnapshot(String flowIdentifier, Integer version); /** * Deletes the snapshot for the given flow identifier and version. http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardBucketMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardBucketMetadata.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardBucketMetadata.java new file mode 100644 index 0000000..02568e6 --- /dev/null +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardBucketMetadata.java @@ -0,0 +1,131 @@ +/* + * 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.metadata; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +public class StandardBucketMetadata implements BucketMetadata { + + private final String identifier; + private final String name; + private final long createdTimestamp; + private final String description; + private final Set<FlowMetadata> flowMetadata; + + private StandardBucketMetadata(final Builder builder) { + this.identifier = builder.identifier; + this.name = builder.name; + this.createdTimestamp = builder.createdTimestamp; + this.description = builder.description; + this.flowMetadata = Collections.unmodifiableSet( + builder.flowMetadata == null + ? Collections.emptySet() : new LinkedHashSet<>(builder.flowMetadata) + ); + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getName() { + return name; + } + + @Override + public long getCreatedTimestamp() { + return createdTimestamp; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public Set<FlowMetadata> getFlowMetadata() { + return flowMetadata; + } + + public static class Builder { + + private String identifier; + private String name; + private long createdTimestamp; + private String description; + private Set<FlowMetadata> flowMetadata = new LinkedHashSet<>(); + + public Builder() { + + } + + public Builder(BucketMetadata bucketMetadata) { + identifier(bucketMetadata.getIdentifier()); + name(bucketMetadata.getName()); + created(bucketMetadata.getCreatedTimestamp()); + description(bucketMetadata.getDescription()); + addFlows(bucketMetadata.getFlowMetadata()); + } + + public Builder identifier(final String identifier) { + this.identifier = identifier; + return this; + } + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder created(final long createdTimestamp) { + this.createdTimestamp = createdTimestamp; + return this; + } + + public Builder description(final String description) { + this.description = description; + return this; + } + + public Builder addFlow(final FlowMetadata flowMetadata) { + if (flowMetadata != null) { + this.flowMetadata.add(flowMetadata); + } + return this; + } + + public Builder addFlows(final Collection<FlowMetadata> flows) { + if (flows != null) { + this.flowMetadata.addAll(flows); + } + return this; + } + + public Builder clearFlows() { + this.flowMetadata.clear(); + return this; + } + + public StandardBucketMetadata build() { + return new StandardBucketMetadata(this); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowMetadata.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowMetadata.java new file mode 100644 index 0000000..cfef423 --- /dev/null +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowMetadata.java @@ -0,0 +1,174 @@ +/* + * 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.metadata; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * Standard immutable implementation of FlowMetadata. + */ +public class StandardFlowMetadata implements FlowMetadata { + + private final String identifier; + private final String name; + private final String bucketIdentifier; + private final long createdTimestamp; + private final long modifiedTimestamp; + private final String description; + private final Set<FlowSnapshotMetadata> snapshotMetadata; + private final Map<String,FlowSnapshotMetadata> snapshotMetadataByVersion; + + private StandardFlowMetadata(final Builder builder) { + this.identifier = builder.identifier; + this.name = builder.name; + this.bucketIdentifier = builder.bucketIdentifier; + this.createdTimestamp = builder.createdTimestamp; + this.modifiedTimestamp = builder.modifiedTimestamp; + this.description = builder.description; + this.snapshotMetadata = Collections.unmodifiableSet( + builder.snapshotMetadata == null + ? Collections.emptySet() : new LinkedHashSet<>(builder.snapshotMetadata)); + + final Map<String,FlowSnapshotMetadata> tempMetadataMap = new HashMap<>(); + this.snapshotMetadata.stream().forEach(s -> tempMetadataMap.put(String.valueOf(s.getVersion()), s)); + this.snapshotMetadataByVersion = Collections.unmodifiableMap(tempMetadataMap); + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getBucketIdentifier() { + return bucketIdentifier; + } + + @Override + public long getCreatedTimestamp() { + return createdTimestamp; + } + + @Override + public long getModifiedTimestamp() { + return modifiedTimestamp; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public Set<FlowSnapshotMetadata> getSnapshotMetadata() { + return snapshotMetadata; + } + + @Override + public FlowSnapshotMetadata getSnapshot(int version) { + return snapshotMetadataByVersion.get(String.valueOf(version)); + } + + public static class Builder { + + private String identifier; + private String name; + private String bucketIdentifier; + private long createdTimestamp; + private long modifiedTimestamp; + private String description; + private Set<FlowSnapshotMetadata> snapshotMetadata = new LinkedHashSet<>(); + + public Builder() { + + } + + public Builder(FlowMetadata flowMetadata) { + identifier(flowMetadata.getIdentifier()); + name(flowMetadata.getName()); + bucketIdentifier(flowMetadata.getBucketIdentifier()); + created(flowMetadata.getCreatedTimestamp()); + modified(flowMetadata.getModifiedTimestamp()); + description(flowMetadata.getDescription()); + addSnapshots(flowMetadata.getSnapshotMetadata()); + } + + public Builder identifier(final String identifier) { + this.identifier = identifier; + return this; + } + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder bucketIdentifier(final String bucketIdentifier) { + this.bucketIdentifier = bucketIdentifier; + return this; + } + + public Builder created(final long createdTimestamp) { + this.createdTimestamp = createdTimestamp; + return this; + } + + public Builder modified(final long modifiedTimestamp) { + this.modifiedTimestamp = modifiedTimestamp; + return this; + } + + public Builder description(final String description) { + this.description = description; + return this; + } + + public Builder addSnapshot(final FlowSnapshotMetadata snapshotMetadata) { + if (snapshotMetadata != null) { + this.snapshotMetadata.add(snapshotMetadata); + } + return this; + } + + public Builder addSnapshots(final Collection<FlowSnapshotMetadata> snapshotMetadata) { + if (snapshotMetadata != null) { + this.snapshotMetadata.addAll(snapshotMetadata); + } + return this; + } + + public Builder clearSnapshots() { + this.snapshotMetadata.clear(); + return this; + } + + public StandardFlowMetadata build() { + return new StandardFlowMetadata(this); + } + + } +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowSnapshotMetadata.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowSnapshotMetadata.java b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowSnapshotMetadata.java new file mode 100644 index 0000000..f8d09ce --- /dev/null +++ b/nifi-registry-provider-api/src/main/java/org/apache/nifi/registry/metadata/StandardFlowSnapshotMetadata.java @@ -0,0 +1,136 @@ +/* + * 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.metadata; + +import java.util.Objects; + +/** + * Standard immutable implementation of FlowSnapshotMetadata. + */ +public class StandardFlowSnapshotMetadata implements FlowSnapshotMetadata { + + private final String bucketIdentifier; + private final String flowIdentifier; + private final String flowName; + private final int version; + private final long createdTimestamp; + private final String comments; + + private StandardFlowSnapshotMetadata(final Builder builder) { + this.bucketIdentifier = builder.bucketIdentifier; + this.flowIdentifier = builder.flowIdentifier; + this.flowName = builder.flowName; + this.version = builder.version; + this.createdTimestamp = builder.createdTimestamp; + this.comments = builder.comments; + } + + @Override + public String getBucketIdentifier() { + return bucketIdentifier; + } + + @Override + public String getFlowIdentifier() { + return flowIdentifier; + } + + @Override + public String getFlowName() { + return flowName; + } + + @Override + public int getVersion() { + return version; + } + + @Override + public long getCreatedTimestamp() { + return createdTimestamp; + } + + @Override + public String getComments() { + return comments; + } + + @Override + public int hashCode() { + return Objects.hash(this.bucketIdentifier, this.flowIdentifier, Integer.valueOf(this.version)); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + final StandardFlowSnapshotMetadata other = (StandardFlowSnapshotMetadata) obj; + + return Objects.equals(this.bucketIdentifier, other.bucketIdentifier) + && Objects.equals(this.flowIdentifier, other.flowIdentifier) + && Objects.equals(this.version, other.version); + } + + public static class Builder { + + private String bucketIdentifier; + private String flowIdentifier; + private String flowName; + private int version; + private long createdTimestamp; + private String comments; + + public Builder bucketIdentifier(final String bucketIdentifier) { + this.bucketIdentifier = bucketIdentifier; + return this; + } + + public Builder flowIdentifier(final String flowIdentifier) { + this.flowIdentifier = flowIdentifier; + return this; + } + + public Builder flowName(final String flowName) { + this.flowName = flowName; + return this; + } + + public Builder version(final int version) { + this.version = version; + return this; + } + + public Builder created(long createdTimestamp) { + this.createdTimestamp = createdTimestamp; + return this; + } + + public Builder comments(String comments) { + this.comments = comments; + return this; + } + + public StandardFlowSnapshotMetadata build() { + return new StandardFlowSnapshotMetadata(this); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/FileSystemMetadataProvider.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/FileSystemMetadataProvider.java b/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/FileSystemMetadataProvider.java index ba3af4c..05ddd01 100644 --- a/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/FileSystemMetadataProvider.java +++ b/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/FileSystemMetadataProvider.java @@ -17,9 +17,6 @@ package org.apache.nifi.registry.metadata; import org.apache.commons.lang3.StringUtils; -import org.apache.nifi.registry.bucket.Bucket; -import org.apache.nifi.registry.flow.VersionedFlow; -import org.apache.nifi.registry.flow.VersionedFlowSnapshot; import org.apache.nifi.registry.metadata.generated.Buckets; import org.apache.nifi.registry.metadata.generated.Flow; import org.apache.nifi.registry.metadata.generated.Flows; @@ -142,7 +139,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public synchronized Bucket createBucket(final Bucket bucket) { + public synchronized BucketMetadata createBucket(final BucketMetadata bucket) { if (bucket == null) { throw new IllegalArgumentException("Bucket cannot be null"); } @@ -163,7 +160,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public Bucket getBucket(final String bucketIdentifier) { + public BucketMetadata getBucket(final String bucketIdentifier) { if (bucketIdentifier == null) { throw new IllegalArgumentException("Bucket Identifier cannot be null"); } @@ -173,14 +170,14 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public Set<Bucket> getBuckets() { + public Set<BucketMetadata> getBuckets() { final MetadataHolder holder = metadataHolder.get(); - final Map<String,Bucket> bucketsBydId = holder.getBucketsBydId(); + final Map<String,BucketMetadata> bucketsBydId = holder.getBucketsBydId(); return new HashSet<>(bucketsBydId.values()); } @Override - public synchronized Bucket updateBucket(final Bucket bucket) { + public synchronized BucketMetadata updateBucket(final BucketMetadata bucket) { if (bucket == null) { throw new IllegalArgumentException("Bucket cannot be null"); } @@ -243,7 +240,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public synchronized VersionedFlow createFlow(final String bucketIdentifier, final VersionedFlow versionedFlow) { + public synchronized FlowMetadata createFlow(final String bucketIdentifier, final FlowMetadata versionedFlow) { if (bucketIdentifier == null) { throw new IllegalArgumentException("Bucket Identifier cannot be blank"); } @@ -254,7 +251,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { final MetadataHolder holder = metadataHolder.get(); - final Bucket bucket = holder.getBucketsBydId().get(bucketIdentifier); + final BucketMetadata bucket = holder.getBucketsBydId().get(bucketIdentifier); if (bucket == null) { throw new IllegalStateException("Unable to create Versioned Flow because Bucket does not exist with id " + bucketIdentifier); } @@ -275,7 +272,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public VersionedFlow getFlow(final String flowIdentifier) { + public FlowMetadata getFlow(final String flowIdentifier) { if (flowIdentifier == null) { throw new IllegalArgumentException("Flow Identifier cannot be null"); } @@ -285,17 +282,17 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public Set<VersionedFlow> getFlows() { + public Set<FlowMetadata> getFlows() { final MetadataHolder holder = metadataHolder.get(); - final Map<String,VersionedFlow> flowsById = holder.getFlowsById(); + final Map<String,FlowMetadata> flowsById = holder.getFlowsById(); return new HashSet<>(flowsById.values()); } @Override - public Set<VersionedFlow> getFlows(String bucketId) { + public Set<FlowMetadata> getFlows(String bucketId) { final MetadataHolder holder = metadataHolder.get(); - final Map<String,Set<VersionedFlow>> flowsByBucket = holder.getFlowsByBucket(); + final Map<String,Set<FlowMetadata>> flowsByBucket = holder.getFlowsByBucket(); if (flowsByBucket.containsKey(bucketId)) { return new HashSet<>(flowsByBucket.get(bucketId)); } else { @@ -304,7 +301,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public synchronized VersionedFlow updateFlow(final VersionedFlow versionedFlow) { + public synchronized FlowMetadata updateFlow(final FlowMetadata versionedFlow) { if (versionedFlow == null) { throw new IllegalArgumentException("Versioned Flow cannot be null"); } @@ -357,7 +354,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { } @Override - public synchronized VersionedFlowSnapshot createFlowSnapshot(final VersionedFlowSnapshot flowSnapshot) { + public synchronized FlowSnapshotMetadata createFlowSnapshot(final FlowSnapshotMetadata flowSnapshot) { if (flowSnapshot == null) { throw new IllegalArgumentException("Versioned Flow Snapshot cannot be null"); } @@ -380,17 +377,17 @@ public class FileSystemMetadataProvider implements MetadataProvider { final Flow.Snapshot jaxbSnapshot = new Flow.Snapshot(); jaxbSnapshot.setVersion(flowSnapshot.getVersion()); jaxbSnapshot.setComments(flowSnapshot.getComments()); - jaxbSnapshot.setCreatedTimestamp(flowSnapshot.getTimestamp()); + jaxbSnapshot.setCreatedTimestamp(flowSnapshot.getCreatedTimestamp()); jaxbFlow.getSnapshot().add(jaxbSnapshot); saveAndRefresh(holder.getMetadata()); - final VersionedFlow versionedFlow = metadataHolder.get().getFlowsById().get(flowIdentifier); + final FlowMetadata versionedFlow = metadataHolder.get().getFlowsById().get(flowIdentifier); return versionedFlow.getSnapshot(snapshotVersion); } @Override - public VersionedFlowSnapshot getFlowSnapshot(final String flowIdentifier, final Integer version) { + public FlowSnapshotMetadata getFlowSnapshot(final String flowIdentifier, final Integer version) { if (flowIdentifier == null) { throw new IllegalArgumentException("Flow Identifier cannot be null"); } @@ -401,7 +398,7 @@ public class FileSystemMetadataProvider implements MetadataProvider { final MetadataHolder holder = metadataHolder.get(); - final VersionedFlow versionedFlow = holder.getFlowsById().get(flowIdentifier); + final FlowMetadata versionedFlow = holder.getFlowsById().get(flowIdentifier); if (versionedFlow == null) { return null; } http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/88cae4f1/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/MetadataHolder.java ---------------------------------------------------------------------- diff --git a/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/MetadataHolder.java b/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/MetadataHolder.java index 6ce3dfb..4264b01 100644 --- a/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/MetadataHolder.java +++ b/nifi-registry-provider-impl/src/main/java/org/apache/nifi/registry/metadata/MetadataHolder.java @@ -16,9 +16,7 @@ */ package org.apache.nifi.registry.metadata; -import org.apache.nifi.registry.bucket.Bucket; -import org.apache.nifi.registry.flow.VersionedFlow; -import org.apache.nifi.registry.flow.VersionedFlowSnapshot; +import org.apache.nifi.registry.metadata.generated.Bucket; import org.apache.nifi.registry.metadata.generated.Buckets; import org.apache.nifi.registry.metadata.generated.Flow; import org.apache.nifi.registry.metadata.generated.Flows; @@ -36,86 +34,93 @@ import java.util.Set; public class MetadataHolder { private final Metadata metadata; - private final Map<String,Bucket> bucketsById; - private final Map<String,VersionedFlow> flowsById; - private final Map<String,Set<VersionedFlow>> flowsByBucket; + private final Map<String,Set<FlowMetadata>> flowsByBucket; + private final Map<String,FlowMetadata> flowsById; + private final Map<String,BucketMetadata> bucketsById; public MetadataHolder(final Metadata metadata) { this.metadata = metadata; - this.bucketsById = Collections.unmodifiableMap(createBucketsBydId(metadata)); this.flowsByBucket = Collections.unmodifiableMap(createFlowsByBucket(metadata)); this.flowsById = Collections.unmodifiableMap(createFlowsById(flowsByBucket)); + this.bucketsById = Collections.unmodifiableMap(createBucketsBydId(metadata, flowsByBucket)); } - private Map<String,Bucket> createBucketsBydId(final Metadata metadata) { - final Map<String,Bucket> bucketsById = new HashMap<>(); + private Map<String,BucketMetadata> createBucketsBydId(final Metadata metadata, final Map<String,Set<FlowMetadata>> flowsByBucket) { + final Map<String,BucketMetadata> bucketsById = new HashMap<>(); final Buckets buckets = metadata.getBuckets(); if (buckets != null) { - buckets.getBucket().stream().forEach(b -> bucketsById.put(b.getIdentifier(), createBucket(b))); + buckets.getBucket().stream().forEach(b -> { + final Set<FlowMetadata> bucketFlows = flowsByBucket.get(b.getIdentifier()); + final BucketMetadata bucketMetadata = createBucketMetadata(b, bucketFlows); + bucketsById.put(b.getIdentifier(), bucketMetadata); + }); } return bucketsById; } - private Bucket createBucket(final org.apache.nifi.registry.metadata.generated.Bucket jaxbBucket) { - final Bucket bucket = new Bucket(); - bucket.setIdentifier(jaxbBucket.getIdentifier()); - bucket.setName(jaxbBucket.getName()); - bucket.setDescription(jaxbBucket.getDescription()); - bucket.setCreatedTimestamp(jaxbBucket.getCreatedTimestamp()); - return bucket; + private BucketMetadata createBucketMetadata(final Bucket jaxbBucket, final Set<FlowMetadata> bucketFlows) { + return new StandardBucketMetadata.Builder() + .identifier(jaxbBucket.getIdentifier()) + .name(jaxbBucket.getName()) + .description(jaxbBucket.getDescription()) + .created(jaxbBucket.getCreatedTimestamp()) + .addFlows(bucketFlows) + .build(); } - private Map<String,Set<VersionedFlow>> createFlowsByBucket(final Metadata metadata) { - final Map<String,Set<VersionedFlow>> flowsByBucket = new HashMap<>(); + private Map<String,Set<FlowMetadata>> createFlowsByBucket(final Metadata metadata) { + final Map<String,Set<FlowMetadata>> flowsByBucket = new HashMap<>(); final Flows flows = metadata.getFlows(); if (flows != null) { flows.getFlow().stream().forEach(f -> { - Set<VersionedFlow> bucketFLows = flowsByBucket.get(f.getBucketIdentifier()); + Set<FlowMetadata> bucketFLows = flowsByBucket.get(f.getBucketIdentifier()); if (bucketFLows == null) { bucketFLows = new HashSet<>(); flowsByBucket.put(f.getBucketIdentifier(), bucketFLows); } - bucketFLows.add(createFlow(f)); + bucketFLows.add(createFlowMetadata(f)); }); } return flowsByBucket; } - private VersionedFlow createFlow(final Flow flow) { - final VersionedFlow versionedFlow = new VersionedFlow(); - versionedFlow.setIdentifier(flow.getIdentifier()); - versionedFlow.setName(flow.getName()); - versionedFlow.setDescription(flow.getDescription()); - versionedFlow.setCreatedTimestamp(flow.getCreatedTimestamp()); - versionedFlow.setModifiedTimestamp(flow.getModifiedTimestamp()); - - if (flow.getSnapshot() != null) { - flow.getSnapshot().stream().forEach(s -> versionedFlow.addVersionedFlowSnapshot(createSnapshot(flow, s))); + private FlowMetadata createFlowMetadata(final Flow jaxbFlow) { + final StandardFlowMetadata.Builder builder = new StandardFlowMetadata.Builder() + .identifier(jaxbFlow.getIdentifier()) + .name(jaxbFlow.getName()) + .bucketIdentifier(jaxbFlow.getBucketIdentifier()) + .description(jaxbFlow.getDescription()) + .created(jaxbFlow.getCreatedTimestamp()) + .modified(jaxbFlow.getModifiedTimestamp()); + + if (jaxbFlow.getSnapshot() != null) { + jaxbFlow.getSnapshot().stream().forEach(s -> builder.addSnapshot(createSnapshotMetadata(jaxbFlow, s))); } - return versionedFlow; + return builder.build(); } - private VersionedFlowSnapshot createSnapshot(final Flow flow, final Flow.Snapshot snapshot) { - final VersionedFlowSnapshot versionedFlowSnapshot = new VersionedFlowSnapshot(); - versionedFlowSnapshot.setFlowIdentifier(flow.getIdentifier()); - versionedFlowSnapshot.setFlowName(flow.getName()); - versionedFlowSnapshot.setVersion(snapshot.getVersion()); - versionedFlowSnapshot.setComments(snapshot.getComments()); - versionedFlowSnapshot.setTimestamp(snapshot.getCreatedTimestamp()); - return versionedFlowSnapshot; + private FlowSnapshotMetadata createSnapshotMetadata(final Flow jaxbFlow, final Flow.Snapshot jaxbSnapshot) { + return new StandardFlowSnapshotMetadata.Builder() + .bucketIdentifier(jaxbFlow.getBucketIdentifier()) + .flowIdentifier(jaxbFlow.getIdentifier()) + .flowName(jaxbFlow.getName()) + .version(jaxbSnapshot.getVersion()) + .comments(jaxbSnapshot.getComments()) + .created(jaxbSnapshot.getCreatedTimestamp()) + .build(); } - private Map<String,VersionedFlow> createFlowsById(final Map<String,Set<VersionedFlow>> flowsByBucket) { - final Map<String,VersionedFlow> flowsBdId = new HashMap<>(); + private Map<String,FlowMetadata> createFlowsById(final Map<String,Set<FlowMetadata>> flowsByBucket) { + final Map<String,FlowMetadata> flowsBdId = new HashMap<>(); - for (final Map.Entry<String,Set<VersionedFlow>> entry : flowsByBucket.entrySet()) { - for (final VersionedFlow flow : entry.getValue()) { - flowsBdId.put(flow.getIdentifier(), flow); + for (final Map.Entry<String,Set<FlowMetadata>> entry : flowsByBucket.entrySet()) { + for (final FlowMetadata flowMetadata : entry.getValue()) { + flowsBdId.put(flowMetadata.getIdentifier(), flowMetadata); } } @@ -126,15 +131,15 @@ public class MetadataHolder { return metadata; } - public Map<String,Bucket> getBucketsBydId() { + public Map<String,BucketMetadata> getBucketsBydId() { return bucketsById; } - public Map<String,VersionedFlow> getFlowsById() { + public Map<String,FlowMetadata> getFlowsById() { return flowsById; } - public Map<String,Set<VersionedFlow>> getFlowsByBucket() { + public Map<String,Set<FlowMetadata>> getFlowsByBucket() { return flowsByBucket; }
