Esempio n. 1
0
        public void ICanSerializeAndDeserializeUserChangeResponseWithErrorPackage()
        {
            var serverConverter = new ClusterProvisioningServerPayloadConverter();

            PassthroughResponse responseObject = new PassthroughResponse()
            {
                Data = Guid.NewGuid(),
                Error = new ErrorDetails()
                {
                    ErrorId = "Error123",
                    ErrorMessage = "ErrorMessage",
                    StatusCode = HttpStatusCode.NotAcceptable
                }
            };

            var payload = serverConverter.SerailizeChangeRequestResponse(responseObject);

            var deserialized = new PayloadConverter().DeserializeConnectivityResponse(payload);

            Assert.AreEqual(responseObject.Data, deserialized.Data, "Round trip serialize/deserialize enable RDP does not match the ID code");
            Assert.IsNotNull(deserialized.ErrorDetails, "No error object was present after deserialization.");
            Assert.AreEqual(responseObject.Error.ErrorId, deserialized.ErrorDetails.ErrorId, "The Error Id did not match after deserialization.");
            Assert.AreEqual(responseObject.Error.ErrorMessage, deserialized.ErrorDetails.ErrorMessage, "The error message did not match after deserialization.");
            Assert.AreEqual(responseObject.Error.StatusCode, deserialized.ErrorDetails.StatusCode, "The status code did not match after deserialization.");
        }
Esempio n. 2
0
        public void InternalValidation_PayloadConverter_ExtractResourceOutputValue()
        {
            // During serialization\deserialization it loses ms precission. Therefore using ms-less times 
            DateTime time1 = TruncateMiliseconds(DateTime.UtcNow), time2 = TruncateMiliseconds(DateTime.Now);

            // Creates a response
            var res = new Resource();
            res.OutputItems = new OutputItemList
            {
                new OutputItem { Key = "boolean", Value = "true" },
                new OutputItem { Key = "time1", Value = time1.ToString(CultureInfo.InvariantCulture) },
                new OutputItem { Key = "time2", Value = time2.ToString(CultureInfo.InvariantCulture) },
                new OutputItem { Key = "string", Value = "value" },
                new OutputItem { Key = "number", Value = "7" },
                new OutputItem { Key = "uri", Value = new Uri("https://some/long/uri/").AbsoluteUri },
            };

            XElement resourceElement = ServerSerializer.SerializeResource(res);

            // Validates nonexisting properties
            var payloadConverter = new PayloadConverter();
            Assert.AreEqual(DateTime.MinValue, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "nonexist"));
            Assert.AreEqual(null, payloadConverter.ExtractResourceOutputStringValue(resourceElement, "nonexist"));
            Assert.AreEqual(0, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "nonexist"));

            // Validates existing properties
            Assert.AreEqual(time1, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "time1"));
            Assert.AreEqual(time2, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "time2"));
            Assert.AreEqual("value", payloadConverter.ExtractResourceOutputStringValue(resourceElement, "string"));
            Assert.AreEqual(7, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "number"));
        }
 internal async Task<ComponentSettingAddress> GetComponentSettingAddress()
 {
     var restClient = ServiceLocator.Instance.Locate<IAzureHDInsightConfigurationRestClientFactory>().Create(this.credentials);
     var componentResponse = await restClient.GetComponentSettingsAddress();
     var converter = new PayloadConverter();
     return converter.DeSerializeComponentSettingAddresses(componentResponse.Content);
 }
 public async Task<OozieSiteConfigurationCollection> GetOozieServiceConfiguration()
 {
     var componentAddress = await this.GetComponentSettingAddress();
     var restClient = ServiceLocator.Instance.Locate<IAzureHDInsightConfigurationRestClientFactory>().Create(this.credentials);
     var componentSettingResponse = await restClient.GetComponentSettings(componentAddress.Core);
     var converter = new PayloadConverter();
     return converter.DeserializeSettingsCollection<OozieSiteConfigurationCollection>(componentSettingResponse.Content);
 }
 /// <inheritdoc />
 public async Task<JobDetails> GetJob(string jobId)
 {
     //NEIN: Any code modification here should add unit tests for this class
     var converter = new PayloadConverter();
     var client = ServiceLocator.Instance.Locate<IHadoopRemoteJobSubmissionRestClientFactory>().Create(this.credentials, this.context, this.ignoreSslErrors, this.GetUserAgentString());
     var result = await client.GetJob(jobId);
     return converter.DeserializeJobDetails(result.Content);
 }
 /// <inheritdoc />
 public async Task<JobCreationResults> SubmitMapReduceJob(MapReduceJobCreateParameters details)
 {
     //NEIN: Any code modification here should add unit tests for this class
     var converter = new PayloadConverter();
     var payload = converter.SerializeMapReduceRequest(this.credentials.UserName, details);
     var client = ServiceLocator.Instance.Locate<IHadoopRemoteJobSubmissionRestClientFactory>().Create(this.credentials, this.context, this.ignoreSslErrors, this.GetUserAgentString());
     var result = await client.SubmitMapReduceJob(payload);
     return new JobCreationResults() { JobId = converter.DeserializeJobSubmissionResponse(result.Content) };
 }
 public void CanDeserializeRootCall()
 {
     var converter = new PayloadConverter();
     var componentSettingsAddresses = converter.DeSerializeComponentSettingAddresses(RootCallsPayload);
     Assert.IsNotNull(componentSettingsAddresses);
     Assert.AreEqual(componentSettingsAddresses.Core.OriginalString, "https://apitestclusterrdfe19-fake.hdinsight.azure.net:563/ambari/api/v1/clusters/apitestclusterrdfe19-laureny/configurations/?type=core-site&tag=default");
     Assert.AreEqual(componentSettingsAddresses.Hive.OriginalString, "https://apitestclusterrdfe19-fake.hdinsight.azure.net:563/ambari/api/v1/clusters/apitestclusterrdfe19-laureny/configurations/?type=hive-site&tag=default");
     Assert.AreEqual(componentSettingsAddresses.Hdfs.OriginalString, "https://apitestclusterrdfe19-fake.hdinsight.azure.net:563/ambari/api/v1/clusters/apitestclusterrdfe19-laureny/configurations/?type=hdfs-site&tag=default");
     Assert.AreEqual(componentSettingsAddresses.MapReduce.OriginalString, "https://apitestclusterrdfe19-fake.hdinsight.azure.net:563/ambari/api/v1/clusters/apitestclusterrdfe19-laureny/configurations/?type=mapred-site&tag=default");
     Assert.AreEqual(componentSettingsAddresses.Oozie.OriginalString, "https://apitestclusterrdfe19-fake.hdinsight.azure.net:563/ambari/api/v1/clusters/apitestclusterrdfe19-laureny/configurations/?type=oozie-site&tag=default");
 }
        /// <summary>
        ///     Processes an incoming payload asynchronously.
        /// </summary>
        /// <remarks>
        ///     This method should not be called manually. It is called in the connection life cycle,
        ///     see: <see cref="RunLifeCycleAsync"/>.
        /// </remarks>
        /// <returns>a task that represents the asynchronous operation</returns>
        /// <exception cref="ObjectDisposedException">thrown if the instance is disposed</exception>
        private async Task ProcessNextPayload()
        {
            EnsureNotDisposed();

            WebSocketReceiveResult result;

            try
            {
                result = await _webSocket !.ReceiveAsync(new ArraySegment <byte>(_receiveBuffer, 0, _receiveBuffer.Length), _cancellationTokenSource !.Token);
            }
            catch (WebSocketException ex)
            {
                if (_cancellationTokenSource !.IsCancellationRequested)
                {
                    return;
                }

                Logger?.Log(ex, "Lavalink Node disconnected (without handshake, maybe connection loss or server crash)");
                await OnDisconnectedAsync(new DisconnectedEventArgs(_webSocketUri, WebSocketCloseStatus.Empty, string.Empty, true));

                _webSocket?.Dispose();
                _webSocket = null;
                return;
            }

            // check if the web socket received a close frame
            if (result.MessageType == WebSocketMessageType.Close)
            {
                Logger?.Log(this, string.Format("Lavalink Node disconnected: {0}, {1}.", result.CloseStatus.GetValueOrDefault(), result.CloseStatusDescription), LogLevel.Warning);
                await OnDisconnectedAsync(new DisconnectedEventArgs(_webSocketUri, result.CloseStatus.GetValueOrDefault(), result.CloseStatusDescription, true));

                _webSocket.Dispose();
                _webSocket = null;
                return;
            }

            var content = Encoding.UTF8.GetString(_receiveBuffer, 0, result.Count);

            if (!result.EndOfMessage)
            {
                // the server sent a message frame that is incomplete
                _overflowBuffer.Append(content);
                return;
            }

            // check if old data exists
            if (result.EndOfMessage && _overflowBuffer.Length > 0)
            {
                _overflowBuffer.Append(content);
                content = _overflowBuffer.ToString();
                _overflowBuffer.Clear();
            }

            if (_ioDebug)
            {
                Logger?.Log(this, string.Format("Received payload: `{0}` from: {1}.", content, _webSocketUri), LogLevel.Trace);
            }

            // process data
            try
            {
                var payload   = PayloadConverter.ReadPayload(content);
                var eventArgs = new PayloadReceivedEventArgs(payload, content);
                await OnPayloadReceived(eventArgs);
            }
            catch (Exception ex)
            {
                Logger?.Log(this, string.Format("Received bad payload: {0}.", content), LogLevel.Warning, ex);
                await CloseAsync(WebSocketCloseStatus.InvalidPayloadData);
            }
        }
