Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit schema reqs #1983

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions coral/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const CONTENT_TYPE_JSON = "application/json" as const;
const API_BASE_URL = getHTTPBaseAPIUrl();

const API_PATHS = {
getSchemaRequest: "/schema/request/{schemaReqId}",
getAclRequest: "/acl/request/{aclRequestId}",
approveOperationalRequest: "/operationalRequest/reqId/{reqId}/approve",
declineOperationalRequest: "/operationalRequest/reqId/{reqId}/decline",
Expand Down
89 changes: 55 additions & 34 deletions coral/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ export type paths = {
"/schemas/source/{source}/kafkaEnv/{kafkaEnvId}/topic/{topicName}/schemaVersion/{schemaVersion}": {
get: operations["getSchemaOfTopicFromSource"];
};
"/schema/request/{schemaReqId}": {
get: operations["getSchemaRequest"];
};
"/resetCache": {
get: operations["resetCache"];
};
Expand Down Expand Up @@ -1067,6 +1070,39 @@ export type components = {
schemaVersion?: string;
envName?: string;
};
SchemaRequestsResponseModel: {
environment: string;
environmentName: string;
requestor: string;
/** Format: int32 */
teamId: number;
teamname: string;
/** @enum {string} */
requestOperationType: "CREATE" | "UPDATE" | "PROMOTE" | "CLAIM" | "DELETE" | "ALL";
/** @enum {string} */
requestStatus: "CREATED" | "DELETED" | "DECLINED" | "APPROVED" | "ALL";
/** Format: date-time */
requesttime: string;
requesttimestring: string;
currentPage: string;
totalNoPages: string;
allPageNos: string[];
approvingTeamDetails: string;
approver?: string;
/** Format: date-time */
approvingtime?: string;
remarks?: string;
appname?: string;
otherParams?: string;
topicname: string;
schemafull: string;
/** Format: int32 */
req_no: number;
forceRegister: boolean;
schemaversion?: string;
deletable?: boolean;
editable?: boolean;
};
RequestEntityStatusCount: {
/** @enum {string} */
requestEntityType?: "TOPIC" | "ACL" | "SCHEMA" | "CONNECTOR" | "OPERATIONAL" | "USER";
Expand Down Expand Up @@ -1245,8 +1281,8 @@ export type components = {
hasSchema: boolean;
/** Format: int32 */
clusterId: number;
highestEnv?: boolean;
topicOwner?: boolean;
highestEnv?: boolean;
};
TopicBaseConfig: {
topicName: string;
Expand Down Expand Up @@ -1323,6 +1359,7 @@ export type components = {
allTopicsCount?: number;
/** Format: int32 */
allTopicWarningsCount?: number;
topicsLoadingStatus?: boolean;
};
TopicSyncResponseModel: {
environment: string;
Expand Down Expand Up @@ -1455,39 +1492,6 @@ export type components = {
kafkaFlavorType?: "APACHE_KAFKA" | "AIVEN_FOR_APACHE_KAFKA" | "CONFLUENT" | "CONFLUENT_CLOUD" | "OTHERS";
remarks?: string;
};
SchemaRequestsResponseModel: {
environment: string;
environmentName: string;
requestor: string;
/** Format: int32 */
teamId: number;
teamname: string;
/** @enum {string} */
requestOperationType: "CREATE" | "UPDATE" | "PROMOTE" | "CLAIM" | "DELETE" | "ALL";
/** @enum {string} */
requestStatus: "CREATED" | "DELETED" | "DECLINED" | "APPROVED" | "ALL";
/** Format: date-time */
requesttime: string;
requesttimestring: string;
currentPage: string;
totalNoPages: string;
allPageNos: string[];
approvingTeamDetails: string;
approver?: string;
/** Format: date-time */
approvingtime?: string;
remarks?: string;
appname?: string;
otherParams?: string;
topicname: string;
schemafull: string;
/** Format: int32 */
req_no: number;
forceRegister: boolean;
schemaversion?: string;
deletable?: boolean;
editable?: boolean;
};
SchemaDetailsPerEnv: {
/** Format: int32 */
id: number;
Expand Down Expand Up @@ -1678,6 +1682,7 @@ export type components = {
addDeleteEditClusters: string;
addDeleteEditEnvs: string;
coralEnabled: string;
coralAvailableForUser: string;
adAuthRoleEnabled: string;
supportlink: string;
myteamtopics: string;
Expand Down Expand Up @@ -3066,6 +3071,21 @@ export type operations = {
};
};
};
getSchemaRequest: {
parameters: {
path: {
schemaReqId: number;
};
};
responses: {
/** @description OK */
200: {
content: {
"application/json": components["schemas"]["SchemaRequestsResponseModel"];
};
};
};
};
resetCache: {
responses: {
/** @description OK */
Expand Down Expand Up @@ -3421,6 +3441,7 @@ export type operations = {
currentPage?: string;
topicnamesearch?: string;
showAllTopics?: string;
resetTopicsCache?: boolean;
isBulkOption?: string;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -203,4 +204,18 @@ public ResponseEntity<ApiResponse> validateSchema(@RequestBody SchemaRequestMode

return ResponseEntity.ok(schemaRegistryControllerService.validateSchema(schemaRequest));
}

/**
* @param schemaReqId requestId of schema
* @return Schema Request details
*/
@RequestMapping(
value = "/schema/request/{schemaReqId}",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<SchemaRequestsResponseModel> getSchemaRequest(
@PathVariable Integer schemaReqId) {
return new ResponseEntity<>(
schemaRegistryControllerService.getSchemaRequest(schemaReqId), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ public String editAclRequest(
return checkAuth("editAclRequest.html", request, response, abstractAuthenticationToken);
}

@RequestMapping(value = "/editSchemaRequest", method = RequestMethod.GET)
public String editSchemaRequest(
ModelMap model,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is model required here? I don't see it used in this class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we added a new html page, we would need this.

HttpServletRequest request,
HttpServletResponse response,
AbstractAuthenticationToken abstractAuthenticationToken) {
return checkAuth("editSchemaRequest.html", request, response, abstractAuthenticationToken);
}

@RequestMapping(value = "/requestConnector", method = RequestMethod.GET)
public String requestConnector(
ModelMap model,
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ public class KlawErrorMessages {
public static final String SCHEMA_ERR_109 =
"Failure. Request Schema environments not configured Settings - tenant config";

public static final String SCHEMA_ERR_110 = "Failure. Schema request is not in CREATED state";

public static final String SCHEMA_ERR_111 = "Failure. Schema request is not owned by you.";

public static final String SERVER_CONFIG_ERR_101 =
"Failure. Invalid json / incorrect name values. Check tenant and env details.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ public synchronized String insertIntoAclsSOT(List<Acl> acls, boolean isSyncAcls)
public synchronized String insertIntoRequestSchema(SchemaRequest schemaRequest) {
log.debug("insertIntoRequestSchema {}", schemaRequest.getTopicname());

schemaRequest.setReq_no(getNextSchemaRequestId("SCHEMA_REQ_ID", schemaRequest.getTenantId()));
if (schemaRequest.getReq_no() == null) {
schemaRequest.setReq_no(getNextSchemaRequestId("SCHEMA_REQ_ID", schemaRequest.getTenantId()));
}

schemaRequest.setSchemafull(schemaRequest.getSchemafull().trim());
schemaRequest.setRequestStatus(RequestStatus.CREATED.value);
schemaRequest.setRequesttime(new Timestamp(System.currentTimeMillis()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_107;
import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_108;
import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_109;
import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_110;
import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_111;
import static io.aiven.klaw.helpers.UtilMethods.updateEnvStatus;
import static io.aiven.klaw.model.enums.MailType.*;
import static org.springframework.beans.BeanUtils.copyProperties;
Expand Down Expand Up @@ -451,6 +453,7 @@ public ApiResponse uploadSchema(
getPrincipal(), PermissionType.REQUEST_CREATE_SCHEMAS)) {
return ApiResponse.NOT_AUTHORIZED;
}
schemaRequest.setRequestor(userName);

int tenantId = commonUtilsService.getTenantId(getUserName());
Optional<Env> schemaEnv = getSchemaEnvFromKafkaEnvId(schemaRequest.getEnvironment());
Expand Down Expand Up @@ -508,23 +511,41 @@ public ApiResponse uploadSchema(
.collect(Collectors.toList());

// request status filtering
if (schemaReqs != null) {
if (schemaReqs != null && schemaRequest.getRequestId() == null) {
schemaReqs =
schemaReqs.stream()
.filter(
schemaRequest1 ->
"created".equals(schemaRequest1.getRequestStatus())
RequestStatus.CREATED.value.equals(schemaRequest1.getRequestStatus())
&& Objects.equals(
schemaRequest1.getTopicname(), schemaRequest.getTopicname()))
.collect(Collectors.toList());
if (schemaReqs.size() > 0) {
return ApiResponse.notOk(SCHEMA_ERR_107);
}
} else if (schemaReqs != null && schemaRequest.getRequestId() != null) {
// edit schema request
Optional<SchemaRequest> optionalSchemaRequest =
schemaReqs.stream()
.filter(schemaReq -> schemaReq.getReq_no().equals(schemaRequest.getRequestId()))
.findFirst();

if (optionalSchemaRequest.isPresent()) {
// verify if request is in CREATED state
if (!optionalSchemaRequest.get().getRequestStatus().equals(RequestStatus.CREATED.value)) {
return ApiResponse.notOk(SCHEMA_ERR_110);
}

// verify if the edit request is being submitted by request owner
if (!optionalSchemaRequest.get().getRequestor().equals(schemaRequest.getRequestor())) {
return ApiResponse.notOk(SCHEMA_ERR_111);
}
}
}

schemaRequest.setRequestor(userName);
SchemaRequest schemaRequestDao = new SchemaRequest();
copyProperties(schemaRequest, schemaRequestDao);
schemaRequestDao.setReq_no(schemaRequest.getRequestId());
schemaRequestDao.setRequestOperationType(requestOperationType.value);
HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests();
schemaRequestDao.setTenantId(tenantId);
Expand Down Expand Up @@ -568,6 +589,44 @@ public ApiResponse validateSchema(SchemaRequestModel schemaRequest) throws KlawE
}
}

public SchemaRequestsResponseModel getSchemaRequest(Integer schemaReqId) {
String userName = getUserName();
int tenantId = commonUtilsService.getTenantId(userName);
SchemaRequest schemaRequest =
manageDatabase.getHandleDbRequests().getSchemaRequest(schemaReqId, tenantId);

if (schemaRequest == null) {
return null;
} else {
SchemaRequestsResponseModel schemaRequestsResponseModel = new SchemaRequestsResponseModel();
copyProperties(schemaRequest, schemaRequestsResponseModel);
schemaRequestsResponseModel.setRequestStatus(
RequestStatus.of(schemaRequest.getRequestStatus()));
schemaRequestsResponseModel.setRequestOperationType(
RequestOperationType.of(schemaRequest.getRequestOperationType()));
// Set kafka env name, id
manageDatabase.getKafkaEnvList(tenantId).stream()
.filter(
kafkaEnv -> {
if (kafkaEnv.getAssociatedEnv() != null) {
return kafkaEnv.getAssociatedEnv().getId().equals(schemaRequest.getEnvironment());
}
return false;
})
.findFirst()
.ifPresent(
env -> {
schemaRequestsResponseModel.setEnvironmentName(env.getName());
schemaRequestsResponseModel.setEnvironment(env.getId());
});

schemaRequestsResponseModel.setTeamname(
manageDatabase.getTeamNameFromTeamId(tenantId, schemaRequest.getTeamId()));

return schemaRequestsResponseModel;
}
}

private String prettyPrintUglyJsonString(String json) {
ObjectMapper mapper = new ObjectMapper();

Expand Down
Loading