Ejemplo n.º 1
0
        public async Task DoRemove(Identifier id, LogHandler logCallback, ProgressHandler progressCallback)
        {
            var installedPackInfo = LocalRegistry.QueryInstalledPackage(this, id);

            DependencyHelper.CheckCanRemove(this, id);
            await LocalRegistry.DoRemove(this, id, logCallback, progressCallback);
        }
Ejemplo n.º 2
0
        public async Task DoInstall(IEnumerable <Tuple <Identifier, Version, string> > sequence, LogHandler logCallback, ProgressHandler progressCallback)
        {
            foreach (var tempFile in sequence)
            {
                // Let the LocalRegistry decide if removal is needed
                logCallback(LogLevel.Info, Translation.Translate("bpmcore_context_installing", tempFile));
                await LocalRegistry.DoInstall(this, tempFile.Item3, logCallback, progressCallback);

                System.IO.File.Delete(tempFile.Item3);
            }
        }
Ejemplo n.º 3
0
        public async Task TestRegistryBuildAsync()
        {
            using (var localRegistry = new LocalRegistry(5000))
            {
                await localRegistry.StartAsync();

                var properties = new Dictionary <string, string>
                {
                    ["PublishProvider"]            = "FibDotNet",
                    ["FibPublishType"]             = "Push",
                    ["FibTargetRegistry"]          = "localhost:5000",
                    ["FibAllowInsecureRegistries"] = "True",
                    ["FibPort"] = "80"
                };
                string propertiesString = string.Join(" ", properties.Select(kvp => $"-p:{kvp.Key}={kvp.Value}"));
                string arguments        = $"publish {TestProjectName} {propertiesString}";
                var    p = Process.Start(
                    new ProcessStartInfo("dotnet", arguments)
                {
                    UseShellExecute        = false,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true
                });
                p.EnableRaisingEvents = true;
                var stdOutTask = p.StandardOutput.ReadToEndAsync();
                var stdErrTask = p.StandardError.ReadToEndAsync();
                var tcs        = new TaskCompletionSource <int>();
                p.Exited += (sender, args) => tcs.TrySetResult(p.ExitCode);
                if (!p.HasExited)
                {
                    await tcs.Task;
                }

                TestContext.WriteLine(await stdOutTask);
                TestContext.WriteLine(await stdErrTask);

                Assert.AreEqual(0, p.ExitCode);

                string imageReference = "localhost:5000/" + TestProjectName.ToLowerInvariant() + ":" + TestProjectVersion;
                Command.Run("docker", "pull", imageReference);
                string dockerPortsEnv = Command.Run("docker", "inspect", imageReference, "-f", "{{.Config.ExposedPorts}}");
                Assert.That(dockerPortsEnv, Does.Contain("80/tcp"));
                string dockerConfigEnv =
                    Command.Run("docker", "inspect", "-f", "{{.Config.Env}}", imageReference);
                Assert.That(dockerConfigEnv, Does.Contain("ASPNETCORE_URLS=http://+:80"));

                string history = Command.Run("docker", "history", imageReference);
                Assert.That(history, Does.Contain("Fib.Net.MSBuild"));

                Command.Run("docker", "image", "rm", imageReference);
            }
        }
        private LocalRegistry Join3Nodes()
        {
            var registry = new LocalRegistry(Config.NodeMatching(Id.Of(3)), Config, TestWorld.DefaultLogger);
            var node1    = NodeOf(1);
            var node2    = NodeOf(2);
            var node3    = NodeOf(3);

            registry.Join(node1);
            registry.Join(node2);
            registry.Join(node3);

            return(registry);
        }
        public void TestNoLiveNodes()
        {
            var registry = new LocalRegistry(Config.NodeMatching(Id.Of(3)), Config, TestWorld.DefaultLogger);

            Assert.Empty(registry.LiveNodes);
        }
