Search in sources :

Example 36 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class FlowUtil method waitForFlow.

private void waitForFlow(FlowPublicEndpoint flowEndpoint, String crn, String flowChainId, String flowId, RunningParameter runningParameter) {
    boolean flowRunning = true;
    boolean flowFailed = false;
    int retryCount = 0;
    int failureCount = 0;
    long pollingInterval = getPollingInterval();
    while (flowRunning && retryCount < maxRetry) {
        sleep(pollingInterval, crn, flowChainId, flowId);
        try {
            if (StringUtils.isNotBlank(flowChainId)) {
                LOGGER.info("Waiting for flow chain: '{}' at resource: '{}', retry count: '{}'", flowChainId, crn, retryCount);
                FlowCheckResponse flowCheckResponse = flowEndpoint.hasFlowRunningByChainId(flowChainId, crn);
                flowRunning = flowCheckResponse.getHasActiveFlow();
                flowFailed = flowCheckResponse.getLatestFlowFinalizedAndFailed();
            } else if (StringUtils.isNoneBlank(flowId)) {
                LOGGER.info("Waiting for flow: '{}' at resource: '{}', retry count: '{}'", flowId, crn, retryCount);
                FlowCheckResponse flowCheckResponse = flowEndpoint.hasFlowRunningByFlowId(flowId, crn);
                flowRunning = flowCheckResponse.getHasActiveFlow();
                flowFailed = flowCheckResponse.getLatestFlowFinalizedAndFailed();
            } else {
                LOGGER.info("Flow id and flow chain id are empty so flow is not running at resource: '{}'", crn);
                flowRunning = false;
            }
        } catch (Exception ex) {
            if (failureCount >= maxFailureRetry) {
                LOGGER.error("Error during polling flow. Crn={}, FlowId={}, FlowChainId={}, Message={}", crn, flowId, flowChainId, ex.getMessage(), ex);
                throw new TestFailException(String.format(" Error during polling flow. Crn=%s, FlowId=%s , FlowChainId=%s, Message=%s ", crn, flowId, flowChainId, ex.getMessage()));
            } else {
                LOGGER.info("Retrying after failure. Failure count {}", ++failureCount);
            }
        }
        retryCount++;
    }
    if (retryCount >= maxRetry) {
        String errorMessage = String.format("Test timed out, flow did not finish in time. Crn=%s, FlowId=%s, FlowChainId=%s", crn, flowId, flowChainId);
        LOGGER.error(errorMessage);
        throw new TestFailException(errorMessage);
    }
    if (flowFailed && runningParameter.isWaitForFlowSuccess()) {
        LOGGER.error("Flow has been finalized with failed status. Crn={}, FlowId={}, FlowChainId={}", crn, flowId, flowChainId);
        throw new TestFailException(String.format(" Flow has been finalized with failed status. Crn=%s, FlowId=%s , FlowChainId=%s ", crn, flowId, flowChainId));
    }
    if (!flowFailed && runningParameter.isWaitForFlowFail()) {
        LOGGER.error("Flow has been finalized with success status. Crn={}, FlowId={}, FlowChainId={}", crn, flowId, flowChainId);
        throw new TestFailException(String.format(" Flow has been finalized with success status but it was expected to fail. Crn=%s, FlowId=%s , FlowChainId=%s ", crn, flowId, flowChainId));
    }
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) FlowPublicEndpoint(com.sequenceiq.flow.api.FlowPublicEndpoint) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 37 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class InstanceFailedChecker method refresh.

