Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6758] Platform: Reuse on-premise instance once the instance got delete. #6970

Merged
merged 12 commits into from
Feb 16, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.yugabyte.yw.common.services.YBClientService;
import com.yugabyte.yw.forms.UniverseTaskParams.EncryptionAtRestConfig.OpType;
import com.yugabyte.yw.forms.UniverseDefinitionTaskParams.Cluster;
import com.yugabyte.yw.models.Universe.UniverseUpdater;
import com.yugabyte.yw.models.helpers.NodeDetails;
import com.yugabyte.yw.models.helpers.TableDetails;
Expand Down Expand Up @@ -312,10 +313,20 @@ public SubTaskGroup createDestroyServerTasks(Collection<NodeDetails> nodes,
SubTaskGroup subTaskGroup = new SubTaskGroup("AnsibleDestroyServers", executor);
for (NodeDetails node : nodes) {
// Check if the private ip for the node is set. If not, that means we don't have
// a clean state to delete the node. Log it and skip the node.
if (node.cloudInfo.private_ip == null) {
// a clean state to delete the node. Log it, free up the onprem node
// so that the client can use the node instance to create another universe.
if (node.cloudInfo.private_ip == null){
LOG.warn(String.format("Node %s doesn't have a private IP. Skipping node delete.",
node.nodeName));
if (node.cloudInfo.cloud.equals(
com.yugabyte.yw.commissioner.Common.CloudType.onprem.name())) {
try {
NodeInstance providerNode = NodeInstance.getByName(node.nodeName);
providerNode.clearNodeDetails();
} catch (Exception ex) {
LOG.warn("On-prem node {} doesn't have a linked instance ", node.nodeName);
}
}
continue;
}
AnsibleDestroyServer.Params params = new AnsibleDestroyServer.Params();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -2321,4 +2322,28 @@ public void testRemoveEnclosingDoubleQuotes() {
// Null string
assertEquals(null, UniverseController.removeEnclosingDoubleQuotes(null));
}

@Test
public void testClearNodeDetails() {
mahendranbhat marked this conversation as resolved.
Show resolved Hide resolved
Provider p = ModelFactory.newProvider(customer, CloudType.onprem);
Region r = Region.create(p, "region-1", "PlacementRegion 1", "default-image");
AvailabilityZone az1 = AvailabilityZone.create(r, "az-1", "PlacementAZ 1", "subnet-1");
List<AvailabilityZone> azList = new ArrayList<AvailabilityZone>();
azList.add(az1);
UniverseDefinitionTaskParams taskParams = setupOnPremTestData(2, p, r, azList);

List<NodeInstance> nodeInstances = NodeInstance.listByProvider(p.uuid);
for (NodeInstance node : nodeInstances) {
node.setNodeName("TestUniverse");
node.inUse = true;
node.save();
}
for (NodeInstance node : nodeInstances) {
node.clearNodeDetails();
}
for (NodeInstance node : nodeInstances) {
assertFalse(node.inUse);
assertEquals("", node.getNodeName());
}
}
}