Try out chunking

This commit is contained in:
pratik
2025-10-21 15:19:49 -05:00
parent 9ad9e6b7b8
commit fdcc92eeb6
9 changed files with 849 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
package com.cfdeployer.model;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class ChunkUploadRequest {
@NotBlank(message = "Upload session ID is required")
private String uploadSessionId;
@NotBlank(message = "File type is required (jarFile or manifest)")
private String fileType; // "jarFile" or "manifest"
@NotNull(message = "Chunk index is required")
@Min(value = 0, message = "Chunk index must be non-negative")
private Integer chunkIndex;
@NotNull(message = "Total chunks is required")
@Min(value = 1, message = "Total chunks must be at least 1")
private Integer totalChunks;
private String fileName;
}

View File

@@ -0,0 +1,41 @@
package com.cfdeployer.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChunkUploadResponse {
private Boolean success;
private String uploadSessionId;
private String fileType;
private Integer chunkIndex;
private Integer totalChunks;
private Integer receivedChunks;
private String message;
public static ChunkUploadResponse success(String uploadSessionId, String fileType,
Integer chunkIndex, Integer totalChunks, Integer receivedChunks) {
return ChunkUploadResponse.builder()
.success(true)
.uploadSessionId(uploadSessionId)
.fileType(fileType)
.chunkIndex(chunkIndex)
.totalChunks(totalChunks)
.receivedChunks(receivedChunks)
.message("Chunk uploaded successfully")
.build();
}
public static ChunkUploadResponse failure(String message) {
return ChunkUploadResponse.builder()
.success(false)
.message(message)
.build();
}
}

View File

@@ -0,0 +1,61 @@
package com.cfdeployer.model;
import lombok.Data;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Data
public class UploadSession {
private String sessionId;
private String requestJson;
private Path workingDirectory;
private LocalDateTime createdAt;
private LocalDateTime lastAccessedAt;
// File type -> chunk tracking
private Map<String, FileUploadState> fileStates;
public UploadSession(String sessionId, String requestJson, Path workingDirectory) {
this.sessionId = sessionId;
this.requestJson = requestJson;
this.workingDirectory = workingDirectory;
this.createdAt = LocalDateTime.now();
this.lastAccessedAt = LocalDateTime.now();
this.fileStates = new ConcurrentHashMap<>();
}
public void updateLastAccessed() {
this.lastAccessedAt = LocalDateTime.now();
}
@Data
public static class FileUploadState {
private String fileName;
private int totalChunks;
private Map<Integer, Boolean> receivedChunks;
private Path targetPath;
public FileUploadState(String fileName, int totalChunks, Path targetPath) {
this.fileName = fileName;
this.totalChunks = totalChunks;
this.targetPath = targetPath;
this.receivedChunks = new ConcurrentHashMap<>();
}
public void markChunkReceived(int chunkIndex) {
receivedChunks.put(chunkIndex, true);
}
public boolean isComplete() {
return receivedChunks.size() == totalChunks;
}
public int getReceivedChunkCount() {
return receivedChunks.size();
}
}
}