From 0197f4572bf38ddc98bc61b3b4b639d3ad074ed0 Mon Sep 17 00:00:00 2001 From: Hiroyuki Eguchi Date: Sat, 11 Feb 2017 13:15:08 +0900 Subject: [PATCH] Add load/unload actions Add load and unload action into Model Panel. Change-Id: Idcd698a47df9c974b5ea063cf3760132665e570a --- meteos_ui/api/client.py | 8 +++ meteos_ui/api/rest_api.py | 8 +++ .../machine_learning/meteos.service.js | 16 +++++ .../machine_learning/models/actions.module.js | 21 ++++++ .../models/operations/load.service.js | 68 +++++++++++++++++++ .../models/operations/unload.service.js | 68 +++++++++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 meteos_ui/static/dashboard/machine_learning/models/operations/load.service.js create mode 100644 meteos_ui/static/dashboard/machine_learning/models/operations/unload.service.js diff --git a/meteos_ui/api/client.py b/meteos_ui/api/client.py index b10fc18..131516d 100644 --- a/meteos_ui/api/client.py +++ b/meteos_ui/api/client.py @@ -170,6 +170,14 @@ def model_show(request, id): return meteosclient(request).models.get(id) +def model_load(request, id): + return meteosclient(request).models.load(id) + + +def model_unload(request, id): + return meteosclient(request).models.unload(id) + + def model_evaluation_create(request, **kwargs): args = {} for (key, value) in kwargs.items(): diff --git a/meteos_ui/api/rest_api.py b/meteos_ui/api/rest_api.py index 052223b..0dbcdbf 100644 --- a/meteos_ui/api/rest_api.py +++ b/meteos_ui/api/rest_api.py @@ -193,6 +193,14 @@ class ModelActions(generic.View): """API for retrieving a single model""" url_regex = r'meteos/models/(?P[^/]+)/(?P[^/]+)$' + @rest_utils.ajax() + def post(self, request, id, action): + """Execute a action of the Models.""" + if action == 'load': + return client.model_load(request, id) + elif action == 'unload': + return client.model_unload(request, id) + @urls.register class Models(generic.View): diff --git a/meteos_ui/static/dashboard/machine_learning/meteos.service.js b/meteos_ui/static/dashboard/machine_learning/meteos.service.js index 4e680a7..f955c67 100644 --- a/meteos_ui/static/dashboard/machine_learning/meteos.service.js +++ b/meteos_ui/static/dashboard/machine_learning/meteos.service.js @@ -46,6 +46,8 @@ getModels: getModels, deleteModel: deleteModel, deleteModels: deleteModels, + loadModel: loadModel, + unloadModel: unloadModel, createModelEvaluation: createModelEvaluation, getModelEvaluation: getModelEvaluation, getModelEvaluations: getModelEvaluations, @@ -244,6 +246,20 @@ }); } + function loadModel(id) { + return apiService.post('/api/meteos/models/' + id + '/load') + .error(function() { + toastService.add('error', gettext('Unable to load Model')); + }); + } + + function unloadModel(id) { + return apiService.post('/api/meteos/models/' + id + '/unload') + .error(function() { + toastService.add('error', gettext('Unable to load Model')); + }); + } + ////////////////////// // ModelEvaluations // ////////////////////// diff --git a/meteos_ui/static/dashboard/machine_learning/models/actions.module.js b/meteos_ui/static/dashboard/machine_learning/models/actions.module.js index 73e5587..43e6187 100644 --- a/meteos_ui/static/dashboard/machine_learning/models/actions.module.js +++ b/meteos_ui/static/dashboard/machine_learning/models/actions.module.js @@ -30,6 +30,8 @@ 'horizon.framework.util.i18n.gettext', 'horizon.dashboard.machine_learning.models.create.service', 'horizon.dashboard.machine_learning.models.delete.service', + 'horizon.dashboard.machine_learning.models.load.service', + 'horizon.dashboard.machine_learning.models.unload.service', 'horizon.dashboard.machine_learning.models.resourceType', ]; @@ -38,6 +40,8 @@ gettext, createModelService, deleteModelService, + loadModelService, + unloadModelService, resourceType) { var modelsResourceType = registry.getResourceType(resourceType); @@ -61,6 +65,23 @@ text: gettext('Delete Models') } }); + + modelsResourceType.itemActions + .append({ + id: 'loadModelAction', + service: loadModelService, + template: { + text: gettext('Load Model') + } + }) + .append({ + id: 'unloadModelAction', + service: unloadModelService, + template: { + text: gettext('Unload Model') + } + }); + } })(); diff --git a/meteos_ui/static/dashboard/machine_learning/models/operations/load.service.js b/meteos_ui/static/dashboard/machine_learning/models/operations/load.service.js new file mode 100644 index 0000000..ab56c53 --- /dev/null +++ b/meteos_ui/static/dashboard/machine_learning/models/operations/load.service.js @@ -0,0 +1,68 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use self 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. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.machine_learning.models') + .factory('horizon.dashboard.machine_learning.models.load.service', loadModelService); + + loadModelService.$inject = [ + 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.toast.service', + 'horizon.app.core.openstack-service-api.meteos' + ]; + + /** + * @ngDoc factory + * @name horizon.dashboard.machine_learning.models.load.service + * @Description + * Start model. + */ + function loadModelService( + $qExtensions, toast, meteos + ) { + + var message = { + success: gettext('Model %s was successfully loaded.') + }; + + var service = { + initAction: initAction, + allowed: allowed, + perform: perform + }; + + return service; + + ////////////// + + // include this function in your service + // if you plan to emit events to the parent controller + function initAction() { + } + + function allowed() { + return $qExtensions.booleanAsPromise(true); + } + + function perform(selected) { + // load selected model + return meteos.loadModel(selected.id).success(function(response) { + toast.add('success', interpolate(message.success, [selected.name])); + }); + } + } +})(); diff --git a/meteos_ui/static/dashboard/machine_learning/models/operations/unload.service.js b/meteos_ui/static/dashboard/machine_learning/models/operations/unload.service.js new file mode 100644 index 0000000..fcec04f --- /dev/null +++ b/meteos_ui/static/dashboard/machine_learning/models/operations/unload.service.js @@ -0,0 +1,68 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use self 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. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.machine_learning.models') + .factory('horizon.dashboard.machine_learning.models.unload.service', unloadModelService); + + unloadModelService.$inject = [ + 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.toast.service', + 'horizon.app.core.openstack-service-api.meteos' + ]; + + /** + * @ngDoc factory + * @name horizon.dashboard.machine_learning.models.unload.service + * @Description + * Start model. + */ + function unloadModelService( + $qExtensions, toast, meteos + ) { + + var message = { + success: gettext('Model %s was successfully unloaded.') + }; + + var service = { + initAction: initAction, + allowed: allowed, + perform: perform + }; + + return service; + + ////////////// + + // include this function in your service + // if you plan to emit events to the parent controller + function initAction() { + } + + function allowed() { + return $qExtensions.booleanAsPromise(true); + } + + function perform(selected) { + // unload selected model + return meteos.unloadModel(selected.id).success(function(response) { + toast.add('success', interpolate(message.success, [selected.name])); + }); + } + } +})();