public UndeploymentResult Undeploy(String deploymentId, UndeploymentOptions undeploymentOptions)
 {
     using (_iLock.Acquire())
     {
         return(UndeployInternal(deploymentId, undeploymentOptions ?? new UndeploymentOptions()));
     }
 }
Example #2
0
        private UndeploymentResult UndeployRemoveInternal(
            DeploymentInformation info,
            UndeploymentOptions undeploymentOptions)
        {
            var reverted = new DeploymentInformationItem[info.Items.Length];

            for (int i = 0; i < info.Items.Length; i++)
            {
                reverted[i] = info.Items[info.Items.Length - 1 - i];
            }

            var revertedStatements = new List <DeploymentInformationItem>();

            if (undeploymentOptions.IsDestroyStatements)
            {
                var referencedTypes = new HashSet <string>();

                Exception firstExceptionEncountered = null;

                foreach (DeploymentInformationItem item in reverted)
                {
                    EPStatement statement = _epService.GetStatement(item.StatementName);
                    if (statement == null)
                    {
                        Log.Debug("Deployment id '" + info.DeploymentId + "' statement name '" + item + "' not found");
                        continue;
                    }
                    referencedTypes.AddAll(_statementEventTypeRef.GetTypesForStatementName(statement.Name));
                    if (statement.IsDisposed)
                    {
                        continue;
                    }
                    try
                    {
                        statement.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Log.Warn("Unexpected exception destroying statement: " + ex.Message, ex);
                        if (firstExceptionEncountered == null)
                        {
                            firstExceptionEncountered = ex;
                        }
                    }
                    revertedStatements.Add(item);
                }
                EPLModuleUtil.UndeployTypes(
                    referencedTypes, _statementEventTypeRef, _eventAdapterService, _filterService);
                revertedStatements.Reverse();

                if (firstExceptionEncountered != null &&
                    _undeployRethrowPolicy ==
                    ConfigurationEngineDefaults.UndeployRethrowPolicy.RETHROW_FIRST)
                {
                    throw firstExceptionEncountered;
                }
            }

            return(new UndeploymentResult(info.DeploymentId, revertedStatements));
        }
Example #3
0
 private UndeploymentResult UndeployInternal(string deploymentId, UndeploymentOptions undeploymentOptions)
 {
     undeploymentOptions.DeploymentLockStrategy.Acquire(_eventProcessingRwLock);
     try
     {
         return(UndeployInternalLockTaken(deploymentId, undeploymentOptions));
     }
     finally
     {
         undeploymentOptions.DeploymentLockStrategy.Release(_eventProcessingRwLock);
     }
 }
Example #4
0
        public void TestFlagUndeployNoDestroy()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            var resultOne = _deploymentAdmin.ParseDeploy("@Name('S0') select * from SupportBean");
            var resultTwo = _deploymentAdmin.ParseDeploy("@Name('S1') select * from SupportBean");

            var options = new UndeploymentOptions();

            options.IsDestroyStatements = false;
            _deploymentAdmin.UndeployRemove(resultOne.DeploymentId, options);
            Assert.NotNull(_epService.EPAdministrator.GetStatement("S0"));

            _deploymentAdmin.Undeploy(resultTwo.DeploymentId, options);
            Assert.NotNull(_epService.EPAdministrator.GetStatement("S1"));
        }
        private UndeploymentResult UndeployRemoveInternal(String deploymentId, UndeploymentOptions options)
        {
            using (_iLock.Acquire())
            {
                var info = _deploymentStateService.GetDeployment(deploymentId);
                if (info == null)
                {
                    throw new DeploymentNotFoundException("Deployment by id '" + deploymentId + "' could not be found");
                }

                UndeploymentResult result = info.State == DeploymentState.DEPLOYED
                    ? UndeployRemoveInternal(info, options)
                    : new UndeploymentResult(deploymentId, Collections.GetEmptyList <DeploymentInformationItem>());
                _deploymentStateService.Remove(deploymentId);
                return(result);
            }
        }
