Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement decommission APIs for Models #14670

Merged
merged 7 commits into from
Sep 1, 2020
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
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
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
*/
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