Skip to content

Commit

Permalink
Construct *ApiImpl instead of injecting the V1 rest instances
Browse files Browse the repository at this point in the history
The change #9553 has to pass an additional parameter depending on the "receiving API" to the `*ApiImpl` types, which is quite complex to implement with CDI. Therefore this change removes the old `Rest*Service` types and constructs the `*ApiImpl` types directly.
  • Loading branch information
snazy committed Sep 19, 2024
1 parent 3bea155 commit aa8db80
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 256 deletions.
1 change: 1 addition & 0 deletions catalog/service/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation(project(":nessie-versioned-storage-common"))
implementation(project(":nessie-model"))
implementation(project(":nessie-services"))
implementation(project(":nessie-services-config"))
implementation(project(":nessie-versioned-spi"))
implementation(project(":nessie-tasks-api"))
implementation(project(":nessie-tasks-service-async"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@
import org.projectnessie.model.GetMultipleContentsResponse;
import org.projectnessie.model.Reference;
import org.projectnessie.nessie.tasks.api.TasksService;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.services.impl.ContentApiImpl;
import org.projectnessie.services.impl.TreeApiImpl;
import org.projectnessie.services.spi.ContentService;
import org.projectnessie.services.spi.TreeService;
import org.projectnessie.storage.uri.StorageUri;
import org.projectnessie.versioned.VersionStore;
import org.projectnessie.versioned.storage.common.persist.ObjId;
import org.projectnessie.versioned.storage.common.persist.Persist;
import org.slf4j.Logger;
Expand All @@ -116,18 +122,34 @@ public class CatalogServiceImpl implements CatalogService {
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogServiceImpl.class);

@Inject ObjectIO objectIO;
@Inject TreeService treeService;
@Inject ContentService contentService;
TreeService treeService;
ContentService contentService;
CatalogConfig catalogConfig;
@Inject Persist persist;
@Inject TasksService tasksService;
@Inject BackendExceptionMapper backendExceptionMapper;
@Inject CatalogConfig catalogConfig;
@Inject ServiceConfig serviceConfig;

@Inject
@Named("import-jobs")
Executor executor;

public CatalogServiceImpl() {
this(null, null, null, null, null);
}

@Inject
public CatalogServiceImpl(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
this.catalogConfig = catalogConfig;
this.treeService = new TreeApiImpl(serverConfig, store, authorizer, accessContext);
this.contentService = new ContentApiImpl(serverConfig, store, authorizer, accessContext);
}

private IcebergStuff icebergStuff() {
return new IcebergStuff(
objectIO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.authz.BatchAccessChecker;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.services.impl.ConfigApiImpl;
import org.projectnessie.services.impl.ContentApiImpl;
import org.projectnessie.services.impl.DiffApiImpl;
import org.projectnessie.services.impl.TreeApiImpl;
import org.projectnessie.services.rest.RestV2ConfigResource;
import org.projectnessie.services.rest.RestV2TreeResource;
import org.projectnessie.services.spi.ConfigService;
import org.projectnessie.services.spi.DiffService;
import org.projectnessie.versioned.VersionStore;
import org.projectnessie.versioned.storage.common.persist.Persist;
import org.projectnessie.versioned.storage.testextension.NessiePersist;
Expand Down Expand Up @@ -270,16 +266,12 @@ public boolean sendStacktraceToClient() {
VersionStore versionStore = new VersionStoreImpl(persist);
Authorizer authorizer = context -> batchAccessCheckerFactory.apply(context);
AccessContext accessContext = () -> () -> null;
ConfigService configService =
new ConfigApiImpl(config, versionStore, authorizer, accessContext, 2);

treeService = new TreeApiImpl(config, versionStore, authorizer, accessContext);
contentService = new ContentApiImpl(config, versionStore, authorizer, accessContext);
DiffService diffService = new DiffApiImpl(config, versionStore, authorizer, accessContext);

RestV2TreeResource treeResource =
new RestV2TreeResource(
configService, treeService, contentService, diffService, emptyHttpHeaders());
new RestV2TreeResource(config, versionStore, authorizer, accessContext, emptyHttpHeaders());
RestV2ConfigResource configResource =
new RestV2ConfigResource(config, versionStore, authorizer, accessContext);
api =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
import org.projectnessie.catalog.formats.iceberg.rest.IcebergConfigResponse;
import org.projectnessie.catalog.service.api.CatalogCommit;
import org.projectnessie.catalog.service.api.SnapshotReqParams;
import org.projectnessie.catalog.service.config.CatalogConfig;
import org.projectnessie.catalog.service.rest.IcebergErrorMapper.IcebergEntityKind;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.versioned.VersionStore;

/**
* Handles Iceberg REST API v1 endpoints that are not strongly associated with a particular entity
Expand All @@ -58,6 +63,20 @@ public class IcebergApiV1GenericResource extends IcebergApiV1ResourceBase {
@Inject IcebergConfigurer icebergConfigurer;
@Inject IcebergErrorMapper errorMapper;

public IcebergApiV1GenericResource() {
this(null, null, null, null, null);
}

@Inject
public IcebergApiV1GenericResource(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
super(serverConfig, catalogConfig, store, authorizer, accessContext);
}

@ServerExceptionMapper
public Response mapException(Exception ex) {
return errorMapper.toResponse(ex, IcebergEntityKind.UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.projectnessie.catalog.formats.iceberg.rest.IcebergListNamespacesResponse;
import org.projectnessie.catalog.formats.iceberg.rest.IcebergUpdateNamespacePropertiesRequest;
import org.projectnessie.catalog.formats.iceberg.rest.IcebergUpdateNamespacePropertiesResponse;
import org.projectnessie.catalog.service.config.CatalogConfig;
import org.projectnessie.catalog.service.config.WarehouseConfig;
import org.projectnessie.catalog.service.rest.IcebergErrorMapper.IcebergEntityKind;
import org.projectnessie.error.NessieContentNotFoundException;
Expand All @@ -70,8 +71,12 @@
import org.projectnessie.model.Namespace;
import org.projectnessie.model.Operations;
import org.projectnessie.model.Reference;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.services.spi.PagedResponseHandler;
import org.projectnessie.storage.uri.StorageUri;
import org.projectnessie.versioned.VersionStore;

/** Handles Iceberg REST API v1 endpoints that are associated with namespaces. */
@RequestScoped
Expand All @@ -82,6 +87,20 @@ public class IcebergApiV1NamespaceResource extends IcebergApiV1ResourceBase {

@Inject IcebergErrorMapper errorMapper;

public IcebergApiV1NamespaceResource() {
this(null, null, null, null, null);
}

@Inject
public IcebergApiV1NamespaceResource(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
super(serverConfig, catalogConfig, store, authorizer, accessContext);
}

@ServerExceptionMapper
public Response mapException(Exception ex) {
return errorMapper.toResponse(ex, IcebergEntityKind.NAMESPACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import com.google.common.base.Splitter;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import java.io.IOException;
import java.net.URI;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -70,17 +69,34 @@
import org.projectnessie.model.Operations;
import org.projectnessie.model.Reference;
import org.projectnessie.model.TableReference;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.services.impl.ContentApiImpl;
import org.projectnessie.services.impl.TreeApiImpl;
import org.projectnessie.services.spi.ContentService;
import org.projectnessie.services.spi.PagedCountingResponseHandler;
import org.projectnessie.services.spi.TreeService;
import org.projectnessie.versioned.VersionStore;

abstract class IcebergApiV1ResourceBase extends AbstractCatalogResource {

@Inject TreeService treeService;
@Inject ContentService contentService;
@Inject ServerConfig serverConfig;
@Inject CatalogConfig catalogConfig;
final TreeService treeService;
final ContentService contentService;
final ServerConfig serverConfig;
final CatalogConfig catalogConfig;

protected IcebergApiV1ResourceBase(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
this.serverConfig = serverConfig;
this.catalogConfig = catalogConfig;
this.treeService = new TreeApiImpl(serverConfig, store, authorizer, accessContext);
this.contentService = new ContentApiImpl(serverConfig, store, authorizer, accessContext);
}

protected Stream<EntriesResponse.Entry> listContent(
NamespaceRef namespaceRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@
import org.projectnessie.catalog.formats.iceberg.rest.IcebergS3SignRequest;
import org.projectnessie.catalog.formats.iceberg.rest.IcebergS3SignResponse;
import org.projectnessie.catalog.service.api.SignerKeysService;
import org.projectnessie.catalog.service.config.CatalogConfig;
import org.projectnessie.catalog.service.objtypes.SignerKey;
import org.projectnessie.catalog.service.rest.IcebergErrorMapper.IcebergEntityKind;
import org.projectnessie.model.ContentKey;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.versioned.VersionStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -63,6 +68,20 @@ public class IcebergApiV1S3SignResource extends IcebergApiV1ResourceBase {

Clock clock = Clock.systemUTC();

public IcebergApiV1S3SignResource() {
this(null, null, null, null, null);
}

@Inject
public IcebergApiV1S3SignResource(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
super(serverConfig, catalogConfig, store, authorizer, accessContext);
}

@ServerExceptionMapper
public Response mapException(Exception ex) {
return errorMapper.toResponse(ex, IcebergEntityKind.UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.projectnessie.catalog.service.api.CatalogEntityAlreadyExistsException;
import org.projectnessie.catalog.service.api.SnapshotReqParams;
import org.projectnessie.catalog.service.api.SnapshotResponse;
import org.projectnessie.catalog.service.config.CatalogConfig;
import org.projectnessie.catalog.service.config.WarehouseConfig;
import org.projectnessie.catalog.service.rest.IcebergErrorMapper.IcebergEntityKind;
import org.projectnessie.error.NessieContentNotFoundException;
Expand All @@ -106,7 +107,11 @@
import org.projectnessie.model.Operation.Delete;
import org.projectnessie.model.Operation.Put;
import org.projectnessie.model.Operations;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.storage.uri.StorageUri;
import org.projectnessie.versioned.VersionStore;

/** Handles Iceberg REST API v1 endpoints that are associated with tables. */
@RequestScoped
Expand All @@ -118,6 +123,20 @@ public class IcebergApiV1TableResource extends IcebergApiV1ResourceBase {
@Inject IcebergConfigurer icebergConfigurer;
@Inject IcebergErrorMapper errorMapper;

public IcebergApiV1TableResource() {
this(null, null, null, null, null);
}

@Inject
public IcebergApiV1TableResource(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
super(serverConfig, catalogConfig, store, authorizer, accessContext);
}

@ServerExceptionMapper
public Response mapException(Exception ex) {
return errorMapper.toResponse(ex, IcebergEntityKind.TABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.projectnessie.catalog.formats.iceberg.rest.IcebergUpdateRequirement;
import org.projectnessie.catalog.service.api.SnapshotReqParams;
import org.projectnessie.catalog.service.api.SnapshotResponse;
import org.projectnessie.catalog.service.config.CatalogConfig;
import org.projectnessie.catalog.service.rest.IcebergErrorMapper.IcebergEntityKind;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.model.Branch;
Expand All @@ -70,6 +71,10 @@
import org.projectnessie.model.ImmutableOperations;
import org.projectnessie.model.Operation.Delete;
import org.projectnessie.model.Operations;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.versioned.VersionStore;

/** Handles Iceberg REST API v1 endpoints that are associated with views. */
@RequestScoped
Expand All @@ -80,6 +85,20 @@ public class IcebergApiV1ViewResource extends IcebergApiV1ResourceBase {

@Inject IcebergErrorMapper errorMapper;

public IcebergApiV1ViewResource() {
this(null, null, null, null, null);
}

@Inject
public IcebergApiV1ViewResource(
ServerConfig serverConfig,
CatalogConfig catalogConfig,
VersionStore store,
Authorizer authorizer,
AccessContext accessContext) {
super(serverConfig, catalogConfig, store, authorizer, accessContext);
}

@ServerExceptionMapper
public Response mapException(Exception ex) {
return errorMapper.toResponse(ex, IcebergEntityKind.VIEW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import org.projectnessie.api.v1.http.HttpConfigApi;
import org.projectnessie.model.NessieConfiguration;
import org.projectnessie.model.ser.Views;
import org.projectnessie.services.authz.AccessContext;
import org.projectnessie.services.authz.Authorizer;
import org.projectnessie.services.config.ServerConfig;
import org.projectnessie.services.impl.ConfigApiImpl;
import org.projectnessie.services.spi.ConfigService;
import org.projectnessie.versioned.VersionStore;

/** REST endpoint to retrieve server settings. */
@RequestScoped
Expand All @@ -33,12 +38,13 @@ public class RestConfigResource implements HttpConfigApi {

// Mandated by CDI 2.0
public RestConfigResource() {
this(null);
this(null, null, null, null);
}

@Inject
public RestConfigResource(ConfigService configService) {
this.configService = configService;
public RestConfigResource(
ServerConfig config, VersionStore store, Authorizer authorizer, AccessContext accessContext) {
this.configService = new ConfigApiImpl(config, store, authorizer, accessContext, 1);
}

@Override
Expand Down
Loading

0 comments on commit aa8db80

Please sign in to comment.