Search in sources :

Example 96 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class StackScalabilityConditionTest method createInstanceMetaData.

private InstanceMetaData createInstanceMetaData(InstanceStatus instanceStatus) {
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setInstanceStatus(instanceStatus);
    return instanceMetaData;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)

Example 97 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class StackScalabilityConditionTest method testIsScalableShouldReturnFalseWhenThereArePendingInstances.

@Test
public void testIsScalableShouldReturnFalseWhenThereArePendingInstances() {
    Set<InstanceMetaData> instanceMetaData = createInstanceMetadataWithPendingInstance();
    Stack stack = createStac(instanceMetaData);
    boolean actual = underTest.isScalable(stack, GROUP_NAME);
    assertFalse(actual);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 98 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class UpgradeServiceTest method upgradeAllowedWhenConnectedDataHubStackAndClusterStoppedOrDeleted.

@Test
public void upgradeAllowedWhenConnectedDataHubStackAndClusterStoppedOrDeleted() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = getStack();
    Image image = getImage("id-1");
    setUpMocks(stack, image, true, "id-1", "id-2");
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.success(new HashMap<>());
    when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
    StackViewV4Response datahubStack1 = new StackViewV4Response();
    datahubStack1.setStatus(Status.STOPPED);
    ClusterViewV4Response datahubCluster1 = new ClusterViewV4Response();
    datahubCluster1.setStatus(Status.STOPPED);
    datahubStack1.setCluster(datahubCluster1);
    StackViewV4Response datahubStack2 = new StackViewV4Response();
    datahubStack2.setStatus(Status.DELETE_COMPLETED);
    ClusterViewV4Response datahubCluster2 = new ClusterViewV4Response();
    datahubCluster2.setStatus(Status.DELETE_COMPLETED);
    datahubStack2.setCluster(datahubCluster2);
    StackViewV4Response datahubStack3 = new StackViewV4Response();
    datahubStack3.setStatus(Status.STOPPED);
    when(distroXV1Endpoint.list(any(), anyString())).thenReturn(new StackViewV4Responses(Set.of(datahubStack1, datahubStack2, datahubStack3)));
    when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
    UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
    verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
    verify(distroXV1Endpoint).list(eq(null), eq("env-crn"));
    verify(componentConfigProviderService).getImage(1L);
    verify(imageService).determineImageFromCatalog(eq(WORKSPACE_ID), captor.capture(), eq("aws"), eq("AWS"), eq(stack.getCluster().getBlueprint()), eq(false), eq(false), eq(user), any());
    assertThat(result.getUpgrade().getImageName()).isEqualTo("id-2");
    assertThat(result.getReason()).isEqualTo(null);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) ClusterViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.views.ClusterViewV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 99 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class UpgradeServiceTest method shouldNotAllowUpgradeIfDryRunFails.

@Test
public void shouldNotAllowUpgradeIfDryRunFails() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = getStack();
    Image image = getImage("id-1");
    when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
    when(componentConfigProviderService.getImage(anyLong())).thenReturn(image);
    StatedImage currentImageFromCatalog = imageFromCatalog(true, image.getImageId());
    when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(currentImageFromCatalog);
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.error(RepairValidation.of(List.of("Repair cannot be performed because there is an active flow running.", "No external Database")));
    when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
    UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
    verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
    verifyNoMoreInteractions(distroXV1Endpoint);
    verifyNoMoreInteractions(componentConfigProviderService);
    verifyNoMoreInteractions(imageService);
    assertThat(result.getUpgrade()).isEqualTo(null);
    assertThat(result.getReason()).isEqualTo("Repair cannot be performed because there is an active flow running.; No external Database");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 100 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class HostMetadataSetupTest method testSetupNewHostMetadataWithMultipleNonPrimaryChange.

@Test
@DisplayName("when multiple non-primary gateways are repaired and scaled we should not make any changes in the primary gateway assignments")
public void testSetupNewHostMetadataWithMultipleNonPrimaryChange() throws CloudbreakException, CloudbreakOrchestratorException {
    Stack stack = mock(Stack.class);
    InstanceMetaData im1 = createInstanceMetadata("id1", InstanceMetadataType.GATEWAY, 1L, "10.0.0.1", "host1", false);
    InstanceMetaData im2 = createInstanceMetadata("id2", InstanceMetadataType.GATEWAY, 2L, "10.0.0.2", "host2", false);
    Set<InstanceMetaData> allNewInstances = Set.of(im1, im2);
    when(instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(STACK_ID)).thenReturn(allNewInstances);
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
    when(hostOrchestrator.getMembers(any(), any())).thenReturn(Map.of("10.0.0.1", "host1", "10.0.0.2", "host2"));
    hostMetadataSetup.setupNewHostMetadata(STACK_ID, List.of("10.0.0.1", "10.0.0.2"));
    verify(instanceMetaDataService, times(0)).getLastTerminatedPrimaryGatewayInstanceMetadata(STACK_ID);
    verify(instanceMetaDataService, times(1)).saveAll(instanceMetadataCaptor.capture());
    Set<InstanceMetaData> actualIm = instanceMetadataCaptor.getValue();
    InstanceMetaData expectedIm1 = createInstanceMetadata("id1", InstanceMetadataType.GATEWAY, 1L, "10.0.0.1", "host1", false);
    InstanceMetaData expectedIm2 = createInstanceMetadata("id2", InstanceMetadataType.GATEWAY, 2L, "10.0.0.2", "host2", false);
    assertMetadataEquals(expectedIm1, actualIm.stream().filter(im -> im.getPrivateId() == 1L).findFirst().get());
    assertMetadataEquals(expectedIm2, actualIm.stream().filter(im -> im.getPrivateId() == 2L).findFirst().get());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) Captor(org.mockito.Captor) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMocks(org.mockito.InjectMocks) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Mockito.verify(org.mockito.Mockito.verify) DisplayName(org.junit.jupiter.api.DisplayName) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Test(org.junit.jupiter.api.Test) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Assertions(org.junit.jupiter.api.Assertions) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Mockito.mock(org.mockito.Mockito.mock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)415 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)165 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)152 Test (org.junit.jupiter.api.Test)143 Map (java.util.Map)92 HashSet (java.util.HashSet)90 Set (java.util.Set)86 List (java.util.List)84 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)77 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)73 Collectors (java.util.stream.Collectors)71 ArrayList (java.util.ArrayList)62 Test (org.junit.Test)60 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)57 Optional (java.util.Optional)52 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)48 Inject (javax.inject.Inject)47 Logger (org.slf4j.Logger)47 LoggerFactory (org.slf4j.LoggerFactory)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45