Esempio n. 9
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequestWithHBaseConfiguration_ResourcesV3()
        {
            var expected = new HDInsight.ClusterCreateParameters
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                Version = "3.0",
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                ClusterSizeInNodes = new Random().Next(),
                ClusterType = ClusterType.HBase
            };

            expected.HBaseConfiguration.ConfigurationCollection.Add(new KeyValuePair<string, string>("my setting 1", "my value 1"));
            expected.HBaseConfiguration.ConfigurationCollection.Add(new KeyValuePair<string, string>("my setting 2", "my value 2"));
            expected.HBaseConfiguration.AdditionalLibraries = new WabStorageAccountConfiguration(
                Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            string payload = new PayloadConverter().SerializeClusterCreateRequestV3(expected);
            var actual = ServerSerializer.DeserializeClusterCreateRequestV3(payload);
            Assert.IsTrue(Equals(expected, actual));
        }
Esempio n. 10
0
    public void TestConvertVersionBPayloadFromProto()
    {
        var payload = PayloadConverter.ConvertVersionBPayload(new VersionB.ProtoBuf.ProtoBufPayload());

        Assert.IsNotNull(payload);
    }
Esempio n. 11
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequest_MayContracts()
        {
            var cluster1 = new HDInsight.ClusterCreateParameters
            {
                Name = "bcarlson",
                ClusterSizeInNodes = 1,
                UserName = "******",
                Version = "default",
                Password = "******",
                Location = "East US"
            };

            cluster1.DefaultStorageAccountName = "hdicurrenteastus.blob.core.windows.net";
            cluster1.DefaultStorageContainer = "newcontainer";
            cluster1.DefaultStorageAccountKey = "jKe7cqoU0a9OmDFlwi3DHZLf7JoKwGOU2pV1iZdBKifxwQuDOKwZFyXMJrPSLtGgDV9b7pVKSGz6lbBWcfX2lA==";

            var metaStore = new Metastore("lbl44y45cd.bigbean.windowsazure.mscds.com", "newmaytestdb", "bcarlson", "SuperPass1!");
            cluster1.HiveMetastore = cluster1.OozieMetastore = metaStore;

            string payload = new PayloadConverter().SerializeClusterCreateRequest(cluster1);
            var resource = ServerSerializer.DeserializeClusterCreateRequestIntoResource(payload);
            Assert.AreEqual(resource.SchemaVersion, "2.0");
        }
Esempio n. 12
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequestV3()
        {
            var cluster1 = new HDInsight.ClusterCreateParameters
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                Version = "3.0",
                ClusterSizeInNodes = new Random().Next(),
                ClusterType = ClusterType.HBase
            };
            cluster1.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(Guid.NewGuid().ToString("N"),
                                                                 Guid.NewGuid().ToString("N")));
            cluster1.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(Guid.NewGuid().ToString("N"),
                                                                 Guid.NewGuid().ToString("N")));

            string payload = new PayloadConverter().SerializeClusterCreateRequestV3(cluster1);
            var cluster2 = ServerSerializer.DeserializeClusterCreateRequestV3(payload);
            Assert.IsTrue(Equals(cluster1, cluster2));
        }
        public async Task<JobDetails> StopJob(string jobId)
        {
            var client = ServiceLocator.Instance.Locate<IHadoopRemoteJobSubmissionRestClientFactory>().Create(this.credentials, this.context, this.ignoreSslErrors, this.GetUserAgentString());
            var result = await client.StopJob(jobId);
            var converter = new PayloadConverter();

            return converter.DeserializeJobDetails(result.Content);
        }
Esempio n. 14
0
    public void TestConvertVersionBDataTypeDataSetValueToProto()
    {
        var payload = PayloadConverter.ConvertVersionBDataTypeDataSetValue(new VersionB.Data.DataType());

        Assert.IsNotNull(payload);
    }
Esempio n. 15
0
    public void TestConvertVersionBDataTypeDataSetValueFromProto()
    {
        var payload = PayloadConverter.ConvertVersionBDataTypeDataSetValue(new VersionB.ProtoBuf.ProtoBufPayload.DataSet.DataSetValue.ValueOneofCase());

        Assert.IsNotNull(payload);
    }
Esempio n. 16
0
    public void TestConvertVersionADataTypeFromProto()
    {
        var payload = PayloadConverter.ConvertVersionADataType(new VersionA.ProtoBuf.ProtoBufPayload.KuraMetric.ValueType());

        Assert.IsNotNull(payload);
    }
Esempio n. 17
0
    public void TestConvertVersionBPayloadToProto()
    {
        var payload = PayloadConverter.ConvertVersionBPayload(new VersionB.Data.Payload());

        Assert.IsNotNull(payload);
    }
Esempio n. 18
0
    public void TestConvertVersionBDataTypeParameterFromProto()
    {
        var payload = PayloadConverter.ConvertVersionBDataTypeParameter(new VersionB.ProtoBuf.ProtoBufPayload.Template.Parameter.ValueOneofCase());

        Assert.IsNotNull(payload);
    }
