Search in sources :

Example 51 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class DatabaseConfigServiceTest method testTestNewConnectionFails.

@Test
public void testTestNewConnectionFails() {
    DatabaseConfig newConfig = new DatabaseConfig();
    doAnswer((Answer) invocation -> {
        MapBindingResult errors = invocation.getArgument(1, MapBindingResult.class);
        errors.addError(new ObjectError("failed", ERROR_MESSAGE));
        return null;
    }).when(connectionValidator).validate(any(), any());
    String result = underTest.testConnection(newConfig);
    assertEquals(ERROR_MESSAGE, result);
    verify(connectionValidator).validate(eq(newConfig), any());
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TestData(com.sequenceiq.redbeams.TestData) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) MockitoAnnotations(org.mockito.MockitoAnnotations) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ObjectError(org.springframework.validation.ObjectError) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Is.is(org.hamcrest.core.Is.is) DriverFunctions(com.sequenceiq.redbeams.service.drivers.DriverFunctions) DatabaseVendor(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DatabaseVendor) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) DatabaseConnectionValidator(com.sequenceiq.redbeams.service.validation.DatabaseConnectionValidator) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) UUID(java.util.UUID) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) MapBindingResult(org.springframework.validation.MapBindingResult) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) DatabaseCommon(com.sequenceiq.cloudbreak.common.database.DatabaseCommon) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Mock(org.mockito.Mock) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) CrnTestUtil(com.sequenceiq.cloudbreak.auth.crn.CrnTestUtil) Mockito.lenient(org.mockito.Mockito.lenient) Supplier(java.util.function.Supplier) Every(org.hamcrest.core.Every) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Assert.assertTrue(org.junit.Assert.assertTrue) CrnService(com.sequenceiq.redbeams.service.crn.CrnService) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Mockito.verify(org.mockito.Mockito.verify) DatabaseConfigRepository(com.sequenceiq.redbeams.repository.DatabaseConfigRepository) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException) Collections(java.util.Collections) ResourceStatus(com.sequenceiq.redbeams.api.endpoint.v4.ResourceStatus) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectError(org.springframework.validation.ObjectError) MapBindingResult(org.springframework.validation.MapBindingResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.Test)

Example 52 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class DatabaseConfigServiceTest method testRegisterConnectionFailure.

@Test
public void testRegisterConnectionFailure() {
    thrown.expect(IllegalArgumentException.class);
    DatabaseConfig configToRegister = new DatabaseConfig();
    configToRegister.setConnectionDriver("org.postgresql.MyCustomDriver");
    doAnswer((Answer) invocation -> {
        MapBindingResult errors = invocation.getArgument(1, MapBindingResult.class);
        errors.addError(new ObjectError("failed", ERROR_MESSAGE));
        return null;
    }).when(connectionValidator).validate(any(), any());
    underTest.register(configToRegister, true);
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TestData(com.sequenceiq.redbeams.TestData) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) MockitoAnnotations(org.mockito.MockitoAnnotations) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ObjectError(org.springframework.validation.ObjectError) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Is.is(org.hamcrest.core.Is.is) DriverFunctions(com.sequenceiq.redbeams.service.drivers.DriverFunctions) DatabaseVendor(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DatabaseVendor) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) DatabaseConnectionValidator(com.sequenceiq.redbeams.service.validation.DatabaseConnectionValidator) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) UUID(java.util.UUID) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) MapBindingResult(org.springframework.validation.MapBindingResult) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) DatabaseCommon(com.sequenceiq.cloudbreak.common.database.DatabaseCommon) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Mock(org.mockito.Mock) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) CrnTestUtil(com.sequenceiq.cloudbreak.auth.crn.CrnTestUtil) Mockito.lenient(org.mockito.Mockito.lenient) Supplier(java.util.function.Supplier) Every(org.hamcrest.core.Every) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Assert.assertTrue(org.junit.Assert.assertTrue) CrnService(com.sequenceiq.redbeams.service.crn.CrnService) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Mockito.verify(org.mockito.Mockito.verify) DatabaseConfigRepository(com.sequenceiq.redbeams.repository.DatabaseConfigRepository) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException) Collections(java.util.Collections) ResourceStatus(com.sequenceiq.redbeams.api.endpoint.v4.ResourceStatus) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectError(org.springframework.validation.ObjectError) MapBindingResult(org.springframework.validation.MapBindingResult) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.Test)

Example 53 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class AwsSdxSpotInstanceTest method testSdxOnSpotInstances.

