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

Fix image and hardware provider IDs

parent f429b3d2
...@@ -2,6 +2,7 @@ package org.activeeon.morphemic.service; ...@@ -2,6 +2,7 @@ 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.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -118,7 +119,7 @@ public class NodeCandidateUtils { ...@@ -118,7 +119,7 @@ public class NodeCandidateUtils {
hardware = new Hardware(); hardware = new Hardware();
hardware.setId(hardwareId); hardware.setId(hardwareId);
hardware.setName(hardwareJSON.optString("type")); hardware.setName(hardwareJSON.optString("type"));
hardware.setProviderId(paCloud.getCloudID()); hardware.setProviderId(hardwareJSON.optString("type"));
hardware.setCores(Math.round(Float.parseFloat(hardwareJSON.optString("minCores")))); hardware.setCores(Math.round(Float.parseFloat(hardwareJSON.optString("minCores"))));
hardware.setRam(Long.valueOf(hardwareJSON.optString("minRam"))); hardware.setRam(Long.valueOf(hardwareJSON.optString("minRam")));
if ("aws-ec2".equals(nodeCandidateJSON.optString("cloud"))) { if ("aws-ec2".equals(nodeCandidateJSON.optString("cloud"))) {
...@@ -133,7 +134,7 @@ public class NodeCandidateUtils { ...@@ -133,7 +134,7 @@ public class NodeCandidateUtils {
} }
private Location createLocation(JSONObject nodeCandidateJSON, PACloud paCloud) { private Location createLocation(JSONObject nodeCandidateJSON, PACloud paCloud) {
LOGGER.info("Creating location ..."); LOGGER.debug("Creating location ...");
String locationId = paCloud.getCloudID() + "/" + nodeCandidateJSON.optString("region"); String locationId = paCloud.getCloudID() + "/" + nodeCandidateJSON.optString("region");
Location location = em.find(Location.class, locationId); Location location = em.find(Location.class, locationId);
if (location == null) { if (location == null) {
...@@ -145,7 +146,7 @@ public class NodeCandidateUtils { ...@@ -145,7 +146,7 @@ public class NodeCandidateUtils {
location.setIsAssignable(true); location.setIsAssignable(true);
location.setGeoLocation(createGeoLocation(paCloud.getCloudProviderName(), location.getName())); location.setGeoLocation(createGeoLocation(paCloud.getCloudProviderName(), location.getName()));
} }
LOGGER.info("Location created: " + location.toString()); LOGGER.debug("Location created: " + location.toString());
return location; return location;
} }
...@@ -171,7 +172,7 @@ public class NodeCandidateUtils { ...@@ -171,7 +172,7 @@ public class NodeCandidateUtils {
image = new Image(); image = new Image();
image.setId(imageId); image.setId(imageId);
image.setName(imageJSON.optString("name")); image.setName(imageJSON.optString("name"));
image.setProviderId(paCloud.getCloudID()); image.setProviderId(StringUtils.substringAfterLast(imageJSON.optString("id"), "/"));
OperatingSystem os = new OperatingSystem(); OperatingSystem os = new OperatingSystem();
JSONObject osJSON = imageJSON.optJSONObject("operatingSystem"); JSONObject osJSON = imageJSON.optJSONObject("operatingSystem");
os.setOperatingSystemFamily(OperatingSystemFamily.fromValue(osJSON.optString("family"))); os.setOperatingSystemFamily(OperatingSystemFamily.fromValue(osJSON.optString("family")));
...@@ -208,7 +209,7 @@ public class NodeCandidateUtils { ...@@ -208,7 +209,7 @@ public class NodeCandidateUtils {
} }
public NodeCandidate createNodeCandidate(JSONObject nodeCandidateJSON, JSONObject imageJSON, PACloud paCloud) { public NodeCandidate createNodeCandidate(JSONObject nodeCandidateJSON, JSONObject imageJSON, PACloud paCloud) {
LOGGER.info("Creating node candidate ..."); LOGGER.debug("Creating node candidate ...");
NodeCandidate nodeCandidate = new NodeCandidate(); NodeCandidate nodeCandidate = new NodeCandidate();
nodeCandidate.setNodeCandidateType(NodeCandidate.NodeCandidateTypeEnum.IAAS); nodeCandidate.setNodeCandidateType(NodeCandidate.NodeCandidateTypeEnum.IAAS);
nodeCandidate.setPrice(nodeCandidateJSON.optDouble("price")); nodeCandidate.setPrice(nodeCandidateJSON.optDouble("price"));
...@@ -221,7 +222,7 @@ public class NodeCandidateUtils { ...@@ -221,7 +222,7 @@ public class NodeCandidateUtils {
nodeCandidate.setPricePerInvocation((double) 0); nodeCandidate.setPricePerInvocation((double) 0);
nodeCandidate.setMemoryPrice((double) 0); nodeCandidate.setMemoryPrice((double) 0);
nodeCandidate.setEnvironment(new Environment()); nodeCandidate.setEnvironment(new Environment());
LOGGER.info("Node candidate created: " + nodeCandidate.toString()); LOGGER.debug("Node candidate created: " + nodeCandidate.toString());
return nodeCandidate; return nodeCandidate;
} }
......
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