use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.
the class SdxUpgradeService method changeImage.
public void changeImage(Long id, UpgradeOptionV4Response upgradeOption) {
SdxCluster cluster = sdxService.getById(id);
String targetImageId = upgradeOption.getUpgrade().getImageId();
StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
stackImageChangeRequest.setImageId(targetImageId);
stackImageChangeRequest.setImageCatalogName(upgradeOption.getUpgrade().getImageCatalogName());
sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.CHANGE_IMAGE_IN_PROGRESS, "Changing image", cluster);
try {
String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageInternal(0L, cluster.getClusterName(), stackImageChangeRequest, initiatorUserCrn));
cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
} catch (WebApplicationException e) {
String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
String message = String.format("Stack change image failed on cluster: [%s]. Message: [%s]", cluster.getClusterName(), exceptionMessage);
throw new CloudbreakApiException(message, e);
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.
the class UpgradeService method getUpgradeOption.
private UpgradeOptionV4Response getUpgradeOption(Stack stack, Long workspaceId, User user) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Image image = componentConfigProviderService.getImage(stack.getId());
UpgradeOptionV4Response upgradeResponse;
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairResult = clusterRepairService.repairWithDryRun(stack.getId());
if (repairResult.isSuccess()) {
StatedImage latestImage = getLatestImage(workspaceId, stack, image, user);
if (!isLatestImage(stack, image, latestImage)) {
upgradeResponse = currentImageNotLatest(stack, image, latestImage);
} else {
upgradeResponse = notUpgradable(image, String.format("According to the image catalog, the current image %s is already the latest version.", image.getImageId()));
}
} else {
upgradeResponse = notUpgradableWithValidationResult(image, repairResult.getError());
}
return upgradeResponse;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.
the class UpgradeService method notUpgradable.
private UpgradeOptionV4Response notUpgradable(Image image, String reason) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
UpgradeOptionV4Response response = createUpgradeBaseWithCurrent(image);
response.setReason(reason);
LOGGER.error("Datalake upgrade option evaluation finished with error, reason: {}", response.getReason());
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.
the class UpgradeService method upgradeableAfterAction.
private UpgradeOptionV4Response upgradeableAfterAction(Image image, StatedImage latestImage, Stack stack, String reason) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
UpgradeOptionV4Response response = notUpgradable(image, reason);
ImageInfoV4Response upgradeImageInfo = new ImageInfoV4Response(getImageNameForStack(stack, latestImage), latestImage.getImage().getUuid(), latestImage.getImageCatalogName(), latestImage.getImage().getCreated(), latestImage.getImage().getDate(), getComponentVersions(latestImage.getImage()));
response.setUpgrade(upgradeImageInfo);
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.
the class UpgradeServiceTest method shouldReturnNewImageName.
@Test
public void shouldReturnNewImageName() 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);
ClouderaManagerRepo clouderaManagerRepo = new ClouderaManagerRepo();
clouderaManagerRepo.setBaseUrl("cm-base-url");
when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(1L)).thenReturn(clouderaManagerRepo);
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("AWS"), eq(stack.getCluster().getBlueprint()), eq(false), eq(false), eq(user), any());
assertThat(result.getUpgrade().getImageName()).isEqualTo("id-2");
assertThat(result.getReason()).isEqualTo(null);
}
Aggregations