Search in sources :

Example 41 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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 42 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class UpgradeFlowEventChainFactoryTest method testFlowChainCreation.

@Test
public void testFlowChainCreation() {
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    UpgradeEvent event = new UpgradeEvent("selector", STACK_ID, Sets.newHashSet("repl1", "repl2"), "pgw", OPERATION_ID, imageSettingsRequest, false);
    FlowTriggerEventQueue eventQueue = underTest.createFlowTriggerEventQueue(event);
    assertEquals("UpgradeFlowEventChainFactory", eventQueue.getFlowChainName());
    Queue<Selectable> queue = eventQueue.getQueue();
    assertEquals(10, queue.size());
    SaltUpdateTriggerEvent saltUpdateTriggerEvent = (SaltUpdateTriggerEvent) queue.poll();
    assertEquals(OPERATION_ID, saltUpdateTriggerEvent.getOperationId());
    assertEquals(STACK_ID, saltUpdateTriggerEvent.getResourceId());
    assertEquals(SaltUpdateEvent.SALT_UPDATE_EVENT.event(), saltUpdateTriggerEvent.selector());
    assertFalse(saltUpdateTriggerEvent.isFinalChain());
    ImageChangeEvent imageChangeEvent = (ImageChangeEvent) queue.poll();
    assertEquals(OPERATION_ID, imageChangeEvent.getOperationId());
    assertEquals(STACK_ID, imageChangeEvent.getResourceId());
    assertEquals(IMAGE_CHANGE_EVENT.event(), imageChangeEvent.selector());
    assertEquals(imageSettingsRequest, imageChangeEvent.getRequest());
    UpscaleEvent upscaleEvent1 = (UpscaleEvent) queue.poll();
    assertEquals(OPERATION_ID, upscaleEvent1.getOperationId());
    assertEquals(STACK_ID, upscaleEvent1.getResourceId());
    assertTrue(upscaleEvent1.isChained());
    assertFalse(upscaleEvent1.isFinalChain());
    assertFalse(upscaleEvent1.isRepair());
    assertEquals(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent1.selector());
    assertEquals(4, upscaleEvent1.getInstanceCountByGroup());
    DownscaleEvent downscaleEvent1 = (DownscaleEvent) queue.poll();
    assertEquals(OPERATION_ID, downscaleEvent1.getOperationId());
    assertEquals(STACK_ID, downscaleEvent1.getResourceId());
    assertTrue(downscaleEvent1.isChained());
    assertFalse(downscaleEvent1.isFinalChain());
    assertFalse(downscaleEvent1.isRepair());
    assertEquals(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent1.selector());
    assertEquals(3, downscaleEvent1.getInstanceCountByGroup());
    assertEquals(1, downscaleEvent1.getInstanceIds().size());
    String firstInstanceToDownscale = downscaleEvent1.getInstanceIds().get(0);
    assertTrue(firstInstanceToDownscale.startsWith("repl"));
    UpscaleEvent upscaleEvent2 = (UpscaleEvent) queue.poll();
    assertEquals(OPERATION_ID, upscaleEvent2.getOperationId());
    assertEquals(STACK_ID, upscaleEvent2.getResourceId());
    assertTrue(upscaleEvent2.isChained());
    assertFalse(upscaleEvent2.isFinalChain());
    assertFalse(upscaleEvent2.isRepair());
    assertEquals(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent2.selector());
    assertEquals(4, upscaleEvent2.getInstanceCountByGroup());
    DownscaleEvent downscaleEvent2 = (DownscaleEvent) queue.poll();
    assertEquals(OPERATION_ID, downscaleEvent2.getOperationId());
    assertEquals(STACK_ID, downscaleEvent2.getResourceId());
    assertTrue(downscaleEvent2.isChained());
    assertFalse(downscaleEvent2.isFinalChain());
    assertFalse(downscaleEvent2.isRepair());
    assertEquals(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent2.selector());
    assertEquals(3, downscaleEvent2.getInstanceCountByGroup());
    assertEquals(1, downscaleEvent2.getInstanceIds().size());
    String secondInstanceToDownscale = downscaleEvent2.getInstanceIds().get(0);
    assertTrue(secondInstanceToDownscale.startsWith("repl"));
    assertNotEquals(firstInstanceToDownscale, secondInstanceToDownscale);
    UpscaleEvent upscaleEvent3 = (UpscaleEvent) queue.poll();
    assertEquals(OPERATION_ID, upscaleEvent3.getOperationId());
    assertEquals(STACK_ID, upscaleEvent3.getResourceId());
    assertTrue(upscaleEvent3.isChained());
    assertFalse(upscaleEvent3.isFinalChain());
    assertFalse(upscaleEvent3.isRepair());
    assertEquals(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent3.selector());
    assertEquals(4, upscaleEvent3.getInstanceCountByGroup());
    ChangePrimaryGatewayEvent changePrimaryGatewayEvent = (ChangePrimaryGatewayEvent) queue.poll();
    assertEquals(OPERATION_ID, changePrimaryGatewayEvent.getOperationId());
    assertEquals(STACK_ID, changePrimaryGatewayEvent.getResourceId());
    assertFalse(changePrimaryGatewayEvent.isFinalChain());
    assertEquals(ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_EVENT.event(), changePrimaryGatewayEvent.selector());
    assertEquals(3, changePrimaryGatewayEvent.getRepairInstaceIds().size());
    assertTrue(List.of("repl1", "repl2", "pgw").containsAll(changePrimaryGatewayEvent.getRepairInstaceIds()));
    DownscaleEvent downscaleEvent3 = (DownscaleEvent) queue.poll();
    assertEquals(OPERATION_ID, downscaleEvent3.getOperationId());
    assertEquals(STACK_ID, downscaleEvent3.getResourceId());
    assertTrue(downscaleEvent3.isChained());
    assertFalse(downscaleEvent3.isFinalChain());
    assertFalse(downscaleEvent3.isRepair());
    assertEquals(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent3.selector());
    assertEquals(3, downscaleEvent3.getInstanceCountByGroup());
    assertEquals(1, downscaleEvent3.getInstanceIds().size());
    assertEquals("pgw", downscaleEvent3.getInstanceIds().get(0));
    SaltUpdateTriggerEvent saltUpdateTriggerEvent2 = (SaltUpdateTriggerEvent) queue.poll();
    assertEquals(OPERATION_ID, saltUpdateTriggerEvent2.getOperationId());
    assertEquals(STACK_ID, saltUpdateTriggerEvent2.getResourceId());
    assertEquals(SaltUpdateEvent.SALT_UPDATE_EVENT.event(), saltUpdateTriggerEvent2.selector());
    assertTrue(saltUpdateTriggerEvent2.isChained());
    assertTrue(saltUpdateTriggerEvent2.isFinalChain());
}
Also used : UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) UpscaleEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent) SaltUpdateTriggerEvent(com.sequenceiq.freeipa.flow.freeipa.salt.update.SaltUpdateTriggerEvent) ChangePrimaryGatewayEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayEvent) Test(org.junit.jupiter.api.Test)

