Skip to content

Commit

Permalink
Implement decommission APIs for Models (#14670)
Browse files Browse the repository at this point in the history
  • Loading branch information
azabbasi authored Sep 1, 2020
1 parent 4a74849 commit 1b10644
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 47 deletions.
32 changes: 0 additions & 32 deletions sdk/digitaltwins/azure-digitaltwins-core/API design.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,43 +802,11 @@ When updating a model, the payload for a multi-operation json patch follows the
Async APIs

```java

/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> decommissionModel(String modelId) { }

/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
* @return The http response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response> decommissionModelWithResponse(String modelId) { }

```

Sync APIs
```java
/**
/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Void decommissionModel(String modelId) { }

/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return The http response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response decommissionModelWithResponse(String modelId, Context context) { }

```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.azure.digitaltwins.core.util.DigitalTwinsResponse;
import com.azure.digitaltwins.core.util.DigitalTwinsResponseHeaders;
import com.azure.digitaltwins.core.util.ListModelOptions;
import com.azure.digitaltwins.core.util.UpdateOperationUtility;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
Expand Down Expand Up @@ -593,8 +594,8 @@ Mono<PagedResponse<ModelData>> createModelsSinglePageAsync(List<String> models,
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<ModelData> getModel(String modelId) {
return withContext(context -> getModelWithResponse(modelId, context))
.flatMap(response -> Mono.just(response.getValue()));
return getModelWithResponse(modelId)
.map(Response::getValue);
}

/**
Expand Down Expand Up @@ -665,8 +666,8 @@ Mono<PagedResponse<ModelData>> listModelsNextSinglePageAsync(String nextLink, Co
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> deleteModel(String modelId) {
return withContext(context -> deleteModelWithResponse(modelId, context))
.flatMap(response -> Mono.just(response.getValue()));
return deleteModelWithResponse(modelId)
.map(Response::getValue);
}

/**
Expand All @@ -683,11 +684,36 @@ Mono<Response<Void>> deleteModelWithResponse(String modelId, Context context){
return protocolLayer.getDigitalTwinModels().deleteWithResponseAsync(modelId, context);
}

//TODO: Decommission Model APIs (waiting for Abhipsa's change to come in)
PagedFlux<String> listRelationships(String digitalTwinId, String relationshipName, Context context) {
return new PagedFlux<>(
() -> listRelationshipsFirstPage(digitalTwinId, relationshipName, context),
nextLink -> listRelationshipsNextPage(nextLink, context));
}

/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
* @return an empty Mono
*/
public Mono<Void> decommissionModel(String modelId) {
return decommissionModelWithResponse(modelId)
.map(Response::getValue);
}

/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
* @return The http response.
*/
public Mono<Response<Void>> decommissionModelWithResponse(String modelId) {
return withContext(context -> decommissionModelWithResponse(modelId, context));
}

Mono<Response<Void>> decommissionModelWithResponse(String modelId, Context context) {
List<Object> updateOperation = new UpdateOperationUtility()
.appendReplaceOperation("/decommissioned", true)
.getUpdateOperations();

return protocolLayer.getDigitalTwinModels().updateWithResponseAsync(modelId, updateOperation, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,10 @@ public PagedIterable<ModelData> listModels() {
/**
* Deletes a model.
* @param modelId The Id for the model. The Id is globally unique and case sensitive.
* @return Void
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Void deleteModel(String modelId) {
return digitalTwinsAsyncClient.deleteModel(modelId).block();
public void deleteModel(String modelId) {
deleteModelWithResponse(modelId, Context.NONE);
}

/**
Expand All @@ -365,6 +364,21 @@ public Response<Void> deleteModelWithResponse(String modelId, Context context) {
return digitalTwinsAsyncClient.deleteModelWithResponse(modelId, context).block();
}

//TODO: Decommission Model APIs (waiting for Abhipsa's change to come in)
/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
*/
public void decommissionModel(String modelId) {
decommissionModelWithResponse(modelId, Context.NONE);
}

/**
* Decommissions a model.
* @param modelId The Id of the model to decommission.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return The http response.
*/
public Response<Void> decommissionModelWithResponse(String modelId, Context context) {
return digitalTwinsAsyncClient.decommissionModelWithResponse(modelId, context).block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.util.Configuration;
import com.azure.core.util.logging.ClientLogger;
import com.azure.identity.ClientSecretCredentialBuilder;
import reactor.core.publisher.Mono;

import java.util.Locale;

public class DigitalTwinsTestBase extends TestBase
{
protected static final String TENANT_ID = Configuration.getGlobalConfiguration()
Expand Down

0 comments on commit 1b10644

Please sign in to comment.