Add load/unload actions

Add load and unload action into Model Panel.

Change-Id: Idcd698a47df9c974b5ea063cf3760132665e570a
This commit is contained in:
Hiroyuki Eguchi 2017-02-11 13:15:08 +09:00
parent f954622ae2
commit 0197f4572b
6 changed files with 189 additions and 0 deletions

View File

@ -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():

View File

@ -193,6 +193,14 @@ class ModelActions(generic.View):
"""API for retrieving a single model"""
url_regex = r'meteos/models/(?P<id>[^/]+)/(?P<action>[^/]+)$'
@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):

View File

@ -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 //
//////////////////////

View File

@ -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')
}
});
}
})();

View File

@ -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]));
});
}
}
})();

View File

@ -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]));
});
}
}
})();