-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from rundeck/enh/cluster-exec-mode-toggle
API41: cluster exec mode toggle
- Loading branch information
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...nds/enterprise/license/BaseExtension.java → ...ol/commands/enterprise/BaseExtension.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
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
27 changes: 27 additions & 0 deletions
27
...in/java/org/rundeck/client/tool/commands/enterprise/api/model/EnterpriseModeResponse.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,27 @@ | ||
package org.rundeck.client.tool.commands.enterprise.api.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import org.rundeck.client.api.model.SystemMode; | ||
import org.rundeck.client.util.DataOutput; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@Data | ||
public class EnterpriseModeResponse extends SystemMode implements DataOutput { | ||
String status; | ||
String uuid; | ||
|
||
@Override | ||
public Map<?, ?> asMap() { | ||
HashMap<String, String> map = new HashMap<>(); | ||
map.put("status", status); | ||
map.put("mode", getExecutionMode().toString()); | ||
map.put("uuid", uuid); | ||
return map; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...li-enterprise/src/main/java/org/rundeck/client/tool/commands/enterprise/cluster/Mode.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,79 @@ | ||
package org.rundeck.client.tool.commands.enterprise.cluster; | ||
|
||
import com.lexicalscope.jewel.cli.CommandLineInterface; | ||
import com.lexicalscope.jewel.cli.Option; | ||
import org.rundeck.client.api.model.ExecutionMode; | ||
import org.rundeck.client.tool.InputError; | ||
import org.rundeck.client.tool.commands.enterprise.BaseExtension; | ||
import org.rundeck.client.tool.commands.enterprise.api.EnterpriseApi; | ||
import org.rundeck.client.tool.commands.enterprise.api.model.EnterpriseModeResponse; | ||
import org.rundeck.client.tool.extension.RdTool; | ||
import org.rundeck.toolbelt.Command; | ||
import org.rundeck.toolbelt.CommandOutput; | ||
import org.rundeck.toolbelt.SubCommand; | ||
import retrofit2.Call; | ||
|
||
import java.io.IOException; | ||
import java.util.function.BiFunction; | ||
|
||
@Command() | ||
@SubCommand(path = {"cluster"}, descriptions = {"Manage Rundeck Enterprise Cluster"}) | ||
public class Mode extends BaseExtension { | ||
|
||
interface QuietOption { | ||
@Option(shortName = "q", longName = "quiet", description = "Reduce output.") | ||
boolean isQuiet(); | ||
} | ||
|
||
interface UuidOption { | ||
@Option(shortName = "u", longName = "uuid", description = "Cluster member UUID") | ||
String getUuid(); | ||
} | ||
|
||
interface BaseOption extends QuietOption, UuidOption { | ||
} | ||
|
||
@CommandLineInterface(application = "active") | ||
interface ModeActive extends BaseOption { | ||
|
||
} | ||
|
||
@Command(description = "Set cluster member execution mode Active") | ||
public boolean active(ModeActive opts, CommandOutput output) throws IOException, InputError { | ||
return changeMode(opts, output, ExecutionMode.active, EnterpriseApi::executionModeEnable); | ||
} | ||
|
||
@CommandLineInterface(application = "passive") | ||
interface ModePassive extends BaseOption { | ||
|
||
} | ||
|
||
@Command(description = "Set cluster member execution mode Passive") | ||
public boolean passive(ModePassive opts, CommandOutput output) throws IOException, InputError { | ||
return changeMode(opts, output, ExecutionMode.passive, EnterpriseApi::executionModeDisable); | ||
} | ||
|
||
boolean changeMode( | ||
final BaseOption opts, | ||
final CommandOutput output, | ||
final ExecutionMode expected, | ||
final BiFunction<EnterpriseApi, String, Call<EnterpriseModeResponse>> operation | ||
) | ||
throws InputError, IOException { | ||
RdTool.apiVersionCheck("change cluster member execution mode", 41, getClient().getApiVersion()); | ||
|
||
if (!opts.isQuiet()) { | ||
output.info(String.format("Setting Execution Mode to %s for cluster member %s...", expected, opts.getUuid())); | ||
} | ||
|
||
EnterpriseModeResponse mode = getClient().apiCall((e) -> operation.apply(e, opts.getUuid())); | ||
|
||
if (!opts.isQuiet()) { | ||
output.info(String.format("Execution Mode change is %s for cluster member %s:", mode.getStatus(), opts.getUuid())); | ||
output.output(mode.getExecutionMode()); | ||
} | ||
|
||
return expected.equals(mode.getExecutionMode()); | ||
} | ||
|
||
} |
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