Search in sources :

Example 1 with DeploymentException

use of org.mule.runtime.deployment.model.api.DeploymentException in project mule by mulesoft.

the class DefaultMuleDeployerTestCase method disposesAppOnDeployFailure.

@Test
public void disposesAppOnDeployFailure() throws Exception {
    DefaultArtifactDeployer deployer = new DefaultArtifactDeployer();
    Application app = mock(Application.class);
    doThrow(new IllegalStateException()).when(app).init();
    try {
        deployer.deploy(app);
        fail("Deployment is supposed to fail");
    } catch (DeploymentException expected) {
    }
    verify(app, times(1)).dispose();
}
Also used : DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) Application(org.mule.runtime.deployment.model.api.application.Application) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with DeploymentException

use of org.mule.runtime.deployment.model.api.DeploymentException in project mule by mulesoft.

the class ArtifactArchiveInstaller method uninstallArtifact.

/**
 * Uninstalls an artifact from the Mule container installation.
 *
 * It will remove the artifact folder and the anchor file related
 *
 * @param artifactName name of the artifact to be uninstalled.
 */
void uninstallArtifact(final String artifactName) {
    try {
        final File artifactDir = new File(artifactParentDir, artifactName);
        deleteDirectory(artifactDir);
        // remove a marker, harmless, but a tidy artifact dir is always better :)
        File marker = getArtifactAnchorFile(artifactName);
        marker.delete();
        Introspector.flushCaches();
    } catch (Throwable t) {
        if (t instanceof DeploymentException) {
            throw ((DeploymentException) t);
        }
        final String msg = String.format("Failed to undeployArtifact artifact [%s]", artifactName);
        throw new DeploymentException(I18nMessageFactory.createStaticMessage(msg), t);
    }
}
Also used : DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile)

Example 3 with DeploymentException

use of org.mule.runtime.deployment.model.api.DeploymentException in project mule by mulesoft.

the class DefaultArchiveDeployer method deployExplodedApp.

private T deployExplodedApp(String addedApp, Optional<Properties> deploymentProperties) throws DeploymentException {
    if (logger.isInfoEnabled()) {
        logger.info("================== New Exploded Artifact: " + addedApp);
    }
    T artifact;
    try {
        File artifactLocation = new File(artifactDir, addedApp);
        artifact = createArtifact(artifactLocation, deploymentProperties);
        // add to the list of known artifacts first to avoid deployment loop on failure
        trackArtifact(artifact);
    } catch (Throwable t) {
        final File artifactDir1 = artifactDir;
        File artifactDir = new File(artifactDir1, addedApp);
        addZombieFile(addedApp, artifactDir);
        if (containsType(t, DeploymentStartException.class)) {
            logger.error(miniSplash(format("Failed to deploy artifact '%s', see artifact's log for details", addedApp)));
            logger.error(t.getMessage());
        } else {
            logger.error(miniSplash(format("Failed to deploy artifact '%s', see below", addedApp)), t);
        }
        deploymentListener.onDeploymentFailure(addedApp, t);
        if (t instanceof DeploymentException) {
            throw (DeploymentException) t;
        } else {
            throw new DeploymentException(createStaticMessage("Failed to deploy artifact: " + addedApp), t);
        }
    }
    deployArtifact(artifact, deploymentProperties);
    return artifact;
}
Also used : DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) File(java.io.File)

Example 4 with DeploymentException

use of org.mule.runtime.deployment.model.api.DeploymentException in project mule by mulesoft.

the class DefaultArchiveDeployer method deployPackagedArtifact.

@Override
public T deployPackagedArtifact(URI artifactAchivedUri, Optional<Properties> appProperties) throws DeploymentException {
    Optional<T> foundMatchingArtifact = empty();
    try {
        File artifactLocation = installArtifact(artifactAchivedUri);
        T artifact;
        try {
            artifact = createArtifact(artifactLocation, appProperties);
            trackArtifact(artifact);
        } catch (Throwable t) {
            String artifactName = artifactLocation.getName();
            // error text has been created by the deployer already
            logDeploymentFailure(t, artifactName);
            foundMatchingArtifact.ifPresent(a -> deploymentListener.onRedeploymentFailure(a.getArtifactName(), t));
            addZombieFile(artifactName, artifactLocation);
            deploymentListener.onDeploymentFailure(artifactName, t);
            throw t;
        }
        deployArtifact(artifact, appProperties);
        foundMatchingArtifact.ifPresent(a -> deploymentListener.onRedeploymentSuccess(a.getArtifactName()));
        return artifact;
    } catch (Throwable t) {
        foundMatchingArtifact.ifPresent(a -> deploymentListener.onRedeploymentFailure(a.getArtifactName(), t));
        if (t instanceof DeploymentException) {
            // re-throw
            throw ((DeploymentException) t);
        }
        final String msg = "Failed to deploy from URI: " + artifactAchivedUri;
        throw new DeploymentException(createStaticMessage(msg), t);
    }
}
Also used : ObservableList(org.mule.runtime.module.deployment.internal.util.ObservableList) Optional.empty(java.util.Optional.empty) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileUtils.deleteDirectory(org.apache.commons.io.FileUtils.deleteDirectory) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ExceptionUtils.containsType(org.mule.runtime.core.api.util.ExceptionUtils.containsType) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) CollectionUtils.find(org.apache.commons.collections.CollectionUtils.find) URI(java.net.URI) MuleContextListenerFactory(org.mule.runtime.module.deployment.impl.internal.artifact.MuleContextListenerFactory) Properties(java.util.Properties) Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) Collection(java.util.Collection) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) IOException(java.io.IOException) CollectionUtils.collect(org.apache.commons.collections.CollectionUtils.collect) StringUtils.removeEndIgnoreCase(org.apache.commons.lang3.StringUtils.removeEndIgnoreCase) String.format(java.lang.String.format) File(java.io.File) MuleFoldersUtil.getAppDataFolder(org.mule.runtime.container.api.MuleFoldersUtil.getAppDataFolder) DeploymentPropertiesUtils.resolveDeploymentProperties(org.mule.runtime.module.deployment.impl.internal.util.DeploymentPropertiesUtils.resolveDeploymentProperties) AbstractDeployableArtifactFactory(org.mule.runtime.module.deployment.impl.internal.artifact.AbstractDeployableArtifactFactory) DeployableArtifact(org.mule.runtime.deployment.model.api.DeployableArtifact) List(java.util.List) BeanPropertyValueEqualsPredicate(org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate) Optional(java.util.Optional) ArtifactFactory(org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactFactory) SplashScreen.miniSplash(org.mule.runtime.core.internal.util.splash.SplashScreen.miniSplash) BeanToPropertyValueTransformer(org.apache.commons.beanutils.BeanToPropertyValueTransformer) Arrays.stream(java.util.Arrays.stream) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) File(java.io.File)

Example 5 with DeploymentException

use of org.mule.runtime.deployment.model.api.DeploymentException in project mule by mulesoft.

the class DefaultArtifactDeployer method deploy.

public void deploy(T artifact) {
    try {
        artifact.install();
        doInit(artifact);
        artifact.start();
    } catch (Throwable t) {
        artifact.dispose();
        if (t instanceof DeploymentException) {
            throw ((DeploymentException) t);
        }
        final String msg = String.format("Failed to deploy artifact [%s]", artifact.getArtifactName());
        throw new DeploymentException(I18nMessageFactory.createStaticMessage(msg), t);
    }
}
Also used : DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException)

Aggregations

DeploymentException (org.mule.runtime.deployment.model.api.DeploymentException)14 File (java.io.File)6 IOException (java.io.IOException)4 DeploymentStartException (org.mule.runtime.deployment.model.api.DeploymentStartException)4 URI (java.net.URI)3 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)3 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Optional.empty (java.util.Optional.empty)2 BeanPropertyValueEqualsPredicate (org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate)2 CollectionUtils.find (org.apache.commons.collections.CollectionUtils.find)2 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)2 StringUtils.removeEndIgnoreCase (org.apache.commons.lang3.StringUtils.removeEndIgnoreCase)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2 Application (org.mule.runtime.deployment.model.api.application.Application)2 DeploymentListener (org.mule.runtime.module.deployment.api.DeploymentListener)2 ObservableList (org.mule.runtime.module.deployment.internal.util.ObservableList)2 Logger (org.slf4j.Logger)2