Search in sources :

Example 51 with InstanceGroup

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

the class MetadataSetupServiceTest method saveInstanceMetaDataTestOneNewInstance.

@Test
public void saveInstanceMetaDataTestOneNewInstance() throws CloudbreakImageNotFoundException {
    when(imageService.getImage(STACK_ID)).thenReturn(image);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setId(INSTANCE_GROUP_ID);
    instanceGroup.setGroupName(GROUP_NAME);
    Set<InstanceGroup> instanceGroupSet = new TreeSet<>();
    instanceGroupSet.add(instanceGroup);
    when(instanceGroupService.findByStackId(STACK_ID)).thenReturn(instanceGroupSet);
    when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME);
    Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = getCloudVmMetaDataStatuses(InstanceStatus.CREATED);
    InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
    pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(pgwInstanceMetadata));
    int newInstances = underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, CREATED);
    assertEquals(1, newInstances);
    verify(imageService).getImage(STACK_ID);
    verify(instanceMetaDataService).save(instanceMetaDataCaptor.capture());
    InstanceMetaData instanceMetaData = instanceMetaDataCaptor.getValue();
    assertThat(instanceMetaData.getInstanceGroup()).isSameAs(instanceGroup);
    assertCommonProperties(instanceMetaData);
    assertEquals(CREATED, instanceMetaData.getInstanceStatus());
    assertNotNull(instanceMetaData.getImage());
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) TreeSet(java.util.TreeSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with InstanceGroup

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

the class MetadataSetupServiceTest method saveInstanceMetaDataTestOneZombieInstance.

@Test
public void saveInstanceMetaDataTestOneZombieInstance() {
    Stack stack = new Stack();
    stack.setId(STACK_ID);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setId(INSTANCE_GROUP_ID);
    instanceGroup.setGroupName(GROUP_NAME);
    Set<InstanceGroup> instanceGroupSet = new TreeSet<>();
    instanceGroupSet.add(instanceGroup);
    when(instanceGroupService.findByStackId(STACK_ID)).thenReturn(instanceGroupSet);
    when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME);
    Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = getCloudVmMetaDataStatuses(InstanceStatus.CREATED);
    InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
    pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
    InstanceMetaData zombieInstanceMetadata = new InstanceMetaData();
    zombieInstanceMetadata.setInstanceStatus(ZOMBIE);
    zombieInstanceMetadata.setPrivateId(PRIVATE_ID);
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(zombieInstanceMetadata, pgwInstanceMetadata));
    int newInstances = underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, SERVICES_RUNNING);
    assertEquals(1, newInstances);
    verifyNoInteractions(imageService);
    verify(instanceMetaDataService).save(instanceMetaDataCaptor.capture());
    InstanceMetaData instanceMetaData = instanceMetaDataCaptor.getValue();
    assertThat(instanceMetaData.getInstanceGroup()).isSameAs(instanceGroup);
    assertCommonProperties(instanceMetaData);
    assertEquals(ZOMBIE, instanceMetaData.getInstanceStatus());
    assertNull(instanceMetaData.getImage());
    assertFalse(instanceMetaData.getClusterManagerServer());
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) TreeSet(java.util.TreeSet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with InstanceGroup

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

the class MetadataSetupServiceTest method saveInstanceMetaDataTestServerFlagIsAlreadySet.

@ParameterizedTest(name = "{0}")
@MethodSource("saveInstanceMetaDataTestServerFlagIsAlreadySetDataProvider")
public void saveInstanceMetaDataTestServerFlagIsAlreadySet(String testCaseName, String subnetId, String availabilityZone, String rackId) throws CloudbreakImageNotFoundException {
    when(imageService.getImage(STACK_ID)).thenReturn(image);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setId(INSTANCE_GROUP_ID);
    instanceGroup.setGroupName(GROUP_NAME);
    Set<InstanceGroup> instanceGroupSet = new TreeSet<>();
    instanceGroupSet.add(instanceGroup);
    when(instanceGroupService.findByStackId(STACK_ID)).thenReturn(instanceGroupSet);
    when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME);
    Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = getCloudVmMetaDataStatuses(InstanceStatus.STOPPED);
    InstanceMetaData originalInstanceMetadata = new InstanceMetaData();
    originalInstanceMetadata.setServer(true);
    originalInstanceMetadata.setInstanceId("instanceId");
    originalInstanceMetadata.setPrivateId(PRIVATE_ID);
    originalInstanceMetadata.setInstanceGroup(instanceGroup);
    originalInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
    originalInstanceMetadata.setSubnetId(subnetId);
    originalInstanceMetadata.setAvailabilityZone(availabilityZone);
    originalInstanceMetadata.setRackId(rackId);
    when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(originalInstanceMetadata));
    int newInstances = underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, SERVICES_RUNNING);
    assertEquals(0, newInstances);
    verify(imageService).getImage(STACK_ID);
    verify(instanceMetaDataService).save(instanceMetaDataCaptor.capture());
    InstanceMetaData instanceMetaData = instanceMetaDataCaptor.getValue();
    assertThat(instanceMetaData.getInstanceGroup()).isSameAs(instanceGroup);
    assertTrue(instanceMetaData.getAmbariServer());
    assertTrue(instanceMetaData.getClusterManagerServer());
    assertThat(instanceMetaData.getSubnetId()).isEqualTo(subnetId);
    assertThat(instanceMetaData.getAvailabilityZone()).isEqualTo(availabilityZone);
    assertThat(instanceMetaData.getRackId()).isEqualTo(rackId);
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) TreeSet(java.util.TreeSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 54 with InstanceGroup

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

the class MetadataSetupServiceTest method testSaveInstanceMetadataAndSelectTheRightPGW.

@Test
public void testSaveInstanceMetadataAndSelectTheRightPGW() throws CloudbreakImageNotFoundException {
    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id1", new InstanceTemplate("medium", "gateway", 10L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.1", "1.1.1.1")));
    cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id2", new InstanceTemplate("medium", "gateway", 11L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.2", "1.1.1.2")));
    cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id3", new InstanceTemplate("medium", "worker", 12L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 41L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.2", "1.1.1.2")));
    InstanceMetaData lastTerminatedPGW = new InstanceMetaData();
    String primaryGWDiscoveryFQDN = "primarygw.example.com";
    lastTerminatedPGW.setDiscoveryFQDN(primaryGWDiscoveryFQDN);
    when(instanceMetaDataService.getLastTerminatedPrimaryGatewayInstanceMetadata(1L)).thenReturn(Optional.of(lastTerminatedPGW));
    InstanceMetaData gwInstanceMetadata1 = new InstanceMetaData();
    InstanceGroup gwInstanceGroup = new InstanceGroup();
    gwInstanceGroup.setGroupName("gateway");
    gwInstanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    gwInstanceMetadata1.setInstanceGroup(gwInstanceGroup);
    gwInstanceMetadata1.setPrivateId(10L);
    gwInstanceMetadata1.setDiscoveryFQDN(primaryGWDiscoveryFQDN);
    InstanceMetaData gwInstanceMetadata2 = new InstanceMetaData();
    gwInstanceMetadata2.setInstanceGroup(gwInstanceGroup);
    gwInstanceMetadata2.setPrivateId(11L);
    String gw1DiscoveryFQDN = "gw1.example.com";
    gwInstanceMetadata2.setDiscoveryFQDN(gw1DiscoveryFQDN);
    InstanceGroup workerInstanceGroup = new InstanceGroup();
    workerInstanceGroup.setGroupName("worker");
    workerInstanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
    InstanceMetaData gwInstanceMetadata3 = new InstanceMetaData();
    gwInstanceMetadata3.setInstanceGroup(workerInstanceGroup);
    gwInstanceMetadata3.setPrivateId(12L);
    String gw2DiscoveryFQDN = "gw2.example.com";
    gwInstanceMetadata3.setDiscoveryFQDN(gw2DiscoveryFQDN);
    when(imageService.getImage(STACK_ID)).thenReturn(image);
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(gwInstanceMetadata1, gwInstanceMetadata2, gwInstanceMetadata3));
    underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, CREATED);
    verify(instanceMetaDataService, times(3)).save(instanceMetaDataCaptor.capture());
    List<InstanceMetaData> savedInstanceMetadatas = instanceMetaDataCaptor.getAllValues();
    List<InstanceMetaData> primaryGWs = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY_PRIMARY.equals(instanceMetaData.getInstanceMetadataType())).collect(Collectors.toList());
    assertEquals(1, primaryGWs.size());
    assertEquals(primaryGWDiscoveryFQDN, primaryGWs.get(0).getDiscoveryFQDN());
    List<InstanceMetaData> gws = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY.equals(instanceMetaData.getInstanceMetadataType())).collect(Collectors.toList());
    assertEquals(1, gws.size());
    assertEquals(gw1DiscoveryFQDN, gws.get(0).getDiscoveryFQDN());
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) Mockito.doThrow(org.mockito.Mockito.doThrow) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) GATEWAY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY) Map(java.util.Map) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) MethodSource(org.junit.jupiter.params.provider.MethodSource) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.STOPPED) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) StackIdViewImpl(com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) InstanceLifeCycle(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) Mock(org.mockito.Mock) GATEWAY_PRIMARY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY_PRIMARY) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Captor(org.mockito.Captor) ZOMBIE(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.ZOMBIE) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) StackStatusService(com.sequenceiq.cloudbreak.service.stackstatus.StackStatusService) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) LoadBalancerConfigConverter(com.sequenceiq.cloudbreak.service.LoadBalancerConfigConverter) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMocks(org.mockito.InjectMocks) CloudInstanceLifeCycle(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceLifeCycle) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) Collections(java.util.Collections) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with InstanceGroup

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