Esempio n. 19
0
        public void InternalValidation_PayloadConverter_SerializationListContainersResult_WithoutErrorWithExtendedError()
        {
            var storageAccount = new WabStorageAccountConfiguration(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            var container1 = new ClusterDetails(GetRandomClusterName(), "ClusterStorageProvisioned")
            {
                CreatedDate = DateTime.Now,
                ConnectionUrl = @"https://some/long/uri/",
                HttpUserName = "******",
                Location = "West US",
                ClusterSizeInNodes = 10,
                Error = new ClusterErrorStatus(10, "error", "create"),
                Version = IntegrationTestBase.TestCredentials.WellKnownCluster.Version,
            };
            container1.DefaultStorageAccount = storageAccount;
            container1.AdditionalStorageAccounts = new List<WabStorageAccountConfiguration>() 
            { 
                new WabStorageAccountConfiguration(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
                new WabStorageAccountConfiguration(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) 
            };

            var originalContainers = new Collection<ClusterDetails> { container1 };

            Guid subscriptionId = new Guid();
            var payload = ServerSerializer.SerializeListContainersResult(originalContainers, "namespace", false, true);
            var finalContainers = new PayloadConverter().DeserializeListContainersResult(payload, "namespace", subscriptionId);

            Assert.AreEqual(originalContainers.Count, finalContainers.Count);
            var deserializedCluster = finalContainers.FirstOrDefault(cluster => cluster.Name == container1.Name);
            Assert.IsNotNull(deserializedCluster);
            Assert.AreEqual(deserializedCluster.SubscriptionId, subscriptionId);
            Assert.AreEqual(deserializedCluster.Error.Message, "error");
            Assert.AreEqual(deserializedCluster.Error.HttpCode, 10);
            Assert.AreEqual(deserializedCluster.Error.OperationType, "create");
        }
Esempio n. 20
0
        public void ICanSerializeAndDeserializeUserChangeResponse()
        {
            var serverConverter = new ClusterProvisioningServerPayloadConverter();

            PassthroughResponse responseObject = new PassthroughResponse() { Data = Guid.NewGuid() };

            var payload = serverConverter.SerailizeChangeRequestResponse(responseObject);

            var deserialized = new PayloadConverter().DeserializeConnectivityResponse(payload);

            Assert.AreEqual(responseObject.Data, deserialized.Data, "Round trip serialize/deserialize enable RDP does not match the ID code");
        }
Esempio n. 21
0
 public void InternalValidation_PayloadConverter_SerializationCreateRequest_HeadNodeSize_SupportedValues()
 {
     var supportedHeadNodeSizes = (NodeVMSize[])Enum.GetValues(typeof(NodeVMSize));
     for (int i = 0; i < supportedHeadNodeSizes.Length; i++)
     {
         var cluster1 = GetClusterCreateParametersForHeadNodeSize(NodeVMSize.Default);
         string payload = new PayloadConverter().SerializeClusterCreateRequest(cluster1);
         var cluster2 = ServerSerializer.DeserializeClusterCreateRequest(payload);
         Assert.IsTrue(Equals(cluster1, cluster2));
     }
 }
Esempio n. 22
0
        public void InternalValidation_PayloadConverter_SerializationCreateHadoopClusterRequestWithVirtualNetworkConfigurationV3()
        {
            var expected = new HDInsight.ClusterCreateParameters
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                Version = "3.0",
                ClusterSizeInNodes = new Random().Next()
            };
            expected.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(Guid.NewGuid().ToString("N"),
                                                                 Guid.NewGuid().ToString("N")));
            expected.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(Guid.NewGuid().ToString("N"),
                                                                 Guid.NewGuid().ToString("N")));
            expected.VirtualNetworkId = Guid.NewGuid().ToString();
            expected.SubnetName = "MySubnet";

            string payload = new PayloadConverter().SerializeClusterCreateRequestV3(expected);
            var actual = ServerSerializer.DeserializeClusterCreateRequestV3(payload);
            Assert.IsTrue(Equals(expected, actual));
        }
Esempio n. 23
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequestWithHiveConfiguration()
        {
            var expected = new HDInsight.ClusterCreateParameters
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                Version = IntegrationTestBase.TestCredentials.WellKnownCluster.Version,
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                ClusterSizeInNodes = new Random().Next()
            };

            expected.HiveConfiguration.ConfigurationCollection.Add(new KeyValuePair<string, string>("my setting 1", "my value 1"));
            expected.HiveConfiguration.ConfigurationCollection.Add(new KeyValuePair<string, string>("my setting 2", "my value 2"));

            string payload = new PayloadConverter().SerializeClusterCreateRequest(expected);
            var actual = ServerSerializer.DeserializeClusterCreateRequest(payload);
            Assert.IsTrue(Equals(expected, actual));
        }
