CreateOrUpdateCommand(IModuleManager moduleManager, ModuleSpec moduleSpec, Operation operation) { this.moduleManager = Preconditions.CheckNotNull(moduleManager, nameof(moduleManager)); this.moduleSpec = Preconditions.CheckNotNull(moduleSpec, nameof(moduleSpec)); this.id = new Lazy <string>(() => JsonConvert.SerializeObject(this.moduleSpec).CreateSha256()); this.operation = operation; }
/// <summary> Initialize all members with the given number of tiles and components. /// /// </summary> /// <param name="nt">Number of tiles /// /// </param> /// <param name="nc">Number of components /// /// </param> public DecoderSpecs(int nt, int nc) { // Quantization qts = new QuantTypeSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); qsss = new QuantStepSizeSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); gbs = new GuardBitsSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); // Wavelet transform wfs = new SynWTFilterSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); dls = new IntegerSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); // Component transformation cts = new CompTransfSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); // Entropy decoder ecopts = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); ers = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); cblks = new CBlkSizeSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP); // Precinct partition pss = new PrecinctSizeSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE_COMP, dls); // Codestream nls = new IntegerSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); pos = new IntegerSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); pcs = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); sops = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); ephs = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); pphs = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); iccs = new ModuleSpec(nt, nc, ModuleSpec.SPEC_TYPE_TILE); pphs.setDefault((System.Object)false); }
public async Task CreateModuleAsync(ModuleSpec moduleSpec) { using (HttpClient httpClient = HttpClientHelper.GetHttpClient(this.managementUri)) { var edgeletHttpClient = new EdgeletHttpClient(httpClient) { BaseUrl = HttpClientHelper.GetBaseUrl(this.managementUri) }; await this.Execute(() => edgeletHttpClient.CreateModuleAsync(Constants.EdgeletManagementApiVersion, moduleSpec), $"Create module {moduleSpec.Name}"); } }
public async Task Test_PrepareUpdate_ShouldSucceed(string serverApiVersion, string clientApiVersion) { // Arrange var moduleSpec = new ModuleSpec( "Module1", "Docker", JObject.Parse("{ \"image\": \"testimage\" }"), new ObservableCollection <EnvVar> { new EnvVar("E1", "P1") }); IModuleManager client = new ModuleManagementHttpClient(this.serverUrl, serverApiVersion, clientApiVersion); await client.PrepareUpdateAsync(moduleSpec); }
static CreateOrUpdateCommand Build(IModuleManager moduleManager, IModule module, IModuleIdentity identity, IConfigSource configSource, object settings, Operation operation) { Preconditions.CheckNotNull(moduleManager, nameof(moduleManager)); Preconditions.CheckNotNull(module, nameof(module)); Preconditions.CheckNotNull(identity, nameof(identity)); Preconditions.CheckNotNull(configSource, nameof(configSource)); Preconditions.CheckNotNull(settings, nameof(settings)); IEnumerable <EnvVar> envVars = GetEnvVars(module.Env, identity, configSource); ModuleSpec moduleSpec = BuildModuleSpec(module, envVars, settings); return(new CreateOrUpdateCommand(moduleManager, moduleSpec, operation)); }
internal static ModuleSpec BuildModuleSpec(IModule module, IEnumerable <EnvVar> envVars, object settings) { var moduleSpec = new ModuleSpec { Name = module.Name, Config = new Config { Settings = settings, Env = new ObservableCollection <EnvVar>(envVars) }, Type = module.Type }; return(moduleSpec); }
static ModuleDetails GetModuleDetails(ModuleSpec moduleSpec) { var moduleDetails = new ModuleDetails { Id = Guid.NewGuid().ToString(), Name = moduleSpec.Name, Type = moduleSpec.Type, Status = new Status { ExitStatus = null, RuntimeStatus = new RuntimeStatus { Status = "Created", Description = "Created" }, StartTime = null }, Config = moduleSpec.Config }; return(moduleDetails); }
public PrepareUpdateCommand(IModuleManager moduleManager, IModule module, object settings) { this.moduleManager = moduleManager; this.module = BuildModuleSpec(module, settings); }
public System.Threading.Tasks.Task <ModuleDetails> CreateModule(string api_version, [Microsoft.AspNetCore.Mvc.FromBody] ModuleSpec module) { return(_implementation.CreateModuleAsync(api_version, module)); }
public Task UpdateAndStartModuleAsync(ModuleSpec moduleSpec) => throw new NotImplementedException();
public Task PrepareUpdateModuleAsync(string api_version, string name, ModuleSpec module) => Task.CompletedTask;
public Task PrepareUpdateAsync(ModuleSpec moduleSpec) => this.inner.PrepareUpdateAsync(moduleSpec);
public async Task ModulesTest() { // Arrange IModuleManager client = new ModuleManagementHttpClient(this.serverUrl); var moduleSpec = new ModuleSpec { Name = "Module1", Type = "Docker", Config = new Config { Env = new System.Collections.ObjectModel.ObservableCollection <EnvVar> { new EnvVar { Key = "E1", Value = "P1" } }, Settings = "{ \"image\": \"testimage\" }" } }; // Act await client.CreateModuleAsync(moduleSpec); ModuleDetails moduleDetails = (await client.GetModules(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal("Module1", moduleDetails.Name); Assert.NotNull(moduleDetails.Id); Assert.Equal("Docker", moduleDetails.Type); Assert.NotNull(moduleDetails.Status); Assert.Equal("Created", moduleDetails.Status.RuntimeStatus.Status); // Act await client.StartModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal("Running", moduleDetails.Status.RuntimeStatus.Status); // Act await client.StopModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal("Stopped", moduleDetails.Status.RuntimeStatus.Status); // Act - Stopping a stopped module should not throw await client.StopModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal("Stopped", moduleDetails.Status.RuntimeStatus.Status); // Act await client.DeleteModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules(CancellationToken.None)).FirstOrDefault(); // Assert Assert.Null(moduleDetails); }
public System.Threading.Tasks.Task PrepareUpdateModule(string api_version, string name, [Microsoft.AspNetCore.Mvc.FromBody] ModuleSpec module) { return(_implementation.PrepareUpdateModuleAsync(api_version, name, module)); }
public System.Threading.Tasks.Task <ModuleDetails> UpdateModule(string api_version, string name, bool?start, [Microsoft.AspNetCore.Mvc.FromBody] ModuleSpec module) { return(_implementation.UpdateModuleAsync(api_version, name, start ?? false, module)); }
public Task CreateModuleAsync(ModuleSpec moduleSpec) => this.inner.CreateModuleAsync(moduleSpec);
public Task UpdateAndStartModuleAsync(ModuleSpec moduleSpec) => this.inner.UpdateAndStartModuleAsync(moduleSpec);
public Task UpdateModuleAsync(ModuleSpec moduleSpec) => this.Throttle(() => this.inner.UpdateModuleAsync(moduleSpec));
public async Task ModulesTest(string serverApiVersion, string clientApiVersion) { // Arrange IModuleManager client = new ModuleManagementHttpClient(this.serverUrl, serverApiVersion, clientApiVersion); var moduleSpec = new ModuleSpec("Module1", "Docker", JObject.Parse("{ \"image\": \"testimage\" }"), new ObservableCollection <EnvVar> { new EnvVar("E1", "P1") }); // Act await client.CreateModuleAsync(moduleSpec); ModuleRuntimeInfo moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal("Module1", moduleDetails.Name); Assert.Equal("Docker", moduleDetails.Type); Assert.Equal(ModuleStatus.Unknown, moduleDetails.ModuleStatus); // Act await client.StartModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal(ModuleStatus.Running, moduleDetails.ModuleStatus); // Act await client.StopModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal(ModuleStatus.Stopped, moduleDetails.ModuleStatus); // Act await client.RestartModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal(ModuleStatus.Running, moduleDetails.ModuleStatus); // Act moduleSpec.EnvironmentVariables.ToList().Add(new EnvVar("test", "added")); await client.UpdateModuleAsync(moduleSpec); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal(ModuleStatus.Unknown, moduleDetails.ModuleStatus); // Act moduleSpec.EnvironmentVariables.ToList().Add(new EnvVar("test", "added")); await client.UpdateAndStartModuleAsync(moduleSpec); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal(ModuleStatus.Running, moduleDetails.ModuleStatus); // Act - Stopping a stopped module should not throw await client.StopModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.NotNull(moduleDetails); Assert.Equal(ModuleStatus.Stopped, moduleDetails.ModuleStatus); // Act await client.DeleteModuleAsync(moduleSpec.Name); moduleDetails = (await client.GetModules <TestConfig>(CancellationToken.None)).FirstOrDefault(); // Assert Assert.Null(moduleDetails); }
public Task PrepareUpdateAsync(ModuleSpec moduleSpec) => this.Throttle(() => this.inner.PrepareUpdateAsync(moduleSpec));
public Task <ModuleDetails> UpdateModuleAsync(string apiVersion, string name, bool start, ModuleSpec module) { if (!this.modules.ContainsKey(name)) { throw new InvalidOperationException("Module not found"); } var moduleDetails = GetModuleDetails(module); if (start) { moduleDetails.Status.RuntimeStatus.Status = "Running"; } this.modules[module.Name] = moduleDetails; return(Task.FromResult(this.modules[module.Name])); }
public abstract Task UpdateModuleAsync(ModuleSpec moduleSpec);
public Task <ModuleDetails> CreateModuleAsync(string apiVersion, ModuleSpec module) { ModuleDetails createdModule = this.modules.GetOrAdd(module.Name, (n) => GetModuleDetails(module)); return(Task.FromResult(createdModule)); }
public abstract Task UpdateAndStartModuleAsync(ModuleSpec moduleSpec);
public Task CreateModuleAsync(ModuleSpec moduleSpec) => throw new NotImplementedException();
public abstract Task PrepareUpdateAsync(ModuleSpec moduleSpec);
public Task PrepareUpdateAsync(ModuleSpec moduleSpec) => throw new NotImplementedException();
/// <summary> This function parses the values given for the ROIs with the argument /// -Rroi. Currently only circular and rectangular ROIs are supported. /// /// <p>A rectangular ROI is indicated by a 'R' followed the coordinates for /// the upper left corner of the ROI and then its width and height.</p> /// /// <p>A circular ROI is indicated by a 'C' followed by the coordinates of /// the circle center and then the radius.</p> /// /// <p>Before the R and C values, the component that are affected by the /// ROI are indicated.</p> /// /// </summary> /// <param name="roiopt">The info on the ROIs /// /// </param> /// <param name="nc">number of components /// /// </param> /// <param name="roiVector">The vcector containing the ROI parsed from the cmd line /// /// </param> /// <returns> The ROIs specified in roiopt /// /// </returns> protected internal static System.Collections.ArrayList parseROIs(System.String roiopt, int nc, System.Collections.ArrayList roiVector) { //ROI[] ROIs; ROI roi; SupportClass.Tokenizer stok; //char tok; int nrOfROIs = 0; //char c; int ulx, uly, w, h, x, y, rad; // comp removed bool[] roiInComp = null; stok = new SupportClass.Tokenizer(roiopt); System.String word; while (stok.HasMoreTokens()) { word = stok.NextToken(); switch (word[0]) { case 'c': // Components specification roiInComp = ModuleSpec.parseIdx(word, nc); break; case 'R': // Rectangular ROI to be read nrOfROIs++; try { word = stok.NextToken(); ulx = (System.Int32.Parse(word)); word = stok.NextToken(); uly = (System.Int32.Parse(word)); word = stok.NextToken(); w = (System.Int32.Parse(word)); word = stok.NextToken(); h = (System.Int32.Parse(word)); } catch (System.FormatException) { throw new System.ArgumentException("Bad parameter for " + "'-Rroi R' option : " + word); } catch (System.ArgumentOutOfRangeException) { throw new System.ArgumentException("Wrong number of " + "parameters for " + "h'-Rroi R' option."); } // If the ROI is component-specific, check which comps. if (roiInComp != null) { for (int i = 0; i < nc; i++) { if (roiInComp[i]) { roi = new ROI(i, ulx, uly, w, h); roiVector.Add(roi); } } } else { // Otherwise add ROI for all components for (int i = 0; i < nc; i++) { roi = new ROI(i, ulx, uly, w, h); roiVector.Add(roi); } } break; case 'C': // Circular ROI to be read nrOfROIs++; try { word = stok.NextToken(); x = (System.Int32.Parse(word)); word = stok.NextToken(); y = (System.Int32.Parse(word)); word = stok.NextToken(); rad = (System.Int32.Parse(word)); } catch (System.FormatException) { throw new System.ArgumentException("Bad parameter for " + "'-Rroi C' option : " + word); } catch (System.ArgumentOutOfRangeException) { throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi C' option."); } // If the ROI is component-specific, check which comps. if (roiInComp != null) { for (int i = 0; i < nc; i++) { if (roiInComp[i]) { roi = new ROI(i, x, y, rad); roiVector.Add(roi); } } } else { // Otherwise add ROI for all components for (int i = 0; i < nc; i++) { roi = new ROI(i, x, y, rad); roiVector.Add(roi); } } break; case 'A': // ROI wth arbitrary shape nrOfROIs++; System.String filename; ImgReaderPGM maskPGM = null; try { filename = stok.NextToken(); } catch (System.ArgumentOutOfRangeException) { throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi A' option."); } try { maskPGM = new ImgReaderPGM(filename); } catch (System.IO.IOException) { throw new System.ApplicationException("Cannot read PGM file with ROI"); } // If the ROI is component-specific, check which comps. if (roiInComp != null) { for (int i = 0; i < nc; i++) { if (roiInComp[i]) { roi = new ROI(i, maskPGM); roiVector.Add(roi); } } } else { // Otherwise add ROI for all components for (int i = 0; i < nc; i++) { roi = new ROI(i, maskPGM); roiVector.Add(roi); } } break; default: throw new System.ApplicationException("Bad parameters for ROI nr " + roiVector.Count); } } return(roiVector); }