@Test(dataProvider = TEST_CONTEXT)
@Description(given = "there is a running cloudbreak ", when = "creating an SDX with 100% spot percentage ", then = "SDX is started on spot instances, or fails with insufficient spot capacity")
public void testSdxOnSpotInstances(TestContext testContext) {
    String sdx = resourcePropertyProvider().getName();
    SdxDatabaseRequest database = new SdxDatabaseRequest();
    database.setCreate(false);
    testContext.given(SdxTestDto.class).withCloudStorage().withExternalDatabase(database).withSpotPercentage(100).when(sdxTestClient.create(), key(sdx)).then((tc, testDto, client) -> {
        testDto.await(STACK_CREATED, key(sdx));
        Map<String, Exception> exceptionMap = testContext.getExceptionMap();
        if (!exceptionMap.isEmpty()) {
            String key = testDto.getAwaitExceptionKey(STACK_CREATED);
            if (exceptionMap.containsKey(key)) {
                LOGGER.info("Awaiting STACK_CREATED failed, clearing exception to check status reason", exceptionMap.get(key));
                exceptionMap.remove(key);
            }
        }
        return testDto;
    }).when(sdxTestClient.describe()).then(assertSpotInstances()).validate();
}
Also used : SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Test(org.testng.annotations.Test) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) Assertion(com.sequenceiq.it.cloudbreak.assertion.Assertion) Map(java.util.Map) SdxClient(com.sequenceiq.it.cloudbreak.SdxClient) InstanceLifeCycle(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) Map(java.util.Map) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)

Example 54 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method dnsLookups.

private void dnsLookups(SdxTestDto sdxTestDto, SdxClient sdxClient) {
    InstanceMetaDataV4Response instanceGroupMetadata = getInstanceGroups(sdxTestDto, sdxClient).stream().flatMap(instanceGroup -> instanceGroup.getMetadata().stream()).filter(metadata -> metadata.getInstanceGroup().equals("idbroker")).filter(metadata -> StringUtils.isNoneBlank(metadata.getDiscoveryFQDN(), metadata.getPrivateIp())).findFirst().orElseThrow(() -> new TestFailException("FreeIPA upgrade DNS lookups test failed, idbroker instance group was not found."));
    try {
        String cmd = String.format(CHECK_DNS_LOOKUPS_CMD, instanceGroupMetadata.getDiscoveryFQDN(), instanceGroupMetadata.getPrivateIp());
        Map<String, Pair<Integer, String>> results = sshJClientActions.executeSshCommandOnHost(getInstanceGroups(sdxTestDto, sdxClient), List.of(HostGroupType.MASTER.getName()), cmd, false);
        results.values().forEach(result -> Assertions.assertEquals(0, result.getLeft()));
    } catch (Exception e) {
        logger.error("FreeIPA upgrade DNS lookups test failed with unexpected error", e);
        throw new TestFailException("FreeIPA upgrade DNS lookups test failed with unexpected error: " + e.getMessage(), e);
    }
}
Also used : SdxDatabaseAvailabilityType(com.sequenceiq.sdx.api.model.SdxDatabaseAvailabilityType) AddDnsZoneForSubnetsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) StringUtils(org.apache.commons.lang3.StringUtils) Description(com.sequenceiq.it.cloudbreak.context.Description) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) RUNNING(com.sequenceiq.freeipa.api.v1.operation.model.OperationState.RUNNING) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) List(java.util.List) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) ServiceKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest) SshJClientActions(com.sequenceiq.it.cloudbreak.util.ssh.action.SshJClientActions) AbsolutTimeBasedTimeoutChecker(com.sequenceiq.cloudbreak.polling.AbsolutTimeBasedTimeoutChecker) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) TelemetryTestDto(com.sequenceiq.it.cloudbreak.dto.telemetry.TelemetryTestDto) HostKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest) FreeIpaOperationStatusTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaOperationStatusTestDto) RunningParameter.waitForFlow(com.sequenceiq.it.cloudbreak.context.RunningParameter.waitForFlow) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) Inject(javax.inject.Inject) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) SynchronizationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus) COMPLETED(com.sequenceiq.freeipa.api.v1.operation.model.OperationState.COMPLETED) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) Assertions(org.junit.jupiter.api.Assertions) SdxClient(com.sequenceiq.it.cloudbreak.SdxClient) Collections(java.util.Collections) HostGroupType(com.sequenceiq.it.cloudbreak.cloud.HostGroupType) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 55 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class SdxUpgradeRecoveryService method validateRecovery.

public SdxRecoverableResponse validateRecovery(SdxCluster sdxCluster) {
    MDCBuilder.buildMdcContext(sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        RecoveryValidationV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.getClusterRecoverableByNameInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn));
        return new SdxRecoverableResponse(response.getReason(), response.getStatus());
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack recovery validation failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 List (java.util.List)19 Set (java.util.Set)18 Inject (javax.inject.Inject)18 Optional (java.util.Optional)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Map (java.util.Map)16 Collectors (java.util.stream.Collectors)15 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)14 HashSet (java.util.HashSet)13 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)9 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)9 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)8 VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)8 ResourceAttributeUtil (com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil)8 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8