Try out chunking
This commit is contained in:
26
src/main/java/com/cfdeployer/model/ChunkUploadRequest.java
Normal file
26
src/main/java/com/cfdeployer/model/ChunkUploadRequest.java
Normal 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;
|
||||
}
|
||||
41
src/main/java/com/cfdeployer/model/ChunkUploadResponse.java
Normal file
41
src/main/java/com/cfdeployer/model/ChunkUploadResponse.java
Normal 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();
|
||||
}
|
||||
}
|
||||
61
src/main/java/com/cfdeployer/model/UploadSession.java
Normal file
61
src/main/java/com/cfdeployer/model/UploadSession.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user