From ff6265e4245c437fc03f3d6100a1324aec6b58da Mon Sep 17 00:00:00 2001 From: NThakur4 <nthakur4@slb.com> Date: Wed, 10 May 2023 06:35:04 -0500 Subject: [PATCH] combine index alias and cluster config logic in one API --- .../osdu/indexer/api/PartitionSetupApi.java | 36 +++++++++---------- .../indexer/api/PartitionSetupApiTest.java | 6 ++++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/PartitionSetupApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/PartitionSetupApi.java index 105a46334..6a5aae39f 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/PartitionSetupApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/PartitionSetupApi.java @@ -21,16 +21,18 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppError; import org.opengroup.osdu.indexer.logging.AuditLogger; -import org.opengroup.osdu.indexer.model.IndexAliasesResult; import org.opengroup.osdu.indexer.service.IClusterConfigurationService; import org.opengroup.osdu.indexer.service.IndexAliasService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.annotation.RequestScope; import java.io.IOException; @@ -51,32 +53,30 @@ public class PartitionSetupApi { @Autowired private IClusterConfigurationService clusterConfigurationService; @Autowired + private JaxRsDpsLog jaxRsDpsLog; + @Autowired private AuditLogger auditLogger; @Operation(summary = "${partitionSetupApi.provisionPartition.summary}", description = "${partitionSetupApi.provisionPartition.description}", - security = {@SecurityRequirement(name = "Authorization")}, tags = { "partition-setup-api" }) + security = {@SecurityRequirement(name = "Authorization")}, tags = {"partition-setup-api"}) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "400", description = "Bad Request", content = {@Content(schema = @Schema(implementation = AppError.class))}), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = {@Content(schema = @Schema(implementation = AppError.class))}), - @ApiResponse(responseCode = "403", description = "User not authorized to perform the action", content = {@Content(schema = @Schema(implementation = AppError.class))}), - @ApiResponse(responseCode = "404", description = "Not Found", content = {@Content(schema = @Schema(implementation = AppError.class))}), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = {@Content(schema = @Schema(implementation = AppError.class))}), - @ApiResponse(responseCode = "502", description = "Bad Gateway", content = {@Content(schema = @Schema(implementation = AppError.class))}), - @ApiResponse(responseCode = "503", description = "Service Unavailable", content = {@Content(schema = @Schema(implementation = AppError.class))}) + @ApiResponse(responseCode = "400", description = "Bad Request", content = {@Content(schema = @Schema(implementation = AppError.class))}), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = {@Content(schema = @Schema(implementation = AppError.class))}), + @ApiResponse(responseCode = "403", description = "User not authorized to perform the action", content = {@Content(schema = @Schema(implementation = AppError.class))}), + @ApiResponse(responseCode = "404", description = "Not Found", content = {@Content(schema = @Schema(implementation = AppError.class))}), + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = {@Content(schema = @Schema(implementation = AppError.class))}), + @ApiResponse(responseCode = "502", description = "Bad Gateway", content = {@Content(schema = @Schema(implementation = AppError.class))}), + @ApiResponse(responseCode = "503", description = "Service Unavailable", content = {@Content(schema = @Schema(implementation = AppError.class))}) }) @PreAuthorize("@authorizationFilter.hasPermission('" + OPS + "')") @PutMapping(path = "/provision", consumes = "application/json") public ResponseEntity<?> provisionPartition(@RequestHeader(DATA_PARTITION_ID) String dataPartitionId) throws IOException { + this.jaxRsDpsLog.info("applying cluster configuration for partition: " + dataPartitionId); this.clusterConfigurationService.updateClusterConfiguration(); + this.jaxRsDpsLog.info("creating default alias for all pre-exiting indices for partition: " + dataPartitionId); + this.indexAliasService.createIndexAliasesForAll(); this.auditLogger.getConfigurePartition(singletonList(dataPartitionId)); return new ResponseEntity<>(org.springframework.http.HttpStatus.OK); } - - @PreAuthorize("@authorizationFilter.hasPermission('" + OPS + "')") - @PostMapping(path = "/aliases") - public ResponseEntity<IndexAliasesResult> createIndexAliases() { - IndexAliasesResult result = indexAliasService.createIndexAliasesForAll(); - return new ResponseEntity<>(result, HttpStatus.OK); - } } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/PartitionSetupApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/PartitionSetupApiTest.java index 03c6d718f..46c7a775d 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/PartitionSetupApiTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/PartitionSetupApiTest.java @@ -18,9 +18,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.service.IClusterConfigurationService; +import org.opengroup.osdu.indexer.service.IndexAliasService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; @@ -38,6 +40,10 @@ public class PartitionSetupApiTest { private AuditLogger auditLogger; @Mock private IClusterConfigurationService clusterConfigurationService; + @Mock + private IndexAliasService indexAliasService; + @Mock + private JaxRsDpsLog jaxRsDpsLog; @InjectMocks private PartitionSetupApi sut; -- GitLab