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
Prevent flapping slave from rejoining cluster #1428
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50ee69a
Prevent flapping slave from rejoining cluster
PtrTeixeira 9ca3ab6
Fill out functions to active/deactivate slaves
PtrTeixeira ea64db1
Add small test suite for inactive slave manager
PtrTeixeira 6925c31
Mark slaves on inactive host as decommissioned
PtrTeixeira e385344
Add resource for marking slaves as inactive
PtrTeixeira 8ac0386
Add UI for marking hosts inactive
PtrTeixeira 9ce5f94
Fix issues from code review
PtrTeixeira 5490a1d
Rename ZooKeeper path
PtrTeixeira 6f677f1
fix merge conflicts with master
ssalinas File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
SingularityService/src/main/java/com/hubspot/singularity/data/InactiveSlaveManager.java
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,43 @@ | ||
package com.hubspot.singularity.data; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.apache.curator.framework.CuratorFramework; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import com.hubspot.singularity.config.SingularityConfiguration; | ||
|
||
@Singleton | ||
public class InactiveSlaveManager extends CuratorManager { | ||
private static final String ROOT_PATH = "/inactive"; | ||
|
||
@Inject | ||
public InactiveSlaveManager(CuratorFramework curator, | ||
SingularityConfiguration configuration, | ||
MetricRegistry metricRegistry) { | ||
super(curator, configuration, metricRegistry); | ||
} | ||
|
||
public Set<String> getInactiveSlaves() { | ||
return new HashSet<>(getChildren(ROOT_PATH)); | ||
} | ||
|
||
public void deactivateSlave(String host) { | ||
create(pathOf(host)); | ||
} | ||
|
||
public void activateSlave(String host) { | ||
delete(pathOf(host)); | ||
} | ||
|
||
public boolean isInactive(String host) { | ||
return exists(pathOf(host)); | ||
} | ||
|
||
private String pathOf(String host) { | ||
return String.format("%s/%s", ROOT_PATH, host); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...ularityService/src/main/java/com/hubspot/singularity/resources/InactiveSlaveResource.java
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,57 @@ | ||
package com.hubspot.singularity.resources; | ||
|
||
import java.util.Set; | ||
|
||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import com.google.common.base.Optional; | ||
import com.google.inject.Inject; | ||
import com.hubspot.singularity.SingularityService; | ||
import com.hubspot.singularity.SingularityUser; | ||
import com.hubspot.singularity.auth.SingularityAuthorizationHelper; | ||
import com.hubspot.singularity.data.InactiveSlaveManager; | ||
import com.wordnik.swagger.annotations.Api; | ||
|
||
@Path(InactiveSlaveResource.PATH) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Api(description="Manages Singularity Deploys for existing requests", value=DisastersResource.PATH) | ||
public class InactiveSlaveResource { | ||
public static final String PATH = SingularityService.API_BASE_PATH + "/inactive"; | ||
|
||
private final InactiveSlaveManager inactiveSlaveManager; | ||
private final SingularityAuthorizationHelper authorizationHelper; | ||
private final Optional<SingularityUser> user; | ||
|
||
|
||
@Inject | ||
public InactiveSlaveResource(InactiveSlaveManager inactiveSlaveManager, | ||
SingularityAuthorizationHelper authorizationHelper, | ||
Optional<SingularityUser> user) { | ||
this.inactiveSlaveManager = inactiveSlaveManager; | ||
this.authorizationHelper = authorizationHelper; | ||
this.user = user; | ||
} | ||
|
||
@GET | ||
public Set<String> getInactiveSlaves() { | ||
return inactiveSlaveManager.getInactiveSlaves(); | ||
} | ||
|
||
@POST | ||
public void deactivateSlave(@QueryParam("host") String host) { | ||
authorizationHelper.checkAdminAuthorization(user); | ||
inactiveSlaveManager.deactivateSlave(host); | ||
} | ||
|
||
@DELETE | ||
public void reactivateSlave(@QueryParam("host") String host) { | ||
authorizationHelper.checkAdminAuthorization(user); | ||
inactiveSlaveManager.activateSlave(host); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
SingularityService/src/test/java/com/hubspot/singularity/data/InactiveSlaveManagerTest.java
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,37 @@ | ||
package com.hubspot.singularity.data; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.hubspot.singularity.SingularitySlave; | ||
import com.hubspot.singularity.scheduler.SingularitySchedulerTestBase; | ||
|
||
public class InactiveSlaveManagerTest extends SingularitySchedulerTestBase { | ||
public InactiveSlaveManagerTest() { | ||
super(false); | ||
} | ||
|
||
@Test | ||
public void itShouldContainAnInactiveHostWhenHostDeactivated() { | ||
inactiveSlaveManager.deactivateSlave("localhost"); | ||
|
||
Assert.assertTrue(inactiveSlaveManager.getInactiveSlaves().contains("localhost")); | ||
} | ||
|
||
@Test | ||
public void itShouldNotContainHostAfterActivatingHost() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to extend these tests, you can have the class extend |
||
inactiveSlaveManager.deactivateSlave("localhost"); | ||
inactiveSlaveManager.activateSlave("localhost"); | ||
|
||
Assert.assertFalse(inactiveSlaveManager.getInactiveSlaves().contains("localhost")); | ||
} | ||
|
||
@Test | ||
public void itShouldMarkSlavesFromInactiveHostAsDecommissioned() { | ||
inactiveSlaveManager.deactivateSlave("host1"); | ||
|
||
resourceOffers(); | ||
SingularitySlave slave = slaveManager.getObject("slave1").get(); | ||
Assert.assertTrue(slave.getCurrentState().getState().isDecommissioning()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { buildApiAction } from './base'; | ||
|
||
export const DeactivateHost = buildApiAction( | ||
'DEACTIVATE_HOST', | ||
(host) => ({ | ||
method: 'POST', | ||
url: `/inactive?host=${host}` | ||
}) | ||
); | ||
|
||
export const ReactivateHost = buildApiAction( | ||
'REACTIVATE_HOST', | ||
(host) => ({ | ||
method: 'DELETE', | ||
url: `/inactive?host=${host}` | ||
}) | ||
); | ||
|
||
export const FetchInactiveHosts = buildApiAction( | ||
'FETCH_INACTIVE_HOST', | ||
{url: '/inactive'} | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit pick here, but could we have this be
/inactiveSlaves
? when looking at the top level in zk would be easier to tell what it's for