Commit 2afcbc4a authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Remove remaining notifications usage

parent 2d8cb174
Pipeline #155961 passed with stages
in 17 minutes and 31 seconds
......@@ -178,7 +178,7 @@ class DeploymentsController < ApplicationController
:partition_number, :block_device, :reformat_tmp,
:disable_disk_partitioning, :disable_bootloader_install,
:reboot_classical_timeout, :reboot_kexec_timeout,
:ignore_nodes_deploying, :vlan, notifications: [],nodes: [])
:ignore_nodes_deploying, :vlan, nodes: [])
end
def collection_path
......
......@@ -14,7 +14,7 @@
class RootController < ResourcesController
# Display links to sub resources.
#
#
# def show
# root = {
# :uid => "grid5000",
......@@ -48,13 +48,13 @@ class RootController < ResourcesController
# format.json { render :json => root }
# end
# end
protected
def collection_path
"/"
end
def resource_path(id)
""
end
......@@ -63,7 +63,7 @@ class RootController < ResourcesController
links = super(item)
item['release'] = Grid5000::VERSION
item['timestamp'] = Time.now.to_i
%w{users notifications}.each do |rel|
%w{users}.each do |rel|
links.push({
"rel" => rel,
"type" => api_media_type(:g5kcollectionjson),
......
......@@ -24,7 +24,6 @@ module Grid5000
# Ugly hack to make the communication between the controller and the model possible
attr_accessor :base_uri, :user, :tls_options
serialize :nodes, JSON
serialize :notifications, JSON
serialize :result, JSON
validates_presence_of :user_uid, :site_uid, :environment, :nodes
......@@ -49,10 +48,6 @@ module Grid5000
# Experiment states
state_machine :status, :initial => :waiting do
after_transition :processing => :canceled, :do => :deliver_notification
after_transition :processing => :error, :do => :deliver_notification
after_transition :processing => :terminated, :do => :deliver_notification
before_transition :processing => :canceled, :do => :cancel_workflow!
before_transition :waiting => :processing, :do => :launch_workflow!
......@@ -79,27 +74,12 @@ module Grid5000
validate do
errors.add :nodes, "must be a non-empty list of node FQDN" unless (nodes.kind_of?(Array) && nodes.length > 0)
errors.add :notifications, "must be a list of notification URIs" unless (notifications.nil? || notifications.kind_of?(Array))
end
def processing?
status.nil? || status == "processing"
end
def deliver_notification
unless notifications.blank?
begin
Grid5000::Notification.new(
notification_message,
:to => notifications
).deliver!
rescue Exception => e
Rails.logger.warn "Unable to deliver notification to #{notifications.inspect} for deployment ##{uid}: #{e.class.name} - #{e.message} - #{e.backtrace.join("; ")}"
end
end
true
end
# When some attributes such as :key are passed as text strings,
# we must transform such strings into files
# and replace the attribute value by the HTTP URI
......@@ -268,10 +248,6 @@ module Grid5000
attributes.merge(:links => links).reject{|k,v| v.nil? || k=="id"}
end
def notification_message
::JSON.pretty_generate(as_json)
end
def to_hash
params = {
'environment' => {}
......
......@@ -56,7 +56,6 @@ development:
uri_out_private_key_file: /etc/ssl/certs/clientkey_nopass.pem
uri_out_cert_chain_file: /etc/ssl/certs/clientcert.pem
uri_out_verify_peer: false
notifications_uri: https://localhost:3443/sid/notifications
reference_repository_path: ~/reference-repository
smtp_host: localhost
smtp_port: 2525
......@@ -71,7 +70,6 @@ test: &test
base_uri_out: http://api-out.local
from.config: http
reference_repository_path: spec/fixtures/reference-repository
notifications_uri: http://fake.api/sid/notifications
smtp_host: localhost
smtp_port: 2525
oar:
......@@ -96,5 +94,4 @@ test_mysql:
production:
<<: *defaults
notifications_uri: http://localhost:8888/sid/notifications
......@@ -24,30 +24,29 @@ Api::Application.routes.draw do
get '*resource/versions' => 'versions#index', :via => [:get]
get '*resource/versions/:id' => 'versions#show', :via => [:get]
# abasu : 1 line introduced below for correction to bug ref 5065 -- 2015.01.23
# abasu : 1 line introduced below for correction to bug ref 5065 -- 2015.01.23
resources :environments, :only => [:index, :show], :constraints => { :id => /[0-9A-Za-z\-\.]+/ }
resources :network_equipments, :only => [:index, :show]
resources :sites, :only => [:index, :show] do
resources :sites, :only => [:index, :show] do
member do
get :status
end
# abasu : 1 line introduced below for correction to bug ref 5065 -- 2015.01.23
# abasu : 1 line introduced below for correction to bug ref 5065 -- 2015.01.23
resources :environments, :only => [:index, :show], :constraints => { :id => /[0-9A-Za-z\-\.]+/ }
resources :network_equipments, :only => [:index, :show]
resources :pdus, :only => [:index, :show]
resources :clusters, :only => [:index, :show] do
# abasu : 3 lines introduced below for correction to bug ref 5856 -- 2015.04.17
# abasu : 3 lines introduced below for correction to bug ref 5856 -- 2015.04.17
member do
get :status
end
resources :nodes, :only => [:index, :show]
end
# abasu bug #7301 to incorporate feature /servers -- 2016.10.24
# abasu bug #7301 to incorporate feature /servers -- 2016.10.24
resources :servers, :only => [:index, :show]
resources :jobs
resources :deployments
end
resources :notifications, :only => [:index, :create]
get '/ui/events' => redirect('https://www.grid5000.fr/status/')
......
class RemoveNotificationsFromDeployments < ActiveRecord::Migration[6.0]
def change
remove_column :deployments, :notifications, :text
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_08_21_092321) do
ActiveRecord::Schema.define(version: 2020_07_06_075317) do
create_table "deployments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "uid"
......@@ -21,7 +21,6 @@ ActiveRecord::Schema.define(version: 2018_08_21_092321) do
t.string "status", default: "waiting"
t.text "key"
t.text "nodes"
t.text "notifications"
t.text "result"
t.text "output"
t.integer "partition_number"
......
......@@ -34,7 +34,6 @@ describe RootController do
{"rel"=>"version", "type"=>"application/vnd.grid5000.item+json", "href"=>"/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0"},
{"rel"=>"versions", "type"=>"application/vnd.grid5000.collection+json", "href"=>"/versions"},
{"rel"=>"users", "type"=>"application/vnd.grid5000.collection+json", "href"=>"/users"},
{"rel"=>"notifications", "type"=>"application/vnd.grid5000.collection+json", "href"=>"/notifications"}
]
})
end
......@@ -57,7 +56,6 @@ describe RootController do
{"rel"=>"version", "type"=>"application/vnd.grid5000.item+json", "href"=>"/sid/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0"},
{"rel"=>"versions", "type"=>"application/vnd.grid5000.collection+json", "href"=>"/sid/versions"},
{"rel"=>"users", "type"=>"application/vnd.grid5000.collection+json", "href"=>"/sid/users"},
{"rel"=>"notifications", "type"=>"application/vnd.grid5000.collection+json", "href"=>"/sid/notifications"}
]
})
end
......
......@@ -60,13 +60,6 @@ describe Grid5000::Deployment do
to eq ["can't be blank"]
end
end
it "should not be valid if :notifications is not null but is not a list" do
@deployment.notifications = ""
expect(@deployment).to_not be_valid
expect(@deployment.errors[:notifications]).
to eq ["must be a list of notification URIs"]
end
end # describe "validations"
......@@ -187,9 +180,6 @@ describe Grid5000::Deployment do
@deployment=create(:deployment,
uid: "1234",
nodes: ["paradent-1.rennes.grid5000.fr"],
notifications: [
"mailto:cyril.rohr@irisa.fr"
],
result: {
"paradent-1.rennes.grid5000.fr" => {
"state" => "OK"
......@@ -201,10 +191,6 @@ describe Grid5000::Deployment do
it "should correctly serialize the to-be-serialized attributes" do
expect(@deployment.nodes).
to be == ["paradent-1.rennes.grid5000.fr"]
expect(@deployment.notifications).
to be == [
"mailto:cyril.rohr@irisa.fr"
]
expect(@deployment.result).
to be == {
"paradent-1.rennes.grid5000.fr" => {
......@@ -214,15 +200,13 @@ describe Grid5000::Deployment do
end
it "correctly build the attributes hash for JSON export" do
expect(@deployment.as_json).to be == {"created_at"=>@now.to_i, "disable_bootloader_install"=>false, "disable_disk_partitioning"=>false, "environment"=>"lenny-x64-base", "ignore_nodes_deploying"=>false, "nodes"=>["paradent-1.rennes.grid5000.fr"], "notifications"=>["mailto:cyril.rohr@irisa.fr"], "result"=>{"paradent-1.rennes.grid5000.fr"=>{"state"=>"OK"}}, "site_uid"=>"rennes", "status"=>"waiting", "uid"=>"1234", "updated_at"=>@now.to_i, "user_uid"=>"crohr"}
expect(@deployment.as_json).to be == {"created_at"=>@now.to_i, "disable_bootloader_install"=>false, "disable_disk_partitioning"=>false, "environment"=>"lenny-x64-base", "ignore_nodes_deploying"=>false, "nodes"=>["paradent-1.rennes.grid5000.fr"], "result"=>{"paradent-1.rennes.grid5000.fr"=>{"state"=>"OK"}}, "site_uid"=>"rennes", "status"=>"waiting", "uid"=>"1234", "updated_at"=>@now.to_i, "user_uid"=>"crohr"}
end
it "should correctly export to json" do
export = JSON.parse(@deployment.to_json)
expect(export['nodes']).to be == [
"paradent-1.rennes.grid5000.fr"]
expect(export['notifications']).to be == [
"mailto:cyril.rohr@irisa.fr"]
expect(export['result']).to be == {
"paradent-1.rennes.grid5000.fr"=>{"state"=>"OK"}
}
......@@ -264,13 +248,11 @@ describe Grid5000::Deployment do
end
it "should be able to go from waiting to processing" do
expect(@deployment.status?(:waiting)).to be true
expect(@deployment).not_to receive(:deliver_notification)
expect(@deployment).to receive(:launch_workflow!).and_return(true)
expect(@deployment.launch).to be true
expect(@deployment.status?(:processing)).to be true
end
it "should not be able to go from waiting to processing if an exception is raised when launch_workflow" do
expect(@deployment).not_to receive(:deliver_notification)
expect(@deployment).to receive(:launch_workflow!).
and_raise(Exception.new("some error"))
expect(@deployment.status?(:waiting)).to be true
......@@ -287,32 +269,27 @@ describe Grid5000::Deployment do
expect(@deployment.status?(:processing)).to be true
end
it "should be able to go from processing to processing" do
expect(@deployment).not_to receive(:deliver_notification)
expect(@deployment.process).to be true
expect(@deployment.status?(:processing)).to be true
end
it "should be able to go from processing to terminated, and should call :deliver_notification" do
expect(@deployment).to receive(:deliver_notification)
it "should be able to go from processing to terminated" do
expect(@deployment.terminate).to be true
expect(@deployment.status?(:terminated)).to be true
end
it "should be able to go from processing to canceled, and should call :deliver_notification" do
it "should be able to go from processing to canceled" do
expect(@deployment).to receive(:cancel_workflow!).and_return(true)
expect(@deployment).to receive(:deliver_notification)
expect(@deployment.cancel).to be true
expect(@deployment.status?(:canceled)).to be true
end
it "should not be able to go from processing to canceled if an exception is raised when cancel_workflow" do
expect(@deployment).to receive(:cancel_workflow!).
and_raise(Exception.new("some error"))
expect(@deployment).not_to receive(:deliver_notification)
expect(lambda{
@deployment.cancel
}).to raise_error(Exception, "some error")
expect(@deployment.status?(:canceled)).to be false
end
it "should be able to go from processing to error, and should call :deliver_notification" do
expect(@deployment).to receive(:deliver_notification)
it "should be able to go from processing to error" do
expect(@deployment.failed).to be true
expect(@deployment.status?(:error)).to be true
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment