partial migration to new openAPI

This commit is contained in:
Michele Artini 2022-08-19 13:27:36 +02:00
parent 834c21ffc8
commit e037cd0b41
4 changed files with 69 additions and 75 deletions

View File

@ -1,53 +1,46 @@
package eu.dnetlib.data.mdstore.manager; package eu.dnetlib.data.mdstore.manager;
import org.springframework.beans.factory.annotation.Value; import org.springdoc.core.GroupedOpenApi;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import eu.dnetlib.common.app.AbstractDnetApp; import eu.dnetlib.common.app.AbstractDnetApp;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
@SpringBootApplication @SpringBootApplication
@EnableSwagger2
@EnableCaching @EnableCaching
@EnableScheduling @EnableScheduling
@EntityScan("eu.dnetlib.dhp.schema.mdstore") @EntityScan("eu.dnetlib.dhp.schema.mdstore")
public class MainApplication extends AbstractDnetApp { public class MainApplication extends AbstractDnetApp {
@Value("${dhp.swagger.api.host}")
private String swaggetHost;
@Value("${dhp.swagger.api.basePath}")
private String swaggerPath;
public static void main(final String[] args) { public static void main(final String[] args) {
SpringApplication.run(MainApplication.class, args); SpringApplication.run(MainApplication.class, args);
} }
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("MDStore APIs")
.pathsToMatch("**/mdstores/**")
.build();
}
@Override @Override
protected void configSwagger(final Docket docket) { protected void configSwagger(final OpenAPI openApi) {
docket openApi.info(new Info().title("MDStore Manager APIs")
.host(swaggetHost) .description("APIs documentation")
.pathMapping(swaggerPath) .version("1.1")
.select() .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0")))
.apis(RequestHandlerSelectors.any()) .externalDocs(new ExternalDocumentation()
.paths(p -> p.contains("/mdstores")) .description("SpringShop Wiki Documentation")
.build() .url("https://springshop.wiki.github.org/docs"));
.apiInfo(new ApiInfoBuilder()
.title("MDStore Manager APIs")
.description("APIs documentation")
.version("1.1")
.contact(ApiInfo.DEFAULT_CONTACT)
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.build());
} }
} }

View File

