Skip to content

Commit

Permalink
NCL-6600 Update DA version to use latest or lookup API
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Jun 16, 2021
1 parent eb30630 commit a4a23aa
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void checkDependencies()
+ "org.hamcrest:hamcrest-all:1.3 jar test \n"
+ "org.jacoco:jacoco-maven-plugin:0.8[.\\d+]+\\s+ maven-plugin \n"
+ "org.jboss.byteman:byteman-bmunit:4[.\\d+]+\\s+ jar test \n"
+ "org.jboss.da:reports-model:2.1.0.Api-1 jar compile \n"
+ "org.jboss.da:reports-model:2.1.0.Api-[.\\d+]+\\s+ jar compile \n"
+ "org.jdom:jdom:1.1.3 jar compile \n"
+ "org.projectlombok:lombok:1.[.\\d+]+\\s+ jar provided \n"
+ "org.projectlombok:lombok-maven-plugin:1.[.\\d+]+\\s+ maven-plugin \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,36 @@
*/
package org.commonjava.maven.ext.common.json;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import org.commonjava.maven.atlas.ident.ref.ProjectVersionRef;
import org.goots.hiderdoclet.doclet.JavadocExclude;
import org.jboss.da.lookup.model.MavenLookupResult;
import org.jboss.da.model.rest.GAV;

