Commit 17010dcc authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Add instance ID support field in Deployment class

parent 84d64f46
......@@ -668,6 +668,7 @@ public class PAGateway {
*/
public List<Deployment> getAllNodes() {
resourceManagerGateway.synchronizeDeploymentsIPAddresses(schedulerGateway);
resourceManagerGateway.synchronizeDeploymentsInstanceIDs();
return EntityManagerHelper.createQuery("SELECT d FROM Deployment d", Deployment.class).getResultList();
}
......@@ -1000,6 +1001,7 @@ public class PAGateway {
false,
null,
null,
null,
null
);
})
......
......@@ -343,12 +343,12 @@ public class PAResourceManagerGateway {
deployments.parallelStream().forEach(deployment -> {
if (deployment.getIsDeployed()) {
try {
List<String> nodeURLs = searchNodes(Collections.singletonList(deployment.getNodeName()), true);
if (!nodeURLs.isEmpty()) {
if (deployment.getIpAddress() != null) {
LOGGER.info("Deployment " + deployment.getNodeName() +
"already synchronized. IP: " + deployment.getIpAddress());
} else {
if (deployment.getIpAddress() != null) {
LOGGER.info("Deployment " + deployment.getNodeName() +
"already synchronized. IP: " + deployment.getIpAddress());
} else {
List<String> nodeURLs = searchNodes(Collections.singletonList(deployment.getNodeName()), true);
if (!nodeURLs.isEmpty()) {
TaskFlowJob paIPJob = createIPAddrGetterWorkflow(deployment);
if (!paIPJob.getTasks().isEmpty()) {
long submittedJobId = schedulerGateway.submit(paIPJob).longValue();
......@@ -366,9 +366,9 @@ public class PAResourceManagerGateway {
deployment.setIpAddress(ipAddress);
EntityManagerHelper.persist(deployment);
}
} else {
LOGGER.warn("The node " + deployment.getNodeName() + " is not reachable in RM.");
}
} else {
LOGGER.warn("The node " + deployment.getNodeName() + " is not reachable in RM.");
}
} catch (NotConnectedException nce) {
LOGGER.error("ERROR: Not able to search for a node due to a NotConnectedException: " + Arrays.toString(nce.getStackTrace()));
......@@ -398,4 +398,34 @@ public class PAResourceManagerGateway {
LOGGER.info("Job created: " + paJob.toString());
return paJob;
}
public void synchronizeDeploymentsInstanceIDs() {
List<Deployment> deployments = EntityManagerHelper.createQuery("SELECT d FROM Deployment d", Deployment.class).getResultList();
EntityManagerHelper.begin();
deployments.parallelStream().forEach(deployment -> {
if (deployment.getIsDeployed()) {
try {
if (deployment.getInstanceId() != null) {
LOGGER.info("Deployment " + deployment.getNodeName() +
" already synchronized. Instance ID: " + deployment.getInstanceId());
} else {
List<String> nodeURLs = searchNodes(Collections.singletonList(deployment.getNodeName()), true);
if (!nodeURLs.isEmpty()) {
String instanceId = nodeURLs.get(0).substring(nodeURLs.get(0).lastIndexOf("__") + 2);
deployment.setInstanceId(instanceId);
EntityManagerHelper.persist(deployment);
LOGGER.info("Deployment " + deployment.getNodeName() + "instance ID set to: " + instanceId);
} else {
LOGGER.warn("The node " + deployment.getNodeName() + " is not reachable in RM.");
}
}
} catch (NotConnectedException nce) {
LOGGER.error("ERROR: Not able to search for a node due to a NotConnectedException: " + Arrays.toString(nce.getStackTrace()));
} catch (RestException re) {
LOGGER.error("ERROR: Not able to search for a node due to a RestException: " + Arrays.toString(re.getStackTrace()));
}
}
});
EntityManagerHelper.commit();
}
}
......@@ -47,6 +47,9 @@ public class Deployment implements Serializable {
@Column(name = "NUMBER")
private Long number;
@Column(name = "INSTANCE_ID")
private String instanceId;
@Embedded
private IpAddress ipAddress = null;
......@@ -58,6 +61,7 @@ public class Deployment implements Serializable {
", imageProviderId='" + imageProviderId + '\'' +
", hardwareProviderId='" + hardwareProviderId + '\'' +
", isDeployed='" + isDeployed.toString() + '\'' +
", instanceId='" + instanceId + '\'' +
", ipAddress='" + ipAddress + '\'' +
", nodeAccessToken='" + nodeAccessToken + '\'' +
", number='" + number + '\'' +
......
Markdown is supported
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