Exemple #1
0
        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);
        }
Exemple #2
0
        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));
        }