Search in sources :

Example 1 with ArtifactContextBuilder

use of org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder 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 2 with ArtifactContextBuilder

use of org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder 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)

Example 3 with ArtifactContextBuilder

use of org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder in project mule by mulesoft.

the class DefaultApplicationPolicyInstance method initPolicyContext.

private void initPolicyContext() throws InitialisationException {
    ArtifactContextBuilder artifactBuilder = newBuilder().setArtifactType(POLICY).setArtifactProperties(new HashMap<>(parametrization.getParameters())).setArtifactName(parametrization.getId()).setConfigurationFiles(parametrization.getConfig().getAbsolutePath()).setExecutionClassloader(template.getArtifactClassLoader().getClassLoader()).setServiceRepository(serviceRepository).setClassLoaderRepository(classLoaderRepository).setArtifactPlugins(artifactPlugins).setParentArtifact(application).setExtensionManagerFactory(new CompositeArtifactExtensionManagerFactory(application, extensionModelLoaderRepository, artifactPlugins, new DefaultExtensionManagerFactory())).setMuleContextListener(muleContextListener);
    artifactBuilder.withServiceConfigurator(customizationService -> {
        Registry applicationRegistry = application.getRegistry();
        /*
       * OBJECT_POLICY_MANAGER_STATE_HANDLER is not proxied as it doesn't implement any lifecycle interfaces (Startable, Stoppable
       * or Disposable)
       */
        customizationService.overrideDefaultServiceImpl(OBJECT_POLICY_MANAGER_STATE_HANDLER, applicationRegistry.lookupByName(OBJECT_POLICY_MANAGER_STATE_HANDLER).get());
        customizationService.overrideDefaultServiceImpl(OBJECT_LOCK_PROVIDER, createLifecycleFilterProxy(applicationRegistry.lookupByName(OBJECT_LOCK_PROVIDER).get()));
        customizationService.overrideDefaultServiceImpl(BASE_PERSISTENT_OBJECT_STORE_KEY, createLifecycleFilterProxy(applicationRegistry.lookupByName(BASE_PERSISTENT_OBJECT_STORE_KEY).get()));
        customizationService.overrideDefaultServiceImpl(BASE_IN_MEMORY_OBJECT_STORE_KEY, createLifecycleFilterProxy(applicationRegistry.lookupByName(BASE_IN_MEMORY_OBJECT_STORE_KEY).get()));
        customizationService.overrideDefaultServiceImpl(OBJECT_TIME_SUPPLIER, createLifecycleFilterProxy(applicationRegistry.lookupByName(OBJECT_TIME_SUPPLIER).get()));
        applicationRegistry.lookupByName(CLUSTER_MANAGER_ID).ifPresent(muleClusterManager -> customizationService.registerCustomServiceImpl(CLUSTER_MANAGER_ID, createLifecycleFilterProxy(muleClusterManager)));
    });
    try {
        policyContext = artifactBuilder.build();
        enableNotificationListeners(parametrization.getNotificationListeners());
        policyContext.getMuleContext().start();
    } catch (MuleException e) {
        throw new InitialisationException(createStaticMessage("Cannot create artifact context for the policy instance"), e, this);
    }
}
Also used : ArtifactContextBuilder(org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder) CompositeArtifactExtensionManagerFactory(org.mule.runtime.module.deployment.impl.internal.artifact.CompositeArtifactExtensionManagerFactory) HashMap(java.util.HashMap) DefaultExtensionManagerFactory(org.mule.runtime.module.extension.api.manager.DefaultExtensionManagerFactory) Registry(org.mule.runtime.api.artifact.Registry) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)3 ArtifactContextBuilder (org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 DeploymentInitException (org.mule.runtime.deployment.model.api.DeploymentInitException)2 DeploymentStartException (org.mule.runtime.deployment.model.api.DeploymentStartException)2 DeploymentStopException (org.mule.runtime.deployment.model.api.DeploymentStopException)2 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 Registry (org.mule.runtime.api.artifact.Registry)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 NotificationListenerRegistry (org.mule.runtime.api.notification.NotificationListenerRegistry)1 InstallException (org.mule.runtime.deployment.model.api.InstallException)1 Domain (org.mule.runtime.deployment.model.api.domain.Domain)1 CompositeArtifactExtensionManagerFactory (org.mule.runtime.module.deployment.impl.internal.artifact.CompositeArtifactExtensionManagerFactory)1 DefaultExtensionManagerFactory (org.mule.runtime.module.extension.api.manager.DefaultExtensionManagerFactory)1