예제 #1
0
        public IEvent GetDefinition(EventDefinitionHandle handle)
        {
            if (handle.IsNil)
            {
                return(null);
            }
            if (eventDefs == null)
            {
                return(new MetadataEvent(this, handle));
            }
            int row = MetadataTokens.GetRowNumber(handle);

            Debug.Assert(row != 0);
            if (row >= methodDefs.Length)
            {
                HandleOutOfRange(handle);
            }
            var ev = LazyInit.VolatileRead(ref eventDefs[row]);

            if (ev != null)
            {
                return(ev);
            }
            ev = new MetadataEvent(this, handle);
            return(LazyInit.GetOrSet(ref eventDefs[row], ev));
        }
        public override async Task <DataInjectionReply> InjectData(DataInjectionRequest request, ServerCallContext context)
        {
            var results = new List <MetadataEvent>(request.Count);

            _logger.LogInformation("Received request to inject data");
            for (int i = 0; i < request.Count; i++)
            {
                var fileName = Guid.NewGuid().ToString();
                await using (
                    var file = File.OpenWrite($"{permStoragePath}/{fileName}"))
                {
                    await using (
                        var writer = new BinaryWriter(file))
                    {
                        // write 1 KB at a time on the file
                        for (int j = 0; j < request.ContentSize / 1024; j++)
                        {
                            var content = new byte[1024];
                            new Random().NextBytes(content);

                            writer.Write(content);
                            writer.Flush();
                        }
                    }
                }

                _localFiles[fileName] = 1;

                var localFileSystemMetadata = new LocalFileSystemMetadata
                {
                    FileName = fileName
                };

                var metadata = Any.Pack(localFileSystemMetadata);
                var @event   = new MetadataEvent
                {
                    Metadata         = metadata,
                    DataLocalization = this._localization
                };
                await _dataMasterClient.PublishFile(fileName);

                results.Add(@event);
            }

            var ret = new DataInjectionReply();

            ret.Events.AddRange(results);
            return(ret);
        }
        /// <summary>
        /// Copies the file from the "permanent" storage to the destination path.
        /// </summary>
        /// <param name="metadata">The metadata used to identify the </param>
        /// <param name="destinationPath"></param>
        /// <returns></returns>
        public async Task PullDataFromStorage(MetadataEvent metadata, string destinationPath)
        {
            var localFileSystemMetadata = metadata.Metadata.Unpack <LocalFileSystemMetadata>();

            if (this._localFiles.ContainsKey(localFileSystemMetadata.FileName))
            {
                var permanentStoragePath = $"{_permanentStorageBasePath}/{localFileSystemMetadata.FileName}";

                var activity = _activitySource.StartActivity("MoveToPodVolume");
                activity.Start();
                if (!_useHardLinking)
                {
                    File.Copy(permanentStoragePath, destinationPath);

                    if (_configuration["DeleteDataAfterUse"] == "true")
                    {
                        // Delete the file from the permanent storage.
                        File.Delete(permanentStoragePath);
                    }
                }
                else
                {
                    await CreateHardLink(permanentStoragePath, destinationPath);

                    if (_configuration["DeleteDataAfterUse"] == "true")
                    {
                        // Delete the file from the permanent storage.
                        File.Delete(permanentStoragePath);
                    }
                }
                activity.Stop();
            }
            else
            {
                // need to get the node ip of the hosting the data so I can actually get it from there
                var addr = await this._dataMaster.GetAddressForFile(localFileSystemMetadata.FileName);

                // Get the service for the peer hosting the data I am interested in
                var peer = this._peerPool.GetPeerClient(addr.Address);

                // Download the data from the peer directly to the destination path
                await peer.DownloadDataFromPeer(localFileSystemMetadata.FileName, destinationPath, addr.Localization);
            }
        }
        /// <summary>
        /// Copies the file found at the source filepath to a "permanent" storage
        /// </summary>
        /// <param name="filePath">The source filepath</param>
        /// <returns><see cref="MetadataEvent"/> containing information about where in the "permanent" storage the file was stored</returns>
        public async Task <MetadataEvent> PushDataToStorage(string filePath)
        {
            this._logger.LogInformation($"Pushing data to storage from: {filePath}");
            var destinationFileNameGuid = Guid.NewGuid();

            var activity = _activitySource.StartActivity("MoveToPermStorage");

            activity.Start();
            if (!_useHardLinking)
            {
                File.Copy(filePath, $"{_permanentStorageBasePath}/{destinationFileNameGuid}");
            }
            else
            {
                await CreateHardLink(filePath, $"{_permanentStorageBasePath}/{destinationFileNameGuid}");
            }
            activity.Stop();

            this._logger.LogInformation($"The data in permanent storage is {_permanentStorageBasePath}/{destinationFileNameGuid}");
            var localFileSystemMetadata = new LocalFileSystemMetadata
            {
                FileName = destinationFileNameGuid.ToString()
            };

            var metadata = Any.Pack(localFileSystemMetadata);
            var @event   = new MetadataEvent
            {
                Metadata         = metadata,
                DataLocalization = this._localization
            };

            // store this guy in the local files as well.
            _localFiles[destinationFileNameGuid.ToString()] = 1;

            // Publish the information that the data chunk is now available
            await _dataMaster.PublishFile(destinationFileNameGuid.ToString());

            return(@event);
        }
예제 #5
0
        private void ReadLogFileChunk_Type(MetadataEvent t)
        {
            if (t.MType != MetadataEvent.MetaDataType.Class)
            {
                return;
            }

            TypeInfo ti = new TypeInfo();

            ti.Code        = t.Pointer + currentPtrBase;
            ti.Name        = t.Name;
            ti.FieldsIndex = currentData.FieldCodes.Count;

            int nf = 0;

/*			uint fcode;
 *                      while ((fcode = reader.ReadUInt32 ()) != 0) {
 *                              fieldCodes.Add (fcode);
 *                              fieldNamesList.Add (reader.ReadString ());
 *                              nf++;
 *                      }*/
            ti.FieldsCount = nf;
            currentData.TypesList.Add(ti);
        }