public void WebService_UseSampleFetchRequest_CanProperlySerializeAndDeSerializeFetchRequest() { // Arrange var request1 = new Microsoft.Research.Science.FetchClimate2.Serializable.FetchRequest(new FetchRequest( "evn_var_name", FetchDomain.CreateCells( new double[] { 1.0, 3.4 }, new double[] { 2.0, 4.5 }, new double[] { 1.0, 3.4 }, new double[] { 2.0, 4.5 }, new TimeRegion() ) , new DateTime(2012, 11, 15, 0, 0, 0, DateTimeKind.Utc)) ); // Act var json = JsonConvert.SerializeObject(request1); var request2 = JsonConvert.DeserializeObject <Microsoft.Research.Science.FetchClimate2.Serializable.FetchRequest>(json).ConvertFromSerializable(); // Assert Assert.IsNotNull(request2, "Error: Deserilized object is null"); Assert.AreEqual <string>(request1.EnvironmentVariableName, request2.EnvironmentVariableName); Assert.IsNotNull(request2.Domain); Assert.IsNotNull(request2.Domain.Lats); Assert.AreEqual <int>(request1.Domain.Lats.Length, request2.Domain.Lats.Length); Assert.IsNotNull(request2.Domain.Lats[0]); Assert.AreEqual <double>(request1.Domain.Lats[0], request2.Domain.Lats[0]); Assert.IsNotNull(request2.Domain.Lons); Assert.AreEqual <int>(request1.Domain.Lons.Length, request2.Domain.Lons.Length); Assert.IsNotNull(request2.Domain.Lons[0]); Assert.AreEqual <double>(request1.Domain.Lons[0], request2.Domain.Lons[0]); Assert.IsNotNull(request2.Domain.Lats2); Assert.AreEqual <int>(request1.Domain.Lats2.Length, request2.Domain.Lats2.Length); Assert.IsNotNull(request2.Domain.Lats2[0]); Assert.AreEqual <double>(request1.Domain.Lats2[0], request2.Domain.Lats2[0]); Assert.IsNotNull(request2.Domain.Lons2); Assert.AreEqual <int>(request1.Domain.Lons2.Length, request2.Domain.Lons2.Length); Assert.IsNotNull(request2.Domain.Lons2[0]); Assert.AreEqual <double>(request1.Domain.Lons2[0], request2.Domain.Lons2[0]); Assert.IsNotNull(request2.Domain.TimeRegion); Assert.AreEqual <int>(request1.Domain.TimeRegion.Years[0], request2.Domain.TimeRegion.Years[0]); Assert.AreEqual <int>(request1.Domain.TimeRegion.Years[1], request2.Domain.TimeRegion.Years[1]); Assert.AreEqual <int>(request1.Domain.TimeRegion.Days[0], request2.Domain.TimeRegion.Days[0]); Assert.AreEqual <int>(request1.Domain.TimeRegion.Days[1], request2.Domain.TimeRegion.Days[1]); Assert.AreEqual <int>(request1.Domain.TimeRegion.Hours[0], request2.Domain.TimeRegion.Hours[0]); Assert.AreEqual <int>(request1.Domain.TimeRegion.Hours[1], request2.Domain.TimeRegion.Hours[1]); Assert.AreEqual <SpatialRegionSpecification>(SpatialRegionSpecification.Cells, request2.Domain.SpatialRegionType); Assert.AreEqual <DateTime>(request1.ReproducibilityTimestamp, request2.ReproducibilityTimestamp); }
// POST api/Compute public string Post(Microsoft.Research.Science.FetchClimate2.Serializable.FetchRequest request) { try { if (request.ReproducibilityTimestamp == new DateTime()) { request.ReproducibilityTimestamp = DateTime.MaxValue; } var exactTS = WebApiApplication.GetExactConfigurationTimestamp(request.ReproducibilityTimestamp); if (exactTS == DateTime.MinValue) { FrontendTrace.TraceError("Cannot process request. Timestamp {0} is too early for current service configuration", request.ReproducibilityTimestamp); return(String.Format(Constants.FaultReply, "Timestamp is too early for this service")); } else { FrontendTrace.TraceVerbose("Request received: timestamp = {0}, exact timestamp = {1}", request.ReproducibilityTimestamp, exactTS); request.ReproducibilityTimestamp = exactTS; } var jobManager = WebApiApplication.GetSharedJobManager(Request); jobManager.MarkOutdatedAsFailed(permitedTouchTimeTreshold); var fetchRequest = request.ConvertFromSerializable(); string errorMsg; if (!fetchRequest.Domain.IsContentValid(out errorMsg)) //checking request content { return(string.Format(Constants.FaultReply, errorMsg)); } string hash = fetchRequest.GetSHAHash(); FrontendTrace.TraceInfo("{0}: Hash is computed for request", hash); var jobStatus = jobManager.Submit(fetchRequest, hash, jobRegistrationPermitedTime, minPtsPerPartition, maxPtsPerPartition, RoleEnvironment.Roles["FetchWorker"].Instances.Count); if (jobStatus.State == JobOrPartState.Pending || jobStatus.State == JobOrPartState.InProgress) { // Waiting for some time before response in case job manage to complete FrontendTrace.TraceVerbose("{0}:Waiting for request completion", hash); for (int i = 0; i *jobStatusCheckIntervalMilisec * 0.001 < waitingFastResultPeriodSec; ++i) { Thread.Sleep(jobStatusCheckIntervalMilisec); jobStatus = jobManager.GetStatus(hash); if ((jobStatus.State == JobOrPartState.Completed) || (jobStatus.State == JobOrPartState.Failed)) { FrontendTrace.TraceVerbose("{0}:Request result is ready in less than {1} seconds, reporting {2} status", hash, waitingFastResultPeriodSec, jobStatus.ToString()); return(jobStatus.ToString()); } } FrontendTrace.TraceVerbose("{0}:Request result is not ready in {1} seconds, reporting {2} status", hash, waitingFastResultPeriodSec, jobStatus.ToString()); return(jobStatus.ToString()); } else { return(jobStatus.ToString()); } } catch (Exception exc) { FrontendTrace.TraceError("Request is processing error: {0}", exc.ToString()); return(JobStatus.GetFailedStatus(exc.ToString()).ToString()); } }