org.springframework.statemachine.StateContext Java Examples
The following examples show how to use
org.springframework.statemachine.StateContext.
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: AbstractAction.java From cloudbreak with Apache License 2.0 | 6 votes |
private void executeAction(StateContext<S, E> context, P payload, C flowContext, Map<Object, Object> variables, String flowStateName) throws Exception { Object flowStartTime = variables.get(FLOW_START_TIME); if (flowStartTime != null) { Object execTime = variables.get(FLOW_START_EXEC_TIME); long flowElapsed = (System.currentTimeMillis() - (long) flowStartTime) / MS_PER_SEC; long execElapsed = (System.currentTimeMillis() - (long) execTime) / MS_PER_SEC; long executionTime = Math.max(execElapsed, flowElapsed); LOGGER.debug("Stack: {}, flow state: {}, phase: {}, execution time {} sec", payload.getResourceId(), flowStateName, execElapsed > flowElapsed ? "doExec" : "service", executionTime); metricService.submit(FlowMetricType.FLOW_STEP, executionTime, Map.of("name", flowStateName.toLowerCase())); } variables.put(FLOW_STATE_NAME, context.getStateMachine().getState().getId()); variables.put(FLOW_START_EXEC_TIME, System.currentTimeMillis()); doExecute(flowContext, payload, variables); variables.put(FLOW_START_TIME, System.currentTimeMillis()); }
Example #2
Source File: AbstractRedbeamsStartAction.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected RedbeamsStartContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStartState, RedbeamsStartEvent> stateContext, P payload) { DBStack dbStack = dbStackService.getById(payload.getResourceId()); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); CloudContext cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); CloudCredential cloudCredential = credentialConverter.convert(credential); DatabaseStack databaseStack = databaseStackConverter.convert(dbStack); return new RedbeamsStartContext(flowParameters, cloudContext, cloudCredential, databaseStack); }
Example #3
Source File: UpgradeCheckTargetAppsAction.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@Override protected void executeInternal(StateContext<SkipperStates, SkipperEvents> context) { super.executeInternal(context); ReleaseAnalysisReport releaseAnalysisReport = getReleaseAnalysisReport(context); int upgradeStatus = 0; // TODO: should check both releases String kind = ManifestUtils.resolveKind(releaseAnalysisReport.getReplacingRelease().getManifest().getData()); UpgradeStrategy upgradeStrategy = this.upgradeStrategyFactory.getUpgradeStrategy(kind); boolean ok = upgradeStrategy.checkStatus(releaseAnalysisReport.getReplacingRelease()); log.debug("upgradeStrategy checkStatus {}", ok); if (ok) { upgradeStatus = 1; } else if (!ok && cutOffTimeExceed(context)) { upgradeStatus = -1; } log.debug("Setting upgradeStatus {}", upgradeStatus); context.getExtendedState().getVariables().put(SkipperVariables.UPGRADE_STATUS, upgradeStatus); }
Example #4
Source File: AbstractInstanceTerminationAction.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected InstanceTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<InstanceTerminationState, InstanceTerminationEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId()); stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId()))); MDCBuilder.buildMdcContext(stack); Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getPlatformVariant(), location, stack.getCreator().getUserId(), stack.getWorkspace().getId()); CloudCredential cloudCredential = stackUtil.getCloudCredential(stack); Set<String> instanceIds = payload.getInstanceIds(); CloudStack cloudStack = cloudStackConverter.convert(stack, instanceIds); List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources()); List<InstanceMetaData> instanceMetaDataList = new ArrayList<>(); List<CloudInstance> cloudInstances = new ArrayList<>(); for (String instanceId : instanceIds) { InstanceMetaData instanceMetaData = instanceMetaDataService.findByStackIdAndInstanceId(stack.getId(), instanceId) .orElseThrow(NotFoundException.notFound("instanceMetadata", instanceId)); CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData); instanceMetaDataList.add(instanceMetaData); cloudInstances.add(cloudInstance); } return new InstanceTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList); }
Example #5
Source File: AbstractRedbeamsStopAction.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected RedbeamsStopContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStopState, RedbeamsStopEvent> stateContext, P payload) { DBStack dbStack = dbStackService.getById(payload.getResourceId()); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); CloudContext cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); CloudCredential cloudCredential = credentialConverter.convert(credential); DatabaseStack databaseStack = databaseStackConverter.convert(dbStack); return new RedbeamsStopContext(flowParameters, cloudContext, cloudCredential, databaseStack); }
Example #6
Source File: AbstractRedbeamsTerminationAction.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) { Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId()); CloudContext cloudContext = null; CloudCredential cloudCredential = null; DatabaseStack databaseStack = null; DBStack dbStack = null; if (optionalDBStack.isPresent()) { dbStack = optionalDBStack.get(); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String userName = dbStack.getOwnerCrn().getUserId(); String accountId = dbStack.getOwnerCrn().getAccountId(); cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, userName, accountId); Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); cloudCredential = credentialConverter.convert(credential); databaseStack = databaseStackConverter.convert(dbStack); } return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); }
Example #7
Source File: AbstractStackDownscaleAction.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected StackScalingFlowContext createFlowContext(FlowParameters flowParameters, StateContext<StackDownscaleState, StackDownscaleEvent> stateContext, P payload) { Map<Object, Object> variables = stateContext.getExtendedState().getVariables(); Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId()); stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId()))); MDCBuilder.buildMdcContext(stack); Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getPlatformVariant(), location, stack.getCreator().getUserId(), stack.getWorkspace().getId()); CloudCredential cloudCredential = stackUtil.getCloudCredential(stack); String instanceGroupName = extractInstanceGroupName(payload, variables); Set<String> instanceIds = extractInstanceIds(payload, variables, stack); Integer adjustment = extractAdjustment(payload, variables); CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds); return new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, instanceGroupName, instanceIds, adjustment); }
Example #8
Source File: AbstractExternalDatabaseTerminationAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected ExternalDatabaseContext createFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseTerminationState, ExternalDatabaseTerminationEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithClusterInTransaction(payload.getResourceId()); MDCBuilder.buildMdcContext(stack); beforeReturnFlowContext(flowParameters, stateContext, payload); return new ExternalDatabaseContext(flowParameters, stack); }
Example #9
Source File: AbstractAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<S, E> context) { FlowParameters flowParameters = (FlowParameters) context.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name()); ThreadBasedUserCrnProvider.doAs(flowParameters.getFlowTriggerUserCrn(), () -> { MDCBuilder.addFlowId(flowParameters.getFlowId()); P payload = convertPayload(context.getMessageHeader(MessageFactory.HEADERS.DATA.name())); C flowContext = null; try { Map<Object, Object> variables = context.getExtendedState().getVariables(); prepareExecution(payload, variables); String flowStateName = String.valueOf(variables.get(FLOW_STATE_NAME)); Span activeSpan = tracer.activeSpan(); String operationName = context.getEvent().name(); SpanContext spanContext = flowParameters.getSpanContext(); if (TracingUtil.isActiveSpanReusable(activeSpan, spanContext, operationName)) { LOGGER.debug("Reusing existing span. {}", activeSpan.context()); flowContext = createFlowContext(flowParameters, context, payload); executeAction(context, payload, flowContext, variables, flowStateName); } else { Span span = TracingUtil.getSpan(tracer, operationName, spanContext, flowParameters.getFlowId(), null, flowParameters.getFlowTriggerUserCrn()); spanContext = TracingUtil.useOrCreateSpanContext(spanContext, span); flowParameters.setSpanContext(spanContext); try (Scope ignored = tracer.activateSpan(span)) { flowContext = createFlowContext(flowParameters, context, payload); executeAction(context, payload, flowContext, variables, flowStateName); } finally { span.finish(); } } } catch (Exception ex) { LOGGER.error("Error during execution of " + getClass().getName(), ex); if (failureEvent != null) { sendEvent(flowParameters, failureEvent.event(), getFailurePayload(payload, Optional.ofNullable(flowContext), ex), Map.of()); } else { LOGGER.error("Missing error handling for " + getClass().getName()); } } }); }
Example #10
Source File: AbstractExternalDatabaseCreationAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected ExternalDatabaseContext createFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithClusterInTransaction(payload.getResourceId()); MDCBuilder.buildMdcContext(stack); beforeReturnFlowContext(flowParameters, stateContext, payload); return new ExternalDatabaseContext(flowParameters, stack); }
Example #11
Source File: AbstractStackStartAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackStartContext createFlowContext(FlowParameters flowParameters, StateContext<StackStartState, StackStartEvent> stateContext, P payload) { Long stackId = payload.getResourceId(); Stack stack = stackService.getByIdWithListsInTransaction(stackId); MDCBuilder.buildMdcContext(stack); List<InstanceMetaData> instances = stack.getNotDeletedInstanceMetaDataList(); Location location = location(region(stack.getRegion())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.getCloudPlatform(), stack.getCloudPlatform(), location, stack.getOwner(), stack.getAccountId()); Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn()); CloudCredential cloudCredential = credentialConverter.convert(credential); return new StackStartContext(flowParameters, stack, instances, cloudContext, cloudCredential); }
Example #12
Source File: AbstractStackFailureAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackFailureContext createFlowContext(FlowParameters flowParameters, StateContext<S, E> stateContext, StackFailureEvent payload) { Flow flow = getFlow(flowParameters.getFlowId()); Stack stack = stackService.getStackById(payload.getResourceId()); MDCBuilder.buildMdcContext(stack); flow.setFlowFailed(payload.getException()); return new StackFailureContext(flowParameters, stack); }
Example #13
Source File: AbstractStackTerminationAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId()); MDCBuilder.buildMdcContext(stack); Location location = location(region(stack.getRegion())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.getCloudPlatform(), stack.getCloudPlatform(), location, stack.getOwner(), stack.getAccountId()); Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn()); CloudCredential cloudCredential = credentialConverter.convert(credential); CloudStack cloudStack = cloudStackConverter.convert(stack); List<Resource> resourceList = resourceService.findAllByStackId(stack.getId()); List<CloudResource> resources = resourceConverter.convert(resourceList); return new StackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources); }
Example #14
Source File: StackTerminationFailureAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackFailureContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, StackFailureEvent payload) { Flow flow = getFlow(flowParameters.getFlowId()); StackView stackView = stackService.getViewByIdWithoutAuth(payload.getResourceId()); MDCBuilder.buildMdcContext(stackView); flow.setFlowFailed(payload.getException()); return new StackFailureContext(flowParameters, stackView); }
Example #15
Source File: AbstractDownscaleAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<DownscaleState, DownscaleFlowEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId()); MDCBuilder.buildMdcContext(stack); Location location = location(region(stack.getRegion())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.getCloudPlatform(), stack.getCloudPlatform(), location, stack.getOwner(), stack.getOwner(), stack.getAccountId()); CloudCredential cloudCredential = credentialConverter.convert(credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn())); CloudStack cloudStack = cloudStackConverter.convert(stack); return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack); }
Example #16
Source File: ManualStackRepairTriggerActions.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackRepairTriggerContext createFlowContext( FlowParameters flowParameters, StateContext<ManualStackRepairTriggerState, ManualStackRepairTriggerEvent> stateContext, P payload) { Long stackId = payload.getResourceId(); Stack stack = stackService.getByIdWithListsInTransaction(stackId); stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId()))); return new StackRepairTriggerContext(flowParameters, stack); }
Example #17
Source File: AbstractActionTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void testExecute() { stateMachine.sendEvent(new GenericMessage<>(Event.DOIT, Collections.singletonMap(FlowConstants.FLOW_PARAMETERS, FLOW_PARAMETERS))); verify(underTest, times(1)).createFlowContext(eq(FLOW_PARAMETERS), any(StateContext.class), nullable(Payload.class)); verify(underTest, times(1)).doExecute(any(CommonContext.class), nullable(Payload.class), any(Map.class)); verify(underTest, times(0)).sendEvent(any(CommonContext.class)); verify(underTest, times(0)).sendEvent(eq(FLOW_PARAMETERS), anyString(), any(), any(Map.class)); verify(underTest, times(0)).sendEvent(eq(FLOW_PARAMETERS), anyString(), any(Selectable.class), any(Map.class)); verify(underTest, times(0)).getFailurePayload(any(Payload.class), any(Optional.class), any(RuntimeException.class)); }
Example #18
Source File: AbstractActionTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void testFailedExecute() { RuntimeException exception = new UnsupportedOperationException(""); Mockito.doThrow(exception).when(underTest).doExecute(any(CommonContext.class), nullable(Payload.class), any()); stateMachine.sendEvent(new GenericMessage<>(Event.DOIT, Collections.singletonMap(FlowConstants.FLOW_PARAMETERS, FLOW_PARAMETERS))); verify(underTest, times(1)).createFlowContext(eq(FLOW_PARAMETERS), any(StateContext.class), nullable(Payload.class)); verify(underTest, times(1)).doExecute(any(CommonContext.class), nullable(Payload.class), any(Map.class)); verify(underTest, times(1)).getFailurePayload(nullable(Payload.class), any(Optional.class), eq(exception)); verify(underTest, times(1)).sendEvent(eq(FLOW_PARAMETERS), eq(Event.FAILURE.name()), eq(Collections.emptyMap()), any(Map.class)); }
Example #19
Source File: AbstractDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<String, String> context) { Resource artifact = (Resource) context.getMessageHeader(HEADER_ARTIFACT); String artifactDir = (String) context.getMessageHeader(HEADER_ARTIFACT_DIR); if (!isHdfsResource(artifact)) { yarnCloudAppService.pushArtifact(artifact, artifactDir); } else { if (!artifact.exists()) { context.getExtendedState().getVariables().put(VAR_ERROR, new RuntimeException("hdfs artifact missing")); } } }
Example #20
Source File: AbstractStackProvisionAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<StackProvisionState, StackProvisionEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId()); MDCBuilder.buildMdcContext(stack); Location location = location(region(stack.getRegion())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.getCloudPlatform(), stack.getCloudPlatform(), location, stack.getOwner(), stack.getOwner(), stack.getAccountId()); CloudCredential cloudCredential = credentialConverter.convert(credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn())); CloudStack cloudStack = cloudStackConverter.convert(stack); return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack); }
Example #21
Source File: StartDatabaseServerFailedAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected RedbeamsStartContext createFlowContext( FlowParameters flowParameters, StateContext<RedbeamsStartState, RedbeamsStartEvent> stateContext, RedbeamsFailureEvent payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); return super.createFlowContext(flowParameters, stateContext, payload); }
Example #22
Source File: StopDatabaseServerFailedAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected RedbeamsStopContext createFlowContext( FlowParameters flowParameters, StateContext<RedbeamsStopState, RedbeamsStopEvent> stateContext, RedbeamsFailureEvent payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); return super.createFlowContext(flowParameters, stateContext, payload); }
Example #23
Source File: AbstractRedbeamsProvisionAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsProvisionState, RedbeamsProvisionEvent> stateContext, P payload) { DBStack dbStack = dbStackService.getById(payload.getResourceId()); MDCBuilder.buildMdcContext(dbStack); Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone())); String accountId = dbStack.getOwnerCrn().getAccountId(); CloudContext cloudContext = new CloudContext(dbStack.getId(), dbStack.getName(), dbStack.getCloudPlatform(), dbStack.getPlatformVariant(), location, dbStack.getOwnerCrn().getUserId(), dbStack.getUserName(), accountId); Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId()); CloudCredential cloudCredential = credentialConverter.convert(credential); DatabaseStack databaseStack = databaseStackConverter.convert(dbStack); return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack); }
Example #24
Source File: AppDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<String, String> context) { Integer count = context.getMessageHeaders().get(HEADER_COUNT, Integer.class); String clusterId = context.getMessageHeaders().get(HEADER_CLUSTER_ID, String.class); Map<?, ?> definitionParameters = context.getMessageHeaders().get(HEADER_DEFINITION_PARAMETERS, Map.class); Resource artifact = context.getMessageHeaders().get(HEADER_ARTIFACT, Resource.class); context.getExtendedState().getVariables().put(VAR_COUNT, count != null ? count : 1); context.getExtendedState().getVariables().put(VAR_CLUSTER_ID, clusterId); context.getExtendedState().getVariables().put(VAR_DEFINITION_PARAMETERS, definitionParameters); if (artifact != null) { context.getExtendedState().getVariables().put(VAR_ARTIFACT, artifact); } context.getExtendedState().getVariables().put(VAR_MESSAGE_ID, context.getMessageHeaders().getId().toString()); }
Example #25
Source File: AppDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void execute(StateContext<String, String> context) { Resource artifact = context.getExtendedState().get(VAR_ARTIFACT, Resource.class); getYarnCloudAppService().createCluster( context.getExtendedState().get(VAR_APPLICATION_ID, String.class), context.getExtendedState().get(HEADER_CLUSTER_ID, String.class), context.getExtendedState().get(VAR_COUNT, Integer.class), artifact != null ? artifact.getFilename() : null, context.getExtendedState().get(HEADER_DEFINITION_PARAMETERS, Map.class)); }
Example #26
Source File: AppDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<String, String> context) { String appVersion = (String) context.getMessageHeader(HEADER_APP_VERSION); String groupId = (String) context.getMessageHeader(HEADER_GROUP_ID); if (StringUtils.hasText(appVersion) && StringUtils.hasText(groupId)) { String appName = "scdstream:" + appVersion + ":" + groupId; context.getExtendedState().getVariables().put(VAR_APPNAME, appName); } }
Example #27
Source File: AppDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<String, String> context) { String appVersion = (String) context.getMessageHeader(HEADER_APP_VERSION); // we control type so casting is safe @SuppressWarnings("unchecked") List<String> contextRunArgs = (List<String>) context.getMessageHeader(HEADER_CONTEXT_RUN_ARGS); String applicationId = getYarnCloudAppService().submitApplication(appVersion, CloudAppType.STREAM, contextRunArgs); context.getExtendedState().getVariables().put(VAR_APPLICATION_ID, applicationId); }
Example #28
Source File: AppDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<String, String> context) { String appVersion = (String) context.getMessageHeader(HEADER_APP_VERSION); String groupId = (String) context.getMessageHeader(HEADER_GROUP_ID); String appName = "scdstream:" + appVersion + ":" + groupId; CloudAppInstanceInfo appInstanceInfo = findRunningInstance(appName); if (appInstanceInfo != null) { context.getExtendedState().getVariables().put(VAR_APPLICATION_ID, appInstanceInfo.getApplicationId()); } }
Example #29
Source File: AbstractMaintenanceModeValidationAction.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<MaintenanceModeValidationState, MaintenanceModeValidationEvent> stateContext, P payload) { Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId()); stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId()))); MDCBuilder.buildMdcContext(stack); Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone())); CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getPlatformVariant(), location, stack.getCreator().getUserId(), stack.getWorkspace().getId()); CloudCredential cloudCredential = stackUtil.getCloudCredential(stack); CloudStack cloudStack = cloudStackConverter.convert(stack); return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack); }
Example #30
Source File: AppDeployerStateMachine.java From spring-cloud-deployer-yarn with Apache License 2.0 | 5 votes |
@Override public void execute(StateContext<String, String> context) { String appName = context.getExtendedState().get(VAR_APPNAME, String.class); String applicationId = context.getExtendedState().get(VAR_APPLICATION_ID, String.class); CloudAppInstanceInfo appInstanceInfo = findRunningInstance(appName); if (appInstanceInfo != null && appInstanceInfo.getApplicationId().equals(applicationId)) { context.getExtendedState().getVariables().put(VAR_INSTANCE_ADDRESS, appInstanceInfo.getAddress()); } }