From 2f02d62405a64a27e1508c6bb4a49c6097488b02 Mon Sep 17 00:00:00 2001 From: urcan Date: Wed, 25 Nov 2015 15:41:00 +0100 Subject: [PATCH] deploy using settings directive is implemented --- src/app/frontend/deploy/deploy.html | 63 +++------ src/app/frontend/deploy/deploy_controller.js | 83 ++---------- src/app/frontend/deploy/deploy_module.js | 4 +- .../frontend/deploy/deployfromsettings.html | 49 +++++++ .../deploy/deployfromsettings_controller.js | 126 ++++++++++++++++++ .../deploy/deployfromsettings_directive.js | 33 +++++ 6 files changed, 238 insertions(+), 120 deletions(-) create mode 100644 src/app/frontend/deploy/deployfromsettings.html create mode 100644 src/app/frontend/deploy/deployfromsettings_controller.js create mode 100644 src/app/frontend/deploy/deployfromsettings_directive.js diff --git a/src/app/frontend/deploy/deploy.html b/src/app/frontend/deploy/deploy.html index c76fa8dc0..06df4579a 100644 --- a/src/app/frontend/deploy/deploy.html +++ b/src/app/frontend/deploy/deploy.html @@ -17,8 +17,8 @@ limitations under the License.

Deploy a Containerized App

