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);
}
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());
}
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);
}
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.");
}
}
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()));
}
Aggregations