Skip to content

Commit

Permalink
Merge pull request #502 from sharwell/cdn-review
Browse files Browse the repository at this point in the history
Fix build errors and consistency issues in CDN implementation
  • Loading branch information
DonSchenck committed Jun 8, 2015
2 parents c16a59a + 49bfb33 commit 8b56cf6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 49 deletions.
12 changes: 11 additions & 1 deletion src/OpenStack.Net/OpenStack.Net.netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<NTVersion>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion@CurrentVersion)</NTVersion>
<IsWindows81 Condition="'$(NTVersion)' == '6.3'">True</IsWindows81>
<TargetPlatformVersion Condition="'$(IsWindows81)' == 'True'">8.1</TargetPlatformVersion>
<TargetFrameworkVersion Condition="'$(IsWindows81)' == 'True'"/>
<TargetFrameworkVersion Condition="'$(IsWindows81)' == 'True'" />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -118,10 +118,12 @@
<Compile Include="OpenStack\Security\Authentication\NamespaceDoc.cs" />
<Compile Include="OpenStack\Security\Authentication\PassThroughAuthenticationService.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\AddFlavorApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\AddOperation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\AddServiceApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ContentDeliveryClient.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ContentDeliveryServiceExtensionDefinition`1.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ContentDeliveryServiceExtensions.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\CopyOperation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\Flavor.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\FlavorData.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\FlavorId.cs" />
Expand All @@ -133,13 +135,20 @@
<Compile Include="OpenStack\Services\ContentDelivery\V1\GetServiceApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\GetSubsystemHealthApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\IContentDeliveryService.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\JsonDiffer.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\JsonPointer.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ListFlavorsApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ListServicesApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ListServicesExtensions.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\MoveOperation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\Operation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\PatchDocument.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\PingApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveAssetApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveFlavorApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveOperation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveServiceApiCall.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ReplaceOperation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\Service.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceCache.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceCacheRule.cs" />
Expand All @@ -154,6 +163,7 @@
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceRestrictionRule.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceStatus.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\SubsystemId.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\TestOperation.cs" />
<Compile Include="OpenStack\Services\ContentDelivery\V1\UpdateServiceApiCall.cs" />
<Compile Include="OpenStack\Services\Identity\ApiStatus.cs" />
<Compile Include="OpenStack\Services\Identity\ApiVersion.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public virtual Task<GetHomeApiCall> PrepareGetHomeAsync(CancellationToken cancel
UriTemplate template = new UriTemplate(string.Empty);
Dictionary<string, string> parameters = new Dictionary<string, string>();
return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
.Select(task => new GetHomeApiCall(CreateJsonApiCall<HomeDocument>(task.Result)));
}

Expand All @@ -79,7 +79,7 @@ public virtual Task<PingApiCall> PreparePingAsync(CancellationToken cancellation
UriTemplate template = new UriTemplate("ping");
Dictionary<string, string> parameters = new Dictionary<string, string>();
return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
//.Select(RemoveAcceptHeader) **DLS**
.Select(task => new PingApiCall(CreateBasicApiCall(task.Result)));
}
Expand Down Expand Up @@ -174,44 +174,44 @@ public virtual Task<UpdateServiceApiCall> PrepareUpdateServiceAsync(ServiceId se
if (serviceId == null)
throw new ArgumentNullException("serviceId");



// At this point, the serviceData parameter contains the NEW (AFTER) version
// of the service data. Now, we need to retrieve the current (BEFORE) version,
// then use those to calculate the difference, i.e. the JSON Patch document.
CancellationToken cn = new CancellationToken();
var getServiceTask = ContentDeliveryServiceExtensions.GetServiceAsync(this, serviceId, cn);
getServiceTask.Wait();
ServiceData originalServiceData = getServiceTask.Result;


return this.GetServiceAsync(serviceId, cancellationToken)
.Then(task => PrepareUpdateServiceFromExistingAsync(serviceId, updatedServiceData, task.Result, cancellationToken));
}

protected virtual Task<UpdateServiceApiCall> PrepareUpdateServiceFromExistingAsync(ServiceId serviceId, ServiceData updatedServiceData, ServiceData originalServiceData, CancellationToken cancellationToken)
{
// Here's a serious HACK: Because the current ServiceData includes properties
// that are not part of a new instance of ServiceData (such as "Id", "Status" and others)
// we need to create a new instance using the data from the current ServiceData object.
// That way, when we perform the "DIFF" operation to calculate the JSon Patch object,
// the extra properties won't interfere.
ServiceData tempServiceData = new ServiceData(originalServiceData.Name, originalServiceData.FlavorId, originalServiceData.Domains, originalServiceData.Origins, originalServiceData.CachingRules, originalServiceData.Restrictions);



// Calculate the Json Patch document
var beforeUpdate = JToken.Parse(JsonConvert.SerializeObject(tempServiceData));
var afterUpdate = JToken.Parse(JsonConvert.SerializeObject(updatedServiceData));
var patchDoc = new JsonDiffer().Diff(beforeUpdate, afterUpdate);


// Another Hack: For some reason (TODO: which needs to be investigated and fixed),
// we need to deserialize the document in order for it to render a proper Json object.
var jsonPatchDocument = JsonConvert.DeserializeObject(patchDoc.ToString());


// Now we can call the PATCH method to update the ServiceData on the server.
UriTemplate template = new UriTemplate("services/{service_id}");
Dictionary<string, string> parameters = new Dictionary<string, string> { { "service_id", serviceId.Value } };

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(new HttpMethod("PATCH"), "application/json-patch+json", template, parameters, jsonPatchDocument, cancellationToken))
.Select(task => new UpdateServiceApiCall(CreateBasicApiCall(task.Result)));
.Then(PrepareRequestAsyncFunc(new HttpMethod("PATCH"), template, parameters, jsonPatchDocument, cancellationToken))
.Select(
task =>
{
HttpRequestMessage requestMessage = task.Result;
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json-patch+json");
return new UpdateServiceApiCall(CreateBasicApiCall(requestMessage));
});
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions src/OpenStack.Net/OpenStack/Services/IHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface IHttpService : IDisposable
/// <para>-or-</para>
/// <para>If <paramref name="parameters"/> is <see langword="null"/>.</para>
/// </exception>
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, CancellationToken cancellationToken, string mediaType);
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, CancellationToken cancellationToken);

/// <summary>
/// Creates a task continuation function responsible for creating an <see cref="HttpRequestMessage"/> for use in
Expand Down Expand Up @@ -66,7 +66,7 @@ public interface IHttpService : IDisposable
/// <para>-or-</para>
/// <para>If <paramref name="parameters"/> is <see langword="null"/>.</para>
/// </exception>
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T, TBody>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, TBody body, CancellationToken cancellationToken, string mediaType);
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T, TBody>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, TBody body, CancellationToken cancellationToken);

/// <summary>
/// Gets the base absolute URI to use for making asynchronous HTTP API calls to this service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public virtual Task<ListApiVersionsApiCall> PrepareListApiVersionsAsync(Cancella
};

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
.Select(task => new ListApiVersionsApiCall(CreateCustomApiCall(task.Result, HttpCompletionOption.ResponseContentRead, deserializeResult)));
}

Expand All @@ -152,7 +152,7 @@ public virtual Task<GetApiVersionApiCall> PrepareGetApiVersionAsync(ApiVersionId
Dictionary<string, string> parameters = new Dictionary<string, string> { { "version_id", apiVersionId.Value } };

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
.Select(task => new GetApiVersionApiCall(CreateJsonApiCall<ApiVersionResponse>(task.Result)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public virtual Task<ListExtensionsApiCall> PrepareListExtensionsAsync(Cancellati
};

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
.Select(task => new ListExtensionsApiCall(CreateCustomApiCall(task.Result, HttpCompletionOption.ResponseContentRead, deserializeResult)));
}

Expand All @@ -141,7 +141,7 @@ public virtual Task<GetExtensionApiCall> PrepareGetExtensionAsync(ExtensionAlias
Dictionary<string, string> parameters = new Dictionary<string, string> { { "alias", alias.Value } };

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
.Select(task => new GetExtensionApiCall(CreateJsonApiCall<ExtensionResponse>(task.Result)));
}

Expand All @@ -152,7 +152,7 @@ public virtual Task<AuthenticateApiCall> PrepareAuthenticateAsync(Authentication
Dictionary<string, string> parameters = new Dictionary<string, string>();

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Post, template, parameters, request, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Post, template, parameters, request, cancellationToken))
.Select(task => new AuthenticateApiCall(CreateJsonApiCall<AccessResponse>(task.Result)));
}

Expand Down Expand Up @@ -208,7 +208,7 @@ public virtual Task<ListTenantsApiCall> PrepareListTenantsAsync(CancellationToke
};

return GetBaseUriAsync(cancellationToken)
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
.Select(task => new ListTenantsApiCall(CreateCustomApiCall(task.Result, HttpCompletionOption.ResponseContentRead, deserializeResult)));
}

Expand Down
Loading

0 comments on commit 8b56cf6

Please sign in to comment.