internal object GetVertexParam() { string storageConnectionString = null; #if !DOTNETCORE storageConnectionString = ConfigurationManager.AppSettings.Get("AZURE_STORAGE_CONN_STRING"); #endif if (storageConnectionString == null) { storageConnectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING"); } if (storageConnectionString == null) { throw new InvalidOperationException("Azure storage connection string not found. Use appSettings in your app.config to provide this using the key AZURE_STORAGE_CONN_STRING, or use the environment variable AZURE_STORAGE_CONN_STRING."); } CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); string blobName = VertexName + "-" + InstanceName; CloudBlobContainer container = blobClient.GetContainerReference("cra"); container.CreateIfNotExistsAsync().Wait(); var blockBlob = container.GetBlockBlobReference(VertexDefinition + "/" + blobName); Stream blobStream = blockBlob.OpenReadAsync().GetAwaiter().GetResult(); byte[] parameterBytes = blobStream.ReadByteArray(); string parameterString = Encoding.UTF8.GetString(parameterBytes); blobStream.Close(); return(SerializationHelper.DeserializeObject(parameterString)); }
public async Task InitializeVertexAsync(string vertexName, string vertexDefinition, string instanceName, ConcurrentDictionary <string, IVertex> table, CloudBlobContainer container, IVertex vertex) { // INITIALIZE if ((VertexBase)vertex != null) { ((VertexBase)vertex).VertexName = vertexName; ((VertexBase)vertex).ClientLibrary = this; } // LATCH CALLBACKS TO POPULATE ENDPOINT TABLE vertex.OnAddInputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, true, false)); vertex.OnAddOutputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, false, false)); vertex.OnAddAsyncInputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, true, true)); vertex.OnAddAsyncOutputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, false, true)); //ADD TO TABLE if (table != null) { table.AddOrUpdate(vertexName, vertex, (procName, oldProc) => { oldProc.Dispose(); return(vertex); }); vertex.OnDispose(() => { // Delete all endpoints of the vertex foreach (var key in vertex.InputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } foreach (var key in vertex.AsyncInputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } foreach (var key in vertex.OutputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } foreach (var key in vertex.AsyncOutputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } IVertex old; if (!table.TryRemove(vertexName, out old)) { Console.WriteLine("Unable to remove vertex on disposal"); } var entity = new DynamicTableEntity(instanceName, vertexName); entity.ETag = "*"; TableOperation deleteOperation = TableOperation.Delete(entity); _vertexTable.ExecuteAsync(deleteOperation).Wait(); }); } string blobName = vertexName + "-" + instanceName; var parametersBlob = container.GetBlockBlobReference(vertexDefinition + "/" + blobName); Stream parametersStream = parametersBlob.OpenReadAsync().GetAwaiter().GetResult(); byte[] parametersBytes = parametersStream.ReadByteArray(); string parameterString = Encoding.UTF8.GetString(parametersBytes); parametersStream.Close(); var par = SerializationHelper.DeserializeObject(parameterString); vertex.Initialize(par); await vertex.InitializeAsync(par); // Activate vertex ActivateVertex(vertexName, instanceName); }
public async Task InitializeVertexAsync( string vertexName, string vertexDefinition, string instanceName, ConcurrentDictionary <string, IVertex> table, IVertex vertex) { // INITIALIZE if ((VertexBase)vertex != null) { ((VertexBase)vertex).VertexName = vertexName; ((VertexBase)vertex).ClientLibrary = this; } // LATCH CALLBACKS TO POPULATE ENDPOINT TABLE vertex.OnAddInputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, true, false)); vertex.OnAddOutputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, false, false)); vertex.OnAddAsyncInputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, true, true)); vertex.OnAddAsyncOutputEndpoint((name, endpt) => _endpointTableManager.AddEndpoint(vertexName, name, false, true)); //ADD TO TABLE if (table != null) { table.AddOrUpdate(vertexName, vertex, (procName, oldProc) => { oldProc.Dispose(); return(vertex); }); vertex.OnDispose(() => { // Delete all endpoints of the vertex foreach (var key in vertex.InputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } foreach (var key in vertex.AsyncInputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } foreach (var key in vertex.OutputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } foreach (var key in vertex.AsyncOutputEndpoints) { _endpointTableManager.DeleteEndpoint(vertexName, key.Key); } IVertex old; if (!table.TryRemove(vertexName, out old)) { Console.WriteLine("Unable to remove vertex on disposal"); } Task.Run(() => _vertexManager.DeleteInstanceVertex( instanceName, vertexName)); }); } string blobName = vertexName + "-" + instanceName; string parameterString; using (var parametersStream = await _blobStorage.GetReadStream(vertexDefinition + "/" + blobName)) { byte[] parametersBytes = parametersStream.ReadByteArray(); parameterString = Encoding.UTF8.GetString(parametersBytes); } var par = SerializationHelper.DeserializeObject(parameterString); await vertex.InitializeAsync(par); // Activate vertex await ActivateVertexAsync(vertexName, instanceName); }