Search in sources :

Example 21 with ImageEntity

use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.

the class BootstrapServiceTest method testBootstrapWithInstanceIds.

@Test
public void testBootstrapWithInstanceIds() throws CloudbreakOrchestratorException, IOException {
    when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain"), createInstance("filterMe", "filtered" + DOMAIN)));
    Stack stack = new Stack();
    stack.setCloudPlatform("cloud");
    when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain(DOMAIN);
    freeIpa.setHostname(HOSTNAME);
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    List<GatewayConfig> gatewayConfigs = List.of();
    when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
    byte[] bytes = {};
    when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenReturn(bytes);
    ImageEntity image = new ImageEntity();
    image.setOs("ZOS");
    when(imageService.getByStack(stack)).thenReturn(image);
    when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
    underTest.bootstrap(STACK_ID, List.of(INSTANCE_WITH_FQDN, INSTANCE_WO_FQDN, INSTANCE_WRONG_DOMAIN));
    ArgumentCaptor<Set<Node>> targetCaptor = ArgumentCaptor.forClass((Class) Set.class);
    ArgumentCaptor<Set<Node>> allCaptor = ArgumentCaptor.forClass((Class) Set.class);
    ArgumentCaptor<BootstrapParams> bootstrapParamsCaptor = ArgumentCaptor.forClass(BootstrapParams.class);
    ArgumentCaptor<ExitCriteriaModel> exitCriteriaModelCaptor = ArgumentCaptor.forClass(ExitCriteriaModel.class);
    verify(hostOrchestrator).bootstrapNewNodes(eq(gatewayConfigs), targetCaptor.capture(), allCaptor.capture(), eq(bytes), bootstrapParamsCaptor.capture(), exitCriteriaModelCaptor.capture());
    Set<Node> targetNodes = targetCaptor.getValue();
    Set<Node> allNodes = allCaptor.getValue();
    assertEquals(targetNodes, allNodes);
    assertEquals(3, allNodes.size());
    assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WITH_FQDN)), hasProperty("hostname", is("instance1")), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
    assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WO_FQDN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
    assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WRONG_DOMAIN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
    BootstrapParams bootstrapParams = bootstrapParamsCaptor.getValue();
    assertTrue(bootstrapParams.isSaltBootstrapFpSupported());
    assertTrue(bootstrapParams.isRestartNeededFlagSupported());
    assertEquals(image.getOs(), bootstrapParams.getOs());
    assertEquals(stack.getCloudPlatform(), bootstrapParams.getCloud());
    StackBasedExitCriteriaModel exitCriteriaModel = (StackBasedExitCriteriaModel) exitCriteriaModelCaptor.getValue();
    assertEquals(STACK_ID, exitCriteriaModel.getStackId().get());
}
Also used : StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) Set(java.util.Set) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) Stack(com.sequenceiq.freeipa.entity.Stack) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 22 with ImageEntity

use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.

the class BootstrapServiceTest method testIOExceptionConverted.

@Test
public void testIOExceptionConverted() throws CloudbreakOrchestratorException, IOException {
    when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain")));
    Stack stack = new Stack();
    stack.setCloudPlatform("cloud");
    when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain(DOMAIN);
    freeIpa.setHostname(HOSTNAME);
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    List<GatewayConfig> gatewayConfigs = List.of();
    when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
    byte[] bytes = {};
    when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenReturn(bytes);
    ImageEntity image = new ImageEntity();
    image.setOs("ZOS");
    when(imageService.getByStack(stack)).thenReturn(image);
    when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
    doThrow(new CloudbreakOrchestratorCancelledException("wow")).when(hostOrchestrator).bootstrapNewNodes(any(), anySet(), anySet(), any(), any(), any());
    assertThrows(CloudbreakOrchestratorException.class, () -> underTest.bootstrap(STACK_ID));
}
Also used : CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 23 with ImageEntity

use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.

the class ImageCatalogChangeServiceTest method init.

@BeforeAll
static void init() {
    STACK.setId(STACK_ID);
    STACK.setName(STACK_NAME);
    final ImageEntity image = new ImageEntity();
    image.setImageId(IMAGE_ID);
    image.setOs(OS);
    STACK.setImage(image);
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 24 with ImageEntity

use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.

the class ImageServiceTest method testImageChange.

@Test
public void testImageChange() {
    Stack stack = new Stack();
    stack.setCloudPlatform(DEFAULT_PLATFORM);
    stack.setRegion(DEFAULT_REGION);
    ImageSettingsRequest imageRequest = new ImageSettingsRequest();
    when(imageProviderFactory.getImageProvider(any())).thenReturn(imageProvider);
    when(imageProvider.getImage(imageRequest, stack.getRegion(), stack.getCloudPlatform())).thenReturn(Optional.of(new ImageWrapper(image, IMAGE_CATALOG_URL, IMAGE_CATALOG)));
    when(image.getImageSetsByProvider()).thenReturn(Collections.singletonMap(DEFAULT_PLATFORM, Collections.singletonMap(DEFAULT_REGION, EXISTING_ID)));
    when(imageRepository.getByStack(stack)).thenReturn(new ImageEntity());
    when(image.getUuid()).thenReturn(IMAGE_UUID);
    when(imageRepository.save(any(ImageEntity.class))).thenAnswer(invocation -> invocation.getArgument(0, ImageEntity.class));
    ImageEntity imageEntity = underTest.changeImage(stack, imageRequest);
    assertEquals(EXISTING_ID, imageEntity.getImageName());
    assertEquals(IMAGE_CATALOG_URL, imageEntity.getImageCatalogUrl());
    assertEquals(IMAGE_CATALOG, imageEntity.getImageCatalogName());
    assertEquals(IMAGE_UUID, imageEntity.getImageId());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 25 with ImageEntity

use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.

the class StackToCloudStackConverterTest method testBuildInstance.

@Test
public void testBuildInstance() throws Exception {
    InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    ImageEntity imageEntity = mock(ImageEntity.class);
    when(imageService.getByStack(any())).thenReturn(imageEntity);
    when(imageEntity.getImageName()).thenReturn(IMAGE_NAME);
    when(instanceMetaData.getInstanceId()).thenReturn(INSTANCE_ID);
    when(instanceGroup.getGroupName()).thenReturn(GROUP_NAME);
    Template template = mock(Template.class);
    when(instanceGroup.getTemplate()).thenReturn(template);
    when(template.getVolumeCount()).thenReturn(VOLUME_COUNT);
    CloudInstance cloudInstance = underTest.buildInstance(stack, instanceMetaData, instanceGroup, stackAuthentication, 0L, InstanceStatus.CREATED);
    assertEquals(INSTANCE_ID, cloudInstance.getInstanceId());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) Test(org.junit.Test)

Aggregations

ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)39 Stack (com.sequenceiq.freeipa.entity.Stack)17 Test (org.junit.jupiter.api.Test)14 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)10 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)7 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)5 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)5 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)4 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)3 BootstrapParams (com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)3 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)3 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)3 StackBasedExitCriteriaModel (com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Authenticator (com.sequenceiq.cloudbreak.cloud.Authenticator)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2