Search in sources :

Example 61 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class WebAppRunState method executeSteps.

@Nullable
@Override
@AzureOperation(name = "webapp.deploy_artifact", params = { "this.webAppConfiguration.getWebAppName()" }, type = AzureOperation.Type.ACTION)
public IAppService executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
    File file = new File(getTargetPath());
    if (!file.exists()) {
        throw new FileNotFoundException(message("webapp.deploy.error.noTargetFile", file.getAbsolutePath()));
    }
    webAppConfiguration.setTargetName(file.getName());
    final IWebAppBase deployTarget = getOrCreateDeployTargetFromAppSettingModel(processHandler);
    updateApplicationSettings(deployTarget, processHandler);
    AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(deployTarget, file, webAppSettingModel.isDeployToRoot(), processHandler);
    return deployTarget;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IWebAppBase(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppBase) File(java.io.File) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class AzureWebAppMvpModel method updateWebAppOnDocker.

/**
 * Update container settings for existing Web App on Linux.
 *
 * @param webAppId     id of Web App on Linux instance
 * @param imageSetting new container settings
 * @return instance of the updated Web App on Linux
 */
@AzureOperation(name = "docker|image.update", params = { "nameFromResourceId(webAppId)", "imageSetting.getImageNameWithTag()" }, type = AzureOperation.Type.SERVICE)
public IWebApp updateWebAppOnDocker(String webAppId, ImageSetting imageSetting) {
    final IWebApp app = com.microsoft.azure.toolkit.lib.Azure.az(AzureAppService.class).webapp(webAppId);
    // clearTags(app);
    if (imageSetting instanceof PrivateRegistryImageSetting) {
        final PrivateRegistryImageSetting pr = (PrivateRegistryImageSetting) imageSetting;
        final DockerConfiguration dockerConfiguration = DockerConfiguration.builder().image(pr.getImageTagWithServerUrl()).registryUrl(pr.getServerUrl()).userName(pr.getUsername()).password(pr.getPassword()).startUpCommand(pr.getStartupFile()).build();
        app.update().withDockerConfiguration(dockerConfiguration).commit();
    }
    // status-free restart.
    app.restart();
    return app;
}
Also used : DockerConfiguration(com.microsoft.azure.toolkit.lib.appservice.model.DockerConfiguration) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 63 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class AzureManagerBase method getSubscriptionsWithTenant.

@Override
@AzureOperation(name = "account|subscription.list.tenant|authorized", type = AzureOperation.Type.SERVICE)
public List<Pair<Subscription, Tenant>> getSubscriptionsWithTenant() {
    final List<Pair<Subscription, Tenant>> subscriptions = new LinkedList<>();
    final Azure.Authenticated authentication = authTenant(getCurrentTenantId());
    // could be multi tenant - return all subscriptions for the current account
    final List<Tenant> tenants = getTenants(authentication);
    final List<String> failedTenantIds = new ArrayList<>();
    for (final Tenant tenant : tenants) {
        try {
            final Azure.Authenticated tenantAuthentication = authTenant(tenant.tenantId());
            final List<Subscription> tenantSubscriptions = getSubscriptions(tenantAuthentication);
            for (final Subscription subscription : tenantSubscriptions) {
                subscriptions.add(new Pair<>(subscription, tenant));
            }
        } catch (final Exception e) {
            // just skip for cases user failing to get subscriptions of tenants he/she has no permission to get access token.
            LOGGER.log(Level.WARNING, e.getMessage(), e);
            failedTenantIds.add(tenant.tenantId());
        }
    }
    if (!failedTenantIds.isEmpty()) {
        final INotification nw = CommonSettings.getUiFactory().getNotificationWindow();
        nw.deliver("Lack permission for some tenants", "You don't have permission on the tenant(s): " + StringUtils.join(failedTenantIds, ","));
    }
    return subscriptions;
}
Also used : Azure(com.microsoft.azure.management.Azure) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Tenant(com.microsoft.azure.management.resources.Tenant) INotification(com.microsoft.azuretools.authmanage.interact.INotification) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Pair(com.microsoft.azuretools.utils.Pair) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 64 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class AzureManagerBase method authTenant.

@AzureOperation(name = "account|tenant.auth", params = { "tenantId" }, type = AzureOperation.Type.TASK)
protected Azure.Authenticated authTenant(String tenantId) {
    final AzureTokenCredentials credentials = getCredentials(tenantId);
    final Azure.Configurable configurable = Azure.configure().withInterceptor(new TelemetryInterceptor()).withUserAgent(CommonSettings.USER_AGENT);
    Optional.ofNullable(createProxyFromConfig()).ifPresent(proxy -> {
        configurable.withProxy(proxy);
        Optional.ofNullable(createProxyAuthenticatorFromConfig()).ifPresent(configurable::withProxyAuthenticator);
    });
    return configurable.authenticate(credentials);
}
Also used : Azure(com.microsoft.azure.management.Azure) TelemetryInterceptor(com.microsoft.azuretools.telemetry.TelemetryInterceptor) AzureTokenCredentials(com.microsoft.azure.credentials.AzureTokenCredentials) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)64 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)11 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)11 IOException (java.io.IOException)10 Project (com.intellij.openapi.project.Project)9 ArrayList (java.util.ArrayList)9 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)8 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)6 Path (java.nio.file.Path)6 Module (com.intellij.openapi.module.Module)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)5 Azure (com.microsoft.azure.management.Azure)4 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)4 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)4 Action (com.microsoft.azure.toolkit.lib.common.action.Action)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)3 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)3