Commit a2802794 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Fix Hashmap to Json casting in updateNodeCandidate method

parent 99582d13
...@@ -3,12 +3,14 @@ package org.activeeon.morphemic.service; ...@@ -3,12 +3,14 @@ package org.activeeon.morphemic.service;
import org.activeeon.morphemic.infrastructure.deployment.PAConnectorIaasGateway; import org.activeeon.morphemic.infrastructure.deployment.PAConnectorIaasGateway;
import org.activeeon.morphemic.model.*; import org.activeeon.morphemic.model.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence; import javax.persistence.Persistence;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -223,6 +225,16 @@ public class NodeCandidateUtils { ...@@ -223,6 +225,16 @@ public class NodeCandidateUtils {
return nodeCandidate; 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) { public void updateNodeCandidates(List<String> newCloudIds) {
em.getTransaction().begin(); em.getTransaction().begin();
...@@ -235,7 +247,7 @@ public class NodeCandidateUtils { ...@@ -235,7 +247,7 @@ public class NodeCandidateUtils {
LOGGER.info("Getting images from Proactive ..."); LOGGER.info("Getting images from Proactive ...");
JSONArray images = connectorIaasGateway.getImages(paCloud.getDummyInfrastructureName()); JSONArray images = connectorIaasGateway.getImages(paCloud.getDummyInfrastructureName());
LOGGER.info("Returned images: " + images.toString()); 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()); LOGGER.info("Consolidated images: " + consolidatedImages.toString());
//TODO: (Optimization) An images per region map structure <region,[image1,image2]> could be the best here. //TODO: (Optimization) An images per region map structure <region,[image1,image2]> could be the best here.
......
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