本文整理匯總了Java中org.springframework.statemachine.StateContext類的典型用法代碼示例。如果您正苦於以下問題:Java StateContext類的具體用法?Java StateContext怎麽用?Java StateContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StateContext類屬於org.springframework.statemachine包,在下文中一共展示了StateContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeInternal
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected void executeInternal(StateContext<SkipperStates, SkipperEvents> context) {
ReleaseAnalysisReport releaseAnalysisReport = context.getExtendedState().get(SkipperVariables.RELEASE_ANALYSIS_REPORT,
ReleaseAnalysisReport.class);
int upgradeStatus = 0;
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);
}
示例2: createFlowContext
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected InstanceTerminationContext createFlowContext(String flowId, StateContext<InstanceTerminationState, InstanceTerminationEvent> stateContext,
P payload) {
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(),
location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
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 = instanceMetaDataRepository.findByInstanceId(stack.getId(), instanceId);
CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData);
instanceMetaDataList.add(instanceMetaData);
cloudInstances.add(cloudInstance);
}
return new InstanceTerminationContext(flowId, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList);
}
示例3: createFlowContext
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected StackSyncContext createFlowContext(String flowId, StateContext<StackSyncState, StackSyncEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
Long stackId = payload.getStackId();
Stack stack = stackService.getByIdWithLists(stackId);
MDCBuilder.buildMdcContext(stack);
// we need a find all in stack where we have host metadata associated
// if there are multiple instances with the same hostname let's use the latest one only
Map<String, InstanceMetaData> metaDataMap = new HashMap<>();
for (InstanceMetaData im : instanceMetaDataRepository.findAllInStack(stackId)) {
String hostName = im.getDiscoveryFQDN();
InstanceMetaData instanceMetaData = metaDataMap.get(hostName);
if (instanceMetaData == null || im.getPrivateId().compareTo(instanceMetaData.getPrivateId()) == 1) {
metaDataMap.put(hostName, im);
}
}
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(),
location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
return new StackSyncContext(flowId, stack, new ArrayList<>(metaDataMap.values()), cloudContext, cloudCredential, isStatusUpdateEnabled(variables));
}
示例4: setUpgradeCutOffTime
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
private void setUpgradeCutOffTime(StateContext<SkipperStates, SkipperEvents> context) {
Long upgradeTimeout = context.getMessageHeaders().get(SkipperEventHeaders.UPGRADE_TIMEOUT, Long.class);
if (upgradeTimeout == null) {
upgradeTimeout = DEFAULT_UPGRADE_TIMEOUT;
}
long cutOffTime = System.currentTimeMillis() + upgradeTimeout;
context.getExtendedState().getVariables().put(SkipperVariables.UPGRADE_CUTOFF_TIME,
cutOffTime);
log.debug("Set cutoff time as {}", cutOffTime);
}
示例5: evaluate
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
public boolean evaluate(StateContext<SkipperStates, SkipperEvents> context) {
Integer status = context.getExtendedState().get(SkipperVariables.UPGRADE_STATUS, Integer.class);
log.debug("Checking condition {} with upgradeStatus {}", status, upgradeStatus);
if (status == null || status == 0) {
return false;
}
else if (upgradeStatus && status > 0) {
return true;
}
else if (!upgradeStatus && status < 0) {
return true;
}
return false;
}
示例6: executeInternal
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected void executeInternal(StateContext<SkipperStates, SkipperEvents> context) {
log.debug("Starting action " + context);
String releaseName = context.getMessageHeaders().get(SkipperEventHeaders.RELEASE_NAME, String.class);
log.info("About to delete {}", releaseName);
DeleteProperties deleteProperties = context.getMessageHeaders()
.get(SkipperEventHeaders.RELEASE_DELETE_PROPERTIES, DeleteProperties.class);
Release release = this.releaseService.delete(releaseName, deleteProperties.isDeletePackage());
context.getExtendedState().getVariables().put(SkipperVariables.RELEASE, release);
}
示例7: execute
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
public final void execute(StateContext<SkipperStates, SkipperEvents> context) {
try {
executeInternal(context);
}
catch (Exception e) {
// any error here will lead to adding exception into
// extended state, thus allowing machine to break up
// from executing state.
log.error("Action execution failed class=[" + getClass() + "]", e);
context.getExtendedState().getVariables().put(SkipperStateMachineService.SkipperVariables.ERROR, e);
}
}
示例8: executeInternal
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected void executeInternal(StateContext<SkipperStates, SkipperEvents> context) {
ReleaseAnalysisReport releaseAnalysisReport = context.getExtendedState().get(SkipperVariables.RELEASE_ANALYSIS_REPORT,
ReleaseAnalysisReport.class);
upgradeStrategy.cancel(releaseAnalysisReport.getExistingRelease(), releaseAnalysisReport.getReplacingRelease(),
releaseAnalysisReport);
}
示例9: executeInternal
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected void executeInternal(StateContext<SkipperStates, SkipperEvents> context) {
log.info("Using UpgradeStrategy {}", upgradeStrategy);
ReleaseAnalysisReport releaseAnalysisReport = context.getExtendedState().get(SkipperVariables.RELEASE_ANALYSIS_REPORT,
ReleaseAnalysisReport.class);
log.info("releaseAnalysisReport {}", releaseAnalysisReport);
if (releaseAnalysisReport == null) {
throw new SkipperException("ReleaseAnalysis report is null");
}
this.upgradeStrategy.deployApps(releaseAnalysisReport.getExistingRelease(),
releaseAnalysisReport.getReplacingRelease(), releaseAnalysisReport);
context.getExtendedState().getVariables().put(SkipperVariables.RELEASE, releaseAnalysisReport.getReplacingRelease());
}
示例10: executeInternal
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected void executeInternal(StateContext<SkipperStates, SkipperEvents> context) {
ReleaseAnalysisReport releaseAnalysisReport = context.getExtendedState().get(SkipperVariables.RELEASE_ANALYSIS_REPORT,
ReleaseAnalysisReport.class);
upgradeStrategy.accept(releaseAnalysisReport.getExistingRelease(), releaseAnalysisReport.getReplacingRelease(),
releaseAnalysisReport);
}
示例11: s2Guard
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
private Guard<States, Events> s2Guard() {
return new Guard<States, Events>() {
@Override
public boolean evaluate(StateContext<States, Events> context) {
return false;
}
public String getName() {
return "s2Guard.getName()";
}
};
}
示例12: s3Guard
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
private Guard<States, Events> s3Guard() {
return new Guard<States, Events>() {
@Override
public boolean evaluate(StateContext<States, Events> context) {
return true;
}
};
}
示例13: buildMachine
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
public StateMachine<States, Events> buildMachine() throws Exception {
StateMachineBuilder.Builder<States, Events> builder = StateMachineBuilder.builder();
builder.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
;
builder.configureStates()
.withStates()
.initial(States.SI)
.state(States.S1, new Action<States, Events>() {
@Override
public void execute(StateContext<States, Events> context) {
System.out.print("test");
}
}, null)
.states(EnumSet.allOf(States.class))
;
builder.configureTransitions()
.withExternal()
.source(States.SI).target(States.S1)
.event(Events.E1)
.and()
.withLocal()
.source(States.S2).target(States.S3)
.event(Events.E1)
.and()
.withExternal()
.source(States.S2).target(States.SE)
.event(Events.E2)
.and()
.withExternal()
.source(States.S1).target(States.SE)
.event(Events.E2);
return builder.build();
}
示例14: createFlowContext
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected StackContext createFlowContext(String flowId, StateContext<StackCreationState, StackCreationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(),
location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
CloudStack cloudStack = cloudStackConverter.convert(stack);
return new StackContext(flowId, stack, cloudContext, cloudCredential, cloudStack);
}
示例15: createFlowContext
import org.springframework.statemachine.StateContext; //導入依賴的package包/類
@Override
protected StackScalingFlowContext createFlowContext(String flowId, StateContext<StackDownscaleState, StackDownscaleEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(),
location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
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(flowId, stack, cloudContext, cloudCredential, cloudStack, instanceGroupName, instanceIds, adjustment);
}