Esempio n. 24
0
    public void TestConvertVersionBDataTypeParameterToProto()
    {
        var payload = PayloadConverter.ConvertVersionBDataTypeParameter(new VersionB.Data.DataType());

        Assert.IsNotNull(payload);
    }
Esempio n. 25
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequestWithMetastore_Storm()
        {
            var expected = new HDInsight.ClusterCreateParameters
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                Version = "3.0",
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                ClusterSizeInNodes = new Random().Next(),
                ClusterType = ClusterType.Storm
            };
            expected.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(Guid.NewGuid().ToString("N"),
                                                                 Guid.NewGuid().ToString("N")));
            expected.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(Guid.NewGuid().ToString("N"),
                                                                 Guid.NewGuid().ToString("N")));
            expected.OozieMetastore = new Metastore(Guid.NewGuid().ToString("N"),
                                                             Guid.NewGuid().ToString("N"),
                                                             Guid.NewGuid().ToString("N"),
                                                             Guid.NewGuid().ToString("N"));
            expected.HiveMetastore = new Metastore(Guid.NewGuid().ToString("N"),
                                                            Guid.NewGuid().ToString("N"),
                                                            Guid.NewGuid().ToString("N"),
                                                            Guid.NewGuid().ToString("N"));

            string payload = new PayloadConverter().SerializeClusterCreateRequestV3(expected);
            var actual = ServerSerializer.DeserializeClusterCreateRequestV3(payload);
            Assert.IsTrue(Equals(expected, actual));
        }
Esempio n. 26
0
 public virtual object ExtractPayload(Message message)
 {
     return(PayloadConverter.FromMessage(message));
 }
Esempio n. 27
0
        public void InternalValidation_PayloadConverter_ExtractIntrinsicSettingsValue()
        {
            // During serialization\deserialization it loses ms precission. Therefore using ms-less times 
            DateTime time1 = TruncateMiliseconds(DateTime.UtcNow), time2 = TruncateMiliseconds(DateTime.Now);

            // Creates a response
            var res = new Resource();
            res.OutputItems = new OutputItemList();
            var intrinsicSettings = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string,string>("boolean", "true"),
                new KeyValuePair<string,string>("time1", time1.ToString(CultureInfo.InvariantCulture)),
                new KeyValuePair<string,string>("time2", time2.ToString(CultureInfo.InvariantCulture)),
                new KeyValuePair<string,string>("string", "value"),
                new KeyValuePair<string,string>("number", "7")
            };

            XElement resourceElement = ServerSerializer.SerializeResource(res, intrinsicSettings);

            // Validates nonexisting properties
            var payloadConverter = new PayloadConverter();
            Assert.AreEqual(DateTime.MinValue, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, intrinsicSettings, "nonexist"));
            Assert.AreEqual(null, payloadConverter.GetClusterProperty(resourceElement, intrinsicSettings, "nonexist"));
            Assert.AreEqual(0, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, intrinsicSettings, "nonexist"));

            // Validates existing properties
            Assert.AreEqual(time1, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, intrinsicSettings, "time1"));
            Assert.AreEqual(time2, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, intrinsicSettings, "time2"));
            Assert.AreEqual("value", payloadConverter.GetClusterProperty(resourceElement, intrinsicSettings, "string"));
            Assert.AreEqual(7, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, intrinsicSettings, "number"));
        }
        public async Task ICannotPerformA_CreateContainersOnUnregisterdSubscription_Using_RestClient()
        {
            IHDInsightCertificateCredential credentials = IntegrationTestBase.GetValidCredentials();

            // Unregisters location
            var location = "North Europe";
            DeleteClusters(credentials, location);
            var client = ServiceLocator.Instance.Locate<ISubscriptionRegistrationClientFactory>().Create(credentials, GetAbstractionContext(), false);
            if (await client.ValidateSubscriptionLocation(location))
            {
                await client.UnregisterSubscriptionLocation(location);
            }
            Assert.IsFalse(await client.ValidateSubscriptionLocation(location), "Subscription location '{0}' is still registered.", location);

            try
            {
                // Creates the cluster
                var restClient = ServiceLocator.Instance.Locate<IHDInsightManagementRestClientFactory>().Create(credentials, GetAbstractionContext(), false);
                var cluster = GetRandomCluster();
                string payload = new PayloadConverter().SerializeClusterCreateRequest(cluster);
                await restClient.CreateContainer(cluster.Name, location, payload);

                Assert.Fail("Expected exception.");
            }
            catch (HttpLayerException e)
            {
                Assert.AreEqual(HttpStatusCode.NotFound, e.RequestStatusCode);
                // Error looks like The cloud service with name [namespace] was not found.
                Assert.IsTrue(e.RequestContent.Contains("The cloud service with name"));
                Assert.IsTrue(e.RequestContent.Contains("was not found."));
            }
        }
