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
a2802794
Commit
a2802794
authored
Jan 13, 2021
by
Mohamed Khalil Labidi
Browse files
Fix Hashmap to Json casting in updateNodeCandidate method
parent
99582d13
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/activeeon/morphemic/service/NodeCandidateUtils.java
View file @
a2802794
...
...
@@ -3,12 +3,14 @@ package org.activeeon.morphemic.service;
import
org.activeeon.morphemic.infrastructure.deployment.PAConnectorIaasGateway
;
import
org.activeeon.morphemic.model.*
;
import
org.apache.log4j.Logger
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.Persistence
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -223,6 +225,16 @@ public class NodeCandidateUtils {
return
nodeCandidate
;
}
private
static
JSONObject
apply
(
Object
object
)
{
JSONObject
myJson
=
null
;
try
{
myJson
=
new
JSONObject
(
new
ObjectMapper
().
writeValueAsString
(
object
));
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"Error in casting Hashmap to JSON: "
+
Arrays
.
toString
(
e
.
getStackTrace
()));
}
return
myJson
;
}
public
void
updateNodeCandidates
(
List
<
String
>
newCloudIds
)
{
em
.
getTransaction
().
begin
();
...
...
@@ -235,7 +247,7 @@ public class NodeCandidateUtils {
LOGGER
.
info
(
"Getting images from Proactive ..."
);
JSONArray
images
=
connectorIaasGateway
.
getImages
(
paCloud
.
getDummyInfrastructureName
());
LOGGER
.
info
(
"Returned images: "
+
images
.
toString
());
List
<
JSONObject
>
consolidatedImages
=
images
.
toList
().
parallelStream
().
map
(
o
->
(
JSONObject
)
o
).
filter
(
record
->
!
blacklistedRegions
.
contains
(
record
.
get
(
"location"
))).
collect
(
Collectors
.
toList
());
List
<
JSONObject
>
consolidatedImages
=
images
.
toList
().
parallelStream
().
map
(
NodeCandidateUtils:
:
apply
).
filter
(
record
->
!
blacklistedRegions
.
contains
(
record
.
get
(
"location"
))).
collect
(
Collectors
.
toList
());
LOGGER
.
info
(
"Consolidated images: "
+
consolidatedImages
.
toString
());
//TODO: (Optimization) An images per region map structure <region,[image1,image2]> could be the best here.
...
...
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