You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Douglas Service <ds...@gmail.com> on 2017/04/12 22:57:58 UTC

Tang problem

Given the following constructor.


        [Inject]
        private ClientNetworkService(
            [Parameter(typeof(NetworkOptions.NetService))]
INetworkService<string> networkService,
            [Parameter(typeof(NetworkOptions.ServiceIdentifier))] string
serviceIdentifier,
            [Parameter(typeof(NetworkOptions.ServicePort))] int servicePort,
            [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
string remoteServiceIdentifier)

with the following module builder


        public sealed class ModuleBuilder : ConfigurationModuleBuilder
        {
            public static readonly RequiredParameter<INetworkService<string>>
NetService = new RequiredParameter<INetworkService<string>>();
            public static readonly RequiredParameter<string>
ServiceIdentifier = new RequiredParameter<string>();
            public static readonly RequiredParameter<int> ServicePort = new
RequiredParameter<int>();
            public static readonly RequiredParameter<string>
RemoteServiceIdentifier = new RequiredParameter<string>();

            // public static readonly
RequiredParameter<IObserver<NsMessage<string>>>
ClientMessageHandler
            //  = new RequiredParameter<IObserver<NsMessage<string>>>();
            // .BindNamedParameter(GenericType<NetworkOptions.kService>.Class,
NetworkService)
            public static readonly ConfigurationModule Config = new
ModuleBuilder()
                .BindImplementation(GenericType<INetworkService<string>>.Class,
GenericType<NetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
GenericType<INetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.ServiceIdentifier>.Class,
ServiceIdentifier)

.BindNamedParameter(GenericType<NetworkOptions.ServicePort>.Class,
ServicePort)
                .BindNamedParameter(GenericType<NetworkOptions.
RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
                .Build();

                //
.BindNamedParameter(GenericType<DistRNetworkOptions.MessageHandler>.Class,
MessageHandler)
        }

When I try to inject,

           IConfiguration nameClientConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindNamedParameter<NamingConfigurationOptions.NameServerPort,
int>(
                    GenericType<NamingConfigurationOptions.
NameServerPort>.Class,
                    endpoint.Port.ToString(CultureInfo.CurrentCulture))

.BindNamedParameter<NamingConfigurationOptions.NameServerAddress,
string>(

GenericType<NamingConfigurationOptions.NameServerAddress>.Class,
endpoint.Address.ToString())
                .BindImplementation(GenericType<INameClient>.Class,
GenericType<NameClient>.Class)
                .Build();

            IConfiguration networkServiceConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindIntNamedParam<NetworkServiceOptions.
NetworkServicePort>(servicePort.ToString())
                .Build();

            IConfiguration handlerConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindImplementation<IObserver<NsMessage<string>>,
ClientMessageHandler>()
                .Build();

            !!!!!!!!!!!THROWS!!!!!!!!!!!!
            IConfiguration clientNetworkConfig =
NetworkOptions.ModuleBuilder.Config
                .Set(NetworkOptions.ModuleBuilder.NetService,
GenericType<INetworkService<string>>.Class)
                .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
clientId)
                .Set(NetworkOptions.ModuleBuilder.ServicePort,
servicePort.ToString())
                .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
driverId)
                .Build();

            TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(args.Length
> 0 ? args[0] : Local),
                nameClientConf, networkServiceConf, handlerConf,
clientNetworkConfig).GetInstance<DistributedRClient>().Run();

the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception


System.TypeInitializationException occurred
  HResult=0x80131534
  Message=The type initializer for 'ModuleBuilder' threw an exception.
  Source=Org.Apache.REEF.DistributedR
  StackTrace:
   at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] args)
in E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:line
184

Inner Exception 1:
ClassHierarchyException: Found declared options that were not used in
binds: { NetService }


However when I remove it and the corresponding code in the ModuleBuilder, I
also get an exception about not being able to RDistributedR class.

What am i missing?

Doug

RE: Tang problem

Posted by "Julia Wang (QIUHE)" <Qi...@microsoft.com.INVALID>.
Hi Doug,

You are welcome! 

Tang.Test contains many sample code. They were written for not just testing but showing examples. As those are small therefor easy to understand, it is a good resource for developers to reference. 

Julia

-----Original Message-----
From: Douglas Service [mailto:dsopsrc@gmail.com] 
Sent: Thursday, April 13, 2017 3:45 PM
To: dev@reef.apache.org
Subject: Re: Tang problem

Hello Julia,

From reading your email and looking at the code, I see a number issues that I still need to fix which I am working on now. I read the Tang documentation on the website and then looked at many examples in the tests and elsewhere in the code, but I clearly I missed a number of important issues so thanks for your feedback!

Doug

On Thu, Apr 13, 2017 at 10:25 AM, Julia Wang (QIUHE) < Qiuhe.Wang@microsoft.com.invalid> wrote:

> Hi Doug,
>
> The email below was stuck in the mail box yesterday afternoon because 
> a network issue. It is now automatically sent out. As you already 
> found the issue, that is fine. But you can still look at my recommendation.
>
> Julia
> -----Original Message-----
> From: Julia Wang (QIUHE) [mailto:Qiuhe.Wang@microsoft.com.INVALID]
> Sent: Thursday, April 13, 2017 10:17 AM
> To: dev@reef.apache.org
> Subject: RE: Tang problem
>
> I am not sure why you have a parameter like this:
>             [Parameter(typeof(NetworkOptions.NetService))]
> INetworkService<string> networkService, INetworkService is an 
> interface, you don't need to define named parameter for it. You can 
> directly put the following line as a parameter in the constructor.
>
> If you really want to use named parameter for this case, then 
> NetService must be defined as a named parameter. But in your code, it 
> is defined as a RequiredParameter
>             public static readonly 
> RequiredParameter<INetworkService<string>>
> NetService = new RequiredParameter<INetworkService<string>>();
>
> You should not bind an interface into a required parameter in 
> configuration module. It should be opposite.
> .BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
> GenericType<INetworkService<string>>.Class)
>
> To fix it,
> 1. put this line in the constructor instead of [parameter...]
>         INetworkService<string> networkService
>
> 2. Define the following in the ModuleBuilder
>          public static readonly RequiredImpl<INetworkService <string>> 
> NetService = new RequiredImpl<INetworkService<string>>();
> and
>         .BindImplementation(GenericType<INetworkService 
> <string>>.Class, NetworkOptions .NetService)
>
> 3. When you create clientNetworkConfig,
>         .Set(NetworkOptions.NetService, GenericType<NetworkService<
> string>>.Class)
>
> Hope that helps.
>
> Julia
>
> -----Original Message-----
> From: Douglas Service [mailto:dsopsrc@gmail.com]
> Sent: Wednesday, April 12, 2017 3:58 PM
> To: dev@reef.apache.org
> Subject: Tang problem
>
> Given the following constructor.
>
>
>         [Inject]
>         private ClientNetworkService(
>             [Parameter(typeof(NetworkOptions.NetService))]
> INetworkService<string> networkService,
>             [Parameter(typeof(NetworkOptions.ServiceIdentifier))] 
> string serviceIdentifier,
>             [Parameter(typeof(NetworkOptions.ServicePort))] int 
> servicePort,
>             
> [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
> string remoteServiceIdentifier)
>
> with the following module builder
>
>
>         public sealed class ModuleBuilder : ConfigurationModuleBuilder
>         {
>             public static readonly RequiredParameter< 
> INetworkService<string>> NetService = new 
> RequiredParameter<INetworkService<string>>();
>             public static readonly RequiredParameter<string> 
> ServiceIdentifier = new RequiredParameter<string>();
>             public static readonly RequiredParameter<int> ServicePort 
> = new RequiredParameter<int>();
>             public static readonly RequiredParameter<string> 
> RemoteServiceIdentifier = new RequiredParameter<string>();
>
>             // public static readonly
> RequiredParameter<IObserver<NsMessage<string>>>
> ClientMessageHandler
>             //  = new RequiredParameter<IObserver<NsMessage<string>>>();
>             // .BindNamedParameter(GenericType<NetworkOptions.
> kService>.Class,
> NetworkService)
>             public static readonly ConfigurationModule Config = new
> ModuleBuilder()
>                 .BindImplementation(GenericType<INetworkService<
> string>>.Class,
> GenericType<NetworkService<string>>.Class)
>
> .BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
> GenericType<INetworkService<string>>.Class)
>
> .BindNamedParameter(GenericType<NetworkOptions.ServiceIdentifier>.Clas
> s,
> ServiceIdentifier)
>
> .BindNamedParameter(GenericType<NetworkOptions.ServicePort>.Class,
> ServicePort)
>                 .BindNamedParameter(GenericType<NetworkOptions.
> RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
>                 .Build();
>
>                 //
> .BindNamedParameter(GenericType<DistRNetworkOptions.MessageHandler>.Cl
> ass,
> MessageHandler)
>         }
>
> When I try to inject,
>
>            IConfiguration nameClientConf = TangFactory.GetTang().
> NewConfigurationBuilder()
>                 .BindNamedParameter<NamingConfigurationOptions.
> NameServerPort,
> int>(
>                     GenericType<NamingConfigurationOptions.
> NameServerPort>.Class,
>                     
> endpoint.Port.ToString(CultureInfo.CurrentCulture))
>
> .BindNamedParameter<NamingConfigurationOptions.NameServerAddress,
> string>(
>
> GenericType<NamingConfigurationOptions.NameServerAddress>.Class,
> endpoint.Address.ToString())
>                 .BindImplementation(GenericType<INameClient>.Class,
> GenericType<NameClient>.Class)
>                 .Build();
>
>             IConfiguration networkServiceConf = TangFactory.GetTang().
> NewConfigurationBuilder()
>                 .BindIntNamedParam<NetworkServiceOptions.
> NetworkServicePort>(servicePort.ToString())
>                 .Build();
>
>             IConfiguration handlerConf = TangFactory.GetTang().
> NewConfigurationBuilder()
>                 .BindImplementation<IObserver<NsMessage<string>>,
> ClientMessageHandler>()
>                 .Build();
>
>             !!!!!!!!!!!THROWS!!!!!!!!!!!!
>             IConfiguration clientNetworkConfig = 
> NetworkOptions.ModuleBuilder.Config
>                 .Set(NetworkOptions.ModuleBuilder.NetService,
> GenericType<INetworkService<string>>.Class)
>                 .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
> clientId)
>                 .Set(NetworkOptions.ModuleBuilder.ServicePort,
> servicePort.ToString())
>                 
> .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
> driverId)
>                 .Build();
>
>             TangFactory.GetTang().NewInjector(
> GetRuntimeConfiguration(args.Length
> > 0 ? args[0] : Local),
>                 nameClientConf, networkServiceConf, handlerConf, 
> clientNetworkConfig).GetInstance<DistributedRClient>().Run();
>
> the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception
>
>
> System.TypeInitializationException occurred
>   HResult=0x80131534
>   Message=The type initializer for 'ModuleBuilder' threw an exception.
>   Source=Org.Apache.REEF.DistributedR
>   StackTrace:
>    at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] 
> args) in 
> E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:lin
> e
> 184
>
> Inner Exception 1:
> ClassHierarchyException: Found declared options that were not used in
> binds: { NetService }
>
>
> However when I remove it and the corresponding code in the 
> ModuleBuilder, I also get an exception about not being able to RDistributedR class.
>
> What am i missing?
>
> Doug
>

Re: Tang problem

Posted by Douglas Service <ds...@gmail.com>.
Hello Julia,

From reading your email and looking at the code, I see a number issues that
I still need to fix which I am working on now. I read the Tang
documentation on the website and then looked at many examples in the tests
and elsewhere in the code, but I clearly I missed a number of important
issues so thanks for your feedback!

Doug

On Thu, Apr 13, 2017 at 10:25 AM, Julia Wang (QIUHE) <
Qiuhe.Wang@microsoft.com.invalid> wrote:

> Hi Doug,
>
> The email below was stuck in the mail box yesterday afternoon because a
> network issue. It is now automatically sent out. As you already found the
> issue, that is fine. But you can still look at my recommendation.
>
> Julia
> -----Original Message-----
> From: Julia Wang (QIUHE) [mailto:Qiuhe.Wang@microsoft.com.INVALID]
> Sent: Thursday, April 13, 2017 10:17 AM
> To: dev@reef.apache.org
> Subject: RE: Tang problem
>
> I am not sure why you have a parameter like this:
>             [Parameter(typeof(NetworkOptions.NetService))]
> INetworkService<string> networkService, INetworkService is an interface,
> you don't need to define named parameter for it. You can directly put the
> following line as a parameter in the constructor.
>
> If you really want to use named parameter for this case, then NetService
> must be defined as a named parameter. But in your code, it is defined as a
> RequiredParameter
>             public static readonly RequiredParameter<INetworkService<string>>
> NetService = new RequiredParameter<INetworkService<string>>();
>
> You should not bind an interface into a required parameter in
> configuration module. It should be opposite.
> .BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
> GenericType<INetworkService<string>>.Class)
>
> To fix it,
> 1. put this line in the constructor instead of [parameter...]
>         INetworkService<string> networkService
>
> 2. Define the following in the ModuleBuilder
>          public static readonly RequiredImpl<INetworkService <string>>
> NetService = new RequiredImpl<INetworkService<string>>();
> and
>         .BindImplementation(GenericType<INetworkService <string>>.Class,
> NetworkOptions .NetService)
>
> 3. When you create clientNetworkConfig,
>         .Set(NetworkOptions.NetService, GenericType<NetworkService<
> string>>.Class)
>
> Hope that helps.
>
> Julia
>
> -----Original Message-----
> From: Douglas Service [mailto:dsopsrc@gmail.com]
> Sent: Wednesday, April 12, 2017 3:58 PM
> To: dev@reef.apache.org
> Subject: Tang problem
>
> Given the following constructor.
>
>
>         [Inject]
>         private ClientNetworkService(
>             [Parameter(typeof(NetworkOptions.NetService))]
> INetworkService<string> networkService,
>             [Parameter(typeof(NetworkOptions.ServiceIdentifier))] string
> serviceIdentifier,
>             [Parameter(typeof(NetworkOptions.ServicePort))] int
> servicePort,
>             [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
> string remoteServiceIdentifier)
>
> with the following module builder
>
>
>         public sealed class ModuleBuilder : ConfigurationModuleBuilder
>         {
>             public static readonly RequiredParameter<
> INetworkService<string>>
> NetService = new RequiredParameter<INetworkService<string>>();
>             public static readonly RequiredParameter<string>
> ServiceIdentifier = new RequiredParameter<string>();
>             public static readonly RequiredParameter<int> ServicePort =
> new RequiredParameter<int>();
>             public static readonly RequiredParameter<string>
> RemoteServiceIdentifier = new RequiredParameter<string>();
>
>             // public static readonly
> RequiredParameter<IObserver<NsMessage<string>>>
> ClientMessageHandler
>             //  = new RequiredParameter<IObserver<NsMessage<string>>>();
>             // .BindNamedParameter(GenericType<NetworkOptions.
> kService>.Class,
> NetworkService)
>             public static readonly ConfigurationModule Config = new
> ModuleBuilder()
>                 .BindImplementation(GenericType<INetworkService<
> string>>.Class,
> GenericType<NetworkService<string>>.Class)
>
> .BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
> GenericType<INetworkService<string>>.Class)
>
> .BindNamedParameter(GenericType<NetworkOptions.ServiceIdentifier>.Class,
> ServiceIdentifier)
>
> .BindNamedParameter(GenericType<NetworkOptions.ServicePort>.Class,
> ServicePort)
>                 .BindNamedParameter(GenericType<NetworkOptions.
> RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
>                 .Build();
>
>                 //
> .BindNamedParameter(GenericType<DistRNetworkOptions.MessageHandler>.Class,
> MessageHandler)
>         }
>
> When I try to inject,
>
>            IConfiguration nameClientConf = TangFactory.GetTang().
> NewConfigurationBuilder()
>                 .BindNamedParameter<NamingConfigurationOptions.
> NameServerPort,
> int>(
>                     GenericType<NamingConfigurationOptions.
> NameServerPort>.Class,
>                     endpoint.Port.ToString(CultureInfo.CurrentCulture))
>
> .BindNamedParameter<NamingConfigurationOptions.NameServerAddress,
> string>(
>
> GenericType<NamingConfigurationOptions.NameServerAddress>.Class,
> endpoint.Address.ToString())
>                 .BindImplementation(GenericType<INameClient>.Class,
> GenericType<NameClient>.Class)
>                 .Build();
>
>             IConfiguration networkServiceConf = TangFactory.GetTang().
> NewConfigurationBuilder()
>                 .BindIntNamedParam<NetworkServiceOptions.
> NetworkServicePort>(servicePort.ToString())
>                 .Build();
>
>             IConfiguration handlerConf = TangFactory.GetTang().
> NewConfigurationBuilder()
>                 .BindImplementation<IObserver<NsMessage<string>>,
> ClientMessageHandler>()
>                 .Build();
>
>             !!!!!!!!!!!THROWS!!!!!!!!!!!!
>             IConfiguration clientNetworkConfig =
> NetworkOptions.ModuleBuilder.Config
>                 .Set(NetworkOptions.ModuleBuilder.NetService,
> GenericType<INetworkService<string>>.Class)
>                 .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
> clientId)
>                 .Set(NetworkOptions.ModuleBuilder.ServicePort,
> servicePort.ToString())
>                 .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
> driverId)
>                 .Build();
>
>             TangFactory.GetTang().NewInjector(
> GetRuntimeConfiguration(args.Length
> > 0 ? args[0] : Local),
>                 nameClientConf, networkServiceConf, handlerConf,
> clientNetworkConfig).GetInstance<DistributedRClient>().Run();
>
> the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception
>
>
> System.TypeInitializationException occurred
>   HResult=0x80131534
>   Message=The type initializer for 'ModuleBuilder' threw an exception.
>   Source=Org.Apache.REEF.DistributedR
>   StackTrace:
>    at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] args)
> in E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:line
> 184
>
> Inner Exception 1:
> ClassHierarchyException: Found declared options that were not used in
> binds: { NetService }
>
>
> However when I remove it and the corresponding code in the ModuleBuilder,
> I also get an exception about not being able to RDistributedR class.
>
> What am i missing?
>
> Doug
>

RE: Tang problem

Posted by "Julia Wang (QIUHE)" <Qi...@microsoft.com.INVALID>.
Hi Doug,

The email below was stuck in the mail box yesterday afternoon because a network issue. It is now automatically sent out. As you already found the issue, that is fine. But you can still look at my recommendation. 

Julia
-----Original Message-----
From: Julia Wang (QIUHE) [mailto:Qiuhe.Wang@microsoft.com.INVALID] 
Sent: Thursday, April 13, 2017 10:17 AM
To: dev@reef.apache.org
Subject: RE: Tang problem

I am not sure why you have a parameter like this:
            [Parameter(typeof(NetworkOptions.NetService))] INetworkService<string> networkService, INetworkService is an interface, you don't need to define named parameter for it. You can directly put the following line as a parameter in the constructor. 

If you really want to use named parameter for this case, then NetService must be defined as a named parameter. But in your code, it is defined as a RequiredParameter
            public static readonly RequiredParameter<INetworkService<string>> NetService = new RequiredParameter<INetworkService<string>>();

You should not bind an interface into a required parameter in configuration module. It should be opposite. 
.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class, GenericType<INetworkService<string>>.Class)

To fix it,
1. put this line in the constructor instead of [parameter...]
	INetworkService<string> networkService

2. Define the following in the ModuleBuilder
	 public static readonly RequiredImpl<INetworkService <string>> NetService = new RequiredImpl<INetworkService<string>>();
and 
  	.BindImplementation(GenericType<INetworkService <string>>.Class, NetworkOptions .NetService)

3. When you create clientNetworkConfig, 
	.Set(NetworkOptions.NetService, GenericType<NetworkService<string>>.Class)

Hope that helps.

Julia

-----Original Message-----
From: Douglas Service [mailto:dsopsrc@gmail.com]
Sent: Wednesday, April 12, 2017 3:58 PM
To: dev@reef.apache.org
Subject: Tang problem

Given the following constructor.


        [Inject]
        private ClientNetworkService(
            [Parameter(typeof(NetworkOptions.NetService))]
INetworkService<string> networkService,
            [Parameter(typeof(NetworkOptions.ServiceIdentifier))] string serviceIdentifier,
            [Parameter(typeof(NetworkOptions.ServicePort))] int servicePort,
            [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
string remoteServiceIdentifier)

with the following module builder


        public sealed class ModuleBuilder : ConfigurationModuleBuilder
        {
            public static readonly RequiredParameter<INetworkService<string>>
NetService = new RequiredParameter<INetworkService<string>>();
            public static readonly RequiredParameter<string> ServiceIdentifier = new RequiredParameter<string>();
            public static readonly RequiredParameter<int> ServicePort = new RequiredParameter<int>();
            public static readonly RequiredParameter<string> RemoteServiceIdentifier = new RequiredParameter<string>();

            // public static readonly
RequiredParameter<IObserver<NsMessage<string>>>
ClientMessageHandler
            //  = new RequiredParameter<IObserver<NsMessage<string>>>();
            // .BindNamedParameter(GenericType<NetworkOptions.kService>.Class,
NetworkService)
            public static readonly ConfigurationModule Config = new
ModuleBuilder()
                .BindImplementation(GenericType<INetworkService<string>>.Class,
GenericType<NetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
GenericType<INetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.ServiceIdentifier>.Class,
ServiceIdentifier)

.BindNamedParameter(GenericType<NetworkOptions.ServicePort>.Class,
ServicePort)
                .BindNamedParameter(GenericType<NetworkOptions.
RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
                .Build();

                //
.BindNamedParameter(GenericType<DistRNetworkOptions.MessageHandler>.Class,
MessageHandler)
        }

When I try to inject,

           IConfiguration nameClientConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindNamedParameter<NamingConfigurationOptions.NameServerPort,
int>(
                    GenericType<NamingConfigurationOptions.
NameServerPort>.Class,
                    endpoint.Port.ToString(CultureInfo.CurrentCulture))

.BindNamedParameter<NamingConfigurationOptions.NameServerAddress,
string>(

GenericType<NamingConfigurationOptions.NameServerAddress>.Class,
endpoint.Address.ToString())
                .BindImplementation(GenericType<INameClient>.Class,
GenericType<NameClient>.Class)
                .Build();

            IConfiguration networkServiceConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindIntNamedParam<NetworkServiceOptions.
NetworkServicePort>(servicePort.ToString())
                .Build();

            IConfiguration handlerConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindImplementation<IObserver<NsMessage<string>>,
ClientMessageHandler>()
                .Build();

            !!!!!!!!!!!THROWS!!!!!!!!!!!!
            IConfiguration clientNetworkConfig = NetworkOptions.ModuleBuilder.Config
                .Set(NetworkOptions.ModuleBuilder.NetService,
GenericType<INetworkService<string>>.Class)
                .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
clientId)
                .Set(NetworkOptions.ModuleBuilder.ServicePort,
servicePort.ToString())
                .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
driverId)
                .Build();

            TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(args.Length
> 0 ? args[0] : Local),
                nameClientConf, networkServiceConf, handlerConf, clientNetworkConfig).GetInstance<DistributedRClient>().Run();

the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception


System.TypeInitializationException occurred
  HResult=0x80131534
  Message=The type initializer for 'ModuleBuilder' threw an exception.
  Source=Org.Apache.REEF.DistributedR
  StackTrace:
   at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] args) in E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:line
184

Inner Exception 1:
ClassHierarchyException: Found declared options that were not used in
binds: { NetService }


However when I remove it and the corresponding code in the ModuleBuilder, I also get an exception about not being able to RDistributedR class.

What am i missing?

Doug

RE: Tang problem

Posted by "Julia Wang (QIUHE)" <Qi...@microsoft.com.INVALID>.
I am not sure why you have a parameter like this:
            [Parameter(typeof(NetworkOptions.NetService))] INetworkService<string> networkService,
INetworkService is an interface, you don't need to define named parameter for it. You can directly put the following line as a parameter in the constructor. 

If you really want to use named parameter for this case, then NetService must be defined as a named parameter. But in your code, it is defined as a RequiredParameter
            public static readonly RequiredParameter<INetworkService<string>> NetService = new RequiredParameter<INetworkService<string>>();

You should not bind an interface into a required parameter in configuration module. It should be opposite. 
.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class, GenericType<INetworkService<string>>.Class)

To fix it, 
1. put this line in the constructor instead of [parameter...]
	INetworkService<string> networkService

2. Define the following in the ModuleBuilder
	 public static readonly RequiredImpl<INetworkService <string>> NetService = new RequiredImpl<INetworkService<string>>();
and 
  	.BindImplementation(GenericType<INetworkService <string>>.Class, NetworkOptions .NetService)

3. When you create clientNetworkConfig, 
	.Set(NetworkOptions.NetService, GenericType<NetworkService<string>>.Class)

Hope that helps.

Julia

-----Original Message-----
From: Douglas Service [mailto:dsopsrc@gmail.com] 
Sent: Wednesday, April 12, 2017 3:58 PM
To: dev@reef.apache.org
Subject: Tang problem

Given the following constructor.


        [Inject]
        private ClientNetworkService(
            [Parameter(typeof(NetworkOptions.NetService))]
INetworkService<string> networkService,
            [Parameter(typeof(NetworkOptions.ServiceIdentifier))] string serviceIdentifier,
            [Parameter(typeof(NetworkOptions.ServicePort))] int servicePort,
            [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
string remoteServiceIdentifier)

with the following module builder


        public sealed class ModuleBuilder : ConfigurationModuleBuilder
        {
            public static readonly RequiredParameter<INetworkService<string>>
NetService = new RequiredParameter<INetworkService<string>>();
            public static readonly RequiredParameter<string> ServiceIdentifier = new RequiredParameter<string>();
            public static readonly RequiredParameter<int> ServicePort = new RequiredParameter<int>();
            public static readonly RequiredParameter<string> RemoteServiceIdentifier = new RequiredParameter<string>();

            // public static readonly
RequiredParameter<IObserver<NsMessage<string>>>
ClientMessageHandler
            //  = new RequiredParameter<IObserver<NsMessage<string>>>();
            // .BindNamedParameter(GenericType<NetworkOptions.kService>.Class,
NetworkService)
            public static readonly ConfigurationModule Config = new
ModuleBuilder()
                .BindImplementation(GenericType<INetworkService<string>>.Class,
GenericType<NetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
GenericType<INetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.ServiceIdentifier>.Class,
ServiceIdentifier)

.BindNamedParameter(GenericType<NetworkOptions.ServicePort>.Class,
ServicePort)
                .BindNamedParameter(GenericType<NetworkOptions.
RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
                .Build();

                //
.BindNamedParameter(GenericType<DistRNetworkOptions.MessageHandler>.Class,
MessageHandler)
        }

When I try to inject,

           IConfiguration nameClientConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindNamedParameter<NamingConfigurationOptions.NameServerPort,
int>(
                    GenericType<NamingConfigurationOptions.
NameServerPort>.Class,
                    endpoint.Port.ToString(CultureInfo.CurrentCulture))

.BindNamedParameter<NamingConfigurationOptions.NameServerAddress,
string>(

GenericType<NamingConfigurationOptions.NameServerAddress>.Class,
endpoint.Address.ToString())
                .BindImplementation(GenericType<INameClient>.Class,
GenericType<NameClient>.Class)
                .Build();

            IConfiguration networkServiceConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindIntNamedParam<NetworkServiceOptions.
NetworkServicePort>(servicePort.ToString())
                .Build();

            IConfiguration handlerConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindImplementation<IObserver<NsMessage<string>>,
ClientMessageHandler>()
                .Build();

            !!!!!!!!!!!THROWS!!!!!!!!!!!!
            IConfiguration clientNetworkConfig = NetworkOptions.ModuleBuilder.Config
                .Set(NetworkOptions.ModuleBuilder.NetService,
GenericType<INetworkService<string>>.Class)
                .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
clientId)
                .Set(NetworkOptions.ModuleBuilder.ServicePort,
servicePort.ToString())
                .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
