Skip to content
Snippets Groups Projects
Commit ff6265e4 authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

combine index alias and cluster config logic in one API

parent 619a544a
No related branches found
No related tags found
1 merge request!496Provide an endpoint to create aliases for all existing indices that do not have aliases
Pipeline #184216 failed
......@@ -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);
}
}
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment