reactor.bus.Event Java Examples
The following examples show how to use
reactor.bus.Event.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmbariInstallComponentsHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<ClusterManagerInstallComponentsRequest> event) { ClusterManagerInstallComponentsRequest request = event.getData(); Long stackId = request.getResourceId(); ClusterManagerInstallComponentsResult result; try { clusterUpscaleService.installComponents(stackId, request.getComponents(), request.getHostName()); result = new ClusterManagerInstallComponentsResult(request); } catch (Exception e) { String message = "Failed to install components on new host"; LOGGER.error(message, e); result = new ClusterManagerInstallComponentsResult(message, e, request); } eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }
Example #2
Source File: EventBusConfig.java From cloudbreak with Apache License 2.0 | 6 votes |
private String getFlowIdFromHeaders(Throwable throwable) { try { if (throwable.getCause() instanceof Exceptions.ValueCause) { if (((Exceptions.ValueCause) throwable.getCause()).getValue() instanceof Event) { Event event = (Event) ((Exceptions.ValueCause) throwable.getCause()).getValue(); LOGGER.info("Failed event: {}", event); Event.Headers headers = event.getHeaders(); if (headers != null) { LOGGER.info("Failed event headers: {}", headers); if (headers.get("FLOW_ID") != null) { return headers.get("FLOW_ID").toString(); } } else { LOGGER.info("Headers is null object for the event {}", event); } } } } catch (Exception e) { LOGGER.error("Something wrong happened when we tried to get flowId from headers", e); } return null; }
Example #3
Source File: FreeIpaCreationHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
private void createFreeIpa(Event<EnvironmentDto> environmentDtoEvent, EnvironmentDto environmentDto) throws Exception { Optional<DescribeFreeIpaResponse> freeIpa = freeIpaService.describe(environmentDto.getResourceCrn()); if (freeIpa.isEmpty()) { LOGGER.info("FreeIpa for environmentCrn '{}' was not found, creating a new one.", environmentDto.getResourceCrn()); CreateFreeIpaRequest createFreeIpaRequest = createFreeIpaRequest(environmentDto); freeIpaService.create(createFreeIpaRequest); awaitFreeIpaCreation(environmentDtoEvent, environmentDto); AddDnsZoneForSubnetIdsRequest addDnsZoneForSubnetIdsRequest = addDnsZoneForSubnetIdsRequest(environmentDto); if (shouldSendSubnetIdsToFreeIpa(addDnsZoneForSubnetIdsRequest)) { dnsV1Endpoint.addDnsZoneForSubnetIds(addDnsZoneForSubnetIdsRequest); } } else { LOGGER.info("FreeIpa for environmentCrn '{}' already exists. Using this one.", environmentDto.getResourceCrn()); if (CREATE_IN_PROGRESS == freeIpa.get().getStatus()) { awaitFreeIpaCreation(environmentDtoEvent, environmentDto); } } }
Example #4
Source File: ClusterCredentialChangeHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<ClusterCredentialChangeRequest> event) { ClusterCredentialChangeRequest request = event.getData(); ClusterCredentialChangeResult result; try { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); ClusterSecurityService clusterSecurityService = clusterApiConnectors.getConnector(stack).clusterSecurityService(); switch (request.getType()) { case REPLACE: clusterSecurityService.replaceUserNamePassword(request.getUser(), request.getPassword()); break; case UPDATE: clusterSecurityService.updateUserNamePassword(request.getPassword()); break; default: throw new UnsupportedOperationException("Ambari credential update request not supported: " + request.getType()); } result = new ClusterCredentialChangeResult(request); } catch (Exception e) { result = new ClusterCredentialChangeResult(e.getMessage(), e, request); } eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }
Example #5
Source File: EnvironmentValidationHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateEnvironment(Event<EnvironmentDto> environmentDtoEvent, EnvironmentDto environmentDto, Environment environment) { RegionWrapper regionWrapper = environment.getRegionWrapper(); CloudRegions cloudRegions = environmentService.getRegionsByEnvironment(environment); ValidationResult.ValidationResultBuilder validationBuilder = validatorService .validateRegionsAndLocation(regionWrapper.getName(), regionWrapper.getRegions(), environment, cloudRegions); validationBuilder.merge(validatorService.validateTelemetryLoggingStorageLocation(environment)); validationBuilder.merge(validatorService.validateParameters(environmentDto, environmentDto.getParameters())); validationBuilder.merge(validatorService.validateNetworkWithProvider(environmentDto)); validationBuilder.merge(validatorService.validateAuthentication(environmentDto)); ValidationResult validationResult = validationBuilder.build(); if (validationResult.hasError()) { goToFailedState(environmentDtoEvent, validationResult.getFormattedErrors()); } else { goToNetworkCreationState(environmentDtoEvent, environmentDto); } }
Example #6
Source File: GetPlatformOrchestratorsHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<GetPlatformOrchestratorsRequest> getPlatformOrchestratorsRequest) { LOGGER.debug("Received event: {}", getPlatformOrchestratorsRequest); GetPlatformOrchestratorsRequest request = getPlatformOrchestratorsRequest.getData(); try { Map<Platform, Collection<Orchestrator>> platformCollectionHashMap = Maps.newHashMap(); Map<Platform, Orchestrator> defaults = Maps.newHashMap(); for (Entry<Platform, Collection<Variant>> connector : cloudPlatformConnectors.getPlatformVariants().getPlatformToVariants().entrySet()) { PlatformOrchestrator platformOrchestrator = cloudPlatformConnectors.getDefault(connector.getKey()).parameters().orchestratorParams(); platformCollectionHashMap.put(connector.getKey(), platformOrchestrator.types()); defaults.put(connector.getKey(), platformOrchestrator.defaultType()); } GetPlatformOrchestratorsResult getPlatformOrchestratorsResult = new GetPlatformOrchestratorsResult(request.getResourceId(), new PlatformOrchestrators(platformCollectionHashMap, defaults)); request.getResult().onNext(getPlatformOrchestratorsResult); LOGGER.debug("Query platform orchestrators types finished."); } catch (RuntimeException e) { request.getResult().onNext(new GetPlatformOrchestratorsResult(e.getMessage(), e, request.getResourceId())); } }
Example #7
Source File: UnhealthyInstancesDetectionHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<UnhealthyInstancesDetectionRequest> event) { UnhealthyInstancesDetectionRequest request = event.getData(); UnhealthyInstancesDetectionResult result; Long stackId = request.getResourceId(); Stack stack = stackService.getByIdWithTransaction(stackId); try { Set<InstanceMetaData> candidateUnhealthyInstances = unhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId()); if (candidateUnhealthyInstances.isEmpty()) { result = new UnhealthyInstancesDetectionResult(request, Collections.emptySet()); } else { Set<String> unhealthyInstances = unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, candidateUnhealthyInstances); result = new UnhealthyInstancesDetectionResult(request, unhealthyInstances); } } catch (RuntimeException e) { String msg = String.format("Could not get statuses for unhealty instances: %s", e.getMessage()); LOG.info(msg, e); result = new UnhealthyInstancesDetectionResult(msg, e, request); } eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }
Example #8
Source File: StackImageUpdateActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void checkImageVersion() { FlowEvent flowEvent = Mockito.mock(FlowEvent.class); when(stateContext.getEvent()).thenReturn(flowEvent); when(flowEvent.name()).thenReturn(EVENT_NAME); StackImageUpdateTriggerEvent payload = new StackImageUpdateTriggerEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), 1L, "imageId"); when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload); when(state.getId()).thenReturn(StackImageUpdateState.CHECK_IMAGE_VERSIONS_STATE); when(stackImageUpdateService.isCbVersionOk(any(Stack.class))).thenReturn(true); checkImageAction.execute(stateContext); verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.UPDATE_IN_PROGRESS.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_STARTED)); verify(stackImageUpdateService, times(1)).getNewImageIfVersionsMatch(any(Stack.class), anyString(), eq(null), eq(null)); verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event()), any(Event.class)); }
Example #9
Source File: ResourcePersistenceHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<ResourceNotification> event) { LOGGER.debug("Resource notification event received: {}", event); ResourceNotification notification = event.getData(); RetryUtil.withDefaultRetries() .retry(() -> { ResourceNotification notificationPersisted; switch (notification.getType()) { case CREATE: notificationPersisted = cloudResourcePersisterService.persist(notification); break; case UPDATE: notificationPersisted = cloudResourcePersisterService.update(notification); break; case DELETE: notificationPersisted = cloudResourcePersisterService.delete(notification); break; default: throw new IllegalArgumentException("Unsupported notification type: " + notification.getType()); } notificationPersisted.getPromise().onNext(new ResourcePersisted()); }) .checkIfRecoverable(e -> e instanceof TransientDataAccessException) .ifNotRecoverable(e -> notification.getPromise().onError(e)).run(); }
Example #10
Source File: StackPreTerminationHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<StackPreTerminationRequest> requestEvent) { StackPreTerminationRequest request = requestEvent.getData(); Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); try { Cluster cluster = stack.getCluster(); if (cluster != null) { Set<Recipe> recipesByCluster = hostGroupService.getRecipesByCluster(cluster.getId()); telemetryAgentService.stopTelemetryAgent(stack); recipeEngine.executePreTerminationRecipes(stack, recipesByCluster, request.getForced()); preTerminationStateExecutor.runPreteraminationTasks(stack); } } catch (Exception ex) { LOGGER.info("Pre-termination failed: {}", ex.getMessage(), ex); } Selectable result = new StackPreTerminationSuccess(stack.getId()); eventBus.notify(result.selector(), new Event<>(requestEvent.getHeaders(), result)); }
Example #11
Source File: SelectionHandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void testAcceptSuccess() { Stack stack = mock(Stack.class); Optional<String> formerPgw = Optional.of(INSTANCE_ID_1); List<String> instanceIds = List.of(INSTANCE_ID_1); ChangePrimaryGatewaySelectionRequest request = new ChangePrimaryGatewaySelectionRequest(STACK_ID, instanceIds); when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack); when(changePrimaryGatewayService.getPrimaryGatewayInstanceId(any())).thenReturn(formerPgw); when(changePrimaryGatewayService.selectNewPrimaryGatewayInstanceId(any(), any())).thenReturn(INSTANCE_ID_2); underTest.accept(new Event<>(request)); verify(stackService).getByIdWithListsInTransaction(eq(STACK_ID)); verify(changePrimaryGatewayService).getPrimaryGatewayInstanceId(eq(stack)); verify(changePrimaryGatewayService).selectNewPrimaryGatewayInstanceId(eq(stack), eq(instanceIds)); verify(eventBus).notify(eq(EventSelectorUtil.selector(ChangePrimaryGatewaySelectionSuccess.class)), any(Event.class)); }
Example #12
Source File: PrerequisitesCreationHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresentOrElse(environment -> { try { if (AZURE.name().equals(environmentDto.getCloudPlatform())) { createResourceGroup(environmentDto, environment); } else { LOGGER.debug("Cloudplatform not Azure, not creating resource group."); } goToNetworkCreationState(environmentDtoEvent); } catch (Exception e) { goToFailedState(environmentDtoEvent, e.getMessage()); } }, () -> goToFailedState(environmentDtoEvent, String.format("Environment was not found with id '%s'.", environmentDto.getId())) ); }
Example #13
Source File: StackCreationHandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void acceptTest() { long stackId = 2L; StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId); Event receivedEvent = new Event<>(stackCreationWaitRequest); doNothing().when(provisionerService).waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class)); stackCreationHandler.accept(receivedEvent); verify(provisionerService, times(1)).waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class)); final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class); final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class); verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture()); String eventNotified = eventSelector.getValue(); Event event = sentEvent.getValue(); Assertions.assertEquals("StackCreationSuccessEvent", eventNotified); Assertions.assertEquals(StackCreationSuccessEvent.class, event.getData().getClass()); Assertions.assertEquals(stackId, ((StackCreationSuccessEvent) event.getData()).getResourceId()); verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(STACK_CREATION_FINISHED, "Datalake stack created", (Long) stackId); }
Example #14
Source File: ExceptionCatcherEventHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<T> event) { String handlerName = getClass().getSimpleName(); try { HandlerEvent handlerEvent = new HandlerEvent(event); doAccept(handlerEvent); if (handlerEvent.getCounter() < 1) { LOGGER.error("No event has been sent from {}", handlerName); IllegalStateException noEventHasBeenSentException = new IllegalStateException("No event has been sent from " + handlerName); eventBus.notify(defaultFailureEvent(event.getData().getResourceId(), noEventHasBeenSentException).selector(), new Event<>(event.getHeaders(), event)); } } catch (Exception e) { LOGGER.error("Something unexpected happened in handler {}", handlerName, e); eventBus.notify(defaultFailureEvent(event.getData().getResourceId(), e).selector(), new Event<>(event.getHeaders(), event)); } }
Example #15
Source File: ClusterCertificateReissueHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<ClusterCertificateReissueRequest> event) { ClusterCertificateReissueRequest data = event.getData(); Long stackId = data.getResourceId(); LOGGER.debug("Reissue certificate for stack 'id:{}'", stackId); Selectable response; try { boolean certReissued = reissueCertificate(stackId); if (certReissued) { LOGGER.info("Certificate of the cluster has been reissued successfully."); response = new ClusterCertificateReissueSuccess(stackId); } else { String message = "The certificate of the cluster could not be reissued via PEM service."; LOGGER.warn(message); response = new ClusterCertificateRenewFailed(stackId, new IllegalStateException(message)); } } catch (Exception ex) { LOGGER.warn("Reissue of certificate has been failed for cluster", ex); response = new ClusterCertificateRenewFailed(stackId, ex); } eventBus.notify(response.selector(), new Event<>(event.getHeaders(), response)); }
Example #16
Source File: FreeIpaDeletionHandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void shouldNotCallFreeIpaServiceIfFreeIpaCreationIsDisabled() { EnvironmentDto environmentDto = new EnvironmentDto(); environmentDto.setId(CHILD_ENVIRONMENT_ID); EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto .builder() .withEnvironmentDto(environmentDto) .withForceDelete(true) .withId(CHILD_ENVIRONMENT_ID) .build(); when(environmentService.findEnvironmentById(CHILD_ENVIRONMENT_ID)).thenReturn(of(anEnvironmentWithoutParent(Boolean.FALSE))); victim.accept(new Event<>(environmentDeletionDto)); verify(freeIpaService, never()).delete(ENVIRONMENT_CRN); verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Event.Headers.class)); }
Example #17
Source File: PrerequisitesCreationHandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void testWhenResourceGroupDtoCreateNew() { Event<EnvironmentDto> event = getEnvironmentDtoEvent( AzureResourceGroupDto.builder() .withResourceGroupUsagePattern(ResourceGroupUsagePattern.USE_SINGLE) .withResourceGroupCreation(ResourceGroupCreation.CREATE_NEW) .build() ); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(getEnvironment())); when(entitlementService.azureSingleResourceGroupDeploymentEnabled(anyString(), anyString())).thenReturn(true); ArgumentCaptor<BaseNamedFlowEvent> envCreationEventArgumentCaptor = ArgumentCaptor.forClass(BaseNamedFlowEvent.class); ArgumentCaptor<EnvironmentPrerequisitesCreateRequest> environmentPrerequisitesCreateRequestArgumentCaptor = ArgumentCaptor.forClass(EnvironmentPrerequisitesCreateRequest.class); when(costTagging.mergeTags(any())).thenReturn(Map.of()); prepareCloudConnectorSetup(); underTest.accept(event); verify(eventBus, never()).notify(anyString(), any(Event.class)); verify(entitlementService).azureSingleResourceGroupDeploymentEnabled(anyString(), anyString()); verifyNextFlowStepIsInvoked(envCreationEventArgumentCaptor); verifyResourceGroupCreateIsInvoked(environmentPrerequisitesCreateRequestArgumentCaptor); verify(clock).getCurrentTimeMillis(); verify(parameterService).updateResourceGroupName(any(), anyString()); verify(setup).createEnvironmentPrerequisites(any()); }
Example #18
Source File: GetPlatformGatewaysHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<GetPlatformCloudGatewaysRequest> getPlatformCloudGatewaysRequest) { LOGGER.debug("Received event: {}", getPlatformCloudGatewaysRequest); GetPlatformCloudGatewaysRequest request = getPlatformCloudGatewaysRequest.getData(); try { CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant( Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant())); CloudGateWays cloudGateWays = cloudPlatformConnectors.get(cloudPlatformVariant) .platformResources().gateways(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters()); GetPlatformCloudGatewaysResult getPlatformCloudGatewaysResult = new GetPlatformCloudGatewaysResult(request.getResourceId(), cloudGateWays); request.getResult().onNext(getPlatformCloudGatewaysResult); LOGGER.debug("Query platform gateway types finished."); } catch (Exception e) { request.getResult().onNext(new GetPlatformCloudGatewaysResult(e.getMessage(), e, request.getResourceId())); } }
Example #19
Source File: StopStackHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<StopInstancesRequest> event) { LOGGER.debug("Received event: {}", event); StopInstancesRequest<StopInstancesResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<?> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); List<CloudInstance> instances = request.getCloudInstances(); AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); List<CloudVmInstanceStatus> cloudVmInstanceStatuses = connector.instances().stop(authenticatedContext, request.getResources(), instances); InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, cloudVmInstanceStatuses); StopInstancesResult result = new StopInstancesResult(request.getResourceId(), statusResult); request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); } catch (Exception e) { StopInstancesResult failure = new StopInstancesResult("Failed to stop stack", e, request.getResourceId()); request.getResult().onNext(failure); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }
Example #20
Source File: GetPlatformInstanceGroupParametersHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<GetPlatformInstanceGroupParameterRequest> getPlatformInstanceGroupParameterRequestEvent) { LOGGER.debug("Received event: {}", getPlatformInstanceGroupParameterRequestEvent); GetPlatformInstanceGroupParameterRequest request = getPlatformInstanceGroupParameterRequestEvent.getData(); try { CloudPlatformVariant variant = new CloudPlatformVariant(platform(request.getExtendedCloudCredential().getCloudPlatform()), variant(request.getVariant())); Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponses = cloudPlatformConnectors.get(variant) .parameters().collectInstanceGroupParameters(request.getInstanceGroupParameterRequest()); GetPlatformInstanceGroupParameterResult getPlatformInstanceGroupParameterResult = new GetPlatformInstanceGroupParameterResult(request.getResourceId(), instanceGroupParameterResponses); request.getResult().onNext(getPlatformInstanceGroupParameterResult); LOGGER.debug("Query platform instance group parameters finished."); } catch (Exception e) { request.getResult().onNext(new GetPlatformInstanceGroupParameterResult(e.getMessage(), e, request.getResourceId())); } }
Example #21
Source File: UpdateImageHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<UpdateImageRequest> event) { LOGGER.debug("Received event: {}", event); UpdateImageRequest<UpdateImageResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<?> connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant()); AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); CloudStack stack = request.getCloudStack(); List<CloudResource> cloudResources = request.getCloudResources(); cloudResources.stream().filter(resource -> resource.getType().getCommonResourceType() == CommonResourceType.TEMPLATE) .forEach(resource -> resource.putParameter(CloudResource.IMAGE, stack.getImage().getImageName())); connector.resources().update(auth, stack, cloudResources); UpdateImageResult result = new UpdateImageResult(request.getResourceId()); request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); LOGGER.debug("Update image finished for {}", cloudContext); } catch (Exception e) { UpdateImageResult failure = new UpdateImageResult(e.getMessage(), e, request.getResourceId()); request.getResult().onNext(failure); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }
Example #22
Source File: Flow2HandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testFlowCanNotBeSaved() { BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig); given(flowConfig.createFlow(anyString(), anyLong())).willReturn(flow); given(flowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition); given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(true); given(flow.getCurrentState()).willReturn(flowState); Event<Payload> event = new Event<>(payload); event.setKey("KEY"); when(flowLogService.save(any(FlowParameters.class), nullable(String.class), anyString(), any(Payload.class), any(), eq(flowConfig.getClass()), eq(flowState))).thenThrow(new RuntimeException("Can't save flow log")); underTest.accept(event); verify(flowConfigurationMap, times(1)).get(anyString()); verify(runningFlows, times(1)).put(eq(flow), isNull(String.class)); verify(flowLogService, times(1)) .save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(), eq(flowConfig.getClass()), eq(flowState)); verify(runningFlows, times(1)).remove(anyString()); verify(flow, times(0)).sendEvent(anyString(), isNull(), any(), any()); }
Example #23
Source File: GetPlatformVmTypesHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<GetPlatformVmTypesRequest> getPlatformVmTypesRequest) { LOGGER.debug("Received event: {}", getPlatformVmTypesRequest); GetPlatformVmTypesRequest request = getPlatformVmTypesRequest.getData(); try { CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant( Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant())); PlatformResources platformResources = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources(); CloudVmTypes platformVirtualMachinesJson; if (CdpResourceType.DATAHUB.equals(request.getCdpResourceType())) { platformVirtualMachinesJson = platformResources .virtualMachinesForDistroX(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters()); } else { platformVirtualMachinesJson = platformResources .virtualMachines(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters()); } GetPlatformVmTypesResult getPlatformSecurityGroupsResult = new GetPlatformVmTypesResult(request.getResourceId(), platformVirtualMachinesJson); request.getResult().onNext(getPlatformSecurityGroupsResult); LOGGER.debug("Query platform vmtypes types finished."); } catch (Exception e) { request.getResult().onNext(new GetPlatformVmTypesResult(e.getMessage(), e, request.getResourceId())); } }
Example #24
Source File: StopFreeIpaHandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testWhenFreeIpaDescribeTellsFreeIpaIsNotStoppableThenExceptionComesAndNoStopEventHappens() { String envCrn = "someCrnValue"; EnvironmentDto environmentDto = createEnvironmentDto(); environmentDto.setResourceCrn(envCrn); Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto); when(mockDescribeFreeIpaResponse.getStatus()).thenReturn(Status.DELETED_ON_PROVIDER_SIDE); when(freeIpaService.describe(envCrn)).thenReturn(Optional.of(mockDescribeFreeIpaResponse)); underTest.accept(environmentDtoEvent); verify(freeIpaService, times(1)).describe(any()); verify(freeIpaService, times(1)).describe(envCrn); verify(eventSender, times(1)).sendEvent(any(), any()); verify(eventSender, times(1)).sendEvent(any(EnvStopFailedEvent.class), eq(environmentDtoEvent.getHeaders())); }
Example #25
Source File: ClusterCertificateRedeployHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<ClusterCertificateRedeployRequest> event) { ClusterCertificateRedeployRequest data = event.getData(); Long stackId = data.getResourceId(); LOGGER.debug("Redeploy certificate for stack 'id:{}'", stackId); Selectable response; try { clusterServiceRunner.updateSaltState(stackId); LOGGER.info("Certificate of the cluster has been redeployed successfully."); response = new ClusterCertificateRedeploySuccess(stackId); } catch (Exception ex) { LOGGER.warn("Redeploy of certificate has been failed for cluster", ex); response = new ClusterCertificateRenewFailed(stackId, ex); } eventBus.notify(response.selector(), new Event<>(event.getHeaders(), response)); }
Example #26
Source File: ProvisionValidationHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<ValidationRequest> event) { LOGGER.debug("Received event: {}", event); ValidationRequest request = event.getData(); CloudContext cloudContext = request.getCloudContext(); ValidationResult result; try { CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential()); CloudStack cloudStack = request.getCloudStack(); for (Validator v : connector.validators()) { v.validate(ac, cloudStack); } result = new ValidationResult(request.getResourceId()); } catch (RuntimeException e) { result = new ValidationResult(e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }
Example #27
Source File: CollectDownscaleCandidatesHandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void downScaleForcedForced() { //given Stack stack = generateStackData(); Event<CollectDownscaleCandidatesRequest> event = generateTestDataEvent(Collections.singleton(PRIVATE_ID), new ClusterDownscaleDetails(true, false)); when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack); //when testedClass.accept(event); //then ArgumentCaptor<Event<CollectDownscaleCandidatesResult>> capturedEvent = ArgumentCaptor.forClass(Event.class); verify(eventBus).notify((Object) any(), capturedEvent.capture()); Event<CollectDownscaleCandidatesResult> submittedEvent = capturedEvent.getValue(); CollectDownscaleCandidatesResult submittedResult = submittedEvent.getData(); assertNotNull(submittedResult); assertTrue(submittedResult.getRequest().getDetails().isForced()); }
Example #28
Source File: UploadRecipesHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<UploadRecipesRequest> event) { UploadRecipesRequest request = event.getData(); Selectable result; Long stackId = request.getResourceId(); try { Stack stack = stackService.getByIdWithListsInTransaction(stackId); stack.setResources(resourceService.getNotInstanceRelatedByStackId(stackId)); Set<HostGroup> hostGroups = hostGroupService.getByClusterWithRecipes(stack.getCluster().getId()); recipeEngine.uploadRecipes(stack, hostGroups); result = new UploadRecipesSuccess(stackId); } catch (Exception e) { LOGGER.info("Failed to upload recipes", e); result = new UploadRecipesFailed(stackId, e); } eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }
Example #29
Source File: GetTlsInfoHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<GetTlsInfoRequest> getTlsInfoRequestEvent) { LOGGER.debug("Received event: {}", getTlsInfoRequestEvent); GetTlsInfoRequest<?> tlsInfoRequest = getTlsInfoRequestEvent.getData(); try { CloudContext cloudContext = tlsInfoRequest.getCloudContext(); CloudCredential cloudCredential = tlsInfoRequest.getCloudCredential(); CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); CloudStack cloudStack = tlsInfoRequest.getCloudStack(); AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential); TlsInfo tlsInfo = connector.resources().getTlsInfo(ac, cloudStack); GetTlsInfoResult getTlsInfoResult = new GetTlsInfoResult(tlsInfoRequest.getResourceId(), tlsInfo); tlsInfoRequest.getResult().onNext(getTlsInfoResult); eventBus.notify(getTlsInfoResult.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), getTlsInfoResult)); LOGGER.debug("GetTlsInfoHandler finished."); } catch (RuntimeException e) { String errorMsg = "Failed to get TlS info from cloud connector!"; LOGGER.warn(errorMsg, e); GetTlsInfoResult failure = new GetTlsInfoResult(errorMsg, e, tlsInfoRequest.getResourceId()); tlsInfoRequest.getResult().onNext(failure); eventBus.notify(failure.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), failure)); } }
Example #30
Source File: StopDatahubHandler.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { datahubPollerService.stopAttachedDatahubClusters(environmentDto.getId(), environmentDto.getResourceCrn()); EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent() .withSelector(EnvStopStateSelectors.ENV_STOP_DATALAKE_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_DATAHUB_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } }