use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class ClusterUpgradeService method clusterUpgradeFinished.
public void clusterUpgradeFinished(long stackId, StatedImage currentImage, StatedImage targetImage) {
Image targetIm = targetImage.getImage();
Image currentIm = currentImage.getImage();
String clusterStackVersion = NullUtil.getIfNotNull(targetIm.getStackDetails(), ImageStackDetails::getVersion);
String currentRuntimeBuildNumber = NullUtil.getIfNotNull(currentIm.getStackDetails(), ImageStackDetails::getStackBuildNumber);
boolean clusterRuntimeUpgradeNeeded = isUpdateNeeded(currentRuntimeBuildNumber, NullUtil.getIfNotNull(targetIm.getStackDetails(), ImageStackDetails::getStackBuildNumber));
stackUpdater.updateStackStatus(stackId, DetailedStackStatus.CLUSTER_UPGRADE_FINISHED, "Cluster stack was successfully upgraded.");
Optional<String> stackVersion = getStackVersionFromImage(targetIm);
stackVersion.ifPresentOrElse(s -> stackUpdater.updateStackVersion(stackId, s), () -> LOGGER.warn("Cluster runtime could not be upgraded for stack with id {}", stackId));
if (clusterRuntimeUpgradeNeeded) {
flowMessageService.fireEventAndLog(stackId, Status.AVAILABLE.name(), CLUSTER_UPGRADE_FINISHED, clusterStackVersion);
} else {
flowMessageService.fireEventAndLog(stackId, Status.AVAILABLE.name(), CLUSTER_UPGRADE_FINISHED_NOVERSION);
}
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage 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.service.image.StatedImage in project cloudbreak by hortonworks.
the class LoggingAgentAutoRestartPatchService method isAffectedByImageTimestamp.
private boolean isAffectedByImageTimestamp(Stack stack, Image image, long dateAfterTimestamp, long dateBeforeTimestamp) {
boolean affected = false;
ImageCatalog imageCatalog = stackImageService.getImageCatalogFromStackAndImage(stack, image);
if (!imageCatalogService.isCustomImageCatalog(imageCatalog)) {
Optional<StatedImage> statedImageOpt = stackImageService.getStatedImageInternal(stack, image, imageCatalog);
if (statedImageOpt.isEmpty() || statedImageOpt.get().getImage() == null || (dateAfterTimestamp <= statedImageOpt.get().getImage().getCreated() && statedImageOpt.get().getImage().getCreated() < dateBeforeTimestamp)) {
affected = true;
}
}
return affected;
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class MaintenanceModeValidationServiceTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
cluster = new Cluster();
cluster.setId(1L);
stack = new Stack();
stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.AVAILABLE));
stack.setId(1L);
stack.setName("stackname");
stack.setRegion("region");
stack.setCloudPlatform("AWS");
stack.setCluster(cluster);
cluster.setStack(stack);
image = new Image("asdf", System.currentTimeMillis(), System.currentTimeMillis(), "asdf", "centos7", "uuid", "2.8.0", Collections.emptyMap(), Collections.singletonMap("AWS", Collections.emptyMap()), null, "centos", packageVersions, Collections.emptyList(), Collections.emptyList(), "1", true, null, null);
statedImage = StatedImage.statedImage(image, "url", "name");
warnings = new ArrayList<Warning>();
// CHECKSTYLE:OFF
stackRepo = "{\n" + " \"href\" : \"http://127.0.0.1/api/v1/stacks/HDP/versions/2.6/operating_systems/redhat7/repositories/HDP-2.6\",\n" + " \"Repositories\" : {\n" + " \"applicable_services\" : [ ],\n" + " \"base_url\" : \"http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.6.5.0\",\n" + " \"components\" : null,\n" + " \"default_base_url\" : \"http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.6.5.0\",\n" + " \"distribution\" : null,\n" + " \"mirrors_list\" : null,\n" + " \"os_type\" : \"redhat7\",\n" + " \"repo_id\" : \"HDP-2.6\",\n" + " \"repo_name\" : \"HDP\",\n" + " \"stack_name\" : \"HDP\",\n" + " \"stack_version\" : \"2.6\",\n" + " \"tags\" : [ ],\n" + " \"unique\" : false\n" + " }\n" + "}";
// CHECKSTYLE:ON
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionBaseOk.
@Test
public void compareImageAndInstancesMandatoryPackageVersionBaseOk() throws JsonProcessingException {
String packageName = "package";
Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
when(statedImage.getImage()).thenReturn(image);
when(image.isPrewarmed()).thenReturn(false);
when(image.getPackageVersions()).thenReturn(packageVersions);
Package aPackage = new Package();
aPackage.setName(packageName);
aPackage.setPrewarmed(false);
Package prewarmedPackage = new Package();
prewarmedPackage.setName(packageName);
prewarmedPackage.setPrewarmed(true);
when(instanceMetadataUpdater.getPackages()).thenReturn(Lists.newArrayList(aPackage, prewarmedPackage));
when(instanceMetadataUpdater.isPackagesVersionEqual(anyString(), anyString())).thenReturn(true);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
assertEquals(EventStatus.OK, result.getStatus());
}
Aggregations