private static void RolloutCleanStatements( EPStatement[][] statements, DeployerModuleStatementLightweights[] stmtLightweights, DeployerRolloutInitResult[] inits, string[] deploymentIds, ModuleProviderCLPair[] moduleProviders, EPServicesContext services) { for (var i = statements.Length - 1; i >= 0; i--) { if (statements[i] != null) { DeployerHelperResolver.ReverseDeployment( deploymentIds[i], inits[i].ModulePaths.DeploymentTypes, stmtLightweights[i].Lightweights, statements[i], moduleProviders[i], services); stmtLightweights[i] = null; inits[i] = null; } } RolloutCleanLightweights(stmtLightweights, inits, deploymentIds, moduleProviders, services); }
public EPDeployment Deploy( EPCompiled compiled, DeploymentOptions options) { using (_services.Container.EnterContextualReflection()) { if (options == null) { options = new DeploymentOptions(); } ValidateRuntimeAlive(); CheckManifest(-1, compiled.Manifest); DeploymentInternal deployerResult; using (GetDeploymentLock(options)) { var statementIdRecovery = _services.EpServicesHA.StatementIdRecoveryService; var currentStatementId = statementIdRecovery.CurrentStatementId; if (currentStatementId == null) { currentStatementId = 1; } var deploymentId = DeployerHelperResolver.DetermineDeploymentIdCheckExists( -1, options, _runtime.ServicesContext.DeploymentLifecycleService); deployerResult = Deployer.DeployFresh( deploymentId, currentStatementId.Value, compiled, options.StatementNameRuntime, options.StatementUserObjectRuntime, options.StatementSubstitutionParameter, options.DeploymentClassLoaderOption, _runtime); statementIdRecovery.CurrentStatementId = currentStatementId + deployerResult.Statements.Length; // dispatch event DispatchOnDeploymentEvent(deployerResult, -1); } return(MakeDeployment(deployerResult)); } }
private static DeployerRolloutInitResult ResolveDependenciesInitEPLObjects( int rolloutItemNumber, string deploymentId, ModuleProviderCLPair moduleProvider, EPServicesContext services, EPStageService stageService) { var moduleDependencies = moduleProvider.ModuleProvider.ModuleDependencies; var deploymentIdDependencies = DeployerHelperResolver.ResolveDependencies(rolloutItemNumber, moduleDependencies, services); // initialize EPL objects defined by module var moduleEPLObjects = InitializeEPLObjects(moduleProvider, deploymentId, services); // determine staged EPL object overlap ValidateStagedEPLObjects(moduleEPLObjects, moduleProvider.ModuleProvider.ModuleName, rolloutItemNumber, stageService); // add EPL objects defined by module to path var moduleName = moduleProvider.ModuleProvider.ModuleName; var modulePaths = UpdatePath(rolloutItemNumber, moduleEPLObjects, moduleName, deploymentId, services); return(new DeployerRolloutInitResult(deploymentIdDependencies, moduleEPLObjects, modulePaths, moduleName)); }
private static DeploymentInternal DeploySafe( bool recovery, string deploymentId, int statementIdFirstStatement, EPCompiled compiled, StatementNameRuntimeOption statementNameResolverRuntime, StatementUserObjectRuntimeOption userObjectResolverRuntime, StatementSubstitutionParameterOption substitutionParameterResolver, DeploymentClassLoaderOption deploymentClassLoaderOption, EPRuntimeSPI epRuntime) { var services = epRuntime.ServicesContext; var deploymentClassLoader = DeployerHelperResolver.GetClassLoader(-1, deploymentClassLoaderOption, services); var moduleProvider = ModuleProviderUtil.Analyze(compiled, deploymentClassLoader, services.ClassProvidedPathRegistry); if (moduleProvider.ClassLoader is ClassProvidedImportClassLoader) { ((ClassProvidedImportClassLoader)moduleProvider.ClassLoader).Imported = moduleProvider.ModuleProvider.ModuleDependencies.PathClasses; } var moduleName = moduleProvider.ModuleProvider.ModuleName; // resolve external dependencies var moduleDependencies = moduleProvider.ModuleProvider.ModuleDependencies; var deploymentIdDependencies = ResolveDependencies(-1, moduleDependencies, services); // initialize EPL objects defined by module var moduleEPLObjects = InitializeEPLObjects(moduleProvider, deploymentId, services); // determine staged EPL object overlap ValidateStagedEPLObjects(moduleEPLObjects, moduleProvider.ModuleProvider.ModuleName, -1, epRuntime.StageService); // add EPL objects defined by module to path var modulePaths = UpdatePath(-1, moduleEPLObjects, moduleName, deploymentId, services); // obtain statement lightweights var stmtLightweights = InitializeStatements( -1, recovery, moduleEPLObjects, modulePaths, moduleName, moduleProvider, deploymentId, statementIdFirstStatement, userObjectResolverRuntime, statementNameResolverRuntime, substitutionParameterResolver, services); // start statements depending on context association var statements = DeployStatements( -1, stmtLightweights.Lightweights, recovery, modulePaths, moduleProvider, deploymentId, epRuntime); // add dependencies AddPathDependencies(deploymentId, moduleDependencies, services); // keep statement and deployment var deployed = DeploymentInternal.From( deploymentId, statements, deploymentIdDependencies, modulePaths, moduleEPLObjects, moduleProvider); services.DeploymentLifecycleService.AddDeployment(deploymentId, deployed); // register for recovery if (!recovery) { var recoveryInformation = GetRecoveryInformation(deployed); services.DeploymentRecoveryService.Add( deploymentId, statementIdFirstStatement, compiled, recoveryInformation.StatementUserObjectsRuntime, recoveryInformation.StatementNamesWhenProvidedByAPI, stmtLightweights.SubstitutionParameters); } return(deployed); }
public static DeployerModuleStatementLightweights InitializeStatements( int rolloutItemNumber, bool recovery, DeployerModuleEPLObjects moduleEPLObjects, DeployerModulePaths modulePaths, string moduleName, ModuleProviderCLPair moduleProvider, string deploymentId, int statementIdFirstStatement, StatementUserObjectRuntimeOption userObjectResolverRuntime, StatementNameRuntimeOption statementNameResolverRuntime, StatementSubstitutionParameterOption substitutionParameterResolver, EPServicesContext services) { // get module statements IList <StatementProvider> statementResources; try { statementResources = moduleProvider.ModuleProvider.Statements; } catch (Exception e) { throw new EPException(e); } // initialize all statements IList <StatementLightweight> lightweights = new List <StatementLightweight>(); IDictionary <int, IDictionary <int, object> > substitutionParameters; ISet <string> statementNames = new HashSet <string>(); var moduleIncidentals = moduleEPLObjects.Incidentals; try { var statementId = statementIdFirstStatement; foreach (var statement in statementResources) { var lightweight = InitStatement( recovery, moduleName, statement, deploymentId, statementId, moduleEPLObjects.EventTypeResolver, moduleIncidentals, statementNameResolverRuntime, userObjectResolverRuntime, moduleProvider.ClassLoader, services); lightweights.Add(lightweight); statementId++; var statementName = lightweight.StatementContext.StatementName; if (statementNames.Contains(statementName)) { throw new EPDeployException( "Duplicate statement name provide by statement name resolver for statement name '" + statementName + "'", rolloutItemNumber); } statementNames.Add(statementName); } // set parameters substitutionParameters = SetSubstitutionParameterValues(rolloutItemNumber, deploymentId, lightweights, substitutionParameterResolver); } catch (Exception) { DeployerHelperResolver.ReverseDeployment(deploymentId, modulePaths.DeploymentTypes, lightweights, new EPStatement[0], moduleProvider, services); throw; } return(new DeployerModuleStatementLightweights(statementIdFirstStatement, lightweights, substitutionParameters)); }
public static DeployerRolloutDeploymentResult Rollout( int currentStatementId, ICollection <EPDeploymentRolloutCompiled> itemsProvided, EPRuntimeSPI runtime) { var items = itemsProvided.ToArray(); // per-deployment: determine deployment id var deploymentIds = new string[items.Length]; var deploymentIdSet = new HashSet <string>(); for (var i = 0; i < items.Length; i++) { deploymentIds[i] = DeployerHelperResolver.DetermineDeploymentIdCheckExists( i, items[i].Options, runtime.ServicesContext.DeploymentLifecycleService); if (!deploymentIdSet.Add(deploymentIds[i])) { throw new EPDeployException("Deployment id '" + deploymentIds[i] + "' occurs multiple times in the rollout", i); } } // per-deployment: obtain module providers var moduleProviders = new ModuleProviderCLPair[items.Length]; for (var i = 0; i < items.Length; i++) { var classLoader = DeployerHelperResolver.GetClassLoader(i, items[i].Options.DeploymentClassLoaderOption, runtime.ServicesContext); try { moduleProviders[i] = ModuleProviderUtil.Analyze(items[i].Compiled, classLoader, runtime.ServicesContext.ClassProvidedPathRegistry); } catch (Exception) { RolloutCleanClassloader(deploymentIds, runtime.ServicesContext); } } // per-deployment: check dependencies and initialize EPL objects var inits = new DeployerRolloutInitResult[items.Length]; for (var i = 0; i < items.Length; i++) { try { inits[i] = ResolveDependenciesInitEPLObjects(i, deploymentIds[i], moduleProviders[i], runtime.ServicesContext, runtime.StageService); } catch (EPDeployException) { RolloutCleanPathAndTypes(inits, deploymentIds, runtime.ServicesContext); throw; } catch (Exception ex) { RolloutCleanPathAndTypes(inits, deploymentIds, runtime.ServicesContext); throw new EPDeployException(ex.Message, ex, i); } } // per-deployment - obtain statement lightweights var stmtLightweights = new DeployerModuleStatementLightweights[items.Length]; var numStatements = 0; for (var i = 0; i < items.Length; i++) { var statementIdStart = currentStatementId + numStatements; try { stmtLightweights[i] = InitializeStatements( i, false, inits[i].ModuleEPLObjects, inits[i].ModulePaths, inits[i].ModuleName, moduleProviders[i], deploymentIds[i], statementIdStart, items[i].Options.StatementUserObjectRuntime, items[i].Options.StatementNameRuntime, items[i].Options.StatementSubstitutionParameter, runtime.ServicesContext); } catch (EPDeployException ex) { RolloutCleanLightweights(stmtLightweights, inits, deploymentIds, moduleProviders, runtime.ServicesContext); throw ex; } catch (Exception ex) { RolloutCleanLightweights(stmtLightweights, inits, deploymentIds, moduleProviders, runtime.ServicesContext); throw new EPDeployException(ex.Message, ex, i); } numStatements += stmtLightweights[i].Lightweights.Count; } // per-deployment: start statements depending on context association var statements = new EPStatement[items.Length][]; for (var i = 0; i < items.Length; i++) { try { statements[i] = DeployerHelperStatement.DeployStatements( i, stmtLightweights[i].Lightweights, false, inits[i].ModulePaths, moduleProviders[i], deploymentIds[i], runtime); } catch (EPDeployException ex) { RolloutCleanStatements(statements, stmtLightweights, inits, deploymentIds, moduleProviders, runtime.ServicesContext); throw ex; } catch (Exception t) { RolloutCleanStatements(statements, stmtLightweights, inits, deploymentIds, moduleProviders, runtime.ServicesContext); throw new EPDeployException(t.Message, t, i); } } // per-deployment: add paths dependency information and add deployment var deployments = new DeploymentInternal[items.Length]; for (var i = 0; i < items.Length; i++) { try { // add dependencies AddPathDependencies(deploymentIds[i], moduleProviders[i].ModuleProvider.ModuleDependencies, runtime.ServicesContext); // keep statement and deployment deployments[i] = DeploymentInternal.From( deploymentIds[i], statements[i], inits[i].DeploymentIdDependencies, inits[i].ModulePaths, inits[i].ModuleEPLObjects, moduleProviders[i]); runtime.ServicesContext.DeploymentLifecycleService.AddDeployment(deploymentIds[i], deployments[i]); // register for recovery DeploymentRecoveryInformation recoveryInformation = GetRecoveryInformation(deployments[i]); runtime.ServicesContext.DeploymentRecoveryService.Add( deploymentIds[i], stmtLightweights[i].StatementIdFirstStatement, items[i].Compiled, recoveryInformation.StatementUserObjectsRuntime, recoveryInformation.StatementNamesWhenProvidedByAPI, stmtLightweights[i].SubstitutionParameters); } catch (Exception t) { RolloutCleanStatements(statements, stmtLightweights, inits, deploymentIds, moduleProviders, runtime.ServicesContext); throw new EPDeployException(t.Message, t, i); } } return(new DeployerRolloutDeploymentResult(numStatements, deployments)); }