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