Skip to content

Commit

Permalink
Merge pull request #2380 from uProxy/gitlaura-cancel-cloud
Browse files Browse the repository at this point in the history
Adding functionality to cancel cloud creation
  • Loading branch information
gitlaura committed Apr 20, 2016
2 parents 250bb0e + fa9f713 commit 176b3e8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/generic_core/uproxy_core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export class uProxyCore implements uproxy_core_api.CoreApi {

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

private cloudInterfaces_ :{
[cloudProvider: string] :{
installer :any,
provisioner :any
}
} = {};

constructor() {
log.debug('Preparing uProxy Core');
copyPasteConnection = new remote_connection.RemoteConnection(
Expand Down Expand Up @@ -643,13 +650,16 @@ export class uProxyCore implements uproxy_core_api.CoreApi {
return Promise.reject(new Error('unsupported cloud provider'));
}

this.cloudInterfaces_[args.providerName] = this.cloudInterfaces_[args.providerName] || { installer: undefined, provisioner: undefined};
const provisionerName = CLOUD_PROVIDER_MODULE_PREFIX + args.providerName;
const provisioner = freedom[provisionerName]();
const installer = freedom['cloudinstall']();
const provisioner = this.cloudInterfaces_[args.providerName].provisioner || freedom[provisionerName]();
const installer = this.cloudInterfaces_[args.providerName].installer || freedom['cloudinstall']();
this.cloudInterfaces_[args.providerName] = { installer: installer, provisioner: provisioner};

const destroyModules = () => {
freedom[provisionerName].close(provisioner);
freedom['cloudinstall'].close(installer);
delete this.cloudInterfaces_[args.providerName];
};

switch (args.operation) {
Expand Down Expand Up @@ -709,8 +719,15 @@ export class uProxyCore implements uproxy_core_api.CoreApi {
});
});
}, (installError: any) => {
// When we cancel the cloud install we close the connection
// to the installer by destroying the modules
if (installError === 'closed') {
return Promise.reject(new Error('canceled'));
}

// Tell user if the server already exists
if (installError.errcode === "VM_AE") {
destroyModules();
return Promise.reject(new Error('server already exists'));
}

Expand Down
16 changes: 16 additions & 0 deletions src/generic_ui/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1374,5 +1374,21 @@
"REMOVING_UPROXY_CLOUD_STATUS": {
"description": "Label to indicate that we are removing a uproxy cloud server.",
"message": "Removing uProxy cloud server..."
},
"CLOUD_INSTALL_CANCEL_TITLE": {
"description": "Title shown on overlay when user cancels a cloud server install.",
"message": "Hold tight! We're canceling the creation of a cloud server."
},
"CLOUD_INSTALL_CANCEL_MESSAGE": {
"description": "Message shown on overlay when user cancels a cloud server install.",
"message": "Canceling the creation of a cloud server can take up to 2 minutes. Sorry for the wait."
},
"CLOUD_INSTALL_CANCEL_SUCCESS": {
"description": "Message shown on toast when a could server install is completed.",
"message": "Successfully canceled cloud server creation."
},
"CLOUD_INSTALL_CANCEL_FAILURE": {
"description": "Message shown on toast when a could server install fails.",
"message": "We cannot cancel the creation of your cloud server right now. You can delete the server once it's ready."
}
}
16 changes: 16 additions & 0 deletions src/generic_ui/polymer/cloud-install.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ <h1>{{ 'CLOUD_INSTALL_INSTALLING_TITLE' | $$ }}</h1>
<paper-progress id='installProgress' value='{{ ui.cloudInstallProgress }}'></paper-progress>
</div>
<p>{{ ui.cloudInstallStatus }}</p>
<uproxy-button disabled?='{{ ui.cloudInstallCancelDisabled }}' on-tap='{{ cancelCloudInstall }}'>{{ 'CANCEL' | $$ }}</uproxy-button>
</div>
</core-overlay>

