Search in sources :

Example 1 with InstanceGroupService

use of com.sequenceiq.cloudbreak.service.stack.InstanceGroupService 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Resource(com.sequenceiq.cloudbreak.domain.Resource) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) TestUtil(com.sequenceiq.cloudbreak.TestUtil) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) Answer(org.mockito.stubbing.Answer) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) CLUSTER_BOOTSTRAPPER_ERROR_INVALID_NODECOUNT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_BOOTSTRAPPER_ERROR_INVALID_NODECOUNT) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ExpectedException(org.junit.rules.ExpectedException) InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AdditionalAnswers.returnsFirstArg(org.mockito.AdditionalAnswers.returnsFirstArg) Rule(org.junit.Rule) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Optional(java.util.Optional) Resource(com.sequenceiq.cloudbreak.domain.Resource) ResourceType(com.sequenceiq.common.api.type.ResourceType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Collection(java.util.Collection) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.Test)

Aggregations

TestUtil (com.sequenceiq.cloudbreak.TestUtil)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)1 Clock (com.sequenceiq.cloudbreak.common.service.Clock)1 Resource (com.sequenceiq.cloudbreak.domain.Resource)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 CLUSTER_BOOTSTRAPPER_ERROR_INVALID_NODECOUNT (com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_BOOTSTRAPPER_ERROR_INVALID_NODECOUNT)1 CloudbreakMessagesService (com.sequenceiq.cloudbreak.message.CloudbreakMessagesService)1 ContainerOrchestrator (com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator)1 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 ResourceService (com.sequenceiq.cloudbreak.service.resource.ResourceService)1 InstanceGroupService (com.sequenceiq.cloudbreak.service.stack.InstanceGroupService)1 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)1 ServiceProviderConnectorAdapter (com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter)1 CloudbreakEventService (com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService)1 ResourceType (com.sequenceiq.common.api.type.ResourceType)1