Compare commits
2 Commits
refactor
...
osh_api_im
| Author | SHA1 | Date |
|---|---|---|
|
|
136f8de2f0 | 3 years ago |
|
|
04fd871fa6 | 3 years ago |
20 changed files with 321 additions and 71 deletions
@ -0,0 +1,12 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
set +e |
||||||
|
|
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/schema.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_offerings.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_brewscans.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_pncscans.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_gitscans.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_results.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_scans.sql |
||||||
|
psql -U $POSTGRESQL_USER -h localhost -p $POSTGRESQL_PORT -a -f $HOME/tmp/osh/covscanrest/schema/load_archive.sql |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.archive( |
||||||
|
scan_id SERIAL, |
||||||
|
offering_id VARCHAR(100), |
||||||
|
event_id VARCHAR(100) NOT NULL, |
||||||
|
is_managed_service BOOLEAN NOT NULL, |
||||||
|
component_list VARCHAR(100), |
||||||
|
datetime TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL, |
||||||
|
owner VARCHAR(50) NOT NULL, |
||||||
|
results SERIAL, |
||||||
|
status VARCHAR (50) CONSTRAINT valid_status CHECK(status in ('PENDING', 'DELETED', 'COMPLETED', 'IN PROGRESS')), |
||||||
|
last_updated TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL, |
||||||
|
PRIMARY KEY(scan_id), |
||||||
|
FOREIGN KEY (offering_id) REFERENCES osh.offerings(offering_id), |
||||||
|
FOREIGN KEY (results) REFERENCES osh.results(results_id) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO osh.archive (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(1,'ansible-automation-platform','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',1,'COMPLETED'); |
||||||
|
INSERT INTO osh.archive (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(2,'eclipse-vertx','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',2,'COMPLETED'); |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.brewscans( |
||||||
|
id SERIAL, |
||||||
|
build_system_type VARCHAR(80), |
||||||
|
brew_id VARCHAR(100), |
||||||
|
brew_nvr VARCHAR(100), |
||||||
|
pnc_id VARCHAR(100), |
||||||
|
artifact_type VARCHAR(100), |
||||||
|
file_name VARCHAR(100), |
||||||
|
built_from_source BOOLEAN, |
||||||
|
PRIMARY KEY(id) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO osh.brewscans (id,build_system_type,brew_id,brew_nvr,pnc_id,artifact_type,file_name,built_from_source) |
||||||
|
VALUES(1,'brew','brew-id-1','brew-nvr-1','pnc-id-1','jar','my-file-1',true); |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.gitscans ( |
||||||
|
id SERIAL, |
||||||
|
build_system_type VARCHAR(80), |
||||||
|
repository VARCHAR(150), |
||||||
|
reference VARCHAR(100), |
||||||
|
commit_id VARCHAR(100), |
||||||
|
-- SHA256 has a length of 256 bits, so 256 bits would represent 64 hex characters |
||||||
|
hashsum VARCHAR(64), |
||||||
|
PRIMARY KEY(id) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO osh.gitscans (id,build_system_type,repository,reference,commit_id) |
||||||
|
VALUES(1, 'git', 'http://github.com/rpms/kubevirt-cpaas-mvp', '9fd87a76beaba5cd6b93cb6f02bf1d88c4855a45','1c1007b8'); |
||||||
|
INSERT INTO osh.gitscans (id,build_system_type,repository,reference,commit_id) |
||||||
|
VALUES(2, 'git', 'http://github.com/rpms/kubevirt-cpaas-mvp', '9fd87a76beaba5cd6b93cb6f02bf1d88c4855a45','1c1007b8'); |
||||||
|
INSERT INTO osh.gitscans (id,build_system_type,repository,reference,commit_id) |
||||||
|
VALUES(3, 'git', 'http://github.com/rpms/kubevirt-cpaas-mvp', '9fd87a76beaba5cd6b93cb6f02bf1d88c4855a45','1c1007b8'); |
||||||
|
INSERT INTO osh.gitscans (id,build_system_type,repository,reference,commit_id) |
||||||
|
VALUES(4, 'git', 'http://github.com/rpms/kubevirt-cpaas-mvp', '9fd87a76beaba5cd6b93cb6f02bf1d88c4855a45','1c1007b8'); |
||||||
|
INSERT INTO osh.gitscans (id,build_system_type,repository,reference,commit_id) |
||||||
|
VALUES(5, 'git', 'http://github.com/rpms/kubevirt-cpaas-mvp', '9fd87a76beaba5cd6b93cb6f02bf1d88c4855a45','1c1007b8'); |
||||||
@ -1,3 +1,9 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.offerings( |
||||||
|
offering_id VARCHAR(100), |
||||||
|
description VARCHAR(200), |
||||||
|
PRIMARY KEY (offering_id) |
||||||
|
); |
||||||
|
|
||||||
INSERT INTO osh.offerings(offering_id,description) VALUES ('ansible-automation-platform','Ansible Automation Platform (AAP)'); |
INSERT INTO osh.offerings(offering_id,description) VALUES ('ansible-automation-platform','Ansible Automation Platform (AAP)'); |
||||||
INSERT INTO osh.offerings(offering_id,description) VALUES ('advisor','Insights Advisor'); |
INSERT INTO osh.offerings(offering_id,description) VALUES ('advisor','Insights Advisor'); |
||||||
INSERT INTO osh.offerings(offering_id,description) VALUES ('ansible-on-aws','Ansible on AWS'); |
INSERT INTO osh.offerings(offering_id,description) VALUES ('ansible-on-aws','Ansible on AWS'); |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.pncscans( |
||||||
|
id SERIAL, |
||||||
|
build_system_type VARCHAR(80), |
||||||
|
build_id VARCHAR(100), |
||||||
|
PRIMARY KEY(id) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(1, 'pnc', 'AA123AG456'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(2, 'pnc', 'B2'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(3, 'pnc', 'B3'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(4, 'pnc', 'B4'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(5, 'pnc', 'B5'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(6, 'pnc', 'B6'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(7, 'pnc', 'B7'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(8, 'pnc', 'B8'); |
||||||
|
INSERT INTO osh.pncscans (id,build_system_type,build_id) VALUES(9, 'pnc', 'B9'); |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.results( |
||||||
|
results_id SERIAL, |
||||||
|
datetime TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL, |
||||||
|
state BOOLEAN, |
||||||
|
logs bytea, |
||||||
|
task_reference VARCHAR(50), |
||||||
|
PRIMARY KEY (results_id) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO osh.results (results_id,datetime,state,logs) |
||||||
|
VALUES(1,'2023-06-22 16:04:04.816453',true,bytea('/home/lbossis/osh/postgres/logs/bulk-load.log.hex')); |
||||||
|
INSERT INTO osh.results (results_id,datetime,state,logs) |
||||||
|
VALUES(2,'2023-06-22 16:04:04.816453',true,bytea('/home/lbossis/osh/postgres/logs/inp.log.hex')); |
||||||
|
INSERT INTO osh.results (results_id,datetime,state,logs) |
||||||
|
VALUES(3,'2023-06-22 16:04:04.816453',true,bytea('/home/lbossis/osh/postgres/logs/bulk-load.log')); |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
CREATE TABLE IF NOT EXISTS osh.scans( |
||||||
|
scan_id SERIAL, |
||||||
|
offering_id VARCHAR(100), |
||||||
|
event_id VARCHAR(100) NOT NULL, |
||||||
|
is_managed_service BOOLEAN NOT NULL, |
||||||
|
component_list VARCHAR(100), |
||||||
|
datetime TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL, |
||||||
|
owner VARCHAR(50) NOT NULL, |
||||||
|
results SERIAL, |
||||||
|
status VARCHAR (50) CONSTRAINT valid_status CHECK(status in ('PENDING', 'DELETED', 'COMPLETED', 'IN PROGRESS')), |
||||||
|
last_updated TIMESTAMP WITHOUT TIME ZONE DEFAULT (NOW() AT TIME ZONE 'utc') NOT NULL, |
||||||
|
PRIMARY KEY(scan_id), |
||||||
|
FOREIGN KEY (offering_id) REFERENCES osh.offerings(offering_id), |
||||||
|
FOREIGN KEY (results) REFERENCES osh.results(results_id) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO osh.scans (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(1,'ansible-automation-platform','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',1,'PENDING'); |
||||||
|
INSERT INTO osh.scans (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(2,'ansible-automation-platform','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',1,'IN PROGRESS'); |
||||||
|
INSERT INTO osh.scans (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(3,'ansible-automation-platform','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',1,'COMPLETED'); |
||||||
|
INSERT INTO osh.scans (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(4,'eclipse-vertx','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',2,'PENDING'); |
||||||
|
INSERT INTO osh.scans (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(5,'eclipse-vertx','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',2,'IN PROGRESS'); |
||||||
|
INSERT INTO osh.scans (scan_id,offering_id,event_id,is_managed_service,component_list,datetime,owner,results,status) |
||||||
|
VALUES(6,'eclipse-vertx','event-id-1',true,'publisher','2023-06-22 16:04:04.816453','RedHat',2,'COMPLETED'); |
||||||
@ -1,25 +1,39 @@ |
|||||||
package dto; |
package dto; |
||||||
|
|
||||||
import org.json.JSONException; |
import org.json.JSONException; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
import static constants.PSGQL.*; |
import static io.smallrye.common.constraint.Assert.assertNotNull; |
||||||
|
|
||||||
// @TODO Replace hard-coded credentials; make use of our secure db connection practice
|
// @TODO Replace hard-coded credentials; make use of our secure db connection practice
|
||||||
|
|
||||||
public class ConnectDB { |
public class ConnectDB { |
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ConnectDB.class); |
||||||
|
|
||||||
public Connection connect() throws JSONException { |
public Connection connect() throws JSONException, SQLException, IOException { |
||||||
|
FileReader reader = new FileReader("src/main/resources/application.properties"); |
||||||
|
Properties p = new Properties(); |
||||||
|
p.load(reader); |
||||||
|
String port = p.getProperty("quarkus.datasource.devservices.port"); |
||||||
|
String uid = p.getProperty("quarkus.datasource.username"); |
||||||
|
String pwd = p.getProperty("quarkus.datasource.password"); |
||||||
try { |
try { |
||||||
Connection conn = DriverManager.getConnection(url, user, password); |
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:" + port + "/", uid, pwd); |
||||||
System.out.println("Connected to PostgreSQL server"); |
logger.info("Opened DB connection: " + conn); |
||||||
|
assertNotNull(conn); |
||||||
return conn; |
return conn; |
||||||
} catch (SQLException e) { |
} catch (Exception e) { |
||||||
System.out.println(e.getMessage()); |
e.printStackTrace(); |
||||||
|
logger.error(e.getClass().getName() + ": " + e.getMessage()); |
||||||
|
throw new SQLException(); |
||||||
} |
} |
||||||
return null; |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,71 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import org.eclipse.microprofile.config.ConfigProvider; |
||||||
|
import org.eclipse.microprofile.config.inject.ConfigProperty; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.util.NoSuchElementException; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||||
|
|
||||||
|
class FailingDbConnectionTests { |
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FailingDbConnectionTests.class); |
||||||
|
|
||||||
|
@ConfigProperty(name = "quarkus.datasource.devservices.port", defaultValue = "36000") |
||||||
|
String port; |
||||||
|
|
||||||
|
@ConfigProperty(name = "quarkus.datasource.username", defaultValue = "quarkus") |
||||||
|
String uid; |
||||||
|
|
||||||
|
@ConfigProperty(name = "quarkus.datasource.password") |
||||||
|
String pwd; |
||||||
|
|
||||||
|
/** |
||||||
|
* These tests fail due to failed initialization of the above variables via @ConfigProperty and |
||||||
|
* via direct call to ConfigProvider.getConfig().getValue() whereas application.properties have all |
||||||
|
* these properties defined. Since we know they fail for the time being we expect such behaviour and |
||||||
|
* put reversed asserts accordingly in order not to break execution of the entire test suit. |
||||||
|
*/ |
||||||
|
|
||||||
|
@Test |
||||||
|
void TestDbConnUsingConfigProperty() { |
||||||
|
logger.info(String.format("TestDbConnViaConfigProperty: port=%s uid=%s pwd=%s%n", port, uid, pwd)); |
||||||
|
try (Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:" + port + "/", uid, pwd)) { |
||||||
|
logger.info("Opened database connection to PostgreSQL using @ConfigProperty: " + conn); |
||||||
|
assertNotNull(conn); |
||||||
|
} catch (Exception e) { |
||||||
|
logger.error(e.getClass().getName() + ": " + e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void TestDbConnUsingConfigProvider() { |
||||||
|
try { |
||||||
|
String _port = getPropertyOfStringType("quarkus.datasource.devservices.port"); |
||||||
|
String _uid = getPropertyOfStringType("quarkus.datasource.username"); |
||||||
|
String _pwd = getPropertyOfStringType("quarkus.datasource.password"); |
||||||
|
logger.info(String.format("TestDbConnViaConfigProvider: port=%s uid=%s pwd=%s%n", _port, _uid, _pwd)); |
||||||
|
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:" + _port + "/", _uid, _pwd); |
||||||
|
logger.info("Opened database connection to PostgreSQL using ConfigProvider: " + conn); |
||||||
|
assertNotNull(conn); |
||||||
|
conn.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
logger.error(e.getClass().getName() + ": " + e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String getPropertyOfStringType(String name) { |
||||||
|
try { |
||||||
|
String value = ConfigProvider.getConfig().getValue(name, String.class); |
||||||
|
logger.info("Found config property '" + name + "' value '" + value + "'"); |
||||||
|
return value; |
||||||
|
} catch (NoSuchElementException e) { |
||||||
|
logger.error(e.getClass().getName() + ": " + e.getMessage()); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||||
|
|
||||||
|
class TestDbConnection { |
||||||
|
@Test |
||||||
|
void TestDbConn() throws SQLException, IOException { |
||||||
|
ConnectDB connectDB = new ConnectDB(); |
||||||
|
Connection conn = connectDB.connect(); |
||||||
|
assertNotNull(conn); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue