public void Setup()
 {
     _serviceInterfaceMapper = Substitute.For <IServiceInterfaceMapper>();
     _serviceInterfaceMapper.ServiceInterfaceTypes.Returns(_ => _typesToValidate);
     _unitTesting      = new TestingKernel <ConsoleLog>(kernel => kernel.Rebind <IServiceInterfaceMapper>().ToConstant(_serviceInterfaceMapper));
     _serviceValidator = _unitTesting.Get <SensitivityAttributesValidator>();
 }
예제 #2
0
 public HealthEndpoint(IServiceEndPointDefinition serviceEndPointDefinition, IServiceInterfaceMapper serviceInterfaceMapper, IActivator activator, IServiceDrainListener drainListener)
 {
     _drainListener            = drainListener;
     ServiceEndPointDefinition = serviceEndPointDefinition;
     ServiceInterfaceMapper    = serviceInterfaceMapper;
     Activator = activator;
 }
예제 #3
0
 public void Setup()
 {
     _serviceInterfaceMapper = Substitute.For <IServiceInterfaceMapper>();
     _serviceInterfaceMapper.ServiceInterfaceTypes.Returns(_ => _typesToValidate);
     _unitTesting      = new MicrodotInitializer("", new ConsoleLogLoggersModules(), kernel => kernel.Rebind <IServiceInterfaceMapper>().ToConstant(_serviceInterfaceMapper));
     _serviceValidator = _unitTesting.Kernel.Get <SensitivityAttributesValidator>();
 }
        public LogFieldAttributeValidator(IServiceInterfaceMapper serviceInterfaceMapper)
        {
            _serviceInterfaceMapper = serviceInterfaceMapper;

            _typesPrecludedFromLogFieldAttributeUsage = new[]
            {
                typeof(string), typeof(JToken), typeof(Type)
            };
        }
예제 #5
0
        public GrainsWarmup(IServiceInterfaceMapper orleansMapper, IKernel kernel, ILog log)
        {
            _orleansMapper = orleansMapper;
            _kernel        = kernel;
            _log           = log;

            _orleansInternalTypes.Add(typeof(IGrainFactory));
            _orleansInternalTypes.Add(typeof(IGrainState));
            _orleansInternalTypes.Add(typeof(IGrainIdentity));
            _orleansInternalTypes.Add(typeof(IGrainRuntime));
        }
예제 #6
0
        public GrainsWarmup(IServiceInterfaceMapper orleansMapper, IKernel kernel, ILog log)
        {
            _orleansMapper = orleansMapper;
            _kernel        = kernel;
            _log           = log;

            _orleansInternalTypes.Add(typeof(IGrainFactory));
            _orleansInternalTypes.Add(typeof(IGrainState));
            _orleansInternalTypes.Add(typeof(IGrainIdentity));
            _orleansInternalTypes.Add(typeof(IGrainRuntime));
            _orleansInternalTypesString.Add("OrleansDashboard");
            _orleansInternalTypesString.Add("Orleans.IReminderTable");
        }
예제 #7
0
        public ServiceMethodResolver(IServiceInterfaceMapper mapper)
        {
            // get services methods
            GrainMethods = mapper.ServiceInterfaceTypes
                           .SelectMany(t => t.GetMethods()          // get service's methods
                                       .Select(methodInfo => new ServiceMethod(mapper.GetGrainInterface(t), methodInfo))).ToArray();

            var incompatibleMethods = GrainMethods.Where(gm => gm.IsCompatible == false).ToArray();

            if (incompatibleMethods.Any())
            {
                var incompatibleMethodNames = string.Join("\n", incompatibleMethods.AsEnumerable());
                throw new ArgumentException("The specified assemblies contain service interfaces methods which have incompatible signatures:\n\n" + incompatibleMethodNames);
            }

            MethodCache       = GrainMethods.ToDictionary(gm => new InvocationTarget(gm.ServiceInterfaceMethod));
            SimpleMethodCache = GrainMethods.GroupBy(gm => gm.ServiceInterfaceMethod.Name).ToDictionary(a => a.Key, a => a.ToArray(), StringComparer.OrdinalIgnoreCase);
            TypedMethodCache  = GrainMethods.GroupBy(gm => GetTypedMethodKey(gm.ServiceInterfaceMethod.DeclaringType, gm.ServiceInterfaceMethod.Name)).ToDictionary(a => a.Key, a => a.ToArray(), StringComparer.OrdinalIgnoreCase);
        }
 public void Setup()
 {
     _serviceInterfaceMapper = Substitute.For <IServiceInterfaceMapper>();
     _serviceInterfaceMapper.ServiceInterfaceTypes.Returns(_ => _typesToValidate);
 }
예제 #9
0
 public SensitivityAttributesValidator(IServiceInterfaceMapper serviceInterfaceMapper)
 {
     _serviceInterfaceMapper = serviceInterfaceMapper;
 }
