Search in sources :

Example 1 with CertificatesRotationV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request in project cloudbreak by hortonworks.

the class SdxAutotlsCertRotationAction method action.

@Override
public SdxTestDto action(TestContext testContext, SdxTestDto testDto, SdxClient client) throws Exception {
    CertificatesRotationV4Request certificatesRotationV4Request = new CertificatesRotationV4Request();
    Log.when(LOGGER, " SDX endpoint: %s" + client.getDefaultClient().sdxEndpoint() + ", SDX's environment: " + testDto.getRequest().getEnvironment());
    Log.whenJson(LOGGER, " SDX autotls cert rotation request: ", certificatesRotationV4Request);
    FlowIdentifier flowIdentifier = client.getDefaultClient().sdxEndpoint().rotateAutoTlsCertificatesByName(testDto.getName(), new CertificatesRotationV4Request());
    testDto.setFlow("SDX autotls cert rotation", flowIdentifier);
    SdxClusterDetailResponse detailedResponse = client.getDefaultClient().sdxEndpoint().getDetail(testDto.getName(), Collections.emptySet());
    testDto.setResponse(detailedResponse);
    Log.whenJson(LOGGER, " SDX response after autotls cert rotation: ", detailedResponse);
    return testDto;
}
Also used : CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxClusterDetailResponse(com.sequenceiq.sdx.api.model.SdxClusterDetailResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 2 with CertificatesRotationV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request in project cloudbreak by hortonworks.

the class ClusterCommonServiceTest method testRotateAutoTlsCertificatesWithNodeFailure.

@Test
public void testRotateAutoTlsCertificatesWithNodeFailure() {
    NameOrCrn cluster = NameOrCrn.ofName("cluster");
    Stack stack = new Stack();
    stack.setName("cluster");
    stack.setStackStatus(new StackStatus(stack, NODE_FAILURE));
    when(stackService.getByNameOrCrnInWorkspace(cluster, 1L)).thenReturn(stack);
    CertificatesRotationV4Request certificatesRotationV4Request = new CertificatesRotationV4Request();
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.rotateAutoTlsCertificates(cluster, 1L, certificatesRotationV4Request));
    assertEquals("Stack 'cluster' is currently in 'NODE_FAILURE' state. Certificates rotation can only be made when the underlying stack is 'AVAILABLE'.", badRequestException.getMessage());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with CertificatesRotationV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request in project cloudbreak by hortonworks.

the class CertRotationServiceTest method testStartCertRotationWebAppEx.

@Test
public void testStartCertRotationWebAppEx() {
    CertificatesRotationV4Request request = new CertificatesRotationV4Request();
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setClusterName("testclustername");
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(sdxService.getById(1L)).thenReturn(sdxCluster);
    when(stackV4Endpoint.rotateAutoTlsCertificates(0L, sdxCluster.getClusterName(), TEST_USER_CRN, request)).thenThrow(new WebApplicationException("asdf"));
    assertThrows(RuntimeException.class, () -> ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.startCertRotation(1L, request)));
    verifyNoInteractions(cloudbreakFlowService);
    verifyNoInteractions(sdxStatusService);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Test(org.junit.jupiter.api.Test)

Example 4 with CertificatesRotationV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request in project cloudbreak by hortonworks.

the class CertRotationServiceTest method testStartCertRotation.

@Test
public void testStartCertRotation() {
    CertificatesRotationV4Request request = new CertificatesRotationV4Request();
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setClusterName("testclustername");
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(sdxService.getById(1L)).thenReturn(sdxCluster);
    CertificatesRotationV4Response response = new CertificatesRotationV4Response();
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, "pollid");
    response.setFlowIdentifier(flowIdentifier);
    when(stackV4Endpoint.rotateAutoTlsCertificates(0L, sdxCluster.getClusterName(), TEST_USER_CRN, request)).thenReturn(response);
    ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.startCertRotation(1L, request));
    verify(cloudbreakFlowService).saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    verify(sdxStatusService).setStatusForDatalakeAndNotify(DatalakeStatusEnum.CERT_ROTATION_IN_PROGRESS, "Datalake cert rotation in progress", sdxCluster);
}
Also used : CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) CertificatesRotationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 5 with CertificatesRotationV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request in project cloudbreak by hortonworks.

the class ClusterCommonServiceTest method testRotateAutoTls.

@Test
public void testRotateAutoTls() {
    NameOrCrn cluster = NameOrCrn.ofName("cluster");
    Stack stack = new Stack();
    stack.setName("cluster");
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    CertificatesRotationV4Request certificatesRotationV4Request = new CertificatesRotationV4Request();
    when(clusterOperationService.rotateAutoTlsCertificates(stack, certificatesRotationV4Request)).thenReturn(new FlowIdentifier(FlowType.FLOW, "1"));
    when(stackService.getByNameOrCrnInWorkspace(cluster, 1L)).thenReturn(stack);
    underTest.rotateAutoTlsCertificates(cluster, 1L, certificatesRotationV4Request);
    verify(clusterOperationService, times(1)).rotateAutoTlsCertificates(stack, certificatesRotationV4Request);
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)8 Test (org.junit.jupiter.api.Test)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 CertificatesRotationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response)3 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)1 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)1 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)1 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)1 UnhealthyInstances (com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances)1 SdxStartCertRotationEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent)1 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1