This is an automated email from the ASF dual-hosted git repository. benyoka pushed a commit to branch branch-feature-AMBARI-14714 in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by this push: new c9a804d [AMBARI 24101] detailed error reporting for blueprint mpack download (benyoka) (#1543) c9a804d is described below commit c9a804d9617cc5f8f0e0308c19b348ec32486d78 Author: benyoka <beny...@users.noreply.github.com> AuthorDate: Fri Jun 15 22:39:33 2018 +0200 [AMBARI 24101] detailed error reporting for blueprint mpack download (benyoka) (#1543) * AMBARI-24101 more detailed error reporting in DownloadMpacksTask (benyoka) * AMBARI-24101 add mpack uri to the error message (benyoka) * AMBARI-24101 fix review comment (benyoka) --- .../ambari/server/topology/DownloadMpacksTask.java | 10 ++++++--- .../server/topology/DownloadMpacksTaskTest.java | 26 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java index 2216936..e267174 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.controller.internal.MpackResourceProvider; import org.apache.ambari.server.controller.spi.Request; import org.apache.ambari.server.controller.spi.RequestStatus; import org.apache.ambari.server.controller.utilities.PropertyHelper; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,9 +73,12 @@ public class DownloadMpacksTask { } } catch (Exception ex) { - throw ex instanceof RuntimeException ? - (RuntimeException)ex : - new RuntimeException("Error occured while registering mpack: " + mpack.getStackId(), ex); + List<Throwable> causes = ExceptionUtils.getThrowableList(ex); + Throwable rootCause = causes.get(causes.size() - 1); + throw new RuntimeException( + String.format("Error occured while registering mpack: %s (uri: %s). Caused by %s: %s", mpack.getStackId(), + mpack.getUrl(), rootCause.getClass().getName(), rootCause.getMessage(), + rootCause)); } } } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/DownloadMpacksTaskTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/DownloadMpacksTaskTest.java index bce2a1e..66c6e0f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/topology/DownloadMpacksTaskTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/DownloadMpacksTaskTest.java @@ -28,10 +28,12 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.mock; import static org.easymock.EasyMock.newCapture; import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.reset; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.net.UnknownHostException; import java.util.List; import java.util.Set; @@ -40,16 +42,22 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.controller.internal.MpackResourceProvider; import org.apache.ambari.server.controller.internal.RequestStatusImpl; import org.apache.ambari.server.controller.spi.Request; +import org.apache.ambari.server.controller.spi.SystemException; import org.apache.ambari.server.state.StackId; import org.easymock.Capture; import org.easymock.CaptureType; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import com.google.common.collect.ImmutableList; public class DownloadMpacksTaskTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private static final List<MpackInstance> INSTALLED_MPACKS = ImmutableList.of( mpack("HDPCORE", "1.0.0.0"), mpack("HDF", "3.1.1.0")); @@ -118,6 +126,24 @@ public class DownloadMpacksTaskTest { downloadMpacksTask.downloadMissingMpacks(ImmutableList.of(brokenMpack)); } + @Test + public void testDownloadMissingMpacks_errorReporting() throws Exception { + // then + expectedException.expect(RuntimeException.class); + expectedException.expectMessage( + "Error occured while registering mpack: EDW-1.0.0 (uri: http://mpacks.org/EDW.1.0.0). " + + "Caused by java.net.UnknownHostException: mpacks.org"); + + // given + reset(resourceProvider); + expect(resourceProvider.createResources(anyObject())) + .andThrow(new SystemException("", new UnknownHostException("mpacks.org"))); + replay(resourceProvider); + + // when + downloadMpacksTask.downloadMissingMpacks(MISSING_MPACKS.subList(0, 1)); + } + private String getUriFromRequest(Request request) { return (String)request.getProperties().iterator().next().get(MpackResourceProvider.MPACK_URI); -- To stop receiving notification emails like this one, please contact beny...@apache.org.