@Override public Object deserializeKey(String sspString, DeserializationContext ctxt) throws IOException { int idx = sspString.indexOf('.'); int lastIdx = sspString.lastIndexOf('.'); if (idx < 0 || lastIdx < 0) { throw new IllegalArgumentException("System stream partition expected in format 'system.stream.partition"); } return new SystemStreamPartition( new SystemStream(sspString.substring(0, idx), sspString.substring(idx + 1, lastIdx)), new Partition(Integer.parseInt(sspString.substring(lastIdx + 1)))); } }
@Override public String toString() { return "SystemStreamPartition [" + system + ", " + stream + ", " + partition.getPartitionId() + "]"; }
@Override public int compareTo(SystemStreamPartition that) { if (this.system.compareTo(that.system) < 0) { return -1; } else if (this.system.compareTo(that.system) > 0) { return 1; } if (this.stream.compareTo(that.stream) < 0) { return -1; } else if (this.stream.compareTo(that.stream) > 0) { return 1; } if (this.partition.compareTo(that.partition) < 0) { return -1; } else if (this.partition.compareTo(that.partition) > 0) { return 1; } return 0; } }
@Override public SystemStreamPartition getPreviousSSP(SystemStreamPartition currentSystemStreamPartition, int previousPartitionCount, int currentPartitionCount) { Preconditions.checkNotNull(currentSystemStreamPartition); Preconditions.checkArgument(currentPartitionCount % previousPartitionCount == 0, String.format("New partition count: %d should be a multiple of previous partition count: %d.", currentPartitionCount, previousPartitionCount)); Partition partition = currentSystemStreamPartition.getPartition(); Preconditions.checkNotNull(partition, String.format("SystemStreamPartition: %s cannot have null partition", currentSystemStreamPartition)); int currentPartitionId = partition.getPartitionId(); int previousPartitionId = currentPartitionId % previousPartitionCount; return new SystemStreamPartition(currentSystemStreamPartition.getSystemStream(), new Partition(previousPartitionId)); } }
private int computeHashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((partition == null) ? 0 : partition.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SystemStreamPartition other = (SystemStreamPartition) obj; if (partition == null) { if (other.partition != null) return false; } else if (!partition.equals(other.partition)) return false; return true; }
private int computeHashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((partition == null) ? 0 : partition.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SystemStreamPartition other = (SystemStreamPartition) obj; if (partition == null) { if (other.partition != null) return false; } else if (!partition.equals(other.partition)) return false; return true; }
@Override public Map<String, SystemStreamMetadata> getSystemStreamMetadata(Set<String> streamNames) { return streamNames.stream() .collect(Collectors.toMap(Function.identity(), streamName -> new SystemStreamMetadata(streamName, Collections.singletonMap(new Partition(0), new SystemStreamMetadata.SystemStreamPartitionMetadata(null, null, null))))); }
@Override public String toString() { return "SystemStreamPartition [" + system + ", " + stream + ", " + partition.getPartitionId() + "]"; }
@Override public int hashCode() { int result = taskName.hashCode(); result = 31 * result + systemStreamPartitions.hashCode(); result = 31 * result + changelogPartition.hashCode(); return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TaskModel taskModel = (TaskModel) o; if (!changelogPartition.equals(taskModel.changelogPartition)) { return false; } if (!systemStreamPartitions.equals(taskModel.systemStreamPartitions)) { return false; } if (!taskName.equals(taskModel.taskName)) { return false; } return true; }
@Override public int compareTo(SystemStreamPartition that) { if (this.system.compareTo(that.system) < 0) { return -1; } else if (this.system.compareTo(that.system) > 0) { return 1; } if (this.stream.compareTo(that.stream) < 0) { return -1; } else if (this.stream.compareTo(that.stream) > 0) { return 1; } if (this.partition.compareTo(that.partition) < 0) { return -1; } else if (this.partition.compareTo(that.partition) > 0) { return 1; } return 0; } }
public static Map<Partition, List<String>> getDescriptorMapFromJson(String json) { try { @SuppressWarnings("unchecked") Map<String, String> rawMap = new ObjectMapper().readValue(json, HashMap.class); Map<Partition, List<String>> descriptorMap = new HashMap<>(); rawMap.forEach((key, value) -> descriptorMap.put(new Partition(Integer.valueOf(key)), getPathsFromString(value))); return descriptorMap; } catch (IOException | NumberFormatException e) { throw new SamzaException("Failed to convert json: " + json, e); } }
@Override public void serialize(Partition partition, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException { jsonGenerator.writeObject(Integer.valueOf(partition.getPartitionId())); } }
@Override public int hashCode() { int result = taskName.hashCode(); result = 31 * result + systemStreamPartitions.hashCode(); result = 31 * result + changelogPartition.hashCode(); result = 31 * result + taskMode.hashCode(); return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TaskModel taskModel = (TaskModel) o; if (!changelogPartition.equals(taskModel.changelogPartition)) { return false; } if (!systemStreamPartitions.equals(taskModel.systemStreamPartitions)) { return false; } if (!taskName.equals(taskModel.taskName)) { return false; } if (!taskMode.equals(taskModel.taskMode)) { return false; } return true; }
@Override public Object deserializeKey(String sspString, DeserializationContext ctxt) throws IOException { int idx = sspString.indexOf('.'); int lastIdx = sspString.lastIndexOf('.'); if (idx < 0 || lastIdx < 0) { throw new IllegalArgumentException("System stream partition expected in format 'system.stream.partition"); } return new SystemStreamPartition( new SystemStream(sspString.substring(0, idx), sspString.substring(idx + 1, lastIdx)), new Partition(Integer.parseInt(sspString.substring(lastIdx + 1)))); } }
@Override public void serialize(Partition partition, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException { jsonGenerator.writeObject(Integer.valueOf(partition.getPartitionId())); } }
@Override public Object deserializeKey(String sspString, DeserializationContext ctxt) throws IOException { int idx = sspString.indexOf('.'); int lastIdx = sspString.lastIndexOf('.'); if (idx < 0 || lastIdx < 0) { throw new IllegalArgumentException("System stream partition expected in format 'system.stream.partition"); } return new SystemStreamPartition( new SystemStream(sspString.substring(0, idx), sspString.substring(idx + 1, lastIdx)), new Partition(Integer.parseInt(sspString.substring(lastIdx + 1)))); } }