Example 43 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class ImageChangeActionTest method testStoreImageEntity.

@Test
public void testStoreImageEntity() throws Exception {
    StackContext stackContext = mock(StackContext.class);
    Stack stack = new Stack();
    when(stackContext.getStack()).thenReturn(stack);
    when(stackContext.getFlowParameters()).thenReturn(new FlowParameters("flid", "userCrn", null));
    ImageEntity imageEntity = new ImageEntity();
    imageEntity.setId(2L);
    when(imageService.getByStackId(1L)).thenReturn(imageEntity);
    when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of());
    Map<Object, Object> variables = new HashMap<>();
    ImageSettingsRequest request = new ImageSettingsRequest();
    underTest.doExecute(stackContext, new ImageChangeEvent(1L, request), variables);
    assertEquals(Boolean.TRUE, variables.get(IMAGE_CHANGED_IN_DB));
    assertFalse(variables.containsKey(ORIGINAL_IMAGE_REVISION));
    assertFalse(variables.containsKey(IMAGE_ENTITY_ID));
    assertEquals(imageEntity, variables.get(ORIGINAL_IMAGE));
    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), captor.capture());
    ImageChangeEvent event = (ImageChangeEvent) captor.getValue();
    assertEquals(IMAGE_CHANGED_IN_DB_EVENT.event(), event.selector());
    assertEquals(1L, event.getResourceId());
    assertEquals(request, event.getRequest());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) HashMap(java.util.HashMap) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 44 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class CoreImageProvider method getImages.

