Ejemplo n.º 1
0
        public override bool OnStart()
        {
            DumplingEventHub.FireEvent(new DataWorkerStartEvent()).Wait();
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            return(base.OnStart());
        }
        public async Task <string> GetStatus(string owner, string dumplingid)
        {
            await DumplingEventHub.FireEvent(new WebAPIGetStatusEvent());

            return(await StateTableController.GetState(new StateTableIdentifier()
            {
                Owner = owner, DumplingId = dumplingid
            }));
        }
Ejemplo n.º 3
0
        public override void OnStop()
        {
            DumplingEventHub.FireEvent(new DataWorkerStopEvent()).Wait();

            // Close the connection to Service Bus Queue
            DumplingDataWorkerQueueController.Queue.Close();
            _completedEvent.Set();
            base.OnStop();
        }
        public override bool OnStart()
        {
            // Before events or anything else can happen, we have to do this.
            NearbyConfig.RetrieveSecretsAsync(ConfigurationManager.AppSettings["dumpling_ad_client_id"], ConfigurationManager.AppSettings["thumbprint"]).Wait();
            DumplingEventHub.FireEvent(new DataWorkerStartEvent()).Wait();
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            return(base.OnStart());
        }
Ejemplo n.º 5
0
        public override void Run()
        {
            DumplingEventHub.FireEvent(new DataWorkerRunEvent()).Wait();
            Trace.WriteLine("Starting processing of messages");


            // start a background task that queries Helix for data.
            Task.Run(HelixEventProxy.PollTrackedHelixWorkItems);

            // initiates the message pump and callback is invoked for each message that is received, calling close on the client will stop the pump.
            DumplingDataWorkerQueueController.Queue.OnMessageAsync(async(receivedMessage) =>
            {
                Trace.WriteLine("processing service bus message: " + receivedMessage.SequenceNumber.ToString());
                try
                {
                    // Process the message
                    if (receivedMessage.Properties.ContainsKey("data_type") && (receivedMessage.Properties["data_type"] is string))
                    {
                        var key        = receivedMessage.Properties["data_type"] as string;
                        var dumplingId = receivedMessage.Properties["dumpling_id"] as string;
                        var body       = receivedMessage.GetBody <Stream>();

                        await receivedMessage.CompleteAsync();

                        // TODO: Debug/Understand: the received message is disposed of after the await call returns. Is this a framework/runtime bug?
                        await DumplingEventHub.FireEvent(new DataWorkerMessageReceivedEvent());
                        using (var reader = new StreamReader(body))
                        {
                            await _dataHandler[key](int.Parse(dumplingId), await reader.ReadToEndAsync());
                        }

                        await DumplingEventHub.FireEvent(new DataWorkerCompletedMessageEvent());
                    }
                    else
                    {
                        Trace.WriteLine("message does not contain a 'data_type' property, or the 'data_type' property is not a string, and so we do not know how to route it. this message will be deadlettered.");
                        await receivedMessage.DeadLetterAsync();
                        await DumplingEventHub.FireEvent(new DataWorkerDeadLetterEvent());
                    }
                }
                catch (Exception e)
                {
                    await DumplingEventHub.FireEvent(new DataWorkerExceptionEvent());
                    // Handle any message processing specific exceptions here
                    Trace.WriteLine($"all catching exception of doom.\n{e}");
                }
            });

            _completedEvent.WaitOne();
        }
Ejemplo n.º 6
0
        private static void FireHelixWorkItemProxyEventsForPath(JObject data, string path, ref int current)
        {
            try
            {
                // fire off initial events
                switch (data.SelectToken(path).Type)
                {
                case JTokenType.Integer:
                    for (; current < data.SelectToken(path).ToObject <int>(); current++)
                    {
                        DumplingEventHub.FireEvent(new HelixServiceProxyWorkItemsStatusEvent(path));
                    }
                    break;

                default:
                    Console.WriteLine("count information type needs to be an int.");
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"could not fire helix work item events: {e}");
            }
        }
        public async Task <string> SayHi(string name)
        {
            await DumplingEventHub.FireEvent(new WebAPIGreetingEvent());

            return($"Hi {name}. I am v.{_version} of the dumpling service.");
        }
        public async Task <string> PostDumpChunk(string owner, string targetos, int index, ulong filesize, string displayName = "")
        {
            if (index > 0 || filesize > int.MaxValue)
            {
                throw new NotSupportedException("We do not support chunked files yet, and the file must be <= 2GB or more specifically, int.MaxValue");
            }

            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            owner    = owner.ToLowerInvariant();
            targetos = targetos.ToLowerInvariant();

            await DumplingEventHub.FireEvent(new WebAPIStartUploadChunkEvent());

            /* Handle Upload */
            // Get or create the blob container
            var container = DumpStorageController.GetContainerForOwner(owner);
            await container.CreateIfNotExistsAsync();

            // Create a AzureBlobStorageMultipartProvider and process the request
            var path = Path.GetTempPath();
            AzureBlobStorageMultipartProvider streamProvider = new AzureBlobStorageMultipartProvider(container, path);

            await Request.Content.ReadAsMultipartAsync <AzureBlobStorageMultipartProvider>(streamProvider);

            await DumplingEventHub.FireEvent(new WebAPIFinishedUploadChunkEvent());

            /* Meta data handling */
            var dump_uri = streamProvider.AzureBlobs.First().Location;

            if (displayName == string.Empty)
            {
                displayName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            }

            int dumplingid = await TriageDb.AddDumpAsync(new Dump()
            {
                DumpTime    = DateTime.Now,
                DumpPath    = dump_uri,
                DisplayName = displayName,
                Origin      = owner
            });


            StateTableIdentifier id = new StateTableIdentifier()
            {
                Owner      = owner,
                DumplingId = dumplingid.ToString(),
            };

            await AnalysisTopicController.EnqueueAnalysisWork(owner, dumplingid.ToString(), targetos, dump_uri);

            // let the dumpling services know about our dumpling
            await StateTableController.AddOrUpdateStateEntry(new StateTableEntity(id)
            {
                DumpRelics_uri = dump_uri,
                OriginatingOS  = targetos,
                State          = "enqueued"
            });

            // Return result from storing content in the blob container
            return(dumplingid.ToString());
        }