From e5d9fc0ec46a3566740c9623b743f5c0b46d858e Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Wed, 18 Dec 2019 13:39:25 -0800 Subject: [PATCH 01/12] Update to the version 2.12.3. --- README.md | 7 ++++++- build.properties | 2 +- lib/metacat.properties | 3 ++- metacat-common/pom.xml | 2 +- metacat-index/pom.xml | 4 ++-- pom.xml | 4 ++-- src/loaddtdschema-postgres.sql | 2 +- src/upgrade-db-to-2.12.3-postgres.sql | 12 ++++++++++++ 8 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 src/upgrade-db-to-2.12.3-postgres.sql diff --git a/README.md b/README.md index a38644f0f..cb034d337 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Metacat: Data Preservation and Discovery System -Version: 2.12.2 Release +Version: 2.12.3 Release Send feedback and bugs to: metacat-dev@ecoinformatics.org http://github.com/NCEAS/metacat @@ -67,6 +67,11 @@ for the next release. ## Release Notes +### Release Notes for 2.12.3 +Bugs fixed in this release: +* Return an invalid response to the call of cn.getLogRecords if some log records have a null ip address +* Make the accounts of returned log records more accurate + ### Release Notes for 2.12.2 Bugs fixed in this release: * Modify the schema files of the format ids of portal and collections diff --git a/build.properties b/build.properties index e4cfd2986..e6ca04ec1 100755 --- a/build.properties +++ b/build.properties @@ -2,7 +2,7 @@ #Version of this build. This needs to be a dotted numeric version. For #instance 1.9.1 is okay. 1.9.1_rc1 is not. -metacat.version=2.12.2 +metacat.version=2.12.3 #This is for packaging purposes. leave it blank for final production release. metacat.releaseCandidate= diff --git a/lib/metacat.properties b/lib/metacat.properties index 5c2ba64f1..a82592d12 100755 --- a/lib/metacat.properties +++ b/lib/metacat.properties @@ -25,7 +25,7 @@ server.internalPort=80 ############### Application Values ############ ## one of the few places where we use ANT tokens -application.metacatVersion=2.12.2 +application.metacatVersion=2.12.3 application.metacatReleaseInfo=-1 application.readOnlyMode=false @@ -119,6 +119,7 @@ database.upgradeVersion.2.11.1=upgrade-db-to-2.11.1 database.upgradeVersion.2.12.0=upgrade-db-to-2.12.0 database.upgradeVersion.2.12.1=upgrade-db-to-2.12.1 database.upgradeVersion.2.12.2=upgrade-db-to-2.12.2 +database.upgradeVersion.2.12.3=upgrade-db-to-2.12.3 ## for running java-based utilities database.upgradeUtility.1.5.0=edu.ucsb.nceas.metacat.admin.upgrade.Upgrade1_5_0 diff --git a/metacat-common/pom.xml b/metacat-common/pom.xml index 5b731171d..b81fd9ab2 100644 --- a/metacat-common/pom.xml +++ b/metacat-common/pom.xml @@ -4,7 +4,7 @@ edu.ucsb.nceas.metacat.common metacat-common jar - 2.12.2 + 2.12.3 metacat-common http://maven.apache.org diff --git a/metacat-index/pom.xml b/metacat-index/pom.xml index 1e2ef661a..d672a60ce 100644 --- a/metacat-index/pom.xml +++ b/metacat-index/pom.xml @@ -4,13 +4,13 @@ edu.ucsb.nceas.metacat.index metacat-index war - 2.12.2 + 2.12.3 metacat-index http://maven.apache.org 2.3.8 - 2.12.2 + 2.12.3 diff --git a/pom.xml b/pom.xml index e9219eb43..5197ad8b9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.ecoinformatics metacat - 2.12.2 + 2.12.3 metacat war http://maven.apache.org @@ -12,7 +12,7 @@ UTF-8 2.3.1 2.3.1 - 2.12.2 + 2.12.3 diff --git a/src/loaddtdschema-postgres.sql b/src/loaddtdschema-postgres.sql index ab8fa7bda..23e46c144 100755 --- a/src/loaddtdschema-postgres.sql +++ b/src/loaddtdschema-postgres.sql @@ -212,4 +212,4 @@ INSERT INTO xml_catalog (entry_type, public_id, format_id, system_id) INSERT INTO xml_catalog (entry_type, public_id, system_id) SELECT 'Schema', 'http://www.openarchives.org/OAI/2.0/oai_dc/', '/schema/oai_dc/oai_dc.xsd' WHERE NOT EXISTS (SELECT * FROM xml_catalog WHERE public_id='http://www.openarchives.org/OAI/2.0/oai_dc/'); INSERT INTO db_version (version, status, date_created) - VALUES ('2.12.2',1,CURRENT_DATE); + VALUES ('2.12.3',1,CURRENT_DATE); diff --git a/src/upgrade-db-to-2.12.3-postgres.sql b/src/upgrade-db-to-2.12.3-postgres.sql new file mode 100644 index 000000000..487314f7c --- /dev/null +++ b/src/upgrade-db-to-2.12.3-postgres.sql @@ -0,0 +1,12 @@ +/* + * Ensure xml_catalog sequence is at table max + */ +SELECT setval('xml_catalog_id_seq', (SELECT max(catalog_id) from xml_catalog)); + +/* + * update the database version + */ +UPDATE db_version SET status=0; + +INSERT INTO db_version (version, status, date_created) + VALUES ('2.12.3', 1, CURRENT_DATE); From da09ca39dfd73c9b270fff32f88424e4a30486e8 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Wed, 18 Dec 2019 16:21:48 -0800 Subject: [PATCH 02/12] Cache the ip address and user agent from the request on the asynchronouse call of the replicate and systemmetadataChanged methods. --- .../nceas/metacat/dataone/D1NodeService.java | 58 ++++++++++++++++++- .../nceas/metacat/dataone/MNodeService.java | 27 ++++++++- .../restservice/v2/MNResourceHandler.java | 8 ++- 3 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java b/src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java index 07c8fbab0..b17e42be1 100644 --- a/src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java +++ b/src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java @@ -128,6 +128,8 @@ public abstract class D1NodeService { /** For logging the operations */ protected HttpServletRequest request; + protected String ipAddress = null; + protected String userAgent = null; /* reference to the metacat handler */ protected MetacatHandler handler; @@ -1049,7 +1051,13 @@ public String insertOrUpdateDocument(InputStream xmlStream, String encoding, Id // do the insert or update action handler = new MetacatHandler(new Timer()); - String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null, + if (ipAddress == null) { + ipAddress = request.getRemoteAddr(); + } + if (userAgent == null) { + userAgent = request.getHeader("User-Agent"); + } + String result = handler.handleInsertOrUpdateAction(ipAddress, userAgent, null, null, params, username, groupnames, false, false, xmlBytes, formatId, checksum); boolean isScienceMetadata = true; if(result.indexOf("") != -1 || !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata)) { @@ -1184,8 +1192,19 @@ public String insertDataObject(InputStream object, Identifier pid, e.getMessage()); } - logMetacat.debug("Logging the creation event."); - EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, "create"); + try { + if (ipAddress == null) { + ipAddress = request.getRemoteAddr(); + } + if (userAgent == null) { + userAgent = request.getHeader("User-Agent"); + } + logMetacat.debug("Logging the creation event."); + EventLog.getInstance().log(ipAddress, userAgent, username, localId, "create"); + } catch (Exception e) { + logMetacat.warn("D1NodeService.insertDataObject - can't log the create event for the object " + pid.getValue()); + } + // Schedule replication for this data file, the "insert" action is important here! logMetacat.debug("Scheduling replication."); @@ -2327,4 +2346,37 @@ private String existsInFields(String column, Identifier id) throws InvalidReques return guid; } + + + /** + * Get the ip address from the service + * @return the ip address + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * Set the ip address for the service + * @param ipAddress the address will be set + */ + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + /** + * Get the user agent from the service + * @return + */ + public String getUserAgent() { + return userAgent; + } + + /** + * Set the user agent for the service + * @param userAgent the user agent will be set + */ + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } } diff --git a/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java b/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java index 7710683a3..c8be3a4e4 100644 --- a/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java +++ b/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java @@ -225,6 +225,7 @@ public class MNodeService extends D1NodeService private static ExecutorService executor = null; private boolean needSync = true; + static { // use a shared executor service with nThreads == one less than available processors int availableProcessors = Runtime.getRuntime().availableProcessors(); @@ -236,13 +237,27 @@ public class MNodeService extends D1NodeService /** - * Singleton accessor to get an instance of MNodeService. + * Get an instance of MNodeService. * * @return instance - the instance of MNodeService */ public static MNodeService getInstance(HttpServletRequest request) { return new MNodeService(request); } + + /** + * Get an instance of MNodeService. + * @param request the servlet request associated with the MNodeService instance + * @param ipAddress the ip address associated with the MNodeService instance + * @param userAgent the user agent associated with the MNodeService instance + * @return the instance of MNodeService + */ + public static MNodeService getInstance(HttpServletRequest request, String ipAddress, String userAgent) { + MNodeService mnService = new MNodeService(request); + mnService.setIpAddress(ipAddress); + mnService.setUserAgent(userAgent); + return mnService; + } /** * Constructor, private for singleton access @@ -1736,8 +1751,13 @@ public boolean systemMetadataChanged(boolean needCheckAuthoriativeNode, Session try { String localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); - EventLog.getInstance().log(request.getRemoteAddr(), - request.getHeader("User-Agent"), session.getSubject().getValue(), + if (ipAddress == null) { + request.getRemoteAddr(); + } + if (userAgent == null) { + userAgent = request.getHeader("User-Agent"); + } + EventLog.getInstance().log(ipAddress, userAgent, session.getSubject().getValue(), localId, "updateSystemMetadata"); } catch (Exception e) { // do nothing, no localId to log with @@ -3026,4 +3046,5 @@ protected boolean isReadOnlyMode() { return readOnly; } + } diff --git a/src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java b/src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java index b109b43cd..a97a985b0 100644 --- a/src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java +++ b/src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java @@ -800,12 +800,14 @@ private void systemMetadataChanged() // } // run it in a thread to avoid connection timeout + final String ipAddress = request.getRemoteAddr(); + final String userAgent = request.getHeader("User-Agent"); Runnable runner = new Runnable() { @Override public void run() { try { // call the service - MNodeService.getInstance(request).systemMetadataChanged(session, pid, serialVersion, dateSysMetaLastModified); + MNodeService.getInstance(request, ipAddress, userAgent).systemMetadataChanged(session, pid, serialVersion, dateSysMetaLastModified); } catch (Exception e) { logMetacat.error("Error running replication: " + e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); @@ -1084,11 +1086,13 @@ private void replicate() sourceNode.setValue(sn); // run it in a thread to avoid connection timeout + final String ipAddress = request.getRemoteAddr(); + final String userAgent = request.getHeader("User-Agent"); Runnable runner = new Runnable() { @Override public void run() { try { - MNodeService.getInstance(request).replicate(session, sysmeta, sourceNode); + MNodeService.getInstance(request, ipAddress, userAgent).replicate(session, sysmeta, sourceNode); } catch (Exception e) { logMetacat.error("Error running replication: " + e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); From 0f08cba1aa7b56ea981b68d520be0ebc37fa994d Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Thu, 19 Dec 2019 09:55:46 -0800 Subject: [PATCH 03/12] Add the code to handle the case of the log fields being null on the database. --- src/edu/ucsb/nceas/metacat/EventLog.java | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/edu/ucsb/nceas/metacat/EventLog.java b/src/edu/ucsb/nceas/metacat/EventLog.java index 5bb9fdd34..30424aa7d 100755 --- a/src/edu/ucsb/nceas/metacat/EventLog.java +++ b/src/edu/ucsb/nceas/metacat/EventLog.java @@ -642,13 +642,26 @@ public Log getD1Report(String[] ipAddress, String[] principal, String[] docid, //process the result and return it while (rs.next()) { LogEntry logEntry = new LogEntry(); - logEntry.setEntryId(rs.getString(1)); + String logId = rs.getString(1); + if (logId == null || logId.trim().equals("")) { + logId = "N/A"; + } + logEntry.setEntryId(logId); Identifier identifier = new Identifier(); - identifier.setValue(rs.getString(2)); + String id = rs.getString(2); + if (id == null || id.trim().equals("")) { + id = "N/A"; + } + identifier.setValue(id); logEntry.setIdentifier(identifier); - logEntry.setIpAddress(anonymous ? "N/A" : rs.getString(3)); + String ip = rs.getString(3); + if (ip == null || ip.trim().equals("")) { + ip = "N/A"; + } + logEntry.setIpAddress(anonymous ? "N/A" : ip); + String userAgent = "N/A"; if (rs.getString(4) != null) { userAgent = rs.getString(4); @@ -656,7 +669,11 @@ public Log getD1Report(String[] ipAddress, String[] principal, String[] docid, logEntry.setUserAgent(userAgent); Subject subject = new Subject(); - subject.setValue(anonymous ? "N/A" : rs.getString(5)); + String subjectStr = rs.getString(5); + if (subjectStr == null || subjectStr.trim().equals("")) { + subjectStr = "N/A"; + } + subject.setValue(anonymous ? "N/A" : subjectStr); logEntry.setSubject(subject); String logEventString = rs.getString(6); From 85603467ee14527e9064339ac3eda6058b47447a Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Fri, 20 Dec 2019 15:19:26 -0800 Subject: [PATCH 04/12] Add more configuration on the apache section. --- docs/user/metacat/source/dataone.rst | 65 ++++++++++++++++++++---- docs/user/metacat/source/install.rst | 10 ++-- src/scripts/debian/metacat-site-ssl.conf | 16 ++++-- 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/docs/user/metacat/source/dataone.rst b/docs/user/metacat/source/dataone.rst index 83f5623d0..573334040 100644 --- a/docs/user/metacat/source/dataone.rst +++ b/docs/user/metacat/source/dataone.rst @@ -328,17 +328,60 @@ These Apache directives are crucial for Metacat to function as a Tier 2+ Member :: ... - AllowEncodedSlashes On - AcceptPathInfo On - JkOptions +ForwardURICompatUnparsed - SSLEngine on - SSLOptions +StrictRequire +StdEnvVars +ExportCertData - SSLVerifyClient optional - SSLVerifyDepth 10 - SSLCertificateFile /etc/ssl/certs/ - SSLCertificateKeyFile /etc/ssl/private/ - SSLCertificateChainFile /etc/ssl/certs/.crt - SSLCACertificatePath /etc/ssl/certs/ + + DocumentRoot /var/www + ServerName dev.nceas.ucsb.edu + ## Allow CORS requests from all origins to use cookies + SetEnvIf Origin "^(.*)$" ORIGIN_DOMAIN=$1 + Header set Access-Control-Allow-Origin "%{ORIGIN_DOMAIN}e" env=ORIGIN_DOMAIN + Header set Access-Control-Allow-Headers "Authorization, Content-Type, Origin, Cache-Control" + Header set Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS" + Header set Access-Control-Allow-Credentials "true" + ErrorLog /var/log/httpd/error_log + CustomLog /var/log/httpd/access_log common + ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" + + AllowOverride None + Options ExecCGI + Require all granted + + ScriptAlias /metacat/cgi-bin/ "/var/www/webapps/metacat/cgi-bin/" + + AllowOverride None + Options ExecCGI + Require all granted + + + RewriteEngine on + RewriteCond %{HTTP:Authorization} ^(.*) + RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] + + JkMount /metacat ajp13 + JkMount /metacat/* ajp13 + JkMount /metacat/metacat ajp13 + JkUnMount /metacat/cgi-bin/* ajp13 + JkMount /metacatui ajp13 + JkMount /metacatui/* ajp13 + JkMount /*.jsp ajp13 + AllowEncodedSlashes On + AcceptPathInfo On + JkOptions +ForwardURICompatUnparsed + SSLEngine on + SSLOptions +StrictRequire +StdEnvVars +ExportCertData + SSLVerifyClient optional + SSLVerifyDepth 10 + SSLCertificateFile /etc/ssl/certs/ + SSLCertificateKeyFile /etc/ssl/private/ + SSLCertificateChainFile /etc/ssl/certs/.crt + SSLCACertificatePath /etc/ssl/certs/ + + #SSLRenegBufferSize 10000000 + #SSLOptions +OptRenegotiate + + SSLVerifyClient optional + + + ... Where ```` and ```` are the certificate/key pair used by Apache diff --git a/docs/user/metacat/source/install.rst b/docs/user/metacat/source/install.rst index 04a67433b..632a47bfc 100644 --- a/docs/user/metacat/source/install.rst +++ b/docs/user/metacat/source/install.rst @@ -252,8 +252,8 @@ install and run the Metacat Registry or to use the Metacat Replication feature. DocumentRoot /var/www ServerName dev.nceas.ucsb.edu ## Allow CORS requests from all origins to use cookies - #SetEnvIf Origin "^(.*)$" ORIGIN_DOMAIN=$1 - #Header set Access-Control-Allow-Origin "%{ORIGIN_DOMAIN}e" env=ORIGIN_DOMAIN + SetEnvIf Origin "^(.*)$" ORIGIN_DOMAIN=$1 + Header set Access-Control-Allow-Origin "%{ORIGIN_DOMAIN}e" env=ORIGIN_DOMAIN Header set Access-Control-Allow-Headers "Authorization, Content-Type, Origin, Cache-Control" Header set Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS" Header set Access-Control-Allow-Credentials "true" @@ -263,15 +263,13 @@ install and run the Metacat Registry or to use the Metacat Replication feature. AllowOverride None Options ExecCGI - Order allow,deny - Allow from all + Require all granted ScriptAlias /metacat/cgi-bin/ "/var/www/webapps/metacat/cgi-bin/" AllowOverride None Options ExecCGI - Order allow,deny - Allow from all + Require all granted JkMount /metacat ajp13 JkMount /metacat/* ajp13 diff --git a/src/scripts/debian/metacat-site-ssl.conf b/src/scripts/debian/metacat-site-ssl.conf index 2c3991217..ec20d4928 100644 --- a/src/scripts/debian/metacat-site-ssl.conf +++ b/src/scripts/debian/metacat-site-ssl.conf @@ -4,8 +4,8 @@ NameVirtualHost *:443 DocumentRoot /var/lib/tomcat7/webapps/metacat ## Allow CORS requests from all origins to use cookies - #SetEnvIf Origin "^(.*)$" ORIGIN_DOMAIN=$1 - #Header set Access-Control-Allow-Origin "%{ORIGIN_DOMAIN}e" env=ORIGIN_DOMAIN + SetEnvIf Origin "^(.*)$" ORIGIN_DOMAIN=$1 + Header set Access-Control-Allow-Origin "%{ORIGIN_DOMAIN}e" env=ORIGIN_DOMAIN Header set Access-Control-Allow-Headers "Authorization, Content-Type, Origin, Cache-Control" Header set Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS" Header set Access-Control-Allow-Credentials "true" @@ -14,8 +14,7 @@ NameVirtualHost *:443 AllowOverride All Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch - Order allow,deny - Allow from all + Require all granted @@ -76,6 +75,15 @@ NameVirtualHost *:443 SSLVerifyClient require SSLVerifyDepth 10 + + + #SSLRenegBufferSize 10000000 + #SSLOptions +OptRenegotiate + + SSLVerifyClient optional + + + # disable SSL v2 and v3 # intermediate configuration from https://mozilla.github.io/server-side-tls/ssl-config-generator/ From 3891a89c31e993355fd3d1cdae839fa13c9b9cd0 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Mon, 23 Dec 2019 09:57:04 -0800 Subject: [PATCH 05/12] Add a test method to test the replication of data objects. --- .../metacat/dataone/MNodeReplicationTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/edu/ucsb/nceas/metacat/dataone/MNodeReplicationTest.java b/test/edu/ucsb/nceas/metacat/dataone/MNodeReplicationTest.java index b9a5a884c..205f14905 100644 --- a/test/edu/ucsb/nceas/metacat/dataone/MNodeReplicationTest.java +++ b/test/edu/ucsb/nceas/metacat/dataone/MNodeReplicationTest.java @@ -153,6 +153,7 @@ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new MNodeReplicationTest("initialize")); suite.addTest(new MNodeReplicationTest("testReplicate")); + suite.addTest(new MNodeReplicationTest("testReplicateData")); return suite; } @@ -227,5 +228,56 @@ public void testReplicate() { fail("Failed to test the replicate method : " + e.getMessage()); } } + + + /** + * Test to replicate a data object + */ + public void testReplicateData() { + printTestHeader("testReplicateData"); + try { + + //insert an object to the source node + Session session = null; + Identifier guid = new Identifier(); + guid.setValue("testReplicateData." + System.currentTimeMillis()); + InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); + Subject subject = MNodeService.getInstance(request).getCapabilities().getSubject(0); + SystemMetadata sysmeta = createSystemMetadata(guid, subject, object); + ObjectFormatIdentifier formatId = new ObjectFormatIdentifier(); + //create a replication policy + Node localNode = MNodeService.getInstance(request).getCapabilities(); + if(!localNode.isReplicate()) { + throw new Exception("The local node "+localNode.getIdentifier().getValue()+" is configured to not to accept replicas!"); + } + ReplicationPolicy rePolicy = new ReplicationPolicy(); + rePolicy.setReplicationAllowed(true); + rePolicy.setNumberReplicas(new Integer(3)); + rePolicy.addPreferredMemberNode(localNode.getIdentifier()); + sysmeta.setReplicationPolicy(rePolicy); + + NodeReference sourceNode = new NodeReference(); + sourceNode.setValue(sourceMNodeId); + MNode sourceMN = D1Client.getMN(sourceNode); + Node source = sourceMN.getCapabilities(); + if(!source.isSynchronize()) { + throw new Exception("The source node "+source.getIdentifier().getValue()+" is configured to not to be synchronized to the cn!"); + } + object = new ByteArrayInputStream("test".getBytes("UTF-8")); + sysmeta.setAuthoritativeMemberNode(sourceNode); + System.out.println("------------------------before creating the object into the source node "+sourceMNodeId+" with id "+guid.getValue()); + sourceMN.create(session, guid, object, sysmeta); + System.out.println("scucessfully created the object into the source node "+sourceMNodeId+" with id "+guid.getValue()); + Thread.sleep(waitTime); + MNode local = D1Client.getMN(localNode.getIdentifier()); + SystemMetadata sys = local.getSystemMetadata(session, guid); + System.out.println("--------------The pid of DATA from the replica on the localhost is "+sys.getIdentifier().getValue()); + assertTrue(sys.getIdentifier().equals(guid)); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Failed to test the replicate method : " + e.getMessage()); + fail("Failed to test the replicate method : " + e.getMessage()); + } + } } From 3babb216387c59495c1bed5d71e3e4b172f6861f Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Mon, 6 Jan 2020 15:19:51 -0800 Subject: [PATCH 06/12] Read the metacat version from db. Ref: https://github.com/NCEAS/metacat/issues/1416 --- .../ucsb/nceas/metacat/MetaCatServlet.java | 17 ++++-- .../ucsb/nceas/metacat/MetacatVersion.java | 53 ++++++++++++++++++- .../ucsb/nceas/metacattest/VersionTest.java | 14 ++++- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/edu/ucsb/nceas/metacat/MetaCatServlet.java b/src/edu/ucsb/nceas/metacat/MetaCatServlet.java index 86c5bbad5..2d8ce99bc 100755 --- a/src/edu/ucsb/nceas/metacat/MetaCatServlet.java +++ b/src/edu/ucsb/nceas/metacat/MetaCatServlet.java @@ -1056,9 +1056,20 @@ private void handleGetOrPost(HttpServletRequest request, out.close(); } else if (action.equals("getversion")) { response.setContentType("text/xml"); - PrintWriter out = response.getWriter(); - out.println(MetacatVersion.getVersionAsXml()); - out.close(); + String version = null; + try { + version = MetacatVersion.getVersionAsXml(); + PrintWriter out = response.getWriter(); + out.println(version); + out.close(); + } catch (SQLException e) { + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println(StringEscapeUtils.escapeXml(e.getMessage())); + out.println(""); + out.close(); + } } else if (action.equals("getlog")) { handler.handleGetLogAction(params, request, response, userName, groupNames, sessionId); } else if (action.equals("getloggedinuserinfo")) { diff --git a/src/edu/ucsb/nceas/metacat/MetacatVersion.java b/src/edu/ucsb/nceas/metacat/MetacatVersion.java index 044d9672e..61145e317 100755 --- a/src/edu/ucsb/nceas/metacat/MetacatVersion.java +++ b/src/edu/ucsb/nceas/metacat/MetacatVersion.java @@ -23,6 +23,14 @@ */ package edu.ucsb.nceas.metacat; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.Date; + +import edu.ucsb.nceas.metacat.database.DBConnection; +import edu.ucsb.nceas.metacat.database.DBConnectionPool; import edu.ucsb.nceas.metacat.properties.PropertyService; import edu.ucsb.nceas.utilities.PropertyNotFoundException; @@ -52,12 +60,53 @@ public static String getVersionID() throws PropertyNotFoundException { * * @return the version wrapped in an XML document */ - public static String getVersionAsXml() throws PropertyNotFoundException { + public static String getVersionAsXml() throws SQLException { StringBuffer sb = new StringBuffer(); sb.append(""); sb.append(""); - sb.append(getVersionID()); + sb.append(getVersionFromDB()); sb.append(""); return sb.toString(); } + + + /** + * Get the version number from DB + * @return a string of the Metacat version from DB + * @throws SQLException + */ + public static String getVersionFromDB() throws SQLException { + DBConnection conn = null; + PreparedStatement pstmt = null; + ResultSet rs = null; + String version = null; + int serialNumber = -1; + try { + // check out DBConnection + conn = DBConnectionPool.getDBConnection("MetacatVersion.getVersionFromDB()"); + serialNumber = conn.getCheckOutSerialNumber(); + pstmt = conn.prepareStatement("SELECT version FROM db_version WHERE status = ?"); + pstmt.setInt(1, 1); + rs = pstmt.executeQuery(); + if(rs.next()) { + version = rs.getString(1); + } + pstmt.close(); + rs.close(); + } catch (SQLException e) { + throw new SQLException("MetacatVersion.getVersionFromDB - sql error: " + e.getMessage()); + }finally { + try { + if (pstmt != null) { + pstmt.close(); + } + if (rs != null) { + rs.close(); + } + } finally { + DBConnectionPool.returnDBConnection(conn, serialNumber); + } + } + return version; + } } diff --git a/test/edu/ucsb/nceas/metacattest/VersionTest.java b/test/edu/ucsb/nceas/metacattest/VersionTest.java index f99e5aefc..e6849330b 100755 --- a/test/edu/ucsb/nceas/metacattest/VersionTest.java +++ b/test/edu/ucsb/nceas/metacattest/VersionTest.java @@ -23,6 +23,8 @@ */ package edu.ucsb.nceas.metacattest; +import java.sql.SQLException; + import edu.ucsb.nceas.MCTestCase; import edu.ucsb.nceas.metacat.MetacatVersion; import edu.ucsb.nceas.metacat.properties.PropertyService; @@ -62,8 +64,7 @@ public void testGetVersion() /** * Test the "printVersionAsXml" method by printing its output. */ - public void testPrintVersionAsXml() - { + public void testPrintVersionAsXml() throws SQLException { try { System.out.println(MetacatVersion.getVersionAsXml()); assertTrue(MetacatVersion.getVersionAsXml().indexOf( @@ -73,4 +74,13 @@ public void testPrintVersionAsXml() } } + /** + * Test the method of getVersionFromDB + * @throws SQLException + * @throws PropertyNotFoundException + */ + public void testGetVersionFromDB() throws SQLException, PropertyNotFoundException { + assertTrue(MetacatVersion.getVersionFromDB().equals( + PropertyService.getProperty("application.metacatVersion"))); + } } From 1ab7a9e34c295360d3d9a5e8e6d55f463bb10797 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Tue, 7 Jan 2020 13:33:11 -0800 Subject: [PATCH 07/12] Add the code for updating the upgrade status. Also add the junit test code. Ref: https://github.com/NCEAS/metacat/issues/1416 --- lib/metacat.properties | 6 ++ .../nceas/metacat/admin/MetacatAdmin.java | 49 ++++++++++ .../nceas/metacat/admin/MetacatAdminTest.java | 94 +++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100755 test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java diff --git a/lib/metacat.properties b/lib/metacat.properties index a82592d12..d4cd5bbe4 100755 --- a/lib/metacat.properties +++ b/lib/metacat.properties @@ -14,6 +14,12 @@ configutil.geoserverConfigured=false configutil.dataoneConfigured=false configutil.ezidConfigured=bypassed +#The property of configutil.upgrade.status depends on other status (database, java et al). +#If all of them are success, the property of configutil.upgrade will be successs; otherwise failure. +configutil.upgrade.status= +configutil.upgrade.database.status= +configutil.upgrade.java.status= + ############### Server Values ################# server.name=localhost diff --git a/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java b/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java index dcf830b19..b2cf778fc 100755 --- a/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java +++ b/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java @@ -29,15 +29,24 @@ package edu.ucsb.nceas.metacat.admin; +import java.util.Map; +import java.util.Set; import java.util.Vector; import javax.servlet.http.HttpServletRequest; +import edu.ucsb.nceas.metacat.properties.PropertyService; +import edu.ucsb.nceas.utilities.GeneralPropertyException; + /** * A suite of utility classes for querying DB * */ public abstract class MetacatAdmin { + + public final static String SUCCESS = "success"; + public final static String FAILURE = "failure"; + public final static String IN_PROGRESS = "in_progress"; /** * Require subclasses to implement a properties validator. @@ -46,5 +55,45 @@ public abstract class MetacatAdmin { * validation. */ protected abstract Vector validateOptions(HttpServletRequest request); + + + /** + * Update the status of an sub upgrade process (e.g. database). It will also update the status + * of the property which indicates the whole upgrade process (database, and java upgrade). + * @param propertyName the name of property needs to be updated + * @param status the new status should be set + * @throws GeneralPropertyException + */ + public static void updateUpgradeStatus(String propertyName, String status, boolean persist) throws GeneralPropertyException { + PropertyService.setPropertyNoPersist(propertyName, status); + //update the indicator of the whole upgrade process. + if (status.equals(FAILURE)) { + //this sub upgrade process failed, so the whole process fails as well + PropertyService.setPropertyNoPersist("configutil.upgrade.status", FAILURE); + } else if (status.equals(SUCCESS)) { + // This sub upgrade process succeeded. If other sub process already succeeded, we need to set the whole process success; otherwise, we keep its original value (do nothing). + Map properties = PropertyService.getPropertiesByGroup("configutil.upgrade"); + Set names = properties.keySet(); + boolean success = true; + for (String name : names) { + //we only look the sub processes (excluding the current one) + if (!name.equals("configutil.upgrade.status") && !name.equals(propertyName)) { + if (!PropertyService.getProperty(name).equals(SUCCESS)) { + //found a failed or in_progress process. So the whole process should not be success + success = false; + break; + } + } + } + if (success) { + PropertyService.setPropertyNoPersist("configutil.upgrade.status", SUCCESS); + } + } + if(persist) { + // persist them all + PropertyService.persistProperties(); + PropertyService.syncToSettings(); + } + } } diff --git a/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java b/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java new file mode 100755 index 000000000..0ad714faf --- /dev/null +++ b/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java @@ -0,0 +1,94 @@ +/** + * '$RCSfile$' + * Copyright: 2000 Regents of the University of California and the + * National Center for Ecological Analysis and Synthesis + * Purpose: To test the MetaCatURL class by JUnit + * Authors: Jing Tao + * + * '$Author$' + * '$Date$' + * '$Revision$' + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package edu.ucsb.nceas.metacat.admin; + +import edu.ucsb.nceas.MCTestCase; +import edu.ucsb.nceas.metacat.admin.MetacatAdmin; +import edu.ucsb.nceas.metacat.properties.PropertyService; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * A JUnit test for testing the MetacatAdmin class + */ +public class MetacatAdminTest extends MCTestCase { + + /** + * Constructor to build the test + * + * @param name the name of the test method + */ + public MetacatAdminTest(String name){ + super(name); + } + + + + /** + * Create a suite of tests to be run together + */ + public static Test suite() + { + TestSuite suite = new TestSuite(); + suite.addTest(new MetacatAdminTest("initialize")); + suite.addTest(new MetacatAdminTest("testUpdateUpgradeStatus")); + return suite; + } + + /** + * Run an initial test that always passes to check that the test + * harness is working. + */ + public void initialize() { + assertTrue(1 == 1); + } + + /** + * Test the method of updateUpgradeStatus + */ + public void testUpdateUpgradeStatus() throws Exception { + boolean persist = false; + String status = PropertyService.getProperty("configutil.upgrade.status"); + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.IN_PROGRESS, persist); + assertTrue(PropertyService.getProperty("configutil.upgrade.database.status").equals(MetacatAdmin.IN_PROGRESS)); + assertTrue(PropertyService.getProperty("configutil.upgrade.status").equals(status)); + + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.FAILURE, persist); + assertTrue(PropertyService.getProperty("configutil.upgrade.database.status").equals(MetacatAdmin.FAILURE)); + assertTrue(PropertyService.getProperty("configutil.upgrade.status").equals(MetacatAdmin.FAILURE)); + + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.java.status", MetacatAdmin.SUCCESS, persist); + assertTrue(PropertyService.getProperty("configutil.upgrade.java.status").equals(MetacatAdmin.SUCCESS)); + assertTrue(PropertyService.getProperty("configutil.upgrade.database.status").equals(MetacatAdmin.FAILURE)); + assertTrue(PropertyService.getProperty("configutil.upgrade.status").equals(MetacatAdmin.FAILURE)); + + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.SUCCESS, persist); + assertTrue(PropertyService.getProperty("configutil.upgrade.java.status").equals(MetacatAdmin.SUCCESS)); + assertTrue(PropertyService.getProperty("configutil.upgrade.database.status").equals(MetacatAdmin.SUCCESS)); + assertTrue(PropertyService.getProperty("configutil.upgrade.status").equals(MetacatAdmin.SUCCESS)); + } +} From 6bd4d3803ebda01c32debd8706ae93410ecb01f6 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Tue, 7 Jan 2020 15:45:33 -0800 Subject: [PATCH 08/12] Add the code to update the status of the upgrading process. Also remove some obsoleted code. Ref:https://github.com/NCEAS/metacat/issues/1416 --- src/edu/ucsb/nceas/metacat/admin/DBAdmin.java | 125 ++++++++---------- 1 file changed, 52 insertions(+), 73 deletions(-) diff --git a/src/edu/ucsb/nceas/metacat/admin/DBAdmin.java b/src/edu/ucsb/nceas/metacat/admin/DBAdmin.java index 7ae9b71b1..7df324fa2 100755 --- a/src/edu/ucsb/nceas/metacat/admin/DBAdmin.java +++ b/src/edu/ucsb/nceas/metacat/admin/DBAdmin.java @@ -463,52 +463,6 @@ public DBVersion getUnRegisteredDBVersion() throws AdminException, SQLException } } - /** - * Updates the version of the database. Typically this is done in the update - * scripts that get run when we upgrade the application. This method can be - * used if you are automating a patch on the database internally. - * - * @returns string representing the version of the database. - */ - public void updateDBVersion() throws SQLException { - DBConnection conn = null; - PreparedStatement pstmt = null; - int serialNumber = -1; - try { - - // check out DBConnection - conn = DBConnectionPool.getDBConnection("DBAdmin.updateDBVersion()"); - serialNumber = conn.getCheckOutSerialNumber(); - conn.setAutoCommit(false); - - pstmt = conn.prepareStatement("UPDATE db_version SET status = ?"); - pstmt.setInt(1, VERSION_INACTIVE); - pstmt.execute(); - pstmt.close(); - - pstmt = conn.prepareStatement("INSERT INTO db_version " - + "(version, status, date_created) VALUES (?,?,?)"); - pstmt.setString(1, MetacatVersion.getVersionID()); - pstmt.setInt(2, VERSION_ACTIVE); - pstmt.setTimestamp(3, new Timestamp(new Date().getTime())); - pstmt.execute(); - - conn.commit(); - } catch (SQLException e) { - conn.rollback(); - throw new SQLException("DBAdmin.updateDBVersion - sql error: " + e.getMessage()); - } catch (PropertyNotFoundException pnfe) { - conn.rollback(); - throw new SQLException("DBAdmin.updateDBVersion - property error" + pnfe.getMessage()); - } - finally { - try { - pstmt.close(); - } finally { - DBConnectionPool.returnDBConnection(conn, serialNumber); - } - } - } /** * Validate connectivity to the database. Validation methods return a string @@ -808,6 +762,7 @@ public Vector getUpdateClasses() throws AdminException { * the database and calls runSQLFile on each. */ public void upgradeDatabase() throws AdminException { + boolean persist = true; try { // get a list of the script names that need to be run Vector updateScriptList = getUpdateScripts(); @@ -816,37 +771,61 @@ public void upgradeDatabase() throws AdminException { for (String updateScript : updateScriptList) { runSQLFile(updateScript); } + try { + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.SUCCESS, persist); + } catch (Exception e) { + logMetacat.warn("DBAdmin.upgradeDatabase - couldn't update the status of the upgrading database process since " + e.getMessage()); + } + } catch (SQLException sqle) { + try { + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.FAILURE, persist); + } catch (Exception e) { + logMetacat.warn("DBAdmin.upgradeDatabase - couldn't update the status of the upgrading database process since " + e.getMessage()); + } + throw new AdminException("DBAdmin.upgradeDatabase - SQL error when running upgrade scripts: " + + sqle.getMessage()); + } - // get the classes we need to execute in order to bring DB to current version - Vector updateClassList = getUpdateClasses(); - for (String className : updateClassList) { - UpgradeUtilityInterface utility = null; - try { - utility = (UpgradeUtilityInterface) Class.forName(className).newInstance(); - utility.upgrade(); - } catch (SolrSchemaModificationException e) { - //don't throw the exception and continue - solrSchemaException = e; - continue; - } catch (Exception e) { - throw new AdminException("DBAdmin.upgradeDatabase - error getting utility class: " - + className + ". Error message: " - + e.getMessage()); - } + // get the classes we need to execute in order to bring DB to current version + Vector updateClassList = getUpdateClasses(); + for (String className : updateClassList) { + UpgradeUtilityInterface utility = null; + try { + utility = (UpgradeUtilityInterface) Class.forName(className).newInstance(); + utility.upgrade(); + } catch (SolrSchemaModificationException e) { + //don't throw the exception and continue + solrSchemaException = e; + continue; + } catch (Exception e) { + try { + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.java.status", MetacatAdmin.FAILURE, persist); + } catch (Exception ee) { + logMetacat.warn("DBAdmin.upgradeDatabase - couldn't update the status of the upgrading database process since " + ee.getMessage()); + } + throw new AdminException("DBAdmin.upgradeDatabase - error getting utility class: " + + className + ". Error message: " + + e.getMessage()); } + } + try { + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.java.status", MetacatAdmin.SUCCESS, persist); + } catch (Exception e) { + logMetacat.warn("DBAdmin.upgradeDatabase - couldn't update the status of the upgrading database process since " + e.getMessage()); + } + - // update the db version to be the metacat version - databaseVersion = new DBVersion(SystemUtil.getMetacatVersion().getVersionString()); - } catch (SQLException sqle) { - throw new AdminException("DBAdmin.upgradeDatabase - SQL error when running upgrade scripts: " - + sqle.getMessage()); + // update the db version to be the metacat version + try { + databaseVersion = new DBVersion(SystemUtil.getMetacatVersion().getVersionString()); } catch (PropertyNotFoundException pnfe) { - throw new AdminException("DBAdmin.upgradeDatabase - SQL error when running upgrade scripts: " - + pnfe.getMessage()); - }catch (NumberFormatException nfe) { - throw new AdminException("DBAdmin.upgradeDatabase - Bad version format numbering: " - + nfe.getMessage()); - } + throw new AdminException("DBAdmin.upgradeDatabase - Couldn't set the database version since: " + + pnfe.getMessage()); + }catch (NumberFormatException nfe) { + throw new AdminException("DBAdmin.upgradeDatabase - Bad version format numbering: " + + nfe.getMessage()); + } + } /** From e5599e76aceaacda2805f769a294ff84de6f9a25 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Wed, 8 Jan 2020 10:29:53 -0800 Subject: [PATCH 09/12] Add the properties of upgrade_status and metacat_version on the node capabilities method. --- .../nceas/metacat/dataone/MNodeService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java b/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java index c8be3a4e4..3d0ac7dea 100644 --- a/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java +++ b/src/edu/ucsb/nceas/metacat/dataone/MNodeService.java @@ -106,6 +106,7 @@ import org.dataone.service.types.v2.Log; import org.dataone.service.types.v2.LogEntry; import org.dataone.service.types.v2.OptionList; +import org.dataone.service.types.v2.Property; import org.dataone.service.types.v1.MonitorInfo; import org.dataone.service.types.v1.MonitorList; import org.dataone.service.types.v2.Node; @@ -154,6 +155,7 @@ import edu.ucsb.nceas.metacat.McdbDocNotFoundException; import edu.ucsb.nceas.metacat.MetaCatServlet; import edu.ucsb.nceas.metacat.MetacatHandler; +import edu.ucsb.nceas.metacat.MetacatVersion; import edu.ucsb.nceas.metacat.ReadOnlyChecker; import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines; import edu.ucsb.nceas.metacat.common.query.stream.ContentTypeByteArrayInputStream; @@ -1401,6 +1403,27 @@ public Node getCapabilities() node.setSynchronization(synchronization); node.setType(nodeType); + + //add properties such as the Metacat version and upgrade status + String upgradeStatus = Settings.getConfiguration().getString("configutil.upgrade.status"); + if (upgradeStatus != null && !upgradeStatus.trim().equals("")) { + Property statusProperty = new Property(); + statusProperty.setKey("upgrade_status"); + statusProperty.setValue(upgradeStatus); + node.addProperty(statusProperty); + } + try { + String metacatVersion = MetacatVersion.getVersionFromDB(); + if (metacatVersion != null && !metacatVersion.trim().equals("")) { + Property versionProperty = new Property(); + versionProperty.setKey("metacat_version"); + versionProperty.setValue(metacatVersion); + node.addProperty(versionProperty); + } + } catch (SQLException e) { + logMetacat.warn("MNodeService.getCapabilities - couldn't get the metacat version since " + e.getMessage()); + } + return node; } catch (PropertyNotFoundException pnfe) { From e41adabd99cdff2b8c36145f729e55e17f53dbf7 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Wed, 8 Jan 2020 10:55:47 -0800 Subject: [PATCH 10/12] The the whole status to be in_progress if one of sub upgrade process is in_progress. --- src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java | 10 +++++----- .../edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java b/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java index b2cf778fc..da771fce4 100755 --- a/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java +++ b/src/edu/ucsb/nceas/metacat/admin/MetacatAdmin.java @@ -67,10 +67,7 @@ public abstract class MetacatAdmin { public static void updateUpgradeStatus(String propertyName, String status, boolean persist) throws GeneralPropertyException { PropertyService.setPropertyNoPersist(propertyName, status); //update the indicator of the whole upgrade process. - if (status.equals(FAILURE)) { - //this sub upgrade process failed, so the whole process fails as well - PropertyService.setPropertyNoPersist("configutil.upgrade.status", FAILURE); - } else if (status.equals(SUCCESS)) { + if (status.equals(SUCCESS)) { // This sub upgrade process succeeded. If other sub process already succeeded, we need to set the whole process success; otherwise, we keep its original value (do nothing). Map properties = PropertyService.getPropertiesByGroup("configutil.upgrade"); Set names = properties.keySet(); @@ -88,7 +85,10 @@ public static void updateUpgradeStatus(String propertyName, String status, boole if (success) { PropertyService.setPropertyNoPersist("configutil.upgrade.status", SUCCESS); } - } + } else if (status.equals(FAILURE) || status.equals(IN_PROGRESS)) { + //this sub upgrade process failed or is in progress, so the whole process will have the same status as well + PropertyService.setPropertyNoPersist("configutil.upgrade.status", status); + } if(persist) { // persist them all PropertyService.persistProperties(); diff --git a/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java b/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java index 0ad714faf..8893b42b0 100755 --- a/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java +++ b/test/edu/ucsb/nceas/metacat/admin/MetacatAdminTest.java @@ -75,7 +75,7 @@ public void testUpdateUpgradeStatus() throws Exception { String status = PropertyService.getProperty("configutil.upgrade.status"); MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.IN_PROGRESS, persist); assertTrue(PropertyService.getProperty("configutil.upgrade.database.status").equals(MetacatAdmin.IN_PROGRESS)); - assertTrue(PropertyService.getProperty("configutil.upgrade.status").equals(status)); + assertTrue(PropertyService.getProperty("configutil.upgrade.status").equals(MetacatAdmin.IN_PROGRESS)); MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.FAILURE, persist); assertTrue(PropertyService.getProperty("configutil.upgrade.database.status").equals(MetacatAdmin.FAILURE)); From 3d93ae2f2dcdc175994bb9561a90e701e4389370 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Thu, 9 Jan 2020 09:40:15 -0800 Subject: [PATCH 11/12] Modify the release note for 2.12.3. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb034d337..f71d78847 100755 --- a/README.md +++ b/README.md @@ -68,9 +68,9 @@ for the next release. ## Release Notes ### Release Notes for 2.12.3 -Bugs fixed in this release: +New features and bugs fixed in this release: * Return an invalid response to the call of cn.getLogRecords if some log records have a null ip address -* Make the accounts of returned log records more accurate +* Add the indication of completing the database upgrade process during configuration ### Release Notes for 2.12.2 Bugs fixed in this release: From d5a35254b98c3940c324734f68dfe8c80fa95543 Mon Sep 17 00:00:00 2001 From: Jing Tao Date: Thu, 9 Jan 2020 10:07:15 -0800 Subject: [PATCH 12/12] If we don't need to do the upgrade database and other stuff, we will set the upgrading success. --- src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java b/src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java index abc54f0c7..9fff91e4a 100755 --- a/src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java +++ b/src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java @@ -363,6 +363,14 @@ public void configureProperties(HttpServletRequest request, dbVersion.compareTo(metacatVersion) == 0) { PropertyService.setProperty("configutil.databaseConfigured", PropertyService.CONFIGURED); + //Also set the upgrade status to be success since the upgrade happened successfully at the previous upgrade + try { + boolean persist = true; + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.database.status", MetacatAdmin.SUCCESS, persist); + MetacatAdmin.updateUpgradeStatus("configutil.upgrade.java.status", MetacatAdmin.SUCCESS, persist); + } catch (Exception e) { + logMetacat.warn("PropertiesAdmin.configureProperties - couldn't update the status of the upgrading process since " + e.getMessage()); + } } // Reload the main metacat configuration page