Example #1
0
        public async stt::Task GetRuntimeRequestObjectAsync()
        {
            moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient> mockGrpcClient = new moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetRuntimeRequest request = new GetRuntimeRequest
            {
                RuntimeName = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"),
            };
            Runtime expectedResponse = new Runtime
            {
                RuntimeName    = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"),
                VirtualMachine = new VirtualMachine(),
                State          = Runtime.Types.State.Active,
                HealthState    = Runtime.Types.HealthState.Healthy,
                AccessConfig   = new RuntimeAccessConfig(),
                SoftwareConfig = new RuntimeSoftwareConfig(),
                Metrics        = new RuntimeMetrics(),
                CreateTime     = new wkt::Timestamp(),
                UpdateTime     = new wkt::Timestamp(),
            };

            mockGrpcClient.Setup(x => x.GetRuntimeAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Runtime>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            ManagedNotebookServiceClient client = new ManagedNotebookServiceClientImpl(mockGrpcClient.Object, null);
            Runtime responseCallSettings        = await client.GetRuntimeAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Runtime responseCancellationToken = await client.GetRuntimeAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Example #2
0
        public void GetRuntime()
        {
            moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient> mockGrpcClient = new moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetRuntimeRequest request = new GetRuntimeRequest
            {
                RuntimeName = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"),
            };
            Runtime expectedResponse = new Runtime
            {
                RuntimeName    = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"),
                VirtualMachine = new VirtualMachine(),
                State          = Runtime.Types.State.Active,
                HealthState    = Runtime.Types.HealthState.Healthy,
                AccessConfig   = new RuntimeAccessConfig(),
                SoftwareConfig = new RuntimeSoftwareConfig(),
                Metrics        = new RuntimeMetrics(),
                CreateTime     = new wkt::Timestamp(),
                UpdateTime     = new wkt::Timestamp(),
            };

            mockGrpcClient.Setup(x => x.GetRuntime(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ManagedNotebookServiceClient client = new ManagedNotebookServiceClientImpl(mockGrpcClient.Object, null);
            Runtime response = client.GetRuntime(request.Name);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #3
0
 public EvaluatorDescriptor(
     INodeDescriptor nodeDescriptor,
     int memory,
     int virtualCore,
     RuntimeName runtimeName = RuntimeName.Local)
 {
     NodeDescriptor = nodeDescriptor;
     Memory         = memory;
     VirtualCore    = virtualCore;
     RuntimeName    = runtimeName;
 }
 /// <summary>
 /// Sets the runtime name for requested evaluators in the same request. The batch of Evaluators requested in the
 /// same request will have the same runtime name.
 /// </summary>
 /// <param name="runtimeName">The runtime name for the Evaluator request.</param>
 public EvaluatorRequestBuilder SetRuntimeName(RuntimeName runtimeName)
 {
     _runtimeName = (runtimeName == RuntimeName.Default) ? string.Empty : runtimeName.ToString();
     return(this);
 }
Example #5
0
        /// <summary>
        /// Constructor only to be used by the bridge.
        /// </summary>
        /// <param name="str"></param>
        public EvaluatorDescriptorImpl(string str)
        {
            var settings = new Dictionary<string, string>();
            var components = str.Split(',');
            foreach (var component in components)
            {
                var pair = component.Trim().Split('=');
                if (pair == null || pair.Length != 2)
                {
                    var e = new ArgumentException("invalid component to be used as key-value pair:", component);
                    Exceptions.Throw(e, LOGGER);
                }
                settings.Add(pair[0], pair[1]);
            }

            string runtimeNameStr;
            if (!settings.TryGetValue("RuntimeName", out runtimeNameStr))
            {
                Exceptions.Throw(new ArgumentException("cannot find RuntimeName entry"), LOGGER);
            }

            RuntimeName runtimeName;

            if (!Enum.TryParse(runtimeNameStr, true, out runtimeName))
            {
                Exceptions.Throw(new ArgumentException("cannot parse RuntimeName entry"), LOGGER);
            }

            string ipAddress;
            if (!settings.TryGetValue("IP", out ipAddress))
            {
                Exceptions.Throw(new ArgumentException("cannot find IP entry"), LOGGER);
            }
            ipAddress = ipAddress.Split('/').Last();
            string port;
            if (!settings.TryGetValue("Port", out port))
            {
                Exceptions.Throw(new ArgumentException("cannot find Port entry"), LOGGER);
            }
            var portNumber = 0;
            int.TryParse(port, out portNumber);
            string hostName;
            if (!settings.TryGetValue("HostName", out hostName))
            {
                Exceptions.Throw(new ArgumentException("cannot find HostName entry"), LOGGER);
            }
            string memory;
            if (!settings.TryGetValue("Memory", out memory))
            {
                Exceptions.Throw(new ArgumentException("cannot find Memory entry"), LOGGER);
            }
            var memoryInMegaBytes = 0;
            int.TryParse(memory, out memoryInMegaBytes);

            string core;
            if (!settings.TryGetValue("Core", out core))
            {
                Exceptions.Throw(new ArgumentException("cannot find Core entry"), LOGGER);
            }
            var vCore = 0;
            int.TryParse(core, out vCore);

            var ipEndPoint = new IPEndPoint(IPAddress.Parse(ipAddress), portNumber);

            _nodeDescriptor = new NodeDescriptorImpl { InetSocketAddress = ipEndPoint, HostName = hostName };
            _evaluatorType = EvaluatorType.CLR;
            _megaBytes = memoryInMegaBytes;
            _core = vCore;
            _runtimeName = runtimeName;
        }
        /// <summary>
        /// Constructor only to be used by the bridge.
        /// </summary>
        /// <param name="str"></param>
        public EvaluatorDescriptorImpl(string str)
        {
            var settings   = new Dictionary <string, string>();
            var components = str.Split(',');

            foreach (var component in components)
            {
                var pair = component.Trim().Split('=');
                if (pair == null || pair.Length != 2)
                {
                    var e = new ArgumentException("invalid component to be used as key-value pair:", component);
                    Exceptions.Throw(e, LOGGER);
                }
                settings.Add(pair[0], pair[1]);
            }

            string runtimeNameStr;

            if (!settings.TryGetValue("RuntimeName", out runtimeNameStr))
            {
                Exceptions.Throw(new ArgumentException("cannot find RuntimeName entry"), LOGGER);
            }

            RuntimeName runtimeName;

            if (!Enum.TryParse(runtimeNameStr, true, out runtimeName))
            {
                Exceptions.Throw(new ArgumentException("cannot parse RuntimeName entry"), LOGGER);
            }

            string ipAddress;

            if (!settings.TryGetValue("IP", out ipAddress))
            {
                Exceptions.Throw(new ArgumentException("cannot find IP entry"), LOGGER);
            }
            ipAddress = ipAddress.Split('/').Last();
            string port;

            if (!settings.TryGetValue("Port", out port))
            {
                Exceptions.Throw(new ArgumentException("cannot find Port entry"), LOGGER);
            }
            var portNumber = 0;

            int.TryParse(port, out portNumber);
            string hostName;

            if (!settings.TryGetValue("HostName", out hostName))
            {
                Exceptions.Throw(new ArgumentException("cannot find HostName entry"), LOGGER);
            }
            string memory;

            if (!settings.TryGetValue("Memory", out memory))
            {
                Exceptions.Throw(new ArgumentException("cannot find Memory entry"), LOGGER);
            }
            var memoryInMegaBytes = 0;

            int.TryParse(memory, out memoryInMegaBytes);

            string core;

            if (!settings.TryGetValue("Core", out core))
            {
                Exceptions.Throw(new ArgumentException("cannot find Core entry"), LOGGER);
            }
            var vCore = 0;

            int.TryParse(core, out vCore);

            var ipEndPoint = new IPEndPoint(IPAddress.Parse(ipAddress), portNumber);

            _nodeDescriptor = new NodeDescriptorImpl {
                InetSocketAddress = ipEndPoint, HostName = hostName
            };
            _evaluatorType = EvaluatorType.CLR;
            _megaBytes     = memoryInMegaBytes;
            _core          = vCore;
            _runtimeName   = runtimeName;
        }
Example #7
0
 /// <summary>
 /// Sets the runtime name for requested evaluators in the same request. The batch of Evaluators requested in the 
 /// same request will have the same runtime name.
 /// </summary>
 /// <param name="runtimeName">The runtime name for the Evaluator request.</param>
 public EvaluatorRequestBuilder SetRuntimeName(RuntimeName runtimeName)
 {
     _runtimeName = (runtimeName == RuntimeName.Default) ? string.Empty : runtimeName.ToString();
     return this;
 }