diff --git a/src/flow/lib/LifeCycleManager.rb b/src/flow/lib/LifeCycleManager.rb index b06a0fd319..c9f561cc6c 100644 --- a/src/flow/lib/LifeCycleManager.rb +++ b/src/flow/lib/LifeCycleManager.rb @@ -858,13 +858,24 @@ class ServiceLCM rc = @srv_pool.get(service_id, client) do |service| service.remove_role(role_name) - service.set_state(Service::STATE['RUNNING']) + if service.all_roles_done? + rc = service.delete_networks - rc = service.update + if rc && !rc.empty? + Log.info LOG_COMP, 'Error trying to delete '\ + "Virtual Networks #{rc}" + end - return rc if OpenNebula.is_error?(rc) + service.delete + else + service.set_state(Service::STATE['RUNNING']) - @wd.add_service(service) if service.all_roles_running? + rc = service.update + + return rc if OpenNebula.is_error?(rc) + + @wd.add_service(service) if service.all_roles_running? + end end Log.error LOG_COMP, rc.message if OpenNebula.is_error?(rc) diff --git a/src/sunstone/models/sunstone_guac.rb b/src/sunstone/models/sunstone_guac.rb index c009d52c79..b824bd2ae8 100644 --- a/src/sunstone/models/sunstone_guac.rb +++ b/src/sunstone/models/sunstone_guac.rb @@ -26,9 +26,9 @@ require 'openssl' require 'sunstone_remotes' if !ONE_LOCATION - VAR_LOCATION = '/var/lib/one/' + VAR_LOCATION ||= '/var/lib/one/' else - VAR_LOCATION = ONE_LOCATION + '/var/' + VAR_LOCATION ||= ONE_LOCATION + '/var/' end FIREEDGE_KEY = VAR_LOCATION + '/.one/fireedge_key' diff --git a/src/sunstone/public/app/opennebula/role.js b/src/sunstone/public/app/opennebula/role.js index f39fd33e72..dd9de2d3bf 100644 --- a/src/sunstone/public/app/opennebula/role.js +++ b/src/sunstone/public/app/opennebula/role.js @@ -189,6 +189,44 @@ define(function(require) { } }); }, + "remove" : function(params) { + var request = OpenNebulaHelper.request(RESOURCE, "remove", params.data.id); + + $.ajax({ + url: PATH + "/" + String(params.data.id) + "/role_action", + type: "POST", + dataType: "json", + contentType: "application/json; charset=utf-8", + data: JSON.stringify(params.data.extra_param), + success: function(response) { + return params.success ? params.success(request, response) : null; + }, + error: function(response) { + response.status === 201 + ? params.success ? params.success(request, response) : null + : params.error ? params.error(request, OpenNebulaError(response)) : null; + } + }); + }, + "add" : function(params) { + var request = OpenNebulaHelper.request(RESOURCE, "add", params.data.id); + + $.ajax({ + url: PATH + "/" + String(params.data.id) + "/role_action", + type: "POST", + dataType: "json", + contentType: "application/json; charset=utf-8", + data: JSON.stringify(params.data.extra_param), + success: function(response) { + return params.success ? params.success(request, response) : null; + }, + error: function(response) { + response.status === 201 + ? params.success ? params.success(request, response) : null + : params.error ? params.error(request, OpenNebulaError(response)) : null; + } + }); + }, } return Role; diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab.js b/src/sunstone/public/app/tabs/oneflow-services-tab.js index 0c0a695656..a18c668338 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab.js @@ -26,6 +26,7 @@ define(function(require) { var _dialogs = [ require('./oneflow-services-tab/dialogs/scale'), + require('./oneflow-services-tab/dialogs/add'), ]; var _panels = [ diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js b/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js index 8a1d2dcc5f..b08109016b 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js @@ -29,6 +29,8 @@ define(function(require) { var ROLES_PANEL_ID = require('./panels/roles/panelId'); var SCALE_DIALOG_ID = require('./dialogs/scale/dialogId'); + var ADD_DIALOG_ID = require('./dialogs/add/dialogId'); + var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); var UPDATE_DIALOG_ID = require('./form-panels/update/formPanelId'); @@ -317,6 +319,84 @@ define(function(require) { notify: true }, + "Role.remove_dialog" : { + type: "custom", + call: function(){ + params = roleElement(); + + if(!params.serviceId || !params.roleName) { + Notifier.onError("Select one role"); + return; + } + + var obj = { + "action": { + "perform":"remove_role", + "params" : { + "role" : params.roleName + } + } + } + + Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ + header : Locale.tr("Confirm"), + headerTabId: TAB_ID, + body : "", + question : Locale.tr("Are you sure you want to delete the role") + " " + params.roleName + "?", + buttons : [ + Locale.tr("Confirm"), + ], + submit : [ + function(){ + Sunstone.getDialog(CONFIRM_DIALOG_ID).hide(); + Sunstone.runAction('Role.remove', params.serviceId, obj); + return false; + } + ] + }); + Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); + Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); + } + }, + + "Role.remove" : { + type: "single", + call: OpenNebulaRole.remove, + callback : function() { + Sunstone.getDialog(CONFIRM_DIALOG_ID).hide(); + roleCallback(); + }, + error: function(request, response) { + Sunstone.getDialog(CONFIRM_DIALOG_ID).hide(); + Notifier.onError(request, response); + }, + notify: true + }, + + "Role.add" : { + type: "single", + call: OpenNebulaRole.add, + callback : function() { + Sunstone.getDialog(ADD_DIALOG_ID).hide(); + roleCallback(); + }, + error: function(request, response) { + Sunstone.getDialog(ADD_DIALOG_ID).hide(); + Notifier.onError(request, response); + }, + notify: true + }, + + "Role.add_dialog" : { + type: "custom", + call: function(){ + params = roleElement(); + + Sunstone.getDialog(ADD_DIALOG_ID).reset(); + Sunstone.getDialog(ADD_DIALOG_ID).show(); + } + }, + //-------------------------------------------------------------------------- "RoleVM.deploy" : { diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add.js b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add.js new file mode 100644 index 0000000000..5b3c813a82 --- /dev/null +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add.js @@ -0,0 +1,124 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./add/html'); + var Sunstone = require('sunstone'); + var Notifier = require('utils/notifier'); + var Locale = require('utils/locale'); + var Tips = require('utils/tips'); + var RoleTab = require('tabs/oneflow-services-tab/utils/role-tab'); + var OpenNebulaRole = require("opennebula/role"); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./add/dialogId'); + var TAB_ID = require('../tabId'); + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + BaseDialog.call(this); + } + + Dialog.DIALOG_ID = DIALOG_ID; + Dialog.prototype = Object.create(BaseDialog.prototype); + Dialog.prototype.constructor = Dialog; + Dialog.prototype.html = _html; + Dialog.prototype.onShow = _onShow; + Dialog.prototype.setup = _setup; + Dialog.prototype.setParams = _setParams; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId + }); + } + + function _onShow(context) { + this.setNames( {tabId: TAB_ID} ); + } + + function _setup(context) { + var that = this; + + var html_role_id = "newRole"; + + var role = new RoleTab(html_role_id) + + var role_section = $("
" + + role.html() + + "
" + ); + + $('.add-role-form', context).html(role_section); + $('#roleTabTemplatesnewRoleContainer', context).closest('.row').show(); + + role.setup(role_section); + role.onShow(); + + $('#refresh_button_roleTabTemplatesnewRole').trigger('click'); + + $('#addServiceRoleDialogForm',context).on("submit", function(ev) { + ev.preventDefault(); + var role_info = role.retrieve(context); + var obj = { + "action": { + "perform":"add_role", + "params" : { + "role" : JSON.stringify(role_info) + } + } + } + + + var flow_id = $('.resource-id').text(); + Sunstone.runAction('Role.add', flow_id, obj); + return false; + }); + + return false; + } + + /** + * @param {object} params + * - params.serviceId : selected service ID + * - params.roleName : selected role name + */ + function _setParams(params) { + this.serviceId = params.serviceId; + this.roleName = params.roleName; + } + }); diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add/dialogId.js b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add/dialogId.js new file mode 100644 index 0000000000..19e8f4445c --- /dev/null +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add/dialogId.js @@ -0,0 +1,19 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +define(function(require){ + return 'addServiceRoleDialog'; + }); diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add/html.hbs b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add/html.hbs new file mode 100644 index 0000000000..2560e7833d --- /dev/null +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add/html.hbs @@ -0,0 +1,35 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2021, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! 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. }} +{{! -------------------------------------------------------------------------- }} + +
+
+

{{tr "Add role"}}

+
+
+
+
+ +
+
+ +
+ +
+
diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js index 47de6078d8..31fa43f00a 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js @@ -152,6 +152,13 @@ define(function(require) { Tips.setup(context); + console.log() + + $('#addRoleBtn').on('click', function(event){ + event.preventDefault(); + Sunstone.runAction("Role.add_dialog"); + }); + if (roles && roles.length) { that.servicerolesDataTable = new DomDataTable( "datatable_roles_"+this.panelId, diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/html.hbs b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/html.hbs index f459f53674..ac0d21f66d 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/html.hbs +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/html.hbs @@ -18,7 +18,13 @@
{{#if servicePanel}}
-
+
+ +
+
diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js index fdbb5f063b..c139d93a1f 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js @@ -89,6 +89,12 @@ define(function(require) { text: Locale.tr("Terminate") + ' hard', layout: "vmsdelete_buttons", custom_classes : "role-state-dependent" + }, + "Role.remove_dialog" : { + type: "action", + text: Locale.tr("Remove Role"), + layout: "vmsdelete_buttons", + custom_classes : "role-state-dependent" } }; diff --git a/src/sunstone/routes/oneflow.rb b/src/sunstone/routes/oneflow.rb index c145e6d83f..b6ac95965c 100644 --- a/src/sunstone/routes/oneflow.rb +++ b/src/sunstone/routes/oneflow.rb @@ -121,6 +121,14 @@ post '/service/purge' do af_format_response(resp) end +post '/service/:id/role_action' do + client = af_build_client + + resp = client.post('/service/' + params[:id] + '/role_action' , @request_body) + + af_format_response(resp) +end + ############################################################################## # Service Template ############################################################################## diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 95d3874509..3b3608bf65 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -20,21 +20,21 @@ ONE_LOCATION = ENV['ONE_LOCATION'] if !ONE_LOCATION - LOG_LOCATION = '/var/log/one' - VAR_LOCATION = '/var/lib/one' - ETC_LOCATION = '/etc/one' - SHARE_LOCATION = '/usr/share/one' - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' - GEMS_LOCATION = '/usr/share/one/gems' - SUNSTONE_LOCATION = '/usr/lib/one/sunstone' + LOG_LOCATION ||= '/var/log/one' + VAR_LOCATION ||= '/var/lib/one' + ETC_LOCATION ||= '/etc/one' + SHARE_LOCATION ||= '/usr/share/one' + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' + SUNSTONE_LOCATION ||= '/usr/lib/one/sunstone' else - VAR_LOCATION = ONE_LOCATION + '/var' - LOG_LOCATION = ONE_LOCATION + '/var' - ETC_LOCATION = ONE_LOCATION + '/etc' - SHARE_LOCATION = ONE_LOCATION + '/share' - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' - GEMS_LOCATION = ONE_LOCATION + '/share/gems' - SUNSTONE_LOCATION = ONE_LOCATION + '/lib/sunstone' + VAR_LOCATION ||= ONE_LOCATION + '/var' + LOG_LOCATION ||= ONE_LOCATION + '/var' + ETC_LOCATION ||= ONE_LOCATION + '/etc' + SHARE_LOCATION ||= ONE_LOCATION + '/share' + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' + SUNSTONE_LOCATION ||= ONE_LOCATION + '/lib/sunstone' end SUNSTONE_AUTH = VAR_LOCATION + '/.one/sunstone_auth'