-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-12198 Add API and CLI commands to import reporting task snapshots (
#7875) * NIFI-12198 Add API and CLI commands to import reporting task snapshots
- Loading branch information
Showing
22 changed files
with
928 additions
and
139 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...c/main/java/org/apache/nifi/web/api/entity/VersionedReportingTaskImportRequestEntity.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,47 @@ | ||
/* | ||
* 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.annotations.ApiModelProperty; | ||
import org.apache.nifi.flow.VersionedReportingTaskSnapshot; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "versionedReportingTaskImportRequestEntity") | ||
public class VersionedReportingTaskImportRequestEntity extends Entity { | ||
|
||
private VersionedReportingTaskSnapshot reportingTaskSnapshot; | ||
private Boolean disconnectedNodeAcknowledged; | ||
|
||
@ApiModelProperty("The snapshot to import") | ||
public VersionedReportingTaskSnapshot getReportingTaskSnapshot() { | ||
return reportingTaskSnapshot; | ||
} | ||
|
||
public void setReportingTaskSnapshot(VersionedReportingTaskSnapshot reportingTaskSnapshot) { | ||
this.reportingTaskSnapshot = reportingTaskSnapshot; | ||
} | ||
|
||
@ApiModelProperty("The disconnected node acknowledged flag") | ||
public Boolean getDisconnectedNodeAcknowledged() { | ||
return disconnectedNodeAcknowledged; | ||
} | ||
|
||
public void setDisconnectedNodeAcknowledged(Boolean disconnectedNodeAcknowledged) { | ||
this.disconnectedNodeAcknowledged = disconnectedNodeAcknowledged; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../main/java/org/apache/nifi/web/api/entity/VersionedReportingTaskImportResponseEntity.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,47 @@ | ||
/* | ||
* 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.annotations.ApiModelProperty; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.Set; | ||
|
||
@XmlRootElement(name = "versionedReportingTaskImportResponseEntity") | ||
public class VersionedReportingTaskImportResponseEntity extends Entity { | ||
|
||
private Set<ReportingTaskEntity> reportingTasks; | ||
private Set<ControllerServiceEntity> controllerServices; | ||
|
||
@ApiModelProperty("The reporting tasks created by the import") | ||
public Set<ReportingTaskEntity> getReportingTasks() { | ||
return reportingTasks; | ||
} | ||
|
||
public void setReportingTasks(Set<ReportingTaskEntity> reportingTasks) { | ||
this.reportingTasks = reportingTasks; | ||
} | ||
|
||
@ApiModelProperty("The controller services created by the import") | ||
public Set<ControllerServiceEntity> getControllerServices() { | ||
return controllerServices; | ||
} | ||
|
||
public void setControllerServices(Set<ControllerServiceEntity> controllerServices) { | ||
this.controllerServices = controllerServices; | ||
} | ||
} |
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
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
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
111 changes: 111 additions & 0 deletions
111
...core/src/main/java/org/apache/nifi/controller/serialization/FlowSynchronizationUtils.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,111 @@ | ||
/* | ||
* 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.controller.serialization; | ||
|
||
import org.apache.nifi.bundle.BundleCoordinate; | ||
import org.apache.nifi.components.PropertyDescriptor; | ||
import org.apache.nifi.controller.ComponentNode; | ||
import org.apache.nifi.encrypt.EncryptionException; | ||
import org.apache.nifi.encrypt.PropertyEncryptor; | ||
import org.apache.nifi.flow.Bundle; | ||
import org.apache.nifi.flow.VersionedConfigurableExtension; | ||
import org.apache.nifi.flow.VersionedPropertyDescriptor; | ||
import org.apache.nifi.nar.ExtensionManager; | ||
import org.apache.nifi.util.BundleUtils; | ||
import org.apache.nifi.web.api.dto.BundleDTO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class FlowSynchronizationUtils { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(FlowSynchronizationUtils.class); | ||
|
||
private FlowSynchronizationUtils() { | ||
} | ||
|
||
static BundleCoordinate createBundleCoordinate(final ExtensionManager extensionManager, final Bundle bundle, final String componentType) { | ||
BundleCoordinate coordinate; | ||
try { | ||
final BundleDTO bundleDto = new BundleDTO(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); | ||
coordinate = BundleUtils.getCompatibleBundle(extensionManager, componentType, bundleDto); | ||
} catch (final IllegalStateException e) { | ||
coordinate = new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); | ||
} | ||
|
||
return coordinate; | ||
} | ||
|
||
static Set<String> getSensitiveDynamicPropertyNames(final ComponentNode componentNode, final VersionedConfigurableExtension extension) { | ||
final Set<String> versionedSensitivePropertyNames = new LinkedHashSet<>(); | ||
|
||
// Get Sensitive Property Names based on encrypted values including both supported and dynamic properties | ||
extension.getProperties() | ||
.entrySet() | ||
.stream() | ||
.filter(entry -> isValueSensitive(entry.getValue())) | ||
.map(Map.Entry::getKey) | ||
.forEach(versionedSensitivePropertyNames::add); | ||
|
||
// Get Sensitive Property Names based on supported and dynamic property descriptors | ||
extension.getPropertyDescriptors() | ||
.values() | ||
.stream() | ||
.filter(VersionedPropertyDescriptor::isSensitive) | ||
.map(VersionedPropertyDescriptor::getName) | ||
.forEach(versionedSensitivePropertyNames::add); | ||
|
||
// Filter combined Sensitive Property Names based on Component Property Descriptor status | ||
return versionedSensitivePropertyNames.stream() | ||
.map(componentNode::getPropertyDescriptor) | ||
.filter(PropertyDescriptor::isDynamic) | ||
.map(PropertyDescriptor::getName) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
static boolean isValueSensitive(final String value) { | ||
return value != null && value.startsWith(FlowSerializer.ENC_PREFIX) && value.endsWith(FlowSerializer.ENC_SUFFIX); | ||
} | ||
|
||
static Map<String, String> decryptProperties(final Map<String, String> encrypted, final PropertyEncryptor encryptor) { | ||
final Map<String, String> decrypted = new HashMap<>(encrypted.size()); | ||
encrypted.forEach((key, value) -> decrypted.put(key, decrypt(value, encryptor))); | ||
return decrypted; | ||
} | ||
|
||
static String decrypt(final String value, final PropertyEncryptor encryptor) { | ||
if (isValueSensitive(value)) { | ||
try { | ||
return encryptor.decrypt(value.substring(FlowSerializer.ENC_PREFIX.length(), value.length() - FlowSerializer.ENC_SUFFIX.length())); | ||
} catch (EncryptionException e) { | ||
final String moreDescriptiveMessage = "There was a problem decrypting a sensitive flow configuration value. " + | ||
"Check that the nifi.sensitive.props.key value in nifi.properties matches the value used to encrypt the flow.json.gz file"; | ||
logger.error(moreDescriptiveMessage, e); | ||
throw new EncryptionException(moreDescriptiveMessage, e); | ||
} | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.