Skip to content

Commit 1499d1b

Browse files
committed
Adding cloud cancel functionality
1 parent 250bb0e commit 1499d1b

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

src/generic_core/uproxy_core.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export class uProxyCore implements uproxy_core_api.CoreApi {
7070

7171
private connectedNetworks_ = new StoredValue<string[]>('connectedNetworks', []);
7272

73+
private cloudInterfaces_ :{
74+
[cloudProvider: string] :{
75+
installer :any,
76+
provisioner :any
77+
}
78+
} = {};
79+
7380
constructor() {
7481
log.debug('Preparing uProxy Core');
7582
copyPasteConnection = new remote_connection.RemoteConnection(
@@ -643,13 +650,16 @@ export class uProxyCore implements uproxy_core_api.CoreApi {
643650
return Promise.reject(new Error('unsupported cloud provider'));
644651
}
645652

653+
this.cloudInterfaces_[args.providerName] = this.cloudInterfaces_[args.providerName] || { installer: undefined, provisioner: undefined};
646654
const provisionerName = CLOUD_PROVIDER_MODULE_PREFIX + args.providerName;
647-
const provisioner = freedom[provisionerName]();
648-
const installer = freedom['cloudinstall']();
655+
const provisioner = this.cloudInterfaces_[args.providerName].provisioner || freedom[provisionerName]();
656+
const installer = this.cloudInterfaces_[args.providerName].installer || freedom['cloudinstall']();
657+
this.cloudInterfaces_[args.providerName] = { installer: installer, provisioner: provisioner};
649658

650659
const destroyModules = () => {
651660
freedom[provisionerName].close(provisioner);
652661
freedom['cloudinstall'].close(installer);
662+
delete this.cloudInterfaces_[args.providerName];
653663
};
654664

655665
switch (args.operation) {
@@ -709,8 +719,15 @@ export class uProxyCore implements uproxy_core_api.CoreApi {
709719
});
710720
});
711721
}, (installError: any) => {
722+
// When we cancel the cloud install we close the connection
723+
// to the installer by destroying the modules
724+
if (installError === 'closed') {
725+
return Promise.reject(new Error('canceled'));
726+
}
727+
712728
// Tell user if the server already exists
713729
if (installError.errcode === "VM_AE") {
730+
destroyModules();
714731
return Promise.reject(new Error('server already exists'));
715732
}
716733

src/generic_ui/locales/en/messages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,5 +1374,21 @@
13741374
"REMOVING_UPROXY_CLOUD_STATUS": {
13751375
"description": "Label to indicate that we are removing a uproxy cloud server.",
13761376
"message": "Removing uProxy cloud server..."
1377+
},
1378+
"CLOUD_INSTALL_CANCEL_TITLE": {
1379+
"description": "Title shown on overlay when user cancels a cloud server install.",
1380+
"message": "Hold tight! We're canceling the creation of a cloud server."
1381+
},
1382+
"CLOUD_INSTALL_CANCEL_MESSAGE": {
1383+
"description": "Message shown on overlay when user cancels a cloud server install.",
1384+
"message": "Canceling the creation of a cloud server can take up to 2 minutes. Sorry for the wait."
1385+
},
1386+
"CLOUD_INSTALL_CANCEL_SUCCESS": {
1387+
"description": "Message shown on toast when a could server install is completed.",
1388+
"message": "Successfully canceled cloud server creation."
1389+
},
1390+
"CLOUD_INSTALL_CANCEL_FAILURE": {
1391+
"description": "Message shown on toast when a could server install fails.",
1392+
"message": "We cannot cancel the creation of your cloud server right now. You can delete the server once it's ready."
13771393
}
13781394
}

src/generic_ui/polymer/cloud-install.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ <h1>{{ 'CLOUD_INSTALL_INSTALLING_TITLE' | $$ }}</h1>
163163
<paper-progress id='installProgress' value='{{ ui.cloudInstallProgress }}'></paper-progress>
164164
</div>
165165
<p>{{ ui.cloudInstallStatus }}</p>
166+
<uproxy-button disabled?='{{ ui.cloudInstallCancelDisabled }}' on-tap='{{ cancelCloudInstall }}'>{{ 'CANCEL' | $$ }}</uproxy-button>
166167
</div>
167168
</core-overlay>
168169

