Exemplo n.º 1
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);
        }
Exemplo n.º 2
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();
            }
        }