@Test public void upgradeNotAllowedWhenConnectedDataHubStackIsAvailable() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { Stack stack = getStack(); Image image = getImage("id-1"); setUpMocks(stack, image, true, "id-1", "id-2"); Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.success(new HashMap<>()); when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult); StackViewV4Response stackViewV4Response = new StackViewV4Response(); stackViewV4Response.setStatus(Status.AVAILABLE); when(distroXV1Endpoint.list(any(), anyString())).thenReturn(new StackViewV4Responses(Set.of(stackViewV4Response))); when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack); UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user); verify(clusterRepairService).repairWithDryRun(eq(stack.getId())); verify(distroXV1Endpoint).list(eq(null), eq("env-crn")); verify(componentConfigProviderService).getImage(1L); verify(imageService) .determineImageFromCatalog(eq(WORKSPACE_ID), captor.capture(), eq("aws"), eq(stack.getCluster().getBlueprint()), eq(false), eq(false), eq(user), any()); assertThat(result.getUpgrade().getImageName()).isEqualTo("id-2"); assertThat(result.getReason()).isEqualTo("Please stop connected DataHub clusters before upgrade."); }
public UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user) { Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId); MDCBuilder.buildMdcContext(stack); try { return getUpgradeOption(stack, workspaceId, user); } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) { LOGGER.warn("Error retrieving image", e); throw new BadRequestException(e.getMessage(), e); } }
UpgradeService { public UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user) { Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId); MDCBuilder.buildMdcContext(stack); try { return getUpgradeOption(stack, workspaceId, user); } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) { LOGGER.warn("Error retrieving image", e); throw new BadRequestException(e.getMessage(), e); } } }
UpgradeService { public UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user) { Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId); MDCBuilder.buildMdcContext(stack); try { return getUpgradeOption(stack, workspaceId, user); } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) { LOGGER.warn("Error retrieving image", e); throw new BadRequestException(e.getMessage(), e); } }  }
UpgradeService { public UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user) { Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId); MDCBuilder.buildMdcContext(stack); try { return getUpgradeOption(stack, workspaceId, user); } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) { LOGGER.warn("Error retrieving image", e); throw new BadRequestException(e.getMessage(), e); } }  UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user); FlowIdentifier upgradeOs(Long workspaceId, NameOrCrn stackNameOrCrn); FlowIdentifier upgradeCluster(Long workspaceId, NameOrCrn stackNameOrCrn, String imageId); boolean isOsUpgrade(UpgradeV4Request request); }
UpgradeService { public UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user) { Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId); MDCBuilder.buildMdcContext(stack); try { return getUpgradeOption(stack, workspaceId, user); } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) { LOGGER.warn("Error retrieving image", e); throw new BadRequestException(e.getMessage(), e); } }  UpgradeOptionV4Response getOsUpgradeOptionByStackNameOrCrn(Long workspaceId, NameOrCrn nameOrCrn, User user); FlowIdentifier upgradeOs(Long workspaceId, NameOrCrn stackNameOrCrn); FlowIdentifier upgradeCluster(Long workspaceId, NameOrCrn stackNameOrCrn, String imageId); boolean isOsUpgrade(UpgradeV4Request request);  }