Skip to content

Commit

Permalink
case insenetive
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Sep 21, 2024
1 parent 8734d16 commit 59abe0e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@

package org.apache.celeborn.service.deploy.master.http.api.v1

import javax.ws.rs.{BadRequestException, Consumes, GET, Path, POST, Produces}
import javax.ws.rs.{BadRequestException, Consumes, GET, POST, Path, Produces}
import javax.ws.rs.core.MediaType

import scala.collection.JavaConverters._

import io.swagger.v3.oas.annotations.media.{Content, Schema}
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag

import org.apache.celeborn.common.protocol.WorkerEventType
import org.apache.celeborn.rest.v1.model._
import org.apache.celeborn.rest.v1.model.SendWorkerEventRequest.EventTypeEnum
import org.apache.celeborn.server.common.http.api.ApiRequestContext
import org.apache.celeborn.server.common.http.api.v1.ApiUtils
import org.apache.celeborn.service.deploy.master.Master
Expand Down Expand Up @@ -122,7 +121,7 @@ class WorkerResource extends ApiRequestContext {
mediaType = MediaType.APPLICATION_JSON,
schema = new Schema(implementation = classOf[HandleResponse]))),
description =
"For Master(Leader) can send worker event to manager workers. Legal types are 'None', 'Immediately', 'Decommission', 'DecommissionThenIdle', 'Graceful', 'Recommission'.")
"For Master(Leader) can send worker event to manager workers. Legal types are 'NONE', 'IMMEDIATELY', 'DECOMMISSION', 'DECOMMISSIONTHENIDLE', 'GRACEFUL', 'RECOMMISSION'.")
@POST
@Path("/events")
def sendWorkerEvents(request: SendWorkerEventRequest): HandleResponse =
Expand All @@ -137,7 +136,8 @@ class WorkerResource extends ApiRequestContext {
throw new BadRequestException(
s"None of the workers are known: ${unknownWorkers.map(_.readableAddress).mkString(", ")}")
}
val (success, msg) = httpService.handleWorkerEvent(request.getEventType.toString, workers)
val (success, msg) =
httpService.handleWorkerEvent(toWorkerEventType(request.getEventType), workers)
val finalMsg =
if (unknownWorkers.isEmpty) {
msg
Expand All @@ -146,4 +146,16 @@ class WorkerResource extends ApiRequestContext {
}
new HandleResponse().success(success).message(finalMsg)
}

private def toWorkerEventType(enum: EventTypeEnum): String = {
enum match {
case EventTypeEnum.NONE => WorkerEventType.None.toString
case EventTypeEnum.IMMEDIATELY => WorkerEventType.Immediately.toString
case EventTypeEnum.DECOMMISSION => WorkerEventType.Decommission.toString
case EventTypeEnum.DECOMMISSIONTHENIDLE => WorkerEventType.DecommissionThenIdle.toString
case EventTypeEnum.GRACEFUL => WorkerEventType.Graceful.toString
case EventTypeEnum.RECOMMISSION => WorkerEventType.Recommission.toString
case _ => WorkerEventType.UNRECOGNIZED.toString
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ApiV1MasterResourceSuite extends ApiV1BaseResourceSuite {
Entity.entity(sendWorkerEventRequest, MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_BAD_REQUEST == response.getStatus)
assert(
response.readEntity(classOf[String]).contains("eventType(None) and workers([]) are required"))
response.readEntity(classOf[String]).contains("eventType(NONE) and workers([]) are required"))
sendWorkerEventRequest.workers(Collections.singletonList(worker))
response = webTarget.path("workers/events").request(MediaType.APPLICATION_JSON).post(
Entity.entity(sendWorkerEventRequest, MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public HandleResponse removeWorkersUnavailableInfo(RemoveWorkersUnavailableInfoR

/**
*
* For Master(Leader) can send worker event to manager workers. Legal types are 'None', 'Immediately', 'Decommission', 'DecommissionThenIdle', 'Graceful', 'Recommission'.
* For Master(Leader) can send worker event to manager workers. Legal types are 'NONE', 'IMMEDIATELY', 'DECOMMISSION', 'DECOMMISSIONTHENIDLE', 'GRACEFUL', 'RECOMMISSION'.
* @param sendWorkerEventRequest (optional)
* @return HandleResponse
* @throws ApiException if fails to make API call
Expand All @@ -337,7 +337,7 @@ public HandleResponse sendWorkerEvent(SendWorkerEventRequest sendWorkerEventRequ

/**
*
* For Master(Leader) can send worker event to manager workers. Legal types are 'None', 'Immediately', 'Decommission', 'DecommissionThenIdle', 'Graceful', 'Recommission'.
* For Master(Leader) can send worker event to manager workers. Legal types are 'NONE', 'IMMEDIATELY', 'DECOMMISSION', 'DECOMMISSIONTHENIDLE', 'GRACEFUL', 'RECOMMISSION'.
* @param sendWorkerEventRequest (optional)
* @param additionalHeaders additionalHeaders for this call
* @return HandleResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public class SendWorkerEventRequest {
* The type of the event.
*/
public enum EventTypeEnum {
IMMEDIATELY("Immediately"),
IMMEDIATELY("IMMEDIATELY"),

DECOMMISSION("Decommission"),
DECOMMISSION("DECOMMISSION"),

DECOMMISSION_THEN_IDLE("DecommissionThenIdle"),
DECOMMISSIONTHENIDLE("DECOMMISSIONTHENIDLE"),

GRACEFUL("Graceful"),
GRACEFUL("GRACEFUL"),

RECOMMISSION("Recommission"),
RECOMMISSION("RECOMMISSION"),

NONE("None");
NONE("NONE");

private String value;

Expand Down
14 changes: 7 additions & 7 deletions openapi/openapi-client/src/main/openapi3/master_rest_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ paths:
operationId: sendWorkerEvent
description: |
For Master(Leader) can send worker event to manager workers.
Legal types are 'None', 'Immediately', 'Decommission', 'DecommissionThenIdle', 'Graceful', 'Recommission'.
Legal types are 'NONE', 'IMMEDIATELY', 'DECOMMISSION', 'DECOMMISSIONTHENIDLE', 'GRACEFUL', 'RECOMMISSION'.
requestBody:
content:
application/json:
Expand Down Expand Up @@ -706,12 +706,12 @@ components:
type: string
description: The type of the event.
enum:
- Immediately
- Decommission
- DecommissionThenIdle
- Graceful
- Recommission
- None
- IMMEDIATELY
- DECOMMISSION
- DECOMMISSIONTHENIDLE
- GRACEFUL
- RECOMMISSION
- NONE
workers:
type: array
description: The workers to send the event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ApiV1OpenapiClientSuite extends ApiV1WorkerOpenapiClientSuite {

handleResponse = api.sendWorkerEvent(
new SendWorkerEventRequest().addWorkersItem(workerId).eventType(
EventTypeEnum.DECOMMISSION_THEN_IDLE))
EventTypeEnum.DECOMMISSIONTHENIDLE))
assert(handleResponse.getSuccess)

assert(!api.getWorkerEvents.getWorkerEvents.isEmpty)
Expand Down

0 comments on commit 59abe0e

Please sign in to comment.