Skip to content

Commit

Permalink
Fix initialization or service controllers (Netflix#558)
Browse files Browse the repository at this point in the history
* Fix initialization or service controllers

* Refactor metacat ini order to ensure controllers are inited after the catalog

* Remove constructor injection and use DependsOn for bean ordering
  • Loading branch information
swaranga-netflix authored May 31, 2023
1 parent bcf3f44 commit 3b13e41
Show file tree
Hide file tree
Showing 18 changed files with 458 additions and 402 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -79,6 +81,8 @@
consumes = MediaType.APPLICATION_JSON_VALUE
)
@Slf4j
@DependsOn("metacatCoreInitService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MetacatController implements MetacatV1 {
private final CatalogService catalogService;
private final DatabaseService databaseService;
Expand All @@ -87,33 +91,6 @@ public class MetacatController implements MetacatV1 {
private final RequestWrapper requestWrapper;
private final Config config;

/**
* Constructor.
*
* @param catalogService catalog service
* @param databaseService database service
* @param mViewService view service
* @param tableService table service
* @param requestWrapper request wrapper obj
* @param config Config
*/
@Autowired
public MetacatController(
final CatalogService catalogService,
final DatabaseService databaseService,
final MViewService mViewService,
final TableService tableService,
final RequestWrapper requestWrapper,
final Config config
) {
this.catalogService = catalogService;
this.databaseService = databaseService;
this.mViewService = mViewService;
this.tableService = tableService;
this.requestWrapper = requestWrapper;
this.config = config;
}

/**
* Simple get on / to show API is up and available.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -66,33 +68,14 @@
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@DependsOn("metacatCoreInitService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MetadataController {
private final UserMetadataService userMetadataService;
private final MetacatServiceHelper helper;
private final MetadataService metadataService;
private final RequestWrapper requestWrapper;

/**
* Constructor.
*
* @param userMetadataService user metadata service
* @param helper helper
* @param metadataService metadata service
* @param requestWrapper request wrapper object
*/
@Autowired
public MetadataController(
final UserMetadataService userMetadataService,
final MetacatServiceHelper helper,
final MetadataService metadataService,
final RequestWrapper requestWrapper
) {
this.userMetadataService = userMetadataService;
this.helper = helper;
this.metadataService = metadataService;
this.requestWrapper = requestWrapper;
}

/**
* Returns the data metadata.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -68,34 +70,15 @@
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@DependsOn("metacatCoreInitService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PartitionController implements PartitionV1 {

private final MetacatController v1;
private final MViewService mViewService;
private final PartitionService partitionService;
private final RequestWrapper requestWrapper;

/**
* Constructor.
*
* @param v1 Metacat V1
* @param mViewService view service
* @param partitionService partition service
* @param requestWrapper request wrapper object
*/
@Autowired
public PartitionController(
final MetacatController v1,
final MViewService mViewService,
final PartitionService partitionService,
final RequestWrapper requestWrapper
) {
this.v1 = v1;
this.mViewService = mViewService;
this.partitionService = partitionService;
this.requestWrapper = requestWrapper;
}

/**
* Delete named partitions from a table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -52,21 +54,11 @@
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@DependsOn("metacatCoreInitService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ResolverController {
private TableService tableService;
private PartitionService partitionService;

/**
* Constructor.
*
* @param tableService table service
* @param partitionService partition service
*/
@Autowired
public ResolverController(final TableService tableService, final PartitionService partitionService) {
this.tableService = tableService;
this.partitionService = partitionService;
}
private final TableService tableService;
private final PartitionService partitionService;

/**
* Gets the qualified name by uri.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package com.netflix.metacat.main.api.v1;

import com.netflix.metacat.common.dto.TableDto;
import com.netflix.metacat.main.services.search.ElasticSearchUtil;
import com.netflix.metacat.main.api.RequestWrapper;
import com.netflix.metacat.main.services.search.ElasticSearchUtil;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -42,25 +44,12 @@
path = "/mds/v1/search",
produces = MediaType.APPLICATION_JSON_VALUE
)
@DependsOn("metacatCoreInitService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SearchController {
private final ElasticSearchUtil elasticSearchUtil;
private final RequestWrapper requestWrapper;

/**
* Constructor.
*
* @param elasticSearchUtil search util
* @param requestWrapper request wrapper object
*/
@Autowired
public SearchController(
final ElasticSearchUtil elasticSearchUtil,
final RequestWrapper requestWrapper
) {
this.elasticSearchUtil = elasticSearchUtil;
this.requestWrapper = requestWrapper;
}

/**
* Searches the list of tables for the given search string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.WebDataBinder;
Expand Down Expand Up @@ -78,6 +80,8 @@
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@DependsOn("metacatCoreInitService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TagController {

private final RequestWrapper requestWrapper;
Expand All @@ -88,36 +92,6 @@ public class TagController {
private final CatalogService catalogService;
private final MViewService mViewService;

/**
* Constructor.
*
* @param eventBus event bus
* @param tagService tag service
* @param tableService table service
* @param databaseService database service
* @param catalogService catalog service
* @param mViewService mView service
* @param requestWrapper request wrapper object
*/
@Autowired
public TagController(
final MetacatEventBus eventBus,
final TagService tagService,
final TableService tableService,
final DatabaseService databaseService,
final CatalogService catalogService,
final MViewService mViewService,
final RequestWrapper requestWrapper
) {
this.tagService = tagService;
this.eventBus = eventBus;
this.tableService = tableService;
this.databaseService = databaseService;
this.catalogService = catalogService;
this.requestWrapper = requestWrapper;
this.mViewService = mViewService;
}

/**
* Return the list of tags.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@
import com.netflix.metacat.main.services.CatalogTraversalServiceHelper;
import com.netflix.metacat.main.services.DatabaseService;
import com.netflix.metacat.main.services.MViewService;
import com.netflix.metacat.main.services.MetacatInitializationService;
import com.netflix.metacat.main.services.MetacatServiceHelper;
import com.netflix.metacat.main.services.MetacatThriftService;
import com.netflix.metacat.main.services.MetadataService;
import com.netflix.metacat.main.services.OwnerValidationService;
import com.netflix.metacat.main.services.PartitionService;
import com.netflix.metacat.main.services.TableService;
import com.netflix.metacat.main.services.health.MetacatHealthIndicator;
import com.netflix.metacat.main.services.impl.CatalogServiceImpl;
import com.netflix.metacat.main.services.impl.ConnectorTableServiceProxy;
import com.netflix.metacat.main.services.impl.DatabaseServiceImpl;
import com.netflix.metacat.main.services.impl.DefaultOwnerValidationService;
import com.netflix.metacat.main.services.impl.MViewServiceImpl;
import com.netflix.metacat.main.services.impl.PartitionServiceImpl;
import com.netflix.metacat.main.services.impl.TableServiceImpl;
import com.netflix.metacat.main.services.init.MetacatCoreInitService;
import com.netflix.metacat.main.services.init.MetacatThriftInitService;
import com.netflix.spectator.api.Registry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down Expand Up @@ -393,29 +396,59 @@ public MetadataService metadataService(
}

/**
* The initialization service that will handle startup and shutdown of Metacat.
* The core initialization service that will handle startup and shutdown of the catalog.
* We do not configure the start and stop methods as bean lifecycle methods to Spring since they are
* called via the thrift init service.
*
* @param pluginManager Plugin manager to use
* @param catalogManager Catalog manager to use
* @param connectorManager Connector manager to use
* @param threadServiceManager Thread service manager to use
* @param applicationContext the application context
*
* @return The initialization service bean
*/
@Bean
public MetacatCoreInitService metacatCoreInitService(final PluginManager pluginManager,
final CatalogManager catalogManager,
final ConnectorManager connectorManager,
final ThreadServiceManager threadServiceManager,
final ApplicationContext applicationContext) {
return new MetacatCoreInitService(
pluginManager, catalogManager, connectorManager,
threadServiceManager, applicationContext);
}

/**
* The initialization service that will handle startup and shutdown of Metacat thrift service.
*
* @param metacatCoreInitService the core init service
* @param metacatThriftService Thrift service to use
*
* @return The initialization service bean
*/
@Bean(initMethod = "start", destroyMethod = "stop")
public MetacatThriftInitService metacatThriftInitService(final MetacatCoreInitService metacatCoreInitService,
final MetacatThriftService metacatThriftService) {
return new MetacatThriftInitService(
metacatThriftService,
metacatCoreInitService
);
}

/**
* Metacat health indicator.
*
* @param metacatCoreInitService the code in it service
* @param metacatThriftInitService the thrift init service
*
* @return the health indicator
*/
@Bean
public MetacatInitializationService metacatInitializationService(
final PluginManager pluginManager,
final CatalogManager catalogManager,
final ConnectorManager connectorManager,
final ThreadServiceManager threadServiceManager,
final MetacatThriftService metacatThriftService
) {
return new MetacatInitializationService(
pluginManager,
catalogManager,
connectorManager,
threadServiceManager,
metacatThriftService
public MetacatHealthIndicator metacatHealthIndicator(final MetacatCoreInitService metacatCoreInitService,
final MetacatThriftInitService metacatThriftInitService) {
return new MetacatHealthIndicator(
metacatCoreInitService, metacatThriftInitService
);
}

Expand Down
Loading

0 comments on commit 3b13e41

Please sign in to comment.