Search in sources :

Example 6 with DeploymentException

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

the class DefaultArtifactDeployer method undeploy.

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

Example 7 with DeploymentException

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

the class DomainBundleArchiveDeployer method deployArtifact.

/**
 * Deploys a domain bundle
 *
 * @param uri points to the domain bundle file to be deployed
 * @throws DeploymentException when the domain bundle was not successfully deployed
 */
public void deployArtifact(URI uri) throws DeploymentException {
    LOGGER.info("deploying artifact: " + uri);
    File bundleFile = new File(uri);
    final String bundleName = removeEndIgnoreCase(bundleFile.getName(), ZIP_FILE_SUFFIX);
    deploymentListener.onDeploymentStart(bundleName);
    File tempFolder = null;
    boolean isRedeploy = false;
    String domainName = null;
    try {
        tempFolder = unzipDomainBundle(bundleFile);
        File domainFile = getDomainFile(tempFolder);
        domainName = getBaseName(domainFile.getName());
        Domain domain = findDomain(domainName);
        isRedeploy = domain != null;
        Set<String> originalAppIds = new HashSet<>();
        if (isRedeploy) {
            domainDeploymentListener.onRedeploymentStart(domainName);
            Collection<Application> originalDomainApplications = deploymentService.findDomainApplications(domainName);
            for (Application domainApplication : originalDomainApplications) {
                if (domainApplication.getStatus() == ApplicationStatus.STARTED || domainApplication.getStatus() == ApplicationStatus.STOPPED) {
                    applicationDeploymentListener.onRedeploymentStart(domainApplication.getArtifactName());
                }
            }
            originalAppIds = originalDomainApplications.stream().map(a -> a.getArtifactName()).collect(toSet());
        }
        try {
            deployDomain(domainFile);
        } catch (Exception e) {
            // Ignore, deploy applications anyway
            LOGGER.warn("Domain bundle's domain was not deployed", e);
        }
        deployApplications(tempFolder, isRedeploy);
        if (isRedeploy) {
            Collection<Application> newDomainApplications = deploymentService.findDomainApplications(domainName);
            originalAppIds.stream().forEach(appId -> {
                Optional<Application> application = newDomainApplications.stream().filter(newApp -> appId.equals(newApp.getArtifactName())).findFirst();
                if (!application.isPresent()) {
                    DeploymentException cause = new DeploymentException(createStaticMessage("Application was not included in the updated domain bundle"));
                    applicationDeploymentListener.onDeploymentFailure(appId, cause);
                    applicationDeploymentListener.onRedeploymentFailure(appId, cause);
                }
            });
            domainDeploymentListener.onRedeploymentSuccess(domainName);
        }
        deploymentListener.onDeploymentSuccess(bundleName);
    } catch (Exception e) {
        if (isRedeploy) {
            domainDeploymentListener.onRedeploymentFailure(domainName, e);
        }
        deploymentListener.onDeploymentFailure(bundleName, e);
        if (e instanceof DeploymentException) {
            throw (DeploymentException) e;
        } else {
            throw new DeploymentException(createStaticMessage("Error deploying domain bundle"), e);
        }
    } finally {
        if (tempFolder != null) {
            deleteTree(tempFolder);
        }
    }
}
Also used : DeploymentService(org.mule.runtime.module.deployment.api.DeploymentService) ObservableList(org.mule.runtime.module.deployment.internal.util.ObservableList) Optional.empty(java.util.Optional.empty) ARTIFACT_NAME_PROPERTY(org.mule.runtime.module.deployment.internal.DefaultArchiveDeployer.ARTIFACT_NAME_PROPERTY) LoggerFactory(org.slf4j.LoggerFactory) ZIP_FILE_SUFFIX(org.mule.runtime.module.deployment.internal.DefaultArchiveDeployer.ZIP_FILE_SUFFIX) FileUtils.deleteTree(org.mule.runtime.core.api.util.FileUtils.deleteTree) HashSet(java.util.HashSet) FilenameUtils.getBaseName(org.apache.commons.io.FilenameUtils.getBaseName) FileUtils.unzip(org.mule.runtime.core.api.util.FileUtils.unzip) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) CollectionUtils.find(org.apache.commons.collections.CollectionUtils.find) Application(org.mule.runtime.deployment.model.api.application.Application) URI(java.net.URI) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Collection(java.util.Collection) Set(java.util.Set) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) IOException(java.io.IOException) JAR_FILE_SUFFIX(org.mule.runtime.module.deployment.internal.DefaultArchiveDeployer.JAR_FILE_SUFFIX) StringUtils.removeEndIgnoreCase(org.apache.commons.lang3.StringUtils.removeEndIgnoreCase) File(java.io.File) Domain(org.mule.runtime.deployment.model.api.domain.Domain) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) BeanPropertyValueEqualsPredicate(org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate) FileUtils(org.mule.runtime.core.api.util.FileUtils) Optional(java.util.Optional) ApplicationStatus(org.mule.runtime.deployment.model.api.application.ApplicationStatus) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) Domain(org.mule.runtime.deployment.model.api.domain.Domain) File(java.io.File) Application(org.mule.runtime.deployment.model.api.application.Application) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 8 with DeploymentException

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

