Commit 3f246d19 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[TAP,UWS] Fix backup restoration. When restoring upload only, the error message:

```
RESTORATION Incorrect JSON format for the serialization of an uploaded file!
Caused by a org.json.JSONException: JSONObject["length"] not a string.
[...]

RESTORATION Incorrect JSON format for the DALIUpload labelled "xxx" of the job "xxxxxxxxx": "xxxxxxxx" is not pointing a job parameter representing a file!
[...]

RESTORATION Unexpected error while restoring the UWS!
Caused by a java.lang.NullPointerException: Missing UploadFile! => Can not build a DaliUpload instance.
[...]
```

Now, in case of grave error while restoring backup files, it will be just
disabled, instead of preventing start-up of the TAP service.
In case of non-grave error while restoring a job or a user, the failed job or
error won't be restored and then the restoration process will go on with the
other jobs/users.
parent f83a6b75
Loading
Loading
Loading
Loading
+58 −56
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package tap.backup;
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2020 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -46,7 +46,7 @@ import uws.service.request.UploadFile;
 * <p><i>note: Basically the saved data are the same, but in addition some execution statistics are also added.</i></p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (12/2014)
 * @version 2.4 (01/2020)
 *
 * @see DefaultUWSBackupManager
 */
@@ -219,7 +219,8 @@ public class DefaultTAPBackupManager extends DefaultUWSBackupManager {
					// finally convert the ArrayList into a DALIUpload[] and add it inside the parameters list of the job:
					job.addOrUpdateParameter(TAPJob.PARAM_UPLOAD, lstTAPUploads.toArray(new DALIUpload[lstTAPUploads.size()]));
				}
			}catch(JSONException ex){}
			} catch(JSONException ex) {
			}
		}

		// 2. Get the execution report and add it into the given job:
@@ -279,6 +280,7 @@ public class DefaultTAPBackupManager extends DefaultUWSBackupManager {
				Object f = job.getAdditionalParameterValue(item.getString("file"));
				if (f == null || !(f instanceof UploadFile))
					getLogger().logUWS(LogLevel.ERROR, item, "RESTORATION", "Incorrect JSON format for the DALIUpload labelled \"" + label + "\" of the job \"" + job.getJobId() + "\": \"" + item.getString("file") + "\" is not pointing a job parameter representing a file!", null);
				else
					return new DALIUpload(label, (UploadFile)f);
			}
			/* If the upload spec. IS A URI, the attribute 'uri' should contain it
+34 −35
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package tap.resource;
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2020 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -71,7 +71,7 @@ import uws.service.log.UWSLog.LogLevel;
 * </ul>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (04/2015)
 * @version 2.4 (01/2020)
 *
 * @see UWSService
 */
@@ -131,7 +131,6 @@ public class ASync implements TAPResource {
			if (errorMsg != null) {
				errorMsg += " => Backup disabled.";
				service.getLogger().logTAP(LogLevel.FATAL, null, "ASYNC_INIT", errorMsg, null);
				throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, errorMsg);
			}
		}
	}
+213 −216
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package uws.service.backup;
 * You should have received a copy of the GNU Lesser General Public License
 * along with UWSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2012-2018 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2020 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -86,7 +86,7 @@ import uws.service.request.UploadFile;
 * <p>Another positive value will be considered as the frequency (in milliseconds) of the automatic backup (= {@link #saveAll()}).</p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 4.4 (08/2018)
 * @version 4.5 (01/2020)
 */
public class DefaultUWSBackupManager implements UWSBackupManager {

@@ -1181,11 +1181,8 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
			UploadFile upl = new UploadFile(obj.getString("paramName"), (obj.has("fileName") ? obj.getString("fileName") : null), obj.getString("location"), uws.getFileManager());
			if (obj.has("mime"))
				upl.mimeType = obj.getString("mime");
			try{
			if (obj.has("length"))
					upl.length = Long.parseLong(obj.getString("length"));
			}catch(NumberFormatException ex){
			}
				upl.length = obj.getLong("length");
			return upl;
		} catch(JSONException je) {
			getLogger().logUWS(LogLevel.ERROR, obj, "RESTORATION", "Incorrect JSON format for the serialization of an uploaded file!", je);