@Override
public List<ImageWrapper> getImages(ImageSettingsRequest imageSettings, String region, String platform) {
    try {
        ImagesV4Response imagesV4Response = imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, imageSettings.getCatalog(), null, platform, null, null, false);
        LOGGER.debug("Images received: {}", imagesV4Response);
        return Optional.ofNullable(imagesV4Response.getFreeipaImages()).orElseGet(List::of).stream().map(this::convert).flatMap(Optional::stream).map(img -> new ImageWrapper(img, null, imageSettings.getCatalog())).collect(Collectors.toList());
    } catch (WebApplicationException e) {
        String errorMessage = messageExtractor.getErrorMessage(e);
        LOGGER.warn("Fetching images failed with: {}", errorMessage, e);
        return List.of();
    } catch (Exception e) {
        LOGGER.warn("Fetching images failed", e);
        return List.of();
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Logger(org.slf4j.Logger) ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) LoggerFactory(org.slf4j.LoggerFactory) WebApplicationExceptionMessageExtractor(com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 45 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest in project cloudbreak by hortonworks.

the class FreeIpaImageProvider method getImages.

public List<ImageWrapper> getImages(ImageSettingsRequest imageSettings, String region, String platform) {
    String imageId = imageSettings.getId();
    String catalogUrl = StringUtils.isNotBlank(imageSettings.getCatalog()) ? imageSettings.getCatalog() : defaultCatalogUrl;
    String imageOs = StringUtils.isNotBlank(imageSettings.getOs()) ? imageSettings.getOs() : defaultOs;
    ImageCatalog cachedImageCatalog = imageCatalogProvider.getImageCatalog(catalogUrl);
    List<Image> compatibleImages = findImage(imageId, imageOs, cachedImageCatalog.getImages().getFreeipaImages(), region, platform);
    List<String> imagesInVersions = filterFreeIpaVersionsByAppVersion(cachedImageCatalog.getVersions().getFreeIpaVersions()).stream().map(FreeIpaVersions::getImageIds).flatMap(Collection::stream).distinct().collect(Collectors.toList());
    LOGGER.debug("Compatible images: {} " + System.lineSeparator() + "Images in versions: {}", compatibleImages, imagesInVersions);
    return compatibleImages.stream().filter(image -> imagesInVersions.contains(image.getUuid())).map(image -> new ImageWrapper(image, catalogUrl, null)).collect(Collectors.toList());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FreeIpaVersions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Matcher(java.util.regex.Matcher) Service(org.springframework.stereotype.Service) Map(java.util.Map) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Comparator(java.util.Comparator) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Collections(java.util.Collections) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Collection(java.util.Collection) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)

Aggregations

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)57 Test (org.junit.jupiter.api.Test)41 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)28 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)23 Stack (com.sequenceiq.freeipa.entity.Stack)23 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)16 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)7 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)5 FreeIpaUpgradeRequest (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest)4 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Backup (com.sequenceiq.freeipa.api.model.Backup)3 UpgradeEvent (com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent)3 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)2 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)2