forked from apache/nifi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAR Manager - Initial setup of API, NiFi Properties, creation in Flow…
…Controller, and Spring config
- Loading branch information
Showing
20 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.nar; | ||
|
||
import org.apache.nifi.bundle.BundleCoordinate; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Set; | ||
|
||
public interface NarManager { | ||
|
||
void initialize(NarManagerInitializationContext initializationContext) throws IOException; | ||
|
||
void shutdown(); | ||
|
||
BundleCoordinate addNar(String filename, InputStream inputStream) throws IOException; | ||
|
||
Set<BundleCoordinate> getNars(); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarManagerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.nar; | ||
|
||
public class NarManagerException extends RuntimeException { | ||
|
||
public NarManagerException(final String message) { | ||
super(message); | ||
} | ||
|
||
public NarManagerException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarManagerInitializationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.nar; | ||
|
||
import java.util.Map; | ||
|
||
public interface NarManagerInitializationContext { | ||
|
||
/** | ||
* @return the properties that have been configured for the NarManager | ||
*/ | ||
Map<String, String> getProperties(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...i-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/StandardNarManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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.nar; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.nifi.bundle.BundleCoordinate; | ||
import org.apache.nifi.util.FileUtils; | ||
import org.apache.nifi.util.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class StandardNarManager implements NarManager { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(StandardNarManager.class); | ||
|
||
private static final String DIRECTORY_PROPERTY = "directory"; | ||
|
||
private volatile File directory; | ||
|
||
@Override | ||
public void initialize(final NarManagerInitializationContext initializationContext) throws IOException { | ||
final String directoryPropertyValue = getRequiredValue(initializationContext, DIRECTORY_PROPERTY); | ||
final File directory = new File(directoryPropertyValue); | ||
FileUtils.ensureDirectoryExistAndCanReadAndWrite(directory); | ||
this.directory = directory; | ||
LOGGER.info("NarManager initialization completed - NARs will be stored at [{}]", directory.getAbsolutePath()); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
// TODO | ||
} | ||
|
||
@Override | ||
public BundleCoordinate addNar(final String filename, final InputStream inputStream) throws IOException { | ||
final File destFile = new File(directory, filename); | ||
if (destFile.exists()) { | ||
throw new NarManagerException("NAR file with the same name already exists"); | ||
} | ||
|
||
final File tempFile = new File(directory, "." + filename); | ||
LOGGER.debug("Writing NAR to temp file at [{}]", tempFile.getAbsolutePath()); | ||
try (final OutputStream outputStream = new FileOutputStream(tempFile)) { | ||
IOUtils.copy(inputStream, outputStream); | ||
} | ||
|
||
// TODO should we extract and verify the file has a MANIFEST, throw exception if not, otherwise use info to return BundleCoordinate? | ||
|
||
LOGGER.debug("Moving NAR to final file at [{}]", destFile.getAbsolutePath()); | ||
Files.move(tempFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||
return null; | ||
} | ||
|
||
@Override | ||
public Set<BundleCoordinate> getNars() { | ||
// TODO | ||
return null; | ||
} | ||
|
||
private String getRequiredValue(final NarManagerInitializationContext initializationContext, final String property) { | ||
final Map<String, String> properties = initializationContext.getProperties(); | ||
final String value = properties.get(property); | ||
if (StringUtils.isBlank(value)) { | ||
throw new IllegalStateException("Missing required property: " + property); | ||
} | ||
return value; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ework-core/src/main/java/org/apache/nifi/nar/StandardNarManagerInitializationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.nar; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class StandardNarManagerInitializationContext implements NarManagerInitializationContext { | ||
|
||
private final Map<String, String> properties; | ||
|
||
public StandardNarManagerInitializationContext(final Map<String, String> properties) { | ||
this.properties = properties == null ? Collections.emptyMap() : Map.copyOf(properties); | ||
} | ||
|
||
@Override | ||
public Map<String, String> getProperties() { | ||
return properties; | ||
} | ||
|
||
} |
Oops, something went wrong.