use of com.sequenceiq.cloudbreak.service.resource.ResourceService in project cloudbreak by hortonworks.
the class ClusterBootstrapperErrorHandlerTest method clusterBootstrapErrorHandlerWhenNodeCountHigherThanZeroAfterTheRollbackThenClusterProvisionFailed.
@Test
public void clusterBootstrapErrorHandlerWhenNodeCountHigherThanZeroAfterTheRollbackThenClusterProvisionFailed() throws CloudbreakOrchestratorFailedException {
Stack stack = TestUtil.stack();
when(orchestrator.getAvailableNodes(any(GatewayConfig.class), anySet())).thenReturn(new ArrayList<>());
when(instanceGroupService.save(any(InstanceGroup.class))).then(returnsFirstArg());
when(instanceMetaDataService.save(any(InstanceMetaData.class))).then(returnsFirstArg());
when(resourceService.findByStackIdAndNameAndType(nullable(Long.class), nullable(String.class), nullable(ResourceType.class))).thenReturn(Optional.of(new Resource()));
when(connector.removeInstances(any(Stack.class), anySet(), anyString())).thenReturn(new HashSet<>());
when(instanceMetaDataService.findNotTerminatedByPrivateAddress(anyLong(), anyString())).thenAnswer((Answer<Optional<InstanceMetaData>>) invocation -> {
Object[] args = invocation.getArguments();
String ip = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getNotDeletedAndNotZombieInstanceMetaDataSet()) {
if (instanceMetaData.getPrivateIp().equals(ip)) {
return Optional.of(instanceMetaData);
}
}
return Optional.empty();
});
when(instanceGroupService.findOneWithInstanceMetadataByGroupNameInStack(anyLong(), anyString())).thenAnswer((Answer<Optional<InstanceGroup>>) invocation -> {
Object[] args = invocation.getArguments();
String name = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getNotDeletedAndNotZombieInstanceMetaDataSet()) {
if (instanceMetaData.getInstanceGroup().getGroupName().equals(name)) {
return Optional.ofNullable(instanceMetaData.getInstanceGroup());
}
}
return Optional.empty();
});
underTest.terminateFailedNodes(null, orchestrator, TestUtil.stack(), new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 443, "instanceId", false), prepareNodes(stack));
verify(eventService, times(4)).fireCloudbreakEvent(anyLong(), anyString(), any(ResourceEvent.class), nullable(Collection.class));
verify(instanceGroupService, times(3)).save(any(InstanceGroup.class));
verify(instanceMetaDataService, times(3)).save(any(InstanceMetaData.class));
verify(connector, times(3)).removeInstances(any(Stack.class), anySet(), anyString());
verify(resourceService, times(3)).findByStackIdAndNameAndType(anyLong(), anyString(), nullable(ResourceType.class));
verify(resourceService, times(3)).delete(nullable(Resource.class));
verify(instanceGroupService, times(3)).findOneWithInstanceMetadataByGroupNameInStack(anyLong(), anyString());
}
Aggregations