-
Notifications
You must be signed in to change notification settings - Fork 109
Feat: Remote Deployment and Running #204
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
Merged
JLLeitschuh
merged 4 commits into
WPIRoboticsProjects:master
from
JLLeitschuh:feat/copyToRemoteDeviceAndLaunch
Jan 3, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
130 changes: 130 additions & 0 deletions
130
ui/src/main/java/edu/wpi/grip/ui/DeployerController.java
This file contains hidden or 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,130 @@ | ||
| package edu.wpi.grip.ui; | ||
|
|
||
|
|
||
| import com.google.common.base.Throwables; | ||
| import com.google.inject.Inject; | ||
| import edu.wpi.grip.ui.annotations.ParametrizedController; | ||
| import edu.wpi.grip.ui.components.StartStoppableButton; | ||
| import edu.wpi.grip.ui.deployment.DeploymentOptionsController; | ||
| import edu.wpi.grip.ui.deployment.DeploymentOptionsControllersFactory; | ||
| import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager; | ||
| import javafx.application.Platform; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Accordion; | ||
| import javafx.scene.control.DialogPane; | ||
| import javafx.scene.control.ProgressBar; | ||
| import javafx.scene.control.TextArea; | ||
| import javafx.scene.layout.HBox; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.io.PrintStream; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @ParametrizedController(url = "DeployerPane.fxml") | ||
| public class DeployerController { | ||
|
|
||
| @FXML | ||
| private DialogPane root; | ||
|
|
||
| @FXML | ||
| private HBox controlsBox; | ||
|
|
||
| @FXML | ||
| private Accordion deploymentMethods; | ||
|
|
||
| @FXML | ||
| private TextArea stdOutStreamTextArea; | ||
|
|
||
| @FXML | ||
| private TextArea stdErrStreamTextArea; | ||
|
|
||
| @FXML | ||
| private ProgressBar progressIndicator; | ||
|
|
||
| private final StartStoppableButton.Factory startStopButtonFactory; | ||
| private final DeploymentOptionsControllersFactory optionsControllersFactory; | ||
|
|
||
| private class StreamToTextArea extends OutputStream { | ||
| private final TextArea outputArea; | ||
|
|
||
| public StreamToTextArea(TextArea outputArea) { | ||
| super(); | ||
| this.outputArea = outputArea; | ||
| } | ||
|
|
||
| public StreamToTextArea reset() { | ||
| outputArea.clear(); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void write(int i) throws IOException { | ||
| outputArea.appendText(String.valueOf((char) i)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public interface Factory { | ||
| DeployerController create(); | ||
| } | ||
|
|
||
| @Inject | ||
| DeployerController(StartStoppableButton.Factory startStopButtonFactory, DeploymentOptionsControllersFactory optionsControllersFactory) { | ||
| this.startStopButtonFactory = startStopButtonFactory; | ||
| this.optionsControllersFactory = optionsControllersFactory; | ||
| } | ||
|
|
||
| @FXML | ||
| @SuppressWarnings("PMD.UnusedPrivateMethod") | ||
| private void initialize() { | ||
| final Supplier<OutputStream> out = () -> | ||
| new PrintStream(new StreamToTextArea(stdOutStreamTextArea).reset(), false); | ||
| final Supplier<OutputStream> err = () -> | ||
| new PrintStream(new StreamToTextArea(stdErrStreamTextArea).reset(), false); | ||
| deploymentMethods.getPanes().addAll( | ||
| optionsControllersFactory | ||
| .createControllers(this::onDeploy, out, err) | ||
| .stream() | ||
| .map(DeploymentOptionsController::getRoot) | ||
| .collect(Collectors.toList())); | ||
| } | ||
|
|
||
| /** | ||
| * Calls {@link DeployedInstanceManager#deploy()} and displays the result to the UI. | ||
| * @param manager The manager to call deploy on | ||
| */ | ||
| private void onDeploy(DeployedInstanceManager manager) { | ||
| Platform.runLater(() -> { | ||
| progressIndicator.setProgress(0); | ||
| deploymentMethods.setDisable(true); | ||
| }); | ||
| manager.deploy() | ||
| .fail(throwable -> { | ||
| Platform.runLater(() -> { | ||
| stdErrStreamTextArea.setText("Failed to deploy\n" + | ||
| Throwables.getStackTraceAsString(throwable) | ||
| ); | ||
| deploymentMethods.setDisable(false); | ||
| }); | ||
| }) | ||
| .progress(percent -> { | ||
| Platform.runLater(() -> progressIndicator.setProgress(percent)); | ||
| }) | ||
| .done(deployedManager -> { | ||
| Platform.runLater(() -> { | ||
| controlsBox.getChildren().add(startStopButtonFactory.create(deployedManager)); | ||
| deploymentMethods.setDisable(true); | ||
| progressIndicator.setProgress(-1); | ||
| }); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| public DialogPane getRoot() { | ||
| return root; | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
132 changes: 132 additions & 0 deletions
132
ui/src/main/java/edu/wpi/grip/ui/deployment/DeploymentOptionsController.java
This file contains hidden or 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,132 @@ | ||
| package edu.wpi.grip.ui.deployment; | ||
|
|
||
| import edu.wpi.grip.ui.annotations.ParametrizedController; | ||
| import edu.wpi.grip.ui.util.SupplierWithIO; | ||
| import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager; | ||
| import javafx.application.Platform; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.ProgressIndicator; | ||
| import javafx.scene.control.TitledPane; | ||
| import javafx.scene.layout.GridPane; | ||
| import org.jdeferred.DeferredCallable; | ||
| import org.jdeferred.DeferredManager; | ||
| import org.jdeferred.Promise; | ||
| import org.jdeferred.impl.DefaultDeferredManager; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.InetAddress; | ||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * A simple UI component that can be used to display options for deploying to a remote device using | ||
| * asynchronous callbacks. | ||
| */ | ||
| @ParametrizedController(url = "DeploymentOptions.fxml") | ||
| public abstract class DeploymentOptionsController { | ||
|
|
||
| @FXML | ||
| private TitledPane root; | ||
|
|
||
| @FXML | ||
| private GridPane optionsGrid; | ||
|
|
||
| @FXML | ||
| private Label deployErrorText; | ||
|
|
||
| @FXML | ||
| private ProgressIndicator deploySpinner; | ||
|
|
||
| @FXML | ||
| private Button deployButton; | ||
|
|
||
| private final String title; | ||
| private final Consumer<DeployedInstanceManager> onDeployCallback; | ||
|
|
||
| DeploymentOptionsController(String title, Consumer<DeployedInstanceManager> onDeployCallback) { | ||
| this.title = title; | ||
| this.onDeployCallback = onDeployCallback; | ||
| } | ||
|
|
||
| @FXML | ||
| protected final void initialize() { | ||
| root.setText(title); | ||
| postInit(); | ||
| } | ||
|
|
||
| /** | ||
| * Called after the initialize method | ||
| */ | ||
| protected abstract void postInit(); | ||
|
|
||
| protected abstract Promise<DeployedInstanceManager, String, String> onDeploy(); | ||
|
|
||
| @FXML | ||
| @SuppressWarnings("PMD.UnusedPrivateMethod") | ||
| private void deploy() { | ||
|
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.
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.
|
||
| deploySpinner.setVisible(true); | ||
| deployButton.setDisable(true); | ||
| onDeploy() | ||
| .progress(this::setErrorText) | ||
| .fail((text) -> { | ||
| setErrorText(text); | ||
| Platform.runLater(() -> { | ||
| deploySpinner.setVisible(false); | ||
| deployButton.setDisable(false); | ||
| }); | ||
| }) | ||
| .done((t) -> { | ||
| onDeployCallback.accept(t); | ||
| Platform.runLater(() -> { | ||
| deploySpinner.setVisible(false); | ||
| deployButton.setDisable(false); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| private void setErrorText(String text) { | ||
| Platform.runLater(() -> { | ||
| deployErrorText.setText(text); | ||
| root.requestLayout(); | ||
| }); | ||
| } | ||
|
|
||
| protected GridPane getOptionsGrid() { | ||
| return optionsGrid; | ||
| } | ||
|
|
||
| protected Button getDeployButton() { | ||
| return deployButton; | ||
| } | ||
|
|
||
| public TitledPane getRoot() { | ||
| return root; | ||
| } | ||
|
|
||
| /** | ||
| * Checks that an InetAddress is reachable asynchronously | ||
| * | ||
| * @param address The address supplier to check | ||
| * @return A promise that is resolved when the InetAddress is determined to be reachable. | ||
| */ | ||
| protected static Promise<InetAddress, Throwable, String> checkInetAddressReachable(SupplierWithIO<InetAddress> address) { | ||
| final DeferredManager checkAddressDeferred = new DefaultDeferredManager(); | ||
| return checkAddressDeferred.when(new DeferredCallable<InetAddress, String>() { | ||
| @Override | ||
| public InetAddress call() throws IOException { | ||
| final InetAddress inetAddress = address.getWithIO(); | ||
| final int attemptCount = 5; | ||
| for (int i = 0; i < attemptCount; i++) { | ||
| if (inetAddress.isReachable(1000)) { | ||
| return inetAddress; | ||
| } else { | ||
| notify("Attempt " + i + "/" + attemptCount + " failed"); | ||
| } | ||
| } | ||
| throw new IOException("Failed to connect"); | ||
| } | ||
| }); | ||
|
|
||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
ui/src/main/java/edu/wpi/grip/ui/deployment/DeploymentOptionsControllersFactory.java
This file contains hidden or 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,35 @@ | ||
| package edu.wpi.grip.ui.deployment; | ||
|
|
||
|
|
||
| import com.google.inject.Inject; | ||
| import com.google.inject.Singleton; | ||
| import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager; | ||
|
|
||
| import java.io.OutputStream; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
|
|
||
| @Singleton | ||
| public class DeploymentOptionsControllersFactory { | ||
|
|
||
| private final FRCDeploymentOptionsController.Factory frcDeploymentOptionsControllerFactory; | ||
| private final FRCAdvancedDeploymentOptionsController.Factory frcAdvancedDeploymentOptionsControllerFactory; | ||
|
|
||
| @Inject | ||
| DeploymentOptionsControllersFactory( | ||
| FRCDeploymentOptionsController.Factory frcDeploymentOptionsControllerFactory, | ||
| FRCAdvancedDeploymentOptionsController.Factory frcAdvancedDeploymentOptionsControllerFactory) { | ||
| this.frcDeploymentOptionsControllerFactory = frcDeploymentOptionsControllerFactory; | ||
| this.frcAdvancedDeploymentOptionsControllerFactory = frcAdvancedDeploymentOptionsControllerFactory; | ||
| } | ||
|
|
||
|
|
||
| public Collection<DeploymentOptionsController> createControllers(Consumer<DeployedInstanceManager> onDeployCallback, Supplier<OutputStream> stdOut, Supplier<OutputStream> stdErr) { | ||
| return Arrays.asList( | ||
| frcDeploymentOptionsControllerFactory.create(onDeployCallback, stdOut, stdErr), | ||
| frcAdvancedDeploymentOptionsControllerFactory.create(onDeployCallback, stdOut, stdErr) | ||
| ); | ||
| } | ||
| } |
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.
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.