Example #1
0
        private static void RolloutCleanPathAndTypes(
            DeployerRolloutInitResult[] inits,
            string[] deploymentIds,
            EPServicesContext services)
        {
            RolloutCleanClassloader(deploymentIds, services);

            for (var i = 0; i < inits.Length; i++)
            {
                Undeployer.DeleteFromPathRegistries(services, deploymentIds[i]);
                if (inits[i] != null)
                {
                    Undeployer.DeleteFromEventTypeBus(services, inits[i].ModulePaths.DeploymentTypes);
                }
            }
        }
Example #2
0
        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);
        }
Example #3
0
        private void UndeployRemoveInternal(
            string deploymentId,
            UndeploymentOptions options)
        {
            var deployment = _services.DeploymentLifecycleService.GetDeploymentById(deploymentId);

            if (deployment == null)
            {
                var stageUri = _services.StageRecoveryService.DeploymentGetStage(deploymentId);
                if (stageUri != null)
                {
                    throw new EPUndeployPreconditionException("Deployment id '" + deploymentId + "' is staged and cannot be undeployed");
                }

                throw new EPUndeployNotFoundException("Deployment id '" + deploymentId + "' cannot be found");
            }

            var statements = deployment.Statements;

            if (options == null)
            {
                options = new UndeploymentOptions();
            }


            using (options.UndeploymentLockStrategy.Acquire(_services.EventProcessingRWLock)) {
                // build list of statements in reverse order
                var reverted = new StatementContext[statements.Length];
                var count    = reverted.Length - 1;
                foreach (var stmt in statements)
                {
                    reverted[count--] = ((EPStatementSPI)stmt).StatementContext;
                }

                // check module preconditions
                var moduleName = deployment.ModuleProvider.ModuleName;
                Undeployer.CheckModulePreconditions(deploymentId, moduleName, deployment, _services);

                // check preconditions
                try {
                    foreach (var statement in reverted)
                    {
                        statement.StatementAIFactoryProvider.Factory.StatementDestroyPreconditions(statement);
                    }
                }
                catch (UndeployPreconditionException t) {
                    throw new EPUndeployException("Precondition not satisfied for undeploy: " + t.Message, t);
                }

                // disassociate statements
                Undeployer.Disassociate(statements);

                // undeploy statements
                Exception undeployException = null;
                try {
                    Undeployer.Undeploy(deploymentId, deployment.DeploymentTypes, reverted, deployment.ModuleProvider, _services);
                }
                catch (Exception ex) {
                    log.Error("Exception encountered during undeploy: " + ex.Message, ex);
                    undeployException = ex;
                }

                // remove deployment
                _services.EpServicesHA.DeploymentRecoveryService.Remove(deploymentId);
                _services.DeploymentLifecycleService.RemoveDeployment(deploymentId);

                DispatchOnUndeploymentEvent(deployment, -1);

                // rethrow exception if configured
                if (undeployException != null &&
                    _services.ConfigSnapshot.Runtime.ExceptionHandling.UndeployRethrowPolicy == RETHROW_FIRST)
                {
                    throw new EPUndeployException("Undeploy completed with an exception: " + undeployException.Message, undeployException);
                }

                ((EPEventServiceSPI)_runtime.EventService).ClearCaches();
            }
        }
