Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 1772676: Azure Toolkit for IntelliJ/Eclipse - Docker Run/Run on Web App for Containers ... Throws javax.ws.rs.ProcessingException #4595

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static com.microsoft.azuretools.telemetry.TelemetryConstants.DEPLOY_WEBAPP_DOCKERLOCAL;
import static com.microsoft.azuretools.telemetry.TelemetryConstants.WEBAPP;

import com.microsoft.azure.common.exceptions.AzureExecutionException;
import com.microsoft.azuretools.telemetrywrapper.ErrorType;
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
import com.microsoft.azuretools.telemetrywrapper.Operation;
Expand All @@ -42,8 +41,6 @@
import java.util.HashMap;
import java.util.Map;

import com.microsoft.tooling.msservices.components.DefaultLoader;
import com.spotify.docker.client.exceptions.DockerException;
import org.apache.commons.io.FilenameUtils;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
Expand Down Expand Up @@ -107,7 +104,6 @@ public class DockerRunDialog extends AzureTitleAreaDialogWrapper {
private static final String IMAGE_NAME_PREFIX = "localimage";
private static final String DEFAULT_TAG_NAME = "latest";
private static final String SELECT_DOCKER_FILE = "Browse...";
private static final String DOCKER_PING_ERROR = "Failed to connect docker host: %s\nIs Docker installed and running?";

private DockerHostRunSetting dataModel;
private Text txtDockerHost;
Expand Down Expand Up @@ -349,13 +345,7 @@ private void execute() {
ConsoleLogger.info(String.format("Building image ... [%s]", imageNameWithTag));
DockerClient docker = DockerUtil.getDockerClient(dataModel.getDockerHost(), dataModel.isTlsEnabled(),
dataModel.getDockerCertPath());
try {
docker.ping();
} catch (DockerException | InterruptedException e) {
final String msg = String.format(DOCKER_PING_ERROR, dataModel.getDockerHost());
DefaultLoader.getUIHelper().showError(msg, "Failed to connect docker host");
throw new AzureExecutionException(String.format("Failed to connect docker host: %s", dataModel.getDockerHost()));
}
DockerUtil.ping(docker);
DockerUtil.buildImage(docker, imageNameWithTag, targetDockerfile.getParent(),
targetDockerfile.getFileName().toString(), new DockerProgressHandler());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ private void execute() {
PrivateRegistryImageSetting acrInfo = model.getPrivateRegistryImageSetting();
ConsoleLogger.info(String.format("Building image ... [%s]", acrInfo.getImageTagWithServerUrl()));
DockerClient docker = DefaultDockerClient.fromEnv().build();

DockerUtil.ping(docker);
DockerUtil.buildImage(docker, acrInfo.getImageTagWithServerUrl(), targetDockerfile.getParent(),
targetDockerfile.getFileName().toString(), new DockerProgressHandler());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ private void execute() {
PrivateRegistryImageSetting acrInfo = model.getPrivateRegistryImageSetting();
ConsoleLogger.info(String.format("Building image ... [%s]", acrInfo.getImageTagWithServerUrl()));
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.ping(docker);
DockerUtil.buildImage(docker, acrInfo.getImageTagWithServerUrl(), targetDockerfile.getParent(),
targetDockerfile.getFileName().toString(), new DockerProgressHandler());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import java.util.Map;
import java.util.Optional;

import com.microsoft.azure.common.exceptions.AzureExecutionException;
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
import com.microsoft.azuretools.azurecommons.util.Utils;
import com.microsoft.azuretools.container.Constant;
import com.microsoft.tooling.msservices.components.DefaultLoader;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerCertificates;
import com.spotify.docker.client.DockerClient;
Expand All @@ -51,6 +53,8 @@
import com.spotify.docker.client.messages.RegistryAuth;

public class DockerUtil {
private static final String DOCKER_PING_ERROR = "Failed to connect docker host: %s\nIs Docker installed and running?";

/**
* create a docker file in specified folder.
*/
Expand Down Expand Up @@ -186,4 +190,14 @@ public static String getDefaultDockerFilePathIfExist(String basePath) {
}
return "";
}

public static void ping(DockerClient docker) throws AzureExecutionException {
try {
docker.ping();
} catch (DockerException | InterruptedException e) {
final String msg = String.format(DOCKER_PING_ERROR, docker.getHost());
DefaultLoader.getUIHelper().showError(msg, "Failed to connect docker host");
throw new AzureExecutionException(String.format("Failed to connect docker host: %s", docker.getHost()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.microsoft.azure.common.exceptions.AzureExecutionException;
import com.microsoft.azuretools.core.mvp.model.container.pojo.DockerHostRunSetting;
import com.microsoft.azuretools.telemetrywrapper.Operation;
import com.microsoft.azuretools.telemetrywrapper.TelemetryManager;
Expand All @@ -40,9 +39,7 @@
import com.microsoft.intellij.runner.container.utils.DockerProgressHandler;
import com.microsoft.intellij.runner.container.utils.DockerUtil;
import com.microsoft.intellij.util.MavenRunTaskUtil;
import com.microsoft.tooling.msservices.components.DefaultLoader;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.Container;

import com.spotify.docker.client.shaded.com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -134,13 +131,7 @@ public void onTextAvailable(ProcessEvent processEvent, Key key) {
dataModel.isTlsEnabled(),
dataModel.getDockerCertPath()
);
try {
docker.ping();
} catch (DockerException | InterruptedException e) {
final String msg = String.format(DOCKER_PING_ERROR, dataModel.getDockerHost());
DefaultLoader.getUIHelper().showError(msg, "Failed to connect docker host");
throw new AzureExecutionException(String.format("Failed to connect docker host: %s", dataModel.getDockerHost()));
}
DockerUtil.ping(docker);
DockerUtil.buildImage(docker,
imageNameWithTag,
targetDockerfile.getParent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public String executeSteps(@NotNull RunProcessHandler processHandler,
PrivateRegistryImageSetting acrInfo = dataModel.getPrivateRegistryImageSetting();
processHandler.setText(String.format("Building image ... [%s]", acrInfo.getImageTagWithServerUrl()));
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.ping(docker);
String image = DockerUtil.buildImage(docker,
acrInfo.getImageTagWithServerUrl(),
targetDockerfile.getParent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

package com.microsoft.intellij.runner.container.utils;

import com.microsoft.azure.common.exceptions.AzureExecutionException;
import com.microsoft.azuretools.azurecommons.util.Utils;
import com.microsoft.tooling.msservices.components.DefaultLoader;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerCertificates;
import com.spotify.docker.client.DockerClient;
Expand Down Expand Up @@ -50,6 +52,8 @@


public class DockerUtil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why there are two same DockerUtil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are for eclipse/intellij separately.
they should be merged and shared. there are many other such kind of duplicate classes in eclipse/intellij.
we can refactor in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

private static final String DOCKER_PING_ERROR = "Failed to connect docker host: %s\nIs Docker installed and running?";

/**
* create a docker file in specified folder.
*/
Expand Down Expand Up @@ -177,14 +181,25 @@ public static DockerClient getDockerClient(String dockerHost, boolean tlsEnabled
* Else return an empty String.
*/
public static String getDefaultDockerFilePathIfExist(String basePath) {
try{
try {
if (!Utils.isEmptyString(basePath)) {
Path targetDockerfile = Paths.get(basePath, Constant.DOCKERFILE_NAME);
if (targetDockerfile != null && targetDockerfile.toFile().exists()) {
return targetDockerfile.toString();
}
}
} catch (RuntimeException ignored) {}
} catch (RuntimeException ignored) {
}
return "";
}

public static void ping(DockerClient docker) throws AzureExecutionException {
try {
docker.ping();
} catch (DockerException | InterruptedException e) {
final String msg = String.format(DOCKER_PING_ERROR, docker.getHost());
DefaultLoader.getUIHelper().showError(msg, "Failed to connect docker host");
throw new AzureExecutionException(String.format("Failed to connect docker host: %s", docker.getHost()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public WebApp executeSteps(@NotNull RunProcessHandler processHandler,
processHandler.setText(String.format("Building image ... [%s]",
acrInfo.getImageTagWithServerUrl()));
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.ping(docker);
DockerUtil.buildImage(docker,
acrInfo.getImageTagWithServerUrl(),
targetDockerfile.getParent(),
Expand Down Expand Up @@ -144,7 +145,7 @@ protected void onSuccess(WebApp result, @NotNull RunProcessHandler processHandle
processHandler.setText("Job done");
processHandler.notifyComplete();
if (deployModel.isCreatingNewWebAppOnLinux() && AzureUIRefreshCore.listeners != null) {
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH,null));
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
}
}

Expand Down