Ejemplo n.º 6
0
        public void MetricsRegistryDowsNotThrowOnMetricsOfDifferentTypeWithSameName()
        {
            var registry = new LocalRegistry();

            ((Action)(() => AddMetrics(registry))).ShouldNotThrow();
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <Tuple <Identifier, Version, string> > > DoFetch(Identifier id, VersionRange range, LogHandler logCallback, ProgressHandler progressCallback)
        {
            // TODO: Throw exception on circular reference

            var resolveQueue       = new Queue <Tuple <Identifier, VersionRange, string> >();
            var revInstallSequence = new List <Tuple <Identifier, Version, string> >();

            resolveQueue.Enqueue(new Tuple <Identifier, VersionRange, string>(id, range, ""));
            while (resolveQueue.Count > 0)
            {
                var elem = resolveQueue.Dequeue();
                RemotePackageInfo remotePack = null;
                if (!elem.Item1.HasGuid || !elem.Item1.HasName)
                {
                    // Get the full identifier first, so that installed package can be queried better
                    logCallback(LogLevel.Info, Translation.Translate("bpmcore_context_downloadmetadata", elem.Item1));
                    remotePack = await CachedQueryRemotePackage(elem.Item1);

                    if (remotePack == null)
                    {
                        if (string.IsNullOrEmpty(elem.Item3))
                        {
                            throw new PackageNotFoundException(this, elem.Item1);
                        }
                        else
                        {
                            throw new DependencyException(this, elem.Item1.ToString(), elem.Item3, new PackageNotFoundException(this, elem.Item1));
                        }
                    }
                    else
                    {
                        var newIdentifier = elem.Item1;
                        if (!newIdentifier.HasGuid && remotePack.ID.HasGuid)
                        {
                            newIdentifier.Guid    = remotePack.ID.Guid;
                            newIdentifier.HasGuid = true;
                        }
                        if (!newIdentifier.HasName && remotePack.ID.HasName)
                        {
                            newIdentifier.Name    = remotePack.ID.Name;
                            newIdentifier.HasName = true;
                        }
                        elem = new Tuple <Identifier, VersionRange, string>(newIdentifier, elem.Item2, elem.Item3);
                    }
                }
                var installedPackInfo = LocalRegistry.QueryInstalledPackage(this, elem.Item1);

                // Skip if the dependency is already installed and the version satisfies the requirement
                if (installedPackInfo != null && elem.Item2.ContainsVersion(installedPackInfo.Version))
                {
                    logCallback(LogLevel.Debug, Translation.Translate("bpmcore_context_alreadyinstalled", elem.Item1.ToString(), installedPackInfo.Version));
                    continue;
                }

                // Get the remote metadata
                if (remotePack == null)
                {
                    logCallback(LogLevel.Info, Translation.Translate("bpmcore_context_downloadmetadata", elem.Item1));
                    remotePack = await CachedQueryRemotePackage(elem.Item1);

                    if (remotePack == null)
                    {
                        if (string.IsNullOrEmpty(elem.Item3))
                        {
                            throw new PackageNotFoundException(this, elem.Item1);
                        }
                        else
                        {
                            throw new DependencyException(this, elem.Item1.ToString(), elem.Item3, new PackageNotFoundException(this, elem.Item1));
                        }
                    }
                }
                // Check other dependncies for a highest suitable version
                var installable = DependencyHelper.GetSuitableVersion(this, remotePack, elem.Item3, elem.Item2);
                logCallback(LogLevel.Info, Translation.Translate("bpmcore_context_willinstall", elem.Item1, installable.Item1));
                if (installable.Item1 < remotePack.AvailableVersions.Keys.Last())
                {
                    logCallback(LogLevel.Warning, Translation.Translate("bpmcore_context_cannotlatest",
                                                                        remotePack.AvailableVersions.Keys.Last(), remotePack.ID));
                }

                // Download the file from internet
                logCallback(LogLevel.Info, Translation.Translate("bpmcore_context_downloading", installable.Item2));
                var tempFile = await DownloadManager.AcquirePackage(this, elem.Item1, installable.Item1, installable.Item2, progressCallback);

                // Push further dependencies into the queue
                var packInfo = LocalRegistry.QueryExternalPackage(this, tempFile);
                logCallback(LogLevel.Debug, Translation.Translate("bpmcore_context_requires", packInfo.ID, string.Join(",", packInfo.Dependencies.Select(t => t.Key.ToString() + t.Value))));
                foreach (var dependency in packInfo.Dependencies)
                {
                    resolveQueue.Enqueue(new Tuple <Identifier, VersionRange, string>(dependency.Key, dependency.Value, packInfo.PlainName));
                }

                if (revInstallSequence.Any(t => t.Item3 == tempFile))
                {
                    revInstallSequence.Remove(revInstallSequence.Single(t => t.Item3 == tempFile));
                }
                revInstallSequence.Add(new Tuple <Identifier, Version, string>(remotePack.ID, installable.Item1, tempFile));
            }
            revInstallSequence.Reverse();
            return(revInstallSequence);
        }
Ejemplo n.º 8
0
        public async Task TestOfflineAsync()
        {
            SystemPath cacheDirectory = cacheFolder.GetRoot().ToPath();

            ImageReference targetImageReferenceOnline =
                ImageReference.Of("localhost:5001", "fibdotnet-core", "basic-online");
            ImageReference targetImageReferenceOffline =
                ImageReference.Of("localhost:5001", "fibdotnet-core", "basic-offline");

            FibContainerBuilder fibContainerBuilder =
                FibContainerBuilder.From("localhost:5001/busybox").SetEntrypoint("echo", "Hello World");

            // Should fail since Fib can't build to registry offline
            try
            {
                await fibContainerBuilder.ContainerizeAsync(
                    Containerizer.To(RegistryImage.Named(targetImageReferenceOffline)).SetOfflineMode(true)).ConfigureAwait(false);

                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("Cannot build to a container registry in offline mode", ex.Message);
            }

            // Should fail since Fib hasn't cached the base image yet
            try
            {
                await fibContainerBuilder.ContainerizeAsync(
                    Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOffline))
                    .SetBaseImageLayersCache(cacheDirectory)
                    .SetOfflineMode(true)).ConfigureAwait(false);

                Assert.Fail();
            }
            catch (IOException ex)
            {
                Assert.AreEqual(
                    "Cannot run Fib in offline mode; localhost:5001/busybox not found in local Fib cache",
                    ex.Message);
            }
            using (LocalRegistry tempRegistry = new LocalRegistry(5001))
            {
                await tempRegistry.StartAsync().ConfigureAwait(false);

                tempRegistry.PullAndPushToLocal("busybox", "busybox");

                // Run online to cache the base image
                await fibContainerBuilder.ContainerizeAsync(
                    Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOnline))
                    .SetBaseImageLayersCache(cacheDirectory)
                    .SetAllowInsecureRegistries(true)).ConfigureAwait(false);
            }

            // Run again in offline mode, should succeed this time
            await fibContainerBuilder.ContainerizeAsync(
                Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOffline))
                .SetBaseImageLayersCache(cacheDirectory)
                .SetOfflineMode(true)).ConfigureAwait(false);

            // Verify output
            Assert.AreEqual(
                "Hello World\n",
                new Command("docker", "run", "--rm", targetImageReferenceOffline.ToString()).Run());
        }
Ejemplo n.º 9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                config.Filters.Add(new AuthorizeFilter(policy));

                config.Conventions.Add(new FeatureConvention());
            })
            .AddRazorOptions(options =>
            {
                // 支持默认的方式
                // {0} - Action Name
                // {1} - Controller Name
                // {2} - Area Name
                // {3} - Feature Name
                options.AreaViewLocationFormats.Clear();
                options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/{1}/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Areas/{2}/Features/Shared/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Areas/Shared/{0}.cshtml");

                // 支持Features文件夹组织代码的方式
                // replace normal view location entirely
                options.ViewLocationFormats.Clear();
                options.ViewLocationFormats.Add("/Features/{3}/{1}/{0}.cshtml");
                options.ViewLocationFormats.Add("/Features/{3}/{0}.cshtml");
                options.ViewLocationFormats.Add("/Features/Shared/{0}.cshtml");

                // add support for features side-by-side with /Views
                // (do NOT clear ViewLocationFormats)
                //options.ViewLocationFormats.Insert(0, "/Features/Shared/{0}.cshtml");
                //options.ViewLocationFormats.Insert(0, "/Features/{3}/{0}.cshtml");
                //options.ViewLocationFormats.Insert(0, "/Features/{3}/{1}/{0}.cshtml");
                //
                // (do NOT clear AreaViewLocationFormats)
                //options.AreaViewLocationFormats.Insert(0, "/Areas/{2}/Features/Shared/{0}.cshtml");
                //options.AreaViewLocationFormats.Insert(0, "/Areas/{2}/Features/{3}/{0}.cshtml");
                //options.AreaViewLocationFormats.Insert(0, "/Areas/{2}/Features/{3}/{1}/{0}.cshtml");

                options.ViewLocationExpanders.Add(new FeatureViewLocationExpander());
            });

            // Add memory cache services
            services.AddMemoryCache();
            if (HostingEnvironment.IsDevelopment())
            {
                // 分布式缓存本地实现,开发模式使用,
                services.AddDistributedMemoryCache();
            }
            else
            {
                services.AddDistributedRedisCache(option =>
                {
                    option.Configuration = "127.0.0.1";
                    option.InstanceName  = "UUAC:";
                });
            }
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options => {
                options.Cookie.Name     = ".UUACAPP";
                options.Cookie.HttpOnly = true;
                options.LoginPath       = "/Home/Login";
            });


            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
            });

            //获取数据库连接
            services.Configure <DBOption>(Configuration.GetSection("connectionStrings"));

            UUAC.DataAccess.Mysql.RepositoryRegistry.Registry(services); // 注册DB接口
            UUAC.Business.ServiceRegistry.Registry(services);            //注册服务接口
            LocalRegistry.Registry(services);                            //注册本地服务

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IRuntimeContextStorage, AspNetCoreContext>();
            services.AddSingleton <IConnectionFactory, MySqlConnectionFactory>();


            //链接管理器
            services.AddSingleton <IConnectionManagerFactory, ConnectionManagerFactory>();
        }
Ejemplo n.º 10
0
 public void MetricsRegistryDowsNotThrowOnMetricsOfDifferentTypeWithSameName()
 {
     var registry = new LocalRegistry();
     ((Action)(() => AddMetrics(registry))).ShouldNotThrow();
 }