the class DomainBundleArchiveDeployer method deployApplications.

private void deployApplications(File tempFolder, boolean isRedeploy) {
    File applicationsFolder = new File(tempFolder, "applications");
    if (!applicationsFolder.exists()) {
        throw new DeploymentException(createStaticMessage("Domain bundle does not contain an application folder"));
    }
    String[] applicationArtifacts = applicationsFolder.list(new SuffixFileFilter(JAR_FILE_SUFFIX));
    if (applicationArtifacts == null) {
        throw new DeploymentException(createStaticMessage("Domain bundle does not contain applications"));
    }
    Set<String> deployedApps = new HashSet<>();
    boolean applicationDeploymentError = false;
    for (String applicationArtifact : applicationArtifacts) {
        try {
            deployApplication(applicationsFolder, deployedApps, applicationArtifact, isRedeploy);
        } catch (Exception e) {
            applicationDeploymentError = true;
        }
    }
    if (applicationDeploymentError) {
        throw new DeploymentException(createStaticMessage("There was an error deploying the bundled applications"));
    }
}
Also used : DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) File(java.io.File) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 9 with DeploymentException

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

the class ToolingApplicationClassLoaderBuilder method build.

/**
 * Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
 * and filters so application classes, resources, plugins and it's domain resources are resolve correctly.
 *
 * @return a {@code MuleDeployableArtifactClassLoader} created from the provided configuration.
 * @throws IOException exception cause when it was not possible to access the file provided as dependencies
 */
public ToolingArtifactClassLoader build() throws IOException {
    ArtifactClassLoader ownerArtifactClassLoader = super.build();
    ClassLoader parent = ownerArtifactClassLoader.getClassLoader().getParent();
    if (!(parent instanceof RegionClassLoader)) {
        throw new DeploymentException(createStaticMessage(format("The parent of the current owner must be of type '%s' but found '%s'", RegionClassLoader.class.getName(), parent.getClass().getName())));
    }
    final RegionClassLoader regionClassLoader = (RegionClassLoader) parent;
    return new ToolingArtifactClassLoader(regionClassLoader, ownerArtifactClassLoader);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)

Example 10 with DeploymentException

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

the class ToolingDomainClassLoaderBuilder method build.

/**
 * Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
 * and filters so domain classes, resources and plugins are resolve correctly.
 *
 * @return a {@code MuleDeployableArtifactClassLoader} created from the provided configuration.
 * @throws IOException exception cause when it was not possible to access the file provided as dependencies
 */
public ToolingArtifactClassLoader build() throws IOException {
    ArtifactClassLoader domainClassLoader = super.build();
    ClassLoader parent = domainClassLoader.getClassLoader().getParent();
    if (!(parent instanceof RegionClassLoader)) {
        throw new DeploymentException(createStaticMessage(format("The parent of the current owner must be of type '%s' but found '%s'", RegionClassLoader.class.getName(), parent.getClass().getName())));
    }
    final RegionClassLoader regionClassLoader = (RegionClassLoader) parent;
    return new ToolingArtifactClassLoader(regionClassLoader, domainClassLoader);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)

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