Search in sources :

Example 16 with CheckResult

use of com.sequenceiq.cloudbreak.core.flow2.CheckResult in project zipkin-gcp by openzipkin.

the class StackdriverSpanConsumerTest method verifyCheckReturnsFailureWhenServiceFailsForUnknownReason.

@Test
public void verifyCheckReturnsFailureWhenServiceFailsForUnknownReason() {
    onClientCall(observer -> {
        observer.onError(new RuntimeException("oh no"));
    });
    CheckResult result = storage.check();
    assertThat(result.ok()).isFalse();
    assertThat(result.error()).isInstanceOf(ArmeriaStatusException.class).satisfies(e -> assertThat(((ArmeriaStatusException) e).getCode()).isEqualTo(Status.UNKNOWN.getCode().value()));
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) CheckResult(zipkin2.CheckResult) ArmeriaStatusException(com.linecorp.armeria.common.grpc.protocol.ArmeriaStatusException) Test(org.junit.Test)

Example 17 with CheckResult

use of com.sequenceiq.cloudbreak.core.flow2.CheckResult in project cloudbreak by hortonworks.

the class StackImageUpdateService method checkPackageVersions.

public CheckResult checkPackageVersions(Stack stack, StatedImage newImage) {
    Set<InstanceMetaData> instanceMetaDataSet = stack.getNotDeletedAndNotZombieInstanceMetaDataSet();
    CheckResult instanceHaveMultipleVersionResult = packageVersionChecker.checkInstancesHaveMultiplePackageVersions(instanceMetaDataSet);
    if (instanceHaveMultipleVersionResult.getStatus() == EventStatus.FAILED) {
        LOGGER.debug("Check packages - Instances do have multiple package versions: {}", instanceHaveMultipleVersionResult);
        return instanceHaveMultipleVersionResult;
    }
    CheckResult instancesHaveAllMandatoryPackageVersionResult = packageVersionChecker.checkInstancesHaveAllMandatoryPackageVersion(instanceMetaDataSet);
    if (instancesHaveAllMandatoryPackageVersionResult.getStatus() == EventStatus.FAILED) {
        LOGGER.debug("Check packages - Instances are missing one or more package versions: {}", instancesHaveAllMandatoryPackageVersionResult);
        return instancesHaveAllMandatoryPackageVersionResult;
    }
    CheckResult compareImageAndInstancesMandatoryPackageVersion = packageVersionChecker.compareImageAndInstancesMandatoryPackageVersion(newImage, instanceMetaDataSet);
    if (compareImageAndInstancesMandatoryPackageVersion.getStatus() == EventStatus.FAILED) {
        LOGGER.debug("Check packages - Image and instances mandatory packages do differ: {}", compareImageAndInstancesMandatoryPackageVersion);
        return compareImageAndInstancesMandatoryPackageVersion;
    }
    return CheckResult.ok();
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult)

Example 18 with CheckResult

use of com.sequenceiq.cloudbreak.core.flow2.CheckResult in project cloudbreak by hortonworks.

the class StackImageUpdateService method isValidImage.

public boolean isValidImage(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
    if (isCbVersionOk(stack)) {
        try {
            Image currentImage = stackImageService.getCurrentImage(stack);
            StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage);
            boolean cloudPlatformMatches = isCloudPlatformMatches(stack, newImage);
            boolean osVersionsMatch = isOsVersionsMatch(currentImage, newImage);
            boolean stackMatchIfPrewarmed = isStackMatchIfPrewarmed(newImage);
            CheckResult checkPackageVersionsStatus = checkPackageVersions(stack, newImage);
            boolean aggregatedValidationResult = cloudPlatformMatches && osVersionsMatch && stackMatchIfPrewarmed;
            if (!aggregatedValidationResult) {
                LOGGER.info("Image validation for {}:\n " + "Valid platform? {}\n " + "Valid os? {}\n " + "Valid stack (prewarmed only)? {}", newImageId, cloudPlatformMatches, osVersionsMatch, stackMatchIfPrewarmed);
            }
            if (checkPackageVersionsStatus.getStatus() != EventStatus.OK) {
                LOGGER.info("Image validation for {}:\n " + "Valid package versions? {}", newImageId, checkPackageVersionsStatus);
            }
            return aggregatedValidationResult;
        } catch (CloudbreakImageNotFoundException e) {
            LOGGER.debug("Cloudbreak Image not found", e);
            return false;
        } catch (CloudbreakImageCatalogException e) {
            LOGGER.debug("Cloudbreak Image catalog error", e);
            return false;
        }
    }
    return false;
}
Also used : CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 19 with CheckResult

use of com.sequenceiq.cloudbreak.core.flow2.CheckResult in project cloudbreak by hortonworks.

the class PackageVersionCheckerTest method checkInstancesHaveAllMandatoryPackageVersionNok.

@Test
public void checkInstancesHaveAllMandatoryPackageVersionNok() {
    when(instanceMetadataUpdater.collectInstancesWithMissingPackageVersions(anySet())).thenReturn(Collections.singletonMap("instance", Collections.singletonList("package")));
    CheckResult result = underTest.checkInstancesHaveAllMandatoryPackageVersion(Collections.emptySet());
    assertEquals(EventStatus.FAILED, result.getStatus());
}
Also used : CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) Test(org.junit.Test)

Example 20 with CheckResult

use of com.sequenceiq.cloudbreak.core.flow2.CheckResult in project cloudbreak by hortonworks.

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionPrewarmedOk.

@Test
public void compareImageAndInstancesMandatoryPackageVersionPrewarmedOk() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(packageVersions);
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    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

CheckResult (zipkin2.CheckResult)30 Test (org.junit.Test)24 CheckResult (com.sequenceiq.cloudbreak.core.flow2.CheckResult)12 Test (org.junit.jupiter.api.Test)7 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)5 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)4 Json (com.sequenceiq.cloudbreak.common.json.Json)4 Package (com.sequenceiq.cloudbreak.service.cluster.Package)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ElasticsearchStorage (zipkin2.elasticsearch.ElasticsearchStorage)4 Bean (org.springframework.context.annotation.Bean)3 Span (zipkin2.Span)3 ArmeriaStatusException (com.linecorp.armeria.common.grpc.protocol.ArmeriaStatusException)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Future (java.util.concurrent.Future)2