Expand Down Expand Up @@ -223,6 +224,21 @@ <h1>{{ 'CLOUD_INSTALL_ERROR_EXISTING_SERVER_TITLE' | $$ }}</h1>
</div>
</core-overlay>


<core-overlay id='cancelingOverlay'>
<uproxy-app-bar color='#34AFCE' disableback="true">
{{ 'CREATE_A_CLOUD_SERVER' | $$ }}
</uproxy-app-bar>

<div class='content'>
<div class='imgWrapper'>
<img src='../../icons/cloud/error-circle-ic.svg'>
</div>
<h1>{{ 'CLOUD_INSTALL_CANCEL_TITLE' | $$ }}</h1>
<p>{{ 'CLOUD_INSTALL_CANCEL_MESSAGE' | $$ }}</p>
</div>
</core-overlay>

</template>
<script src='cloud-install.js'></script>
</polymer-element>
20 changes: 18 additions & 2 deletions src/generic_ui/polymer/cloud-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Polymer({
this.injectBoundHTML(
ui.i18nSanitizeHtml(ui.i18n_t('CLOUD_INSTALL_LOGIN_MESSAGE')),
this.$.loginMessage);


ui.cloudInstallCancelDisabled = false;
this.$.getStartedOverlay.open();
},
showDigitalOceanAccountHelpOverlay: function() {
Expand Down Expand Up @@ -60,6 +61,7 @@ Polymer({
this.$.successOverlay.close();
this.$.failureOverlay.close();
this.$.serverExistsOverlay.close();
this.$.cancelingOverlay.close();
},
loginTapped: function() {
if (!this.$.installingOverlay.opened) {
Expand All @@ -79,14 +81,15 @@ Polymer({
// TODO: Figure out why e.message is not set
if (e === 'Error: server already exists') {
this.$.serverExistsOverlay.open();
} else {
} else if (e !== 'Error: canceled') {
this.$.failureOverlay.open();
}
});
},
removeServerAndInstallAgain: function() {
this.closeOverlays();
ui.cloudInstallStatus = ui.i18n_t('REMOVING_UPROXY_CLOUD_STATUS');
ui.cloudInstallCancelDisabled = true;
this.$.installingOverlay.open();
// Destroy uProxy cloud server
return ui.cloudUpdate({
Expand All @@ -108,6 +111,19 @@ Polymer({
return this.loginTapped();
});
},
cancelCloudInstall: function() {
this.$.cancelingOverlay.open();
return ui.cloudUpdate({
operation: uproxy_core_api.CloudOperationType.CLOUD_DESTROY,
providerName: DEFAULT_PROVIDER
}).then(() => {
this.closeOverlays();
ui.toastMessage = ui.i18n_t('CLOUD_INSTALL_CANCEL_SUCCESS');
}).catch((e: Error) => {
this.$.cancelingOverlay.close();
ui.toastMessage = ui.i18n_t('CLOUD_INSTALL_CANCEL_FAILURE');
});
},
select: function(e: Event, d: Object, input: HTMLInputElement) {
input.focus();
input.select();
Expand Down
4 changes: 4 additions & 0 deletions src/generic_ui/scripts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class UserInterface implements ui_constants.UiApi {

public cloudInstallStatus :string = '';
public cloudInstallProgress = 0;
public cloudInstallCancelDisabled :boolean = false;

/**
* UI must be constructed with hooks to Notifications and Core.
Expand Down Expand Up @@ -307,6 +308,9 @@ export class UserInterface implements ui_constants.UiApi {

core.onUpdate(uproxy_core_api.Update.CLOUD_INSTALL_STATUS, (status: string) => {
this.cloudInstallStatus = this.i18n_t(status);
// Don't allow user to cancel during last stage of cloud install
// because user may have already accepted cloud invitation
this.cloudInstallCancelDisabled = (status === 'CLOUD_INSTALL_STATUS_CONFIGURING_SSH') ? true : false;
});

core.onUpdate(uproxy_core_api.Update.CLOUD_INSTALL_PROGRESS, (progress: number) => {
Expand Down

0 comments on commit 176b3e8

Please sign in to comment.