@ -23,15 +23,13 @@ import eu.dnetlib.data.mdstore.manager.utils.DatabaseUtils;
import eu.dnetlib.data.mdstore.manager.utils.HdfsClient; import eu.dnetlib.data.mdstore.manager.utils.HdfsClient;
import eu.dnetlib.dhp.schema.mdstore.MDStoreVersion; import eu.dnetlib.dhp.schema.mdstore.MDStoreVersion;
import eu.dnetlib.dhp.schema.mdstore.MDStoreWithInfo; import eu.dnetlib.dhp.schema.mdstore.MDStoreWithInfo;
import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.annotations.ApiOperation; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.tags.Tag;
@RestController @RestController
@RequestMapping("/mdstores") @RequestMapping("/mdstores")
@Tag(tags = { @Tag(name = "Metadata Stores")
"Metadata Stores"
})
public class MDStoreController extends AbstractDnetController { public class MDStoreController extends AbstractDnetController {
@Autowired @Autowired
@ -56,32 +54,32 @@ public class MDStoreController extends AbstractDnetController {
@Operation(summary = "Return a mdstores by id") @Operation(summary = "Return a mdstores by id")
@GetMapping("/mdstore/{mdId}") @GetMapping("/mdstore/{mdId}")
public MDStoreWithInfo getMdStore(@Parameter("the mdstore identifier") @PathVariable final String mdId) throws MDStoreManagerException { public MDStoreWithInfo getMdStore(@Parameter(name = "the mdstore identifier") @PathVariable final String mdId) throws MDStoreManagerException {
return databaseUtils.findMdStore(mdId); return databaseUtils.findMdStore(mdId);
} }
@Operation(summary = "Increase the read count of the current mdstore") @Operation(summary = "Increase the read count of the current mdstore")
@GetMapping("/mdstore/{mdId}/startReading") @GetMapping("/mdstore/{mdId}/startReading")
public MDStoreVersion startReading(@Parameter("the mdstore identifier") @PathVariable final String mdId) throws MDStoreManagerException { public MDStoreVersion startReading(@Parameter(name = "the mdstore identifier") @PathVariable final String mdId) throws MDStoreManagerException {
return databaseUtils.startReading(mdId); return databaseUtils.startReading(mdId);
} }
@Operation(summary = "Create a new mdstore") @Operation(summary = "Create a new mdstore")
@GetMapping("/new/{format}/{layout}/{interpretation}") @GetMapping("/new/{format}/{layout}/{interpretation}")
public MDStoreWithInfo createMDStore( public MDStoreWithInfo createMDStore(
@Parameter("mdstore format") @PathVariable final String format, @Parameter(name = "mdstore format") @PathVariable final String format,
@Parameter("mdstore layout") @PathVariable final String layout, @Parameter(name = "mdstore layout") @PathVariable final String layout,
@Parameter("mdstore interpretation") @PathVariable final String interpretation, @Parameter(name = "mdstore interpretation") @PathVariable final String interpretation,
@Parameter("datasource name") @RequestParam(required = true) final String dsName, @Parameter(name = "datasource name") @RequestParam(required = true) final String dsName,
@Parameter("datasource id") @RequestParam(required = true) final String dsId, @Parameter(name = "datasource id") @RequestParam(required = true) final String dsId,
@Parameter("api id") @RequestParam(required = true) final String apiId) throws MDStoreManagerException { @Parameter(name = "api id") @RequestParam(required = true) final String apiId) throws MDStoreManagerException {
final String id = databaseUtils.createMDStore(format, layout, interpretation, dsName, dsId, apiId); final String id = databaseUtils.createMDStore(format, layout, interpretation, dsName, dsId, apiId);
return databaseUtils.findMdStore(id); return databaseUtils.findMdStore(id);
} }
@Operation(summary = "Delete a mdstore by id") @Operation(summary = "Delete a mdstore by id")
@DeleteMapping("/mdstore/{mdId}") @DeleteMapping("/mdstore/{mdId}")
public StatusResponse delete(@Parameter("the id of the mdstore that will be deleted") @PathVariable final String mdId) throws MDStoreManagerException { public StatusResponse delete(@Parameter(name = "the id of the mdstore that will be deleted") @PathVariable final String mdId) throws MDStoreManagerException {
final String hdfsPath = databaseUtils.deleteMdStore(mdId); final String hdfsPath = databaseUtils.deleteMdStore(mdId);
hdfsClient.deletePath(hdfsPath); hdfsClient.deletePath(hdfsPath);
return StatusResponse.DELETED; return StatusResponse.DELETED;
@ -95,14 +93,14 @@ public class MDStoreController extends AbstractDnetController {
@Operation(summary = "Create a new preliminary version of a mdstore") @Operation(summary = "Create a new preliminary version of a mdstore")
@GetMapping("/mdstore/{mdId}/newVersion") @GetMapping("/mdstore/{mdId}/newVersion")
public MDStoreVersion prepareNewVersion(@Parameter("the id of the mdstore for which will be created a new version") @PathVariable final String mdId) { public MDStoreVersion prepareNewVersion(@Parameter(name = "the id of the mdstore for which will be created a new version") @PathVariable final String mdId) {
return databaseUtils.prepareMdStoreVersion(mdId); return databaseUtils.prepareMdStoreVersion(mdId);
} }
@Operation(summary = "Promote a preliminary version to current") @Operation(summary = "Promote a preliminary version to current")
@GetMapping("/version/{versionId}/commit/{size}") @GetMapping("/version/{versionId}/commit/{size}")
public MDStoreVersion commitVersion(@Parameter("the id of the version that will be promoted to the current version") @PathVariable final String versionId, public MDStoreVersion commitVersion(@Parameter(name = "the id of the version that will be promoted to the current version") @PathVariable final String versionId,
@Parameter("the size of the new current mdstore") @PathVariable final long size) throws MDStoreManagerException { @Parameter(name = "the size of the new current mdstore") @PathVariable final long size) throws MDStoreManagerException {
try { try {
return databaseUtils.commitMdStoreVersion(versionId, size); return databaseUtils.commitMdStoreVersion(versionId, size);
} finally { } finally {
@ -112,7 +110,7 @@ public class MDStoreController extends AbstractDnetController {
@Operation(summary = "Abort a preliminary version") @Operation(summary = "Abort a preliminary version")
@GetMapping("/version/{versionId}/abort") @GetMapping("/version/{versionId}/abort")
public StatusResponse commitVersion(@Parameter("the id of the version to abort") @PathVariable final String versionId) throws MDStoreManagerException { public StatusResponse commitVersion(@Parameter(name = "the id of the version to abort") @PathVariable final String versionId) throws MDStoreManagerException {
final String hdfsPath = databaseUtils.deleteMdStoreVersion(versionId, true); final String hdfsPath = databaseUtils.deleteMdStoreVersion(versionId, true);
hdfsClient.deletePath(hdfsPath); hdfsClient.deletePath(hdfsPath);
return StatusResponse.ABORTED; return StatusResponse.ABORTED;
@ -120,15 +118,15 @@ public class MDStoreController extends AbstractDnetController {
@Operation(summary = "Return an existing mdstore version") @Operation(summary = "Return an existing mdstore version")
@GetMapping("/version/{versionId}") @GetMapping("/version/{versionId}")
public MDStoreVersion getVersion(@Parameter("the id of the version that has to be deleted") @PathVariable final String versionId) public MDStoreVersion getVersion(@Parameter(name = "the id of the version that has to be deleted") @PathVariable final String versionId)
throws MDStoreManagerException { throws MDStoreManagerException {
return databaseUtils.findVersion(versionId); return databaseUtils.findVersion(versionId);
} }
@Operation(summary = "Delete a mdstore version") @Operation(summary = "Delete a mdstore version")
@DeleteMapping("/version/{versionId}") @DeleteMapping("/version/{versionId}")
public StatusResponse deleteVersion(@Parameter("the id of the version that has to be deleted") @PathVariable final String versionId, public StatusResponse deleteVersion(@Parameter(name = "the id of the version that has to be deleted") @PathVariable final String versionId,
@Parameter("if true, the controls on writing and readcount values will be skipped") @RequestParam(required = false, defaultValue = "false") final boolean force) @Parameter(name = "if true, the controls on writing and readcount values will be skipped") @RequestParam(required = false, defaultValue = "false") final boolean force)
throws MDStoreManagerException { throws MDStoreManagerException {
final String hdfsPath = databaseUtils.deleteMdStoreVersion(versionId, force); final String hdfsPath = databaseUtils.deleteMdStoreVersion(versionId, force);
hdfsClient.deletePath(hdfsPath); hdfsClient.deletePath(hdfsPath);
@ -137,14 +135,14 @@ public class MDStoreController extends AbstractDnetController {
@Operation(summary = "Decrease the read count of a mdstore version") @Operation(summary = "Decrease the read count of a mdstore version")
@GetMapping("/version/{versionId}/endReading") @GetMapping("/version/{versionId}/endReading")
public MDStoreVersion endReading(@Parameter("the id of the version that has been completely read") @PathVariable final String versionId) public MDStoreVersion endReading(@Parameter(name = "the id of the version that has been completely read") @PathVariable final String versionId)
throws MDStoreManagerException { throws MDStoreManagerException {
return databaseUtils.endReading(versionId); return databaseUtils.endReading(versionId);
} }
@Operation(summary = "Reset the read count of a mdstore version") @Operation(summary = "Reset the read count of a mdstore version")
@GetMapping("/version/{versionId}/resetReading") @GetMapping("/version/{versionId}/resetReading")
public MDStoreVersion resetReading(@Parameter("the id of the version") @PathVariable final String versionId) public MDStoreVersion resetReading(@Parameter(name = "the id of the version") @PathVariable final String versionId)
throws MDStoreManagerException { throws MDStoreManagerException {
return databaseUtils.resetReading(versionId); return databaseUtils.resetReading(versionId);
} }
@ -172,7 +170,7 @@ public class MDStoreController extends AbstractDnetController {
@Operation(summary = "Fix the inconsistencies on HDFS") @Operation(summary = "Fix the inconsistencies on HDFS")
@GetMapping("/hdfs/inconsistencies") @GetMapping("/hdfs/inconsistencies")
public Set<String> fixHdfsInconsistencies( public Set<String> fixHdfsInconsistencies(
@Parameter("force the deletion of hdfs paths") @RequestParam(required = false, defaultValue = "false") final boolean delete) @Parameter(name = "force the deletion of hdfs paths") @RequestParam(required = false, defaultValue = "false") final boolean delete)
throws MDStoreManagerException { throws MDStoreManagerException {
final Set<String> hdfsDirs = hdfsClient.listHadoopDirs(); final Set<String> hdfsDirs = hdfsClient.listHadoopDirs();

View File

@ -42,5 +42,5 @@ dhp.mdstore-manager.hadoop.zeppelin.name-prefix = mdstoreManager
dhp.mdstore-manager.inspector.records.max = 1000 dhp.mdstore-manager.inspector.records.max = 1000
dhp.swagger.api.host = localhost # dhp.swagger.api.host = localhost
dhp.swagger.api.basePath = / dhp.swagger.api.basePath = /**

View File

@ -1,20 +1,20 @@
package eu.dnetlib.organizations; package eu.dnetlib.organizations;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import eu.dnetlib.common.app.AbstractDnetApp; import eu.dnetlib.common.app.AbstractDnetApp;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
@SpringBootApplication @SpringBootApplication
@EnableSwagger2
@EnableCaching @EnableCaching
@EnableScheduling @EnableScheduling
@ComponentScan(basePackages = "eu.dnetlib") @ComponentScan(basePackages = "eu.dnetlib")
@ -24,20 +24,23 @@ public class MainApplication extends AbstractDnetApp {
SpringApplication.run(MainApplication.class, args); SpringApplication.run(MainApplication.class, args);
} }
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("D-Net Organizations Service APIs")
.pathsToMatch("/api/**", "/oa_api/**")
.build();
}
@Override @Override
protected void configSwagger(final Docket docket) { protected void configSwagger(final OpenAPI openApi) {
docket.select() openApi.info(new Info().title("D-Net Organizations Service APIs\"")
.apis(RequestHandlerSelectors.any()) .description("APIs documentation")
.paths(p -> p.startsWith("/api/") || p.startsWith("/oa_api")) .version("1.1")
.build() .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0")))
.apiInfo(new ApiInfoBuilder() .externalDocs(new ExternalDocumentation()
.title("D-Net Organizations Service APIs") .description("SpringShop Wiki Documentation")
.description("APIs documentation") .url("https://springshop.wiki.github.org/docs"));
.version("1.1")
.contact(ApiInfo.DEFAULT_CONTACT)
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.build());
} }
} }