Search in sources :

Example 11 with ImageEntity

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

the class ImageChangeAction method storeOriginalImageRevision.

private ImageEntity storeOriginalImageRevision(ImageChangeEvent payload, Map<Object, Object> variables) {
    ImageEntity imageEntity = imageService.getByStackId(payload.getResourceId());
    Long imageEntityId = imageEntity.getId();
    List<Number> revisions = auditReader.getRevisions(ImageEntity.class, imageEntityId);
    if (!revisions.isEmpty()) {
        storeRevisionInfo(variables, imageEntityId, revisions);
    } else {
        LOGGER.info("No revision found for current image with id [{}]", imageEntityId);
        variables.put(ImageChangeActions.ORIGINAL_IMAGE, imageEntity);
    }
    return imageEntity;
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity)

Example 12 with ImageEntity

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

the class ImageChangeAction method doExecute.

@Override
protected void doExecute(StackContext context, ImageChangeEvent payload, Map<Object, Object> variables) throws Exception {
    setOperationId(variables, payload.getOperationId());
    ImageEntity originalImageEntity = storeOriginalImageRevision(payload, variables);
    ImageEntity newImageEntity = imageService.changeImage(context.getStack(), payload.getRequest());
    variables.put(ImageChangeActions.IMAGE_CHANGED_IN_DB, Boolean.TRUE);
    if (originalImageEntity.equals(newImageEntity)) {
        LOGGER.info("New and original image is the same, no change is required");
        sendEvent(context, new ImageChangeEvent(IMAGE_CHANGE_NOT_REQUIRED_EVENT.event(), payload.getResourceId(), payload.getRequest()));
    } else {
        sendEvent(context, new ImageChangeEvent(IMAGE_CHANGED_IN_DB_EVENT.event(), payload.getResourceId(), payload.getRequest()));
    }
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)

Example 13 with ImageEntity

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

the class BootstrapServiceTest method testBootstrapWithoutInstanceIds.

@Test
public void testBootstrapWithoutInstanceIds() 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();
    underTest.bootstrap(STACK_ID);
    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 14 with ImageEntity

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

the class BootstrapServiceTest method testCbOrchestratorExRethrown.

@Test
public void testCbOrchestratorExRethrown() 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);
    when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenThrow(new IOException("wow"));
    ImageEntity image = new ImageEntity();
    image.setOs("ZOS");
    when(imageService.getByStack(stack)).thenReturn(image);
    when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
    assertThrows(CloudbreakOrchestratorException.class, () -> underTest.bootstrap(STACK_ID));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) IOException(java.io.IOException) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 15 with ImageEntity

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

the class UsedImagesProviderTest method createImage.

private ImageEntity createImage(String imageId) {
    final ImageEntity image = new ImageEntity();
    image.setImageId(imageId);
    return image;
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity)

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