@@ -223,6 +224,21 @@ <h1>{{ 'CLOUD_INSTALL_ERROR_EXISTING_SERVER_TITLE' | $$ }}</h1>
223224
</div>
224225
</core-overlay>
225226

227+
228+
<core-overlay id='cancelingOverlay'>
229+
<uproxy-app-bar color='#34AFCE' disableback="true">
230+
{{ 'CREATE_A_CLOUD_SERVER' | $$ }}
231+
</uproxy-app-bar>
232+
233+
<div class='content'>
234+
<div class='imgWrapper'>
235+
<img src='../../icons/cloud/error-circle-ic.svg'>
236+
</div>
237+
<h1>{{ 'CLOUD_INSTALL_CANCEL_TITLE' | $$ }}</h1>
238+
<p>{{ 'CLOUD_INSTALL_CANCEL_MESSAGE' | $$ }}</p>
239+
</div>
240+
</core-overlay>
241+
226242
</template>
227243
<script src='cloud-install.js'></script>
228244
</polymer-element>

src/generic_ui/polymer/cloud-install.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ Polymer({
6060
this.$.successOverlay.close();
6161
this.$.failureOverlay.close();
6262
this.$.serverExistsOverlay.close();
63+
this.$.cancelingOverlay.close();
6364
},
6465
loginTapped: function() {
6566
if (!this.$.installingOverlay.opened) {
6667
this.closeOverlays();
6768
ui.cloudInstallStatus = '';
69+
ui.cloudInstallCancelDisabled = false;
6870
this.$.installingOverlay.open();
6971
}
7072
ui.cloudUpdate({
@@ -79,14 +81,15 @@ Polymer({
7981
// TODO: Figure out why e.message is not set
8082
if (e === 'Error: server already exists') {
8183
this.$.serverExistsOverlay.open();
82-
} else {
84+
} else if (e !== 'Error: canceled') {
8385
this.$.failureOverlay.open();
8486
}
8587
});
8688
},
8789
removeServerAndInstallAgain: function() {
8890
this.closeOverlays();
8991
ui.cloudInstallStatus = ui.i18n_t('REMOVING_UPROXY_CLOUD_STATUS');
92+
ui.cloudInstallCancelDisabled = true;
9093
this.$.installingOverlay.open();
9194
// Destroy uProxy cloud server
9295
return ui.cloudUpdate({
@@ -108,6 +111,19 @@ Polymer({
108111
return this.loginTapped();
109112
});
110113
},
114+
cancelCloudInstall: function() {
115+
this.$.cancelingOverlay.open();
116+
return ui.cloudUpdate({
117+
operation: uproxy_core_api.CloudOperationType.CLOUD_DESTROY,
118+
providerName: DEFAULT_PROVIDER
119+
}).then(() => {
120+
this.closeOverlays();
121+
ui.toastMessage = ui.i18n_t('CLOUD_INSTALL_CANCEL_SUCCESS');
122+
}).catch((e: Error) => {
123+
this.$.cancelingOverlay.close();
124+
ui.toastMessage = ui.i18n_t('CLOUD_INSTALL_CANCEL_FAILURE');
125+
});
126+
},
111127
select: function(e: Event, d: Object, input: HTMLInputElement) {
112128
input.focus();
113129
input.select();

src/generic_ui/scripts/ui.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class UserInterface implements ui_constants.UiApi {
132132

133133
public cloudInstallStatus :string = '';
134134
public cloudInstallProgress = 0;
135+
public cloudInstallCancelDisabled :boolean = false;
135136

136137
/**
137138
* UI must be constructed with hooks to Notifications and Core.
@@ -311,6 +312,9 @@ export class UserInterface implements ui_constants.UiApi {
311312

312313
core.onUpdate(uproxy_core_api.Update.CLOUD_INSTALL_PROGRESS, (progress: number) => {
313314
this.cloudInstallProgress = progress;
315+
// Don't allow user to cancel during last stage of cloud install
316+
// because user may have already accepted cloud invitation
317+
this.cloudInstallCancelDisabled = (status === 'CLOUD_INSTALL_STATUS_CONFIGURING_SSH') ? true : false;
314318
});
315319

316320
browserApi.on('copyPasteUrlData', this.handleCopyPasteUrlData);

0 commit comments

Comments
 (0)