5 Commits

Author SHA1 Message Date
Senad Uka
6304fba940 update readme 2021-10-29 11:27:53 +02:00
beec4a00de Froegin keys 2021-10-26 12:44:05 +02:00
f76b125f84 Added device_jobs table 2021-10-22 17:37:32 +02:00
842a55be5f Added table jobs and devices 2021-10-20 12:17:31 +02:00
799f55335f Added rails api with postrgess db config 2021-10-20 11:19:22 +02:00
21 changed files with 161 additions and 144 deletions

4
.gitignore vendored
View File

@@ -7,10 +7,6 @@
# Ignore bundler config. # Ignore bundler config.
/.bundle /.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-*
# Ignore all logfiles and tempfiles. # Ignore all logfiles and tempfiles.
/log/* /log/*
/tmp/* /tmp/*

View File

@@ -5,8 +5,8 @@ ruby '3.0.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1' gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use sqlite3 as the database for Active Record # Use postgresql as the database for Active Record
gem 'sqlite3', '~> 1.4' gem 'pg', '~> 1.1'
# Use Puma as the app server # Use Puma as the app server
gem 'puma', '~> 5.0' gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

View File

@@ -88,9 +88,10 @@ GEM
nio4r (2.5.8) nio4r (2.5.8)
nokogiri (1.12.5-x86_64-linux) nokogiri (1.12.5-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
pg (1.2.3)
puma (5.5.2) puma (5.5.2)
nio4r (~> 2.0) nio4r (~> 2.0)
racc (1.5.2) racc (1.6.0)
rack (2.2.3) rack (2.2.3)
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
@@ -132,7 +133,6 @@ GEM
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.4.2)
thor (1.1.0) thor (1.1.0)
tzinfo (2.0.4) tzinfo (2.0.4)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
@@ -148,10 +148,10 @@ DEPENDENCIES
bootsnap (>= 1.4.4) bootsnap (>= 1.4.4)
byebug byebug
listen (~> 3.3) listen (~> 3.3)
pg (~> 1.1)
puma (~> 5.0) puma (~> 5.0)
rails (~> 6.1.4, >= 6.1.4.1) rails (~> 6.1.4, >= 6.1.4.1)
spring spring
sqlite3 (~> 1.4)
tzinfo-data tzinfo-data
RUBY VERSION RUBY VERSION

View File

@@ -1,93 +1,6 @@
# offlineposaoserver # Offline Job Scheduler
Offline Jobs Scheduler (OJS) component as a RESTFUL API in Rails 6.1 and Ruby 3.0.0. Offline Jobs Scheduler (OJS) component as a RESTFUL API in Rails 6.1 and Ruby 3.0.0.
The OJS will keep its data inside of the Jobs DB - separate Postgresql database hosted on the RDS. The OJS will keep its data inside of the Jobs DB - separate Postgresql database hosted on the RDS.
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.com/ukacorp/vozovi/offlineposaoserver.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/integrations/)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Automatically merge when pipeline succeeds](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://docs.gitlab.com/ee/user/clusters/agent/)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://gitlab.com/-/experiment/new_project_readme_content:11188747d1ca6f0008819c2a2dd3798f?https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

View File

@@ -46,6 +46,6 @@ class DeviceJobsController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def device_job_params def device_job_params
params.require(:device_job).permit(:references, :references, :id, :job_id, :device_id) params.require(:device_job).permit(:device_id, :job_id, :status)
end end
end end

View File

@@ -46,6 +46,6 @@ class DevicesController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def device_params def device_params
params.require(:device).permit(:id, :device_id) params.require(:device).permit(:device_id)
end end
end end

View File

@@ -46,6 +46,6 @@ class JobsController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def job_params def job_params
params.require(:job).permit(:job_id, :params, :type) params.require(:job).permit(:job_id, :params, :job_type)
end end
end end

View File

@@ -1,2 +1,7 @@
class DeviceJob < ApplicationRecord class DeviceJob < ApplicationRecord
# self.primary_key = :jobs_id, :device_id
belongs_to :job
belongs_to :device
# :foreign_key => [:user_id, :group_id]
end end

View File

@@ -1,2 +1,4 @@
class Job < ApplicationRecord class Job < ApplicationRecord
has_many :device_jobs
end end

View File

@@ -1 +1 @@
iz+/lBxKVEnxJlQKzNGAf6QuLKh4WFW307gHWOkRL7pzWNLs2lBEfEcKM/v2pkajGgB42M0jONGnG3s3+xDscYoQmUG7uLgn4vrihDONw3d6XaqpwmFTj5x5yYN53Wk7P0Lg8JYk5XAN4M+6JSwZsF8kTUrjujdpEUuHL+EWCDCCitqzMHpHb0xUThQo6eq3q6PuudrmsXV4rbAyhwhGprIz+4WySAHbxlqe7qWJAJsPURvPjATfkYsgAm9dMN1V5PuocKCVB8gpHjYcflBSaogFi+D/0HQ6fouWaPmC02HDrd0KefEaX2E8/E3PkevQPACuR2pOFdWmUkZz2L58ebQzdXLulhpZ9+lL4S3xNKN8FQH8MFUiYt7+jq7g+QjcdXYAa7ogtuey2LRvDs+yjE8wecdDFt7igQZQ--kpFXTAgoZ/5+bSGK--BWWj4Gsl94s5dWqoCcfFzw== BOb+hwh8vwYwiInNczlOehhiauFTKuUW5rU90V0dvmT1hcsL374FyJcncd+DXbx6rekWF2IHQEet/qRv5/oq2Bf0/cx9UYwjbNO9u2oAQksYzQ8LeNXJ5v5kKiGh2wXZQ5apbYk87AWsDDlMcwQgOtvt2/jPvBDp8zglYFCxYAiIcDb5Il/cPSqlPSfwVVKWbbbtY+FW84SXBVc+Swf7F4m+e+OM3MydNf9QAXAcKElcYZRAxKAig8r4FWvd+oydVUNxXwIg7hL1YLUHYOdwSL1IBLe6TCXBWNwOv3i1wTSgo8bz7QW7WuO0KVjJEqkiQ3rszWwy7GeyJCRpaGib/CT6dqh4QVD+C03tHKQDBjI7/yFK1X6IZdD9K+taoFgfBCmqPXKUxy3YIkXhHvCb+3opEBaeYIVdRNR0--nzGCaJK8eWxcClk+--fkCWtTHNRMI6x99+CO8vJg==

View File

@@ -1,25 +1,86 @@
# SQLite. Versions 3.8.0 and up are supported. # PostgreSQL. Versions 9.3 and up are supported.
# gem install sqlite3
# #
# Ensure the SQLite 3 gem is defined in your Gemfile # Install the pg driver:
# gem 'sqlite3' # gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
# #
default: &default default: &default
adapter: sqlite3 adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development: development:
<<: *default <<: *default
database: db/development.sqlite3 database: offlinejobs
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user running Rails.
username: admin
# The password associated with the postgres role (username).
password: admin
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
<<: *default <<: *default
database: db/test.sqlite3 database: offlineposaoserver_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production: production:
<<: *default <<: *default
database: db/production.sqlite3 database: offlineposaoserver_production
username: offlineposaoserver
password: <%= ENV['OFFLINEPOSAOSERVER_DATABASE_PASSWORD'] %>

View File

@@ -1,14 +0,0 @@
class CreateDeviceJobs < ActiveRecord::Migration[6.1]
def change
create_table :device_jobs do |t|
t.Jobs :references
t.Devices :references
t.primary_key :id
t.integer :job_id
t.integer :device_id
t.timestamps
add_index :device_jobs_index, [:job_id, :device_id]
end
end
end

View File

@@ -1,9 +1,8 @@
class CreateJobs < ActiveRecord::Migration[6.1] class CreateJobs < ActiveRecord::Migration[6.1]
def change def change
create_table :jobs do |t| create_table :jobs do |t|
t.primary_key :job_id
t.json :params t.json :params
t.string :type t.string :job_type
t.timestamps t.timestamps
end end

View File

@@ -1,7 +1,6 @@
class CreateDevices < ActiveRecord::Migration[6.1] class CreateDevices < ActiveRecord::Migration[6.1]
def change def change
create_table :devices do |t| create_table :devices do |t|
t.primary_key :id
t.string :device_id t.string :device_id
t.timestamps t.timestamps

View File

@@ -0,0 +1,19 @@
class CreateDeviceJobs < ActiveRecord::Migration[6.1]
def change
create_table :device_jobs, id: false do |t|
# t.references :job_id, references: :job, foreign_key: true # the owner
# t.references :device_id, references: :device, foreign_key: true # the invitee
t.integer :device_id
t.integer :job_id
t.string :status
t.timestamps
end
add_index :device_jobs, :job_id
add_foreign_key :device_jobs, :jobs, column: :job_id
add_index :device_jobs, :device_id
add_foreign_key :device_jobs, :devices, column: :device_id
# execute "ALTER TABLE device_jobs ADD PRIMARY KEY (device_id, jobs_id);"
end
end

43
db/schema.rb generated Normal file
View File

@@ -0,0 +1,43 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_21_061911) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "device_jobs", id: false, force: :cascade do |t|
t.integer "device_id"
t.integer "job_id"
t.string "status"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["device_id"], name: "index_device_jobs_on_device_id"
t.index ["job_id"], name: "index_device_jobs_on_job_id"
end
create_table "devices", force: :cascade do |t|
t.string "device_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "jobs", force: :cascade do |t|
t.json "params"
t.string "job_type"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
add_foreign_key "device_jobs", "devices"
add_foreign_key "device_jobs", "jobs"
end

View File

@@ -12,7 +12,7 @@ class DeviceJobsControllerTest < ActionDispatch::IntegrationTest
test "should create device_job" do test "should create device_job" do
assert_difference('DeviceJob.count') do assert_difference('DeviceJob.count') do
post device_jobs_url, params: { device_job: { device_id: @device_job.device_id, id: @device_job.id, job_id: @device_job.job_id, references: @device_job.references } }, as: :json post device_jobs_url, params: { device_job: { device_id: @device_job.device_id, jobs_id: @device_job.jobs_id, status: @device_job.status } }, as: :json
end end
assert_response 201 assert_response 201
@@ -24,7 +24,7 @@ class DeviceJobsControllerTest < ActionDispatch::IntegrationTest
end end
test "should update device_job" do test "should update device_job" do
patch device_job_url(@device_job), params: { device_job: { device_id: @device_job.device_id, id: @device_job.id, job_id: @device_job.job_id, references: @device_job.references } }, as: :json patch device_job_url(@device_job), params: { device_job: { device_id: @device_job.device_id, jobs_id: @device_job.jobs_id, status: @device_job.status } }, as: :json
assert_response 200 assert_response 200
end end

View File

@@ -12,7 +12,7 @@ class DevicesControllerTest < ActionDispatch::IntegrationTest
test "should create device" do test "should create device" do
assert_difference('Device.count') do assert_difference('Device.count') do
post devices_url, params: { device: { device_id: @device.device_id, id: @device.id } }, as: :json post devices_url, params: { device: { device_id: @device.device_id } }, as: :json
end end
assert_response 201 assert_response 201
@@ -24,7 +24,7 @@ class DevicesControllerTest < ActionDispatch::IntegrationTest
end end
test "should update device" do test "should update device" do
patch device_url(@device), params: { device: { device_id: @device.device_id, id: @device.id } }, as: :json patch device_url(@device), params: { device: { device_id: @device.device_id } }, as: :json
assert_response 200 assert_response 200
end end

View File

@@ -12,7 +12,7 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
test "should create job" do test "should create job" do
assert_difference('Job.count') do assert_difference('Job.count') do
post jobs_url, params: { job: { job_id: @job.job_id, params: @job.params, type: @job.type } }, as: :json post jobs_url, params: { job: { job_id: @job.job_id, params: @job.params, job_type: @job.job_type } }, as: :json
end end
assert_response 201 assert_response 201
@@ -24,7 +24,7 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
end end
test "should update job" do test "should update job" do
patch job_url(@job), params: { job: { job_id: @job.job_id, params: @job.params, type: @job.type } }, as: :json patch job_url(@job), params: { job: { job_id: @job.job_id, params: @job.params, job_type: @job.job_type } }, as: :json
assert_response 200 assert_response 200
end end

View File

@@ -1,15 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: one:
references:
references:
id:
job_id: 1
device_id: 1 device_id: 1
jobs_id: 1
status: MyString
two: two:
references:
references:
id:
job_id: 1
device_id: 1 device_id: 1
jobs_id: 1
status: MyString

View File

@@ -1,9 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: one:
id:
device_id: MyString device_id: MyString
two: two:
id:
device_id: MyString device_id: MyString