Skip to content

Commit

Permalink
Separate repository services from projects
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-gunjan committed Jul 27, 2023
1 parent 977e18b commit a2b717d
Show file tree
Hide file tree
Showing 25 changed files with 257 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package org.finos.legend.depot.store.artifacts.purge.services;

import org.finos.legend.depot.artifacts.repository.domain.ArtifactType;
import org.finos.legend.depot.artifacts.repository.services.RepositoryServices;
import org.finos.legend.depot.domain.VersionedData;
import org.finos.legend.depot.domain.api.MetadataEventResponse;
import org.finos.legend.depot.domain.project.ProjectVersion;
import org.finos.legend.depot.domain.project.StoreProjectData;
import org.finos.legend.depot.domain.project.StoreProjectVersionData;
import org.finos.legend.depot.services.VersionsRepositoryService;
import org.finos.legend.depot.services.api.projects.ManageProjectsService;
import org.finos.legend.depot.store.artifacts.api.ProjectArtifactsHandler;
import org.finos.legend.depot.store.artifacts.purge.api.ArtifactsPurgeService;
Expand Down Expand Up @@ -60,15 +60,15 @@ public class ArtifactsPurgeServiceImpl implements ArtifactsPurgeService
private static final String EVICT_OLDEST = "evict_old";

private final ManageProjectsService projects;
private final RepositoryServices repository;
private final VersionsRepositoryService repositoryService;
private final QueryMetricsHandler metrics;

@Inject
public ArtifactsPurgeServiceImpl(ManageProjectsService projects, RepositoryServices repository, QueryMetricsHandler metrics)
public ArtifactsPurgeServiceImpl(ManageProjectsService projects, VersionsRepositoryService repositoryService, QueryMetricsHandler metrics)
{
this.projects = projects;
this.metrics = metrics;
this.repository = repository;
this.repositoryService = repositoryService;
}


Expand Down Expand Up @@ -155,7 +155,7 @@ public MetadataEventResponse deprecate(String groupId, String artifactId, String
public MetadataEventResponse deprecateVersionsNotInRepository()
{
MetadataEventResponse response = new MetadataEventResponse();
repository.findVersionsMismatches().parallelStream().forEach(versionMismatch ->
repositoryService.findVersionsMismatches().parallelStream().forEach(versionMismatch ->
{
if (!versionMismatch.versionsNotInRepository.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

import org.finos.legend.depot.artifacts.repository.api.ArtifactRepository;
import org.finos.legend.depot.artifacts.repository.domain.ArtifactType;
import org.finos.legend.depot.artifacts.repository.domain.VersionMismatch;
import org.finos.legend.depot.artifacts.repository.services.RepositoryServices;
import org.finos.legend.depot.domain.version.VersionMismatch;
import org.finos.legend.depot.domain.DatesHandler;
import org.finos.legend.depot.domain.api.MetadataEventResponse;
import org.finos.legend.depot.domain.project.StoreProjectData;
import org.finos.legend.depot.domain.project.StoreProjectVersionData;
import org.finos.legend.depot.services.VersionsRepositoryService;
import org.finos.legend.depot.services.api.entities.ManageEntitiesService;
import org.finos.legend.depot.services.api.projects.ManageProjectsService;
import org.finos.legend.depot.services.entities.ManageEntitiesServiceImpl;
Expand Down Expand Up @@ -82,9 +82,9 @@ public class TestArtifactsPurgeService extends TestStoreMongo
protected UpdateEntities entitiesStore = new EntitiesMongo(mongoProvider);
protected UpdateFileGenerations fileGenerationsStore = new FileGenerationsMongo(mongoProvider);
protected ArtifactRepository repository = mock(ArtifactRepository.class);
protected RepositoryServices repositoryServices = new RepositoryServices(repository, projectsService);
protected VersionsRepositoryService versionsRepositoryService = new VersionsRepositoryService(repository, projectsService);
protected ManageEntitiesService entitiesService = new ManageEntitiesServiceImpl(entitiesStore, projectsService);
protected ArtifactsPurgeService purgeService = new ArtifactsPurgeServiceImpl(projectsService, repositoryServices, metricHandler);
protected ArtifactsPurgeService purgeService = new ArtifactsPurgeServiceImpl(projectsService, versionsRepositoryService, metricHandler);



Expand Down Expand Up @@ -225,7 +225,7 @@ public void canDeprecateVersionIfNotInRepository()
List<String> versions = projectsService.getVersions(TEST_GROUP_ID,TEST_ARTIFACT_ID);
Assert.assertEquals(versions.size(), 3);
Assert.assertEquals(3, fileGenerationsStore.getAll().size());
when(repositoryServices.findVersionsMismatches()).thenReturn(Collections.singletonList(versionMismatch));
when(versionsRepositoryService.findVersionsMismatches()).thenReturn(Collections.singletonList(versionMismatch));
//deleting the version not present in the repository
purgeService.deprecateVersionsNotInRepository();
versions = projectsService.getVersions(TEST_GROUP_ID,TEST_ARTIFACT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.finos.legend.depot.store.artifacts.resources.ArtifactsRefreshResource;
import org.finos.legend.depot.store.artifacts.resources.DependenciesResource;
import org.finos.legend.depot.store.artifacts.services.ArtifactsRefreshServiceImpl;
import org.finos.legend.depot.store.artifacts.services.DependencyManager;
import org.finos.legend.depot.store.artifacts.services.ProjectVersionRefreshHandler;
import org.finos.legend.depot.store.notifications.api.NotificationEventHandler;
import org.finos.legend.depot.tracing.api.PrometheusMetricsHandler;
Expand All @@ -50,7 +49,6 @@ protected void configure()
bind(ArtifactsRefreshService.class).to(ArtifactsRefreshServiceImpl.class);
bind(NotificationEventHandler.class).to(ProjectVersionRefreshHandler.class);
bind(ProjectVersionRefreshHandler.class);
bind(DependencyManager.class);

expose(ArtifactsRefreshService.class);
expose(NotificationEventHandler.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.finos.legend.depot.core.authorisation.api.AuthorisationProvider;
import org.finos.legend.depot.core.authorisation.resources.BaseAuthorisedResource;
import org.finos.legend.depot.domain.project.StoreProjectVersionData;
import org.finos.legend.depot.store.artifacts.services.DependencyManager;
import org.finos.legend.depot.services.DependencyManager;
import org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing;

import javax.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.finos.legend.depot.domain.CoordinateValidator;
import org.finos.legend.depot.domain.api.MetadataEventResponse;
import org.finos.legend.depot.domain.notifications.MetadataNotification;
import org.finos.legend.depot.services.DependencyManager;
import org.finos.legend.depot.store.artifacts.configuration.IncludeProjectPropertiesConfiguration;
import org.finos.legend.depot.domain.project.ProjectVersion;
import org.finos.legend.depot.domain.project.ProjectVersionData;
Expand Down Expand Up @@ -59,8 +60,7 @@
import java.util.jar.Manifest;
import java.util.stream.Collectors;

import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.REPO_EXCEPTIONS;

import static org.finos.legend.depot.services.VersionsRepositoryService.REPO_EXCEPTIONS;

public final class ProjectVersionRefreshHandler implements NotificationEventHandler
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.finos.legend.depot.domain.api.MetadataEventResponse;
import org.finos.legend.depot.domain.api.status.MetadataEventStatus;
import org.finos.legend.depot.domain.notifications.MetadataNotification;
import org.finos.legend.depot.services.DependencyManager;
import org.finos.legend.depot.store.artifacts.configuration.IncludeProjectPropertiesConfiguration;
import org.finos.legend.depot.domain.project.ProjectVersion;
import org.finos.legend.depot.domain.project.ProjectVersionData;
Expand Down Expand Up @@ -96,7 +97,7 @@ public class TestArtifactsRefreshService extends TestStoreMongo
protected FileGenerationsArtifactsProvider fileGenerationsProvider = new FileGenerationsProvider();
protected ManageEntitiesService entitiesService = new ManageEntitiesServiceImpl(entitiesStore, projectsService);
protected ArtifactRepository repository = new TestMavenArtifactsRepository();
protected RepositoryServices repositoryServices = new RepositoryServices(repository,projectsService);
protected RepositoryServices repositoryServices = new RepositoryServices(repository);
protected DependencyManager dependencyManager = new DependencyManager(projectsService, repositoryServices);

protected ProjectVersionRefreshHandler versionHandler = new ProjectVersionRefreshHandler(projectsService, repositoryServices, queue, artifacts, new IncludeProjectPropertiesConfiguration(properties, manifestProperties), dependencyManager, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class TestArtifactsRefreshServiceExceptionEscenarios extends TestStoreMon
protected UpdateEntities mongoEntities = mock(UpdateEntities.class);
protected ManageEntitiesService entitiesService = new ManageEntitiesServiceImpl(mongoEntities,projectsService);
protected UpdateFileGenerations mongoGenerations = mock(UpdateFileGenerations.class);
protected RepositoryServices repositoryServices = new RepositoryServices(repository,projectsService);
protected RepositoryServices repositoryServices = new RepositoryServices(repository);

protected ArtifactsRefreshService artifactsRefreshService = new ArtifactsRefreshServiceImpl(projectsService, repositoryServices, queue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class TestArtifactsRefreshServiceWithMocks extends TestStoreMongo
protected UpdateEntities mongoEntities = mock(UpdateEntities.class);
protected ManageEntitiesService entitiesService = new ManageEntitiesServiceImpl(mongoEntities,projectsService);
protected UpdateFileGenerations mongoGenerations = mock(UpdateFileGenerations.class);
protected RepositoryServices repositoryServices = new RepositoryServices(repository,projectsService);
protected RepositoryServices repositoryServices = new RepositoryServices(repository);

protected ArtifactsRefreshServiceImpl artifactsRefreshService = new ArtifactsRefreshServiceImpl(projectsService, repositoryServices,queue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.finos.legend.depot.domain.api.MetadataEventResponse;
import org.finos.legend.depot.domain.api.status.MetadataEventStatus;
import org.finos.legend.depot.domain.notifications.MetadataNotification;
import org.finos.legend.depot.services.DependencyManager;
import org.finos.legend.depot.store.artifacts.configuration.IncludeProjectPropertiesConfiguration;
import org.finos.legend.depot.domain.project.StoreProjectData;
import org.finos.legend.depot.domain.project.StoreProjectVersionData;
Expand Down
4 changes: 0 additions & 4 deletions legend-depot-artifacts-repository-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<groupId>org.finos.legend.depot</groupId>
<artifactId>legend-depot-model</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.depot</groupId>
<artifactId>legend-depot-core-services</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.depot</groupId>
<artifactId>legend-depot-core-http</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,11 @@
import org.finos.legend.depot.artifacts.repository.api.VoidArtifactRepositoryProvider;
import org.finos.legend.depot.artifacts.repository.resources.RepositoryResource;
import org.finos.legend.depot.artifacts.repository.services.RepositoryServices;
import org.finos.legend.depot.schedules.services.SchedulesFactory;
import org.finos.legend.depot.tracing.api.PrometheusMetricsHandler;
import org.finos.legend.depot.tracing.configuration.PrometheusConfiguration;
import org.slf4j.Logger;

import javax.inject.Named;

import java.util.Arrays;

import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.MISSING_REPO_VERSIONS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.MISSING_STORE_VERSIONS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.PROJECTS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.REPO_EXCEPTIONS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.REPO_VERSIONS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.STORE_VERSIONS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.EXCLUDED_VERSIONS;
import static org.finos.legend.depot.artifacts.repository.services.RepositoryServices.EVICTED_VERSIONS;

public class RepositoryModule extends PrivateModule
{
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(RepositoryModule.class);
private static final String REPOSITORY_METRICS_SCHEDULE = "repository-metrics-schedule";

@Override
protected void configure()
Expand Down Expand Up @@ -73,23 +56,4 @@ public ArtifactRepository getArtifactRepository(ArtifactRepositoryProviderConfig
LOGGER.info("Using void Artifact Repository provider, artifacts cant/wont be updated");
return new VoidArtifactRepositoryProvider(configuration);
}

@Provides
@Named("repository-metrics")
@Singleton
boolean registerMetrics(PrometheusConfiguration prometheusConfiguration,SchedulesFactory schedulesFactory,RepositoryServices repositoryServices)
{
if (prometheusConfiguration.isEnabled())
{
PrometheusMetricsHandler metricsHandler = prometheusConfiguration.getMetricsHandler();
metricsHandler.registerGauge(PROJECTS, PROJECTS);
metricsHandler.registerGauge(REPO_VERSIONS, REPO_VERSIONS);
metricsHandler.registerGauge(STORE_VERSIONS, STORE_VERSIONS);
metricsHandler.registerGauge(MISSING_REPO_VERSIONS, MISSING_REPO_VERSIONS);
metricsHandler.registerGauge(MISSING_STORE_VERSIONS, MISSING_STORE_VERSIONS);
metricsHandler.registerGauge(REPO_EXCEPTIONS, REPO_EXCEPTIONS);
schedulesFactory.register(REPOSITORY_METRICS_SCHEDULE, 5 * SchedulesFactory.MINUTE, 5 * SchedulesFactory.MINUTE, repositoryServices::findVersionsMismatches);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.swagger.annotations.ApiParam;
import org.finos.legend.depot.artifacts.repository.api.ArtifactRepository;
import org.finos.legend.depot.artifacts.repository.api.ArtifactRepositoryException;
import org.finos.legend.depot.artifacts.repository.domain.VersionMismatch;
import org.finos.legend.depot.artifacts.repository.services.RepositoryServices;
import org.finos.legend.depot.tracing.resources.BaseResource;
import org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing;
Expand Down Expand Up @@ -91,14 +90,4 @@ public Optional<String> getRepositoryVersion(@PathParam("groupId") String groupI
});
}

@GET
@Path("/repository/versions/mismatch")
@ApiOperation(ResourceLoggingAndTracing.GET_PROJECT_CACHE_MISMATCHES)
@Produces(MediaType.APPLICATION_JSON)
public List<VersionMismatch> getVersionMissMatches()
{
return handle(ResourceLoggingAndTracing.GET_PROJECT_CACHE_MISMATCHES, () -> this.repositoryServices.findVersionsMismatches());
}


}
Loading

0 comments on commit a2b717d

Please sign in to comment.