public AuthorizeFilterAttribute(OperatorCache operatord, IMenuAuthorizeBLL menuAuthorizeBLL,
                                 ApiAuthorizeCache apiAuthorizeCache)
 {
     _operator          = operatord;
     _menuAuthorizeBLL  = menuAuthorizeBLL;
     _apiAuthorizeCache = apiAuthorizeCache;
 }
Esempio n. 2
0
 public DepartmentBLL(IDepartmentService departmentService, OperatorCache operatorCache,
                      IUserService userService)
 {
     _departmentService = departmentService;
     _operatorCache     = operatorCache;
     _userService       = userService;
 }
Esempio n. 3
0
 public HomeController(ImageCache imageCache, OperatorCache operatorCache, IMenuBLL menuBLL,
                       IMenuAuthorizeBLL menuAuthorizeBLL)
 {
     _imageCache       = imageCache;
     _operatorCache    = operatorCache;
     _menuBLL          = menuBLL;
     _menuAuthorizeBLL = menuAuthorizeBLL;
 }
Esempio n. 4
0
 public HomeController(MenuBLL _menuBLL, UserBLL _userBLL, LogLoginBLL _logLoginBLL,
                       MenuAuthorizeBLL _menuAuthorizeBLL, OperatorCache operatorCache)
 {
     menuBLL          = _menuBLL;
     userBLL          = _userBLL;
     logLoginBLL      = _logLoginBLL;
     menuAuthorizeBLL = _menuAuthorizeBLL;
     _operator        = operatorCache;
 }
Esempio n. 5
0
        /// <summary>
        /// Scales a value by (max - min), then divides it by scale and adds it to min
        /// </summary>
        /// <param name="scale">An optional scale value for integer types (default 1)</param>
        public static T FractionToValue <T> (T fraction, T min, T max, T?scale = null)
            where T : struct
        {
            var range = OperatorCache <T> .Subtract(max, min);

            var global = OperatorCache <T> .Multiply(fraction, range);

            if (scale != null)
            {
                global = OperatorCache <T> .Divide(global, scale.Value);
            }
            return(OperatorCache <T> .Add(min, global));
        }
Esempio n. 6
0
        /// <summary>
        /// Clamps a value to the range (min, max) then scales it to the range (0, scale)
        /// </summary>
        /// <param name="scale">An optional scale value for integer types (default 1)</param>
        public static T Fraction <T> (T value, T min, T max, T?scale = null)
            where T : struct
        {
            var range = OperatorCache <T> .Subtract(max, min);

            var relative = OperatorCache <T> .Subtract(value, min);

            if (scale != null)
            {
                relative = OperatorCache <T> .Multiply(relative, scale.Value);
            }
            return(OperatorCache <T> .Divide(relative, range));
        }
Esempio n. 7
0
 public static T Add <T>(T x, T y)
 {
     return(OperatorCache <T> .Add(x, y));
 }
Esempio n. 8
0
 public static T Subtract <T>(T x, T y)
 {
     return(OperatorCache <T> .Subtract(x, y));
 }
Esempio n. 9
0
 public static T Multiply <T, TU>(T x, TU y)
 {
     return(OperatorCache <T, TU> .Multiply(x, y));
 }
Esempio n. 10
0
    public void NotifyWithPrimaryResourceCausesCacheEntryAndQueueItem()
    {
        var generator       = Mock.Of <IOperatorGenerator <TypicalResource> >();
        var typicalInformer = new FakeResourceInformer <TypicalResource>();
        var podInformer     = new FakeResourceInformer <V1Pod>();
        var addCalls        = new List <NamespacedName>();
        var queue           = new FakeQueue <NamespacedName>
        {
            OnAdd = addCalls.Add,
        };
        var cache = new OperatorCache <TypicalResource>();

        using var host = new HostBuilder()
                         .ConfigureServices(services =>
        {
            services
            .AddLogging()
            .AddKubernetesOperatorRuntime()
            .AddOperator <TypicalResource>(op =>
            {
                op.WithRelatedResource <V1Pod>();
                op.Configure(options => options.NewRateLimitingQueue = _ => queue);
            })
            .AddSingleton(generator)
            .AddSingleton <IResourceInformer <TypicalResource> >(typicalInformer)
            .AddSingleton <IResourceInformer <V1Pod> >(podInformer)
            .AddSingleton <IOperatorCache <TypicalResource> >(cache);
        })
                         .Build();

        var handler = host.Services.GetRequiredService <IOperatorHandler <TypicalResource> >();

        var typical = new TypicalResource
        {
            ApiVersion = $"{TypicalResource.KubeGroup}/{TypicalResource.KubeApiVersion}",
            Kind       = TypicalResource.KubeKind,
            Metadata   = new V1ObjectMeta(
                name: "test-name",
                namespaceProperty: "test-namespace")
        };

        var unrelatedPod = new V1Pod
        {
            ApiVersion = TypicalResource.KubeApiVersion,
            Kind       = TypicalResource.KubeKind,
            Metadata   = new V1ObjectMeta(
                name: "test-unrelated",
                namespaceProperty: "test-namespace")
        };

        var relatedPod = new V1Pod(

            apiVersion: TypicalResource.KubeApiVersion,
            kind: TypicalResource.KubeKind,
            metadata: new V1ObjectMeta(
                name: "test-related",
                namespaceProperty: "test-namespace",
                ownerReferences: new[]
        {
            new V1OwnerReference(
                uid: typical.Uid(),
                apiVersion: typical.ApiVersion,
                kind: typical.Kind,
                name: typical.Name())
        }));

        typicalInformer.Callback(WatchEventType.Added, typical);
        podInformer.Callback(WatchEventType.Added, unrelatedPod);
        podInformer.Callback(WatchEventType.Added, relatedPod);

        var expectedName = new NamespacedName("test-namespace", "test-name");

        Assert.Equal(new[] { expectedName, expectedName }, addCalls);

        Assert.True(cache.TryGetWorkItem(expectedName, out var cacheItem));

        Assert.Equal(typical, cacheItem.Resource);

        var related = Assert.Single(cacheItem.Related);

        Assert.Equal(GroupKindNamespacedName.From(relatedPod), related.Key);
        Assert.Equal(relatedPod, related.Value);
    }
Esempio n. 11
0
 public UserController(IUserBLL userBLL, OperatorCache operatorCache, MenuAuthorizeBLL menuAuthorizeBll)
 {
     _userBLL          = userBLL;
     _operator         = operatorCache;
     _menuAuthorizeBll = menuAuthorizeBll;
 }
Esempio n. 12
0
 public UserController(UserBLL userBLL, DepartmentBLL departmentBLL, OperatorCache operatorCache)
 {
     _userBLL       = userBLL;
     _departmentBLL = departmentBLL;
     _operatorCache = operatorCache;
 }
Esempio n. 13
0
 public LoginController(IUserBLL userBLL, ILogLoginBLL logLoginBLL, OperatorCache operatorCache)
 {
     _userBLL       = userBLL;
     _logLoginBLL   = logLoginBLL;
     _operatorCache = operatorCache;
 }