Search in sources :

Example 26 with ImageEntity

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

the class UpgradeCcmFlowChainIntegrationTest method setup.

@BeforeEach
public void setup() {
    Stack stack = new Stack();
    stack.setId(STACK_ID);
    stack.setTunnel(Tunnel.CCM);
    ImageEntity image = new ImageEntity();
    stack.setImage(image);
    image.setUserdata(USER_DATA);
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
    when(stackService.getStackById(STACK_ID)).thenReturn(stack);
    CloudConnector<Object> connector = mock(CloudConnector.class);
    AuthenticatedContext context = mock(AuthenticatedContext.class);
    Authenticator authApi = mock(Authenticator.class);
    when(cloudPlatformConnectors.get(any())).thenReturn(connector);
    when(connector.authentication()).thenReturn(authApi);
    when(connector.resources()).thenReturn(resourcesApi);
    when(authApi.authenticate(any(), any())).thenReturn(context);
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Authenticator(com.sequenceiq.cloudbreak.cloud.Authenticator) Stack(com.sequenceiq.freeipa.entity.Stack) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with ImageEntity

use of com.sequenceiq.freeipa.entity.ImageEntity 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 28 with ImageEntity

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

the class UpdateUserDataFlowIntegrationTest method setup.

@BeforeEach
public void setup() {
    Stack stack = new Stack();
    stack.setId(STACK_ID);
    stack.setTunnel(Tunnel.CCM);
    ImageEntity image = new ImageEntity();
    stack.setImage(image);
    image.setUserdata(USER_DATA);
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
    when(stackService.getStackById(STACK_ID)).thenReturn(stack);
    CloudConnector<Object> connector = mock(CloudConnector.class);
    AuthenticatedContext context = mock(AuthenticatedContext.class);
    Authenticator authApi = mock(Authenticator.class);
    when(cloudPlatformConnectors.get(any())).thenReturn(connector);
    when(connector.authentication()).thenReturn(authApi);
    when(connector.resources()).thenReturn(resourcesApi);
    when(authApi.authenticate(any(), any())).thenReturn(context);
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Authenticator(com.sequenceiq.cloudbreak.cloud.Authenticator) Stack(com.sequenceiq.freeipa.entity.Stack) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with ImageEntity

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

the class UpgradeCcmService method checkPrerequsities.

public void checkPrerequsities(Long stackId) {
    Stack stack = stackService.getStackById(stackId);
    ImageEntity stackImage = imageService.getByStackId(stackId);
    FreeIpaUpgradeOptions freeIpaUpgradeOptions = upgradeService.collectUpgradeOptions(stack.getAccountId(), stack.getEnvironmentCrn(), Objects.requireNonNullElse(stackImage.getImageCatalogName(), stackImage.getImageCatalogUrl()));
    if (!freeIpaUpgradeOptions.getImages().isEmpty()) {
        throw new CloudbreakServiceException("FreeIPA is not on the latest available image. Please upgrade that first. CCM upgrade is not possible yet.");
    }
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) FreeIpaUpgradeOptions(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeOptions) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 30 with ImageEntity

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

the class ImageChangeFailureHandlerAction method doExecute.

@Override
protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) throws Exception {
    LOGGER.error("Image change failed", payload.getException());
    if (variables.containsKey(ImageChangeActions.ORIGINAL_IMAGE_REVISION) && variables.containsKey(ImageChangeActions.IMAGE_CHANGED_IN_DB)) {
        LOGGER.info("Reverting to original image using revision [{}]", variables.get(ImageChangeActions.ORIGINAL_IMAGE_REVISION));
        imageService.revertImageToRevision((Long) variables.get(ImageChangeActions.IMAGE_ENTITY_ID), (Number) variables.get(ImageChangeActions.ORIGINAL_IMAGE_REVISION));
    } else if (variables.containsKey(ImageChangeActions.ORIGINAL_IMAGE) && variables.containsKey(ImageChangeActions.IMAGE_CHANGED_IN_DB)) {
        LOGGER.info("Reverting to original image using entity stored in variables");
        ImageEntity originalImage = (ImageEntity) variables.get(ImageChangeActions.ORIGINAL_IMAGE);
        imageService.save(originalImage);
    }
    if (isOperationIdSet(variables)) {
        operationService.failOperation(context.getStack().getAccountId(), getOperationId(variables), payload.getException().getMessage());
    }
    sendEvent(context, new StackEvent(IMAGE_CHANGE_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()));
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) 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