Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

adding flag to force delete healthy instances #4

Open
wants to merge 1 commit into
base: delete-multiple-instances
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

public interface InstancePayload extends Payload {
Set<String> getInstanceIds();

Boolean getForceHealthyInstanceDeletion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ public class DownscaleStackRequest extends CloudStackRequest<DownscaleStackResul

private final Object resourcesToScale;

private Boolean forceHealthyInstanceDeletion;

public DownscaleStackRequest(CloudContext cloudContext, CloudCredential cloudCredential, CloudStack cloudStack, List<CloudResource> cloudResources,
List<CloudInstance> instances) {
List<CloudInstance> instances, Boolean forceHealthyInstanceDeletion) {
super(cloudContext, cloudCredential, cloudStack);
this.cloudResources = cloudResources;
this.instances = instances;
resourcesToScale = null;
this.forceHealthyInstanceDeletion = forceHealthyInstanceDeletion;
}

public DownscaleStackRequest(CloudContext cloudContext, CloudCredential cloudCredential, CloudStack cloudStack, List<CloudResource> cloudResources,
List<CloudInstance> instances, Object resourcesToScale) {
List<CloudInstance> instances, Object resourcesToScale, Boolean forceHealthyInstanceDeletion) {
super(cloudContext, cloudCredential, cloudStack);
this.cloudResources = cloudResources;
this.instances = instances;
this.resourcesToScale = resourcesToScale;
this.forceHealthyInstanceDeletion = forceHealthyInstanceDeletion;

}

public List<CloudResource> getCloudResources() {
Expand All @@ -43,4 +48,8 @@ public List<CloudInstance> getInstances() {
public Object getResourcesToScale() {
return resourcesToScale;
}

public Boolean getForceHealthyInstanceDeletion() {
return forceHealthyInstanceDeletion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ public class RemoveInstanceRequest extends CloudStackRequest<RemoveInstanceResul

private final List<CloudInstance> instances;

private Boolean forceHealthyInstanceDeletion;

public RemoveInstanceRequest(CloudContext cloudContext, CloudCredential cloudCredential, CloudStack cloudStack,
List<CloudResource> cloudResources, List<CloudInstance> instances) {
List<CloudResource> cloudResources, List<CloudInstance> instances, Boolean forceHealthyInstanceDeletion) {
super(cloudContext, cloudCredential, cloudStack);
this.cloudResources = cloudResources;
this.instances = instances;
this.forceHealthyInstanceDeletion = forceHealthyInstanceDeletion;
}

public List<CloudResource> getCloudResources() {
Expand All @@ -28,4 +31,8 @@ public List<CloudResource> getCloudResources() {
public List<CloudInstance> getInstances() {
return instances;
}

public Boolean getForceHealthyInstanceDeletion() {
return forceHealthyInstanceDeletion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public Set<String> getInstanceIds() {
return instances.stream().map(CloudInstance::getInstanceId).collect(Collectors.toSet());
}
}

@Override
public Boolean getForceHealthyInstanceDeletion() {
return getRequest().getForceHealthyInstanceDeletion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected CloudPlatformRequest getRequest() {
g().createCloudCredential(),
g().createCloudStack(),
g().createCloudResourceList(),
g().createCloudInstances());
g().createCloudInstances(),
false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ void delete(@PathParam("id") Long id, @QueryParam("forced") @DefaultValue("false

PlatformVariantsJson variants();

Response deleteInstance(@PathParam("stackId") Long stackId, @PathParam("instanceId") String instanceId);
Response deleteInstance(@PathParam("stackId") Long stackId, @PathParam("instanceId") String instanceId,
@QueryParam("forceHealtyInstance") @DefaultValue("false") Boolean forceHealtyInstance);

Response deleteInstances(@PathParam("stackId") Long stackId, @PathParam("instanceIds") Set<String> instanceIds);
Response deleteInstances(@PathParam("stackId") Long stackId, @PathParam("instanceIds") Set<String> instanceIds,
@QueryParam("forceHealtyInstances") @DefaultValue("false") Boolean forceHealtyInstances);

CertificateResponse getCertificate(@PathParam("id") Long stackId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,16 @@ void delete(@PathParam("id") Long id, @QueryParam("forced") @DefaultValue("false
@Produces(MediaType.APPLICATION_JSON)
@Override
@ApiOperation(value = StackOpDescription.DELETE_INSTANCE_BY_ID, produces = ContentType.JSON, notes = Notes.STACK_NOTES, nickname = "deleteInstanceStack")
Response deleteInstance(@PathParam("stackId") Long stackId, @PathParam("instanceId") String instanceId);
Response deleteInstance(@PathParam("stackId") Long stackId, @PathParam("instanceId") String instanceId,
@QueryParam("forceHealtyInstance") @DefaultValue("false") Boolean forceHealtyInstance);

@DELETE
@Path("{stackId}/deleteInstances")
@Produces(MediaType.APPLICATION_JSON)
@Override
@ApiOperation(value = StackOpDescription.DELETE_INSTANCE_BY_ID, produces = ContentType.JSON, notes = Notes.STACK_NOTES, nickname = "deleteInstancesStack")
Response deleteInstances(@PathParam("stackId") Long stackId, @QueryParam("instanceIds") Set<String> instanceIds);
Response deleteInstances(@PathParam("stackId") Long stackId, @QueryParam("instanceIds") Set<String> instanceIds,
@QueryParam("forceHealtyInstances") @DefaultValue("false") Boolean forceHealtyInstances);

@GET
@Path("{id}/certificate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ void delete(@PathParam("id") Long id, @QueryParam("forced") @DefaultValue("false
@Override
@ApiOperation(value = StackOpDescription.DELETE_INSTANCE_BY_ID, produces = ContentType.JSON, notes = Notes.STACK_NOTES,
nickname = "deleteInstanceStackV2")
Response deleteInstance(@PathParam("stackId") Long stackId, @PathParam("instanceId") String instanceId);
Response deleteInstance(@PathParam("stackId") Long stackId, @PathParam("instanceId") String instanceId,
@QueryParam("forceHealtyInstance") @DefaultValue("false") Boolean forceHealtyInstance);

@DELETE
@Path("{stackId}/deleteInstances")
@Produces(MediaType.APPLICATION_JSON)
@Override
@ApiOperation(value = OperationDescriptions.StackOpDescription.DELETE_INSTANCE_BY_ID, produces = ContentType.JSON, notes = Notes.STACK_NOTES,
nickname = "deleteInstancesStackV2")
Response deleteInstances(@PathParam("stackId") Long stackId, @QueryParam("instanceIds") Set<String> instanceIds);
Response deleteInstances(@PathParam("stackId") Long stackId, @QueryParam("instanceIds") Set<String> instanceIds,
@QueryParam("forceHealtyInstances") @DefaultValue("false") Boolean forceHealtyInstances);

@GET
@Path("{id}/certificate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public PlatformVariantsJson variants() {
}

@Override
public Response deleteInstance(Long stackId, String instanceId) {
return stackCommonService.deleteInstance(stackId, instanceId);
public Response deleteInstance(Long stackId, String instanceId, Boolean forceHealtyInstance) {
return stackCommonService.deleteInstance(stackId, instanceId, forceHealtyInstance);
}

@Override
public Response deleteInstances(Long stackId, Set<String> instanceIds) {
return stackCommonService.deleteInstances(stackId, instanceIds);
public Response deleteInstances(Long stackId, Set<String> instanceIds, Boolean forceHealtyInstances) {
return stackCommonService.deleteInstances(stackId, instanceIds, forceHealtyInstances);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ public PlatformVariantsJson variants() {
}

@Override
public Response deleteInstance(Long stackId, String instanceId) {
return stackCommonService.deleteInstance(stackId, instanceId);
public Response deleteInstance(Long stackId, String instanceId, Boolean forceHealtyInstance) {
return stackCommonService.deleteInstance(stackId, instanceId, forceHealtyInstance);
}

@Override
public Response deleteInstances(Long stackId, Set<String> instanceIds) {
return stackCommonService.deleteInstances(stackId, instanceIds);
public Response deleteInstances(Long stackId, Set<String> instanceIds, Boolean forceHealtyInstances) {
return stackCommonService.deleteInstances(stackId, instanceIds, forceHealtyInstances);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void terminateFailedNodes(HostOrchestrator hostOrchestrator, ContainerOrc
Arrays.asList(instanceMetaData.getInstanceId(), ig.getGroupName()));
LOGGER.info(message);
eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
deleteResourceAndDependencies(stack, instanceMetaData);
deleteResourceAndDependencies(stack, instanceMetaData, Boolean.FALSE);
deleteInstanceResourceFromDatabase(stack, instanceMetaData);
long timeInMillis = Calendar.getInstance().getTimeInMillis();
instanceMetaData.setTerminationDate(timeInMillis);
Expand Down Expand Up @@ -127,11 +127,11 @@ private List<Node> selectMissingNodes(Iterable<Node> clusterNodes, Iterable<Stri
return missingNodes;
}

private void deleteResourceAndDependencies(Stack stack, InstanceMetaData instanceMetaData) {
private void deleteResourceAndDependencies(Stack stack, InstanceMetaData instanceMetaData, Boolean forceHealthyInstances) {
LOGGER.info("Rolling back instance [name: {}, id: {}]", instanceMetaData.getId(), instanceMetaData.getInstanceId());
Set<String> instanceIds = new HashSet<>();
instanceIds.add(instanceMetaData.getInstanceId());
connector.removeInstances(stack, instanceIds, instanceMetaData.getInstanceGroup().getGroupName());
connector.removeInstances(stack, instanceIds, instanceMetaData.getInstanceGroup().getGroupName(), forceHealthyInstances);
LOGGER.info("Deleted instance [name: {}, id: {}]", instanceMetaData.getId(), instanceMetaData.getInstanceId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Queue<Selectable> createFlowTriggerEventQueue(ClusterRepairTriggerEvent e
Stack stack = stackService.getByIdWithLists(event.getStackId());
Set<Long> privateIdsForHostNames = stackService.getPrivateIdsForHostNames(stack.getInstanceMetaDataAsList(), hostNames);
flowChainTriggers.add(new ClusterAndStackDownscaleTriggerEvent(FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT, event.getStackId(),
hostGroupName, Sets.newHashSet(privateIdsForHostNames), ScalingType.DOWNSCALE_TOGETHER, event.accepted()));
Boolean.FALSE, hostGroupName, Sets.newHashSet(privateIdsForHostNames), ScalingType.DOWNSCALE_TOGETHER, event.accepted()));
if (!event.isRemoveOnly()) {
flowChainTriggers.add(new StackAndClusterUpscaleTriggerEvent(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.getStackId(),
hostGroupName, hostNames.size(), ScalingType.UPSCALE_TOGETHER, Sets.newHashSet(hostNames)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public Queue<Selectable> createFlowTriggerEventQueue(ClusterAndStackDownscaleTri
Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
ClusterScaleTriggerEvent cste;
if (event.getPrivateIds() == null) {
cste = new ClusterDownscaleTriggerEvent(DECOMMISSION_EVENT.event(), event.getStackId(), event.getHostGroupName(),
event.getAdjustment(), event.accepted());
cste = new ClusterDownscaleTriggerEvent(DECOMMISSION_EVENT.event(), event.getStackId(), event.getForceHealthyInstanceDeletion(),
event.getHostGroupName(), event.getAdjustment(), event.accepted());
} else {
cste = new ClusterDownscaleTriggerEvent(DECOMMISSION_EVENT.event(), event.getStackId(), event.getHostGroupName(),
event.getPrivateIds(), event.accepted());
cste = new ClusterDownscaleTriggerEvent(DECOMMISSION_EVENT.event(), event.getStackId(), event.getForceHealthyInstanceDeletion(),
event.getHostGroupName(), event.getPrivateIds(), event.accepted());
}
flowEventChain.add(cste);
if (event.getScalingType() == ScalingType.DOWNSCALE_TOGETHER) {
Expand All @@ -57,9 +57,11 @@ public Queue<Selectable> createFlowTriggerEventQueue(ClusterAndStackDownscaleTri
String instanceGroupName = Optional.ofNullable(hostGroupConstraint.getInstanceGroup()).map(InstanceGroup::getGroupName).orElse(null);
StackScaleTriggerEvent sste;
if (event.getPrivateIds() == null) {
sste = new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getStackId(), instanceGroupName, event.getAdjustment());
sste = new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getStackId(), event.getForceHealthyInstanceDeletion(),
instanceGroupName, event.getAdjustment());
} else {
sste = new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getStackId(), instanceGroupName, event.getPrivateIds());
sste = new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getStackId(), event.getForceHealthyInstanceDeletion(),
instanceGroupName, event.getPrivateIds());
}
flowEventChain.add(sste);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class ClusterDownscaleActions {
return new AbstractClusterAction<ClusterDownscaleTriggerEvent>(ClusterDownscaleTriggerEvent.class) {
@Override
protected void doExecute(ClusterViewContext context, ClusterDownscaleTriggerEvent payload, Map<Object, Object> variables) {
clusterDownscaleService.clusterDownscaleStarted(context.getStackId(), payload.getHostGroupName(), payload.getAdjustment(),
payload.getPrivateIds());
CollectDownscaleCandidatesRequest request = new CollectDownscaleCandidatesRequest(context.getStackId(), payload.getHostGroupName(),
clusterDownscaleService.clusterDownscaleStarted(context.getStackId(), payload.getForceHealthyInstanceDeletion(), payload.getHostGroupName(),
payload.getAdjustment(), payload.getPrivateIds());
CollectDownscaleCandidatesRequest request = new CollectDownscaleCandidatesRequest(context.getStackId(),
payload.getForceHealthyInstanceDeletion(), payload.getHostGroupName(), payload.getAdjustment(), payload.getPrivateIds());
sendEvent(context.getFlowId(), request.selector(), request);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class ClusterDownscaleService {
@Inject
private HostGroupService hostGroupService;

public void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds) {
public void clusterDownscaleStarted(long stackId, Boolean forceHealthyInstanceDeletion, String hostGroupName,
Integer scalingAdjustment, Set<Long> privateIds) {
flowMessageService.fireEventAndLog(stackId, Msg.AMBARI_CLUSTER_SCALING_DOWN, Status.UPDATE_IN_PROGRESS.name());
clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS);
if (scalingAdjustment != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
public class ClusterAndStackDownscaleTriggerEvent extends ClusterDownscaleTriggerEvent {
private final ScalingType scalingType;

public ClusterAndStackDownscaleTriggerEvent(String selector, Long stackId, String hostGroup, Integer adjustment, ScalingType scalingType) {
super(selector, stackId, hostGroup, adjustment);
public ClusterAndStackDownscaleTriggerEvent(String selector, Long stackId, Boolean forceHealtyInstance, String hostGroup,
Integer adjustment, ScalingType scalingType) {
super(selector, stackId, forceHealtyInstance, hostGroup, adjustment);
this.scalingType = scalingType;
}

public ClusterAndStackDownscaleTriggerEvent(String selector, Long stackId, String hostGroup, Set<Long> privateIds, ScalingType scalingType,
Promise<Boolean> accepted) {
super(selector, stackId, hostGroup, privateIds, accepted);
public ClusterAndStackDownscaleTriggerEvent(String selector, Long stackId, Boolean forceHealtyInstances, String hostGroup,
Set<Long> privateIds, ScalingType scalingType, Promise<Boolean> accepted) {
super(selector, stackId, forceHealtyInstances, hostGroup, privateIds, accepted);
this.scalingType = scalingType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,39 @@
public class ClusterDownscaleTriggerEvent extends ClusterScaleTriggerEvent {
private final Set<Long> privateIds;

public ClusterDownscaleTriggerEvent(String selector, Long stackId, String hostGroup, Integer adjustment) {
private final Boolean forceHealthyInstanceDeletion;

public ClusterDownscaleTriggerEvent(String selector, Long stackId, Boolean forceHealtyInstance, String hostGroup, Integer adjustment) {
super(selector, stackId, hostGroup, adjustment);
privateIds = null;
forceHealthyInstanceDeletion = forceHealtyInstance;
}

public ClusterDownscaleTriggerEvent(String selector, Long stackId, String hostGroup, Integer adjustment, Promise<Boolean> accepted) {
public ClusterDownscaleTriggerEvent(String selector, Long stackId, Boolean forceHealtyInstance, String hostGroup, Integer adjustment,
Promise<Boolean> accepted) {
super(selector, stackId, hostGroup, adjustment, accepted);
privateIds = null;
forceHealthyInstanceDeletion = forceHealtyInstance;
}

public ClusterDownscaleTriggerEvent(String selector, Long stackId, String hostGroup, Set<Long> privateIds) {
super(selector, stackId, hostGroup, null);
this.privateIds = privateIds;
forceHealthyInstanceDeletion = false;
}

public ClusterDownscaleTriggerEvent(String selector, Long stackId, String hostGroup, Set<Long> privateIds, Promise<Boolean> accepted) {
public ClusterDownscaleTriggerEvent(String selector, Long stackId, Boolean forceHealtyInstances, String hostGroup, Set<Long> privateIds,
Promise<Boolean> accepted) {
super(selector, stackId, hostGroup, null, accepted);
this.privateIds = privateIds;
forceHealthyInstanceDeletion = forceHealtyInstances;
}

public Set<Long> getPrivateIds() {
return privateIds;
}

public Boolean getForceHealthyInstanceDeletion() {
return forceHealthyInstanceDeletion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
public class InstanceTerminationTriggerEvent extends StackEvent implements InstancePayload {
private final Set<String> instanceIds;

public InstanceTerminationTriggerEvent(String selector, Long stackId, Set<String> instanceIds) {
private Boolean forceHealthyInstanceDeletion;

public InstanceTerminationTriggerEvent(String selector, Long stackId, Set<String> instanceIds, Boolean forceHealthyInstanceDeletion) {
super(selector, stackId);
this.instanceIds = instanceIds;
this.forceHealthyInstanceDeletion = forceHealthyInstanceDeletion;
}

@Override
public Set<String> getInstanceIds() {
return instanceIds;
}

@Override
public Boolean getForceHealthyInstanceDeletion() {
return forceHealthyInstanceDeletion;
}
}
Loading