driverId)
                .Build();

            TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(args.Length
> 0 ? args[0] : Local),
                nameClientConf, networkServiceConf, handlerConf, clientNetworkConfig).GetInstance<DistributedRClient>().Run();

the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception


System.TypeInitializationException occurred
  HResult=0x80131534
  Message=The type initializer for 'ModuleBuilder' threw an exception.
  Source=Org.Apache.REEF.DistributedR
  StackTrace:
   at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] args) in E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:line
184

Inner Exception 1:
ClassHierarchyException: Found declared options that were not used in
binds: { NetService }


However when I remove it and the corresponding code in the ModuleBuilder, I also get an exception about not being able to RDistributedR class.

What am i missing?

Doug

RE: Tang problem

Posted by "Julia Wang (QIUHE)" <Qi...@microsoft.com.INVALID>.
I was looking at it, yes that was the issue. Always:

1. Bind RequiredParameter/OptionalParamter to the interface in configuration module
2. Set implementation to the requiredParameter/optionalParameter in configuration when configuration module is used. 

If you don't use configuration module, a direct way is to bind implementation to interface. 

Julia

-----Original Message-----
From: Douglas Service [mailto:dsopsrc@gmail.com] 
Sent: Wednesday, April 12, 2017 9:38 PM
To: dev@reef.apache.org
Subject: Re: Tang problem

I had mistakenly put (see bold below)

            public static readonly ConfigurationModule Config = new
ModuleBuilder()

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
*GenericType<INetworkService<string>.Class*)

instead of

            public static readonly ConfigurationModule Config = new
ModuleBuilder()

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
*NetService*)
                ......

The error message told me NetService was not getting bound. Debugging I noticed it was not getting added to the reqUsed queue in the ConfigurationModuleBuilder because the wrong version of .BindNamedParameter(), which does not call ProcessUse(), was being called.
Knowing that it was the last parameter in the call that was causing NetService to be not be considered bound by the ConfigurationModuleBuilder would have been helpful.

Doug

On Thu, Apr 13, 2017 at 4:19 AM, Markus Weimer <ma...@weimo.de> wrote:

> On Wed, Apr 12, 2017 at 8:45 PM, Douglas Service <ds...@gmail.com>
> wrote:
> > Fixed the issue by spending a long time stepping through the tang code.
>
>
> What was the root cause? Any learnings for better Tang error messages?
>
> Markus
>

Re: Tang problem

Posted by Douglas Service <ds...@gmail.com>.
I had mistakenly put (see bold below)

            public static readonly ConfigurationModule Config = new
ModuleBuilder()

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
*GenericType<INetworkService<string>.Class*)

instead of

            public static readonly ConfigurationModule Config = new
ModuleBuilder()

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
*NetService*)
                ......

The error message told me NetService was not getting bound. Debugging I
noticed it was not getting added to the reqUsed queue in the
ConfigurationModuleBuilder because the wrong version of
.BindNamedParameter(), which does not call ProcessUse(), was being called.
Knowing that it was the last parameter in the call that was causing
NetService to be not be considered bound by the ConfigurationModuleBuilder
would have been helpful.

Doug

On Thu, Apr 13, 2017 at 4:19 AM, Markus Weimer <ma...@weimo.de> wrote:

> On Wed, Apr 12, 2017 at 8:45 PM, Douglas Service <ds...@gmail.com>
> wrote:
> > Fixed the issue by spending a long time stepping through the tang code.
>
>
> What was the root cause? Any learnings for better Tang error messages?
>
> Markus
>

Re: Tang problem

Posted by Markus Weimer <ma...@weimo.de>.
On Wed, Apr 12, 2017 at 8:45 PM, Douglas Service <ds...@gmail.com> wrote:
> Fixed the issue by spending a long time stepping through the tang code.


What was the root cause? Any learnings for better Tang error messages?

Markus

Re: Tang problem

Posted by Douglas Service <ds...@gmail.com>.
Fixed the issue by spending a long time stepping through the tang code.

Thanks if you took a look.

On Wed, Apr 12, 2017 at 10:57 PM, Douglas Service <ds...@gmail.com> wrote:

