Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from main branch #139

Merged
merged 14 commits into from
Feb 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/merge-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service)
# Copyright (C) 2022-2023 Red Hat, Inc. (https://github.com/Commonjava/indy-repository-service)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service)
# Copyright (C) 2022-2023 Red Hat, Inc. (https://github.com/Commonjava/indy-repository-service)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
23 changes: 14 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.14.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.infinispan</groupId>-->
<!-- <artifactId>infinispan-core</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-component-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
Expand Down Expand Up @@ -265,6 +265,16 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
Expand All @@ -280,11 +290,6 @@
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interpolation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.commonjava.event.common.EventMetadata;
import org.commonjava.indy.service.repository.audit.ChangeSummary;
Expand All @@ -32,17 +35,18 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import static java.util.Map.of;
Expand Down Expand Up @@ -96,35 +100,40 @@ public File getRepoBundle()
public Map<String, List<String>> importRepoBundle( final InputStream zipStream )
throws IOException
{
File tempRepoZip = createTempFile();
logger.info( "Saving repo file to {}", tempRepoZip.getPath() );
try (zipStream)
{
try (OutputStream out = new FileOutputStream( tempRepoZip ))
{
IOUtils.copy( zipStream, out );
}
}

final List<String> skipped = new ArrayList<>();
final List<String> failed = new ArrayList<>();
final Map<String, String> payload = new HashMap<>();
logger.info( "Start extracting repos definitions from bundle!" );
try (ZipInputStream zip = new ZipInputStream( zipStream ))

try (ZipFile zipFile = ZipFile.builder().setFile( tempRepoZip ).get())
{
if ( zip.available() > 0 )
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
while ( entries.hasMoreElements() )
{
ZipEntry entry = zip.getNextEntry();
while ( entry != null )
ZipArchiveEntry entry = entries.nextElement();
if ( !entry.isDirectory() )
{
if ( !entry.isDirectory() )
try (InputStream in = zipFile.getInputStream( entry ))
{
logger.debug( "Processing {}", entry.getName() );
byte[] buffer = new byte[2048];
final StringBuilder builder = new StringBuilder();
while ( zip.read( buffer ) > 0 )
{
builder.append( new String( buffer, Charset.defaultCharset() ) );
buffer = new byte[2048];
}

payload.put( entry.getName(), builder.toString().trim() );

payload.put( entry.getName(), IOUtils.toString( in, Charset.defaultCharset() ) );
}
entry = zip.getNextEntry();
}
}
}
finally
{
FileUtils.deleteQuietly( tempRepoZip );
}

logger.info( "Repos definitions extraction from bundle finished.\n\n" );
logger.info( "Start importing repos definitions to data store." );
for ( Map.Entry<String, String> entry : payload.entrySet() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.commonjava.indy.service.repository.model.RemoteRepository;
import org.commonjava.indy.service.repository.model.StoreKey;
import org.commonjava.indy.service.repository.model.StoreType;
import org.commonjava.indy.service.repository.model.dto.EndpointView;
import org.commonjava.indy.service.repository.model.dto.EndpointViewListing;
import org.commonjava.indy.service.repository.util.JaxRsUriFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,8 +37,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -82,7 +87,7 @@ public List<ArtifactStore> getAllArtifactStores( final String packageType, final
// when packageType and type are all unique value, use storeManager.getArtifactStoresByPkgAndType to improve performance
stores = storeManager.getArtifactStoresByPkgAndType( packageType, typeList.get( 0 ) );
}
else if ( !isValidPackageType( packageType ) && typeList.size() == 0 )
else if ( !isValidPackageType( packageType ) && typeList.isEmpty() )
{
stores = storeManager.getAllArtifactStores();
}
Expand Down Expand Up @@ -251,6 +256,76 @@ public Boolean isStoreDataEmpty()
return storeManager.isEmpty();
}

public EndpointViewListing getEndpointsListing( final String pkgType, final String baseUri,
final JaxRsUriFormatter uriFormatter )
throws IndyWorkflowException
{
List<ArtifactStore> stores;
try
{
stores = new ArrayList<>( storeManager.getAllArtifactStores() );
if ( StringUtils.isNotBlank( pkgType ) && !"all".equals( pkgType ) && isValidPackageType( pkgType ) )
{
stores = stores.stream()
.filter( s -> pkgType.equals( s.getPackageType() ) )
.collect( Collectors.toList() );
}
}
catch ( final IndyDataException e )
{
throw new IndyWorkflowException( INTERNAL_SERVER_ERROR.getStatusCode(),
"Failed to retrieve all endpoints: {}", e, e.getMessage() );
}

final List<EndpointView> points = new ArrayList<>();
for ( final ArtifactStore store : stores )
{
final StoreKey key = store.getKey();
final String resourceUri = uriFormatter.formatAbsolutePathTo( baseUri, "content", key.getPackageType(),
key.getType().singularEndpointName(),
key.getName() );

final EndpointView point = new EndpointView( store, resourceUri );
if ( !points.contains( point ) )
{
points.add( point );
}
}

return new EndpointViewListing( points );
}

public Map<String, List<String>> getStoreKeysByPackageType( final String pkgType )
throws IndyWorkflowException
{
final List<ArtifactStore> stores;

try
{
final Map<String, List<String>> result = new HashMap<>();
stores = new ArrayList<>( storeManager.getAllArtifactStores() );
List<String> items;
if ( StringUtils.isNotBlank( pkgType ) && !"all".equals( pkgType ) && isValidPackageType( pkgType ) )
{
items = stores.stream()
.filter( s -> pkgType.equals( s.getPackageType() ) )
.map( s -> s.getKey().toString() )
.collect( Collectors.toList() );
}
else
{
items = stores.stream().map( s -> s.getKey().toString() ).collect( Collectors.toList() );
}
result.put( "items", items );
return result;
}
catch ( final IndyDataException e )
{
throw new IndyWorkflowException( INTERNAL_SERVER_ERROR.getStatusCode(),
"Failed to retrieve all store keys: {}", e, e.getMessage() );
}
}

private StoreKey validateStoreKey( final String storeKey )
throws IndyWorkflowException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import org.commonjava.indy.service.repository.model.dto.EndpointView;
import org.commonjava.indy.service.repository.model.dto.EndpointViewListing;
import org.commonjava.indy.service.repository.model.version.Versioning;
import org.commonjava.indy.service.repository.util.JaxRsUriFormatter;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.commonjava.indy.service.repository.util.JaxRsUriFormatter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.spi.HttpRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,10 +36,11 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.MediaType;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -99,13 +99,13 @@ public Response getRepoBundle()
@APIResponse( responseCode = "200", description = "All repository definitions which are imported successfully." )
@POST
@Path( "/import" )
@Consumes( MEDIATYPE_APPLICATION_ZIP )
@Consumes( MediaType.MULTIPART_FORM_DATA )
@Produces( APPLICATION_JSON )
public Response importRepoBundle( @Context final HttpRequest request )
public Response importRepoBundle( InputStream input )
{
try
{
Map<String, List<String>> results = maintController.importRepoBundle( request.getInputStream() );
Map<String, List<String>> results = maintController.importRepoBundle( input );
return ok( results ).build();
}
catch ( IOException e )
Expand Down
Loading
Loading