Skip to content

Commit 0f825ac

Browse files
committed
NIFI-14615 - removed processor and springboot dependency
1 parent d3fc229 commit 0f825ac

File tree

6 files changed

+235
-82
lines changed

6 files changed

+235
-82
lines changed

nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-content-viewer/pom.xml

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<artifactId>nifi-parquet-content-viewer</artifactId>
2626
<packaging>war</packaging>
2727
<properties>
28-
<spring.boot.version>3.4.6</spring.boot.version>
2928
<source.skip>true</source.skip>
3029
<standard-content-viewer.ui.working.dir>${project.build.directory}/standard-content-viewer-ui-working-directory</standard-content-viewer.ui.working.dir>
3130
</properties>
@@ -63,16 +62,6 @@
6362
</exclusion>
6463
</exclusions>
6564
</dependency>
66-
<dependency>
67-
<groupId>org.springframework.boot</groupId>
68-
<artifactId>spring-boot-autoconfigure</artifactId>
69-
<version>3.4.6</version>
70-
</dependency>
71-
<dependency>
72-
<groupId>org.apache.nifi</groupId>
73-
<artifactId>nifi-parquet-processors</artifactId>
74-
<version>2.5.0-SNAPSHOT</version>
75-
</dependency>
7665
<dependency>
7766
<groupId>org.apache.nifi</groupId>
7867
<artifactId>nifi-framework-api</artifactId>
@@ -95,24 +84,50 @@
9584
<version>2.5.0-SNAPSHOT</version>
9685
</dependency>
9786
<dependency>
98-
<groupId>org.springframework.boot</groupId>
99-
<artifactId>spring-boot-starter-web</artifactId>
100-
<version>${spring.boot.version}</version>
87+
<groupId>org.glassfish.jersey.core</groupId>
88+
<artifactId>jersey-common</artifactId>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.apache.parquet</groupId>
92+
<artifactId>parquet-common</artifactId>
93+
<version>1.15.2</version>
94+
<scope>compile</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.apache.parquet</groupId>
98+
<artifactId>parquet-hadoop</artifactId>
99+
<version>1.15.2</version>
100+
<scope>compile</scope>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.apache.parquet</groupId>
104+
<artifactId>parquet-avro</artifactId>
105+
<version>1.15.2</version>
106+
<scope>compile</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>org.apache.hadoop</groupId>
110+
<artifactId>hadoop-common</artifactId>
111+
<version>${hadoop.version}</version>
101112
<exclusions>
102113
<exclusion>
103-
<groupId>org.springframework.boot</groupId>
104-
<artifactId>spring-boot-starter-tomcat</artifactId>
114+
<groupId>log4j</groupId>
115+
<artifactId>log4j</artifactId>
116+
</exclusion>
117+
<exclusion>
118+
<groupId>org.slf4j</groupId>
119+
<artifactId>slf4j-reload4j</artifactId>
120+
</exclusion>
121+
<exclusion>
122+
<groupId>org.slf4j</groupId>
123+
<artifactId>slf4j-log4j12</artifactId>
105124
</exclusion>
106125
<exclusion>
107-
<groupId>org.springframework.boot</groupId>
108-
<artifactId>spring-boot-starter-logging</artifactId>
126+
<groupId>commons-logging</groupId>
127+
<artifactId>commons-logging</artifactId>
109128
</exclusion>
110129
</exclusions>
111130
</dependency>
112-
<dependency>
113-
<groupId>org.glassfish.jersey.core</groupId>
114-
<artifactId>jersey-common</artifactId>
115-
</dependency>
116131
</dependencies>
117132
<build>
118133
<plugins>

nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-content-viewer/src/main/java/org/apache/parquet/web/ParquetContentViewerApplication.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.parquet.web.content.viewer;
18+
19+
import jakarta.servlet.DispatcherType;
20+
import jakarta.servlet.FilterRegistration;
21+
import jakarta.servlet.ServletContext;
22+
import jakarta.servlet.ServletContextEvent;
23+
import jakarta.servlet.ServletContextListener;
24+
import jakarta.servlet.ServletRegistration;
25+
import jakarta.servlet.annotation.WebListener;
26+
import org.apache.nifi.web.servlet.filter.QueryStringToFragmentFilter;
27+
import org.apache.parquet.web.controller.ParquetContentViewerController;
28+
import org.eclipse.jetty.ee10.servlet.DefaultServlet;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
import java.util.EnumSet;
33+
34+
/**
35+
* Servlet Context Listener supporting registration of Filters
36+
*/
37+
@WebListener
38+
public class ParquetServletContextListener implements ServletContextListener {
39+
private static final String API_CONTENT_MAPPING = "/api/content";
40+
41+
private static final int LOAD_ON_STARTUP_ENABLED = 1;
42+
43+
private static final String DIR_ALLOWED_PARAMETER = "dirAllowed";
44+
45+
private static final String BASE_RESOURCE_PARAMETER = "baseResource";
46+
47+
private static final String BASE_RESOURCE_DIRECTORY = "WEB-INF/classes/static";
48+
49+
private static final String DEFAULT_MAPPING = "/";
50+
51+
private static final Logger logger = LoggerFactory.getLogger(ParquetServletContextListener.class);
52+
53+
@Override
54+
public void contextInitialized(final ServletContextEvent sce) {
55+
final ServletContext servletContext = sce.getServletContext();
56+
final FilterRegistration.Dynamic filter = servletContext.addFilter(QueryStringToFragmentFilter.class.getSimpleName(), QueryStringToFragmentFilter.class);
57+
filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, DEFAULT_MAPPING);
58+
59+
final ServletRegistration.Dynamic servlet = servletContext.addServlet(ParquetContentViewerController.class.getSimpleName(), ParquetContentViewerController.class);
60+
servlet.addMapping(API_CONTENT_MAPPING);
61+
servlet.setLoadOnStartup(LOAD_ON_STARTUP_ENABLED);
62+
63+
final ServletRegistration.Dynamic defaultServlet = servletContext.addServlet(DefaultServlet.class.getSimpleName(), DefaultServlet.class);
64+
defaultServlet.addMapping(DEFAULT_MAPPING);
65+
defaultServlet.setInitParameter(DIR_ALLOWED_PARAMETER, Boolean.FALSE.toString());
66+
defaultServlet.setInitParameter(BASE_RESOURCE_PARAMETER, BASE_RESOURCE_DIRECTORY);
67+
defaultServlet.setLoadOnStartup(LOAD_ON_STARTUP_ENABLED);
68+
69+
logger.info("Parquet Content Viewer Initialized");
70+
}
71+
}

nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-content-viewer/src/main/java/org/apache/parquet/web/controller/ParquetContentViewerController.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
package org.apache.parquet.web.controller;
1818

1919
import jakarta.servlet.ServletContext;
20+
import jakarta.servlet.http.HttpServlet;
2021
import jakarta.servlet.http.HttpServletRequest;
2122
import jakarta.servlet.http.HttpServletResponse;
2223
import org.apache.avro.generic.GenericRecord;
2324
import org.apache.commons.io.IOUtils;
2425
import org.apache.hadoop.conf.Configuration;
2526
import org.apache.nifi.authorization.AccessDeniedException;
26-
import org.apache.nifi.parquet.stream.NifiParquetInputFile;
2727
import org.apache.nifi.web.ContentAccess;
2828
import org.apache.nifi.web.ContentRequestContext;
2929
import org.apache.nifi.web.DownloadableContent;
@@ -32,11 +32,9 @@
3232
import org.apache.parquet.avro.AvroParquetReader;
3333
import org.apache.parquet.hadoop.ParquetReader;
3434
import org.apache.parquet.io.InputFile;
35+
import org.apache.parquet.web.utils.NifiParquetContentViewerInputFile;
3536
import org.slf4j.Logger;
3637
import org.slf4j.LoggerFactory;
37-
import org.springframework.web.bind.annotation.GetMapping;
38-
import org.springframework.web.bind.annotation.RequestMapping;
39-
import org.springframework.web.bind.annotation.RestController;
4038
import java.io.ByteArrayInputStream;
4139
import java.io.IOException;
4240
import java.io.InputStream;
@@ -45,13 +43,11 @@
4543
import java.util.Comparator;
4644
import java.util.List;
4745

