public void WhenIEnableAndDisableAnHttpUserAPostMesageIsSentToTheServer() { this.EnableHttpSpy(); var credentials = GetValidCredentials(); var pocoClient = ServiceLocator.Instance.Locate <IHDInsightManagementPocoClientFactory>().Create(credentials, GetAbstractionContext(), false); var serverPayloadConverter = new ClusterProvisioningServerPayloadConverter(); var passthrough = new PassthroughResponse(); passthrough.Data = Guid.NewGuid(); this.EnableHttpMock((ca) => new HttpResponseMessageAbstraction( HttpStatusCode.Accepted, new HttpResponseHeadersAbstraction(), serverPayloadConverter.SerailizeChangeRequestResponse(passthrough))); this.ApplyIndividualTestMockingOnly(); pocoClient.DisableHttp("some name", "somewhere").WaitForResult(); var httpCalls = this.GetHttpCalls(); Assert.IsNotNull(httpCalls, "The system could not locate an Http call this could indicate that the test system is not operating correctly."); Assert.AreEqual(1, httpCalls.Count()); var call = httpCalls.FirstOrDefault(); Assert.AreEqual(HttpMethod.Post, call.Item1.Method); this.ClearHttpCalls(); pocoClient.EnableHttp("some name", "somewhere", "some one", "some secret"); httpCalls = this.GetHttpCalls(); Assert.IsNotNull(httpCalls, "The system could not locate an Http call this could indicate that the test system is not operating correctly."); Assert.AreEqual(1, httpCalls.Count()); call = httpCalls.FirstOrDefault(); Assert.AreEqual(HttpMethod.Post, call.Item1.Method); }
public string SerializeJobDetails(Hadoop.Client.JobDetails jobDetails) { var result = new PassthroughResponse(); if (jobDetails.ErrorCode.IsNotNullOrEmpty() || jobDetails.HttpStatusCode != HttpStatusCode.Accepted) { result.Error = new PassthroughErrorResponse { StatusCode = jobDetails.HttpStatusCode, ErrorId = jobDetails.ErrorCode }; } var details = new Microsoft.ClusterServices.RDFEProvider.ResourceExtensions.JobSubmission.Models.JobDetails() { ErrorOutputPath = jobDetails.ErrorOutputPath, ExitCode = jobDetails.ExitCode, LogicalOutputPath = jobDetails.LogicalOutputPath, Name = jobDetails.Name, PhysicalOutputPath = new Uri(jobDetails.PhysicalOutputPath), Query = jobDetails.Query, SubmissionTime = jobDetails.SubmissionTime.Ticks.ToString() }; Microsoft.ClusterServices.RDFEProvider.ResourceExtensions.JobSubmission.Models.JobStatusCode statusCode; Assert.IsTrue(Microsoft.ClusterServices.RDFEProvider.ResourceExtensions.JobSubmission.Models.JobStatusCode.TryParse(jobDetails.StatusCode.ToString(), out statusCode)); details.StatusCode = statusCode; result.Data = details; return(this.SerializeJobDetails(result)); }
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."); }
public void ICanSerializeAndDeserializeAGetOperationStatusWithNoErrorDetails() { var responseObject = new UserChangeOperationStatusResponse() { OperationType = UserChangeOperationType.Enable, UserType = UserType.Http, RequestIssueDate = DateTime.UtcNow, State = UserChangeOperationState.Completed, Error = null }; var passthroughOpStatus = new PassthroughResponse() { Data = responseObject, Error = null }; // serialize the non error response var serializedPassthroughResponse = new ClusterProvisioningServerPayloadConverter(); var serializedOpResponse = serializedPassthroughResponse.SerailizeChangeRequestResponse(passthroughOpStatus); // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityStatus(serializedOpResponse); Assert.IsNotNull(deserialized, "Nothing was returned from the deserializer."); Assert.IsNotNull(deserialized.Data, "No data object was present after deserialization."); Assert.AreEqual(responseObject.OperationType.ToString(), deserialized.Data.OperationType.ToString(), "The OperationType did not match after deserialization."); Assert.AreEqual(responseObject.RequestIssueDate, deserialized.Data.RequestIssueDate, "The IssueDate did not match after deserialization."); Assert.AreEqual(responseObject.State.ToString(), deserialized.Data.State.ToString(), "The State did not match after deserialization."); Assert.AreEqual(responseObject.UserType.ToString(), deserialized.Data.UserType.ToString(), "The user type not match after deserialization."); }
private T SafeGetDataFromPassthroughResponse <T>(PassthroughResponse response) { if (response.Error != null) { throw new HttpLayerException(response.Error.StatusCode, response.Error.ErrorMessage); } return((T)response.Data); }
public string SerializeJobCreationResults(JobCreationResults jobResults) { var result = new PassthroughResponse(); if (jobResults.ErrorCode.IsNotNullOrEmpty() || jobResults.HttpStatusCode != HttpStatusCode.Accepted) { result.Error = new PassthroughErrorResponse { StatusCode = jobResults.HttpStatusCode, ErrorId = jobResults.ErrorCode }; } result.Data = jobResults.JobId; return(this.SerializeJobDetails(result)); }
public string SerializeJobList(JobList jobs) { var result = new PassthroughResponse(); if (jobs.ErrorCode.IsNotNullOrEmpty() || jobs.HttpStatusCode != HttpStatusCode.Accepted) { result.Error = new PassthroughErrorResponse { StatusCode = jobs.HttpStatusCode, ErrorId = jobs.ErrorCode }; } result.Data = jobs.Jobs.Select(j => j.JobId).ToList(); return(this.SerializeJobDetails(result)); }
public void ICanSerializeAndDeserializeAChangeRequestPassthroughWithNullFields() { var responseObject = new PassthroughResponse() { Data = null, Error = null }; // SERIALIZE THE RESPONSE var serializedPassthroughResponse = new ClusterProvisioningServerPayloadConverter(); var serializedOpResponse = serializedPassthroughResponse.SerailizeChangeRequestResponse(responseObject); // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityResponse(serializedOpResponse); }
public void ICanSerializeAndDeserializeAGetOperationStatusWithErrorDetails() { var errorStatusCode = HttpStatusCode.NotAcceptable; var errorIdDetails = "Error123"; var errorMessageDetails = "This is an error!"; ErrorDetails errorDetails = new ErrorDetails() { StatusCode = errorStatusCode, ErrorId = errorIdDetails, ErrorMessage = errorMessageDetails }; var userChangeResponse = new UserChangeOperationStatusResponse() { OperationType = UserChangeOperationType.Enable, UserType = UserType.Http, RequestIssueDate = DateTime.UtcNow, State = UserChangeOperationState.Completed, Error = errorDetails }; var responseObject = new PassthroughResponse() { Data = userChangeResponse, Error = errorDetails }; // SERIALIZE THE RESPONSE var serializedPassthroughResponse = new ClusterProvisioningServerPayloadConverter(); var serializedOpResponse = serializedPassthroughResponse.SerailizeChangeRequestResponse(responseObject); // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityStatus(serializedOpResponse); Assert.IsNotNull(deserialized, "Nothing was returned from the deserializer."); 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."); Assert.IsNotNull(deserialized.Data, "No data object was present after deserialization."); Assert.AreEqual(userChangeResponse.OperationType.ToString(), deserialized.Data.OperationType.ToString(), "The OperationType did not match after deserialization."); Assert.AreEqual(userChangeResponse.RequestIssueDate, deserialized.Data.RequestIssueDate, "The IssueDate did not match after deserialization."); Assert.AreEqual(userChangeResponse.State.ToString(), deserialized.Data.State.ToString(), "The State did not match after deserialization."); Assert.AreEqual(userChangeResponse.UserType.ToString(), deserialized.Data.UserType.ToString(), "The user type not match after deserialization."); Assert.IsNotNull(deserialized.Data.ErrorDetails, "No error object was present after deserialization."); Assert.AreEqual(userChangeResponse.Error.ErrorId, deserialized.Data.ErrorDetails.ErrorId, "The (inner) Error Id did not match after deserialization."); Assert.AreEqual(userChangeResponse.Error.ErrorMessage, deserialized.Data.ErrorDetails.ErrorMessage, "The (inner) error message did not match after deserialization."); Assert.AreEqual(userChangeResponse.Error.StatusCode, deserialized.Data.ErrorDetails.StatusCode, "The (inner) status code did not match after deserialization."); }
private string SerializeJobDetails(PassthroughResponse result) { DataContractSerializer ser = new DataContractSerializer(typeof(PassthroughResponse)); using (var stream = new MemoryStream()) { using (var reader = new StreamReader(stream)) { ser.WriteObject(stream, result); stream.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } } }
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"); }
public string SerailizeChangeRequestResponse(PassthroughResponse response) { string result; DataContractSerializer ser = new DataContractSerializer(typeof(PassthroughResponse)); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) { ser.WriteObject(stream, response); stream.Flush(); stream.Position = 0; result = reader.ReadToEnd(); } return(result); }
public PassthroughResponse ProcessPassthrough(PassthroughRequest objRequest) { try { objPassthrough.PassthroughGrid = objclsDashboard.GetPassthroughData(objRequest.DateTime); return(objPassthrough); } catch (Exception) { return(objPassthrough); } finally { objPassthrough = null; objclsDashboard = null; } }
private async Task <GetIaasClusterResult> GetIaasClusterFromCloudServiceResource(CloudService cloudService, Resource clusterResource) { var clusterDetails = PayloadConverterIaasClusters.CreateClusterDetailsFromRdfeResourceOutput(cloudService.GeoRegion, clusterResource); HDInsight.ClusterState clusterState = clusterDetails.State; IaasCluster clusterFromGetClusterCall = null; if (clusterState != HDInsight.ClusterState.Deleting && clusterState != HDInsight.ClusterState.DeletePending) { //we want to poll if we are either in error or unknown state. //this is so that we can get the extended error information. try { PassthroughResponse response = await this.rdfeRestClient.GetCluster( this.credentials.SubscriptionId.ToString(), this.GetCloudServiceName(cloudService.GeoRegion), this.credentials.DeploymentNamespace, clusterResource.Name, this.Context.CancellationToken); clusterFromGetClusterCall = this.SafeGetDataFromPassthroughResponse <IaasCluster>(response); clusterDetails = PayloadConverterIaasClusters.CreateClusterDetailsFromGetClustersResult(clusterFromGetClusterCall); } catch (Exception) { // Ignore all exceptions. We don't want ListContainers to fail on customers for whatever reason. // If there is an issue with obtaining details about the cluster, mark the cluster in Error state with a generic error message clusterDetails.State = ClusterState.Error; if (clusterDetails.Error != null && string.IsNullOrEmpty(clusterDetails.Error.Message)) { clusterDetails.Error.Message = "Unexpected error occurred. Could not retrieve details about the cluster."; } } } clusterDetails.SubscriptionId = this.credentials.SubscriptionId; return(new GetIaasClusterResult(clusterDetails, clusterFromGetClusterCall)); }