Skip to content

Commit

Permalink
NIFI-12898 Follow on updates from initial implementation
Browse files Browse the repository at this point in the history
- Remove AssetRequestReplicator and use existing UploadRequestReplicator
- Remove AssetManagerFactoryBean and expose AssetManager from Java based Spring config
- Switch multi-part form upload to direct octect-stream upload
- Adding CLI commands creating and referencing assets
- Add REST end-point for listing assets in a given param context
- Fix param context update merger
- Add REST end-point for retrieving content of an asset
  • Loading branch information
bbende committed Jul 22, 2024
1 parent 668d2ca commit 147e2c3
Show file tree
Hide file tree
Showing 36 changed files with 911 additions and 210 deletions.
6 changes: 6 additions & 0 deletions nifi-api/src/main/java/org/apache/nifi/asset/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.nifi.asset;

import java.io.File;
import java.util.Optional;

/**
* An Asset is a representation of some resource that is necessary in order to run a dataflow.
Expand All @@ -40,4 +41,9 @@ public interface Asset {
*/
File getFile();

/**
* Returns the digest of the contents of the local file that the Asset is associated with.
* The digest will not be present when the asset is considered missing and the local file does not exist.
*/
Optional<String> getDigest();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class Parameter {
private final boolean provided;
private final List<Asset> referencedAssets;


private Parameter(final Builder builder) {
this.descriptor = new ParameterDescriptor.Builder()
.name(builder.name)
Expand Down Expand Up @@ -153,7 +152,7 @@ public Builder parameterContextId(final String parameterContextId) {
}

public Builder provided(final Boolean provided) {
this.provided = provided;
this.provided = provided != null && provided;
return this;
}

Expand Down
27 changes: 17 additions & 10 deletions nifi-api/src/test/java/org/apache/nifi/parameter/TestParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.File;
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -45,7 +46,7 @@ public void testCreateParameterWithValue() {
@Test
public void testCreateParameterWithSingleReference() {
final File file = new File("file");
final Asset asset = new MockAsset("id", "name", file);
final Asset asset = new MockAsset("id", "name", file, "asset-digest");

final Parameter parameter = new Parameter.Builder()
.name("A")
Expand All @@ -64,9 +65,9 @@ public void testCreateParameterWithMultipleReferences() {
final File file1 = new File("file1");
final File file2 = new File("file2");
final File file3 = new File("file3");
final Asset asset1 = new MockAsset("id1", "name1", file1);
final Asset asset2 = new MockAsset("id2", "name2", file2);
final Asset asset3 = new MockAsset("id3", "name3", file3);
final Asset asset1 = new MockAsset("id1", "name1", file1, "asset-digest");
final Asset asset2 = new MockAsset("id2", "name2", file2, "asset-digest");
final Asset asset3 = new MockAsset("id3", "name3", file3, "asset-digest");

final Parameter parameter = new Parameter.Builder()
.name("A")
Expand All @@ -82,7 +83,7 @@ public void testCreateParameterWithMultipleReferences() {
@Test
public void testCreateParameterWithValueThenAsset() {
final File file = new File("file");
final Asset asset = new MockAsset("id", "name", file);
final Asset asset = new MockAsset("id", "name", file, "asset-digest");

final Parameter parameter = new Parameter.Builder()
.name("A")
Expand All @@ -100,7 +101,7 @@ public void testCreateParameterWithValueThenAsset() {
@Test
public void testCreateParameterAssetThenValue() {
final File file = new File("file");
final Asset asset = new MockAsset("id", "name", file);
final Asset asset = new MockAsset("id", "name", file, "asset-digest");

final Parameter parameter = new Parameter.Builder()
.name("A")
Expand All @@ -117,7 +118,7 @@ public void testCreateParameterAssetThenValue() {
@Test
public void testCreateParameterFromOtherThenOverrideWithAsset() {
final File file = new File("file");
final Asset asset = new MockAsset("id", "name", file);
final Asset asset = new MockAsset("id", "name", file, "asset-digest");

final Parameter original = new Parameter.Builder()
.name("A")
Expand All @@ -138,7 +139,7 @@ public void testCreateParameterFromOtherThenOverrideWithAsset() {
@Test
public void testCreateParameterFromOtherThenOverrideWithValue() {
final File file = new File("file");
final Asset asset = new MockAsset("id", "name", file);
final Asset asset = new MockAsset("id", "name", file, "asset-digest");

final Parameter original = new Parameter.Builder()
.name("A")
Expand Down Expand Up @@ -174,16 +175,17 @@ public void testCreateParameterFromOtherThenOverrideWithDifferentValue() {
assertEquals(0, parameter.getReferencedAssets().size());
}


private static class MockAsset implements Asset {
private final String identifier;
private final String name;
private final File file;
private final String digest;

public MockAsset(final String identifier, final String name, final File file) {
public MockAsset(final String identifier, final String name, final File file, final String digest) {
this.identifier = identifier;
this.name = name;
this.file = file;
this.digest = digest;
}

@Override
Expand All @@ -200,5 +202,10 @@ public String getName() {
public File getFile() {
return file;
}

@Override
public Optional<String> getDigest() {
return Optional.ofNullable(digest);
}
}
}
3 changes: 3 additions & 0 deletions nifi-docs/src/main/asciidoc/toolkit-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ The following are available commands:
nifi delete-nar
nifi list-nars
nifi list-nar-component-types
nifi create-asset
nifi add-asset-reference
nifi remove-asset-reference
registry current-user
registry list-buckets
registry create-bucket
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;

public interface AssetManager {
Expand All @@ -45,6 +46,13 @@ public interface AssetManager {
*/
Optional<Asset> getAsset(String id);

/**
* Retrieves the Assets that belong to the given parameter context.
* @param parameterContextId the id of the parameter context
* @return the list of assets for the given context
*/
List<Asset> getAssets(String parameterContextId);

/**
* Creates an Asset with the given name and associates it with the given parameter context. If the asset already exists, it is returned. Otherwise, an asset is created
* but the underlying file is not created. This allows the asset to be referenced but any component that attempts to use the asset will still see a File that does not exist, which
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@

package org.apache.nifi.web.api.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.xml.bind.annotation.XmlType;

import java.util.Objects;

@XmlType(name = "asset")
public class AssetDTO {

private String id;
private String name;
private String filename;
private String digest;

@Schema(description = "The identifier of the asset.")
public String getId() {
return id;
}
Expand All @@ -34,6 +39,7 @@ public void setId(final String id) {
this.id = id;
}

@Schema(description = "The name of the asset.")
public String getName() {
return name;
}
Expand All @@ -42,11 +48,38 @@ public void setName(final String name) {
this.name = name;
}

@Schema(description = "The filename of the asset.")
public String getFilename() {
return filename;
}

public void setFilename(final String filename) {
this.filename = filename;
}

@Schema(description = "The digest of the asset.")
public String getDigest() {
return digest;
}

public void setDigest(final String digest) {
this.digest = digest;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final AssetDTO assetDTO = (AssetDTO) o;
return Objects.equals(id, assetDTO.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import jakarta.xml.bind.annotation.XmlRootElement;
import org.apache.nifi.web.api.dto.AssetDTO;

import java.util.Objects;

@XmlRootElement(name = "assetEntity")
public class AssetEntity extends Entity {
private AssetDTO asset;
Expand All @@ -35,4 +37,21 @@ public AssetDTO getAsset() {
public void setAsset(AssetDTO asset) {
this.asset = asset;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final AssetEntity that = (AssetEntity) o;
return Objects.equals(asset, that.asset);
}

@Override
public int hashCode() {
return Objects.hash(asset);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 io.swagger.v3.oas.annotations.media.Schema;
import jakarta.xml.bind.annotation.XmlRootElement;

import java.util.Collection;

@XmlRootElement(name = "assetEntity")
public class AssetsEntity extends Entity {

private Collection<AssetEntity> assets;

@Schema(description = "The asset entities")
public Collection<AssetEntity> getAssets() {
return assets;
}

public void setAssets(final Collection<AssetEntity> assets) {
this.assets = assets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import jakarta.ws.rs.core.StreamingOutput;
import org.apache.nifi.cluster.coordination.http.endpoints.AccessPolicyEndpointMerger;
import org.apache.nifi.cluster.coordination.http.endpoints.AssetsEndpointMerger;
import org.apache.nifi.cluster.coordination.http.endpoints.BulletinBoardEndpointMerger;
import org.apache.nifi.cluster.coordination.http.endpoints.ComponentStateEndpointMerger;
import org.apache.nifi.cluster.coordination.http.endpoints.ConnectionEndpointMerger;
Expand Down Expand Up @@ -201,7 +202,7 @@ public StandardHttpResponseMapper(final NiFiProperties nifiProperties) {
endpointMergers.add(new NarSummaryEndpointMerger());
endpointMergers.add(new NarSummariesEndpointMerger());
endpointMergers.add(new NarDetailsEndpointMerger());

endpointMergers.add(new AssetsEndpointMerger());
}

@Override
Expand Down
Loading

0 comments on commit 147e2c3

Please sign in to comment.