Esempio n. 29
0
 public async Task SetInterval(TimeSpan interval, byte targetNodeID)
 {
     var seconds = PayloadConverter.GetBytes((uint)interval.TotalSeconds);
     await Channel.Send(Node, new Command(Class, command.IntervalSet, seconds[1], seconds[2], seconds[3], targetNodeID));
 }
Esempio n. 30
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequestWithYarnAndSparkConfigurationV3()
        {
            var expected = new HDInsight.ClusterCreateParametersV2
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                Version = "3.0",
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                ClusterSizeInNodes = new Random().Next(),
                ClusterType = ClusterType.Spark
            };

            expected.YarnConfiguration.Add(new KeyValuePair<string, string>("my setting 1", "my value 1"));
            expected.YarnConfiguration.Add(new KeyValuePair<string, string>("my setting 2", "my value 2"));
            expected.SparkConfiguration.Add(new KeyValuePair<string, string>("my setting 3", "my value 3"));

            string payload = new PayloadConverter().SerializeClusterCreateRequestV3(expected);
            var actual = ServerSerializer.DeserializeClusterCreateRequestV3(payload);
            fixDefaultExpectedZookeeperSize(expected); 
            Assert.IsTrue(Equals(expected, actual));
        }
        public void ICanDeserializeJobSubmissionResultWithMissingId()
        {
            var converter = new PayloadConverter();

            converter.DeserializeJobSubmissionResponse(JobSubmissionResultsPayloadMissingIdAndError);
        }
Esempio n. 32
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequest_MayContracts()
        {
            var cluster1 = new HDInsight.ClusterCreateParametersV2
            {
                Name = "bcarlson",
                ClusterSizeInNodes = 1,
                UserName = "******",
                Version = "default",
                Password = "******",
                Location = "East US"
            };

            cluster1.DefaultStorageAccountName = "storageaccount.blob.core.windows.net";
            cluster1.DefaultStorageContainer = "newcontainer";
            cluster1.DefaultStorageAccountKey = "fakekey";

            var metaStore = new Metastore("serverabcd.bigbean.windowsazure.mscds.com", "newmaytestdb", "bcarlson", "SuperPass1!");
            cluster1.HiveMetastore = cluster1.OozieMetastore = metaStore;

            string payload = new PayloadConverter().SerializeClusterCreateRequest(cluster1);
            var resource = ServerSerializer.DeserializeClusterCreateRequestIntoResource(payload);
            Assert.AreEqual(resource.SchemaVersion, "2.0");
        }
Esempio n. 33
0
        public void InternalValidation_PayloadConverter_SerializationCreateRequestWithConfigActionsV3()
        {
            var expected = new HDInsight.ClusterCreateParameters
            {
                UserName = Guid.NewGuid().ToString("N"),
                Password = Guid.NewGuid().ToString("N"),
                Version = IntegrationTestBase.TestCredentials.WellKnownCluster.Version,
                DefaultStorageAccountKey = Guid.NewGuid().ToString("N"),
                DefaultStorageAccountName = Guid.NewGuid().ToString("N"),
                DefaultStorageContainer = Guid.NewGuid().ToString("N"),
                Name = GetRandomClusterName(),
                Location = "East US",
                ClusterSizeInNodes = new Random().Next()
            };

            expected.ConfigActions.Add(new ScriptAction("testconfigaction1", new ClusterNodeType[] { ClusterNodeType.HeadNode }, new Uri("http://www.test1.com"), "test parameter1"));
            expected.ConfigActions.Add(new ScriptAction("testconfigaction2", new ClusterNodeType[] { ClusterNodeType.HeadNode, ClusterNodeType.DataNode }, new Uri("http://www.test2.com"), "test parameter2"));

            string payload = new PayloadConverter().SerializeClusterCreateRequestV3(expected);
            var actual = ServerSerializer.DeserializeClusterCreateRequestV3(payload);
            Assert.IsTrue(Equals(expected, actual));
        }
Esempio n. 34
0
        public void InternalValidation_PayloadConverter_SerializationListContainersResult()
        {
            var storageAccount = new WabStorageAccountConfiguration(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            // Creates two random containers
            var container1 = new ClusterDetails(GetRandomClusterName(), "Running")
            {
                CreatedDate = DateTime.Now,
                ConnectionUrl = @"https://some/long/uri/",
                HttpUserName = "******",
                Location = "East US",
                ClusterSizeInNodes = 20,
                Version = IntegrationTestBase.TestCredentials.WellKnownCluster.Version
            };
            container1.DefaultStorageAccount = storageAccount;
            container1.AdditionalStorageAccounts = new List<WabStorageAccountConfiguration>() 
            { 
                new WabStorageAccountConfiguration(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
                new WabStorageAccountConfiguration(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) 
            };
            var container2 = new ClusterDetails(GetRandomClusterName(), "ClusterStorageProvisioned")
            {
                CreatedDate = DateTime.Now,
                ConnectionUrl = @"https://some/long/uri/",
                HttpUserName = "******",
                Location = "West US",
                ClusterSizeInNodes = 10,
                Error = new ClusterErrorStatus(10, "error", "create"),
                Version = IntegrationTestBase.TestCredentials.WellKnownCluster.Version
            };

            var originalContainers = new Collection<ClusterDetails> { container1, container2 };

            // Roundtrip serialize\deserialize
            Guid subscriptionId = new Guid();
            var payload = ServerSerializer.SerializeListContainersResult(originalContainers, "namespace", true, false);
            var finalContainers = new PayloadConverter().DeserializeListContainersResult(payload, "namespace", subscriptionId);

            // Compares the lists
            Assert.AreEqual(originalContainers.Count, finalContainers.Count);
            foreach (var expectedCluster in originalContainers)
            {
                var deserializedCluster = finalContainers.FirstOrDefault(cluster => cluster.Name == expectedCluster.Name);
                Assert.IsNotNull(deserializedCluster);
                Assert.AreEqual(deserializedCluster.SubscriptionId, subscriptionId);
                Assert.IsTrue(Equals(expectedCluster, deserializedCluster), "Failed to deserialize cluster pigJobCreateParameters {0}", expectedCluster.Name);
            }
        }
 public void CanDeserializeCoreSettings()
 {
     var converter = new PayloadConverter();
     var coreComponentSettings = converter.DeserializeCoreSettings(CoreSiteSettings);
     Assert.IsNotNull(coreComponentSettings);
     AssertSettingValue(coreComponentSettings, "hadoop.tmp.dir", "/hdfs/tmp");
     AssertSettingValue(coreComponentSettings, "fs.trash.interval", "60");
 }
Esempio n. 36
0
    public void TestConvertVersionBDataTypeMetricFromProto()
    {
        var payload = PayloadConverter.ConvertVersionBDataTypeMetric(new VersionB.ProtoBuf.ProtoBufPayload.Metric.ValueOneofCase());

        Assert.IsNotNull(payload);
    }