diff options
author | Stas Negara <snegara@google.com> | 2015-07-28 14:27:51 -0700 |
---|---|---|
committer | Stas Negara <snegara@google.com> | 2015-07-28 14:27:51 -0700 |
commit | 25352a696d220f3258bf9029ea92d01b2487c2a2 (patch) | |
tree | 6dcba1def3a8f26b11b1369a04cd8d4de7fe3d69 | |
parent | 9cc831cd73596f2244d2a85a2b15988baafe5998 (diff) | |
download | testing-25352a696d220f3258bf9029ea92d01b2487c2a2.tar.gz |
Closing blank VNC Viewer kills the cloud device.
Also, it removes the corresponding device from the list of the
ghost devices.
Change-Id: I0df64ebc75284e611301304b9ee519225a1c71c8
3 files changed, 52 insertions, 9 deletions
diff --git a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java index 87614b2..23d7386 100644 --- a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java +++ b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java @@ -49,6 +49,7 @@ import com.google.gct.testing.results.GoogleCloudTestResultsConnectionUtil; import com.google.gct.testing.results.GoogleCloudTestingResultParser; import com.google.gct.testing.util.CloudTestingTracking; import com.google.gct.testing.vnc.BlankVncViewer; +import com.google.gct.testing.vnc.BlankVncViewerCallback; import com.intellij.execution.DefaultExecutionResult; import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionResult; @@ -337,13 +338,26 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider { "The returned cloud device is null\n\n"); } - GhostCloudDevice ghostCloudDevice = new GhostCloudDevice(createdDevice); + final String deviceId = createdDevice.getId(); + final GhostCloudDevice ghostCloudDevice = new GhostCloudDevice(createdDevice); synchronized (ghostCloudDevices) { ghostCloudDevices.add(ghostCloudDevice); } String configurationName = ConfigurationInstance.parseFromEncodedString(ghostCloudDevice.getEncodedConfigurationInstance()).getResultsViewerDisplayString(); - BlankVncViewer blankVncViewer = BlankVncViewer.showBlankVncViewer(configurationName); + BlankVncViewer blankVncViewer = BlankVncViewer.showBlankVncViewer(configurationName, new BlankVncViewerCallback() { + @Override + public void viewerClosed() { + try { + getTest().projects().devices().delete(cloudProjectId, deviceId).execute(); + } catch (Exception e) { + e.printStackTrace(); + } + synchronized (ghostCloudDevices) { + ghostCloudDevices.remove(ghostCloudDevice); + } + } + }); final long POLLING_INTERVAL = 10 * 1000; // 10 seconds final long INITIAL_TIMEOUT = 10 * 60 * 1000; // 10 minutes long stopTime = System.currentTimeMillis() + INITIAL_TIMEOUT; @@ -351,7 +365,13 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider { File dir = new File(sdkPath); try { while (System.currentTimeMillis() < stopTime) { - createdDevice = getTest().projects().devices().get(cloudProjectId, createdDevice.getId()).execute(); + synchronized (ghostCloudDevices) { + if (!ghostCloudDevices.contains(ghostCloudDevice)) { + // Blank VNC Viewer was closed, so stop waiting for the device. + return; + } + } + createdDevice = getTest().projects().devices().get(cloudProjectId, deviceId).execute(); System.out.println("Polling for device... (time: " + System.currentTimeMillis() + ", status: " + createdDevice.getState() + ")"); if (createdDevice.getState().equals("DEVICE_ERROR")) { CloudTestingUtils.showErrorMessage(null, "Error launching a cloud device", "Failed to launch a cloud device!\n" + @@ -392,11 +412,11 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider { } CloudTestingUtils.showErrorMessage(null, "Timed out connecting to a cloud device", "Timed out connecting to a cloud device!\n" + "Timed out connecting to a cloud device:\n\n" + - createdDevice.getId()); + deviceId); } catch (IOException e) { - showCloudDevicePollingError(e, createdDevice.getId()); + showCloudDevicePollingError(e, deviceId); } catch (InterruptedException e) { - showCloudDevicePollingError(e, createdDevice.getId()); + showCloudDevicePollingError(e, deviceId); } finally { synchronized (ghostCloudDevices) { ghostCloudDevices.remove(ghostCloudDevice); diff --git a/src/com/google/gct/testing/vnc/BlankVncViewer.java b/src/com/google/gct/testing/vnc/BlankVncViewer.java index 49f9d82..c7b41bc 100644 --- a/src/com/google/gct/testing/vnc/BlankVncViewer.java +++ b/src/com/google/gct/testing/vnc/BlankVncViewer.java @@ -23,11 +23,13 @@ import java.awt.event.WindowListener; public class BlankVncViewer extends JApplet implements Runnable { private final String myConfigurationName; + private final BlankVncViewerCallback myBlankVncViewerCallback; private JFrame blankFrame; private WindowListener exitListener; - public BlankVncViewer(String configurationName) { + public BlankVncViewer(String configurationName, BlankVncViewerCallback blankVncViewerCallback) { myConfigurationName = configurationName; + myBlankVncViewerCallback = blankVncViewerCallback; exitListener = new WindowAdapter() { @Override @@ -38,6 +40,7 @@ public class BlankVncViewer extends JApplet implements Runnable { null, null); if (confirm == 0) { System.out.println("Exiting blank VNC Viewer"); + myBlankVncViewerCallback.viewerClosed(); blankFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } } @@ -64,8 +67,8 @@ public class BlankVncViewer extends JApplet implements Runnable { blankFrame.dispatchEvent(new WindowEvent(blankFrame, WindowEvent.WINDOW_CLOSING)); } - public static BlankVncViewer showBlankVncViewer(String configurationName) { - BlankVncViewer blankViewer = new BlankVncViewer(configurationName); + public static BlankVncViewer showBlankVncViewer(String configurationName, BlankVncViewerCallback blankVncViewerCallback) { + BlankVncViewer blankViewer = new BlankVncViewer(configurationName, blankVncViewerCallback); SwingUtilities.invokeLater(blankViewer); return blankViewer; } diff --git a/src/com/google/gct/testing/vnc/BlankVncViewerCallback.java b/src/com/google/gct/testing/vnc/BlankVncViewerCallback.java new file mode 100644 index 0000000..199aec5 --- /dev/null +++ b/src/com/google/gct/testing/vnc/BlankVncViewerCallback.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed 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 com.google.gct.testing.vnc; + +public interface BlankVncViewerCallback { + public void viewerClosed(); +} |