@Override
public void refresh(T waitObject) {
    List<String> instanceIds = waitObject.getInstanceIds();
    try {
        waitObject.fetchData();
        failed = false;
    } catch (Exception e) {
        LOGGER.error("Failed to get instances: '{}', because of {}", instanceIds, e.getMessage(), e);
        throw new TestFailException(String.format("Failed to get instances status: '%s'", instanceIds), e);
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 38 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class FreeIpaFindGroupsAction method action.

public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
    CheckGroupsV1Request checkGroupsRequest = new CheckGroupsV1Request();
    checkGroupsRequest.setEnvironmentCrn(testDto.getResponse().getEnvironmentCrn());
    checkGroupsRequest.setGroups(groups);
    Log.when(LOGGER, format(" Checking groups [%s] are present at environment '%s'", groups, testDto.getResponse().getEnvironmentCrn()));
    Log.whenJson(LOGGER, format(" FreeIpa '%s' find groups request:%n ", testDto.getResponse().getCrn()), checkGroupsRequest);
    if (!client.getDefaultClient().getClientTestV1Endpoint().checkGroups(checkGroupsRequest).getResult()) {
        throw new TestFailException("Given freeipa groups cannot be found, please check FMS logs for details");
    }
    LOGGER.info(format(" Groups [%s] are present at environment '%s'", groups, testDto.getResponse().getEnvironmentCrn()));
    Log.when(LOGGER, format(" Groups [%s] are present at environment '%s'", groups, testDto.getResponse().getEnvironmentCrn()));
    return testDto;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CheckGroupsV1Request(com.sequenceiq.freeipa.api.v1.freeipa.test.model.CheckGroupsV1Request)

Example 39 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class FreeIpaFindUsersInGroupAction method action.

public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
    CheckUsersInGroupV1Request checkUsersInGroupRequest = new CheckUsersInGroupV1Request();
    checkUsersInGroupRequest.setEnvironmentCrn(testDto.getResponse().getEnvironmentCrn());
    checkUsersInGroupRequest.setGroup(group);
    checkUsersInGroupRequest.setUsers(users);
    Log.when(LOGGER, format(" Checking users [%s] are present in group '%s' at environment '%s'", users, group, testDto.getResponse().getEnvironmentCrn()));
    Log.whenJson(LOGGER, format(" FreeIpa '%s' find users in group request:%n ", testDto.getResponse().getCrn()), checkUsersInGroupRequest);
    if (expectedPresence) {
        if (!client.getDefaultClient().getClientTestV1Endpoint().checkUsersInGroup(checkUsersInGroupRequest).getResult()) {
            throw new TestFailException("Given freeipa users cannot be found in the given group, please check FMS logs for details");
        }
        LOGGER.info(format(" Users [%s] are present in group '%s' at environment '%s'", users, group, testDto.getResponse().getEnvironmentCrn()));
        Log.when(LOGGER, format(" Users [%s] are present in group '%s' at environment '%s'", users, group, testDto.getResponse().getEnvironmentCrn()));
    } else {
        if (client.getDefaultClient().getClientTestV1Endpoint().checkUsersInGroup(checkUsersInGroupRequest).getResult()) {
            throw new TestFailException("Given freeipa users have been found in the given group, please check FMS logs for details");
        }
        LOGGER.info(format(" Users [%s] have been removed successfully from group '%s' at environment '%s'", users, group, testDto.getResponse().getEnvironmentCrn()));
        Log.when(LOGGER, format(" Users [%s] have been removed successfully from group '%s' at environment '%s'", users, group, testDto.getResponse().getEnvironmentCrn()));
    }
    return testDto;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CheckUsersInGroupV1Request(com.sequenceiq.freeipa.api.v1.freeipa.test.model.CheckUsersInGroupV1Request)

Example 40 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class SdxImagesTests method testSDXWithBaseImageCanBeCreatedSuccessfully.

@Test(dataProvider = TEST_CONTEXT)
@UseSpotInstances
@Description(given = "there is a running Cloudbreak", when = "a valid SDX create request is sent (latest Base Image)", then = "SDX should be available AND deletable")
public void testSDXWithBaseImageCanBeCreatedSuccessfully(TestContext testContext) {
    String sdxInternal = resourcePropertyProvider().getName();
    String cluster = resourcePropertyProvider().getName();
    String clouderaManager = resourcePropertyProvider().getName();
    String imageSettings = resourcePropertyProvider().getName();
    String imageCatalog = resourcePropertyProvider().getName();
    String stack = resourcePropertyProvider().getName();
    String masterInstanceGroup = "master";
    String idbrokerInstanceGroup = "idbroker";
    AtomicReference<String> selectedImageID = new AtomicReference<>();
    SdxDatabaseRequest sdxDatabaseRequest = new SdxDatabaseRequest();
    sdxDatabaseRequest.setAvailabilityType(SdxDatabaseAvailabilityType.NONE);
    testContext.given(imageCatalog, ImageCatalogTestDto.class).when((tc, dto, client) -> {
        selectedImageID.set(testContext.getCloudProvider().getLatestBaseImageID(tc, dto, client));
        return dto;
    }).given(imageSettings, ImageSettingsTestDto.class).given(clouderaManager, ClouderaManagerTestDto.class).given(cluster, ClusterTestDto.class).withBlueprintName(getDefaultSDXBlueprintName()).withValidateBlueprint(Boolean.FALSE).withClouderaManager(clouderaManager).given(masterInstanceGroup, InstanceGroupTestDto.class).withHostGroup(MASTER).withNodeCount(1).given(idbrokerInstanceGroup, InstanceGroupTestDto.class).withHostGroup(IDBROKER).withNodeCount(1).given(stack, StackTestDto.class).withCluster(cluster).withImageSettings(imageSettings).withInstanceGroups(masterInstanceGroup, idbrokerInstanceGroup).given(sdxInternal, SdxInternalTestDto.class).withDatabase(sdxDatabaseRequest).withCloudStorage(getCloudStorageRequest(testContext)).withStackRequest(key(cluster), key(stack)).when(sdxTestClient.createInternal(), key(sdxInternal)).await(SdxClusterStatusResponse.RUNNING).awaitForHealthyInstances().then((tc, dto, client) -> {
        Log.log(LOGGER, format(" Image Catalog Name: %s ", dto.getResponse().getStackV4Response().getImage().getCatalogName()));
        Log.log(LOGGER, format(" Image Catalog URL: %s ", dto.getResponse().getStackV4Response().getImage().getCatalogUrl()));
        Log.log(LOGGER, format(" Image ID: %s ", dto.getResponse().getStackV4Response().getImage().getId()));
        if (!dto.getResponse().getStackV4Response().getImage().getId().equals(selectedImageID.get())) {
            throw new TestFailException(" The selected image ID is: " + dto.getResponse().getStackV4Response().getImage().getId() + " instead of: " + selectedImageID.get());
        }
        return dto;
    }).validate();
}
Also used : ClusterTestDto(com.sequenceiq.it.cloudbreak.dto.ClusterTestDto) SdxDatabaseAvailabilityType(com.sequenceiq.sdx.api.model.SdxDatabaseAvailabilityType) LoggerFactory(org.slf4j.LoggerFactory) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) InstanceGroupTestDto(com.sequenceiq.it.cloudbreak.dto.InstanceGroupTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StackTestDto(com.sequenceiq.it.cloudbreak.dto.stack.StackTestDto) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ClouderaManagerTestDto(com.sequenceiq.it.cloudbreak.dto.ClouderaManagerTestDto) MASTER(com.sequenceiq.it.cloudbreak.cloud.HostGroupType.MASTER) Log(com.sequenceiq.it.cloudbreak.log.Log) IDBROKER(com.sequenceiq.it.cloudbreak.cloud.HostGroupType.IDBROKER) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances) String.format(java.lang.String.format) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) ImageSettingsTestDto(com.sequenceiq.it.cloudbreak.dto.ImageSettingsTestDto) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClouderaManagerTestDto(com.sequenceiq.it.cloudbreak.dto.ClouderaManagerTestDto) InstanceGroupTestDto(com.sequenceiq.it.cloudbreak.dto.InstanceGroupTestDto) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances)

Aggregations

TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)101 List (java.util.List)15 Inject (javax.inject.Inject)14 Map (java.util.Map)13 Description (com.sequenceiq.it.cloudbreak.context.Description)12 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Test (org.testng.annotations.Test)12 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Log (com.sequenceiq.it.cloudbreak.log.Log)9 String.format (java.lang.String.format)9 Collectors (java.util.stream.Collectors)9 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)8 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)8 IOException (java.io.IOException)8 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8