public static DeploymentInternal From( string deploymentId, EPStatement[] statements, ISet<string> deploymentIdDependencies, DeployerModulePaths modulePaths, DeployerModuleEPLObjects moduleEPLObjects, ModuleProviderCLPair moduleProvider) { var deploymentIdDependenciesArray = deploymentIdDependencies.ToArray(); return new DeploymentInternal( deploymentId, statements, deploymentIdDependenciesArray, modulePaths.PathNamedWindows.ToArray(), modulePaths.PathTables.ToArray(), modulePaths.PathVariables.ToArray(), modulePaths.PathContexts.ToArray(), modulePaths.PathEventTypes.ToArray(), modulePaths.PathExprDecl.ToArray(), modulePaths.PathScripts.ToArray(), moduleEPLObjects.ModuleIndexes.ToArray(), modulePaths.PathClassProvideds.ToArray(), moduleProvider.ModuleProvider, moduleProvider.ModuleProvider.ModuleProperties, modulePaths.DeploymentTypes, DateTimeHelper.CurrentTimeMillis); }
internal static EPStatement[] DeployStatements( int rolloutItemNumber, IList <StatementLightweight> lightweights, bool recovery, DeployerModulePaths modulePaths, ModuleProviderCLPair provider, string deploymentId, EPRuntimeSPI epRuntime) { var statements = new EPStatement[lightweights.Count]; var count = 0; foreach (var lightweight in lightweights) { EPStatementSPI stmt; try { stmt = DeployerHelperStatement.DeployStatement(recovery, lightweight, epRuntime); } catch (Exception ex) { try { ReverseDeployment(deploymentId, modulePaths.DeploymentTypes, lightweights, statements, provider, epRuntime.ServicesContext); } catch (Exception udex) { log.Warn(udex.Message, udex); } throw new EPDeployException("Failed to deploy: " + ex.Message, ex, rolloutItemNumber); } statements[count++] = stmt; if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get() .QaEngineManagementStmtStarted( epRuntime.URI, deploymentId, lightweight.StatementContext.StatementId, stmt.Name, (string)stmt.GetProperty(StatementProperty.EPL), epRuntime.EventService.CurrentTime); } } return(statements); }
public static void ReverseDeployment( string deploymentId, IDictionary <long, EventType> deploymentTypes, IList <StatementLightweight> lightweights, EPStatement[] statements, ModuleProviderCLPair provider, EPServicesContext services) { var revert = new List <StatementContext>(); foreach (var stmtToRemove in lightweights) { revert.Add(stmtToRemove.StatementContext); } revert.Reverse(); var reverted = revert.ToArray(); Undeployer.Disassociate(statements); Undeployer.Undeploy(deploymentId, deploymentTypes, reverted, provider.ModuleProvider, services); }
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)); }
public static DeployerModuleEPLObjects InitializeEPLObjects( ModuleProviderCLPair provider, string deploymentId, EPServicesContext services) { // keep protected types var beanEventTypeFactory = new BeanEventTypeFactoryPrivate( new EventBeanTypedEventFactoryRuntime(services.EventTypeAvroHandler), services.EventTypeFactory, services.BeanEventTypeStemService); // initialize module event types IDictionary <string, EventType> moduleEventTypes = new LinkedHashMap <string, EventType>(); var eventTypeResolver = new EventTypeResolverImpl( moduleEventTypes, services.EventTypePathRegistry, services.EventTypeRepositoryBus, services.BeanEventTypeFactoryPrivate, services.EventSerdeFactory); var eventTypeCollector = new EventTypeCollectorImpl( services.Container, moduleEventTypes, beanEventTypeFactory, provider.ClassLoader, services.EventTypeFactory, services.BeanEventTypeStemService, eventTypeResolver, services.XmlFragmentEventTypeFactory, services.EventTypeAvroHandler, services.EventBeanTypedEventFactory, services.ImportServiceRuntime); try { provider.ModuleProvider.InitializeEventTypes(new EPModuleEventTypeInitServicesImpl(eventTypeCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } JsonEventTypeUtility.AddJsonUnderlyingClass(moduleEventTypes, services.ClassLoaderParent, deploymentId); // initialize module named windows IDictionary <string, NamedWindowMetaData> moduleNamedWindows = new Dictionary <string, NamedWindowMetaData>(); NamedWindowCollector namedWindowCollector = new NamedWindowCollectorImpl(moduleNamedWindows); try { provider.ModuleProvider.InitializeNamedWindows(new EPModuleNamedWindowInitServicesImpl(namedWindowCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize module tables IDictionary <string, TableMetaData> moduleTables = new Dictionary <string, TableMetaData>(); var tableCollector = new TableCollectorImpl(moduleTables); try { provider.ModuleProvider.InitializeTables(new EPModuleTableInitServicesImpl(tableCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize create-index indexes ISet <ModuleIndexMeta> moduleIndexes = new HashSet <ModuleIndexMeta>(); var indexCollector = new IndexCollectorRuntime(moduleIndexes); try { provider.ModuleProvider.InitializeIndexes(new EPModuleIndexInitServicesImpl(indexCollector)); } catch (Exception e) { throw new EPException(e); } // initialize module contexts IDictionary <string, ContextMetaData> moduleContexts = new Dictionary <string, ContextMetaData>(); ContextCollector contextCollector = new ContextCollectorImpl(moduleContexts); try { provider.ModuleProvider.InitializeContexts(new EPModuleContextInitServicesImpl(contextCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize module variables IDictionary <string, VariableMetaData> moduleVariables = new Dictionary <string, VariableMetaData>(); VariableCollector variableCollector = new VariableCollectorImpl(moduleVariables); try { provider.ModuleProvider.InitializeVariables(new EPModuleVariableInitServicesImpl(variableCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize module expressions IDictionary <string, ExpressionDeclItem> moduleExpressions = new Dictionary <string, ExpressionDeclItem>(); var exprDeclaredCollector = new ExprDeclaredCollectorRuntime(moduleExpressions); try { provider.ModuleProvider.InitializeExprDeclareds(new EPModuleExprDeclaredInitServicesImpl(exprDeclaredCollector)); } catch (Exception e) { throw new EPException(e); } // initialize module scripts IDictionary <NameAndParamNum, ExpressionScriptProvided> moduleScripts = new Dictionary <NameAndParamNum, ExpressionScriptProvided>(); var scriptCollectorRuntime = new ScriptCollectorRuntime(moduleScripts); try { provider.ModuleProvider.InitializeScripts(new EPModuleScriptInitServicesImpl(scriptCollectorRuntime)); } catch (Exception e) { throw new EPException(e); } // initialize module class-provided create-class IDictionary <string, ClassProvided> moduleClasses = new Dictionary <string, ClassProvided>(); var classProvidedCollectorRuntime = new ClassProvidedCollectorRuntime(moduleClasses); try { provider.ModuleProvider.InitializeClassProvided(new EPModuleClassProvidedInitServicesImpl(classProvidedCollectorRuntime)); } catch (Exception e) { throw new EPException(e); } foreach (var moduleClass in moduleClasses) { moduleClass.Value.LoadClasses(provider.ClassLoader); } return(new DeployerModuleEPLObjects( beanEventTypeFactory, moduleEventTypes, moduleNamedWindows, moduleTables, moduleIndexes, moduleContexts, moduleVariables, moduleExpressions, moduleScripts, moduleClasses, eventTypeCollector.Serdes, eventTypeResolver)); }
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)); }