Skip to content

Commit

Permalink
Generated from 605f32e1a3b527439a75e380c6a7fcfc434b25f9
Browse files Browse the repository at this point in the history
Microsoft.HanaOnAzure: Add Delete HanaInstance API

Add example file for the new API
Note: if this PR is merged after Azure/azure-rest-api-specs#5945 a provisioning state of 'deleting' should be displayed in the example
  • Loading branch information
AutorestCI committed May 16, 2019
1 parent b91b912 commit 875f6e7
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package com.microsoft.azure.management.hanaonazure.v2017_11_03_preview;

import com.microsoft.azure.arm.resources.collection.SupportsDeletingByResourceGroup;
import com.microsoft.azure.arm.resources.collection.SupportsBatchDeletion;
import com.microsoft.azure.arm.resources.collection.SupportsGettingByResourceGroup;
import rx.Observable;
import com.microsoft.azure.arm.resources.collection.SupportsListingByResourceGroup;
Expand All @@ -19,7 +21,7 @@
/**
* Type representing HanaInstances.
*/
public interface HanaInstances extends SupportsGettingByResourceGroup<HanaInstance>, SupportsListingByResourceGroup<HanaInstance>, SupportsListing<HanaInstance>, HasInner<HanaInstancesInner> {
public interface HanaInstances extends SupportsDeletingByResourceGroup, SupportsBatchDeletion, SupportsGettingByResourceGroup<HanaInstance>, SupportsListingByResourceGroup<HanaInstance>, SupportsListing<HanaInstance>, HasInner<HanaInstancesInner> {
/**
* The operation to restart a SAP HANA instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import com.microsoft.azure.management.hanaonazure.v2017_11_03_preview.HanaInstance;
import rx.Observable;
import rx.Completable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import com.microsoft.azure.arm.resources.ResourceUtilsCore;
import com.microsoft.azure.arm.utils.RXMapper;
import rx.functions.Func1;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.Page;
Expand All @@ -33,7 +38,39 @@ protected Observable<HanaInstanceInner> getInnerAsync(String resourceGroupName,
@Override
protected Completable deleteInnerAsync(String resourceGroupName, String name) {
HanaInstancesInner client = this.inner();
return Completable.error(new Throwable("Delete by RG not supported for this resource")); // NOP Delete by RG not supported
return client.deleteAsync(resourceGroupName, name).toCompletable();
}

@Override
public Observable<String> deleteByIdsAsync(Collection<String> ids) {
if (ids == null || ids.isEmpty()) {
return Observable.empty();
}
Collection<Observable<String>> observables = new ArrayList<>();
for (String id : ids) {
final String resourceGroupName = ResourceUtilsCore.groupFromResourceId(id);
final String name = ResourceUtilsCore.nameFromResourceId(id);
Observable<String> o = RXMapper.map(this.inner().deleteAsync(resourceGroupName, name), id);
observables.add(o);
}
return Observable.mergeDelayError(observables);
}

@Override
public Observable<String> deleteByIdsAsync(String...ids) {
return this.deleteByIdsAsync(new ArrayList<String>(Arrays.asList(ids)));
}

@Override
public void deleteByIds(Collection<String> ids) {
if (ids != null && !ids.isEmpty()) {
this.deleteByIdsAsync(ids).toBlocking().last();
}
}

@Override
public void deleteByIds(String...ids) {
this.deleteByIds(new ArrayList<String>(Arrays.asList(ids)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package com.microsoft.azure.management.hanaonazure.v2017_11_03_preview.implementation;

import com.microsoft.azure.arm.collection.InnerSupportsGet;
import com.microsoft.azure.arm.collection.InnerSupportsDelete;
import com.microsoft.azure.arm.collection.InnerSupportsListing;
import retrofit2.Retrofit;
import com.google.common.reflect.TypeToken;
Expand All @@ -32,6 +33,7 @@
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.HTTP;
import retrofit2.http.PATCH;
import retrofit2.http.Path;
import retrofit2.http.POST;
Expand All @@ -45,7 +47,7 @@
* An instance of this class provides access to all the operations defined
* in HanaInstances.
*/
public class HanaInstancesInner implements InnerSupportsGet<HanaInstanceInner>, InnerSupportsListing<HanaInstanceInner> {
public class HanaInstancesInner implements InnerSupportsGet<HanaInstanceInner>, InnerSupportsDelete<HanaInstanceInner>, InnerSupportsListing<HanaInstanceInner> {
/** The Retrofit service to perform REST calls. */
private HanaInstancesService service;
/** The service client containing this operation class. */
Expand Down Expand Up @@ -79,6 +81,10 @@ interface HanaInstancesService {
@GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HanaOnAzure/hanaInstances/{hanaInstanceName}")
Observable<Response<ResponseBody>> getByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("hanaInstanceName") String hanaInstanceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.hanaonazure.v2017_11_03_preview.HanaInstances delete" })
@HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HanaOnAzure/hanaInstances/{hanaInstanceName}", method = "DELETE", hasBody = true)
Observable<Response<ResponseBody>> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("hanaInstanceName") String hanaInstanceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.hanaonazure.v2017_11_03_preview.HanaInstances update" })
@PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HanaOnAzure/hanaInstances/{hanaInstanceName}")
Observable<Response<ResponseBody>> update(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("hanaInstanceName") String hanaInstanceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body Tags tagsParameter, @Header("User-Agent") String userAgent);
Expand Down Expand Up @@ -431,6 +437,96 @@ private ServiceResponse<HanaInstanceInner> getByResourceGroupDelegate(Response<R
.build(response);
}

/**
* Deletes a SAP HANA instance.
* Deletes a SAP HANA instance with the specified subscription, resource group, and instance name.
*
* @param resourceGroupName Name of the resource group.
* @param hanaInstanceName Name of the SAP HANA on Azure instance.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws ErrorResponseException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the HanaInstanceInner object if successful.
*/
public HanaInstanceInner delete(String resourceGroupName, String hanaInstanceName) {
return deleteWithServiceResponseAsync(resourceGroupName, hanaInstanceName).toBlocking().single().body();
}

/**
* Deletes a SAP HANA instance.
* Deletes a SAP HANA instance with the specified subscription, resource group, and instance name.
*
* @param resourceGroupName Name of the resource group.
* @param hanaInstanceName Name of the SAP HANA on Azure instance.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture<HanaInstanceInner> deleteAsync(String resourceGroupName, String hanaInstanceName, final ServiceCallback<HanaInstanceInner> serviceCallback) {
return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, hanaInstanceName), serviceCallback);
}

/**
* Deletes a SAP HANA instance.
* Deletes a SAP HANA instance with the specified subscription, resource group, and instance name.
*
* @param resourceGroupName Name of the resource group.
* @param hanaInstanceName Name of the SAP HANA on Azure instance.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the HanaInstanceInner object
*/
public Observable<HanaInstanceInner> deleteAsync(String resourceGroupName, String hanaInstanceName) {
return deleteWithServiceResponseAsync(resourceGroupName, hanaInstanceName).map(new Func1<ServiceResponse<HanaInstanceInner>, HanaInstanceInner>() {
@Override
public HanaInstanceInner call(ServiceResponse<HanaInstanceInner> response) {
return response.body();
}
});
}

/**
* Deletes a SAP HANA instance.
* Deletes a SAP HANA instance with the specified subscription, resource group, and instance name.
*
* @param resourceGroupName Name of the resource group.
* @param hanaInstanceName Name of the SAP HANA on Azure instance.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the HanaInstanceInner object
*/
public Observable<ServiceResponse<HanaInstanceInner>> deleteWithServiceResponseAsync(String resourceGroupName, String hanaInstanceName) {
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
if (resourceGroupName == null) {
throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
}
if (hanaInstanceName == null) {
throw new IllegalArgumentException("Parameter hanaInstanceName is required and cannot be null.");
}
if (this.client.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
}
return service.delete(this.client.subscriptionId(), resourceGroupName, hanaInstanceName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
.flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<HanaInstanceInner>>>() {
@Override
public Observable<ServiceResponse<HanaInstanceInner>> call(Response<ResponseBody> response) {
try {
ServiceResponse<HanaInstanceInner> clientResponse = deleteDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}

private ServiceResponse<HanaInstanceInner> deleteDelegate(Response<ResponseBody> response) throws ErrorResponseException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().<HanaInstanceInner, ErrorResponseException>newInstance(this.client.serializerAdapter())
.register(201, new TypeToken<HanaInstanceInner>() { }.getType())
.registerError(ErrorResponseException.class)
.build(response);
}

/**
* Patches the Tags field of a SAP HANA instance.
* Patches the Tags field of a SAP HANA instance for the specified subscription, resource group, and instance name.
Expand Down

0 comments on commit 875f6e7

Please sign in to comment.