diff --git a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationAsyncClient.java b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationAsyncClient.java index ef014fb4d65e..e044d4ca5cc4 100644 --- a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationAsyncClient.java +++ b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationAsyncClient.java @@ -21,8 +21,10 @@ import com.azure.core.util.polling.PollOperationDetails; import com.azure.core.util.polling.PollerFlux; import com.azure.data.appconfiguration.implementation.AzureAppConfigurationImpl; +import com.azure.data.appconfiguration.implementation.ConfigurationSettingDeserializationHelper; import com.azure.data.appconfiguration.implementation.CreateSnapshotUtilClient; import com.azure.data.appconfiguration.implementation.SyncTokenPolicy; +import com.azure.data.appconfiguration.implementation.Utility; import com.azure.data.appconfiguration.implementation.models.GetKeyValueHeaders; import com.azure.data.appconfiguration.implementation.models.KeyValue; import com.azure.data.appconfiguration.models.ConfigurationSetting; @@ -44,13 +46,9 @@ import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; -import static com.azure.data.appconfiguration.implementation.ConfigurationSettingDeserializationHelper.toConfigurationSettingWithPagedResponse; -import static com.azure.data.appconfiguration.implementation.ConfigurationSettingDeserializationHelper.toConfigurationSettingWithResponse; import static com.azure.data.appconfiguration.implementation.Utility.ETAG_ANY; -import static com.azure.data.appconfiguration.implementation.Utility.addTracingNamespace; import static com.azure.data.appconfiguration.implementation.Utility.getETag; import static com.azure.data.appconfiguration.implementation.Utility.getPageETag; -import static com.azure.data.appconfiguration.implementation.Utility.handleNotModifiedErrorToValidResponse; import static com.azure.data.appconfiguration.implementation.Utility.toKeyValue; import static com.azure.data.appconfiguration.implementation.Utility.toSettingFieldsList; import static com.azure.data.appconfiguration.implementation.Utility.updateSnapshotAsync; @@ -354,7 +352,7 @@ public Mono addConfigurationSetting(String key, String lab /** * Adds a configuration value in the service if that key and label does not exist. The label value of the * ConfigurationSetting is optional. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -391,7 +389,7 @@ public Mono addConfigurationSetting(ConfigurationSetting s /** * Adds a configuration value in the service if that key and label does not exist. The label value of the * ConfigurationSetting is optional. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -429,9 +427,8 @@ public Mono> addConfigurationSettingWithResponse( return withContext( context -> validateSettingAsync(setting).flatMap( settingInternal -> serviceClient.putKeyValueWithResponseAsync(settingInternal.getKey(), - settingInternal.getLabel(), null, ETAG_ANY, toKeyValue(settingInternal), - addTracingNamespace(context)) - .map(response -> toConfigurationSettingWithResponse(response)))); + settingInternal.getLabel(), null, ETAG_ANY, toKeyValue(settingInternal), context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithResponse))); } /** @@ -471,7 +468,7 @@ public Mono setConfigurationSetting(String key, String lab /** * Creates or updates a configuration value in the service. Partial updates are not supported and the entire * configuration setting is updated. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -515,10 +512,10 @@ public Mono setConfigurationSetting(ConfigurationSetting s /** * Creates or updates a configuration value in the service. Partial updates are not supported and the entire * configuration setting is updated. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. - * + *

* If {@link ConfigurationSetting#getETag() ETag} is specified, the configuration value is updated if the current * setting's ETag matches. If the ETag's value is equal to the wildcard character ({@code "*"}), the setting will * always be updated. @@ -574,8 +571,8 @@ public Mono> setConfigurationSettingWithResponse( context -> validateSettingAsync(setting).flatMap( settingInternal -> serviceClient.putKeyValueWithResponseAsync(settingInternal.getKey(), settingInternal.getLabel(), getETag(ifUnchanged, settingInternal), null, - toKeyValue(settingInternal), addTracingNamespace(context)) - .map(response -> toConfigurationSettingWithResponse(response)))); + toKeyValue(settingInternal), context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithResponse))); } /** @@ -716,25 +713,20 @@ public Mono getConfigurationSetting(ConfigurationSetting s @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getConfigurationSettingWithResponse(ConfigurationSetting setting, OffsetDateTime acceptDateTime, boolean ifChanged) { - return withContext( - context -> validateSettingAsync(setting).flatMap( - settingInternal -> - serviceClient.getKeyValueWithResponseAsync(settingInternal.getKey(), settingInternal.getLabel(), - acceptDateTime == null ? null : acceptDateTime.toString(), null, - getETag(ifChanged, settingInternal), null, addTracingNamespace(context)) - .onErrorResume( - HttpResponseException.class, - (Function>>) throwable -> { - HttpResponseException e = (HttpResponseException) throwable; - HttpResponse httpResponse = e.getResponse(); - if (httpResponse.getStatusCode() == 304) { - return Mono.just(new ResponseBase( - httpResponse.getRequest(), httpResponse.getStatusCode(), - httpResponse.getHeaders(), null, null)); - } - return Mono.error(throwable); - }) - .map(response -> toConfigurationSettingWithResponse(response)))); + return withContext(context -> validateSettingAsync(setting).flatMap(settingInternal -> + serviceClient.getKeyValueWithResponseAsync(settingInternal.getKey(), settingInternal.getLabel(), + acceptDateTime == null ? null : acceptDateTime.toString(), null, + getETag(ifChanged, settingInternal), null, context) + .onErrorResume(HttpResponseException.class, + (Function>>) throwable -> { + HttpResponseException e = (HttpResponseException) throwable; + HttpResponse httpResponse = e.getResponse(); + if (httpResponse.getStatusCode() == 304) { + return Mono.just(new ResponseBase(httpResponse.getRequest(), + httpResponse.getStatusCode(), httpResponse.getHeaders(), null, null)); + } + return Mono.error(throwable); + }).map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithResponse))); } /** @@ -770,7 +762,7 @@ public Mono deleteConfigurationSetting(String key, String * {@link ConfigurationSetting#getLabel() label} and optional ETag combination from the service. * For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. - * + *

* If {@link ConfigurationSetting#getETag() ETag} is specified and is not the wildcard character ({@code "*"}), then * the setting is only deleted if the ETag matches the current ETag; this means that no one has updated the * ConfigurationSetting yet. @@ -809,10 +801,10 @@ public Mono deleteConfigurationSetting(ConfigurationSettin /** * Deletes the {@link ConfigurationSetting} with a matching {@link ConfigurationSetting#getKey() key}, and optional * {@link ConfigurationSetting#getLabel() label} and optional ETag combination from the service. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. - * + *

* If {@link ConfigurationSetting#getETag() ETag} is specified and is not the wildcard character ({@code "*"}), then * the setting is only deleted if the ETag matches the current ETag; this means that no one has updated the * ConfigurationSetting yet. @@ -855,8 +847,8 @@ public Mono> deleteConfigurationSettingWithRespon boolean ifUnchanged) { return withContext(context -> validateSettingAsync(setting).flatMap( settingInternal -> serviceClient.deleteKeyValueWithResponseAsync(settingInternal.getKey(), - settingInternal.getLabel(), getETag(ifUnchanged, settingInternal), addTracingNamespace(context)) - .map(response -> toConfigurationSettingWithResponse(response)))); + settingInternal.getLabel(), getETag(ifUnchanged, settingInternal), context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithResponse))); } /** @@ -901,7 +893,7 @@ public Mono setReadOnly(String key, String label, boolean /** * Sets the read-only status for the {@link ConfigurationSetting}. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -949,7 +941,7 @@ public Mono setReadOnly(ConfigurationSetting setting, bool /** * Sets the read-only status for the {@link ConfigurationSetting}. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -1000,16 +992,14 @@ public Mono setReadOnly(ConfigurationSetting setting, bool @ServiceMethod(returns = ReturnType.SINGLE) public Mono> setReadOnlyWithResponse(ConfigurationSetting setting, boolean isReadOnly) { - return withContext(context -> validateSettingAsync(setting).flatMap( - settingInternal -> { - final String key = settingInternal.getKey(); - final String label = settingInternal.getLabel(); - final Context contextInternal = addTracingNamespace(context); - return (isReadOnly - ? serviceClient.putLockWithResponseAsync(key, label, null, null, contextInternal) - : serviceClient.deleteLockWithResponseAsync(key, label, null, null, contextInternal)) - .map(response -> toConfigurationSettingWithResponse(response)); - })); + return withContext(context -> validateSettingAsync(setting).flatMap(settingInternal -> { + final String key = settingInternal.getKey(); + final String label = settingInternal.getLabel(); + return (isReadOnly + ? serviceClient.putLockWithResponseAsync(key, label, null, null, context) + : serviceClient.deleteLockWithResponseAsync(key, label, null, null, context)) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithResponse); + })); } /** @@ -1042,31 +1032,19 @@ public PagedFlux listConfigurationSettings(SettingSelector final List settingFields = selector == null ? null : toSettingFieldsList(selector.getFields()); final List matchConditionsList = selector == null ? null : selector.getMatchConditions(); AtomicInteger pageETagIndex = new AtomicInteger(0); - return new PagedFlux<>( - () -> withContext(context -> serviceClient.getKeyValuesSinglePageAsync( - keyFilter, - labelFilter, - null, - acceptDateTime, - settingFields, - null, - null, - getPageETag(matchConditionsList, pageETagIndex), - addTracingNamespace(context)) - .onErrorResume(HttpResponseException.class, - (Function>>) throwable -> - handleNotModifiedErrorToValidResponse(throwable)) - .map(pagedResponse -> toConfigurationSettingWithPagedResponse(pagedResponse))), - nextLink -> withContext(context -> serviceClient.getKeyValuesNextSinglePageAsync( - nextLink, - acceptDateTime, - null, - getPageETag(matchConditionsList, pageETagIndex), - addTracingNamespace(context)) - .onErrorResume(HttpResponseException.class, - (Function>>) throwable -> - handleNotModifiedErrorToValidResponse(throwable)) - .map(pagedResponse -> toConfigurationSettingWithPagedResponse(pagedResponse))) + return new PagedFlux<>(() -> withContext(context -> serviceClient.getKeyValuesSinglePageAsync(keyFilter, + labelFilter, null, acceptDateTime, settingFields, null, null, + getPageETag(matchConditionsList, pageETagIndex), context) + .onErrorResume(HttpResponseException.class, + (Function>>) + Utility::handleNotModifiedErrorToValidResponse) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithPagedResponse)), + nextLink -> withContext(context -> serviceClient.getKeyValuesNextSinglePageAsync(nextLink, + acceptDateTime, null, getPageETag(matchConditionsList, pageETagIndex), context) + .onErrorResume(HttpResponseException.class, + (Function>>) + Utility::handleNotModifiedErrorToValidResponse) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithPagedResponse)) ); } @@ -1124,29 +1102,13 @@ public PagedFlux listConfigurationSettingsForSnapshot(Stri */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listConfigurationSettingsForSnapshot(String snapshotName, - List fields) { - return new PagedFlux<>( - () -> withContext( - context -> serviceClient.getKeyValuesSinglePageAsync( - null, - null, - null, - null, - fields, - snapshotName, - null, - null, - addTracingNamespace(context)) - .map(pagedResponse -> toConfigurationSettingWithPagedResponse(pagedResponse))), - nextLink -> withContext( - context -> serviceClient.getKeyValuesNextSinglePageAsync( - nextLink, - null, - null, - null, - addTracingNamespace(context)) - .map(pagedResponse -> toConfigurationSettingWithPagedResponse(pagedResponse))) - ); + List fields) { + return new PagedFlux<>(() -> withContext(context -> serviceClient.getKeyValuesSinglePageAsync(null, null, null, + null, fields, snapshotName, null, null, context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithPagedResponse)), + nextLink -> withContext(context -> serviceClient.getKeyValuesNextSinglePageAsync(nextLink, null, null, null, + context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithPagedResponse))); } /** @@ -1154,7 +1116,7 @@ public PagedFlux listConfigurationSettingsForSnapshot(Stri * in descending order from their {@link ConfigurationSetting#getLastModified() lastModified} date. * Revisions expire after a period of time, see Pricing * for more information. - * + *

* If {@code selector} is {@code null}, then all the {@link ConfigurationSetting ConfigurationSettings} are fetched * in their current state. Otherwise, the results returned match the parameters given in {@code selector}. * @@ -1181,21 +1143,12 @@ public PagedFlux listRevisions(SettingSelector selector) { final String labelFilter = selector == null ? null : selector.getLabelFilter(); final String acceptDateTime = selector == null ? null : selector.getAcceptDateTime(); final List settingFields = selector == null ? null : toSettingFieldsList(selector.getFields()); - return new PagedFlux<>( - () -> withContext( - context -> serviceClient.getRevisionsSinglePageAsync( - keyFilter, - labelFilter, - null, - acceptDateTime, - settingFields, - addTracingNamespace(context)) - .map(pagedResponse -> toConfigurationSettingWithPagedResponse(pagedResponse))), - nextLink -> withContext( - context -> - serviceClient.getRevisionsNextSinglePageAsync(nextLink, acceptDateTime, - addTracingNamespace(context)) - .map(pagedResponse -> toConfigurationSettingWithPagedResponse(pagedResponse)))); + return new PagedFlux<>(() -> withContext(context -> serviceClient.getRevisionsSinglePageAsync(keyFilter, + labelFilter, null, acceptDateTime, settingFields, context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithPagedResponse)), + nextLink -> withContext(context -> serviceClient.getRevisionsNextSinglePageAsync(nextLink, acceptDateTime, + context) + .map(ConfigurationSettingDeserializationHelper::toConfigurationSettingWithPagedResponse))); } /** @@ -1440,17 +1393,11 @@ public Mono> recoverSnapshotWithResponse( @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listSnapshots(SnapshotSelector selector) { try { - return new PagedFlux<>( - () -> withContext( - context -> serviceClient.getSnapshotsSinglePageAsync( - selector == null ? null : selector.getNameFilter(), - null, - selector == null ? null : selector.getFields(), - selector == null ? null : selector.getStatus(), - addTracingNamespace(context))), - nextLink -> withContext( - context -> serviceClient.getSnapshotsNextSinglePageAsync(nextLink, addTracingNamespace(context))) - ); + return new PagedFlux<>(() -> withContext(context -> serviceClient.getSnapshotsSinglePageAsync( + selector == null ? null : selector.getNameFilter(), null, + selector == null ? null : selector.getFields(), selector == null ? null : selector.getStatus(), + context)), nextLink -> withContext(context -> + serviceClient.getSnapshotsNextSinglePageAsync(nextLink, context))); } catch (RuntimeException ex) { return new PagedFlux<>(() -> monoError(LOGGER, ex)); } diff --git a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClient.java b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClient.java index 94d07ff34f5c..30e97c8af057 100644 --- a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClient.java +++ b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClient.java @@ -46,8 +46,6 @@ import static com.azure.data.appconfiguration.implementation.ConfigurationSettingDeserializationHelper.toConfigurationSettingWithPagedResponse; import static com.azure.data.appconfiguration.implementation.ConfigurationSettingDeserializationHelper.toConfigurationSettingWithResponse; import static com.azure.data.appconfiguration.implementation.Utility.ETAG_ANY; -import static com.azure.data.appconfiguration.implementation.Utility.addTracingNamespace; -import static com.azure.data.appconfiguration.implementation.Utility.enableSyncRestProxy; import static com.azure.data.appconfiguration.implementation.Utility.getETag; import static com.azure.data.appconfiguration.implementation.Utility.getPageETag; import static com.azure.data.appconfiguration.implementation.Utility.handleNotModifiedErrorToValidResponse; @@ -356,7 +354,7 @@ public ConfigurationSetting addConfigurationSetting(String key, String label, St /** * Adds a configuration value in the service if that key and label does not exist. The label value of the * ConfigurationSetting is optional. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -392,7 +390,7 @@ public ConfigurationSetting addConfigurationSetting(ConfigurationSetting setting /** * Adds a configuration value in the service if that key and label does not exist. The label value of the * ConfigurationSetting is optional. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -433,7 +431,7 @@ public Response addConfigurationSettingWithResponse(Config // return an error. final ResponseBase response = serviceClient.putKeyValueWithResponse(setting.getKey(), setting.getLabel(), null, ETAG_ANY, - toKeyValue(setting), enableSyncRestProxy(addTracingNamespace(context))); + toKeyValue(setting), context); return toConfigurationSettingWithResponse(response); } @@ -475,7 +473,7 @@ public ConfigurationSetting setConfigurationSetting(String key, String label, St /** * Creates or updates a configuration value in the service. Partial updates are not supported and the entire * configuration setting is updated. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -521,10 +519,10 @@ public ConfigurationSetting setConfigurationSetting(ConfigurationSetting setting /** * Creates or updates a configuration value in the service. Partial updates are not supported and the entire * configuration setting is updated. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. - * + *

* If {@link ConfigurationSetting#getETag() ETag} is specified, the configuration value is updated if the current * setting's ETag matches. If the ETag's value is equal to the wildcard character ({@code "*"}), the setting will * always be updated. @@ -578,9 +576,8 @@ public Response setConfigurationSettingWithResponse(Config boolean ifUnchanged, Context context) { validateSetting(setting); final ResponseBase response = - serviceClient.putKeyValueWithResponse(setting.getKey(), setting.getLabel(), - getETag(ifUnchanged, setting), null, toKeyValue(setting), - enableSyncRestProxy(addTracingNamespace(context))); + serviceClient.putKeyValueWithResponse(setting.getKey(), setting.getLabel(), getETag(ifUnchanged, setting), + null, toKeyValue(setting), context); return toConfigurationSettingWithResponse(response); } @@ -646,7 +643,7 @@ public ConfigurationSetting getConfigurationSetting(String key, String label, Of /** * Attempts to get the ConfigurationSetting with a matching {@link ConfigurationSetting#getKey() key}, and optional * {@link ConfigurationSetting#getLabel() label}, optional {@code acceptDateTime} and optional ETag combination. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -681,7 +678,7 @@ public ConfigurationSetting getConfigurationSetting(ConfigurationSetting setting /** * Attempts to get the ConfigurationSetting with a matching {@link ConfigurationSetting#getKey() key}, and optional * {@link ConfigurationSetting#getLabel() label}, optional {@code acceptDateTime} and optional ETag combination. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -725,8 +722,8 @@ public Response getConfigurationSettingWithResponse(Config try { final ResponseBase response = serviceClient.getKeyValueWithResponse(setting.getKey(), setting.getLabel(), - acceptDateTime == null ? null : acceptDateTime.toString(), null, - getETag(ifChanged, setting), null, enableSyncRestProxy(addTracingNamespace(context))); + acceptDateTime == null ? null : acceptDateTime.toString(), null, getETag(ifChanged, setting), null, + context); return toConfigurationSettingWithResponse(response); } catch (HttpResponseException ex) { final HttpResponse httpResponse = ex.getResponse(); @@ -769,7 +766,7 @@ public ConfigurationSetting deleteConfigurationSetting(String key, String label) /** * Deletes the {@link ConfigurationSetting} with a matching {@link ConfigurationSetting#getKey() key}, and optional * {@link ConfigurationSetting#getLabel() label} and optional ETag combination. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -806,10 +803,10 @@ public ConfigurationSetting deleteConfigurationSetting(ConfigurationSetting sett /** * Deletes the {@link ConfigurationSetting} with a matching {@link ConfigurationSetting#getKey() key}, and optional * {@link ConfigurationSetting#getLabel() label} and optional ETag combination. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. - * + *

* If {@link ConfigurationSetting#getETag() ETag} is specified and is not the wildcard character ({@code "*"}), then * the setting is only deleted if the ETag matches the current ETag; this means that no one has updated the * ConfigurationSetting yet. @@ -852,7 +849,7 @@ public Response deleteConfigurationSettingWithResponse(Con validateSetting(setting); final ResponseBase response = serviceClient.deleteKeyValueWithResponse(setting.getKey(), setting.getLabel(), - getETag(ifUnchanged, setting), enableSyncRestProxy(addTracingNamespace(context))); + getETag(ifUnchanged, setting), context); return toConfigurationSettingWithResponse(response); } @@ -898,7 +895,7 @@ public ConfigurationSetting setReadOnly(String key, String label, boolean isRead /** * Sets the read-only status for the {@link ConfigurationSetting}. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -945,7 +942,7 @@ public ConfigurationSetting setReadOnly(ConfigurationSetting setting, boolean is /** * Sets the read-only status for the {@link ConfigurationSetting}. - * + *

* For more configuration setting types, see {@link FeatureFlagConfigurationSetting} and * {@link SecretReferenceConfigurationSetting}. * @@ -995,7 +992,6 @@ public Response setReadOnlyWithResponse(ConfigurationSetti validateSetting(setting); final String key = setting.getKey(); final String label = setting.getLabel(); - context = enableSyncRestProxy(addTracingNamespace(context)); return isReadOnly ? toConfigurationSettingWithResponse(serviceClient.putLockWithResponse(key, label, null, null, context)) @@ -1061,34 +1057,21 @@ public PagedIterable listConfigurationSettings(SettingSele final List settingFields = selector == null ? null : toSettingFieldsList(selector.getFields()); final List matchConditionsList = selector == null ? null : selector.getMatchConditions(); AtomicInteger pageETagIndex = new AtomicInteger(0); - return new PagedIterable<>( - () -> { - PagedResponse pagedResponse; - try { - pagedResponse = serviceClient.getKeyValuesSinglePage( - keyFilter, - labelFilter, - null, - acceptDateTime, - settingFields, - null, - null, - getPageETag(matchConditionsList, pageETagIndex), - enableSyncRestProxy(addTracingNamespace(context))); - } catch (HttpResponseException ex) { - return handleNotModifiedErrorToValidResponse(ex, LOGGER); - } - return toConfigurationSettingWithPagedResponse(pagedResponse); - }, + return new PagedIterable<>(() -> { + PagedResponse pagedResponse; + try { + pagedResponse = serviceClient.getKeyValuesSinglePage(keyFilter, labelFilter, null, acceptDateTime, + settingFields, null, null, getPageETag(matchConditionsList, pageETagIndex), context); + } catch (HttpResponseException ex) { + return handleNotModifiedErrorToValidResponse(ex, LOGGER); + } + return toConfigurationSettingWithPagedResponse(pagedResponse); + }, nextLink -> { PagedResponse pagedResponse; try { - pagedResponse = serviceClient.getKeyValuesNextSinglePage( - nextLink, - acceptDateTime, - null, - getPageETag(matchConditionsList, pageETagIndex), - enableSyncRestProxy(addTracingNamespace(context))); + pagedResponse = serviceClient.getKeyValuesNextSinglePage(nextLink, acceptDateTime, null, + getPageETag(matchConditionsList, pageETagIndex), context); } catch (HttpResponseException ex) { return handleNotModifiedErrorToValidResponse(ex, LOGGER); } @@ -1152,28 +1135,16 @@ public PagedIterable listConfigurationSettingsForSnapshot( */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listConfigurationSettingsForSnapshot(String snapshotName, - List fields, - Context context) { - return new PagedIterable<>( - () -> { - final PagedResponse pagedResponse = serviceClient.getKeyValuesSinglePage( - null, - null, - null, - null, - fields, - snapshotName, - null, - null, - enableSyncRestProxy(addTracingNamespace(context))); - return toConfigurationSettingWithPagedResponse(pagedResponse); - }, - nextLink -> { - final PagedResponse pagedResponse = serviceClient.getKeyValuesNextSinglePage(nextLink, - null, null, null, enableSyncRestProxy(addTracingNamespace(context))); - return toConfigurationSettingWithPagedResponse(pagedResponse); - } - ); + List fields, Context context) { + return new PagedIterable<>(() -> { + final PagedResponse pagedResponse = serviceClient.getKeyValuesSinglePage(null, null, null, null, + fields, snapshotName, null, null, context); + return toConfigurationSettingWithPagedResponse(pagedResponse); + }, nextLink -> { + final PagedResponse pagedResponse = serviceClient.getKeyValuesNextSinglePage(nextLink, null, null, + null, context); + return toConfigurationSettingWithPagedResponse(pagedResponse); + }); } /** @@ -1181,8 +1152,7 @@ public PagedIterable listConfigurationSettingsForSnapshot( * in descending order from their {@link ConfigurationSetting#getLastModified() lastModified} date. * Revisions expire after a period of time, see Pricing * for more information. - * - * + *

* If {@code selector} is {@code null}, then all the {@link ConfigurationSetting ConfigurationSettings} are fetched * in their current state. Otherwise, the results returned match the parameters given in {@code selector}. * @@ -1217,7 +1187,7 @@ public PagedIterable listRevisions(SettingSelector selecto * in descending order from their {@link ConfigurationSetting#getLastModified() lastModified} date. * Revisions expire after a period of time, see Pricing * for more information. - * + *

* If {@code selector} is {@code null}, then all the {@link ConfigurationSetting ConfigurationSettings} are fetched * in their current state. Otherwise, the results returned match the parameters given in {@code selector}. * @@ -1243,23 +1213,16 @@ public PagedIterable listRevisions(SettingSelector selecto @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listRevisions(SettingSelector selector, Context context) { final String acceptDateTime = selector == null ? null : selector.getAcceptDateTime(); - return new PagedIterable<>( - () -> { - final PagedResponse pagedResponse = serviceClient.getRevisionsSinglePage( - selector == null ? null : selector.getKeyFilter(), - selector == null ? null : selector.getLabelFilter(), - null, - acceptDateTime, - selector == null ? null : toSettingFieldsList(selector.getFields()), - enableSyncRestProxy(addTracingNamespace(context))); - return toConfigurationSettingWithPagedResponse(pagedResponse); - }, - nextLink -> { - final PagedResponse pagedResponse = serviceClient.getRevisionsNextSinglePage(nextLink, - acceptDateTime, enableSyncRestProxy(addTracingNamespace(context))); - return toConfigurationSettingWithPagedResponse(pagedResponse); - } - ); + return new PagedIterable<>(() -> { + final PagedResponse pagedResponse = serviceClient.getRevisionsSinglePage( + selector == null ? null : selector.getKeyFilter(), selector == null ? null : selector.getLabelFilter(), + null, acceptDateTime, selector == null ? null : toSettingFieldsList(selector.getFields()), context); + return toConfigurationSettingWithPagedResponse(pagedResponse); + }, nextLink -> { + final PagedResponse pagedResponse = serviceClient.getRevisionsNextSinglePage(nextLink, + acceptDateTime, context); + return toConfigurationSettingWithPagedResponse(pagedResponse); + }); } /** @@ -1525,15 +1488,10 @@ public PagedIterable listSnapshots(SnapshotSelector selec */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listSnapshots(SnapshotSelector selector, Context context) { - return new PagedIterable<>( - () -> serviceClient.getSnapshotsSinglePage( - selector == null ? null : selector.getNameFilter(), - null, - selector == null ? null : selector.getFields(), - selector == null ? null : selector.getStatus(), - enableSyncRestProxy(addTracingNamespace(context))), - nextLink -> serviceClient.getSnapshotsNextSinglePage(nextLink, - enableSyncRestProxy(addTracingNamespace(context)))); + return new PagedIterable<>(() -> serviceClient.getSnapshotsSinglePage( + selector == null ? null : selector.getNameFilter(), null, selector == null ? null : selector.getFields(), + selector == null ? null : selector.getStatus(), context), + nextLink -> serviceClient.getSnapshotsNextSinglePage(nextLink, context)); } /** diff --git a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClientBuilder.java b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClientBuilder.java index a743a01d56bc..489a1b35b7d3 100644 --- a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClientBuilder.java +++ b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClientBuilder.java @@ -12,6 +12,7 @@ import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpHeader; +import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; @@ -126,8 +127,8 @@ public final class ConfigurationClientBuilder implements CLIENT_VERSION = properties.getOrDefault("version", "UnknownVersion"); ADD_HEADERS_POLICY = new AddHeadersPolicy(new HttpHeaders() .set("x-ms-return-client-request-id", "true") - .set("Content-Type", "application/json") - .set("Accept", "application/vnd.microsoft.azconfig.kv+json")); + .set(HttpHeaderName.CONTENT_TYPE, "application/json") + .set(HttpHeaderName.ACCEPT, "application/vnd.microsoft.azconfig.kv+json")); } private static final ClientLogger LOGGER = new ClientLogger(ConfigurationClientBuilder.class); diff --git a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/implementation/Utility.java b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/implementation/Utility.java index 5bc1cca355d7..f40318800e33 100644 --- a/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/implementation/Utility.java +++ b/sdk/appconfiguration/azure-data-appconfiguration/src/main/java/com/azure/data/appconfiguration/implementation/Utility.java @@ -13,6 +13,7 @@ import com.azure.core.http.rest.ResponseBase; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; import com.azure.data.appconfiguration.implementation.models.KeyValue; import com.azure.data.appconfiguration.implementation.models.SnapshotUpdateParameters; @@ -24,19 +25,15 @@ import reactor.core.publisher.Mono; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; -import static com.azure.core.util.tracing.Tracer.AZ_TRACING_NAMESPACE_KEY; - /** * App Configuration Utility methods, use internally. */ public class Utility { - private static final String HTTP_REST_PROXY_SYNC_PROXY_ENABLE = "com.azure.core.http.restproxy.syncproxy.enable"; - public static final String APP_CONFIG_TRACING_NAMESPACE_VALUE = "Microsoft.AppConfiguration"; - public static final String ID = "id"; public static final String DESCRIPTION = "description"; public static final String DISPLAY_NAME = "display_name"; @@ -67,36 +64,9 @@ public static KeyValue toKeyValue(ConfigurationSetting setting) { .setTags(setting.getTags()); } - // List to SettingFields[] - public static SettingFields[] toSettingFieldsArray(List settingFieldsList) { - int size = settingFieldsList.size(); - SettingFields[] fields = new SettingFields[size]; - for (int i = 0; i < size; i++) { - fields[i] = settingFieldsList.get(i); - } - return fields; - } - // SettingFields[] to List public static List toSettingFieldsList(SettingFields[] settingFieldsArray) { - int size = settingFieldsArray.length; - List settingFieldsList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - settingFieldsList.add(settingFieldsArray[i]); - } - return settingFieldsList; - } - - // Iterable to List - public static List iterableToList(Iterable iterable) { - if (iterable == null) { - return null; - } - List outputList = new ArrayList<>(); - for (E item : iterable) { - outputList.add(item); - } - return outputList; + return new ArrayList<>(Arrays.asList(settingFieldsArray)); } /* @@ -117,14 +87,6 @@ public static String getETag(boolean isETagRequired, ConfigurationSetting settin return isETagRequired ? getETagValue(setting.getETag()) : null; } - public static String getETagSnapshot(boolean isETagRequired, ConfigurationSnapshot snapshot) { - if (!isETagRequired) { - return null; - } - Objects.requireNonNull(snapshot); - return getETagValue(snapshot.getETag()); - } - /* * Ensure that setting is not null. And, key cannot be null because it is part of the service REST URL. */ @@ -149,24 +111,6 @@ public static Mono validateSettingAsync(ConfigurationSetti return Mono.just(setting); } - /** - * Enable the sync stack rest proxy. - * - * @param context It offers a means of passing arbitrary data (key-value pairs) to pipeline policies. - * Most applications do not need to pass arbitrary data to the pipeline and can pass Context.NONE or null. - * - * @return The Context. - */ - public static Context enableSyncRestProxy(Context context) { - context = context == null ? Context.NONE : context; - return context.addData(HTTP_REST_PROXY_SYNC_PROXY_ENABLE, true); - } - - public static Context addTracingNamespace(Context context) { - context = context == null ? Context.NONE : context; - return context.addData(AZ_TRACING_NAMESPACE_KEY, APP_CONFIG_TRACING_NAMESPACE_VALUE); - } - public static Response updateSnapshotSync(String snapshotName, MatchConditions matchConditions, ConfigurationSnapshotStatus status, AzureAppConfigurationImpl serviceClient, Context context) { @@ -203,44 +147,44 @@ public static String parseNextLink(String nextLink) { // Async handler public static Mono> handleNotModifiedErrorToValidResponse(HttpResponseException error) { HttpResponse httpResponse = error.getResponse(); + if (httpResponse == null) { + return Mono.error(error); + } + String continuationToken = parseNextLink(httpResponse.getHeaderValue(HttpHeaderName.LINK)); if (httpResponse.getStatusCode() == 304) { - return Mono.just( - new PagedResponseBase<>( - httpResponse.getRequest(), - httpResponse.getStatusCode(), - httpResponse.getHeaders(), - null, - continuationToken, - null)); + return Mono.just(new PagedResponseBase<>(httpResponse.getRequest(), httpResponse.getStatusCode(), + httpResponse.getHeaders(), null, continuationToken, null)); } + return Mono.error(error); } // Sync Handler public static PagedResponse handleNotModifiedErrorToValidResponse(HttpResponseException error, ClientLogger logger) { HttpResponse httpResponse = error.getResponse(); + if (httpResponse == null) { + throw logger.logExceptionAsError(error); + } + String continuationToken = parseNextLink(httpResponse.getHeaderValue(HttpHeaderName.LINK)); if (httpResponse.getStatusCode() == 304) { - return new PagedResponseBase<>( - httpResponse.getRequest(), - httpResponse.getStatusCode(), - httpResponse.getHeaders(), - null, - continuationToken, - null); + return new PagedResponseBase<>(httpResponse.getRequest(), httpResponse.getStatusCode(), + httpResponse.getHeaders(), null, continuationToken, null); } + throw logger.logExceptionAsError(error); } // Get the ETag from a list public static String getPageETag(List matchConditionsList, AtomicInteger pageETagIndex) { - int pageETagListSize = (matchConditionsList == null || matchConditionsList.isEmpty()) - ? 0 - : matchConditionsList.size(); + if (CoreUtils.isNullOrEmpty(matchConditionsList)) { + return null; + } + String nextPageETag = null; int pageETagIndexValue = pageETagIndex.get(); - if (pageETagIndexValue < pageETagListSize) { + if (pageETagIndexValue < matchConditionsList.size()) { nextPageETag = matchConditionsList.get(pageETagIndexValue).getIfNoneMatch(); pageETagIndex.set(pageETagIndexValue + 1); }