Example #6
0
        private void RunAssertionFlagUndeployNoDestroy(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType<SupportBean>();

            var resultOne =
                epService.EPAdministrator.DeploymentAdmin.ParseDeploy("@Name('S0') select * from SupportBean");
            var resultTwo =
                epService.EPAdministrator.DeploymentAdmin.ParseDeploy("@Name('S1') select * from SupportBean");

            var options = new UndeploymentOptions();
            options.IsDestroyStatements = false;
            epService.EPAdministrator.DeploymentAdmin.UndeployRemove(resultOne.DeploymentId, options);
            Assert.IsNotNull(epService.EPAdministrator.GetStatement("S0"));

            epService.EPAdministrator.DeploymentAdmin.Undeploy(resultTwo.DeploymentId, options);
            Assert.IsNotNull(epService.EPAdministrator.GetStatement("S1"));
        }
        private UndeploymentResult UndeployInternal(String deploymentId, UndeploymentOptions undeploymentOptions)
        {
            var info = _deploymentStateService.GetDeployment(deploymentId);

            if (info == null)
            {
                throw new DeploymentNotFoundException("Deployment by id '" + deploymentId + "' could not be found");
            }
            if (info.State == DeploymentState.UNDEPLOYED)
            {
                throw new DeploymentStateException("Deployment by id '" + deploymentId + "' is already in undeployed state");
            }

            var result  = UndeployRemoveInternal(info, undeploymentOptions);
            var updated = new DeploymentInformation(deploymentId, info.Module, info.AddedDate, DateTimeOffsetHelper.Now(_timeZone), new DeploymentInformationItem[0], DeploymentState.UNDEPLOYED);

            _deploymentStateService.AddUpdateDeployment(updated);
            return(result);
        }
Example #8
0
        private void RecursiveUndeploy(
            int index,
            string[] deployments,
            DependencyGraph graph,
            ISet <string> undeployed,
            UndeploymentOptions options)
        {
            var dependencies = graph.GetDependenciesForStream(index);

            foreach (int dependency in dependencies)
            {
                RecursiveUndeploy(dependency, deployments, graph, undeployed, options);
            }

            var next = deployments[index];

            if (!undeployed.Add(next))
            {
                return;
            }

            Undeploy(next, options);
        }
Example #9
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 #10
0
 public void Undeploy(
     string deploymentId,
     UndeploymentOptions options)
 {
     UndeployRemoveInternal(deploymentId, options);
 }
Example #11
0
        private void UndeployAllInternal(UndeploymentOptions options)
        {
            if (options == null)
            {
                options = new UndeploymentOptions();
            }

            var deploymentSvc = _services.DeploymentLifecycleService;
            var deployments   = _services.DeploymentLifecycleService.DeploymentIds;

            if (deployments.Length == 0)
            {
                return;
            }

            if (deployments.Length == 1)
            {
                Undeploy(deployments[0]);
                return;
            }

            if (deployments.Length == 2)
            {
                var zero          = deploymentSvc.GetDeploymentById(deployments[0]);
                var zeroDependsOn = zero.DeploymentIdDependencies;
                if (zeroDependsOn != null && zeroDependsOn.Length > 0)
                {
                    Undeploy(deployments[0]);
                    Undeploy(deployments[1]);
                }
                else
                {
                    Undeploy(deployments[1]);
                    Undeploy(deployments[0]);
                }

                return;
            }

            // build map of deployment-to-index
            var deploymentIndexes = new Dictionary <string, int>();
            var count             = 0;

            foreach (var deployment in deployments)
            {
                deploymentIndexes.Put(deployment, count++);
            }

            var graph = new DependencyGraph(deployments.Length, false);

            foreach (var deploymentId in deployments)
            {
                var deployment  = deploymentSvc.GetDeploymentById(deploymentId);
                var dependentOn = deployment.DeploymentIdDependencies;
                if (dependentOn == null || dependentOn.Length == 0)
                {
                    continue;
                }

                foreach (var target in dependentOn)
                {
                    int fromIndex   = deploymentIndexes.Get(deploymentId);
                    int targetIndex = deploymentIndexes.Get(target);
                    graph.AddDependency(targetIndex, fromIndex);
                }
            }

            var undeployed = new HashSet <string>();

            foreach (var rootIndex in graph.RootNodes)
            {
                RecursiveUndeploy(rootIndex, deployments, graph, undeployed, options);
            }
        }
Example #12
0
 public void UndeployAll(UndeploymentOptions options)
 {
     UndeployAllInternal(options);
 }