Commit 38bb37e4 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Fix URI not hierarchical through temp files

parent 88e80502
......@@ -7,6 +7,7 @@ import org.activeeon.morphemic.infrastructure.deployment.PAResourceManagerGatewa
import org.activeeon.morphemic.model.*;
import org.activeeon.morphemic.service.EntityManagerHelper;
import org.activeeon.morphemic.service.NodeCandidateUtils;
import org.activeeon.morphemic.service.TemporaryFilesHelper;
import org.activeeon.morphemic.service.UpdatingNodeCandidatesThread;
import org.apache.commons.lang3.Validate;
import org.apache.log4j.Logger;
......@@ -16,6 +17,7 @@ import org.json.JSONObject;
import org.ow2.proactive.resourcemanager.exception.RMException;
import org.ow2.proactive.scheduler.common.exception.NotConnectedException;
import org.ow2.proactive.scheduler.common.exception.UserException;
import org.ow2.proactive.scheduler.common.job.JobId;
import org.ow2.proactive.scheduler.common.job.JobResult;
import org.ow2.proactive.scheduler.common.job.JobState;
import org.ow2.proactive.scheduler.common.job.TaskFlowJob;
......@@ -30,7 +32,6 @@ import javax.ws.rs.NotFoundException;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.KeyException;
import java.util.*;
......@@ -269,19 +270,18 @@ public class PAGateway {
throw new IllegalArgumentException("Spark tasks are not handled yet.");
}
File fXmlFile = null;
LOGGER.info("NodeSource deployment workflow filename: " + filename);
try {
LOGGER.info("filename: " + filename);
LOGGER.info("getClass().getResource(filename): " + getClass().getResource(filename).toString());
LOGGER.info("getClass().getResource(filename).getPath()" + getClass().getResource(filename).getPath());
LOGGER.info("getClass().getResource(filename).toExternalForm(): " + getClass().getResource(filename).toExternalForm());
fXmlFile = new File(getClass().getResource(filename).toExternalForm().split(":")[1]);
} catch (Exception e) {
LOGGER.error(e.getStackTrace());
fXmlFile = TemporaryFilesHelper.createTempFileFromResource(filename);
} catch (IOException ioe) {
LOGGER.error("Opening the NS deployment workflow file failed due to : " + Arrays.toString(ioe.getStackTrace()));
}
assert fXmlFile != null;
LOGGER.info("Submitting the file: " + fXmlFile.toString());
LOGGER.info("Trying to deploy the NS: " + nodeSourceName);
schedulerGateway.submit(fXmlFile, variables);
JobId jobId = schedulerGateway.submit(fXmlFile, variables);
LOGGER.info("Job submitted with ID: " + jobId);
TemporaryFilesHelper.delete(fXmlFile);
}
/**
......
package org.activeeon.morphemic.application.deployment;
import org.activeeon.morphemic.service.TemporaryFilesHelper;
import org.apache.log4j.Logger;
import org.ow2.proactive.scheduler.common.job.JobVariable;
import org.ow2.proactive.scheduler.common.task.ScriptTask;
......@@ -9,12 +10,14 @@ import org.ow2.proactive.scripting.SelectionScript;
import org.ow2.proactive.scripting.SimpleScript;
import org.ow2.proactive.scripting.TaskScript;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class PAFactory {
......@@ -49,14 +52,16 @@ public class PAFactory {
*/
public static SimpleScript createSimpleScriptFromFIle(String scriptFileName, String scriptLanguage) {
SimpleScript mySQLSimpleScript = null;
LOGGER.debug("Creating a simple script from the file : " + scriptFileName);
try {
mySQLSimpleScript = createSimpleScript(new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource(scriptFileName).toURI()))), scriptLanguage);
} catch (IOException ie) {
LOGGER.error("ERROR: Simple script not created due to an IOException: " + ie.toString());
} catch (URISyntaxException use) {
LOGGER.error("ERROR: Simple script not created due to an URISyntaxException: " + use.toString());
String script;
String newLine = System.getProperty("line.separator");
String scriptFileNameWithSeparator = (scriptFileName.startsWith(File.separator)) ?
scriptFileName : File.separator + scriptFileName;
LOGGER.debug("Creating a simple script from the file : " + scriptFileNameWithSeparator);
try (Stream<String> lines = new BufferedReader(new InputStreamReader(
PAFactory.class.getResourceAsStream(scriptFileNameWithSeparator))).lines()) {
script = lines.collect(Collectors.joining(newLine));
}
mySQLSimpleScript = createSimpleScript(script, scriptLanguage);
LOGGER.debug("Simple script created.");
return mySQLSimpleScript;
}
......@@ -187,17 +192,18 @@ public class PAFactory {
* @param parameters The selection script parameters
* @return A ProActive SelectionScript instance
*/
public static SelectionScript createGroovySelectionScript(String scriptFileName, String[] parameters) {
public static SelectionScript createGroovySelectionScript(String scriptFileName, String[] parameters) throws IOException {
SelectionScript selectionScript = null;
LOGGER.debug("Creating a groovy selection script");
File scriptFile;
scriptFile = TemporaryFilesHelper.createTempFileFromResource(scriptFileName);
try {
selectionScript = new SelectionScript(Paths.get(ClassLoader.getSystemResource(scriptFileName).toURI()).toFile(), parameters);
selectionScript = new SelectionScript(scriptFile, parameters);
} catch (InvalidScriptException ie) {
LOGGER.error("ERROR: Selection script not created due to an InvalidScriptException: " + ie.toString());
} catch (URISyntaxException use) {
LOGGER.error("ERROR: Selection script not created due to an URISyntaxException: " + use.toString());
}
LOGGER.debug("Groovy selection script created.");
TemporaryFilesHelper.delete(scriptFile);
return selectionScript;
}
......
......@@ -9,6 +9,8 @@ import org.activeeon.morphemic.model.GeoLocationData;
import org.apache.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -29,9 +31,9 @@ public class GeoLocationUtils {
private List<GeoLocationData> chargeCloudGLsDB() {
List<GeoLocationData> cloudsGLDB = new LinkedList<>();
File input;
File input = null;
try {
input = new File(getClass().getResource(File.separator + "db_cloud_regions.csv").toExternalForm().split(":")[1]);
input = TemporaryFilesHelper.createTempFileFromResource(File.separator + "db_cloud_regions.csv");
CsvSchema csv = CsvSchema.emptySchema().withHeader().withColumnSeparator(' ').withNullValue("");
CsvMapper csvMapper = new CsvMapper();
MappingIterator<Map<?, ?>> mappingIterator = csvMapper.reader().forType(Map.class).with(csv).readValues(input);
......@@ -42,9 +44,11 @@ public class GeoLocationUtils {
Double.valueOf(map.get("LONGITUDE").toString()),
map.get("REGION").toString(),
map.get("CLOUD").toString())));
} catch(Exception e) {
e.printStackTrace();
} catch (IOException ioe) {
LOGGER.error("Charging the Geolocation database failed due to: " + Arrays.toString(ioe.getStackTrace()));
}
TemporaryFilesHelper.delete(input);
return cloudsGLDB;
}
......
package org.activeeon.morphemic.service;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import java.io.*;
public class TemporaryFilesHelper {
private static final String TMP_SYS_PROPERTY = "java.io.tmpdir";
private static final String TMP_DIRECTORY;
private static final File TMP_DIRECTORY_FILE;
private static final Logger LOGGER = Logger.getLogger(TemporaryFilesHelper.class);
static {
TMP_DIRECTORY = ((System.getProperty(TMP_SYS_PROPERTY).endsWith(File.separator)) ?
System.getProperty(TMP_SYS_PROPERTY) + "proactive_tmp" :
System.getProperty(TMP_SYS_PROPERTY) + File.separator + "proactive_tmp");
TMP_DIRECTORY_FILE = new File(TMP_DIRECTORY);
boolean result = TMP_DIRECTORY_FILE.mkdirs();
if (result) {
LOGGER.info("Temporary directory created successfully");
} else {
LOGGER.warn("Temporary directory couldn't be created");
}
}
public static File createTempFile(String prefix, String suffix) throws IOException {
File newFile = File.createTempFile(prefix, suffix, TMP_DIRECTORY_FILE);
newFile.deleteOnExit();
LOGGER.info("Temporary file " + newFile.getAbsolutePath() + " created successfully");
return newFile;
}
public static File createTempFile(String prefix, String suffix, InputStream inStream) throws IOException {
File newFile = createTempFile(prefix, suffix);
byte[] buffer = new byte[inStream.available()];
inStream.read(buffer);
try (OutputStream outStream = new FileOutputStream(newFile)) {
outStream.write(buffer);
IOUtils.closeQuietly(inStream);
IOUtils.closeQuietly(outStream);
}
LOGGER.info("Temporary file " + newFile.getAbsolutePath() + " filled successfully with inputStream");
return newFile;
}
public static File createTempFile(String filename, InputStream inStream) throws IOException {
String prefix = filename.split("[.]")[0];
String suffix = filename.substring(filename.indexOf("."));
return createTempFile(prefix, suffix, inStream);
}
public static File createTempFileFromResource(String filename) throws IOException {
return createTempFile(filename.trim().substring(filename.lastIndexOf(File.separator)+1),
TemporaryFilesHelper.class.getResourceAsStream(filename));
}
public static void delete(File fileToDelete) {
if (fileToDelete != null) {
boolean result = fileToDelete.delete();
if (result) {
LOGGER.info("Temporary file deleted successfully");
} else {
LOGGER.warn("Temporary file couldn't be deleted");
}
}
}
}
......@@ -22,9 +22,9 @@
<properties>
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/proactive" />
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="admin"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mariadb://melodic-store:3306/proactive" />
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDB103Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment