Пример #1
0
        public void Invoke_WithSiteModels()
        {
            var message  = new DesignChangedEvent();
            var listener = new DesignChangedEventListener(TRexGrids.ImmutableGridName());

            listener.Invoke(Guid.Empty, message).Should().BeTrue();
        }
Пример #2
0
        public void TestRemoveDesignFromDesignCache()
        {
            AddApplicationRouting();

            var siteModel    = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();
            var designUid    = DITAGFileAndSubGridRequestsWithIgniteFixture.AddDesignToSiteModel(ref siteModel, TestHelper.CommonTestDataPath, TESTFILENAME, true);
            var localStorage = Path.Combine(FilePathHelper.GetTempFolderForProject(siteModel.ID), TESTFILENAME);

            var designFiles = DIContext.ObtainOptional <IDesignFiles>();

            designFiles.NumDesignsInCache().Should().Be(0);
            designFiles.Lock(designUid, siteModel, SubGridTreeConsts.DefaultCellSize, out var loadResult);

            File.Exists(localStorage).Should().BeTrue();

            designFiles.NumDesignsInCache().Should().Be(1);
            var design1 = loadResult.Should().Be(DesignLoadResult.Success);

            design1.Should().NotBeNull();

            var message = new DesignChangedEvent()
            {
                SiteModelUid  = siteModel.ID,
                DesignUid     = designUid,
                DesignRemoved = true,
                FileType      = ImportedFileType.DesignSurface
            };

            var listener = new DesignChangedEventListener(TRexGrids.ImmutableGridName());

            listener.Invoke(Guid.Empty, message).Should().BeTrue();
            File.Exists(localStorage).Should().BeFalse();

            designFiles.NumDesignsInCache().Should().Be(0);
        }
Пример #3
0
        public void Test_ActivatePersistentGridServer_WaitUntilGridActive()
        {
            var server = new ActivatePersistentGridServer();

            server.Should().NotBeNull();

            server.WaitUntilGridActive(TRexGrids.ImmutableGridName()).Should().BeTrue();
        }
Пример #4
0
        public void StartListening_FailWithNoMessagingFabric()
        {
            var listener = new DesignChangedEventListener(TRexGrids.ImmutableGridName())
            {
                MessageTopicName = "TestMessageTopic"
            };

            listener.StartListening();
        }
Пример #5
0
        private bool ActivateImmutable()
        {
            Log.LogInformation("About to call ActivatePersistentGridServer.Instance().SetGridActive() for Immutable TRex grid");
            bool result = ActivatePersistentGridServer.Instance().SetGridActive(TRexGrids.ImmutableGridName());

            Log.LogInformation($"Activation process completed: Immutable = {result}");

            return(result);
        }
Пример #6
0
        public void StartListening()
        {
            var listener = new SiteModelAttributesChangedEventListener(TRexGrids.ImmutableGridName())
            {
                MessageTopicName = "TestMessageTopic"
            };

            listener.StartListening();
        }
Пример #7
0
        public JsonResult GetGridNames()
        {
            IList <Grid> grids = new List <Grid>();

            foreach (string name in TRexGrids.GridNames())
            {
                grids.Add(new Grid(name));
            }

            return(Json(grids));
        }
Пример #8
0
        public void Invoke_WithSiteModels()
        {
            var message = new SiteModelAttributesChangedEvent
            {
                SiteModelID = Guid.NewGuid()
            };

            var listener = new SiteModelAttributesChangedEventListener(TRexGrids.ImmutableGridName());

            listener.Invoke(Guid.NewGuid(), message).Should().BeTrue();
        }
Пример #9
0
        public void AcquireIgniteTopologyProjections_FailWithNullOrEmptyRole()
        {
            string GridName = TRexGrids.GridName(StorageMutability.Immutable);
            string Role     = null;

            Action act = () => new BaseIgniteClass(GridName, Role);

            act.Should().Throw <TRexException>().WithMessage("Role name not defined when acquiring topology projection");

            act = () => new BaseIgniteClass(GridName, "");
            act.Should().Throw <TRexException>().WithMessage("Role name not defined when acquiring topology projection");
        }
Пример #10
0
        /// <summary>
        /// Creates or obtains a reference to an already created change map file buffer queue
        /// </summary>
        private void InstantiateCache()
        {
            var ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Immutable) ??
                         Ignition.GetIgnite(TRexGrids.ImmutableGridName());

            _queueCache = ignite?.GetCache <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem>(
                TRexCaches.SiteModelChangeBufferQueueCacheName());

            if (_queueCache == null)
            {
                Log.LogInformation($"Failed to get Ignite cache {TRexCaches.SiteModelChangeBufferQueueCacheName()}");
                throw new TRexException("Ignite cache not available");
            }
        }
Пример #11
0
        /// <summary>
        /// Creates an appropriate new Ignite client node depending on the TRex Grid it is being attached to
        /// </summary>
        /// <param name="gridName"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public static IgniteServer NewClientNode(string gridName, string role)
        {
            if (gridName.Equals(TRexGrids.MutableGridName()))
            {
                return(new MutableClientServer(role));
            }

            if (gridName.Equals(TRexGrids.ImmutableGridName()))
            {
                return(new ImmutableClientServer(role));
            }

            throw new ArgumentException($"{gridName} is an unknown grid to create a client node within.");
        }
Пример #12
0
        public void AcquireIgniteTopologyProjections_Success()
        {
            var igniteMock = new IgniteMock();

            DIBuilder.Continue()
            .Add(TRexGridFactory.AddGridFactoriesToDI)

            // Override the main Ignite grid factory method DI'ed from TRexGridFactory.AddGridFactoriesToDI()
            .Add(x => x.AddSingleton <Func <string, IgniteConfiguration, IIgnite> >(factory => (gridName, cfg) => igniteMock.mockIgnite.Object))
            .Complete();

            var ignite = new BaseIgniteClass(TRexGrids.GridName(StorageMutability.Immutable), "TestRole");

            ignite.AcquireIgniteTopologyProjections();
        }
Пример #13
0
        public static IIgnite GetIgnite(bool force = false)
        {
            if (!force)
            {
                throw new InvalidOperationException("Running Ignite nodes in unit tests is undesirable if possible...");
            }

            lock (LockObj)
            {
                if (_ignite != null)
                {
                    return(_ignite);
                }

                _ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(TRexGrids.ImmutableGridName(), new IgniteConfiguration());
                return(_ignite);
            }
        }
Пример #14
0
        public void StartTRexGridCacheNode()
        {
            Log.LogInformation("Creating new Ignite node");

            var cfg = new IgniteConfiguration();

            ConfigureTRexGrid(cfg);

            Log.LogInformation($"Creating new Ignite node for {cfg.IgniteInstanceName}");

            try
            {
                Console.WriteLine($"Creating new Ignite node for {cfg.IgniteInstanceName}");
                immutableTRexGrid = DIContext.Obtain <ITRexGridFactory>()?.Grid(TRexGrids.ImmutableGridName(), cfg);
            }
            finally
            {
                Log.LogInformation($"Completed creation of new Ignite node: Exists = {immutableTRexGrid != null}, Factory available = {DIContext.Obtain<ITRexGridFactory>() != null}");
            }

            Log.LogInformation($"Network timeout set to {cfg.NetworkTimeout}");

            // Wait until the grid is active
            DIContext.Obtain <IActivatePersistentGridServer>().WaitUntilGridActive(TRexGrids.ImmutableGridName());

            // Add the immutable Spatial & NonSpatial caches

            InstantiateNonSpatialCacheReference();

            InstantiateSpatialSubGridDirectoryCacheReference();
            InstantiateSpatialSubGridSegmentCacheReference();

            InstantiateSiteModelExistenceMapsCacheReference();

            InstantiateSiteModelsCacheReference();

            InstantiateSiteModelChangeBufferQueueCacheReference();
            InstantiateSiteModelMachinesChangeMapsCacheReference();

            InstantiateDesignTopologyExistenceMapsCache();
        }
Пример #15
0
        public void AcquireIgniteTopologyProjections_FailWithNullComputeProjection()
        {
            var igniteMock = new IgniteMock();

            // Nobble the ICompute setup to mimic a null compute projection
            igniteMock.mockClusterGroup.Setup(x => x.GetCompute()).Returns((ICompute)null);

            DIBuilder.Continue()
            .Add(TRexGridFactory.AddGridFactoriesToDI)

            // Override the main Ignite grid factory method DI'ed from TRexGridFactory.AddGridFactoriesToDI()
            .Add(x => x.AddSingleton <Func <string, IgniteConfiguration, IIgnite> >(factory => (gridName, cfg) => igniteMock.mockIgnite.Object))
            .Complete();

            var GridName = TRexGrids.GridName(StorageMutability.Immutable);
            var Role     = "TestRole";

            Action act = () => new BaseIgniteClass(GridName, Role);

            act.Should().Throw <TRexException>().WithMessage($"Compute projection is null in AcquireIgniteTopologyProjections on grid {GridName}");
        }
Пример #16
0
        public void StartTRexGridCacheNode()
        {
            var cfg = new IgniteConfiguration();

            ConfigureTRexGrid(cfg);

            _log.LogInformation($"Creating new Ignite node for {cfg.IgniteInstanceName}");

            try
            {
                mutableTRexGrid = DIContext.Obtain <ITRexGridFactory>()?.Grid(TRexGrids.MutableGridName(), cfg);
            }
            finally
            {
                _log.LogInformation($"Completed creation of new Ignite node: Exists = {mutableTRexGrid != null}, Factory available = {DIContext.Obtain<ITRexGridFactory>() != null}");
            }

            // Wait until the grid is active
            DIContext.Obtain <IActivatePersistentGridServer>().WaitUntilGridActive(TRexGrids.MutableGridName());

            // Add the mutable Spatial & NonSpatial caches
            InstantiateNonSpatialCacheReference();

            InstantiateSpatialSubGridDirectoryCacheReference();
            InstantiateSpatialSubGridSegmentCacheReference();

            InstantiateTAGFileBufferQueueCacheReference();

            InstantiateSiteModelExistenceMapsCacheReference();
            InstantiateSiteModelsCacheReference();

            InstantiateRebuildSiteModelCacheReferences();

            InstantiateDesignTopologyExistenceMapsCache();

            // Create the SiteModel MetaData Manager so later DI context references wont need to create the cache etc for it at an inappropriate time
            var _ = DIContext.Obtain <ISiteModelMetadataManager>();
        }
Пример #17
0
        public void AcquireIgniteTopologyProjections_FailWithEmptyClusterGroup()
        {
            var igniteMock = new IgniteMock();

            // Nobble the IClusterNodes.Count() setup to mimic an empty cluster group

            igniteMock.mockClusterNodes.Setup(x => x.Count).Returns(0);
            igniteMock.mockCluster.Setup(x => x.GetNodes()).Returns((List <IClusterNode>)null);

            DIBuilder.Continue()
            .Add(TRexGridFactory.AddGridFactoriesToDI)

            // Override the main Ignite grid factory method DI'ed from TRexGridFactory.AddGridFactoriesToDI()
            .Add(x => x.AddSingleton <Func <string, IgniteConfiguration, IIgnite> >(factory => (gridName, cfg) => igniteMock.mockIgnite.Object))
            .Complete();

            string GridName = TRexGrids.GridName(StorageMutability.Immutable);
            string Role     = "TestRole";

            Action act = () => new BaseIgniteClass(GridName, Role);

            act.Should().Throw <TRexException>().WithMessage($"Group cluster topology is empty for role {Role} on grid {GridName}");
        }
Пример #18
0
        public void AcquireIgniteTopologyProjections_FailWithNullIgnite()
        {
            // Ensure any injected IIgnite anf ITRexGridFactory are removed

            DIBuilder.Continue()
            .RemoveSingle <IIgnite>()
            .RemoveSingle <ITRexGridFactory>()
            .Complete();

            var gridName = TRexGrids.GridName(StorageMutability.Immutable);
            var role     = "TestRole";

            Action act = () => _ = new BaseIgniteClass(gridName, role);

            if (DIContext.DefaultIsRequired)
            {
                act.Should().Throw <InvalidOperationException>().WithMessage("No service for type 'VSS.TRex.GridFabric.Grids.ITRexGridFactory' has been registered.");
            }
            else
            {
                act.Should().Throw <TRexException>().WithMessage("Ignite reference is null in AcquireIgniteTopologyProjections");
            }
        }
Пример #19
0
 public QuantizedMeshRequest() : base(TRexGrids.ImmutableGridName(), ServerRoles.QNANTIZED_MESH_NODE)
 {
 }
Пример #20
0
        public void StopListening()
        {
            var listener = new SiteModelAttributesChangedEventListener(TRexGrids.ImmutableGridName());

            listener.StopListening();
        }
Пример #21
0
        /// <summary>
        /// No-arg constructor. Instantiates the continuous query and performs initial scan of elements that the remote filter
        /// will populate into the node-local groupers within the mutable grid.
        /// </summary>
        public SegmentRetirementQueueManager(bool runLocally)
        {
            _log.LogInformation("Establishing segment retirement queue cache context");

            // Get the ignite grid and cache references

            _ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Mutable) ?? Ignition.GetIgnite(TRexGrids.MutableGridName());
            var queueCache = _ignite.GetCache <ISegmentRetirementQueueKey, SegmentRetirementQueueItem>(TRexCaches.SegmentRetirementQueueCacheName());

            // Todo: Create a thread to periodically (needed if we don't go down the service route
            // ....

            _log.LogInformation("Completed segment retirement queue manager initialization");
        }
Пример #22
0
        /// <summary>
        /// Constructor that creates a new server instance with a set of roles
        /// </summary>
        /// <param name="roles"></param>
        public ImmutableClientServer(string[] roles)
        {
            if (immutableTRexGrid == null)
            {
                // Attempt to attach to an already existing Ignite instance
                Log.LogInformation("Getting Immutable grid");
                immutableTRexGrid = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Immutable);
                Log.LogInformation($"Got {immutableTRexGrid?.Name}");

                // If there was no connection obtained, attempt to create a new instance
                if (immutableTRexGrid == null)
                {
                    var roleNames = roles.Aggregate("|", (s1, s2) => s1 + s2 + "|");

                    TRexNodeID = Guid.NewGuid();

                    //Log.LogInformation($"Creating new Ignite node with Roles = {roleNames} & TRexNodeId = {TRexNodeID}");

                    var cfg = new IgniteConfiguration
                    {
                        IgniteInstanceName = TRexGrids.ImmutableGridName(),
                        ClientMode         = true,

                        JvmOptions = new List <string>()
                        {
                            "-DIGNITE_QUIET=false",
                            "-Djava.net.preferIPv4Stack=true",
                            "-XX:+UseG1GC",
                            "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
                            "--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
                            "--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED",
                            "--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED",
                            "--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED",
                            "--illegal-access=permit"
                        },

                        JvmMaxMemoryMb     = DIContext.Obtain <IConfigurationStore>().GetValueInt(IGNITE_JVM_MAX_HEAP_SIZE_MB, DEFAULT_IGNITE_JVM_MAX_HEAP_SIZE_MB),
                        JvmInitialMemoryMb = DIContext.Obtain <IConfigurationStore>().GetValueInt(IGNITE_JVM_INITIAL_HEAP_SIZE_MB, DEFAULT_IGNITE_JVM_INITIAL_HEAP_SIZE_MB),

                        UserAttributes = new Dictionary <string, object>
                        {
                            { "TRexNodeId", TRexNodeID.ToString() }
                        },

                        Logger = new TRexIgniteLogger(DIContext.Obtain <IConfigurationStore>(), Logger.CreateLogger("ImmutableClientServer")),

                        // Set an Ignite metrics heartbeat of 10 seconds
                        MetricsLogFrequency = new TimeSpan(0, 0, 0, 10),

                        PublicThreadPoolSize = DIContext.Obtain <IConfigurationStore>().GetValueInt(IGNITE_PUBLIC_THREAD_POOL_SIZE, DEFAULT_IGNITE_PUBLIC_THREAD_POOL_SIZE),
                        SystemThreadPoolSize = DIContext.Obtain <IConfigurationStore>().GetValueInt(IGNITE_SYSTEM_THREAD_POOL_SIZE, DEFAULT_IGNITE_SYSTEM_THREAD_POOL_SIZE),

                        PeerAssemblyLoadingMode = PeerAssemblyLoadingMode.CurrentAppDomain,

                        BinaryConfiguration = new BinaryConfiguration
                        {
                            Serializer = new BinarizableSerializer()
                        },

                        // Add the TRex progressive request custom thread pool
                        ExecutorConfiguration = new List <ExecutorConfiguration>
                        {
                            new ExecutorConfiguration
                            {
                                Name = BaseIgniteClass.TREX_PROGRESSIVE_QUERY_CUSTOM_THREAD_POOL_NAME,
                                Size = DIContext.Obtain <IConfigurationStore>().GetValueInt(PROGRESSIVE_REQUEST_CUSTOM_POOL_SIZE, DEFAULT_PROGRESSIVE_REQUEST_CUSTOM_POOL_SIZE)
                            }
                        }
                    };

                    foreach (var roleName in roles)
                    {
                        cfg.UserAttributes.Add($"{ServerRoles.ROLE_ATTRIBUTE_NAME}-{roleName}", "True");
                    }

                    bool.TryParse(Environment.GetEnvironmentVariable("IS_KUBERNETES"), out var isKubernetes);
                    cfg = isKubernetes ? setKubernetesIgniteConfiguration(cfg) : setLocalIgniteConfiguration(cfg);

                    try
                    {
                        immutableTRexGrid = DIContext.Obtain <ITRexGridFactory>()?.Grid(TRexGrids.ImmutableGridName(), cfg);
                    }
                    catch (Exception e)
                    {
                        Log.LogError(e, $"Creation of new Ignite node with Role = {roleNames} & TRexNodeId = {TRexNodeID} failed with Exception:");
                        throw;
                    }
                    finally
                    {
                        Log.LogInformation($"Completed creation of new Ignite node with Role = {roleNames} & TRexNodeId = {TRexNodeID}");
                    }
                }
            }
        }
Пример #23
0
 public PassCountStatisticsRequest_ApplicationService() : base(TRexGrids.ImmutableGridName(), ServerRoles.ASNODE)
 {
 }
Пример #24
0
 public PatchRequest() : base(TRexGrids.ImmutableGridName(), ServerRoles.ASNODE)
 {
 }
Пример #25
0
 /// <summary>
 /// Default constructor that configures the request to be sent to the TIN export projection on the immutable data grid
 /// </summary>
 public TINSurfaceRequest() : base(TRexGrids.ImmutableGridName(), ServerRoles.TIN_SURFACE_EXPORT_ROLE)
 {
 }
Пример #26
0
 public TemperatureStatisticsRequest_ApplicationService() : base(TRexGrids.ImmutableGridName(), ServerRoles.ASNODE)
 {
 }
