Search in sources :

Example 1 with CredentialVerificationException

use of com.sequenceiq.environment.credential.exception.CredentialVerificationException in project cloudbreak by hortonworks.

the class SearchCauseExceptionMapperTest method testGetResponseStatusWhenHasTwoDepthsCause.

@Test
public void testGetResponseStatusWhenHasTwoDepthsCause() {
    Response.Status actual = underTest.getResponseStatus(new CredentialVerificationException("", new RuntimeException(new NotFoundException())));
    Assertions.assertEquals(Response.Status.NOT_FOUND, actual);
}
Also used : Response(javax.ws.rs.core.Response) NotFoundException(javax.ws.rs.NotFoundException) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CredentialVerificationException

use of com.sequenceiq.environment.credential.exception.CredentialVerificationException in project cloudbreak by hortonworks.

the class SearchCauseExceptionMapperTest method testGetResponseStatusWhenTheCauseIsTheRealException.

@Test
public void testGetResponseStatusWhenTheCauseIsTheRealException() {
    Response.Status actual = underTest.getResponseStatus(new CredentialVerificationException("", new NotFoundException(new Exception())));
    Assertions.assertEquals(Response.Status.NOT_FOUND, actual);
}
Also used : Response(javax.ws.rs.core.Response) NotFoundException(javax.ws.rs.NotFoundException) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with CredentialVerificationException

use of com.sequenceiq.environment.credential.exception.CredentialVerificationException in project cloudbreak by hortonworks.

the class SearchCauseExceptionMapperTest method testGetResponseStatusWhenNoCause.

@Test
public void testGetResponseStatusWhenNoCause() {
    Response.Status actual = underTest.getResponseStatus(new CredentialVerificationException(""));
    Assertions.assertEquals(Response.Status.BAD_REQUEST, actual);
}
Also used : Response(javax.ws.rs.core.Response) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with CredentialVerificationException

use of com.sequenceiq.environment.credential.exception.CredentialVerificationException in project cloudbreak by hortonworks.

the class SearchCauseExceptionMapperTest method testGetResponseStatusWhenTheExceptionIsTheFirstCause.

@Test
public void testGetResponseStatusWhenTheExceptionIsTheFirstCause() {
    Response.Status actual = underTest.getResponseStatus(new CredentialVerificationException("", new Exception(new NotFoundException())));
    Assertions.assertEquals(Response.Status.NOT_FOUND, actual);
}
Also used : Response(javax.ws.rs.core.Response) NotFoundException(javax.ws.rs.NotFoundException) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with CredentialVerificationException

use of com.sequenceiq.environment.credential.exception.CredentialVerificationException in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapter method verify.

public CredentialVerification verify(Credential credential, String accountId, boolean creationVerification) {
    boolean changed = false;
    credential = credentialPrerequisiteService.decorateCredential(credential);
    CloudContext cloudContext = CloudContext.Builder.builder().withId(credential.getId()).withName(credential.getName()).withCrn(credential.getResourceCrn()).withPlatform(credential.getCloudPlatform()).withVariant(credential.getCloudPlatform()).withAccountId(accountId).build();
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    CredentialVerificationRequest request = requestProvider.getCredentialVerificationRequest(cloudContext, cloudCredential, creationVerification);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        CredentialVerificationResult res = request.await();
        String message = FAILED_CREDETIAL_VERIFICATION_MESSAGE;
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.info(message, res.getErrorDetails());
            throw new CredentialVerificationException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        CloudCredentialStatus cloudCredentialStatus = res.getCloudCredentialStatus();
        if (CredentialStatus.FAILED.equals(cloudCredentialStatus.getStatus())) {
            return new CredentialVerification(credential, setNewStatusText(credential, cloudCredentialStatus));
        }
        changed = setNewStatusText(credential, cloudCredentialStatus);
        CloudCredential cloudCredentialResponse = cloudCredentialStatus.getCloudCredential();
        if (cloudCredentialStatus.isDefaultRegionChanged()) {
            changed = mergeCloudProviderParameters(credential, cloudCredentialResponse, Collections.singleton(SMART_SENSE_ID));
        }
        changed = changed || mergeCloudProviderParameters(credential, cloudCredentialResponse, Collections.singleton(SMART_SENSE_ID));
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing credential verification", e);
        throw new OperationException(e);
    }
    return new CredentialVerification(credential, changed);
}
Also used : CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CredentialVerification(com.sequenceiq.environment.credential.verification.CredentialVerification) CredentialVerificationException(com.sequenceiq.environment.credential.exception.CredentialVerificationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Aggregations

CredentialVerificationException (com.sequenceiq.environment.credential.exception.CredentialVerificationException)8 Response (javax.ws.rs.core.Response)7 Test (org.junit.jupiter.api.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 NotFoundException (javax.ws.rs.NotFoundException)6 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CredentialVerificationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest)1 CredentialVerificationResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 CredentialVerification (com.sequenceiq.environment.credential.verification.CredentialVerification)1