Example #4
0
        public static DeployerModulePaths UpdatePath(
            int rolloutItemNumber,
            DeployerModuleEPLObjects eplObjects,
            string moduleName,
            string deploymentId,
            EPServicesContext services)
        {
            // save path-visibility event types and named windows to the path
            var deploymentIdCrc32 = CRC32Util.ComputeCRC32(deploymentId);
            IDictionary <long, EventType> deploymentTypes = EmptyDictionary <long, EventType> .Instance;
            IList <string>          pathEventTypes        = new List <string>(eplObjects.ModuleEventTypes.Count);
            IList <string>          pathNamedWindows      = new List <string>(eplObjects.ModuleNamedWindows.Count);
            IList <string>          pathTables            = new List <string>(eplObjects.ModuleTables.Count);
            IList <string>          pathContexts          = new List <string>(eplObjects.ModuleContexts.Count);
            IList <string>          pathVariables         = new List <string>(eplObjects.ModuleVariables.Count);
            IList <string>          pathExprDecl          = new List <string>(eplObjects.ModuleExpressions.Count);
            IList <NameAndParamNum> pathScripts           = new List <NameAndParamNum>(eplObjects.ModuleScripts.Count);
            IList <string>          pathClasses           = new List <string>(eplObjects.ModuleClasses.Count);

            try {
                foreach (var entry in eplObjects.ModuleNamedWindows)
                {
                    if (entry.Value.EventType.Metadata.AccessModifier.IsNonPrivateNonTransient())
                    {
                        try {
                            services.NamedWindowPathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathNamedWindows.Add(entry.Key);
                    }
                }

                foreach (var entry in eplObjects.ModuleTables)
                {
                    if (entry.Value.TableVisibility.IsNonPrivateNonTransient())
                    {
                        try {
                            services.TablePathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathTables.Add(entry.Key);
                    }
                }

                foreach (var entry in eplObjects.ModuleEventTypes)
                {
                    var eventTypeSPI      = (EventTypeSPI)entry.Value;
                    var nameTypeId        = CRC32Util.ComputeCRC32(eventTypeSPI.Name);
                    var eventTypeMetadata = entry.Value.Metadata;
                    if (eventTypeMetadata.AccessModifier == NameAccessModifier.PRECONFIGURED)
                    {
                        // For XML all fragment event types are public
                        if (eventTypeMetadata.ApplicationType != EventTypeApplicationType.XML)
                        {
                            throw new IllegalStateException("Unrecognized public visibility type in deployment");
                        }
                    }
                    else if (eventTypeMetadata.AccessModifier.IsNonPrivateNonTransient())
                    {
                        if (eventTypeMetadata.BusModifier == EventTypeBusModifier.BUS)
                        {
                            eventTypeSPI.SetMetadataId(nameTypeId, -1);
                            services.EventTypeRepositoryBus.AddType(eventTypeSPI);
                        }
                        else
                        {
                            eventTypeSPI.SetMetadataId(deploymentIdCrc32, nameTypeId);
                        }

                        try {
                            services.EventTypePathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }
                    }
                    else
                    {
                        eventTypeSPI.SetMetadataId(deploymentIdCrc32, nameTypeId);
                    }

                    if (eventTypeMetadata.AccessModifier.IsNonPrivateNonTransient())
                    {
                        pathEventTypes.Add(entry.Key);
                    }

                    // we retain all types to enable variant-streams
                    if (deploymentTypes.IsEmpty())
                    {
                        deploymentTypes = new Dictionary <long, EventType>();
                    }

                    deploymentTypes.Put(nameTypeId, eventTypeSPI);
                }

                // add serde information to event types
                services.EventTypeSerdeRepository.AddSerdes(
                    deploymentId,
                    eplObjects.EventTypeSerdes,
                    eplObjects.ModuleEventTypes,
                    eplObjects.BeanEventTypeFactory);

                foreach (var entry in eplObjects.ModuleContexts)
                {
                    if (entry.Value.ContextVisibility.IsNonPrivateNonTransient())
                    {
                        try {
                            services.ContextPathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathContexts.Add(entry.Key);
                    }
                }

                foreach (var entry in eplObjects.ModuleVariables)
                {
                    if (entry.Value.VariableVisibility.IsNonPrivateNonTransient())
                    {
                        try {
                            services.VariablePathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathVariables.Add(entry.Key);
                    }
                }

                foreach (var entry in eplObjects.ModuleExpressions)
                {
                    if (entry.Value.Visibility.IsNonPrivateNonTransient())
                    {
                        try {
                            services.ExprDeclaredPathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathExprDecl.Add(entry.Key);
                    }
                }

                foreach (var entry in eplObjects.ModuleScripts)
                {
                    if (entry.Value.Visibility.IsNonPrivateNonTransient())
                    {
                        try {
                            services.ScriptPathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathScripts.Add(entry.Key);
                    }
                }

                foreach (var index in eplObjects.ModuleIndexes)
                {
                    if (index.IsNamedWindow)
                    {
                        var namedWindow = services.NamedWindowPathRegistry.GetWithModule(index.InfraName, index.InfraModuleName);
                        if (namedWindow == null)
                        {
                            throw new IllegalStateException("Failed to find named window '" + index.InfraName + "'");
                        }

                        ValidateIndexPrecondition(rolloutItemNumber, namedWindow.IndexMetadata, index);
                    }
                    else
                    {
                        var table = services.TablePathRegistry.GetWithModule(index.InfraName, index.InfraModuleName);
                        if (table == null)
                        {
                            throw new IllegalStateException("Failed to find table '" + index.InfraName + "'");
                        }

                        ValidateIndexPrecondition(rolloutItemNumber, table.IndexMetadata, index);
                    }
                }

                foreach (var entry in eplObjects.ModuleClasses)
                {
                    if (entry.Value.Visibility.IsNonPrivateNonTransient())
                    {
                        try {
                            services.ClassProvidedPathRegistry.Add(entry.Key, moduleName, entry.Value, deploymentId);
                        }
                        catch (PathExceptionAlreadyRegistered ex) {
                            throw new EPDeployPreconditionException(ex.Message, ex, rolloutItemNumber);
                        }

                        pathClasses.Add(entry.Key);
                    }
                }
            }
            catch (Exception) {
                Undeployer.DeleteFromEventTypeBus(services, deploymentTypes);
                Undeployer.DeleteFromPathRegistries(services, deploymentId);
                throw;
            }

            return(new DeployerModulePaths(
                       deploymentTypes,
                       pathEventTypes,
                       pathNamedWindows,
                       pathTables,
                       pathContexts,
                       pathVariables,
                       pathExprDecl,
                       pathScripts,
                       pathClasses));
        }