Search in sources :

Example 86 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class TopicsInner method regenerateKeysWithServiceResponseAsync.

/**
     * Regenerates primary or secondary connection strings for the topic.
     *
     * @param resourceGroupName Name of the Resource group within the Azure subscription.
     * @param namespaceName The namespace name
     * @param topicName The topic name.
     * @param authorizationRuleName The authorizationrule name.
     * @param policykey Key that needs to be regenerated. Possible values include: 'PrimaryKey', 'SecondaryKey'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ResourceListKeysInner object
     */
public Observable<ServiceResponse<ResourceListKeysInner>> regenerateKeysWithServiceResponseAsync(String resourceGroupName, String namespaceName, String topicName, String authorizationRuleName, Policykey policykey) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (namespaceName == null) {
        throw new IllegalArgumentException("Parameter namespaceName is required and cannot be null.");
    }
    if (topicName == null) {
        throw new IllegalArgumentException("Parameter topicName is required and cannot be null.");
    }
    if (authorizationRuleName == null) {
        throw new IllegalArgumentException("Parameter authorizationRuleName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    RegenerateKeysParameters parameters = new RegenerateKeysParameters();
    parameters.withPolicykey(policykey);
    return service.regenerateKeys(resourceGroupName, namespaceName, topicName, authorizationRuleName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ResourceListKeysInner>>>() {

        @Override
        public Observable<ServiceResponse<ResourceListKeysInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<ResourceListKeysInner> clientResponse = regenerateKeysDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) RegenerateKeysParameters(com.microsoft.azure.management.servicebus.RegenerateKeysParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 87 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class DatabasesInner method createOrUpdateTransparentDataEncryptionConfigurationWithServiceResponseAsync.

/**
     * Creates or updates an Azure SQL Database Transparent Data Encryption Operation.
     *
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the Azure SQL server.
     * @param databaseName The name of the Azure SQL database for which setting the Transparent Data Encryption applies.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the TransparentDataEncryptionInner object
     */
public Observable<ServiceResponse<TransparentDataEncryptionInner>> createOrUpdateTransparentDataEncryptionConfigurationWithServiceResponseAsync(String resourceGroupName, String serverName, String databaseName) {
    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 (serverName == null) {
        throw new IllegalArgumentException("Parameter serverName is required and cannot be null.");
    }
    if (databaseName == null) {
        throw new IllegalArgumentException("Parameter databaseName is required and cannot be null.");
    }
    final String apiVersion = "2014-04-01";
    final TransparentDataEncryptionStates status = null;
    TransparentDataEncryptionInner parameters = new TransparentDataEncryptionInner();
    parameters.withStatus(null);
    return service.createOrUpdateTransparentDataEncryptionConfiguration(this.client.subscriptionId(), resourceGroupName, serverName, databaseName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<TransparentDataEncryptionInner>>>() {

        @Override
        public Observable<ServiceResponse<TransparentDataEncryptionInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<TransparentDataEncryptionInner> clientResponse = createOrUpdateTransparentDataEncryptionConfigurationDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : ServiceResponse(com.microsoft.rest.ServiceResponse) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) TransparentDataEncryptionStates(com.microsoft.azure.management.sql.TransparentDataEncryptionStates) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 88 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class DAGErrorTests method testCompositeError.

@Test
public void testCompositeError() {
    // Terminate on error strategy used in this task group is
    // TaskGroupTerminateOnErrorStrategy::TERMINATE_ON_INPROGRESS_TASKS_COMPLETION
    // Tasks marked X (B & G) will fault. B and G are not depends on each other.
    // If B start at time 't0'th ms then G starts ~'t1 = (t0 + 250)'th ms.
    // After B start, it asynchronously wait and emit an error at time '(t0 + 3500)' ms.
    // In this setup, G gets ~3250 ms to start before B emits error. Eventually G also
    // emit error.
    // The final stream, emits result of all tasks that B and G directly or indirectly
    // depends on and terminate with composite exception (that composes exception from
    // B and G).
    /**
         *                                                                        |--------->[M](0)
         *                                                                        |
         *                                                       |==============>[J](1)----->[N](0)
         *                                 X                     |
         *   |------------------>[D](4)-->[B](3)--------------->[A](2)======================>[K](0)
         *   |                             ^                     ^
         *   |                             |                     |
         *  [F](6)---->[E](5)--------------|                     |
         *   |          |         X                              |
         *   |          |------->[G](4)-->[C](3)------------------
         *   |                    |
         *   |                    |============================>[L](2)---------->[P](1)=====>[Q](0)
         *   |
         *   |------------------------------------------------------------------>[H](1)----->[I](0)
         */
    PancakeImpl pancakeM = new PancakeImpl("M", 250);
    PancakeImpl pancakeN = new PancakeImpl("N", 250);
    PancakeImpl pancakeK = new PancakeImpl("K", 250);
    PancakeImpl pancakeQ = new PancakeImpl("Q", 250);
    PancakeImpl pancakeI = new PancakeImpl("I", 250);
    PancakeImpl pancakeJ = new PancakeImpl("J", 250);
    pancakeJ.withInstantPancake(pancakeM);
    pancakeJ.withInstantPancake(pancakeN);
    PancakeImpl pancakeP = new PancakeImpl("P", 250);
    pancakeP.withDelayedPancake(pancakeQ);
    PancakeImpl pancakeH = new PancakeImpl("H", 250);
    pancakeH.withInstantPancake(pancakeI);
    PancakeImpl pancakeA = new PancakeImpl("A", 250);
    PancakeImpl pancakeL = new PancakeImpl("L", 250);
    pancakeL.withInstantPancake(pancakeP);
    // Task B wait for 3500 ms then emit error
    PancakeImpl pancakeB = new PancakeImpl("B", 3500, true);
    pancakeB.withInstantPancake(pancakeA);
    PancakeImpl pancakeC = new PancakeImpl("C", 250);
    pancakeC.withInstantPancake(pancakeA);
    PancakeImpl pancakeD = new PancakeImpl("D", 250);
    pancakeD.withInstantPancake(pancakeB);
    // Task G wait for 250 ms then emit error
    PancakeImpl pancakeG = new PancakeImpl("G", 250, true);
    pancakeG.withInstantPancake(pancakeC);
    pancakeG.withDelayedPancake(pancakeL);
    PancakeImpl pancakeE = new PancakeImpl("E", 250);
    pancakeE.withInstantPancake(pancakeB);
    pancakeE.withInstantPancake(pancakeG);
    PancakeImpl pancakeF = new PancakeImpl("F", 250);
    pancakeF.withInstantPancake(pancakeD);
    pancakeF.withInstantPancake(pancakeE);
    pancakeF.withInstantPancake(pancakeH);
    pancakeA.withDelayedPancake(pancakeJ);
    pancakeA.withDelayedPancake(pancakeK);
    final Set<String> expectedToSee = new HashSet<>();
    expectedToSee.add("M");
    expectedToSee.add("N");
    expectedToSee.add("K");
    expectedToSee.add("Q");
    expectedToSee.add("I");
    expectedToSee.add("J");
    expectedToSee.add("P");
    expectedToSee.add("H");
    expectedToSee.add("A");
    expectedToSee.add("L");
    expectedToSee.add("C");
    final Set<String> seen = new HashSet<>();
    final List<Throwable> exceptions = new ArrayList<>();
    IPancake rootPancake = pancakeF.createAsync().map(new Func1<Indexable, IPancake>() {

        @Override
        public IPancake call(Indexable indexable) {
            IPancake pancake = (IPancake) indexable;
            String name = pancake.name();
            System.out.println("map.onNext:" + name);
            seen.add(name);
            return pancake;
        }
    }).onErrorResumeNext(new Func1<Throwable, Observable<IPancake>>() {

        @Override
        public Observable<IPancake> call(Throwable throwable) {
            System.out.println("map.onErrorResumeNext:" + throwable);
            exceptions.add(throwable);
            return Observable.empty();
        }
    }).toBlocking().last();
    Assert.assertTrue(Sets.difference(expectedToSee, seen).isEmpty());
    Assert.assertEquals(exceptions.size(), 1);
    Assert.assertTrue(exceptions.get(0) instanceof CompositeException);
    CompositeException compositeException = (CompositeException) exceptions.get(0);
    Assert.assertEquals(compositeException.getExceptions().size(), 2);
    for (Throwable throwable : compositeException.getExceptions()) {
        String message = throwable.getMessage();
        Assert.assertTrue(message.equalsIgnoreCase("B") || message.equalsIgnoreCase("G"));
    }
}
Also used : CompositeException(rx.exceptions.CompositeException) ArrayList(java.util.ArrayList) Observable(rx.Observable) Indexable(com.microsoft.azure.management.resources.fluentcore.model.Indexable) Func1(rx.functions.Func1) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 89 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class NamespacesInner method regenerateKeysWithServiceResponseAsync.

/**
     * Regenerates the primary or secondary connection strings for the namespace.
     *
     * @param resourceGroupName Name of the Resource group within the Azure subscription.
     * @param namespaceName The namespace name
     * @param authorizationRuleName The authorizationrule name.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ResourceListKeysInner object
     */
public Observable<ServiceResponse<ResourceListKeysInner>> regenerateKeysWithServiceResponseAsync(String resourceGroupName, String namespaceName, String authorizationRuleName) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (namespaceName == null) {
        throw new IllegalArgumentException("Parameter namespaceName is required and cannot be null.");
    }
    if (authorizationRuleName == null) {
        throw new IllegalArgumentException("Parameter authorizationRuleName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    final Policykey policykey = null;
    RegenerateKeysParameters parameters = new RegenerateKeysParameters();
    parameters.withPolicykey(null);
    return service.regenerateKeys(resourceGroupName, namespaceName, authorizationRuleName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ResourceListKeysInner>>>() {

        @Override
        public Observable<ServiceResponse<ResourceListKeysInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<ResourceListKeysInner> clientResponse = regenerateKeysDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) Policykey(com.microsoft.azure.management.servicebus.Policykey) RegenerateKeysParameters(com.microsoft.azure.management.servicebus.RegenerateKeysParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 90 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class NamespacesInner method regenerateKeysWithServiceResponseAsync.

/**
     * Regenerates the primary or secondary connection strings for the namespace.
     *
     * @param resourceGroupName Name of the Resource group within the Azure subscription.
     * @param namespaceName The namespace name
     * @param authorizationRuleName The authorizationrule name.
     * @param policykey Key that needs to be regenerated. Possible values include: 'PrimaryKey', 'SecondaryKey'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ResourceListKeysInner object
     */
public Observable<ServiceResponse<ResourceListKeysInner>> regenerateKeysWithServiceResponseAsync(String resourceGroupName, String namespaceName, String authorizationRuleName, Policykey policykey) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (namespaceName == null) {
        throw new IllegalArgumentException("Parameter namespaceName is required and cannot be null.");
    }
    if (authorizationRuleName == null) {
        throw new IllegalArgumentException("Parameter authorizationRuleName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    RegenerateKeysParameters parameters = new RegenerateKeysParameters();
    parameters.withPolicykey(policykey);
    return service.regenerateKeys(resourceGroupName, namespaceName, authorizationRuleName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ResourceListKeysInner>>>() {

        @Override
        public Observable<ServiceResponse<ResourceListKeysInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<ResourceListKeysInner> clientResponse = regenerateKeysDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) RegenerateKeysParameters(com.microsoft.azure.management.servicebus.RegenerateKeysParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Aggregations

Observable (rx.Observable)210 ResponseBody (okhttp3.ResponseBody)97 Response (retrofit2.Response)93 ServiceResponse (com.microsoft.rest.ServiceResponse)92 ArrayList (java.util.ArrayList)39 Test (org.junit.Test)34 List (java.util.List)33 Func1 (rx.functions.Func1)26 IOException (java.io.IOException)16 Subscription (rx.Subscription)14 Action1 (rx.functions.Action1)13 Context (android.content.Context)12 Schedulers (rx.schedulers.Schedulers)12 ByteBuf (io.netty.buffer.ByteBuf)10 NonNull (android.support.annotation.NonNull)9 Collections (java.util.Collections)9 Intent (android.content.Intent)8 SharedPreferences (android.content.SharedPreferences)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 PreferenceManager (android.preference.PreferenceManager)7