public void TestDeserializationWithAlias() { AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); var avroConfiguration = serializer.AvroDeserializeFromFile("evaluator.conf"); var language = avroConfiguration.language; Assert.IsTrue(language.ToString().Equals(Language.Java.ToString())); var classHierarchy = TangFactory.GetTang() .GetClassHierarchy(new string[] { typeof(ApplicationIdentifier).Assembly.GetName().Name }); var config = serializer.FromAvro(avroConfiguration, classHierarchy); IInjector evaluatorInjector = TangFactory.GetTang().NewInjector(config); string appid = evaluatorInjector.GetNamedInstance <ApplicationIdentifier, string>(); string remoteId = evaluatorInjector.GetNamedInstance <DriverRemoteIdentifier, string>(); string evaluatorIdentifier = evaluatorInjector.GetNamedInstance <EvaluatorIdentifier, string>(); string rid = evaluatorInjector.GetNamedInstance <ErrorHandlerRid, string>(); string launchId = evaluatorInjector.GetNamedInstance <LaunchId, string>(); Assert.IsTrue(remoteId.StartsWith(RemoteIdPrefix)); Assert.IsTrue(appid.Equals(AppIdForTest)); Assert.IsTrue(evaluatorIdentifier.StartsWith(EvaluatorIdPrefix)); Assert.IsTrue(rid.StartsWith(RemoteIdPrefix)); Assert.IsTrue(launchId.Equals(AppIdForTest)); }
/// <summary> /// Create a new ContextRuntime. /// </summary> /// <param name="serviceInjector"></param> /// <param name="contextConfiguration">the Configuration for this context.</param> /// <param name="parentContext"></param> public ContextRuntime( IInjector serviceInjector, IConfiguration contextConfiguration, Optional <ContextRuntime> parentContext) { _serviceInjector = serviceInjector; // Note that for Service objects and handlers, we are not merging them into a separate // class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance // of such a class were to be materialized. i.e. if a ServiceContainer object were initialized // and a child ServiceConfiguration is submitted, when the child service injector tries to // get the relevant handlers and services set, it will get the same set of handlers as // previously instantiated by the parent injector, and thus will not allow the stacking // of ServiceConfigurations. _injectedServices = serviceInjector.GetNamedInstance <ServicesSet, ISet <object> >(); _serviceContextStartHandlers = serviceInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >(); _serviceContextStopHandlers = serviceInjector.GetNamedInstance <ContextConfigurationOptions.StopHandlers, ISet <IObserver <IContextStop> > >(); _serviceTaskStartHandlers = serviceInjector.GetNamedInstance <TaskConfigurationOptions.StartHandlers, ISet <IObserver <ITaskStart> > >(); _serviceTaskStopHandlers = serviceInjector.GetNamedInstance <TaskConfigurationOptions.StopHandlers, ISet <IObserver <ITaskStop> > >(); _contextInjector = serviceInjector.ForkInjector(contextConfiguration); _contextLifeCycle = _contextInjector.GetInstance <ContextLifeCycle>(); _parentContext = parentContext; _contextLifeCycle.Start(); }
private CommunicationGroupClient( [Parameter(typeof(GroupCommConfigurationOptions.CommunicationGroupName))] string groupName, [Parameter(typeof(GroupCommConfigurationOptions.SerializedOperatorConfigs))] ISet <string> operatorConfigs, IGroupCommNetworkObserver groupCommNetworkObserver, AvroConfigurationSerializer configSerializer, ICommunicationGroupNetworkObserver commGroupNetworkHandler, IInjector injector) { _operators = new Dictionary <string, object>(); GroupName = groupName; groupCommNetworkObserver.Register(groupName, commGroupNetworkHandler); foreach (string operatorConfigStr in operatorConfigs) { IConfiguration operatorConfig = configSerializer.FromString(operatorConfigStr); IInjector operatorInjector = injector.ForkInjector(operatorConfig); string operatorName = operatorInjector.GetNamedInstance <GroupCommConfigurationOptions.OperatorName, string>( GenericType <GroupCommConfigurationOptions.OperatorName> .Class); string msgType = operatorInjector.GetNamedInstance <GroupCommConfigurationOptions.MessageType, string>( GenericType <GroupCommConfigurationOptions.MessageType> .Class); Type groupCommOperatorGenericInterface = typeof(IGroupCommOperator <>); Type groupCommOperatorInterface = groupCommOperatorGenericInterface.MakeGenericType(Type.GetType(msgType)); var operatorObj = operatorInjector.GetInstance(groupCommOperatorInterface); _operators.Add(operatorName, operatorObj); } }
public void TestServiceContextEventHandlersTriggered() { var launcher = GetRootContextLauncher( GetContextConfiguration(), GetServiceConfiguration(), Optional <IConfiguration> .Empty()); IInjector serviceInjector = null; IInjector contextInjector = null; using (var rootContext = launcher.GetRootContext()) { serviceInjector = rootContext.ServiceInjector; contextInjector = rootContext.ContextInjector; Assert.NotNull(serviceInjector); Assert.NotNull(contextInjector); } var serviceContextStartHandlers = serviceInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >(); var contextContextStartHandlers = contextInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >(); Assert.Equal(1, serviceContextStartHandlers.Count); Assert.Equal(2, contextContextStartHandlers.Count); var serviceContextStartHandler = serviceContextStartHandlers.First() as TestServiceEventHandlers; Assert.True(contextContextStartHandlers.Contains(serviceContextStartHandler)); var serviceContextStopHandlers = serviceInjector.GetNamedInstance <ContextConfigurationOptions.StopHandlers, ISet <IObserver <IContextStop> > >(); var contextContextStopHandlers = contextInjector.GetNamedInstance <ContextConfigurationOptions.StopHandlers, ISet <IObserver <IContextStop> > >(); Assert.Equal(1, serviceContextStopHandlers.Count); Assert.Equal(2, contextContextStopHandlers.Count); var serviceContextStopHandler = serviceContextStopHandlers.First() as TestServiceEventHandlers; Assert.True(contextContextStopHandlers.Contains(serviceContextStopHandler)); foreach (var contextStartHandler in contextContextStartHandlers.Select(h => h as ITestContextEventHandler)) { Assert.NotNull(contextStartHandler); Assert.Equal(1, contextStartHandler.ContextStartInvoked); Assert.Equal(1, contextStartHandler.ContextStopInvoked); } foreach (var contextStopHandler in contextContextStopHandlers.Select(h => h as ITestContextEventHandler)) { Assert.NotNull(contextStopHandler); Assert.Equal(1, contextStopHandler.ContextStartInvoked); Assert.Equal(1, contextStopHandler.ContextStopInvoked); } }
private Optional <IConfiguration> CreateTaskConfiguration() { string taskConfigString = null; try { taskConfigString = _injector.GetNamedInstance <InitialTaskConfiguration, string>(); } catch (InjectionException) { Logger.Log(Level.Info, "InitialTaskConfiguration is not set in Evaluator.config."); } return(string.IsNullOrEmpty(taskConfigString) ? Optional <IConfiguration> .Empty() : Optional <IConfiguration> .Of(_serializer.FromString(taskConfigString))); }
public void TestNamedParameterBoundToDelegatingInterface() { IInjector i = TangFactory.GetTang().NewInjector(); C c = (C)i.GetNamedInstance(typeof(AName)); Assert.IsNotNull(c); }
public void TestBindNamedParameter1() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); cb.BindNamedParameter <AImplName, Aimpl, INamedImplA>(); cb.BindNamedParameter <BImplName, Bimpl, INamedImplA>(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); Aimpl a1 = (Aimpl)i.GetNamedInstance <AImplName, INamedImplA>(GenericType <AImplName> .Class); Aimpl a2 = (Aimpl)i.GetNamedInstance <AImplName, INamedImplA>(GenericType <AImplName> .Class); Bimpl b1 = (Bimpl)i.GetNamedInstance <BImplName, INamedImplA>(GenericType <BImplName> .Class); Bimpl b2 = (Bimpl)i.GetNamedInstance <BImplName, INamedImplA>(GenericType <BImplName> .Class); Assert.Same(a1, a2); Assert.Same(b1, b2); }
public void TestNamedImpl() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { FileNames.Examples }); cb.BindNamedParameter <AImplName, Aimpl, INamedImplA>(GenericType <AImplName> .Class, GenericType <Aimpl> .Class); cb.BindNamedParameter <BImplName, Bimpl, INamedImplA>(GenericType <BImplName> .Class, GenericType <Bimpl> .Class); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); Aimpl a1 = (Aimpl)i.GetNamedInstance <AImplName, INamedImplA>(GenericType <AImplName> .Class); Aimpl a2 = (Aimpl)i.GetNamedInstance <AImplName, INamedImplA>(GenericType <AImplName> .Class); Bimpl b1 = (Bimpl)i.GetNamedInstance <BImplName, INamedImplA>(GenericType <BImplName> .Class); Bimpl b2 = (Bimpl)i.GetNamedInstance <BImplName, INamedImplA>(GenericType <BImplName> .Class); Assert.AreSame(a1, a2); Assert.AreSame(b1, b2); }
internal byte[] SerializeAppArgsToBytes(AppParameters appParameters, IInjector paramInjector) { var avroAppSubmissionParameters = new AvroAppSubmissionParameters { tcpBeginPort = paramInjector.GetNamedInstance <TcpPortRangeStart, int>(), tcpRangeCount = paramInjector.GetNamedInstance <TcpPortRangeCount, int>(), tcpTryCount = paramInjector.GetNamedInstance <TcpPortRangeTryCount, int>() }; var avroYarnAppSubmissionParameters = new AvroYarnAppSubmissionParameters { sharedAppSubmissionParameters = avroAppSubmissionParameters, driverRecoveryTimeout = paramInjector.GetNamedInstance <DriverBridgeConfigurationOptions.DriverRestartEvaluatorRecoverySeconds, int>() }; return(AvroJsonSerializer <AvroYarnAppSubmissionParameters> .ToBytes(avroYarnAppSubmissionParameters)); }
public void TestGetInstanceOfNamedParameter() { IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); IfaceWithDefault iwd = i.GetNamedInstance <IfaceWithDefaultName, IfaceWithDefault>(GenericType <IfaceWithDefaultName> .Class); Assert.IsNotNull(iwd); }
public EvaluatorConfigurations(string configFile) { using (LOGGER.LogFunction("EvaluatorConfigurations::EvaluatorConfigurations")) { if (string.IsNullOrWhiteSpace(configFile)) { Utilities.Diagnostics.Exceptions.Throw(new ArgumentNullException("configFile"), LOGGER); } if (!File.Exists(configFile)) { Utilities.Diagnostics.Exceptions.Throw(new FileNotFoundException("cannot find file " + configFile), LOGGER); } AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); var classHierarchy = TangFactory.GetTang() .GetClassHierarchy(new string[] { typeof(ApplicationIdentifier).Assembly.GetName().Name }); var evaluatorConfiguration = serializer.FromFile(configFile, classHierarchy); IInjector evaluatorInjector = TangFactory.GetTang().NewInjector(evaluatorConfiguration); LOGGER.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "Evaluator Configuration is deserialized from file {0}:", configFile)); try { _taskConfiguration = evaluatorInjector.GetNamedInstance <InitialTaskConfiguration, string>(); } catch (InjectionException) { LOGGER.Log(Level.Info, "InitialTaskConfiguration is not set in Evaluator.config."); } try { _rootContextConfiguration = evaluatorInjector.GetNamedInstance <RootContextConfiguration, string>(); } catch (InjectionException) { LOGGER.Log(Level.Warning, "RootContextConfiguration is not set in Evaluator.config."); } try { _rootServiceConfiguration = evaluatorInjector.GetNamedInstance <RootServiceConfiguration, string>(); } catch (InjectionException) { LOGGER.Log(Level.Info, "RootServiceConfiguration is not set in Evaluator.config."); } _applicationId = evaluatorInjector.GetNamedInstance <ApplicationIdentifier, string>(); _remoteId = evaluatorInjector.GetNamedInstance <DriverRemoteIdentifier, string>(); _evaluatorId = evaluatorInjector.GetNamedInstance <EvaluatorIdentifier, string>(); _errorHandlerRid = evaluatorInjector.GetNamedInstance <ErrorHandlerRid, string>(); _launchId = evaluatorInjector.GetNamedInstance <LaunchId, string>(); } }
internal byte[] SerializeAppArgsToBytes(AppParameters appParameters, IInjector paramInjector) { var avroAppSubmissionParameters = new AvroAppSubmissionParameters { tcpBeginPort = paramInjector.GetNamedInstance<TcpPortRangeStart, int>(), tcpRangeCount = paramInjector.GetNamedInstance<TcpPortRangeCount, int>(), tcpTryCount = paramInjector.GetNamedInstance<TcpPortRangeTryCount, int>() }; var avroYarnAppSubmissionParameters = new AvroYarnAppSubmissionParameters { sharedAppSubmissionParameters = avroAppSubmissionParameters, driverRecoveryTimeout = paramInjector.GetNamedInstance<DriverBridgeConfigurationOptions.DriverRestartEvaluatorRecoverySeconds, int>() }; return AvroJsonSerializer<AvroYarnAppSubmissionParameters>.ToBytes(avroYarnAppSubmissionParameters); }
private static void RunTasksAndVerifyEventHandlers(int tasksRun) { var launcher = GetRootContextLauncher( GetContextConfiguration(), GetServiceConfiguration(), Optional <IConfiguration> .Of(GetTaskConfiguration())); IInjector serviceInjector = null; using (var rootContext = launcher.GetRootContext()) { serviceInjector = rootContext.ServiceInjector; for (var i = 0; i < tasksRun; i++) { rootContext.StartTaskOnNewThread(launcher.RootTaskConfig.Value).Join(); } Assert.NotNull(serviceInjector); } var serviceTaskStartHandlers = serviceInjector.GetNamedInstance <TaskConfigurationOptions.StartHandlers, ISet <IObserver <ITaskStart> > >(); Assert.Equal(1, serviceTaskStartHandlers.Count); var serviceTaskStartHandler = serviceTaskStartHandlers.First() as TestServiceEventHandlers; var serviceTaskStopHandlers = serviceInjector.GetNamedInstance <TaskConfigurationOptions.StopHandlers, ISet <IObserver <ITaskStop> > >(); Assert.Equal(1, serviceTaskStopHandlers.Count); var serviceTaskStopHandler = serviceTaskStopHandlers.First() as TestServiceEventHandlers; Assert.Equal(serviceTaskStopHandler, serviceTaskStartHandler); Assert.NotNull(serviceTaskStartHandler); if (serviceTaskStartHandler == null || serviceTaskStopHandler == null) { // Get rid of warning. throw new Exception(); } Assert.Equal(tasksRun, serviceTaskStartHandler.TaskStartInvoked); Assert.Equal(tasksRun, serviceTaskStopHandler.TaskStopInvoked); }
public void TestDeserializationForServiceAndContext() { AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); var classHierarchy = TangFactory.GetTang() .GetClassHierarchy(new string[] { typeof(ApplicationIdentifier).Assembly.GetName().Name }); var config = serializer.FromFile("evaluatorWithService.conf", classHierarchy); IInjector evaluatorInjector = TangFactory.GetTang().NewInjector(config); string contextConfigString = evaluatorInjector.GetNamedInstance <RootContextConfiguration, string>(); string rootServiceConfigString = evaluatorInjector.GetNamedInstance <RootServiceConfiguration, string>(); var contextClassHierarchy = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(ContextConfigurationOptions.ContextIdentifier).Assembly.GetName().Name }); var contextConfig = serializer.FromString(contextConfigString, contextClassHierarchy); var serviceClassHierarchy = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(ServicesConfigurationOptions).Assembly.GetName().Name, typeof(IStreamingCodec <>).Assembly.GetName().Name }); var rootServiceConfig = serializer.FromString(rootServiceConfigString, serviceClassHierarchy); var contextInjector = evaluatorInjector.ForkInjector(contextConfig); string contextId = contextInjector.GetNamedInstance <ContextConfigurationOptions.ContextIdentifier, string>(); Assert.IsTrue(contextId.StartsWith("MasterTaskContext")); string serviceConfigString = TangFactory.GetTang().NewInjector(rootServiceConfig) .GetNamedInstance <ServicesConfigurationOptions.ServiceConfigString, string>(); var serviceConfig = serializer.FromString(serviceConfigString, serviceClassHierarchy); var serviceInjector = contextInjector.ForkInjector(serviceConfig); var tcpCountRange = serviceInjector.GetNamedInstance <TcpPortRangeStart, int>(); var tcpCountCount = serviceInjector.GetNamedInstance <TcpPortRangeCount, int>(); Assert.IsTrue(tcpCountRange > 0); Assert.IsTrue(tcpCountCount > 0); }
/// <summary> /// Create a new ContextRuntime. /// </summary> /// <param name="serviceInjector"></param> /// <param name="contextConfiguration">the Configuration for this context.</param> /// <param name="parentContext"></param> public ContextRuntime( IInjector serviceInjector, IConfiguration contextConfiguration, Optional<ContextRuntime> parentContext) { _serviceInjector = serviceInjector; _injectedServices = Optional<ISet<object>>.Of(serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>()); _contextInjector = serviceInjector.ForkInjector(contextConfiguration); _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>(); _parentContext = parentContext; _contextLifeCycle.Start(); }
public void TestDeserializationForContextAndTask() { AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); var classHierarchy = TangFactory.GetTang() .GetClassHierarchy(new string[] { typeof(ApplicationIdentifier).Assembly.GetName().Name }); var config = serializer.FromFile("evaluator.conf", classHierarchy); IInjector evaluatorInjector = TangFactory.GetTang().NewInjector(config); string taskConfigString = evaluatorInjector.GetNamedInstance <InitialTaskConfiguration, string>(); string contextConfigString = evaluatorInjector.GetNamedInstance <RootContextConfiguration, string>(); var contextClassHierarchy = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(ContextConfigurationOptions.ContextIdentifier).Assembly.GetName().Name }); var contextConfig = serializer.FromString(contextConfigString, contextClassHierarchy); var taskClassHierarchy = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(ITask).Assembly.GetName().Name, typeof(HelloTask).Assembly.GetName().Name }); var taskConfig = serializer.FromString(taskConfigString, taskClassHierarchy); var contextInjector = evaluatorInjector.ForkInjector(contextConfig); string contextId = contextInjector.GetNamedInstance <ContextConfigurationOptions.ContextIdentifier, string>(); Assert.IsTrue(contextId.StartsWith(ContextIdPrefix)); var taskInjector = contextInjector.ForkInjector(taskConfig); string taskId = taskInjector.GetNamedInstance <TaskConfigurationOptions.Identifier, string>(); ITask task = taskInjector.GetInstance <ITask>(); Assert.IsTrue(taskId.StartsWith("HelloTask")); Assert.IsTrue(task is HelloTask); }
/// <summary> /// Create a new ContextRuntime. /// </summary> /// <param name="serviceInjector"></param> /// <param name="contextConfiguration">the Configuration for this context.</param> /// <param name="parentContext"></param> public ContextRuntime( IInjector serviceInjector, IConfiguration contextConfiguration, Optional <ContextRuntime> parentContext) { _serviceInjector = serviceInjector; _injectedServices = Optional <ISet <object> > .Of(serviceInjector.GetNamedInstance <ServicesSet, ISet <object> >()); _contextInjector = serviceInjector.ForkInjector(contextConfiguration); _contextLifeCycle = _contextInjector.GetInstance <ContextLifeCycle>(); _parentContext = parentContext; _contextLifeCycle.Start(); }
/// <summary> /// Returns the Context Identifier from the Configuration. /// </summary> /// <param name="contextConfiguration">The Configuration object</param> /// <returns>The TaskIdentifier for the given Configuration</returns> public static string GetContextId(IConfiguration contextConfiguration) { try { IInjector injector = TangFactory.GetTang().NewInjector(contextConfiguration); return(injector.GetNamedInstance <ContextConfigurationOptions.ContextIdentifier, string>( GenericType <ContextConfigurationOptions.ContextIdentifier> .Class)); } catch (InjectionException) { LOGGER.Log(Level.Error, "Unable to find task identifier"); throw; } }
private RootContextLauncher( IConfiguration contextConfiguration, IConfiguration rootServiceConfig, Optional<IConfiguration> rootTaskConfig, IInjector injector) { _rootContextConfiguration = contextConfiguration; _rootServiceInjector = injector.ForkInjector(rootServiceConfig); Id = _rootServiceInjector .ForkInjector(contextConfiguration) .GetNamedInstance<ContextConfigurationOptions.ContextIdentifier, string>(); _services = _rootServiceInjector.GetNamedInstance<ServicesSet, ISet<object>>(); Logger.Log(Level.Verbose, string.Format(CultureInfo.InvariantCulture, "injected service(s)")); RootTaskConfig = rootTaskConfig; }
private RootContextLauncher( IConfiguration contextConfiguration, IConfiguration rootServiceConfig, Optional <IConfiguration> rootTaskConfig, IInjector injector) { _rootContextConfiguration = contextConfiguration; _rootServiceInjector = injector.ForkInjector(rootServiceConfig); Id = _rootServiceInjector .ForkInjector(contextConfiguration) .GetNamedInstance <ContextConfigurationOptions.ContextIdentifier, string>(); _services = _rootServiceInjector.GetNamedInstance <ServicesSet, ISet <object> >(); Logger.Log(Level.Verbose, string.Format(CultureInfo.InvariantCulture, "injected service(s)")); RootTaskConfig = rootTaskConfig; }
public void TestInjectionExtension() { IInjector i = TangFactory.GetTang().NewInjector(); i.BindVolatileInstance <Integer>(new Integer(1)); i.BindVolatileInstance <Float>(new Float(2f)); ISet <INumber> actual = (ISet <INumber>) i.GetNamedInstance <SetOfClassesDefaultClass, ISet <INumber> >(); ISet <INumber> expected = new HashSet <INumber>(); expected.Add(new Integer(1)); Assert.Equal(expected.Count, actual.Count); Assert.True(actual.Contains(new Integer(1))); }
public void TestDefaultAsClass() { IInjector i = TangFactory.GetTang().NewInjector(); i.BindVolatileInstance(GenericType <Integer> .Class, new Integer(1)); i.BindVolatileInstance(GenericType <Float> .Class, new Float(2f)); ISet <INumber> actual = (ISet <INumber>) i.GetNamedInstance <SetOfClassesDefaultClass, ISet <INumber> >(GenericType <SetOfClassesDefaultClass> .Class); ISet <INumber> expected = new HashSet <INumber>(); expected.Add(new Integer(1)); Assert.AreEqual(expected.Count, actual.Count); Assert.IsTrue(actual.Contains(new Integer(1))); }
/// <summary> /// Test run for the runtime in the given injector. /// </summary> /// <param name="config">runtime configuration.</param> /// <param name="driverMemory">driver memory in MB.</param> private void TestRun(IConfiguration config, int driverMemory) { IInjector injector = TangFactory.GetTang().NewInjector(config); var jobRequestBuilder = injector.GetInstance <JobRequestBuilder>(); var reefClient = injector.GetInstance <IREEFClient>(); var numberOfContainers = injector.GetNamedInstance <NumberOfContainers, int>(GenericType <NumberOfContainers> .Class); //// The driver configuration contains all the needed handler bindings var helloDriverConfiguration = DriverConfiguration.ConfigurationModule .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType <TestHelloDriver> .Class) .Set(DriverConfiguration.OnDriverStarted, GenericType <TestHelloDriver> .Class) .Set(DriverConfiguration.OnTaskCompleted, GenericType <TestHelloDriver> .Class) .Set(DriverConfiguration.OnTaskFailed, GenericType <TestHelloDriver> .Class) .Set(DriverConfiguration.OnEvaluatorFailed, GenericType <TestHelloDriver> .Class) .Set(DriverConfiguration.OnTaskRunning, GenericType <TestHelloDriver> .Class) .Set(DriverConfiguration.CustomTraceLevel, Level.Info.ToString()) .Build(); var driverConfig = TangFactory.GetTang() .NewConfigurationBuilder(helloDriverConfiguration) .BindIntNamedParam <NumberOfContainers>(numberOfContainers.ToString()); // The JobSubmission contains the Driver configuration as well as the files needed on the Driver. var helloJobRequest = jobRequestBuilder .AddDriverConfiguration(driverConfig.Build()) .AddGlobalAssemblyForType(typeof(TestHelloDriver)) .SetJobIdentifier("TestHelloREEF") .SetDriverMemory(driverMemory) .Build(); var result = reefClient.SubmitAndGetJobStatus(helloJobRequest); var state = PullFinalJobStatus(result); Logger.Log(Level.Info, "Application final state : {0}.", state); Assert.Equal(FinalState.SUCCEEDED, state); }
public void TestServiceContextEventHandlersTriggeredSuccessiveContexts() { var launcher = GetRootContextLauncher( GetContextConfiguration(), GetServiceConfiguration(), Optional <IConfiguration> .Empty()); IInjector serviceInjector = null; IInjector firstContextInjector = null; IInjector secondContextInjector = null; using (var rootContext = launcher.GetRootContext()) { serviceInjector = rootContext.ServiceInjector; firstContextInjector = rootContext.ContextInjector; using (var childContext = rootContext.SpawnChildContext(GetContextConfiguration())) { secondContextInjector = childContext.ContextInjector; } Assert.NotNull(serviceInjector); Assert.NotNull(firstContextInjector); Assert.NotNull(secondContextInjector); } var serviceContextStartHandlers = serviceInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >(); var firstContextContextStartHandlers = firstContextInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >(); var secondContextContextStartHandlers = secondContextInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >(); Assert.Equal(1, serviceContextStartHandlers.Count); Assert.Equal(2, firstContextContextStartHandlers.Count); Assert.Equal(2, secondContextContextStartHandlers.Count); var intersectSet = new HashSet <IObserver <IContextStart> >(serviceContextStartHandlers); intersectSet.IntersectWith(firstContextContextStartHandlers); intersectSet.IntersectWith(secondContextContextStartHandlers); var unionSet = new HashSet <IObserver <IContextStart> >(serviceContextStartHandlers); unionSet.UnionWith(firstContextContextStartHandlers); unionSet.UnionWith(secondContextContextStartHandlers); Assert.Equal(1, intersectSet.Count); Assert.Equal(3, unionSet.Count); var serviceContextHandler = serviceContextStartHandlers.Single() as ITestContextEventHandler; var unionContextHandlerSet = new HashSet <ITestContextEventHandler>( unionSet.Select(h => h as ITestContextEventHandler).Where(h => h != null)); Assert.Equal(unionSet.Count, unionContextHandlerSet.Count); Assert.True(unionContextHandlerSet.Contains(serviceContextHandler)); foreach (var handler in unionContextHandlerSet.Where(h => h != null)) { if (ReferenceEquals(handler, serviceContextHandler)) { Assert.Equal(2, handler.ContextStartInvoked); Assert.Equal(2, handler.ContextStopInvoked); } else { Assert.Equal(1, handler.ContextStartInvoked); Assert.Equal(1, handler.ContextStopInvoked); } } }
/// <summary> /// Create a new ContextRuntime. /// </summary> /// <param name="serviceInjector"></param> /// <param name="contextConfiguration">the Configuration for this context.</param> /// <param name="parentContext"></param> public ContextRuntime( IInjector serviceInjector, IConfiguration contextConfiguration, Optional<ContextRuntime> parentContext) { _serviceInjector = serviceInjector; // Note that for Service objects and handlers, we are not merging them into a separate // class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance // of such a class were to be materialized. i.e. if a ServiceContainer object were initialized // and a child ServiceConfiguration is submitted, when the child service injector tries to // get the relevant handlers and services set, it will get the same set of handlers as // previously instantiated by the parent injector, and thus will not allow the stacking // of ServiceConfigurations. _injectedServices = serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>(); _serviceContextStartHandlers = serviceInjector.GetNamedInstance<ContextConfigurationOptions.StartHandlers, ISet<IObserver<IContextStart>>>(); _serviceContextStopHandlers = serviceInjector.GetNamedInstance<ContextConfigurationOptions.StopHandlers, ISet<IObserver<IContextStop>>>(); _serviceTaskStartHandlers = serviceInjector.GetNamedInstance<TaskConfigurationOptions.StartHandlers, ISet<IObserver<ITaskStart>>>(); _serviceTaskStopHandlers = serviceInjector.GetNamedInstance<TaskConfigurationOptions.StopHandlers, ISet<IObserver<ITaskStop>>>(); _contextInjector = serviceInjector.ForkInjector(contextConfiguration); _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>(); _parentContext = parentContext; try { _contextLifeCycle.Start(); } catch (Exception e) { const string message = "Encountered Exception in ContextStartHandler."; if (ParentContext.IsPresent()) { throw new ContextStartHandlerException( Id, Optional<string>.Of(ParentContext.Value.Id), message, e); } throw new ContextStartHandlerException(Id, Optional<string>.Empty(), message, e); } }
private TaskRuntime GetDeprecatedTaskRuntime( IInjector taskInjector, string contextId, IConfiguration taskConfiguration, IHeartBeatManager heartBeatManager) { var taskId = string.Empty; try { taskId = taskInjector.GetNamedInstance<TaskConfigurationOptions.Identifier, string>(); } catch (Exception e) { var ex = new TaskClientCodeException(string.Empty, Id, "Unable to instantiate the new task", e); Utilities.Diagnostics.Exceptions.CaughtAndThrow(ex, Level.Error, "Cannot get instance of Task ID: " + e.StackTrace, LOGGER); } LOGGER.Log(Level.Info, "Trying to inject task with configuration" + taskConfiguration); return new TaskRuntime(taskInjector, contextId, taskId, heartBeatManager); }