Browse Source

add logging facility

db_schema
Leonid Bossis 3 years ago
parent
commit
a178a7fc18
  1. 10
      src/main/java/rest/CreateGetResource.java
  2. 18
      src/main/java/rest/CreateScanRequest.java
  3. 8
      src/main/java/rest/CreateScanResource.java
  4. 26
      src/main/java/rest/CreateStartScan.java
  5. 7
      src/main/java/rest/RemoveScan.java
  6. 22
      src/test/java/dto/TestPayload.java

10
src/main/java/rest/CreateGetResource.java

@ -6,6 +6,8 @@ import java.util.Set;
import dto.ScanObj;
import dto.ConnectDB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@ -18,15 +20,15 @@ import java.sql.SQLException;
// @Path("/api/v1/[osh-scan]")
@Path("/scanGet")
public class CreateGetResource {
// @Inject
// EntityManager em;
private static final Logger logger = LoggerFactory.getLogger(CreateGetResource.class);
CreateScanService createScanService;
private Set<ScanObj> Scans = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));
public CreateGetResource() {
// LDB: @TODO either put some code here or remove this not used public constructor
}
@GET
@ -49,7 +51,7 @@ public class CreateGetResource {
rs.getString("component_list")));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return Scans;
}

18
src/main/java/rest/CreateScanRequest.java

@ -9,13 +9,15 @@ import dto.PncObj;
import dto.PncObjPayload;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@ -23,6 +25,8 @@ import java.sql.SQLException;
@Path("/scanRequest")
public class CreateScanRequest {
private static final Logger logger = LoggerFactory.getLogger(CreateScanRequest.class);
@RestClient
CreateScanService createScanService;
@ -30,7 +34,7 @@ public class CreateScanRequest {
@Path("/brew")
@Consumes({ "application/json" })
// in theory should take List<String> to clean it up
public BrewObj invokeBrewScanAnalyze(@Valid String scanInvocation) throws URISyntaxException {
public BrewObj invokeBrewScanAnalyze(@Valid String scanInvocation) throws JSONException {
JSONObject jsonData = new JSONObject(scanInvocation);
BrewObj brewObj = BrewObjPayload.constructScanPayload(jsonData);
ConnectDB connectDB = new ConnectDB();
@ -45,7 +49,7 @@ public class CreateScanRequest {
pstmt.setBoolean(7, brewObj.getBuiltFromSource());
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return brewObj;
}
@ -53,7 +57,7 @@ public class CreateScanRequest {
@POST
@Path("/git")
@Consumes({ "application/json" })
public GitObj invokeGitScanAnalyze(@Valid String scanInvocation)throws URISyntaxException {
public GitObj invokeGitScanAnalyze(@Valid String scanInvocation)throws JSONException {
JSONObject jsonData = new JSONObject(scanInvocation);
GitObj gitObj = GitObjPayload.constructScanPayload(jsonData);
ConnectDB connectDB = new ConnectDB();
@ -65,7 +69,7 @@ public class CreateScanRequest {
pstmt.setString(4, gitObj.getCommitId());
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return gitObj;
}
@ -73,7 +77,7 @@ public class CreateScanRequest {
@POST
@Path("/pnc")
@Consumes({ "application/json" })
public PncObj invokePncScanAnalyze(@Valid String scanInvocation)throws URISyntaxException {
public PncObj invokePncScanAnalyze(@Valid String scanInvocation)throws JSONException {
JSONObject jsonData = new JSONObject(scanInvocation);
PncObj pncObj = PncObjPayload.constructScanPayload(jsonData);
ConnectDB connectDB = new ConnectDB();
@ -83,7 +87,7 @@ public class CreateScanRequest {
pstmt.setString(2, pncObj.getBuildId());
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return pncObj;
}

8
src/main/java/rest/CreateScanResource.java

@ -7,6 +7,8 @@ import dto.ScanObj;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
@ -19,6 +21,8 @@ import java.sql.SQLException;
@Path("/")
public class CreateScanResource {
private static final Logger logger = LoggerFactory.getLogger(CreateScanResource.class);
@RestClient
CreateScanService createScanService;
@ -38,8 +42,8 @@ public class CreateScanResource {
pstmt.setString(5, scanObj.getComponentList());
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
logger.error(e.getMessage());
}
return scanObj;
}
}

26
src/main/java/rest/CreateStartScan.java

@ -4,6 +4,8 @@ import dto.ConnectDB;
import dto.ScanObj;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
@ -16,6 +18,8 @@ import java.sql.SQLException;
@Path("/startScan")
public class CreateStartScan {
private static final Logger logger = LoggerFactory.getLogger(CreateStartScan.class);
@RestClient
CreateScanService createScanService;
@ -30,10 +34,10 @@ public class CreateStartScan {
archiveSelectedScans(conn, finalScan);
postArchivingCleanup(conn, scanId);
} else {
System.out.println("No data match found for scan ID=" + scanId);
logger.warn("No data match found for scan ID=" + scanId);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return finalScan;
}
@ -45,8 +49,8 @@ public class CreateStartScan {
pstmt.setString(1, scanId);
ResultSet rs = pstmt.executeQuery();
//TODO: need to add unique keys to DBs
//fix for individual results (not resultset)
// TODO: need to add unique keys to DBs
// fix for individual results (not resultset)
finalScan = new ScanObj(
rs.getString("scan_id"),
rs.getString("offering_id"),
@ -54,7 +58,7 @@ public class CreateStartScan {
rs.getString("is_managed_service"),
rs.getString("component_list"));
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return finalScan;
}
@ -71,21 +75,21 @@ public class CreateStartScan {
pstmt.setString(5, finalScan.getComponentList());
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
}
private void postArchivingCleanup(Connection conn, String scanId) {
//TODO add proper checks
//send task to the actual interface here using the resultset returned (should multiple scanids be allowed):
//once the task is complete AND we have confirmation that the scan is done run the following sql
// TODO add proper checks
// send task to the actual interface here using the resultset returned (should multiple scanids be allowed):
// once the task is complete AND we have confirmation that the scan is done run the following sql
String sql = "DELETE FROM scans WHERE scan_id=?";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, scanId);
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
}
}
}

7
src/main/java/rest/RemoveScan.java

@ -3,6 +3,8 @@ package rest;
import dto.ConnectDB;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.Path;
import javax.ws.rs.DELETE;
@ -13,6 +15,9 @@ import java.sql.SQLException;
@Path("/deleteScan")
public class RemoveScan {
private static final Logger logger = LoggerFactory.getLogger(RemoveScan.class);
// @Inject
@RestClient
CreateScanService createScanService;
@ -31,7 +36,7 @@ public class RemoveScan {
pstmt.executeUpdate();
rc = true;
} catch (SQLException e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
return rc;
}

22
src/test/java/dto/TestPayload.java

@ -2,9 +2,13 @@ package dto;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class TestPayload {
private static final Logger logger = LoggerFactory.getLogger(TestPayload.class);
@Test
void TestBrew() {
JSONObject jsonObject = new JSONObject();
@ -25,8 +29,9 @@ class TestPayload {
jsonObject.getString("artifact_type"),
jsonObject.getString("file_name"),
jsonObject.getBoolean("built_from_source"));
System.out.println("BrewObj1: " + brewObj1.toString());
System.out.println("BrewObj2: " + brewObj2.toString());
logger.info("BrewObj1: " + brewObj1.toString());
logger.info("BrewObj2: " + brewObj2.toString());
assert(brewObj1.getBuildSystemType().equals(brewObj2.getBuildSystemType()));
assert(brewObj1.getBrewId().equals(brewObj2.getBrewId()));
assert(brewObj1.getBrewNvr().equals(brewObj2.getBrewNvr()));
@ -50,8 +55,8 @@ class TestPayload {
jsonObject.getString("repository"),
jsonObject.getString("reference"),
jsonObject.getString("commit_id"));
System.out.println("GitObj1: " + gitObj1.toString());
System.out.println("GitObj2: " + gitObj2.toString());
logger.info("GitObj1: " + gitObj1.toString());
logger.info("GitObj2: " + gitObj2.toString());
assert(gitObj1.getBuildSystemType().equals(gitObj2.getBuildSystemType()));
assert(gitObj1.getRepository().equals(gitObj2.getRepository()));
assert(gitObj1.getReference().equals(gitObj2.getReference()));
@ -68,8 +73,8 @@ class TestPayload {
PncObj pncObj2 = new PncObj(
jsonObject.getString("build_system_type"),
jsonObject.getString("build_id"));
System.out.println("PncObj1: " + pncObj1.toString());
System.out.println("PncObj2: " + pncObj2.toString());
logger.info("PncObj1: " + pncObj1.toString());
logger.info("PncObj2: " + pncObj2.toString());
assert(pncObj1.getBuildSystemType().equals(pncObj2.getBuildSystemType()));
assert(pncObj1.getBuildId().equals(pncObj2.getBuildId()));
}
@ -90,13 +95,12 @@ class TestPayload {
jsonObject.getString("event_id"),
jsonObject.getString("is_managed_service"),
jsonObject.getString("component_list"));
System.out.println("ScanObj1: " + scanObj1.toString());
System.out.println("ScanObj2: " + scanObj2.toString());
logger.info("ScanObj1: " + scanObj1.toString());
logger.info("ScanObj2: " + scanObj2.toString());
assert(scanObj1.getScanId().equals(scanObj2.getScanId()));
assert(scanObj1.getProductId().equals(scanObj2.getProductId()));
assert(scanObj1.getEventId().equals(scanObj2.getEventId()));
assert(scanObj1.getIsManagedService().equals(scanObj2.getIsManagedService()));
assert(scanObj1.getComponentList().equals(scanObj2.getComponentList()));
}
}

Loading…
Cancel
Save