Search in sources :

Example 6 with CertificatesRotationV4Request

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

the class ClusterCommonServiceTest method testRotateAutoTlsCertificatesWithStoppedInstances.

@Test
public void testRotateAutoTlsCertificatesWithStoppedInstances() {
    NameOrCrn cluster = NameOrCrn.ofName("cluster");
    Stack stack = new Stack();
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    when(instanceMetaDataService.anyInstanceStopped(any())).thenReturn(true);
    when(stackService.getByNameOrCrnInWorkspace(cluster, 1L)).thenReturn(stack);
    CertificatesRotationV4Request certificatesRotationV4Request = new CertificatesRotationV4Request();
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.rotateAutoTlsCertificates(cluster, 1L, certificatesRotationV4Request));
    assertEquals("Please start all stopped instances. Certificates rotation can only be made when all your nodes in running state.", 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 7 with CertificatesRotationV4Request

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

the class CertRotationServiceTest method testFlowTrigger.

@Test
public void testFlowTrigger() {
    SdxCluster cluster = new SdxCluster();
    cluster.setId(1L);
    cluster.setClusterName("testclustername");
    CertificatesRotationV4Request request = new CertificatesRotationV4Request();
    ArgumentCaptor<SdxStartCertRotationEvent> eventArgumentCaptor = ArgumentCaptor.forClass(SdxStartCertRotationEvent.class);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, "pollid");
    when(flowManager.triggerCertRotation(eventArgumentCaptor.capture(), anyString())).thenReturn(flowIdentifier);
    FlowIdentifier result = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.rotateAutoTlsCertificates(cluster, request));
    assertEquals(flowIdentifier, result);
    SdxStartCertRotationEvent event = eventArgumentCaptor.getValue();
    assertEquals(request, event.getRequest());
    assertEquals(1L, event.getResourceId());
    assertEquals(TEST_USER_CRN, event.getUserId());
}
Also used : SdxStartCertRotationEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 8 with CertificatesRotationV4Request

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

the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.

@Test
public void shouldReturnTheNextFailureTransition() {
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustment.setScalingAdjustment(5);
    instanceGroupAdjustment.setInstanceGroup("hostgroup");
    HostGroupAdjustmentV4Request hostGroupAdjustment = new HostGroupAdjustmentV4Request();
    hostGroupAdjustment.setHostGroup("hostgroup");
    hostGroupAdjustment.setScalingAdjustment(5);
    Map<String, Set<Long>> instanceIdsByHostgroup = new HashMap<>();
    instanceIdsByHostgroup.put("hostgroup", Collections.singleton(1L));
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, "imageid");
    when(stackService.getPlatformVariantByStackId(STACK_ID)).thenReturn(cloudPlatformVariant);
    when(cloudPlatformVariant.getVariant()).thenReturn(Variant.variant("AWS"));
    underTest.triggerProvisioning(STACK_ID);
    underTest.triggerClusterInstall(STACK_ID);
    underTest.triggerClusterReInstall(STACK_ID);
    underTest.triggerStackStop(STACK_ID);
    underTest.triggerStackStart(STACK_ID);
    underTest.triggerClusterStop(STACK_ID);
    underTest.triggerClusterStart(STACK_ID);
    underTest.triggerTermination(STACK_ID);
    underTest.triggerStackUpscale(STACK_ID, instanceGroupAdjustment, true);
    underTest.triggerStackDownscale(STACK_ID, instanceGroupAdjustment);
    underTest.triggerStackRemoveInstance(STACK_ID, "hostgroup", 5L);
    underTest.triggerStackRemoveInstance(STACK_ID, "hostgroup", 5L, false);
    underTest.triggerStackRemoveInstances(STACK_ID, instanceIdsByHostgroup, false);
    underTest.triggerClusterUpscale(STACK_ID, hostGroupAdjustment);
    underTest.triggerClusterDownscale(STACK_ID, hostGroupAdjustment);
    underTest.triggerClusterSync(STACK_ID);
    underTest.triggerClusterSyncWithoutCheck(STACK_ID);
    underTest.triggerStackSync(STACK_ID);
    underTest.triggerFullSync(STACK_ID);
    underTest.triggerFullSyncWithoutCheck(STACK_ID);
    underTest.triggerClusterCredentialReplace(STACK_ID, "admin", "admin1");
    underTest.triggerClusterCredentialUpdate(STACK_ID, "admin1");
    underTest.triggerClusterTermination(stack, false, USER_CRN);
    underTest.triggerClusterTermination(stack, true, USER_CRN);
    underTest.triggerManualRepairFlow(STACK_ID);
    underTest.triggerStackRepairFlow(STACK_ID, new UnhealthyInstances());
    underTest.triggerClusterRepairFlow(STACK_ID, new HashMap<>(), false);
    underTest.triggerClusterRepairFlow(STACK_ID, new HashMap<>(), true, false);
    underTest.triggerStackImageUpdate(new ImageChangeDto(STACK_ID, "asdf"));
    underTest.triggerMaintenanceModeValidationFlow(STACK_ID);
    underTest.triggerClusterCertificationRenewal(STACK_ID);
    underTest.triggerDatalakeClusterUpgrade(STACK_ID, "asdf");
    underTest.triggerDistroXUpgrade(STACK_ID, imageChangeDto, false, false, "variant");
    underTest.triggerSaltUpdate(STACK_ID);
    underTest.triggerPillarConfigurationUpdate(STACK_ID);
    underTest.triggerDatalakeDatabaseBackup(STACK_ID, null, null, true);
    underTest.triggerDatalakeDatabaseRestore(STACK_ID, null, null);
    underTest.triggerAutoTlsCertificatesRotation(STACK_ID, new CertificatesRotationV4Request());
    underTest.triggerStackLoadBalancerUpdate(STACK_ID);
    underTest.triggerSyncComponentVersionsFromCm(STACK_ID, Set.of());
    underTest.triggerDatalakeClusterRecovery(STACK_ID);
    underTest.triggerStopStartStackUpscale(STACK_ID, instanceGroupAdjustment, true);
    underTest.triggerStopStartStackDownscale(STACK_ID, instanceIdsByHostgroup, false);
    underTest.triggerClusterServicesRestart(STACK_ID);
    underTest.triggerClusterProxyConfigReRegistration(STACK_ID);
    int count = 0;
    for (Method method : underTest.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("trigger")) {
            count++;
        }
    }
    // -3: 2 notifyWithoutCheck, 1 terminationTriggerService, 1 triggerStackRemoveInstance internal
    verify(reactorNotifier, times(count - 3)).notify(anyLong(), anyString(), any(Acceptable.class));
    verify(reactorNotifier, times(2)).notifyWithoutCheck(anyLong(), anyString(), any(Acceptable.class));
    verify(terminationTriggerService, times(1)).triggerTermination(stack, true);
    verify(terminationTriggerService, times(1)).triggerTermination(stack, false);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) UnhealthyInstances(com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Method(java.lang.reflect.Method) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Example 9 with CertificatesRotationV4Request

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

the class CertRotationService method startCertRotation.

public void startCertRotation(Long id, CertificatesRotationV4Request request) {
    SdxCluster sdxCluster = sdxService.getById(id);
    String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
    try {
        CertificatesRotationV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.rotateAutoTlsCertificates(0L, sdxCluster.getClusterName(), initiatorUserCrn, request));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, response.getFlowIdentifier());
        updateCertExpirationState(sdxCluster);
        sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.CERT_ROTATION_IN_PROGRESS, "Datalake cert rotation in progress", sdxCluster);
    } catch (WebApplicationException e) {
        String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
        LOGGER.error("Couldn't start certiificate rotation in CB: {}", errorMessage, e);
        throw new RuntimeException(errorMessage, e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) CertificatesRotationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response)

Example 10 with CertificatesRotationV4Request

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

the class ClusterCommonService method rotateAutoTlsCertificates.

public CertificatesRotationV4Response rotateAutoTlsCertificates(NameOrCrn nameOrCrn, Long workspaceId, CertificatesRotationV4Request certificatesRotationV4Request) {
    Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
    MDCBuilder.buildMdcContext(stack);
    validateOperationOnStack(stack, "Certificates rotation");
    return new CertificatesRotationV4Response(clusterOperationService.rotateAutoTlsCertificates(stack, certificatesRotationV4Request));
}
Also used : CertificatesRotationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

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