Пример #27
0
        /// <summary>
        /// Executes the life cycle of the service until it is aborted
        /// </summary>
        public void Execute(IServiceContext context)
        {
            try
            {
                _log.LogInformation($"{nameof(SegmentRetirementQueueService)} {context.Name} starting executing");

                _aborted    = false;
                _waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

                // Get the ignite grid and cache references

                var mutableIgnite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Mutable) ?? Ignition.GetIgnite(TRexGrids.MutableGridName());

                if (mutableIgnite == null)
                {
                    _log.LogError("Mutable Ignite reference in service is null - aborting service execution");
                    return;
                }

                // Don't start operations until the local (mutable) grid is confirmed as active
                DIContext.ObtainRequired <IActivatePersistentGridServer>().WaitUntilGridActive(TRexGrids.MutableGridName());

                // Once active, delay start of operations for a time to ensure everything is up and running
                var delay = DIContext.ObtainRequired <IConfigurationStore>().GetValueInt("TREX_SEGMENT_RETIREMENT_QUEUE_SERVICE_OPERATION_START_DELAY_SECONDS", 120);
                _log.LogInformation($"Delaying start of operations for {delay} seconds");
                Thread.Sleep(delay * 1000);

                _log.LogInformation("Obtaining queue cache reference");

                var queueCache = mutableIgnite.GetCache <ISegmentRetirementQueueKey, SegmentRetirementQueueItem>(TRexCaches.TAGFileBufferQueueCacheName());

                var queue   = new SegmentRetirementQueue();
                var handler = new SegmentRetirementQueueItemHandler();

                // Cycle looking for new work to do until aborted...
                do
                {
                    try
                    {
                        // Obtain a specific local mutable storage proxy so as to have a local transactional proxy
                        // for this activity
                        var storageProxy = DIContext.Obtain <IStorageProxyFactory>().MutableGridStorage();

                        if (storageProxy.Mutability != StorageMutability.Mutable)
                        {
                            throw new TRexException("Non mutable storage proxy available to segment retirement queue");
                        }

                        _log.LogInformation("About to query retiree spatial streams from cache");

                        var earlierThan = DateTime.UtcNow - retirementAge;
                        // Retrieve the list of segments to be retired
                        var retirees = queue.Query(earlierThan);

                        // Pass the list to the handler for action
                        var retireesCount = retirees?.Count ?? 0;
                        if (retireesCount > 0)
                        {
                            _log.LogInformation($"About to retire {retireesCount} groups of spatial streams from mutable and immutable contexts");

                            if (handler.Process(storageProxy, queueCache, retirees))
                            {
                                if (_reportDetailedSegmentRetirementActivityToLog)
                                {
                                    _log.LogInformation($"Successfully retired {retireesCount} spatial streams from mutable and immutable contexts");
                                }

                                // Remove the elements from the segment retirement queue
                                queue.Remove(earlierThan);
                            }
                            else
                            {
                                _log.LogError($"Failed to retire {retireesCount} spatial streams from mutable and immutable contexts");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _log.LogError(e, "Exception reported while obtaining new group of retirees to process:");
                    }

                    _waitHandle.WaitOne(SEGMENT_RETIREMENT_QUEUE_SERVICE_CHECK_INTERVAL_MS);
                } while (!_aborted);
            }
            catch (Exception e)
            {
                _log.LogError(e, $"Unhandled exception occurred in {nameof(SegmentRetirementQueueService)}");
            }
            finally
            {
                _log.LogInformation($"{nameof(SegmentRetirementQueueService)} {context.Name} completed executing");
            }
        }
Пример #28
0
 /// <summary>
 /// Default no-arg constructor that sets up cluster and compute projections available for use
 /// </summary>
 public CacheComputePoolRequest() : base(TRexGrids.ImmutableGridName(), ServerRoles.PSNODE)
 {
 }
Пример #29
0
 public RemoveTTMDesignRequest() : base(TRexGrids.MutableGridName(), ServerRoles.DATA_MUTATION_ROLE)
 {
 }
Пример #30
0
 public SimpleVolumesRequest_ApplicationService() : base(TRexGrids.ImmutableGridName(), ServerRoles.ASNODE)
 {
 }