> Given the following constructor.
>
>
>         [Inject]
>         private ClientNetworkService(
>             [Parameter(typeof(NetworkOptions.NetService))]
> INetworkService<string> networkService,
>             [Parameter(typeof(NetworkOptions.ServiceIdentifier))] string
> serviceIdentifier,
>             [Parameter(typeof(NetworkOptions.ServicePort))] int
> servicePort,
>             [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
> string remoteServiceIdentifier)
>
> with the following module builder
>
>
>         public sealed class ModuleBuilder : ConfigurationModuleBuilder
>         {
>             public static readonly RequiredParameter<INetworkService<string>>
> NetService = new RequiredParameter<INetworkService<string>>();
>             public static readonly RequiredParameter<string>
> ServiceIdentifier = new RequiredParameter<string>();
>             public static readonly RequiredParameter<int> ServicePort =
> new RequiredParameter<int>();
>             public static readonly RequiredParameter<string>
> RemoteServiceIdentifier = new RequiredParameter<string>();
>
>             // public static readonly RequiredParameter<IObserver<NsMessage<string>>>
> ClientMessageHandler
>             //  = new RequiredParameter<IObserver<NsMessage<string>>>();
>             // .BindNamedParameter(GenericType<NetworkOptions.kService>.Class,
> NetworkService)
>             public static readonly ConfigurationModule Config = new
> ModuleBuilder()
>                 .BindImplementation(GenericType<INetworkService<string>>.Class,
> GenericType<NetworkService<string>>.Class)
>                 .BindNamedParameter(GenericTyp
> e<NetworkOptions.NetService>.Class, GenericType<INetworkService<st
> ring>>.Class)
>                 .BindNamedParameter(GenericTyp
> e<NetworkOptions.ServiceIdentifier>.Class, ServiceIdentifier)
>                 .BindNamedParameter(GenericTyp
> e<NetworkOptions.ServicePort>.Class, ServicePort)
>                 .BindNamedParameter(GenericTyp
> e<NetworkOptions.RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
>                 .Build();
>
>                 // .BindNamedParameter(GenericTyp
> e<DistRNetworkOptions.MessageHandler>.Class, MessageHandler)
>         }
>
> When I try to inject,
>
>            IConfiguration nameClientConf = TangFactory.GetTang().NewConfi
> gurationBuilder()
>                 .BindNamedParameter<NamingConf
> igurationOptions.NameServerPort, int>(
>                     GenericType<NamingConfiguratio
> nOptions.NameServerPort>.Class,
>                     endpoint.Port.ToString(CultureInfo.CurrentCulture))
>                 .BindNamedParameter<NamingConf
> igurationOptions.NameServerAddress, string>(
>                     GenericType<NamingConfiguratio
> nOptions.NameServerAddress>.Class, endpoint.Address.ToString())
>                 .BindImplementation(GenericType<INameClient>.Class,
> GenericType<NameClient>.Class)
>                 .Build();
>
>             IConfiguration networkServiceConf =
> TangFactory.GetTang().NewConfigurationBuilder()
>                 .BindIntNamedParam<NetworkServ
> iceOptions.NetworkServicePort>(servicePort.ToString())
>                 .Build();
>
>             IConfiguration handlerConf = TangFactory.GetTang().NewConfi
> gurationBuilder()
>                 .BindImplementation<IObserver<NsMessage<string>>,
> ClientMessageHandler>()
>                 .Build();
>
>             !!!!!!!!!!!THROWS!!!!!!!!!!!!
>             IConfiguration clientNetworkConfig =
> NetworkOptions.ModuleBuilder.Config
>                 .Set(NetworkOptions.ModuleBuilder.NetService,
> GenericType<INetworkService<string>>.Class)
>                 .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
> clientId)
>                 .Set(NetworkOptions.ModuleBuilder.ServicePort,
> servicePort.ToString())
>                 .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
> driverId)
>                 .Build();
>
>             TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(args.Length
> > 0 ? args[0] : Local),
>                 nameClientConf, networkServiceConf, handlerConf,
> clientNetworkConfig).GetInstance<DistributedRClient>().Run();
>
> the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception
>
>
> System.TypeInitializationException occurred
>   HResult=0x80131534
>   Message=The type initializer for 'ModuleBuilder' threw an exception.
>   Source=Org.Apache.REEF.DistributedR
>   StackTrace:
>    at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] args)
> in E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:line
> 184
>
> Inner Exception 1:
> ClassHierarchyException: Found declared options that were not used in
> binds: { NetService }
>
>
> However when I remove it and the corresponding code in the ModuleBuilder,
> I also get an exception about not being able to RDistributedR class.
>
> What am i missing?
>
> Doug
>