48-
@RestController()
49-
@RequestMapping("/api")
50-
public class ParquetContentViewerController {
46+
public class ParquetContentViewerController extends HttpServlet {
5147
private static final Logger logger = LoggerFactory.getLogger(ParquetContentViewerController.class);
5248

53-
@GetMapping("/content")
54-
public void getContent(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
49+
@Override
50+
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
5551
final ContentRequestContext requestContext = new HttpServletContentRequestContext(request);
5652

5753
final ServletContext servletContext = request.getServletContext();
@@ -105,7 +101,7 @@ public void getContent(final HttpServletRequest request, final HttpServletRespon
105101
Configuration conf = new Configuration();
106102
conf.setBoolean("parquet.avro.readInt96AsFixed", true);
107103

108-
final InputFile inputFile = new NifiParquetInputFile(new ByteArrayInputStream(data), data.length);
104+
final InputFile inputFile = new NifiParquetContentViewerInputFile(new ByteArrayInputStream(data), data.length);
109105
final ParquetReader<GenericRecord> reader = AvroParquetReader.<GenericRecord>builder(inputFile)
110106
.withConf(conf)
111107
.build();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.parquet.web.utils;
18+
19+
import org.apache.nifi.stream.io.ByteCountingInputStream;
20+
import org.apache.parquet.io.InputFile;
21+
import org.apache.parquet.io.SeekableInputStream;
22+
23+
import java.io.InputStream;
24+
25+
public class NifiParquetContentViewerInputFile implements InputFile {
26+
private final long length;
27+
private final ByteCountingInputStream input;
28+
29+
public NifiParquetContentViewerInputFile(final InputStream input, final long length) {
30+
if (input == null) {
31+
throw new IllegalArgumentException("InputStream is required");
32+
}
33+
34+
if (!input.markSupported()) {
35+
throw new IllegalArgumentException("InputStream must support mark/reset to be used with NifiParquetInputFile");
36+
}
37+
38+
this.input = new ByteCountingInputStream(input);
39+
this.length = length;
40+
}
41+
42+
@Override
43+
public long getLength() {
44+
return length;
45+
}
46+
47+
@Override
48+
public SeekableInputStream newStream() {
49+
return new NifiParquetContentViewerSeekableInputStream(input);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.parquet.web.utils;
18+
19+
import org.apache.nifi.stream.io.ByteCountingInputStream;
20+
import org.apache.nifi.stream.io.StreamUtils;
21+
import org.apache.parquet.io.DelegatingSeekableInputStream;
22+
23+
import java.io.IOException;
24+
25+
public class NifiParquetContentViewerSeekableInputStream extends DelegatingSeekableInputStream {
26+
private final ByteCountingInputStream input;
27+
28+
public NifiParquetContentViewerSeekableInputStream(final ByteCountingInputStream input) {
29+
super(input);
30+
this.input = input;
31+
this.input.mark(8192);
32+
}
33+
34+
@Override
35+
public long getPos() {
36+
return input.getBytesConsumed();
37+
}
38+
39+
@Override
40+
public void seek(long newPos) throws IOException {
41+
final long currentPos = getPos();
42+
if (newPos == currentPos) {
43+
return;
44+
}
45+
46+
if (newPos < currentPos) {
47+
// seeking backwards so first reset back to beginning of the stream then seek
48+
input.reset();
49+
input.mark(8192);
50+
}
51+
52+
// must call getPos() again in case reset was called above
53+
StreamUtils.skip(input, newPos - getPos());
54+
}
55+
56+
@Override
57+
public boolean markSupported() {
58+
return false;
59+
}
60+
61+
@Override
62+
public synchronized void mark(int readlimit) {
63+
throw new UnsupportedOperationException("Mark/reset is not supported");
64+
}
65+
66+
@Override
67+
public synchronized void reset() {
68+
throw new UnsupportedOperationException("Mark/reset is not supported");
69+
}
70+
}

0 commit comments

Comments
 (0)