Search in sources :

Example 21 with NameOrCrn

use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn 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)

Example 22 with NameOrCrn

use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn 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 23 with NameOrCrn

use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn in project cloudbreak by hortonworks.

the class StackCommonService method putScalingInWorkspace.

public FlowIdentifier putScalingInWorkspace(NameOrCrn nameOrCrn, Long workspaceId, StackScaleV4Request stackScaleV4Request) {
    User user = userService.getOrCreate(restRequestThreadLocalService.getCloudbreakUser());
    Stack stack;
    try {
        stack = transactionService.required(() -> {
            Stack stackInTransaction = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
            validateNetworkScaleRequest(stackInTransaction, stackScaleV4Request.getStackNetworkScaleV4Request());
            return stackInTransaction;
        });
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.error("Cannot validate network scaling: {}", e.getMessage(), e);
        throw new TransactionService.TransactionRuntimeExecutionException(e);
    }
    MDCBuilder.buildMdcContext(stack);
    stackScaleV4Request.setStackId(stack.getId());
    UpdateStackV4Request updateStackJson = stackScaleV4RequestToUpdateStackV4RequestConverter.convert(stackScaleV4Request);
    Integer scalingAdjustment = updateStackJson.getInstanceGroupAdjustment().getScalingAdjustment();
    validateScalingRequest(stack, scalingAdjustment);
    FlowIdentifier flowIdentifier;
    if (scalingAdjustment > 0) {
        flowIdentifier = put(stack, updateStackJson);
    } else {
        UpdateClusterV4Request updateClusterJson = stackScaleV4RequestToUpdateClusterV4RequestConverter.convert(stackScaleV4Request);
        workspaceService.get(workspaceId, user);
        flowIdentifier = clusterCommonService.put(stack.getResourceCrn(), updateClusterJson);
    }
    return flowIdentifier;
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 24 with NameOrCrn

use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn in project cloudbreak by hortonworks.

the class StackCommonService method syncInWorkspace.

public FlowIdentifier syncInWorkspace(NameOrCrn nameOrCrn, Long workspaceId) {
    Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
    MDCBuilder.buildMdcContext(stack);
    UpdateStackV4Request updateStackJson = new UpdateStackV4Request();
    updateStackJson.setStatus(StatusRequest.FULL_SYNC);
    updateStackJson.setWithClusterEvent(true);
    return put(stack, updateStackJson);
}
Also used : UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 25 with NameOrCrn

use of com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn 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

NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)11 Test (org.junit.Test)8 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)7 Test (org.junit.jupiter.api.Test)6 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 UpdateStackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request)3 CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)3 InternalUpgradeSettings (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings)3 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)3 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)3 InternalOnly (com.sequenceiq.authorization.annotation.InternalOnly)2 UpdateClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)2 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)2 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)1