the class MetadataSetupServiceTest method testSaveInstanceMetadataAndSelectTheRightPGWButFQDNDidNotMatchSoFallback.

@Test
public void testSaveInstanceMetadataAndSelectTheRightPGWButFQDNDidNotMatchSoFallback() throws CloudbreakImageNotFoundException {
    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id1", new InstanceTemplate("medium", "gateway", 10L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.1", "1.1.1.1")));
    cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id2", new InstanceTemplate("medium", "gateway", 11L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.2", "1.1.1.2")));
    cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id3", new InstanceTemplate("medium", "worker", 12L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 41L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.3", "1.1.1.3")));
    InstanceMetaData lastTerminatedPGW = new InstanceMetaData();
    String primaryGWDiscoveryFQDN = "primarygw.example.com";
    lastTerminatedPGW.setDiscoveryFQDN(primaryGWDiscoveryFQDN);
    when(instanceMetaDataService.getLastTerminatedPrimaryGatewayInstanceMetadata(1L)).thenReturn(Optional.of(lastTerminatedPGW));
    InstanceMetaData gwInstanceMetadata1 = new InstanceMetaData();
    InstanceGroup gwInstanceGroup = new InstanceGroup();
    gwInstanceGroup.setGroupName("gateway");
    gwInstanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    gwInstanceMetadata1.setInstanceGroup(gwInstanceGroup);
    gwInstanceMetadata1.setPrivateId(10L);
    String gw1DiscoveryFQDN = "gw1.example.com";
    gwInstanceMetadata1.setDiscoveryFQDN(gw1DiscoveryFQDN);
    InstanceMetaData gwInstanceMetadata2 = new InstanceMetaData();
    gwInstanceMetadata2.setInstanceGroup(gwInstanceGroup);
    gwInstanceMetadata2.setPrivateId(11L);
    String gw2DiscoveryFQDN = "gw2.example.com";
    gwInstanceMetadata2.setDiscoveryFQDN(gw2DiscoveryFQDN);
    gwInstanceGroup.setInstanceMetaData(Set.of(gwInstanceMetadata1, gwInstanceMetadata2));
    InstanceGroup workerInstanceGroup = new InstanceGroup();
    workerInstanceGroup.setGroupName("worker");
    workerInstanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
    InstanceMetaData workerInstanceMetadata3 = new InstanceMetaData();
    workerInstanceMetadata3.setInstanceGroup(workerInstanceGroup);
    workerInstanceMetadata3.setPrivateId(12L);
    String worker1DiscoveryFQDN = "worker1.example.com";
    workerInstanceMetadata3.setDiscoveryFQDN(worker1DiscoveryFQDN);
    workerInstanceGroup.setInstanceMetaData(Set.of(workerInstanceMetadata3));
    when(imageService.getImage(STACK_ID)).thenReturn(image);
    when(instanceGroupService.findByStackId(1L)).thenReturn(Set.of(gwInstanceGroup, workerInstanceGroup));
    when(instanceMetaDataService.findAllByInstanceGroupAndInstanceStatusOrdered(gwInstanceGroup, com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.CREATED)).thenReturn(List.of(gwInstanceMetadata1, gwInstanceMetadata2));
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(gwInstanceMetadata1, gwInstanceMetadata2, workerInstanceMetadata3));
    underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, CREATED);
    verify(instanceMetaDataService, times(4)).save(instanceMetaDataCaptor.capture());
    List<InstanceMetaData> savedInstanceMetadatas = instanceMetaDataCaptor.getAllValues();
    List<InstanceMetaData> primaryGWs = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY_PRIMARY.equals(instanceMetaData.getInstanceMetadataType())).distinct().collect(Collectors.toList());
    assertEquals(1, primaryGWs.size());
    assertEquals(gw1DiscoveryFQDN, primaryGWs.get(0).getDiscoveryFQDN());
    List<InstanceMetaData> gws = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY.equals(instanceMetaData.getInstanceMetadataType())).collect(Collectors.toList());
    assertEquals(1, gws.size());
    assertEquals(gw2DiscoveryFQDN, gws.get(0).getDiscoveryFQDN());
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) Mockito.doThrow(org.mockito.Mockito.doThrow) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) GATEWAY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY) Map(java.util.Map) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) MethodSource(org.junit.jupiter.params.provider.MethodSource) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.STOPPED) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) StackIdViewImpl(com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) InstanceLifeCycle(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) Mock(org.mockito.Mock) GATEWAY_PRIMARY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY_PRIMARY) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Captor(org.mockito.Captor) ZOMBIE(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.ZOMBIE) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) StackStatusService(com.sequenceiq.cloudbreak.service.stackstatus.StackStatusService) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) LoadBalancerConfigConverter(com.sequenceiq.cloudbreak.service.LoadBalancerConfigConverter) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMocks(org.mockito.InjectMocks) CloudInstanceLifeCycle(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceLifeCycle) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) Collections(java.util.Collections) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)288 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)132 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)93 Test (org.junit.jupiter.api.Test)91 HashSet (java.util.HashSet)68 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)47 Template (com.sequenceiq.cloudbreak.domain.Template)45 Test (org.junit.Test)44 Json (com.sequenceiq.cloudbreak.common.json.Json)38 Set (java.util.Set)37 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)34 ArrayList (java.util.ArrayList)31 LinkedHashSet (java.util.LinkedHashSet)31 Map (java.util.Map)28 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)27 List (java.util.List)26 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)25 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22