-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CELEBORN-1589] Ensure master is leader for some POST request APIs
### What changes were proposed in this pull request? Ensure that `excludeWorker`, `removeWorkersUnavailableInfo`, and `sendWorkerEvents` can only happen from Master leader node. ### Why are the changes needed? prevent inconsistencies from peers ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? tested against a cluster Closes #2730 from akpatnam25/CELEBORN-1589. Authored-by: Aravind Patnam <[email protected]> Signed-off-by: SteNicholas <[email protected]>
- Loading branch information
1 parent
30f7da5
commit 5f02f3e
Showing
6 changed files
with
109 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...in/scala/org/apache/celeborn/service/deploy/master/http/api/MasterHttpResourceUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.celeborn.service.deploy.master.http.api | ||
|
||
import javax.ws.rs.BadRequestException | ||
|
||
import org.apache.celeborn.service.deploy.master.Master | ||
|
||
object MasterHttpResourceUtils { | ||
|
||
def ensureMasterIsLeader[T](master: Master)(f: => T): T = { | ||
if (master.isMasterActive != 1) { | ||
throw new BadRequestException( | ||
s"This operation can only be done from a master that has the LEADER role." + | ||
s" The master group info is: \n${master.getMasterGroupInfo}") | ||
} | ||
f | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...cala/org/apache/celeborn/service/deploy/master/http/api/TestMasterHttpResourceUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.celeborn.service.deploy.master.http.api | ||
|
||
import javax.ws.rs.BadRequestException | ||
|
||
import org.mockito.MockitoSugar._ | ||
|
||
import org.apache.celeborn.CelebornFunSuite | ||
import org.apache.celeborn.service.deploy.master.Master | ||
|
||
class TestMasterHttpResourceUtils extends CelebornFunSuite { | ||
|
||
test("ensureMasterIsLeader") { | ||
val mockMaster = mock[Master] | ||
when(mockMaster.isMasterActive).thenReturn(0) | ||
assertThrows[BadRequestException] { | ||
MasterHttpResourceUtils.ensureMasterIsLeader(mockMaster) { | ||
"operation failed" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters