Skip to content

Commit

Permalink
Merge pull request #5 from rollno748/ver1
Browse files Browse the repository at this point in the history
Ver1
  • Loading branch information
rollno748 committed Sep 19, 2023
2 parents b6fec6a + 80b9c38 commit 64ec50d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ local.repo.path=/app/plugins-manager/

## Detailed Instructions

* Detailed instructions is available at [Medium](https://rollno748.medium.com/creating-your-own-jmeter-plugin-manager-a-comprehensive-guide-aaa57021dda9)
* Detailed instructions is available at [Medium](https://rollno748.medium.com/creating-your-own-jmeter-plugin-manager-a-comprehensive-guide-aaa57021dda9)


## Tools used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class MetadataModel {
private String id;
@JsonProperty("version")
private String version;
@JsonProperty("changes")
private String changes;
@JsonProperty("depends")
private String depends;
@JsonProperty("downloadUrl")
private String downloadUrl;
@JsonProperty("libs")
Expand Down Expand Up @@ -42,6 +46,22 @@ public String getLibs() {
return libs;
}

public String getChanges() {
return changes;
}

public void setChanges(String changes) {
this.changes = changes;
}

public String getDepends() {
return depends;
}

public void setDepends(String depends) {
this.depends = depends;
}

public void setLibs(String libs) {
this.libs = libs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public class PluginModel {
import java.util.List;

public class PluginModel {
@JsonProperty("description")
private String description;

Expand All @@ -28,6 +29,9 @@ public class PluginModel {
@JsonProperty("vendor")
private String vendor;

@JsonProperty("componentClasses")
private List<String> componentClasses;

@JsonProperty("versions_count")
private int versions_count;

Expand Down Expand Up @@ -86,6 +90,14 @@ public void setVendor(String vendor) {
this.vendor = vendor;
}

public List<String> getComponentClasses() {
return componentClasses;
}

public void setComponentClasses(List<String> componentClasses) {
this.componentClasses = componentClasses;
}

public String getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.perfwise.local.pluginsmanager.scheduler.http;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import io.perfwise.local.pluginsmanager.model.MetadataModel;
import io.perfwise.local.pluginsmanager.model.PluginModel;
Expand Down Expand Up @@ -48,13 +51,13 @@ public class HttpRequest {
private static final HttpClient HTTP_CLIENT = HttpClients.createDefault();
private static final int MAX_RETRIES = 10;
private static final long RETRY_INTERVAL_MS = 60000;
private static final String INSERT_METADATA_INFO = "INSERT INTO metadata (id, version, downloadUrl, libs) VALUES (?, ?, ?, ?)";
private static final String INSERT_PLUGIN_INFO = "INSERT INTO plugins (id, name, type, description, helpUrl, markerClass, screenshotUrl, vendor, versions_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String INSERT_METADATA_INFO = "INSERT INTO metadata (id, version, changes, depends, downloadUrl, libs) VALUES (?, ?, ?, ?, ?, ?)";
private static final String INSERT_PLUGIN_INFO = "INSERT INTO plugins (id, name, type, description, helpUrl, markerClass, screenshotUrl, vendor, componentClasses, versions_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String SELECT_PLUGIN_VERSION_METADATA = "SELECT COUNT(*) AS COUNT FROM METADATA WHERE ID = ? AND VERSION = ?";
private static final String SELECT_PLUGINS = "SELECT ID, NAME, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR FROM plugins";
private static final String SELECT_PLUGINS_TABLE_DATA = "SELECT ID, NAME, TYPE, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, VERSIONS_COUNT FROM plugins";
private static final String SELECT_PLUGINS_WITH_FILTER = "SELECT ID, NAME, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR FROM plugins WHERE type = ?";
private static final String SELECT_METADATA_BY_ID = "SELECT ID, VERSION, DOWNLOADURL, LIBS FROM metadata WHERE ID = ?";
private static final String SELECT_PLUGINS = "SELECT ID, NAME, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES FROM plugins";
private static final String SELECT_PLUGINS_TABLE_DATA = "SELECT ID, NAME, TYPE, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES, VERSIONS_COUNT FROM plugins";
private static final String SELECT_PLUGINS_WITH_FILTER = "SELECT ID, NAME, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES FROM plugins WHERE type = ?";
private static final String SELECT_METADATA_BY_ID = "SELECT ID, VERSION, CHANGES, DEPENDS, DOWNLOADURL, LIBS FROM metadata WHERE ID = ?";


public HttpRequest(Properties props){
Expand Down Expand Up @@ -148,6 +151,9 @@ public void downloadMissingPlugins(JSONObject pluginObject) throws URISyntaxExce
fileDownloader(this.dependenciesPath, new URI(libUrl).toURL());
}
}

metaDataObj.put("changes", verObj.has("changes") ? verObj.get("changes") : null);
metaDataObj.put("depends", verObj.has("depends") ? verObj.get("depends").toString() : null);
}
this.updatePluginMetadataInfo(metaDataObj);
LOGGER.info("Downloaded {} plugin - version {}", pluginObject.getString("id"), version);
Expand Down Expand Up @@ -191,6 +197,10 @@ public JSONArray fetchPluginsFromLocalDB(String query, String type){
pluginObject.put("vendor", rs.getString("vendor"));
libraryObj = this.getDependentLibraryObj(rs.getString("id"), type);
pluginObject.put("versions", libraryObj);
String componentClasses = rs.getString("componentClasses");
if(componentClasses != null){
pluginObject.put("componentClasses", new JSONArray(componentClasses));
}
jsonArray.put(pluginObject);
}
preparedStatement.close();
Expand All @@ -205,7 +215,6 @@ public JSONArray fetchPluginsFromLocalDB(String query, String type){
}

public JSONArray getAllPlugins() {
// JSONArray pluginsArray = getCombinedPlugins();
JSONArray publicPluginArray = getPublicPlugins();
JSONArray customPluginArray = getCustomPlugins();

Expand Down Expand Up @@ -252,6 +261,7 @@ private JSONArray fetchAllPluginsTableData() {
pluginObject.put("markerClass", rs.getString("markerClass"));
pluginObject.put("screenshotUrl", rs.getString("screenshotUrl"));
pluginObject.put("vendor", rs.getString("vendor"));
pluginObject.put("componentClasses", rs.getString("componentClasses"));
pluginObject.put("versions_count", rs.getString("versions_count"));
jsonArray.put(pluginObject);
}
Expand Down Expand Up @@ -286,6 +296,11 @@ private JSONObject getDependentLibraryObj(String id, String type) throws Unknown

while (rs.next()) {
JSONObject versionsObj = new JSONObject();
String depends = rs.getString("depends");
versionsObj.put("changes", rs.getString("changes"));
if(depends != null){
versionsObj.put("depends", new JSONArray(depends));
}
versionsObj.put("downloadUrl", pluginUrl + rs.getString("downloadUrl"));
if (rs.getString("libs") != null){
versionsObj.put("libs", processLibs(rs.getString("libs"), libUrl));
Expand Down Expand Up @@ -335,12 +350,13 @@ public void updatePluginMetadataInfo(JSONObject metaDataObj) {
if(conn == null || conn.isClosed()){
conn = SQLiteConnectionPool.getConnection();
}

PreparedStatement preparedStatement = conn.prepareStatement(INSERT_METADATA_INFO);
preparedStatement.setString(1, metadataModel.getId());
preparedStatement.setString(2, metadataModel.getVersion());
preparedStatement.setString(3, metadataModel.getDownloadUrl());
preparedStatement.setString(4, metadataModel.getLibs());
preparedStatement.setString(3, metadataModel.getChanges() != null ? metadataModel.getChanges() : null);
preparedStatement.setString(4, metadataModel.getDepends() != null ? metadataModel.getDepends() : null);
preparedStatement.setString(5, metadataModel.getDownloadUrl());
preparedStatement.setString(6, metadataModel.getLibs());

int rowsInserted = preparedStatement.executeUpdate();
if (rowsInserted > 0) {
Expand Down Expand Up @@ -378,7 +394,8 @@ public void updateCustomPluginInfoInDB(JSONObject pluginModel) {
if(conn == null || conn.isClosed()){
conn = SQLiteConnectionPool.getConnection();
}

//"CREATE TABLE plugins (id TEXT PRIMARY KEY, name TEXT, type TEXT, description TEXT, helpUrl TEXT, markerClass TEXT, screenshotUrl TEXT, vendor TEXT, componentClasses TEXT, versions_count INTEGER)";
//id, name, type, description, helpUrl, markerClass, screenshotUrl, vendor, componentClasses, versions_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement preparedStatement = conn.prepareStatement(INSERT_PLUGIN_INFO);
preparedStatement.setString(1, pluginModel.getString("id"));
preparedStatement.setString(2, pluginModel.getString("name"));
Expand All @@ -388,7 +405,8 @@ public void updateCustomPluginInfoInDB(JSONObject pluginModel) {
preparedStatement.setString(6, pluginModel.getString("markerClass"));
preparedStatement.setString(7, pluginModel.getString("screenshotUrl"));
preparedStatement.setString(8, pluginModel.getString("vendor"));
preparedStatement.setDouble(9, pluginModel.getDouble("version_count"));
preparedStatement.setString(9, pluginModel.getString("componentClasses"));
preparedStatement.setDouble(10, pluginModel.getDouble("version_count"));

int rowsInserted = preparedStatement.executeUpdate();
if (rowsInserted > 0) {
Expand Down Expand Up @@ -421,7 +439,8 @@ private void updatePluginInfoInDB(JSONObject pluginObject, String type) {
preparedStatement.setString(6, pluginModel.getMarkerClass());
preparedStatement.setString(7, pluginModel.getScreenshotUrl());
preparedStatement.setString(8, pluginModel.getVendor());
preparedStatement.setInt(9, pluginModel.getVersions_count());
preparedStatement.setString(9, pluginModel.getComponentClasses() != null ? pluginModel.getComponentClasses().toString() : null);
preparedStatement.setDouble(10, pluginModel.getVersions_count());

int rowsInserted = preparedStatement.executeUpdate();
if (rowsInserted > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static void downloadAllPlugins(JSONArray jmeterRepoJson) throws URISyntax
for (int i = 0; i < jmeterRepoJson.length(); i++) {
httpRequest.downloadMissingPlugins(jmeterRepoJson.getJSONObject(i));
}
LOGGER.info("Downloaded all the available plugins from the market");
}

public static int getLocalPluginCount(JSONArray pluginsArray) throws SQLException, InterruptedException {
Expand Down Expand Up @@ -128,6 +129,7 @@ public void downloadMissingPlugins(JSONArray missingPluginsList) throws URISynta
for (int i = 0; i < missingPluginsList.length(); i++) {
httpRequest.downloadMissingPlugins(missingPluginsList.getJSONObject(i));
}
LOGGER.info("Downloaded all the missing plugins from the market");
}

public static HttpRequest getHttpRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class SQLiteConnectionPool {
private static SQLiteConnectionPool instance;
private static String DB_FILE_PATH;
private static final String DBFILENAME = "plugins.db";
private static final String PLUGINS_METADATA = "CREATE TABLE metadata (id TEXT, version TEXT, downloadUrl TEXT, libs TEXT(1000000))";
private static final String PLUGINS_INFO = "CREATE TABLE plugins (id TEXT PRIMARY KEY, name TEXT, type TEXT, description TEXT, helpUrl TEXT, markerClass TEXT, screenshotUrl TEXT, vendor TEXT, versions_count INTEGER)";
private static final String PLUGINS_METADATA = "CREATE TABLE metadata (id TEXT, version TEXT, changes TEXT, depends TEXT, downloadUrl TEXT, libs TEXT(1000000))";
private static final String PLUGINS_INFO = "CREATE TABLE plugins (id TEXT PRIMARY KEY, name TEXT, type TEXT, description TEXT, helpUrl TEXT, markerClass TEXT, screenshotUrl TEXT, vendor TEXT, componentClasses TEXT, versions_count INTEGER)";
private static int minPoolSize;
private static int maxPoolSize;
private static int timeoutSeconds;
Expand Down

0 comments on commit 64ec50d

Please sign in to comment.