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

AUT-13288 AUT-13588-Jenkins-plugin-detached-stateful-instances-are-still-shown-in-console #41

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/spotinst/api/SpotinstApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import hudson.plugins.spotinst.common.SpotinstContext;
import hudson.plugins.spotinst.model.aws.*;
import hudson.plugins.spotinst.model.aws.stateful.AwsDeallocateStatefulInstanceRequest;
import hudson.plugins.spotinst.model.aws.stateful.AwsStatefulDeallocationConfig;
import hudson.plugins.spotinst.model.aws.stateful.AwsStatefulDeAllocationConfig;
import hudson.plugins.spotinst.model.aws.stateful.AwsStatefulInstance;
import hudson.plugins.spotinst.model.aws.stateful.AwsStatefulInstancesResponse;
import hudson.plugins.spotinst.model.azure.*;
Expand Down Expand Up @@ -177,12 +177,12 @@ public static Boolean awsDeallocateInstance(String groupId, String statefulInsta
Map<String, String> queryParams = buildQueryParams(accountId);

AwsDeallocateStatefulInstanceRequest request = new AwsDeallocateStatefulInstanceRequest();
AwsStatefulDeallocationConfig statefulDeallocation = new AwsStatefulDeallocationConfig();
AwsStatefulDeAllocationConfig statefulDeallocation = new AwsStatefulDeAllocationConfig();
statefulDeallocation.setShouldDeleteImages(true);
statefulDeallocation.setShouldDeleteSnapshots(true);
statefulDeallocation.setShouldDeleteVolumes(true);
statefulDeallocation.setShouldDeleteNetworkInterfaces(true);
request.setStatefulDeallocation(statefulDeallocation);
request.setStatefulDeAllocationConfig(statefulDeallocation);

String body = JsonMapper.toJson(request);

Expand Down
56 changes: 37 additions & 19 deletions src/main/java/hudson/plugins/spotinst/cloud/AwsSpotinstCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import hudson.plugins.spotinst.api.infra.JsonMapper;
import hudson.plugins.spotinst.common.ConnectionMethodEnum;
import hudson.plugins.spotinst.common.SpotAwsInstanceTypesHelper;
import hudson.plugins.spotinst.common.stateful.StatefulInstanceStateEnum;
import hudson.plugins.spotinst.common.stateful.AwsStatefulInstanceStateEnum;
import hudson.plugins.spotinst.common.stateful.StatefulInstanceManager;
import hudson.plugins.spotinst.model.aws.*;
import hudson.plugins.spotinst.model.aws.stateful.AwsStatefulInstance;
import hudson.plugins.spotinst.model.common.BlResponse;
Expand Down Expand Up @@ -47,15 +48,15 @@ public class AwsSpotinstCloud extends BaseSpotinstCloud {
@DataBoundConstructor
public AwsSpotinstCloud(String groupId, String labelString, String idleTerminationMinutes, String workspaceDir,
List<? extends SpotinstInstanceWeight> executorsForTypes, SlaveUsageEnum usage,
String tunnel, Boolean shouldUseWebsocket, Boolean shouldRetriggerBuilds, String vmargs,
EnvironmentVariablesNodeProperty environmentVariables,
String tunnel, Boolean shouldUseWebsocket, SpotReTriggerBuilds spotReTriggerBuilds,
String vmargs, EnvironmentVariablesNodeProperty environmentVariables,
ToolLocationNodeProperty toolLocations, String accountId,
ConnectionMethodEnum connectionMethod, ComputerConnector computerConnector,
Boolean shouldUsePrivateIp, SpotGlobalExecutorOverride globalExecutorOverride,
Integer pendingThreshold) {

super(groupId, labelString, idleTerminationMinutes, workspaceDir, usage, tunnel, shouldUseWebsocket,
shouldRetriggerBuilds, vmargs, environmentVariables, toolLocations, accountId, connectionMethod,
spotReTriggerBuilds, vmargs, environmentVariables, toolLocations, accountId, connectionMethod,
computerConnector, shouldUsePrivateIp, globalExecutorOverride, pendingThreshold);

this.executorsForTypes = new LinkedList<>();
Expand Down Expand Up @@ -106,19 +107,36 @@ List<SpotinstSlave> scaleUp(ProvisionRequest request) {
return retVal;
}

@Override
protected String getSsiId(String instanceId) {
String retVal = null;
AwsStatefulInstance statefulInstance = getStatefulInstance(instanceId);

if (statefulInstance != null) {
retVal = statefulInstance.getId();
}

return retVal;
}
// @Override
// protected String getStatefulInstanceId(String instanceId) {
// String retVal = null;
//
// IAwsGroupRepo awsGroupRepo = RepoManager.getInstance().getAwsGroupRepo();
// ApiResponse<List<AwsStatefulInstance>> statefulInstancesResponse =
// awsGroupRepo.getStatefulInstances(groupId, accountId);
//
// if (statefulInstancesResponse.isRequestSucceed()) {
// List<AwsStatefulInstance> groupStatefulInstances = statefulInstancesResponse.getValue();
// boolean isGroupHasStatefulInstances = CollectionUtils.isNotEmpty(groupStatefulInstances);
//
// if (isGroupHasStatefulInstances) {
// Optional<AwsStatefulInstance> optionalAwsStatefulInstance = groupStatefulInstances.stream()
// .filter(statefulInstance -> instanceId.equals(
// statefulInstance.getInstanceId()))
// .findFirst();
// boolean isStatefulInstance = optionalAwsStatefulInstance.isPresent();
//
// if (isStatefulInstance) {
// retVal = optionalAwsStatefulInstance.get().getId();
// }
// }
// }
//
// return retVal;
// }

private AwsStatefulInstance getStatefulInstance(String instanceId) {
@Override
protected AwsStatefulInstance getStatefulInstance(String instanceId) {
AwsStatefulInstance retVal = null;
boolean isInstanceStateful = ssiByInstanceId != null && ssiByInstanceId.containsKey(instanceId);

Expand Down Expand Up @@ -308,6 +326,7 @@ private void syncGroupStatefulInstances() {
List<AwsStatefulInstance> statefulInstances = statefulInstancesResponse.getValue();
this.ssiByInstanceId = statefulInstances.stream().collect(
Collectors.toMap(AwsStatefulInstance::getInstanceId, statefulInstance -> statefulInstance));
StatefulInstanceManager.getStatefulInstanceIdsByGroupId().put(groupId, statefulInstances);
}
else {
LOGGER.error(String.format("Failed to get group %s stateful instances. Errors: %s", groupId,
Expand All @@ -322,7 +341,6 @@ private List<SpotinstSlave> handleNewAwsSpots(AwsScaleUpResult scaleUpResult, St
LOGGER.info(String.format("%s new spot requests created", scaleUpResult.getNewSpotRequests().size()));

for (AwsScaleResultNewSpot spot : scaleUpResult.getNewSpotRequests()) {

SpotinstSlave slave = handleNewAwsInstance(spot.getInstanceId(), spot.getInstanceType(), label);

retVal.add(slave);
Expand Down Expand Up @@ -381,7 +399,7 @@ private Boolean shouldAddNewSlaveInstance(AwsGroupInstance instance) {
AwsStatefulInstance statefulInstance = getStatefulInstance(instance.getInstanceId());
boolean isStatefulInstanceReadyForUse = statefulInstance != null &&
Objects.equals(statefulInstance.getState(),
StatefulInstanceStateEnum.ACTIVE);
AwsStatefulInstanceStateEnum.ACTIVE);
retVal = isStatefulInstanceReadyForUse;
}
else {
Expand Down Expand Up @@ -506,7 +524,7 @@ private void initExecutorsByInstanceType() {
this.executorsByInstanceType.put(type, executors);

if (instance.getIsValid() == false) {
LOGGER.error(String.format("Invalid type \'%s\' in group \'%s\'", type, this.getGroupId()));
LOGGER.error(String.format("Invalid type '%s' in group '%s'", type, this.getGroupId()));
invalidInstanceTypes.add(type);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import hudson.plugins.spotinst.model.azure.AzureGroupVm;
import hudson.plugins.spotinst.model.azure.AzureScaleUpResultNewVm;
import hudson.plugins.spotinst.model.azure.AzureVmSizeEnum;
import hudson.plugins.spotinst.model.common.BaseStatefulInstance;
import hudson.plugins.spotinst.model.common.BlResponse;
import hudson.plugins.spotinst.repos.IAzureVmGroupRepo;
import hudson.plugins.spotinst.repos.RepoManager;
Expand Down Expand Up @@ -41,13 +42,13 @@ public class AzureSpotCloud extends BaseSpotinstCloud {
@DataBoundConstructor
public AzureSpotCloud(String groupId, String labelString, String idleTerminationMinutes, String workspaceDir,
SlaveUsageEnum usage, String tunnel, Boolean shouldUseWebsocket,
Boolean shouldRetriggerBuilds, String vmargs,
SpotReTriggerBuilds spotReTriggerBuilds, String vmargs,
EnvironmentVariablesNodeProperty environmentVariables, ToolLocationNodeProperty toolLocations,
String accountId, ConnectionMethodEnum connectionMethod, ComputerConnector computerConnector,
Boolean shouldUsePrivateIp, SpotGlobalExecutorOverride globalExecutorOverride,
Integer pendingThreshold) {
super(groupId, labelString, idleTerminationMinutes, workspaceDir, usage, tunnel, shouldUseWebsocket,
shouldRetriggerBuilds, vmargs, environmentVariables, toolLocations, accountId, connectionMethod,
spotReTriggerBuilds, vmargs, environmentVariables, toolLocations, accountId, connectionMethod,
computerConnector, shouldUsePrivateIp, globalExecutorOverride, pendingThreshold);
}
//endregion
Expand Down Expand Up @@ -92,7 +93,7 @@ protected BlResponse<Boolean> checkIsStatefulGroup() {
}

@Override
protected String getSsiId(String instanceId) {
protected BaseStatefulInstance getStatefulInstance(String instanceId) {
return null;//TODO: implement
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hudson.plugins.spotinst.common.Constants;
import hudson.plugins.spotinst.model.azure.AzureGroupInstance;
import hudson.plugins.spotinst.model.azure.AzureScaleSetSizeEnum;
import hudson.plugins.spotinst.model.common.BaseStatefulInstance;
import hudson.plugins.spotinst.model.common.BlResponse;
import hudson.plugins.spotinst.repos.IAzureGroupRepo;
import hudson.plugins.spotinst.repos.RepoManager;
Expand Down Expand Up @@ -39,14 +40,14 @@ public class AzureSpotinstCloud extends BaseSpotinstCloud {
@DataBoundConstructor
public AzureSpotinstCloud(String groupId, String labelString, String idleTerminationMinutes, String workspaceDir,
SlaveUsageEnum usage, String tunnel, Boolean shouldUseWebsocket,
Boolean shouldRetriggerBuilds, String vmargs,
SpotReTriggerBuilds spotReTriggerBuilds, String vmargs,
EnvironmentVariablesNodeProperty environmentVariables,
ToolLocationNodeProperty toolLocations, String accountId,
ConnectionMethodEnum connectionMethod, ComputerConnector computerConnector,
Boolean shouldUsePrivateIp, SpotGlobalExecutorOverride globalExecutorOverride,
Integer pendingThreshold) {
super(groupId, labelString, idleTerminationMinutes, workspaceDir, usage, tunnel, shouldUseWebsocket,
shouldRetriggerBuilds, vmargs, environmentVariables, toolLocations, accountId, connectionMethod,
spotReTriggerBuilds, vmargs, environmentVariables, toolLocations, accountId, connectionMethod,
computerConnector, shouldUsePrivateIp, globalExecutorOverride, pendingThreshold);
}
//endregion
Expand Down Expand Up @@ -82,7 +83,7 @@ protected BlResponse<Boolean> checkIsStatefulGroup() {
}

@Override
protected String getSsiId(String instanceId) {
protected BaseStatefulInstance getStatefulInstance(String instanceId) {
return null;//TODO: implement
}

Expand Down
Loading