Search in sources :

Example 16 with Application

use of org.mule.runtime.deployment.model.api.application.Application 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 17 with Application

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

the class DomainDeploymentTemplate method postRedeploy.

/**
 * Deploys applications that were undeployed when {@link #preRedeploy(Artifact)} was called..
 */
@Override
public void postRedeploy(Artifact domain) {
    if (domain != null && !domainApplications.isEmpty()) {
        RuntimeException firstException = null;
        for (Application domainApplication : domainApplications) {
            applicationDeployer.preTrackArtifact(domainApplication);
            if (applicationDeployer.isUpdatedZombieArtifact(domainApplication.getArtifactName())) {
                try {
                    applicationDeployer.deployExplodedArtifact(domainApplication.getArtifactName(), empty());
                    applicationDeploymentListener.onRedeploymentSuccess(domainApplication.getArtifactName());
                } catch (RuntimeException e) {
                    applicationDeploymentListener.onRedeploymentFailure(domainApplication.getArtifactName(), e);
                    if (firstException == null) {
                        firstException = e;
                    }
                }
            }
        }
        if (firstException != null) {
            throw firstException;
        }
    }
    domainApplications = Collections.emptyList();
}
Also used : Application(org.mule.runtime.deployment.model.api.application.Application)

Example 18 with Application

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

the class DomainDeploymentTemplate method preRedeploy.

/**
 * Undeploys all applications that use this domain.
 */
@Override
public void preRedeploy(Artifact domain) {
    if (domain instanceof Domain) {
        domainApplications = deploymentservice.findDomainApplications(domain.getArtifactName());
        for (Application domainApplication : domainApplications) {
            applicationDeploymentListener.onRedeploymentStart(domainApplication.getArtifactName());
            applicationDeployer.undeployArtifactWithoutUninstall(domainApplication);
        }
    }
}
Also used : Domain(org.mule.runtime.deployment.model.api.domain.Domain) Application(org.mule.runtime.deployment.model.api.application.Application)

Example 19 with Application

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

the class StartupSummaryDeploymentListener method onAfterStartup.

public void onAfterStartup() {
    if (!logger.isInfoEnabled()) {
        return;
    }
    Multimap<String, String> applicationsPerDomain = LinkedListMultimap.create();
    Map<String, ArtifactDeploymentStatusTracker.DeploymentState> domainDeploymentState = tracker.getDomainDeploymentStatusTracker().getDeploymentStates();
    SimpleLoggingTable domainTable = new SimpleLoggingTable();
    domainTable.addColumn(DOMAIN_OWNER_LABEL, ARTIFACT_NAME_LABEL_LENGTH);
    domainTable.addColumn(STATUS_LABEL, STATUS_LABEL_LENGTH);
    for (String domain : domainDeploymentState.keySet()) {
        String[] data = new String[] { domain, domainDeploymentState.get(domain).toString() };
        domainTable.addDataRow(data);
    }
    Map<String, ArtifactDeploymentStatusTracker.DeploymentState> applicationStates = tracker.getApplicationDeploymentStatusTracker().getDeploymentStates();
    for (String applicationName : applicationStates.keySet()) {
        Application application = deploymentService.findApplication(applicationName);
        String domainName = UNKNOWN_ARTIFACT_NAME;
        if (application != null) {
            domainName = application.getDomain().getArtifactName();
        }
        applicationsPerDomain.put(domainName, applicationName);
    }
    String message;
    if (!applicationsPerDomain.isEmpty()) {
        SimpleLoggingTable applicationTable = new SimpleLoggingTable();
        applicationTable.addColumn(APPLICATION_LABEL, ARTIFACT_NAME_LABEL_LENGTH);
        applicationTable.addColumn(DOMAIN_OWNER_LABEL, DOMAIN_OWNER_LABEL_LENGTH);
        applicationTable.addColumn(STATUS_LABEL, STATUS_LABEL_LENGTH);
        for (String domainName : applicationsPerDomain.keySet()) {
            for (String app : applicationsPerDomain.get(domainName)) {
                String[] data = new String[] { app, domainName, applicationStates.get(app).toString() };
                applicationTable.addDataRow(data);
            }
        }
        message = String.format("%n%s%n%s", domainTable, applicationTable);
    } else {
        message = String.format("%n%s", domainTable);
    }
    logger.info(message);
}
Also used : SimpleLoggingTable(org.mule.runtime.core.internal.util.splash.SimpleLoggingTable) Application(org.mule.runtime.deployment.model.api.application.Application)

Example 20 with Application

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

the class DefaultToolingService method doCreateApplication.

private Application doCreateApplication(ApplicationDescriptor applicationDescriptor) throws IOException {
    Application application = applicationFactory.createArtifact(applicationDescriptor);
    application.install();
    application.lazyInit();
    application.start();
    return application;
}
Also used : Application(org.mule.runtime.deployment.model.api.application.Application)

Aggregations

Application (org.mule.runtime.deployment.model.api.application.Application)35 Test (org.junit.Test)19 File (java.io.File)7 Domain (org.mule.runtime.deployment.model.api.domain.Domain)6 ApplicationFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IOException (java.io.IOException)4 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)4 PolicyParametrization (org.mule.runtime.core.api.policy.PolicyParametrization)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)3 PolicyRegistrationException (org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)3 DeploymentListener (org.mule.runtime.module.deployment.api.DeploymentListener)3 URI (java.net.URI)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)2