@Setter
@Getter
@EqualsAndHashCode(callSuper = true)
@JavadocExclude
public class ExtendedMavenLookupResult
extends MavenLookupResult
@EqualsAndHashCode(exclude = "projectVersionRef")
@NoArgsConstructor
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class DependencyAnalyserResult
{
@NonNull
@JsonUnwrapped
private GAV gav;

@JsonIgnore
private ProjectVersionRef projectVersionRef;

public ExtendedMavenLookupResult(@NonNull GAV gav, String bestMatchVersion )
{
super( gav, bestMatchVersion );
}
private String latestVersion;

@Override
public String toString ()
{
return "PVR : " + projectVersionRef + " ; BestMatch : " + getBestMatchVersion();
}
private String bestMatchVersion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
import kong.unirest.jackson.JacksonObjectMapper;
import org.commonjava.maven.atlas.ident.ref.ProjectVersionRef;
import org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef;
import org.commonjava.maven.ext.common.json.ExtendedMavenLookupResult;
import org.commonjava.maven.ext.common.json.DependencyAnalyserResult;
import org.commonjava.maven.ext.common.json.PME;
import org.goots.hiderdoclet.doclet.JavadocExclude;
import org.jboss.da.lookup.model.MavenLookupResult;
import org.jboss.da.model.rest.GAV;

import java.io.File;
Expand All @@ -45,7 +44,8 @@ public class JSONUtils
private static final String GROUP_ID = "groupId";
private static final String ARTIFACT_ID = "artifactId";
private static final String VERSION = "version";
private static final String BEST_MATCH = "bestMatchVersion";
private static final String BEST_MATCH_VERSION = "bestMatchVersion";
private static final String LATEST_VERSION = "latestVersion";

private static final ObjectMapper MAPPER = new ObjectMapper();

Expand Down Expand Up @@ -114,32 +114,36 @@ public void serialize( ProjectVersionRef value, JsonGenerator gen, SerializerPro
}

@JavadocExclude
public static class MavenLookupResultDeserializer extends JsonDeserializer<MavenLookupResult>
public static class MavenResultDeserializer extends JsonDeserializer<DependencyAnalyserResult>
{
@Override
public ExtendedMavenLookupResult deserialize( JsonParser p, DeserializationContext ctxt)
public DependencyAnalyserResult deserialize( JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonNode node = p.getCodec().readTree( p);
final String groupId = node.get(GROUP_ID).asText();
final String artifactId = node.get( ARTIFACT_ID ).asText();
final String version = node.get( VERSION ).asText();

ExtendedMavenLookupResult result;
DependencyAnalyserResult result = new DependencyAnalyserResult();
result.setGav( new GAV( groupId, artifactId, version ) );

String bestMatch = null;
if ( node.has( BEST_MATCH ) && !node.get( BEST_MATCH ).getNodeType().equals( JsonNodeType.NULL ) )
if ( node.has( BEST_MATCH_VERSION ) && !node.get( BEST_MATCH_VERSION ).getNodeType().equals( JsonNodeType.NULL ) )
{
bestMatch = node.get( BEST_MATCH ).asText();
result.setBestMatchVersion( node.get( BEST_MATCH_VERSION ).asText() );
}
if ( node.has( LATEST_VERSION ) && !node.get( LATEST_VERSION ).getNodeType().equals( JsonNodeType.NULL ) )
{
result.setLatestVersion( node.get( LATEST_VERSION ).asText() );
}

result = new ExtendedMavenLookupResult( new GAV( groupId, artifactId, version ), bestMatch );
result.setProjectVersionRef( new SimpleProjectVersionRef( groupId, artifactId, version ) );

return result;
}
}


@JavadocExclude
public static class InternalObjectMapper extends JacksonObjectMapper
{
Expand All @@ -154,7 +158,7 @@ public InternalObjectMapper ( ObjectMapper mapper)
SimpleModule module = new SimpleModule();
module.addDeserializer( ProjectVersionRef.class, new ProjectVersionRefDeserializer());
module.addSerializer(ProjectVersionRef.class, new ProjectVersionRefSerializer());
module.addDeserializer( MavenLookupResult.class, new MavenLookupResultDeserializer() );
module.addDeserializer( DependencyAnalyserResult.class, new MavenResultDeserializer() );
mapper.registerModule( module );

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import org.apache.http.HttpStatus;
import org.commonjava.maven.atlas.ident.ref.ProjectVersionRef;
import org.commonjava.maven.ext.common.ManipulationUncheckedException;
import org.commonjava.maven.ext.common.json.DependencyAnalyserResult;
import org.commonjava.maven.ext.common.json.ErrorMessage;
import org.commonjava.maven.ext.common.json.ExtendedMavenLookupResult;
import org.commonjava.maven.ext.common.util.GAVUtils;
import org.commonjava.maven.ext.common.util.JSONUtils.InternalObjectMapper;
import org.commonjava.maven.ext.common.util.ListUtils;
import org.jboss.da.lookup.model.MavenLatestRequest;
import org.jboss.da.lookup.model.MavenLookupRequest;
import org.jboss.da.lookup.model.MavenLookupResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -54,7 +54,7 @@
public class DefaultTranslator
implements Translator
{
private static final GenericType<List<MavenLookupResult>> lookupType = new GenericType<List<MavenLookupResult>>()
private static final GenericType<List<DependencyAnalyserResult>> lookupType = new GenericType<List<DependencyAnalyserResult>>()
{
};

Expand Down Expand Up @@ -107,8 +107,11 @@ public enum ENDPOINT {
* @param restMaxSize initial (maximum) size of the rest call; if zero will send everything.
* @param restMinSize minimum size for the call
* @param brewPullActive flag saying if brew pull should be used for version retrieval
* @param mode lookup mode, either STANDARD (default if empty) or SERVICE
* @param mode lookup mode, either PERSISTENT, TEMPORARY, SERVICE or SERVICE-TEMPORARY
* @param restHeaders the headers to pass to the endpoint
* @param restConnectionTimeout the timeout for the REST request; defaults to {@link Translator#DEFAULT_CONNECTION_TIMEOUT_SEC}
* @param restSocketTimeout the timeout for the REST socket calls; defaults to {@link Translator#DEFAULT_SOCKET_TIMEOUT_SEC}
* @param restRetryDuration the retry duration configuration; ; defaults to {@link Translator#RETRY_DURATION_SEC}
*/
public DefaultTranslator( String endpointUrl, int restMaxSize, int restMinSize, Boolean brewPullActive, String mode,
Map<String, String> restHeaders, int restConnectionTimeout, int restSocketTimeout,
Expand Down Expand Up @@ -177,8 +180,7 @@ public Map<ProjectVersionRef, String> lookupVersions( List<ProjectVersionRef> p
@Override
public Map<ProjectVersionRef, String> lookupProjectVersions( List<ProjectVersionRef> p ) throws RestException
{
// TODO: ### Change to LOOKUP_LATEST
return internalLookup( ENDPOINT.LOOKUP_GAVS, p );
return internalLookup( ENDPOINT.LOOkUP_LATEST, p );
}

private void partition( ENDPOINT endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
Expand Down Expand Up @@ -362,23 +364,22 @@ private class Task

void executeTranslate()
{
HttpResponse<List<MavenLookupResult>> r;
HttpResponse<List<DependencyAnalyserResult>> r;

try
{
// TODO: Change to this to the new type from DA
Object request = endpointType == ENDPOINT.LOOKUP_GAVS ?
final boolean lookup = (endpointType == ENDPOINT.LOOKUP_GAVS);
Object request = lookup ?
( MavenLookupRequest
.builder()
.mode( mode )
.brewPullActive( brewPullActive )
.artifacts( GAVUtils.generateGAVs( chunk ) )
.build() )
:
( MavenLookupRequest
( MavenLatestRequest
.builder()
.mode( mode )
.brewPullActive( brewPullActive )
.artifacts( GAVUtils.generateGAVs( chunk ) )
.build() );

Expand All @@ -390,15 +391,14 @@ void executeTranslate()
.connectTimeout(restConnectionTimeout * 1000)
.socketTimeout(restSocketTimeout * 1000)
.body( request )
// TODO: #### Change this to add the new DA lookup type differentiation
.asObject( lookupType )
.asObject( lookupType )
.ifSuccess( successResponse -> result = successResponse.getBody()
.stream()
.filter( f -> isNotBlank( f.getBestMatchVersion() ) )
.filter( f -> lookup ? isNotBlank( f.getBestMatchVersion() ) : isNotBlank( f.getLatestVersion() ) )
.collect(
Collectors.toMap(
e -> ( (ExtendedMavenLookupResult) e ).getProjectVersionRef(),
MavenLookupResult::getBestMatchVersion,
DependencyAnalyserResult::getProjectVersionRef,
lookup ? DependencyAnalyserResult::getBestMatchVersion : DependencyAnalyserResult::getLatestVersion,
// If there is a duplicate key, use the original.
(o, n) -> {
logger.warn( "Located duplicate key {}", o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.jboss.da.lookup.model.MavenLatestResult;
import org.jboss.da.lookup.model.MavenLookupRequest;
import org.jboss.da.lookup.model.MavenLookupResult;
import org.jboss.da.model.rest.GAV;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void handle( String target, Request baseRequest, HttpServletRequest reque

Set<GAV> requestBody;

List<MavenLookupResult> responseBody = new ArrayList<>();
List<Object> responseBody = new ArrayList<>();

// Protocol analysis
MavenLookupRequest lookupGAVsRequest = objectMapper.readValue( jb.toString(), MavenLookupRequest.class );
Expand All @@ -130,7 +131,7 @@ public void handle( String target, Request baseRequest, HttpServletRequest reque
// Prepare Response
for ( GAV gav : requestBody )
{
MavenLookupResult lr;
Object lr;

String version = gav.getVersion();
String bestMatchVersion;
Expand Down Expand Up @@ -225,7 +226,14 @@ else if ( gav.getVersion().equals("2.7.2_3-fuse") )
}
logger.info( "For GA {}, requesting version {} and got bestMatch {}", gav, version, bestMatchVersion);

lr = new MavenLookupResult( gav, !returnNullBestMatch ? bestMatchVersion : null );
if (request.getPathInfo().contains( DefaultTranslator.ENDPOINT.LOOkUP_LATEST.getEndpoint() ) )
{
lr = new MavenLatestResult( gav, !returnNullBestMatch ? bestMatchVersion : null );
}
else
{
lr = new MavenLookupResult( gav, !returnNullBestMatch ? bestMatchVersion : null );
}

responseBody.add( lr );
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

<mavenVersion>3.5.0</mavenVersion>
<atlasVersion>0.17.1</atlasVersion>
<daVersion>2.1.0.Api-1</daVersion>
<daVersion>2.1.0.Api-2</daVersion>
<galleyVersion>0.16.6</galleyVersion>

<groovyVersion>3.0.7</groovyVersion>
Expand Down

0 comments on commit a4a23aa

Please sign in to comment.