Search in sources :

Example 1 with ProviderInner

use of com.microsoft.azure.management.resources.implementation.ProviderInner in project photon-model by vmware.

the class AzureInstanceService method registerSubscription.

private void registerSubscription(AzureInstanceContext ctx, String namespace) {
    ResourceManagementClientImpl client = getResourceManagementClientImpl(ctx);
    client.providers().registerAsync(namespace, new AzureAsyncCallback<ProviderInner>() {

        @Override
        public void onError(Throwable e) {
            handleError(ctx, e);
        }

        @Override
        public void onSuccess(ProviderInner result) {
            String registrationState = result.registrationState();
            if (!PROVIDER_REGISTRED_STATE.equalsIgnoreCase(registrationState)) {
                logInfo(() -> String.format("%s namespace registration in %s state", namespace, registrationState));
                long retryExpiration = Utils.getNowMicrosUtc() + DEFAULT_EXPIRATION_INTERVAL_MICROS;
                getSubscriptionState(ctx, namespace, retryExpiration);
                return;
            }
            logFine(() -> String.format("Successfully registered namespace [%s]", result.namespace()));
            handleAllocation(ctx);
        }
    });
}
Also used : ProviderInner(com.microsoft.azure.management.resources.implementation.ProviderInner) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)

Example 2 with ProviderInner

use of com.microsoft.azure.management.resources.implementation.ProviderInner in project photon-model by vmware.

the class AzureInstanceService method getSubscriptionState.

private void getSubscriptionState(AzureInstanceContext ctx, String namespace, long retryExpiration) {
    if (Utils.getNowMicrosUtc() > retryExpiration) {
        String msg = String.format("Subscription for %s namespace did not reach %s state", namespace, PROVIDER_REGISTRED_STATE);
        handleError(ctx, new RuntimeException(msg));
        return;
    }
    ResourceManagementClientImpl client = getResourceManagementClientImpl(ctx);
    getHost().schedule(() -> client.providers().getAsync(namespace, new AzureAsyncCallback<ProviderInner>() {

        @Override
        public void onError(Throwable e) {
            handleError(ctx, e);
        }

        @Override
        public void onSuccess(ProviderInner result) {
            String registrationState = result.registrationState();
            if (!PROVIDER_REGISTRED_STATE.equalsIgnoreCase(registrationState)) {
                logInfo(() -> String.format("%s namespace registration in %s state", namespace, registrationState));
                getSubscriptionState(ctx, namespace, retryExpiration);
                return;
            }
            logFine(() -> String.format("Successfully registered namespace [%s]", result.namespace()));
            handleAllocation(ctx);
        }
    }), RETRY_INTERVAL_SECONDS, TimeUnit.SECONDS);
}
Also used : AzureAsyncCallback(com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback) ProviderInner(com.microsoft.azure.management.resources.implementation.ProviderInner) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)

Aggregations

ProviderInner (com.microsoft.azure.management.resources.implementation.ProviderInner)2 ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)2 AzureAsyncCallback (com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback)1