InstanceFSM { @OnTransit public void onInstanceLaunching(@Event InstanceLaunchingEvent event) { Instance instance = event.getInstance(); String cloudId = instance.getCloudId(); Cloud cloud = cloudConfigurationProvider.getCloud(cloudId); if (event.isSync()) { LOG.info("Marking instance {} ({}) as launching", instance.getName(), instance.getId()); instance.setState(InstanceState.LAUNCHING); instancesAware.saveInstance(instance); } else { LOG.info("Adding instance {} ({})", instance.getName(), instance.getId()); Optional<Instance> updatedInstanceCandidate = operationProcessor.process(cloud, OperationType.ADD_INSTANCE, () -> instance); if (!updatedInstanceCandidate.isPresent()) { throw new RuntimeException(String.format("Failed to add %s", instance)); } Instance updatedInstance = updatedInstanceCandidate.get(); updatedInstance.setState(InstanceState.LAUNCHING); String temporaryInstanceId = event.getTemporaryInstanceId(); if (temporaryInstanceId != null && instancesAware.instanceExists(temporaryInstanceId)) { instancesAware.deleteInstance(temporaryInstanceId); } instancesAware.saveInstance(updatedInstance); requestProjectSync(eventBus, cloud, updatedInstance.getProjectId()); } } @Autowired  InstanceFSM(OperationProcessor operationProcessor, InstancesAware instancesAware, CloudConfigurationProvider cloudConfigurationProvider, EventBus eventBus, MailSender mailSender); @BeforeTransit void beforeTransit(@Event InstanceEvent instanceEvent); @OnTransit void onInstanceQueued(@Event InstanceQueuedEvent event); @OnTransit void onInstanceLaunching(@Event InstanceLaunchingEvent event); @OnTransit void onInstanceLaunched(@Event InstanceLaunchedEvent event); @OnTransit void onInstanceRebooting(@Event InstanceRebootingEvent event); @OnTransit void onInstanceHardRebooting(@Event InstanceHardRebootingEvent event); @OnTransit void onInstanceShuttingDown(@Event InstanceShuttingDownEvent event); @OnTransit void onInstanceShutoff(@Event InstanceShutOffEvent event); @OnTransit void onInstancePausing(@Event InstancePausingEvent event); @OnTransit void onInstancePaused(@Event InstancePausedEvent event); @OnTransit void onInstanceResuming(@Event InstanceResumingEvent event); @OnTransit void onInstanceRebuilding(@Event InstanceRebuildingEvent event); @OnTransit void onInstanceResizing(@Event InstanceResizingEvent event); @OnTransit void onInstanceStarting(@Event InstanceStartingEvent event); @OnTransit void onInstanceSuspending(@Event InstanceSuspendingEvent event); @OnTransit void onInstanceSuspended(@Event InstanceSuspendedEvent event); @OnTransit void onInstanceMigrating(@Event InstanceMigratingEvent event); @OnTransit void onInstanceDeleting(@Event InstanceDeletingEvent event); @OnTransit void onInstanceRenaming(@Event InstanceRenamingEvent event); @OnTransit void onInstanceSnapshotting(@Event InstanceSnapshottingEvent event); @OnTransit void onInstanceError(@FromState InstanceEvent from, @Event InstanceErrorEvent event); @OnException void onUnsupportedOperationException(UnsupportedOperationException e);  }
@Test public void testOnInstanceLaunching() { testOnInstanceSyncEvent(InstanceLaunchingEvent.class, LAUNCHING); }