Detect when computer is runnout of free space on hard drive

This commit is contained in:
Laurent Clouet
2016-05-02 13:26:11 +02:00
parent ac7377ad19
commit dc63b9791b
4 changed files with 81 additions and 18 deletions

View File

@@ -35,6 +35,7 @@ import com.sheepit.client.Error.Type;
import com.sheepit.client.exception.FermeException; import com.sheepit.client.exception.FermeException;
import com.sheepit.client.exception.FermeExceptionNoRightToRender; import com.sheepit.client.exception.FermeExceptionNoRightToRender;
import com.sheepit.client.exception.FermeExceptionNoSession; import com.sheepit.client.exception.FermeExceptionNoSession;
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
import com.sheepit.client.exception.FermeExceptionServerInMaintenance; import com.sheepit.client.exception.FermeExceptionServerInMaintenance;
import com.sheepit.client.exception.FermeExceptionServerOverloaded; import com.sheepit.client.exception.FermeExceptionServerOverloaded;
import com.sheepit.client.exception.FermeExceptionSessionDisabled; import com.sheepit.client.exception.FermeExceptionSessionDisabled;
@@ -284,6 +285,15 @@ public class Client {
continue; continue;
} }
if (ret == Error.Type.NO_SPACE_LEFT_ON_DEVICE) {
Job frame_to_reset = this.renderingJob; // copy it because the sendError will take ~5min to execute
this.renderingJob = null;
this.gui.error(Error.humanString(ret));
this.sendError(step, frame_to_reset, ret);
this.log.removeCheckPoint(step);
return -50;
}
if (ret != Error.Type.OK) { if (ret != Error.Type.OK) {
Job frame_to_reset = this.renderingJob; // copy it because the sendError will take ~5min to execute Job frame_to_reset = this.renderingJob; // copy it because the sendError will take ~5min to execute
this.renderingJob = null; this.renderingJob = null;
@@ -522,6 +532,7 @@ public class Client {
public Error.Type work(Job ajob) { public Error.Type work(Job ajob) {
int ret; int ret;
try {
ret = this.downloadExecutable(ajob); ret = this.downloadExecutable(ajob);
if (ret != 0) { if (ret != 0) {
this.log.error("Client::work problem with downloadExecutable (ret " + ret + ")"); this.log.error("Client::work problem with downloadExecutable (ret " + ret + ")");
@@ -539,6 +550,10 @@ public class Client {
this.log.error("Client::work problem with this.prepareWorkingDirectory (ret " + ret + ")"); this.log.error("Client::work problem with this.prepareWorkingDirectory (ret " + ret + ")");
return Error.Type.CAN_NOT_CREATE_DIRECTORY; return Error.Type.CAN_NOT_CREATE_DIRECTORY;
} }
}
catch (FermeExceptionNoSpaceLeftOnDevice e) {
return Error.Type.NO_SPACE_LEFT_ON_DEVICE;
}
File scene_file = new File(ajob.getScenePath()); File scene_file = new File(ajob.getScenePath());
File renderer_file = new File(ajob.getRendererPath()); File renderer_file = new File(ajob.getRendererPath());
@@ -631,7 +646,7 @@ public class Client {
return true; return true;
} }
protected int prepareWorkingDirectory(Job ajob) { protected int prepareWorkingDirectory(Job ajob) throws FermeExceptionNoSpaceLeftOnDevice {
int ret; int ret;
String renderer_archive = ajob.getRendererArchivePath(); String renderer_archive = ajob.getRendererArchivePath();
String renderer_path = ajob.getRendererDirectory(); String renderer_path = ajob.getRendererDirectory();

7
src/com/sheepit/client/Error.java Executable file → Normal file
View File

@@ -44,7 +44,10 @@ public class Error {
FAILED_TO_EXECUTE(16), FAILED_TO_EXECUTE(16),
OS_NOT_SUPPORTED(17), OS_NOT_SUPPORTED(17),
CPU_NOT_SUPPORTED(18), CPU_NOT_SUPPORTED(18),
GPU_NOT_SUPPORTED(19); GPU_NOT_SUPPORTED(19),
NO_SPACE_LEFT_ON_DEVICE(100),
;
private final int id; private final int id;
@@ -166,6 +169,8 @@ public class Error {
return "Operating System not supported."; return "Operating System not supported.";
case CPU_NOT_SUPPORTED: case CPU_NOT_SUPPORTED:
return "CPU not supported."; return "CPU not supported.";
case NO_SPACE_LEFT_ON_DEVICE:
return "No space left on hard disk";
default: default:
return in.toString(); return in.toString();
} }

View File

@@ -44,9 +44,10 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import com.sheepit.client.Error.ServerCode; import com.sheepit.client.Error.ServerCode;
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
public class Utils { public class Utils {
public static int unzipFileIntoDirectory(String zipFileName_, String jiniHomeParentDirName_) { public static int unzipFileIntoDirectory(String zipFileName_, String jiniHomeParentDirName_) throws FermeExceptionNoSpaceLeftOnDevice {
File rootdir = new File(jiniHomeParentDirName_); File rootdir = new File(jiniHomeParentDirName_);
try { try {
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName_)); ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName_));
@@ -78,6 +79,15 @@ public class Utils {
} }
fos.close(); fos.close();
} }
catch (IOException e) {
File f = new File(jiniHomeParentDirName_);
if (f.getUsableSpace() == 0) {
throw new FermeExceptionNoSpaceLeftOnDevice();
}
Log logger = Log.getInstance(null); // might not print the log since the config is null
logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e);
return -3;
}
catch (Exception e1) { catch (Exception e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@@ -91,6 +101,9 @@ public class Utils {
zis.closeEntry(); zis.closeEntry();
} }
} }
catch (FermeExceptionNoSpaceLeftOnDevice e) {
throw e;
}
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
Log logger = Log.getInstance(null); // might not print the log since the config is null Log logger = Log.getInstance(null); // might not print the log since the config is null
logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e); logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e);

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2016 Laurent CLOUET
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
*
* 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; version 2
* of the License.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.sheepit.client.exception;
public class FermeExceptionNoSpaceLeftOnDevice extends FermeException {
public FermeExceptionNoSpaceLeftOnDevice() {
super();
}
public FermeExceptionNoSpaceLeftOnDevice(String message_) {
super(message_);
}
}