NIFI-3764: - Ensuring that UUIDs are not converted multiple times during template export.

This closes #1730.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Matt Gilman 2017-05-02 09:22:35 -04:00 committed by Bryan Bende
parent 82829927ae
commit 8fa35294eb
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
1 changed files with 22 additions and 11 deletions

View File

@ -21,6 +21,7 @@ import com.wordnik.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -34,6 +35,8 @@ import java.util.UUID;
@XmlType(name = "flowSnippet") @XmlType(name = "flowSnippet")
public class FlowSnippetDTO { public class FlowSnippetDTO {
private static final long LSB = 0;
private Set<ProcessGroupDTO> processGroups = new LinkedHashSet<>(); private Set<ProcessGroupDTO> processGroups = new LinkedHashSet<>();
private Set<RemoteProcessGroupDTO> remoteProcessGroups = new LinkedHashSet<>(); private Set<RemoteProcessGroupDTO> remoteProcessGroups = new LinkedHashSet<>();
private Set<ProcessorDTO> processors = new LinkedHashSet<>(); private Set<ProcessorDTO> processors = new LinkedHashSet<>();
@ -45,6 +48,7 @@ public class FlowSnippetDTO {
private Set<ControllerServiceDTO> controllerServices = new LinkedHashSet<>(); private Set<ControllerServiceDTO> controllerServices = new LinkedHashSet<>();
private final boolean newTemplate; private final boolean newTemplate;
private Set<String> convertedUuids = new HashSet<>();
public FlowSnippetDTO() { public FlowSnippetDTO() {
this(false); this(false);
@ -200,18 +204,25 @@ public class FlowSnippetDTO {
} }
private long generateMsb(String id) { private long generateMsb(String id) {
UUID temp = UUID.nameUUIDFromBytes(id.getBytes(StandardCharsets.UTF_8)); final UUID temp;
long msb = temp.getMostSignificantBits(); if (convertedUuids.contains(id)) {
return msb; 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) { private void removeInstanceIdentifierIfNecessary(Set<? extends ComponentDTO> componentDtos) {
if (this.newTemplate) { if (this.newTemplate) {
for (ComponentDTO componentDto : componentDtos) { 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()); componentDto.setId(id.toString());
id = new UUID(this.generateMsb(componentDto.getParentGroupId()), 0); id = new UUID(this.generateMsb(componentDto.getParentGroupId()), LSB);
componentDto.setParentGroupId(id.toString()); componentDto.setParentGroupId(id.toString());
if (componentDto instanceof ControllerServiceDTO) { if (componentDto instanceof ControllerServiceDTO) {
ControllerServiceDTO csDTO = (ControllerServiceDTO) componentDto; ControllerServiceDTO csDTO = (ControllerServiceDTO) componentDto;
@ -221,7 +232,7 @@ public class FlowSnippetDTO {
if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) { if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) {
String key = entry.getKey(); String key = entry.getKey();
String value = props.get(key); String value = props.get(key);
id = new UUID(this.generateMsb(value), 0); id = new UUID(this.generateMsb(value), LSB);
props.put(key, id.toString()); props.put(key, id.toString());
} }
} }
@ -233,7 +244,7 @@ public class FlowSnippetDTO {
if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) { if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) {
String key = entry.getKey(); String key = entry.getKey();
String value = props.get(key); String value = props.get(key);
id = new UUID(this.generateMsb(value), 0); id = new UUID(this.generateMsb(value), LSB);
props.put(key, id.toString()); props.put(key, id.toString());
} }
} }
@ -242,20 +253,20 @@ public class FlowSnippetDTO {
ConnectableDTO cdto = connectionDTO.getSource(); ConnectableDTO cdto = connectionDTO.getSource();
if (!cdto.getType().equals("REMOTE_INPUT_PORT") && !cdto.getType().equals("REMOTE_OUTPUT_PORT")) { 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()); 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.setGroupId(id.toString());
cdto = connectionDTO.getDestination(); cdto = connectionDTO.getDestination();
if (!cdto.getType().equals("REMOTE_INPUT_PORT") && !cdto.getType().equals("REMOTE_OUTPUT_PORT")) { 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()); 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.setGroupId(id.toString());
} else if (componentDto instanceof ProcessGroupDTO) { } else if (componentDto instanceof ProcessGroupDTO) {
FlowSnippetDTO fsDTO = ((ProcessGroupDTO) componentDto).getContents(); FlowSnippetDTO fsDTO = ((ProcessGroupDTO) componentDto).getContents();