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());
}
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());
}
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);
}
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);
}
}
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));
}
Aggregations