-
- + + @@ -30,50 +30,21 @@ limitations under the License. Upload a YAML or JSON file - - - - - - - - -
- - - - - - - - - - - - - {{protocol}} - - - -
- - - - - {{namespace}} - - - Create a new namespace... - - - - - Expose service externally - - - - - + + + + + + + {{namespace}} + + + Create a new namespace... + + + Deploy diff --git a/src/app/frontend/deploy/deploy_controller.js b/src/app/frontend/deploy/deploy_controller.js index 22b5a21a4..0ea19f56d 100644 --- a/src/app/frontend/deploy/deploy_controller.js +++ b/src/app/frontend/deploy/deploy_controller.js @@ -13,7 +13,6 @@ // limitations under the License. import {stateName as zerostate} from 'zerostate/zerostate_state'; -import {stateName as replicasetliststate} from 'replicasetlist/replicasetlist_state'; import showNamespaceDialog from 'deploy/createnamespace_dialog'; /** @@ -34,25 +33,6 @@ export default class DeployController { /** @export {string} */ this.name = ''; - /** @export {string} */ - this.containerImage = ''; - - /** @export {number} */ - this.replicas = 1; - - /** @export {string} */ - this.description = ''; - - /** - * List of supported protocols. - * TODO(bryk): Do not hardcode the here, move to backend. - * @const @export {!Array} - */ - this.protocols = ['TCP', 'UDP']; - - /** @export {!Array} */ - this.portMappings = [this.newEmptyPortMapping_(this.protocols[0])]; - /** * List of available namespaces. * @export {!Array} @@ -65,9 +45,6 @@ export default class DeployController { */ this.namespace = this.namespaces.length > 0 ? this.namespaces[0] : undefined; - /** @export {boolean} */ - this.isExternal = false; - /** @private {!angular.$resource} */ this.resource_ = $resource; @@ -82,42 +59,23 @@ export default class DeployController { /** @private {boolean} */ this.isDeployInProgress_ = false; + + /** + * Contains the selected directive's controller which has its own deploy logic + * + * @export {{deploy:function()}} + */ + this.detail = {deploy: function() {}}; } /** - * Deploys the application based on the sate of the controller. + * Notifies the child scopes to call their deploy methods. * * @export */ - deploy() { - // TODO(bryk): Validate input data before sending to the server. - - /** @type {!backendApi.AppDeploymentSpec} */ - let appDeploymentSpec = { - containerImage: this.containerImage, - isExternal: this.isExternal, - name: this.name, - description: this.description, - portMappings: this.portMappings.filter(this.isPortMappingEmpty_), - replicas: this.replicas, - namespace: this.namespace, - }; - - /** @type {!angular.Resource} */ - let resource = this.resource_('/api/appdeployments'); - + deployBySelection() { this.isDeployInProgress_ = true; - resource.save( - appDeploymentSpec, - (savedConfig) => { - this.isDeployInProgress_ = false; - this.log_.info('Successfully deployed application: ', savedConfig); - this.state_.go(replicasetliststate); - }, - (err) => { - this.isDeployInProgress_ = false; - this.log_.error('Error deploying application:', err); - }); + this.detail.deploy().finally(() => { this.isDeployInProgress_ = false; }); } /** @@ -157,25 +115,4 @@ export default class DeployController { * @export */ cancel() { this.state_.go(zerostate); } - - /** - * @param {string} defaultProtocol - * @return {!backendApi.PortMapping} - * @private - */ - newEmptyPortMapping_(defaultProtocol) { - return { - port: null, - targetPort: null, - protocol: defaultProtocol, - }; - } - - /** - * Returns true when the given port mapping hasn't been filled by the user, i.e., is empty. - * @param {!backendApi.PortMapping} portMapping - * @return {boolean} - * @private - */ - isPortMappingEmpty_(portMapping) { return !!portMapping.port && !!portMapping.targetPort; } } diff --git a/src/app/frontend/deploy/deploy_module.js b/src/app/frontend/deploy/deploy_module.js index ebb70c7a6..642b5d9ff 100644 --- a/src/app/frontend/deploy/deploy_module.js +++ b/src/app/frontend/deploy/deploy_module.js @@ -13,6 +13,7 @@ // limitations under the License. import stateConfig from './deploy_state'; +import deployFromSettingsDirective from './deployfromsettings_directive'; /** * Angular module for the deploy view. @@ -25,4 +26,5 @@ export default angular.module( 'ngMaterial', 'ui.router', ]) - .config(stateConfig); + .config(stateConfig) + .directive('deployFromSettings', deployFromSettingsDirective); diff --git a/src/app/frontend/deploy/deployfromsettings.html b/src/app/frontend/deploy/deployfromsettings.html new file mode 100644 index 000000000..8c44b8d32 --- /dev/null +++ b/src/app/frontend/deploy/deployfromsettings.html @@ -0,0 +1,49 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + {{protocol}} + + + +
+ + Expose service externally + + + + + diff --git a/src/app/frontend/deploy/deployfromsettings_controller.js b/src/app/frontend/deploy/deployfromsettings_controller.js new file mode 100644 index 000000000..9ea169dea --- /dev/null +++ b/src/app/frontend/deploy/deployfromsettings_controller.js @@ -0,0 +1,126 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// 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. + +import {stateName as replicasetliststate} from 'replicasetlist/replicasetlist_state'; + +/** + * Controller for the deploy from settings directive. + * + * @final + */ +export default class DeployFromSettingsController { + /** + * @param {!angular.$log} $log + * @param {!ui.router.$state} $state + * @param {!angular.$resource} $resource + * @param {!angular.$q} $q + * @ngInject + */ + constructor($log, $state, $resource, $q) { + /** + * It initializes the scope output parameter + * + * @export {!DeployFromSettingsController} + */ + this.detail = this; + + /** @private {!angular.$q} */ + this.q_ = $q; + + /** @private {!angular.$resource} */ + this.resource_ = $resource; + + /** @private {!angular.$log} */ + this.log_ = $log; + + /** @private {!ui.router.$state} */ + this.state_ = $state; + + /** @export {string} */ + this.containerImage = ''; + + /** @export {number} */ + this.replicas = 1; + + /** @export {string} */ + this.description = ''; + + /** + * List of supported protocols. + * TODO(bryk): Do not hardcode the here, move to backend. + * @const @export {!Array} + */ + this.protocols = ['TCP', 'UDP']; + + /** @export {!Array} */ + this.portMappings = [this.newEmptyPortMapping_(this.protocols[0])]; + + /** @export {boolean} */ + this.isExternal = false; + } + + /** + * Deploys the application based on the state of the controller. + * + * @export + * @return {angular.$q.Promise} + */ + deploy() { + // TODO(bryk): Validate input data before sending to the server. + /** @type {!backendApi.AppDeploymentSpec} */ + let appDeploymentSpec = { + containerImage: this.containerImage, + isExternal: this.isExternal, + name: this.name, + description: this.description, + portMappings: this.portMappings.filter(this.isPortMappingEmpty_), + replicas: this.replicas, + namespace: this.namespace, + }; + + let defer = this.q_.defer(); + + /** @type {!angular.Resource} */ + let resource = this.resource_('/api/appdeployments'); + resource.save( + appDeploymentSpec, + (savedConfig) => { + defer.resolve(savedConfig); // Progress ends + this.log_.info('Successfully deployed application: ', savedConfig); + this.state_.go(replicasetliststate); + }, + (err) => { + defer.reject(err); // Progress ends + this.log_.error('Error deploying application:', err); + }); + return defer.promise; + } + + /** + * @param {string} defaultProtocol + * @return {!backendApi.PortMapping} + * @private + */ + newEmptyPortMapping_(defaultProtocol) { + return {port: null, targetPort: null, protocol: defaultProtocol}; + } + + /** + * Returns true when the given port mapping hasn't been filled by the user, i.e., is empty. + * @param {!backendApi.PortMapping} portMapping + * @return {boolean} + * @private + */ + isPortMappingEmpty_(portMapping) { return !!portMapping.port && !!portMapping.targetPort; } +} diff --git a/src/app/frontend/deploy/deployfromsettings_directive.js b/src/app/frontend/deploy/deployfromsettings_directive.js new file mode 100644 index 000000000..7c3834ed9 --- /dev/null +++ b/src/app/frontend/deploy/deployfromsettings_directive.js @@ -0,0 +1,33 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// 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. + +import DeployFromSettingsController from './deployfromsettings_controller'; + +/** + * Returns directive definition object for the deploy from settings directive. + * @return {!angular.Directive} + */ +export default function deployFromSettingsDirective() { + return { + scope: {}, + bindToController: { + name: '=', + namespace: '=', + detail: '=', + }, + controller: DeployFromSettingsController, + controllerAs: 'ctrl', + templateUrl: 'deploy/deployfromsettings.html', + }; +} -- GitLab