Repository: nifi Updated Branches: refs/heads/master 82829927a -> 8fa35294e
NIFI-3764: - Ensuring that UUIDs are not converted multiple times during template export. This closes #1730. Signed-off-by: Bryan Bende <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/8fa35294 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/8fa35294 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/8fa35294 Branch: refs/heads/master Commit: 8fa35294eb5c11ee368a76d5e5ecdf171633d7c4 Parents: 8282992 Author: Matt Gilman <[email protected]> Authored: Tue May 2 09:22:35 2017 -0400 Committer: Bryan Bende <[email protected]> Committed: Tue May 2 09:59:39 2017 -0400 ---------------------------------------------------------------------- .../apache/nifi/web/api/dto/FlowSnippetDTO.java | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/8fa35294/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java index 79d94eb..33296f8 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java @@ -21,6 +21,7 @@ import com.wordnik.swagger.annotations.ApiModelProperty; import javax.xml.bind.annotation.XmlType; import java.nio.charset.StandardCharsets; import java.util.Comparator; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; import java.util.Map.Entry; @@ -34,6 +35,8 @@ import java.util.UUID; @XmlType(name = "flowSnippet") public class FlowSnippetDTO { + private static final long LSB = 0; + private Set<ProcessGroupDTO> processGroups = new LinkedHashSet<>(); private Set<RemoteProcessGroupDTO> remoteProcessGroups = new LinkedHashSet<>(); private Set<ProcessorDTO> processors = new LinkedHashSet<>(); @@ -45,6 +48,7 @@ public class FlowSnippetDTO { private Set<ControllerServiceDTO> controllerServices = new LinkedHashSet<>(); private final boolean newTemplate; + private Set<String> convertedUuids = new HashSet<>(); public FlowSnippetDTO() { this(false); @@ -200,18 +204,25 @@ public class FlowSnippetDTO { } private long generateMsb(String id) { - UUID temp = UUID.nameUUIDFromBytes(id.getBytes(StandardCharsets.UTF_8)); - long msb = temp.getMostSignificantBits(); - return msb; + final UUID temp; + if (convertedUuids.contains(id)) { + temp = UUID.fromString(id); + } else { + temp = UUID.nameUUIDFromBytes(id.getBytes(StandardCharsets.UTF_8)); + + // record what the converted uuid will be so we do not re-convert a previously converted uuid + convertedUuids.add(new UUID(temp.getMostSignificantBits(), LSB).toString()); + } + return temp.getMostSignificantBits(); } private void removeInstanceIdentifierIfNecessary(Set<? extends ComponentDTO> componentDtos) { if (this.newTemplate) { for (ComponentDTO componentDto : componentDtos) { - UUID id = new UUID(this.generateMsb(componentDto.getId()), 0); + UUID id = new UUID(this.generateMsb(componentDto.getId()), LSB); componentDto.setId(id.toString()); - id = new UUID(this.generateMsb(componentDto.getParentGroupId()), 0); + id = new UUID(this.generateMsb(componentDto.getParentGroupId()), LSB); componentDto.setParentGroupId(id.toString()); if (componentDto instanceof ControllerServiceDTO) { ControllerServiceDTO csDTO = (ControllerServiceDTO) componentDto; @@ -221,7 +232,7 @@ public class FlowSnippetDTO { if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) { String key = entry.getKey(); String value = props.get(key); - id = new UUID(this.generateMsb(value), 0); + id = new UUID(this.generateMsb(value), LSB); props.put(key, id.toString()); } } @@ -233,7 +244,7 @@ public class FlowSnippetDTO { if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) { String key = entry.getKey(); String value = props.get(key); - id = new UUID(this.generateMsb(value), 0); + id = new UUID(this.generateMsb(value), LSB); props.put(key, id.toString()); } } @@ -242,20 +253,20 @@ public class FlowSnippetDTO { ConnectableDTO cdto = connectionDTO.getSource(); if (!cdto.getType().equals("REMOTE_INPUT_PORT") && !cdto.getType().equals("REMOTE_OUTPUT_PORT")) { - id = new UUID(this.generateMsb(cdto.getId()), 0); + id = new UUID(this.generateMsb(cdto.getId()), LSB); cdto.setId(id.toString()); } - id = new UUID(this.generateMsb(cdto.getGroupId()), 0); + id = new UUID(this.generateMsb(cdto.getGroupId()), LSB); cdto.setGroupId(id.toString()); cdto = connectionDTO.getDestination(); if (!cdto.getType().equals("REMOTE_INPUT_PORT") && !cdto.getType().equals("REMOTE_OUTPUT_PORT")) { - id = new UUID(this.generateMsb(cdto.getId()), 0); + id = new UUID(this.generateMsb(cdto.getId()), LSB); cdto.setId(id.toString()); } - id = new UUID(this.generateMsb(cdto.getGroupId()), 0); + id = new UUID(this.generateMsb(cdto.getGroupId()), LSB); cdto.setGroupId(id.toString()); } else if (componentDto instanceof ProcessGroupDTO) { FlowSnippetDTO fsDTO = ((ProcessGroupDTO) componentDto).getContents();
