Search in sources :

Example 26 with StatedImage

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);
    }
}
Also used : ImageStackDetails(com.sequenceiq.cloudbreak.cloud.model.catalog.ImageStackDetails) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image)

Example 27 with StatedImage

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;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) HashMap(java.util.HashMap) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 28 with StatedImage

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;
}
Also used : ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 29 with StatedImage

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
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Before(org.junit.Before)

Example 30 with StatedImage

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());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Aggregations

StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)48 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 Test (org.junit.Test)12 Image (com.sequenceiq.cloudbreak.cloud.model.Image)11 Test (org.junit.jupiter.api.Test)10 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)9 Json (com.sequenceiq.cloudbreak.common.json.Json)7 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)7 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)7 CheckResult (com.sequenceiq.cloudbreak.core.flow2.CheckResult)6 Map (java.util.Map)6 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CloudbreakDetails (com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)3