Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,29 @@ public void cleanupBCWorkspace( String buildConfigId )
}
}

public File createTestArchive( final String archiveName ) throws IOException
{
File targetDir = new File( archiveDir );
targetDir.mkdirs();

final File archiveFile = new File( archiveDir, archiveName + ARCHIVE_SUFFIX );
logger.info( "Creating test archive: '{}'", archiveFile.getAbsolutePath() );

try ( ZipOutputStream zip = new ZipOutputStream( new FileOutputStream( archiveFile ) ) )
{
// Add a test file to the zip
ZipEntry entry = new ZipEntry( "test-file.txt" );
zip.putNextEntry( entry );

String testContent = "this is a test";
zip.write( testContent.getBytes() );
zip.closeEntry();
}

logger.info( "Test archive created successfully: '{}'", archiveFile.getAbsolutePath() );
return archiveFile;
}

public boolean statusExists( final String buildConfigId )
{
return treated.containsKey( buildConfigId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
Expand Down Expand Up @@ -213,7 +218,7 @@ public Uni<Response> deleteWithChecksum( final @PathParam( "buildConfigId" ) Str
@APIResponse( responseCode = "204", description = "The workplace cleanup is finished" )
@Path( "cleanup" )
@DELETE
public Uni<Response> delete( final @Context UriInfo uriInfo )
public Uni<Response> cleanup( final @Context UriInfo uriInfo )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the rename also related ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related. claude did it. I found it after the push, I guess we can use it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to me.

{
try
{
Expand All @@ -227,4 +232,41 @@ public Uni<Response> delete( final @Context UriInfo uriInfo )
}
return Uni.createFrom().item( noContent().build() );
}

@Operation( description = "Create a test archive with timestamp suffix for testing purposes" )
@APIResponse( responseCode = "200", description = "Test archive created successfully" )
@APIResponse( responseCode = "500", description = "Failed to create test archive - directory may not be writable" )
@POST
@Path( "test" )
@Produces( APPLICATION_JSON )
public Uni<Response> createTestArchive( final @Context UriInfo uriInfo )
{
try
{
String timestamp = LocalDateTime.now().format( DateTimeFormatter.ofPattern( "yyyyMMdd-HHmmss" ) );
String testArchiveName = "test-archive-" + timestamp;

File archiveFile = controller.createTestArchive( testArchiveName );

String message = String.format( "Test archive created successfully: %s.zip", testArchiveName );
logger.info( message );

return Uni.createFrom().item( Response.ok()
.type( MediaType.APPLICATION_JSON )
.entity( String.format( "{\"message\":\"%s\",\"archiveName\":\"%s.zip\"}",
message, testArchiveName ) )
.build() );
}
catch ( final IOException e )
{
final String message = "Failed to create test archive: " + e.getMessage();
logger.error( message, e );
return Uni.createFrom().item( Response.status( Response.Status.INTERNAL_SERVER_ERROR )
.type( MediaType.APPLICATION_JSON )
.entity( String.format( "{\"error\":\"%s\",\"exceptionType\":\"%s\"}",
message.replace("\"", "\\\""),
e.getClass().getSimpleName() ) )
.build() );
}
}
}