Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
import com.azure.cosmos.implementation.DatabaseAccount;
import com.azure.cosmos.implementation.Document;
import com.azure.cosmos.implementation.FeedResponseDiagnostics;
import com.azure.cosmos.implementation.HttpConstants;
import com.azure.cosmos.implementation.JsonSerializable;
import com.azure.cosmos.implementation.MetadataDiagnosticsContext;
import com.azure.cosmos.implementation.QueryMetrics;
import com.azure.cosmos.implementation.RMResources;
import com.azure.cosmos.implementation.ReplicationPolicy;
import com.azure.cosmos.implementation.RequestTimeline;
import com.azure.cosmos.implementation.Resource;
import com.azure.cosmos.implementation.ResourceResponse;
import com.azure.cosmos.implementation.RxDocumentServiceRequest;
import com.azure.cosmos.implementation.RxDocumentServiceResponse;
import com.azure.cosmos.implementation.SerializationDiagnosticsContext;
import com.azure.cosmos.implementation.ServiceUnavailableException;
import com.azure.cosmos.implementation.StoredProcedureResponse;
import com.azure.cosmos.implementation.Strings;
import com.azure.cosmos.implementation.Warning;
import com.azure.cosmos.implementation.directconnectivity.StoreResponse;
import com.azure.cosmos.implementation.directconnectivity.StoreResult;
Expand Down Expand Up @@ -485,4 +489,9 @@ public static CosmosUser createCosmosUser(CosmosAsyncUser asyncUser, CosmosDatab
public static ConsistencyLevel fromServiceSerializedFormat(String consistencyLevel) {
return ConsistencyLevel.fromServiceSerializedFormat(consistencyLevel);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static CosmosException createServiceUnavailableException(Exception innerException) {
Copy link
Member Author

@xinlian12 xinlian12 Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think generally, it is better to create more specific exception compared to CosmosExceptions ?
(Another example is when create BadRequestExceptions)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. We can incorporate those changes after GA.

return new ServiceUnavailableException(innerException.getMessage(), innerException, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ boolean isContentResponseOnWriteEnabled() {
* The {@link Mono} upon successful completion will contain a single cosmos database response with the
* created or existing database.
*
* @param databaseSettings CosmosDatabaseProperties.
* @param databaseProperties CosmosDatabaseProperties.
* @return a {@link Mono} containing the cosmos database response with the created or existing database or
* an error.
*/
Mono<CosmosDatabaseResponse> createDatabaseIfNotExists(CosmosDatabaseProperties databaseSettings) {
return createDatabaseIfNotExistsInternal(getDatabase(databaseSettings.getId()));
Mono<CosmosDatabaseResponse> createDatabaseIfNotExists(CosmosDatabaseProperties databaseProperties) {
return createDatabaseIfNotExistsInternal(getDatabase(databaseProperties.getId()));
}

/**
Expand Down Expand Up @@ -263,17 +263,17 @@ public Mono<CosmosDatabaseResponse> createDatabaseIfNotExists(String id, Through
* created database.
* In case of failure the {@link Mono} will error.
*
* @param databaseSettings {@link CosmosDatabaseProperties}.
* @param databaseProperties {@link CosmosDatabaseProperties}.
* @param options {@link CosmosDatabaseRequestOptions}.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings,
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseProperties,
CosmosDatabaseRequestOptions options) {
if (options == null) {
options = new CosmosDatabaseRequestOptions();
}
Database wrappedDatabase = new Database();
wrappedDatabase.setId(databaseSettings.getId());
wrappedDatabase.setId(databaseProperties.getId());
return asyncDocumentClient.createDatabase(wrappedDatabase, ModelBridgeInternal.toRequestOptions(options))
.map(databaseResourceResponse -> ModelBridgeInternal.createCosmosDatabaseResponse(databaseResourceResponse))
.single();
Expand All @@ -287,11 +287,11 @@ public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties data
* created database.
* In case of failure the {@link Mono} will error.
*
* @param databaseSettings {@link CosmosDatabaseProperties}.
* @param databaseProperties {@link CosmosDatabaseProperties}.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings) {
return createDatabase(databaseSettings, new CosmosDatabaseRequestOptions());
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseProperties) {
return createDatabase(databaseProperties, new CosmosDatabaseRequestOptions());
}

/**
Expand All @@ -317,20 +317,20 @@ public Mono<CosmosDatabaseResponse> createDatabase(String id) {
* created database.
* In case of failure the {@link Mono} will error.
*
* @param databaseSettings {@link CosmosDatabaseProperties}.
* @param databaseProperties {@link CosmosDatabaseProperties}.
* @param throughputProperties the throughput properties for the database.
* @param options {@link CosmosDatabaseRequestOptions}.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings,
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseProperties,
ThroughputProperties throughputProperties,
CosmosDatabaseRequestOptions options) {
if (options == null) {
options = new CosmosDatabaseRequestOptions();
}
ModelBridgeInternal.setThroughputProperties(options, throughputProperties);
Database wrappedDatabase = new Database();
wrappedDatabase.setId(databaseSettings.getId());
wrappedDatabase.setId(databaseProperties.getId());
return asyncDocumentClient.createDatabase(wrappedDatabase, ModelBridgeInternal.toRequestOptions(options))
.map(databaseResourceResponse -> ModelBridgeInternal.createCosmosDatabaseResponse(databaseResourceResponse))
.single();
Expand All @@ -344,14 +344,14 @@ public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties data
* created database.
* In case of failure the {@link Mono} will error.
*
* @param databaseSettings {@link CosmosDatabaseProperties}.
* @param databaseProperties {@link CosmosDatabaseProperties}.
* @param throughputProperties the throughput properties for the database.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings, ThroughputProperties throughputProperties) {
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseProperties, ThroughputProperties throughputProperties) {
CosmosDatabaseRequestOptions options = new CosmosDatabaseRequestOptions();
ModelBridgeInternal.setThroughputProperties(options, throughputProperties);
return createDatabase(databaseSettings, options);
return createDatabase(databaseProperties, options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ public Mono<CosmosStoredProcedureResponse> execute(List<Object> procedureParams,
* procedure.
* In case of failure the {@link Mono} will error.
*
* @param storedProcedureSettings the stored procedure properties
* @param storedProcedureProperties the stored procedure properties
* @return an {@link Mono} containing the single resource response with the replaced stored procedure or an error.
*/
public Mono<CosmosStoredProcedureResponse> replace(CosmosStoredProcedureProperties storedProcedureSettings) {
return replace(storedProcedureSettings, null);
public Mono<CosmosStoredProcedureResponse> replace(CosmosStoredProcedureProperties storedProcedureProperties) {
return replace(storedProcedureProperties, null);
}

/**
Expand All @@ -163,19 +163,19 @@ public Mono<CosmosStoredProcedureResponse> replace(CosmosStoredProcedureProperti
* procedure.
* In case of failure the {@link Mono} will error.
*
* @param storedProcedureSettings the stored procedure properties.
* @param storedProcedureProperties the stored procedure properties.
* @param options the request options.
* @return an {@link Mono} containing the single resource response with the replaced stored procedure or an error.
*/
public Mono<CosmosStoredProcedureResponse> replace(CosmosStoredProcedureProperties storedProcedureSettings,
public Mono<CosmosStoredProcedureResponse> replace(CosmosStoredProcedureProperties storedProcedureProperties,
CosmosStoredProcedureRequestOptions options) {
if (options == null) {
options = new CosmosStoredProcedureRequestOptions();
}
return cosmosContainer.getDatabase()
.getDocClientWrapper()
.replaceStoredProcedure(new StoredProcedure(ModelBridgeInternal.toJsonFromJsonSerializable(
ModelBridgeInternal.getResource(storedProcedureSettings))),
ModelBridgeInternal.getResource(storedProcedureProperties))),
ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosStoredProcedureResponse(response))
.single();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public Mono<CosmosTriggerResponse> read() {
* The {@link Mono} upon successful completion will contain a single resource response with the replaced trigger.
* In case of failure the {@link Mono} will error.
*
* @param triggerSettings the cosmos trigger properties.
* @param triggerProperties the cosmos trigger properties.
* @return an {@link Mono} containing the single resource response with the replaced cosmos trigger or an error.
*/
public Mono<CosmosTriggerResponse> replace(CosmosTriggerProperties triggerSettings) {
public Mono<CosmosTriggerResponse> replace(CosmosTriggerProperties triggerProperties) {
return container.getDatabase()
.getDocClientWrapper()
.replaceTrigger(new Trigger(ModelBridgeInternal.toJsonFromJsonSerializable(
ModelBridgeInternal.getResource(triggerSettings))), null)
ModelBridgeInternal.getResource(triggerProperties))), null)
.map(response -> ModelBridgeInternal.createCosmosTriggerResponse(response))
.single();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public Mono<CosmosUserResponse> read() {
/**
* Replace a cosmos user
*
* @param userSettings the user properties to use
* @param userProperties the user properties to use
* @return a {@link Mono} containing the single resource response with the replaced user or an error.
*/
public Mono<CosmosUserResponse> replace(CosmosUserProperties userSettings) {
public Mono<CosmosUserResponse> replace(CosmosUserProperties userProperties) {
return this.database.getDocClientWrapper()
.replaceUser(ModelBridgeInternal.getV2User(userSettings), null)
.replaceUser(ModelBridgeInternal.getV2User(userProperties), null)
.map(response -> ModelBridgeInternal.createCosmosUserResponse(response)).single();
}

Expand All @@ -91,17 +91,17 @@ public Mono<CosmosUserResponse> delete() {
* The {@link Mono} upon successful completion will contain a single resource response with the created permission.
* In case of failure the {@link Mono} will error.
*
* @param permissionSettings the permission properties to create.
* @param permissionProperties the permission properties to create.
* @param options the request options.
* @return an {@link Mono} containing the single resource response with the created permission or an error.
*/
public Mono<CosmosPermissionResponse> createPermission(
CosmosPermissionProperties permissionSettings,
CosmosPermissionProperties permissionProperties,
CosmosPermissionRequestOptions options) {
if (options == null) {
options = new CosmosPermissionRequestOptions();
}
Permission permission = ModelBridgeInternal.getV2Permissions(permissionSettings);
Permission permission = ModelBridgeInternal.getV2Permissions(permissionProperties);
return database.getDocClientWrapper()
.createPermission(getLink(), permission, ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosPermissionResponse(response))
Expand All @@ -115,14 +115,14 @@ public Mono<CosmosPermissionResponse> createPermission(
* The {@link Mono} upon successful completion will contain a single resource response with the upserted permission.
* In case of failure the {@link Mono} will error.
*
* @param permissionSettings the permission properties to upsert.
* @param permissionProperties the permission properties to upsert.
* @param options the request options.
* @return an {@link Mono} containing the single resource response with the upserted permission or an error.
*/
public Mono<CosmosPermissionResponse> upsertPermission(
CosmosPermissionProperties permissionSettings,
CosmosPermissionProperties permissionProperties,
CosmosPermissionRequestOptions options) {
Permission permission = ModelBridgeInternal.getV2Permissions(permissionSettings);
Permission permission = ModelBridgeInternal.getV2Permissions(permissionProperties);
if (options == null) {
options = new CosmosPermissionRequestOptions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ public CosmosStoredProcedureResponse execute(
/**
* Replace cosmos sync stored procedure.
*
* @param storedProcedureSettings the stored procedure settings
* @param storedProcedureProperties the stored procedure settings
* @return the cosmos stored procedure response
*/
public CosmosStoredProcedureResponse replace(CosmosStoredProcedureProperties storedProcedureSettings) {
public CosmosStoredProcedureResponse replace(CosmosStoredProcedureProperties storedProcedureProperties) {
return container.getScripts()
.blockStoredProcedureResponse(storedProcedure.replace(storedProcedureSettings));
.blockStoredProcedureResponse(storedProcedure.replace(storedProcedureProperties));
}

/**
* Replace cosmos sync stored procedure.
*
* @param storedProcedureSettings the stored procedure settings
* @param storedProcedureProperties the stored procedure settings
* @param options the options
* @return the cosmos stored procedure response
*/
public CosmosStoredProcedureResponse replace(
CosmosStoredProcedureProperties storedProcedureSettings,
CosmosStoredProcedureProperties storedProcedureProperties,
CosmosStoredProcedureRequestOptions options) {
return container.getScripts()
.blockStoredProcedureResponse(storedProcedure.replace(storedProcedureSettings, options));
.blockStoredProcedureResponse(storedProcedure.replace(storedProcedureProperties, options));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public CosmosTriggerResponse read() {
/**
* Replace cosmos trigger.
*
* @param triggerSettings the trigger settings
* @param triggerProperties the trigger properties.
* @return the cosmos trigger response
*/
public CosmosTriggerResponse replace(CosmosTriggerProperties triggerSettings) {
return container.getScripts().blockTriggerResponse(trigger.replace(triggerSettings));
public CosmosTriggerResponse replace(CosmosTriggerProperties triggerProperties) {
return container.getScripts().blockTriggerResponse(trigger.replace(triggerProperties));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public ServiceUnavailableException(String message,
Exception innerException,
HttpHeaders headers,
String requestUriString) {
super(String.format("%s: %s", RMResources.ServiceUnavailable, message),
super(
String.format("%s: %s",
RMResources.ServiceUnavailable,
String.format(RMResources.ExceptionMessage, Strings.isNullOrWhiteSpace(message) ? RMResources.ServiceUnavailable : message)),
innerException,
HttpUtils.asMap(headers),
HttpConstants.StatusCodes.SERVICE_UNAVAILABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public Mono<ShouldRetryResult> shouldRetry(Exception exception) {
} else {
logger.warn("Received gone exception after backoff/retry. Will fail the request. {}",
exception.toString());
exceptionToThrow = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE,
exception);
exceptionToThrow = BridgeInternal.createServiceUnavailableException(exception);
}

} else if (exception instanceof PartitionKeyRangeGoneException) {
Expand All @@ -100,8 +99,7 @@ public Mono<ShouldRetryResult> shouldRetry(Exception exception) {
logger.warn(
"Received partition key range gone exception after backoff/retry. Will fail the request. {}",
exception.toString());
exceptionToThrow = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE,
exception);
exceptionToThrow = BridgeInternal.createServiceUnavailableException(exception);
}
} else if (exception instanceof InvalidPartitionException) {
if (this.lastRetryWithException != null) {
Expand All @@ -113,8 +111,7 @@ public Mono<ShouldRetryResult> shouldRetry(Exception exception) {
logger.warn(
"Received invalid collection partition exception after backoff/retry. Will fail the request. {}",
exception.toString());
exceptionToThrow = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE,
exception);
exceptionToThrow = BridgeInternal.createServiceUnavailableException(exception);
}
} else {
logger.warn("Received retrywith exception after backoff/retry. Will fail the request. {}",
Expand Down Expand Up @@ -151,7 +148,7 @@ public Mono<ShouldRetryResult> shouldRetry(Exception exception) {
logger.warn("Received second InvalidPartitionException after backoff/retry. Will fail the request. {}",
exception.toString());
return Mono.just(ShouldRetryResult
.error(BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, exception)));
.error(BridgeInternal.createServiceUnavailableException(exception)));
}

if (this.request != null) {
Expand Down
Loading