This commit is contained in:
Lucio Lelii 2019-04-17 15:36:38 +00:00
parent 0adfa5b959
commit 9d6794ffde
3 changed files with 28 additions and 14 deletions

View File

@ -248,14 +248,14 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i
float previousStatus = -3; float previousStatus = -3;
String host = WPSConfig.getInstance().getWPSConfig().getServer().getHostname(); String host = WPSConfig.getInstance().getWPSConfig().getServer().getHostname();
public void updateStatus(float status) { public void updateStatus(float status, boolean canWrite) {
if (agent != null) { if (agent != null) {
if (status != previousStatus) { if (status != previousStatus) {
LOGGER.debug("STATUS update to: {} ", status ); LOGGER.debug("STATUS update to: {} ", status );
previousStatus = status; previousStatus = status;
super.update(new Integer((int) status)); super.update(new Integer((int) status));
try { try {
updateComputationOnWS(status, null); if (canWrite) updateComputationOnWS(status, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("error updating compution on WS"); LOGGER.warn("error updating compution on WS");
} }
@ -425,11 +425,11 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i
LOGGER.info("9 - Running the computation and updater"); LOGGER.info("9 - Running the computation and updater");
LOGGER.info("Initializing the WPS status of the computation"); LOGGER.info("Initializing the WPS status of the computation");
updateStatus(0); updateStatus(0, canWriteOnShub);
LOGGER.info("Initializing the computation"); LOGGER.info("Initializing the computation");
agent.init(); agent.init();
LOGGER.info("Updating status"); LOGGER.info("Updating status");
runStatusUpdater(); runStatusUpdater(canWriteOnShub);
LOGGER.info("Running the computation"); LOGGER.info("Running the computation");
agent.compute(); agent.compute();
LOGGER.info("The computation has finished. Retrieving output"); LOGGER.info("The computation has finished. Retrieving output");
@ -505,8 +505,12 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i
private boolean checkWriteAuthorization(String username) { private boolean checkWriteAuthorization(String username) {
if (env!=null && env.getShubUsersExcluded()!=null) { if (env!=null && env.getShubUsersExcluded()!=null) {
if (env.getShubUsersExcluded().isEmpty()) return false; if (env.getShubUsersExcluded().isEmpty()) {
else if (env.getShubUsersExcluded().contains(username)) return false; return false;
}
if (env.getShubUsersExcluded().contains(username)) {
return false;
}
} }
return true; return true;
} }
@ -533,12 +537,18 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i
} }
public class StatusUpdater implements Runnable { public class StatusUpdater implements Runnable {
private boolean canWrite = true;
public StatusUpdater(boolean canWrite) {
this.canWrite = canWrite;
}
@Override @Override
public void run() { public void run() {
while (agent != null && !isCancelled() && agent.getStatus() < 100) { while (agent != null && !isCancelled() && agent.getStatus() < 100) {
try { try {
updateStatus(agent.getStatus()); updateStatus(agent.getStatus(), canWrite);
Thread.sleep(10000); Thread.sleep(10000);
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
} }
@ -546,8 +556,8 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i
} }
} }
private void runStatusUpdater() { private void runStatusUpdater(boolean canWrite) {
StatusUpdater updater = new StatusUpdater(); StatusUpdater updater = new StatusUpdater(canWrite);
Thread t = new Thread(updater); Thread t = new Thread(updater);
t.start(); t.start();

View File

@ -29,6 +29,8 @@ public class ConfigurationManager {
private static Boolean useStorage = null; private static Boolean useStorage = null;
static boolean simulationMode = false; static boolean simulationMode = false;
EnvironmentVariableManager env = null;
public static synchronized Integer getMaxComputations(){ public static synchronized Integer getMaxComputations(){
return maxComputations; return maxComputations;
} }
@ -78,10 +80,11 @@ public class ConfigurationManager {
public ConfigurationManager(EnvironmentVariableManager env) { public ConfigurationManager(EnvironmentVariableManager env) {
if (env == null) inizializePropertiesUsingTemplateFile(); if (env == null) inizializePropertiesUsingTemplateFile();
} else {
maxComputations = env.getMaxComputation();
public ConfigurationManager() { useStorage = env.isSaveOnStorage();
inizializePropertiesUsingTemplateFile(); simulationMode = env.isSimulationMode();
}
} }
public AlgorithmConfiguration getConfig() { public AlgorithmConfiguration getConfig() {

View File

@ -9,6 +9,7 @@ public class EnvironmentVariableManager {
this.maxComputation = maxComputation; this.maxComputation = maxComputation;
this.saveOnStorage = saveOnStorage; this.saveOnStorage = saveOnStorage;
this.simulationMode = simulationMode; this.simulationMode = simulationMode;
this.shubUsersExcluded = shubUsersExcluded;
} }
private int maxComputation; private int maxComputation;
private boolean saveOnStorage; private boolean saveOnStorage;