Search in sources :

Example 1 with DeploymentInitException

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

the class ArtifactArchiveInstaller method installArtifact.

/**
 * Installs an artifact in the mule container.
 *
 * Created the artifact directory and the anchor file related.
 *
 * @param artifactUri URI of the artifact to install. It must be present in the artifact directory as a zip file.
 * @return the location of the installed artifact.
 * @throws IOException in case there was an error reading from the artifact or writing to the artifact folder.
 */
public File installArtifact(final URI artifactUri) throws IOException {
    if (!artifactUri.toString().toLowerCase().endsWith(JAR_FILE_SUFFIX)) {
        throw new IllegalArgumentException("Invalid Mule artifact archive: " + artifactUri);
    }
    final File artifactFile = new File(artifactUri);
    final String baseName = getBaseName(artifactFile.getName());
    if (baseName.contains(" ")) {
        throw new DeploymentInitException(I18nMessageFactory.createStaticMessage("Mule artifact name may not contain spaces: " + baseName));
    }
    File artifactDir = null;
    boolean errorEncountered = false;
    String artifactName;
    try {
        final String fullPath = artifactFile.getAbsolutePath();
        if (logger.isInfoEnabled()) {
            logger.info("Exploding a Mule artifact archive: " + fullPath);
        }
        artifactName = getBaseName(fullPath);
        artifactDir = new File(artifactParentDir, artifactName);
        // Removes previous deployed artifact
        if (artifactDir.exists() && !deleteTree(artifactDir)) {
            throw new IOException("Cannot delete existing folder " + artifactDir);
        }
        // normalize the full path + protocol to make unzip happy
        final File source = artifactFile;
        FileUtils.unzip(source, artifactDir);
        if ("file".equals(artifactUri.getScheme()) && toFile(artifactUri.toURL()).getAbsolutePath().startsWith(artifactParentDir.getAbsolutePath())) {
            deleteQuietly(source);
        }
    } catch (IOException e) {
        errorEncountered = true;
        throw e;
    } catch (Throwable t) {
        errorEncountered = true;
        final String msg = "Failed to install artifact from URI: " + artifactUri;
        throw new DeploymentInitException(I18nMessageFactory.createStaticMessage(msg), t);
    } finally {
        // delete an artifact dir, as it's broken
        if (errorEncountered && artifactDir != null && artifactDir.exists()) {
            deleteTree(artifactDir);
        }
    }
    return artifactDir;
}
Also used : IOException(java.io.IOException) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException)

Example 2 with DeploymentInitException

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

the class DefaultMuleDomain method doInit.

public void doInit(boolean lazy, boolean disableXmlValidations) throws DeploymentInitException {
    withContextClassLoader(null, () -> {
        if (logger.isInfoEnabled()) {
            logger.info(miniSplash(format("Initializing domain '%s'", getArtifactName())));
        }
    });
    try {
        ArtifactContextBuilder artifactBuilder = getArtifactContextBuilder().setArtifactName(getArtifactName()).setDataFolderName(getDescriptor().getDataFolderName()).setArtifactPlugins(artifactPlugins).setExecutionClassloader(deploymentClassLoader.getClassLoader()).setArtifactInstallationDirectory(getArtifactInstallationDirectory()).setExtensionModelLoaderRepository(extensionModelLoaderManager).setArtifactType(DOMAIN).setEnableLazyInit(lazy).setDisableXmlValidations(disableXmlValidations).setClassLoaderRepository(classLoaderRepository).setProperties(ofNullable(resolveDeploymentProperties(descriptor.getDataFolderName(), descriptor.getDeploymentProperties()))).setServiceRepository(serviceRepository);
        if (!descriptor.getConfigResources().isEmpty()) {
            validateConfigurationFileDoNotUsesCoreNamespace();
            artifactBuilder.setConfigurationFiles(descriptor.getConfigResources().toArray(new String[descriptor.getConfigResources().size()]));
        }
        if (muleContextListener != null) {
            artifactBuilder.setMuleContextListener(muleContextListener);
        }
        artifactContext = artifactBuilder.build();
    } catch (Exception e) {
        // log it here so it ends up in app log, sys log will only log a message without stacktrace
        logger.error(null, getRootCause(e));
        throw new DeploymentInitException(createStaticMessage(getRootCauseMessage(e)), e);
    }
}
Also used : ArtifactContextBuilder(org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) FileNotFoundException(java.io.FileNotFoundException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException) DeploymentStopException(org.mule.runtime.deployment.model.api.DeploymentStopException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException)

Example 3 with DeploymentInitException

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

the class DefaultMuleApplication method doInit.

private void doInit(boolean lazy, boolean disableXmlValidations) {
    withContextClassLoader(null, () -> {
        if (logger.isInfoEnabled()) {
            logger.info(miniSplash(format("Initializing app '%s'", descriptor.getName())));
        }
    });
    try {
        ArtifactContextBuilder artifactBuilder = newBuilder().setArtifactProperties(merge(descriptor.getAppProperties(), getProperties())).setArtifactType(APP).setDataFolderName(descriptor.getDataFolderName()).setArtifactName(descriptor.getName()).setArtifactInstallationDirectory(descriptor.getArtifactLocation()).setConfigurationFiles(descriptor.getConfigResources().toArray(new String[descriptor.getConfigResources().size()])).setDefaultEncoding(descriptor.getEncoding()).setArtifactPlugins(artifactPlugins).setExecutionClassloader(deploymentClassLoader.getClassLoader()).setEnableLazyInit(lazy).setDisableXmlValidations(disableXmlValidations).setServiceRepository(serviceRepository).setExtensionModelLoaderRepository(extensionModelLoaderRepository).setClassLoaderRepository(classLoaderRepository).setArtifactDeclaration(descriptor.getArtifactDeclaration()).setProperties(ofNullable(resolveDeploymentProperties(descriptor.getDataFolderName(), descriptor.getDeploymentProperties()))).setPolicyProvider(policyManager);
        Domain domain = domainRepository.getDomain(descriptor.getDomainName());
        if (domain.getRegistry() != null) {
            artifactBuilder.setParentArtifact(domain);
        }
        if (muleContextListener != null) {
            artifactBuilder.setMuleContextListener(muleContextListener);
        }
        artifactContext = artifactBuilder.build();
        setMuleContext(artifactContext.getMuleContext(), artifactContext.getRegistry());
    } catch (Exception e) {
        setStatusToFailed();
        // log it here so it ends up in app log, sys log will only log a message without stacktrace
        logger.error(null, getRootCause(e));
        throw new DeploymentInitException(createStaticMessage(getRootCauseMessage(e)), e);
    }
}
Also used : ArtifactContextBuilder(org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder) Domain(org.mule.runtime.deployment.model.api.domain.Domain) InstallException(org.mule.runtime.deployment.model.api.InstallException) DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) DeploymentStopException(org.mule.runtime.deployment.model.api.DeploymentStopException) MuleException(org.mule.runtime.api.exception.MuleException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException)

Aggregations

DeploymentInitException (org.mule.runtime.deployment.model.api.DeploymentInitException)3 MuleException (org.mule.runtime.api.exception.MuleException)2 DeploymentStartException (org.mule.runtime.deployment.model.api.DeploymentStartException)2 DeploymentStopException (org.mule.runtime.deployment.model.api.DeploymentStopException)2 ArtifactContextBuilder (org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 FileUtils.toFile (org.apache.commons.io.FileUtils.toFile)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 InstallException (org.mule.runtime.deployment.model.api.InstallException)1 Domain (org.mule.runtime.deployment.model.api.domain.Domain)1