예제 #10
0
        public ServiceEndPointDefinition(IServiceInterfaceMapper mapper,
                                         ServiceArguments serviceArguments, Func <DiscoveryConfig> getConfig, CurrentApplicationInfo appInfo)
        {
            _serviceMethodResolver = new ServiceMethodResolver(mapper);
            var serviceInterfaces = mapper.ServiceInterfaceTypes.ToArray();

            if (serviceInterfaces.Any() == false)
            {
                throw new ArgumentException("No service interfaces found in the specified assemblies");
            }

            ServiceNames = serviceInterfaces
                           .Where(i => i.GetCustomAttribute <HttpServiceAttribute>() != null)
                           .ToDictionary(x => x, x => x.Name);

            var interfacePorts = serviceInterfaces.Select(i =>
            {
                var attr = i.GetCustomAttribute <HttpServiceAttribute>();

                return(new
                {
                    ServiceInterface = i,
                    BasePort = serviceArguments.BasePortOverride ?? attr.BasePort,
                    BasePortWithoutOverrides = attr.BasePort,
                    attr.UseHttps
                });
            }).ToArray();

            if (interfacePorts.Select(x => x.UseHttps).Distinct().Count() > 1)
            {
                throw new EnvironmentException("Mix of secure and insecure services.");
            }

            var config        = getConfig();
            var serviceConfig = config.Services[appInfo.Name];

            UseSecureChannel = serviceConfig.UseHttpsOverride ?? interfacePorts.First().UseHttps;

            if (config.PortAllocation.IsSlotMode == false && serviceArguments.SlotNumber == null)
            {
                if (interfacePorts.Select(x => x.BasePort).Distinct().Count() > 1)
                {
                    var conflictingPortList = string.Join("\n", interfacePorts.Select(x => $"BasePort {x.BasePort} for {x.ServiceInterface.FullName}"));
                    throw new EnvironmentException("More than one base port was specified for service interfaces:\n" + conflictingPortList);
                }

                var basePort = interfacePorts.First().BasePort;

                HttpPort           = UseSecureChannel ? (int?)null : basePort + (int)PortOffsets.Http;
                HttpsPort          = basePort + (UseSecureChannel ? (int)PortOffsets.Http : (int)PortOffsets.Https);
                MetricsPort        = basePort + (int)PortOffsets.Metrics;
                SiloGatewayPort    = basePort + (int)PortOffsets.SiloGateway;
                SiloNetworkingPort = basePort + (int)PortOffsets.SiloNetworking;
                SiloNetworkingPortOfPrimaryNode = (serviceArguments.SiloNetworkingPortOfPrimaryNode ?? 0) + (int)PortOffsets.SiloNetworking;
                SiloDashboardPort = basePort + (int)PortOffsets.SiloDashboard;
            }
            else
            {
                if (serviceConfig.DefaultSlotNumber == null)
                {
                    throw new ConfigurationException("Service is configured to run in slot based port but " +
                                                     "DefaultSlotNumber is not set in configuration. " +
                                                     "Either disable this mode via Service.IsSlotMode config value or set it via " +
                                                     $"Discovery.{appInfo.Name}.DefaultSlotNumber.");
                }

                int?slotNumber = serviceArguments.SlotNumber ?? serviceConfig.DefaultSlotNumber;

                if (slotNumber == null)
                {
                    throw new ConfigurationException("Service is configured to run in slot based port but SlotNumber " +
                                                     "command-line argument was not specified and DefaultSlotNumber is not set in configuration. " +
                                                     "Either disable this mode via Service.IsSlotMode config value or set it via " +
                                                     $"Discovery.{appInfo.Name}.DefaultSlotNumber.");
                }

                HttpPort           = UseSecureChannel ? (int?)null : config.PortAllocation.GetPort(slotNumber, PortOffsets.Http).Value;
                HttpsPort          = config.PortAllocation.GetPort(slotNumber, UseSecureChannel ? PortOffsets.Http : PortOffsets.Https).Value;
                MetricsPort        = config.PortAllocation.GetPort(slotNumber, PortOffsets.Metrics).Value;
                SiloGatewayPort    = config.PortAllocation.GetPort(slotNumber, PortOffsets.SiloGateway).Value;
                SiloNetworkingPort = config.PortAllocation.GetPort(slotNumber, PortOffsets.SiloNetworking).Value;
                SiloNetworkingPortOfPrimaryNode = config.PortAllocation.GetPort(serviceConfig.DefaultSlotNumber, PortOffsets.SiloNetworking).Value;
                SiloDashboardPort = config.PortAllocation.GetPort(slotNumber, PortOffsets.SiloDashboard).Value;
            }

            foreach (var method in _serviceMethodResolver.GrainMethods)
            {
                GetMetaData(method);
            }
        }
예제 #11
0
 public HealthEndpoint(IServiceEndPointDefinition serviceEndPointDefinition, IServiceInterfaceMapper serviceInterfaceMapper, IActivator activator)
 {
     ServiceEndPointDefinition = serviceEndPointDefinition;
     ServiceInterfaceMapper    = serviceInterfaceMapper;
     Activator = activator;
 }
예제 #12
0
 public SchemaEndpoint(IServiceInterfaceMapper mapper)
 {
     _jsonSchema = JsonConvert.SerializeObject(new ServiceSchema(mapper.ServiceInterfaceTypes.ToArray()), Formatting.Indented);
 }
 public SchemaEndpoint(IServiceInterfaceMapper mapper)
 {
     _jsonSchema = JsonConvert.SerializeObject(new ServiceSchema(mapper.ServiceInterfaceTypes.ToArray()), new JsonSerializerSettings {
         Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore
     });
 }