Search in sources :

Example 11 with RestClient

use of com.microsoft.rest.RestClient in project azure-sdk-for-java by Azure.

the class ManageSqlDatabaseInElasticPool method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 12 with RestClient

use of com.microsoft.rest.RestClient in project azure-sdk-for-java by Azure.

the class ManageSqlDatabasesAcrossDifferentDataCenters method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 13 with RestClient

use of com.microsoft.rest.RestClient in project azure-sdk-for-java by Azure.

the class ManageSqlFirewallRules method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 14 with RestClient

use of com.microsoft.rest.RestClient in project azure-sdk-for-java by Azure.

the class DataLakeAnalyticsManagementTestBase method initializeClients.

@Override
protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) {
    rgName = generateRandomResourceName("adlarg", 15);
    adlsName = generateRandomResourceName("adls", 15);
    jobAndCatalogAdlaName = generateRandomResourceName("secondadla", 15);
    environmentLocation = Region.US_EAST2;
    dataLakeAnalyticsAccountManagementClient = new DataLakeAnalyticsAccountManagementClientImpl(restClient).withSubscriptionId(defaultSubscription);
    // TODO: in the future this needs to be dynamic depending on the Azure environment
    // the tests are running in.
    String adlaSuffix = "azuredatalakeanalytics.net";
    addTextReplacementRule("https://(.*)." + adlaSuffix, this.mockUri());
    // Generate creds and a set of rest clients for catalog and job
    ApplicationTokenCredentials credentials = new AzureTestCredentials();
    if (IS_RECORD) {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        try {
            credentials = ApplicationTokenCredentials.fromFile(credFile);
        } catch (IOException e) {
            Assert.fail("Failed to read credentials from file: " + credFile + " with error: " + e.getMessage());
        }
    }
    if (IS_RECORD) {
        RestClient restClientWithTimeout = buildRestClient(new RestClient.Builder().withConnectionTimeout(5, TimeUnit.MINUTES).withBaseUrl("https://{accountName}.{adlaJobDnsSuffix}").withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), IS_MOCKED);
        dataLakeAnalyticsJobManagementClient = new DataLakeAnalyticsJobManagementClientImpl(restClientWithTimeout).withAdlaJobDnsSuffix(adlaSuffix);
        RestClient catalogRestClient = buildRestClient(new RestClient.Builder().withBaseUrl("https://{accountName}.{adlaCatalogDnsSuffix}").withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), IS_MOCKED);
        dataLakeAnalyticsCatalogManagementClient = new DataLakeAnalyticsCatalogManagementClientImpl(catalogRestClient).withAdlaCatalogDnsSuffix(adlaSuffix);
    } else {
        // for mocked clients, we can just use the basic rest client, since the DNS is replaced.
        dataLakeAnalyticsCatalogManagementClient = new DataLakeAnalyticsCatalogManagementClientImpl(restClient);
        dataLakeAnalyticsJobManagementClient = new DataLakeAnalyticsJobManagementClientImpl(restClient);
    }
    resourceManagementClient = ResourceManager.authenticate(restClient).withSubscription(defaultSubscription);
    dataLakeStoreAccountManagementClient = new DataLakeStoreAccountManagementClientImpl(restClient).withSubscriptionId(defaultSubscription);
    storageManagementClient = StorageManager.authenticate(restClient, defaultSubscription);
    // create the resource group, ADLS account and ADLA account for job and catalog use.
    resourceManagementClient.resourceGroups().define(rgName).withRegion(environmentLocation).create();
    DataLakeStoreAccount createParams = new DataLakeStoreAccount();
    createParams.withLocation(environmentLocation.name());
    dataLakeStoreAccountManagementClient.accounts().create(rgName, adlsName, createParams);
    List<DataLakeStoreAccountInfo> adlsAccts = new ArrayList<DataLakeStoreAccountInfo>();
    DataLakeStoreAccountInfo adlsInfo = new DataLakeStoreAccountInfo();
    adlsInfo.withName(adlsName);
    adlsAccts.add(adlsInfo);
    DataLakeAnalyticsAccount adlaCreateParams = new DataLakeAnalyticsAccount();
    adlaCreateParams.withLocation(environmentLocation.name());
    adlaCreateParams.withDataLakeStoreAccounts(adlsAccts);
    adlaCreateParams.withDefaultDataLakeStoreAccount(adlsName);
    dataLakeAnalyticsAccountManagementClient.accounts().create(rgName, jobAndCatalogAdlaName, adlaCreateParams);
}
Also used : DataLakeStoreAccount(com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount) DataLakeAnalyticsJobManagementClientImpl(com.microsoft.azure.management.datalake.analytics.implementation.DataLakeAnalyticsJobManagementClientImpl) RestClient(com.microsoft.rest.RestClient) ArrayList(java.util.ArrayList) DataLakeStoreAccountManagementClientImpl(com.microsoft.azure.management.datalake.store.implementation.DataLakeStoreAccountManagementClientImpl) IOException(java.io.IOException) DataLakeAnalyticsAccountManagementClientImpl(com.microsoft.azure.management.datalake.analytics.implementation.DataLakeAnalyticsAccountManagementClientImpl) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) DataLakeAnalyticsCatalogManagementClientImpl(com.microsoft.azure.management.datalake.analytics.implementation.DataLakeAnalyticsCatalogManagementClientImpl) File(java.io.File) AzureTestCredentials(com.microsoft.azure.management.resources.core.AzureTestCredentials)

Example 15 with RestClient

use of com.microsoft.rest.RestClient in project autorest.java by Azure.

the class SubscriptionInCredentialsTests method setup.

@BeforeClass
public static void setup() {
    RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost:3000").withCredentials(new TokenCredentials(null, UUID.randomUUID().toString())).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new RequestIdHeaderInterceptor()).build();
    client = new AutoRestAzureSpecialParametersTestClientImpl(restClient);
    client.withSubscriptionId("1234-5678-9012-3456");
}
Also used : AutoRestAzureSpecialParametersTestClientImpl(fixtures.azurespecials.implementation.AutoRestAzureSpecialParametersTestClientImpl) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) RequestIdHeaderInterceptor(com.microsoft.rest.interceptors.RequestIdHeaderInterceptor) TokenCredentials(com.microsoft.rest.credentials.TokenCredentials) BeforeClass(org.junit.BeforeClass)

Aggregations

RestClient (com.microsoft.rest.RestClient)18 AzureJacksonAdapter (com.microsoft.azure.serializer.AzureJacksonAdapter)15 AzureResponseBuilder (com.microsoft.azure.AzureResponseBuilder)11 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)7 File (java.io.File)6 Azure (com.microsoft.azure.management.Azure)4 RequestIdHeaderInterceptor (com.microsoft.rest.interceptors.RequestIdHeaderInterceptor)4 BeforeClass (org.junit.BeforeClass)4 IOException (java.io.IOException)3 Response (okhttp3.Response)3 MappingBuilder (com.github.tomakehurst.wiremock.client.MappingBuilder)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 AzureEnvironment (com.microsoft.azure.AzureEnvironment)2 AzureTokenCredentials (com.microsoft.azure.credentials.AzureTokenCredentials)2 TokenCredentials (com.microsoft.rest.credentials.TokenCredentials)2 AutoRestAzureSpecialParametersTestClientImpl (fixtures.azurespecials.implementation.AutoRestAzureSpecialParametersTestClientImpl)2 Interceptor (okhttp3.Interceptor)2 Request (okhttp3.Request)2 Test (org.junit.Test)2 CacheBuilder (com.google.common.cache.CacheBuilder)1