Search in sources :

Example 1 with InsightsManager

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager in project azure-tools-for-java by Microsoft.

the class AzureSDKManager method createInsightsResource.

public static ApplicationInsightsComponent createInsightsResource(@NotNull String subscriptionId, @NotNull String resourceGroupName, @NotNull String resourceName, @NotNull String location) throws IOException {
    final InsightsManager insightsManager = getInsightsManagerClient(subscriptionId);
    if (insightsManager == null) {
        // not signed in
        return null;
    }
    final Azure azure = AuthMethodManager.getInstance().getAzureClient(subscriptionId);
    if (!azure.resourceGroups().contain(resourceGroupName)) {
        azure.resourceGroups().define(resourceGroupName).withRegion(location).create();
    }
    return insightsManager.components().define(resourceName).withRegion(location).withExistingResourceGroup(resourceGroupName).withApplicationType(ApplicationType.WEB).withKind("web").create();
}
Also used : Azure(com.microsoft.azure.management.Azure) InsightsManager(com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager)

Example 2 with InsightsManager

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager in project azure-tools-for-java by Microsoft.

the class AzureSDKManager method getOrCreateApplicationInsights.

// SDK will return existing application insights component when you create new one with existing name
// Use this method in case SDK service update their behavior
public static ApplicationInsightsComponent getOrCreateApplicationInsights(@NotNull String subscriptionId, @NotNull String resourceGroupName, @NotNull String resourceName, @NotNull String location) throws IOException {
    final InsightsManager insightsManager = getInsightsManagerClient(subscriptionId);
    if (insightsManager == null) {
        return null;
    }
    ApplicationInsightsComponent component = null;
    try {
        component = insightsManager.components().getByResourceGroup(resourceGroupName, resourceName);
    } catch (Exception e) {
    // SDK will throw exception when resource not found
    }
    return component != null ? component : createInsightsResource(subscriptionId, resourceGroupName, resourceName, location);
}
Also used : ApplicationInsightsComponent(com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent) InsightsManager(com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

Example 3 with InsightsManager

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager in project azure-tools-for-java by Microsoft.

the class AzureManagerBase method authApplicationInsights.

protected InsightsManager authApplicationInsights(String subscriptionId, String tenantId) {
    final AzureTokenCredentials credentials = getCredentials(tenantId);
    final InsightsManager.Configurable configurable = buildAzureManager(InsightsManager.configure()).withInterceptor(new TelemetryInterceptor());
    Optional.ofNullable(createProxyFromConfig()).ifPresent(proxy -> {
        configurable.withProxy(proxy);
        Optional.ofNullable(createProxyAuthenticatorFromConfig()).ifPresent(configurable::withProxyAuthenticator);
    });
    return configurable.authenticate(credentials, subscriptionId);
}
Also used : InsightsManager(com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager) TelemetryInterceptor(com.microsoft.azuretools.telemetry.TelemetryInterceptor) AzureTokenCredentials(com.microsoft.azure.credentials.AzureTokenCredentials)

Aggregations

InsightsManager (com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager)3 JsonParseException (com.google.gson.JsonParseException)1 AzureTokenCredentials (com.microsoft.azure.credentials.AzureTokenCredentials)1 Azure (com.microsoft.azure.management.Azure)1 ApplicationInsightsComponent (com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent)1 TelemetryInterceptor (com.microsoft.azuretools.telemetry.TelemetryInterceptor)1 IOException (java.io.IOException)1