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.
Refactor standard persistence provider to use hierarchical directorie…
…s and include properties file
- Loading branch information
Showing
8 changed files
with
640 additions
and
94 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarPersistenceInfo.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,60 @@ | ||
/* | ||
* 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.io.File; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The information about a NAR persisted by a {@link NarPersistenceProvider}. | ||
*/ | ||
public class NarPersistenceInfo { | ||
|
||
private final File narFile; | ||
private final NarProperties narProperties; | ||
|
||
public NarPersistenceInfo(final File narFile, final NarProperties narProperties) { | ||
this.narFile = Objects.requireNonNull(narFile); | ||
this.narProperties = Objects.requireNonNull(narProperties); | ||
} | ||
|
||
public File getNarFile() { | ||
return narFile; | ||
} | ||
|
||
public NarProperties getNarProperties() { | ||
return narProperties; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final NarPersistenceInfo that = (NarPersistenceInfo) o; | ||
return Objects.equals(narProperties.getCoordinate(), that.narProperties.getCoordinate()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(narProperties.getCoordinate()); | ||
} | ||
} |
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
214 changes: 214 additions & 0 deletions
214
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarProperties.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,214 @@ | ||
/* | ||
* 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.time.Instant; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Properties about a NAR that are persisted by the {@link NarPersistenceProvider}. | ||
*/ | ||
public class NarProperties { | ||
|
||
private final String sourceType; | ||
private final String sourceId; | ||
|
||
private final String narGroup; | ||
private final String narId; | ||
private final String narVersion; | ||
|
||
private final String narDependencyGroup; | ||
private final String narDependencyId; | ||
private final String narDependencyVersion; | ||
|
||
private final Instant created; | ||
|
||
private NarProperties(final Builder builder) { | ||
this.sourceType = Objects.requireNonNull(builder.sourceType); | ||
this.sourceId = builder.sourceId; | ||
|
||
this.narGroup = Objects.requireNonNull(builder.narGroup); | ||
this.narId = Objects.requireNonNull(builder.narId); | ||
this.narVersion = Objects.requireNonNull(builder.narVersion); | ||
|
||
this.narDependencyGroup = builder.narDependencyGroup; | ||
this.narDependencyId = builder.narDependencyId; | ||
this.narDependencyVersion = builder.narDependencyVersion; | ||
|
||
this.created = Objects.requireNonNull(builder.created); | ||
} | ||
|
||
public String getSourceType() { | ||
return sourceType; | ||
} | ||
|
||
public String getSourceId() { | ||
return sourceId; | ||
} | ||
|
||
public String getNarGroup() { | ||
return narGroup; | ||
} | ||
|
||
public String getNarId() { | ||
return narId; | ||
} | ||
|
||
public String getNarVersion() { | ||
return narVersion; | ||
} | ||
|
||
public String getNarDependencyGroup() { | ||
return narDependencyGroup; | ||
} | ||
|
||
public String getNarDependencyId() { | ||
return narDependencyId; | ||
} | ||
|
||
public String getNarDependencyVersion() { | ||
return narDependencyVersion; | ||
} | ||
|
||
public Instant getCreated() { | ||
return created; | ||
} | ||
|
||
public BundleCoordinate getCoordinate() { | ||
return new BundleCoordinate(narGroup, narId, narVersion); | ||
} | ||
|
||
public Optional<BundleCoordinate> getDependencyCoordinate() { | ||
if (narDependencyGroup == null) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(new BundleCoordinate(narDependencyGroup, narDependencyId, narDependencyVersion)); | ||
} | ||
|
||
public Properties toProperties() { | ||
final Properties properties = new Properties(); | ||
properties.put(NarProperty.SOURCE_TYPE.getKey(), sourceType); | ||
if (sourceId != null) { | ||
properties.put(NarProperty.SOURCE_ID.getKey(), sourceId); | ||
} | ||
|
||
properties.put(NarProperty.NAR_GROUP.getKey(), narGroup); | ||
properties.put(NarProperty.NAR_ID.getKey(), narId); | ||
properties.put(NarProperty.NAR_VERSION.getKey(), narVersion); | ||
|
||
if (narDependencyGroup != null) { | ||
properties.put(NarProperty.NAR_DEPENDENCY_GROUP.getKey(), narDependencyGroup); | ||
properties.put(NarProperty.NAR_DEPENDENCY_ID.getKey(), narDependencyId); | ||
properties.put(NarProperty.NAR_DEPENDENCY_VERSION.getKey(), narDependencyVersion); | ||
} | ||
|
||
properties.put(NarProperty.CREATED.getKey(), created.toString()); | ||
return properties; | ||
} | ||
|
||
public static NarProperties parse(final InputStream inputStream) throws IOException { | ||
final Properties properties = new Properties(); | ||
properties.load(inputStream); | ||
|
||
final String createdValue = properties.getProperty(NarProperty.CREATED.getKey()); | ||
final Instant created = Instant.parse(createdValue); | ||
|
||
return NarProperties.builder() | ||
.sourceType(properties.getProperty(NarProperty.SOURCE_TYPE.getKey())) | ||
.sourceId(properties.getProperty(NarProperty.SOURCE_ID.getKey())) | ||
.narGroup(properties.getProperty(NarProperty.NAR_GROUP.getKey())) | ||
.narId(properties.getProperty(NarProperty.NAR_ID.getKey())) | ||
.narVersion(properties.getProperty(NarProperty.NAR_VERSION.getKey())) | ||
.narDependencyGroup(properties.getProperty(NarProperty.NAR_DEPENDENCY_GROUP.getKey())) | ||
.narDependencyId(properties.getProperty(NarProperty.NAR_DEPENDENCY_ID.getKey())) | ||
.narDependencyVersion(properties.getProperty(NarProperty.NAR_DEPENDENCY_VERSION.getKey())) | ||
.created(created) | ||
.build(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
private String sourceType; | ||
private String sourceId; | ||
private String narGroup; | ||
private String narId; | ||
private String narVersion; | ||
private String narDependencyGroup; | ||
private String narDependencyId; | ||
private String narDependencyVersion; | ||
private Instant created; | ||
|
||
public Builder sourceType(final String sourceType) { | ||
this.sourceType = sourceType; | ||
return this; | ||
} | ||
|
||
public Builder sourceId(final String sourceId) { | ||
this.sourceId = sourceId; | ||
return this; | ||
} | ||
|
||
public Builder narGroup(final String narGroup) { | ||
this.narGroup = narGroup; | ||
return this; | ||
} | ||
|
||
public Builder narId(final String narId) { | ||
this.narId = narId; | ||
return this; | ||
} | ||
|
||
public Builder narVersion(final String narVersion) { | ||
this.narVersion = narVersion; | ||
return this; | ||
} | ||
|
||
public Builder narDependencyGroup(final String narDependencyGroup) { | ||
this.narDependencyGroup = narDependencyGroup; | ||
return this; | ||
} | ||
|
||
public Builder narDependencyId(final String narDependencyId) { | ||
this.narDependencyId = narDependencyId; | ||
return this; | ||
} | ||
|
||
public Builder narDependencyVersion(final String narDependencyVersion) { | ||
this.narDependencyVersion = narDependencyVersion; | ||
return this; | ||
} | ||
|
||
public Builder created(final Instant created) { | ||
this.created = created; | ||
return this; | ||
} | ||
|
||
public NarProperties build() { | ||
return new NarProperties(this); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarProperty.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,44 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Keys for {@link NarProperties}. | ||
*/ | ||
public enum NarProperty { | ||
|
||
SOURCE_TYPE("source.type"), | ||
SOURCE_ID("source.id"), | ||
NAR_GROUP("nar.group"), | ||
NAR_ID("nar.id"), | ||
NAR_VERSION("nar.version"), | ||
NAR_DEPENDENCY_GROUP("nar.dependency.group"), | ||
NAR_DEPENDENCY_ID("nar.dependency.id"), | ||
NAR_DEPENDENCY_VERSION("nar.dependency.version"), | ||
CREATED("created"); | ||
|
||
private final String key; | ||
|
||
NarProperty(final String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
} |
Oops, something went wrong.