Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andreas Tsagkaropoulos
morphemic-preprocessor
Commits
4e043d9c
Unverified
Commit
4e043d9c
authored
Jan 29, 2021
by
Mohamed Khalil LABIDI
Committed by
GitHub
Jan 29, 2021
Browse files
Merge pull request #13 from mklkun/fix-uri
Fix URI not hierarchical through temp files
parents
b68f2f8d
38bb37e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/activeeon/morphemic/PAGateway.java
View file @
4e043d9c
...
...
@@ -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,15 +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
{
fXmlFile
=
new
File
(
getClass
().
get
Resource
(
filename
)
.
toURI
())
;
}
catch
(
URISyntax
Exception
e
)
{
LOGGER
.
error
(
e
.
getStackTrace
());
fXmlFile
=
TemporaryFilesHelper
.
createTempFileFrom
Resource
(
filename
);
}
catch
(
IO
Exception
io
e
)
{
LOGGER
.
error
(
"Opening the NS deployment workflow file failed due to : "
+
Arrays
.
toString
(
io
e
.
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
);
}
/**
...
...
src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java
View file @
4e043d9c
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
;
}
...
...
src/main/java/org/activeeon/morphemic/service/GeoLocationUtils.java
View file @
4e043d9c
...
...
@@ -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
().
get
Resource
(
File
.
separator
+
"db_cloud_regions.csv"
)
.
toURI
())
;
input
=
TemporaryFilesHelper
.
createTempFileFrom
Resource
(
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
.
prin
tStackTrace
();
}
catch
(
IO
Exception
io
e
)
{
LOGGER
.
error
(
"Charging the Geolocation database failed due to: "
+
Arrays
.
toString
(
ioe
.
ge
tStackTrace
()
))
;
}
TemporaryFilesHelper
.
delete
(
input
);
return
cloudsGLDB
;
}
...
...
src/main/java/org/activeeon/morphemic/service/TemporaryFilesHelper.java
0 → 100644
View file @
4e043d9c
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"
);
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment