Skip to content

Commit

Permalink
Merge branch 'development' into feature/add-query-logs-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 23, 2025
2 parents 700b90e + c9251ac commit e33395d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.6
2.7.5
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ gem 'redcarpet'

# NCBO gems (can be from a local dev path or from rubygems/git)
gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.git', branch: 'development'
gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master'
gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'development'
gem 'ncbo_ontology_recommender', git: 'https://github.com/ontoportal-lirmm/ncbo_ontology_recommender.git', branch: 'development'
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'feature/add-triple-store-logging'
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development'
gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development'
gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/add-queries-logging-'
gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development'


group :development do
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: e7831230455c5d72447d38537049ff5b8ec8d4ce
branch: feature/add-triple-store-logging
revision: 5825dc1f9d0ff439b1ba9d8f78fa7bb20b1c65d0
branch: development
specs:
goo (0.0.2)
addressable (~> 2.8)
Expand Down Expand Up @@ -29,8 +29,8 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ncbo_cron.git
revision: d50c624868dec11cb0afcc88ba422d021c77926c
branch: master
revision: dd736917974f13ac7558e0d2a61a84030d82acaa
branch: development
specs:
ncbo_cron (0.0.1)
dante
Expand All @@ -57,8 +57,8 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 32c1aed4221e1b5f50a7931137092ee4ba62ca94
branch: feature/add-queries-logging-
revision: 6cb18910e322645e3cc3490951d10f19468da52f
branch: development
specs:
ontologies_linked_data (0.0.1)
activesupport
Expand All @@ -77,7 +77,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/sparql-client.git
revision: d4737ff08f33517cf93b4d82c78a471017991d97
revision: d4a226e75eb4aeaaf42720eac4f23f55380a0bd3
branch: development
specs:
sparql-client (3.2.2)
Expand Down Expand Up @@ -254,7 +254,7 @@ GEM
net-protocol
net-protocol (0.2.2)
timeout
net-scp (4.0.0)
net-scp (4.1.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
Expand Down Expand Up @@ -343,7 +343,7 @@ GEM
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rubocop (1.70.0)
rubocop (1.71.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@
NcboCron.config do |config|
config.redis_host = REDIS_PERSISTENT_HOST.to_s
config.redis_port = REDIS_PORT.to_i
config.graphs_counts_report_path = './test/ontologies_report.json'
# config.ontology_report_path = REPORT_PATH
end
34 changes: 34 additions & 0 deletions controllers/admin_graphs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'ncbo_cron/graphs_counts'
class AdminGraphsController < ApplicationController

namespace '/admin' do
GRAPH_COUNT_REPORT_PATH = NcboCron.settings.graphs_counts_report_path
before do
if LinkedData.settings.enable_security && (!env['REMOTE_USER'] || !env['REMOTE_USER'].admin?)
error 403, 'Access denied'
end
end

get '/graphs' do
output = NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).read_graph_counts
reply output
end

post '/graphs' do
generate_graphs_counts
reply({ message: 'Graph counts generated', status: 200 })
end

delete '/graphs' do
url = params['url']
error 400, 'You must provide a valid URL for the graph to delete' if url.blank?
Goo.sparql_data_client.delete_graph(url)
generate_graphs_counts
reply({ message: "Graph #{url} deleted", status: 200 })
end

def generate_graphs_counts
NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).run
end
end
end
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
ruby = "2.7.8"
53 changes: 53 additions & 0 deletions test/controllers/test_graphs_admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require_relative '../test_case'

class TestGraphAdminController < TestCase
def setup
ontologies = LinkedData::Models::Ontology.all
if ontologies.empty?
LinkedData::SampleData::Ontology.delete_ontologies_and_submissions
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: false)
end
file_path = AdminGraphsController::GRAPH_COUNT_REPORT_PATH
File.delete(file_path) if File.exist?(file_path)
end

def test_initial_graphs_admin_actions
get '/admin/graphs'
assert last_response.ok?
response = MultiJson.load(last_response.body)
assert_empty response
end

def test_graph_creation_and_retrieval
post '/admin/graphs'

get '/admin/graphs'
assert last_response.ok?
response = MultiJson.load(last_response.body)
refute_empty response

response.each do |graph, count|
assert graph.is_a?(String)
assert count.is_a?(Array)
assert count[0].is_a?(Integer)
assert count[1].is_a?(TrueClass) || count[1].is_a?(FalseClass)
end
end

def test_graph_deletion
post '/admin/graphs'

get '/admin/graphs'
response = MultiJson.load(last_response.body)
refute_empty response

graph = 'http://data.bioontology.org/metadata/OntologySubmission'

delete '/admin/graphs', url: graph

get '/admin/graphs'
assert last_response.ok?
response = MultiJson.load(last_response.body)
assert_nil response[graph]
end
end
13 changes: 8 additions & 5 deletions test/controllers/test_logging_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ def test_logging_endpoint
(1..10).each do |_i|
LinkedData::Models::Ontology.where.include(:acronym).all
end
get '/admin/latest_day_query_logs?page=1&pagesize=10'

get '/admin/latest_day_query_logs?page=1&pagesize=9'
assert last_response.ok?
logs = MultiJson.load(last_response.body)
assert_equal 10, logs['collection'].size
assert_equal 9, logs['collection'].size

get '/admin/latest_day_query_logs?page=2&pagesize=10'
get '/admin/latest_day_query_logs?page=2&pagesize=9'
assert last_response.ok?
logs = MultiJson.load(last_response.body)
assert_equal 1, logs['collection'].size

get '/admin/latest_day_query_logs?page=3&pagesize=10'
get '/admin/latest_day_query_logs?page=3&pagesize=9'
assert last_response.ok?
logs = MultiJson.load(last_response.body)
assert_empty logs['collection']
end

def test_n_last_seconds_logs
Goo.logger.info("Test log")
(1..10).each do |_i|
LinkedData::Models::Ontology.where.include(:acronym).all
end

Goo.logger.info("Test log")
get '/admin/last_n_s_query_logs?seconds=2&page=1&pagesize=10'
assert last_response.ok?
logs = MultiJson.load(last_response.body)
Expand All @@ -51,6 +55,5 @@ def test_n_last_seconds_logs
assert last_response.ok?
logs = MultiJson.load(last_response.body)
assert_equal 1, logs['collection'].size
binding.pry
end
end

0 comments on commit e33395d

Please sign in to comment.