use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class MuleObjectStoreManager method initialise.
@Override
public void initialise() throws InitialisationException {
basePersistentStore = lookupBaseStore(basePersistentStoreKey, "Persistent");
baseTransientStore = lookupBaseStore(baseTransientStoreKey, "Transient");
try {
baseTransientPartition = getPartitionFromBaseObjectStore(baseTransientStore, baseTransientStoreKey);
basePersistentPartition = getPartitionFromBaseObjectStore(basePersistentStore, basePersistentStoreKey);
} catch (ObjectStoreException e) {
throw new InitialisationException(e, this);
}
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class ArtifactContextBuilder method build.
/**
* @return the {@code MuleContext} created with the provided configuration
* @throws ConfigurationException when there's a problem creating the {@code MuleContext}
* @throws InitialisationException when a certain configuration component failed during initialisation phase
*/
public ArtifactContext build() throws InitialisationException, ConfigurationException {
checkState(executionClassLoader != null, EXECUTION_CLASSLOADER_WAS_NOT_SET);
checkState(classLoaderRepository != null, CLASS_LOADER_REPOSITORY_WAS_NOT_SET);
checkState(POLICY.equals(artifactType) || APP.equals(artifactType) || parentArtifact == null, ONLY_APPLICATIONS_OR_POLICIES_ARE_ALLOWED_TO_HAVE_A_PARENT_ARTIFACT);
try {
return withContextClassLoader(executionClassLoader, () -> {
List<ConfigurationBuilder> builders = new LinkedList<>();
builders.addAll(additionalBuilders);
builders.add(new ArtifactBootstrapServiceDiscovererConfigurationBuilder(artifactPlugins));
if (extensionManagerFactory == null) {
if (parentArtifact == null) {
extensionManagerFactory = new ArtifactExtensionManagerFactory(artifactPlugins, extensionModelLoaderRepository, new DefaultExtensionManagerFactory());
} else {
extensionManagerFactory = new CompositeArtifactExtensionManagerFactory(parentArtifact, extensionModelLoaderRepository, artifactPlugins, new DefaultExtensionManagerFactory());
}
}
builders.add(new ArtifactExtensionManagerConfigurationBuilder(artifactPlugins, extensionManagerFactory));
builders.add(createConfigurationBuilderFromApplicationProperties());
// TODO MULE-14289 (elrodro83) pass this object to the builder instead of looking it up here
ArtifactConfigurationProcessor artifactConfigurationProcessor = ArtifactConfigurationProcessor.discover();
AtomicReference<ArtifactContext> artifactContext = new AtomicReference<>();
builders.add(new ConfigurationBuilder() {
@Override
public void configure(MuleContext muleContext) throws ConfigurationException {
if (serviceRepository != null) {
serviceConfigurators.add(new ContainerServicesMuleContextConfigurator(serviceRepository));
}
if (classLoaderRepository != null) {
serviceConfigurators.add(customizationService -> customizationService.registerCustomServiceImpl(OBJECT_CLASSLOADER_REPOSITORY, classLoaderRepository));
}
if (policyProvider != null) {
serviceConfigurators.add(customizationService -> customizationService.registerCustomServiceImpl(OBJECT_POLICY_PROVIDER, policyProvider));
}
ArtifactContextConfiguration.ArtifactContextConfigurationBuilder artifactContextConfigurationBuilder = ArtifactContextConfiguration.builder().setMuleContext(muleContext).setConfigResources(configurationFiles).setArtifactDeclaration(artifactDeclaration).setArtifactProperties(merge(artifactProperties, muleContext.getDeploymentProperties())).setArtifactType(artifactType).setEnableLazyInitialization(enableLazyInit).setDisableXmlValidations(disableXmlValidations).setServiceConfigurators(serviceConfigurators);
if (parentArtifact != null) {
artifactContextConfigurationBuilder.setParentContext(parentArtifact.getRegistry().lookupByType(MuleContext.class).get());
}
artifactContext.set(artifactConfigurationProcessor.createArtifactContext(artifactContextConfigurationBuilder.build()));
((DefaultMuleConfiguration) muleContext.getConfiguration()).setDataFolderName(dataFolderName);
}
@Override
public void addServiceConfigurator(ServiceConfigurator serviceConfigurator) {
// Nothing to do
}
});
DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
if (muleContextListener != null) {
muleContextFactory.addListener(muleContextListener);
}
if (APP.equals(artifactType)) {
muleContextBuilder = new ApplicationMuleContextBuilder(artifactName, artifactProperties, defaultEncoding);
} else if (POLICY.equals(artifactType)) {
muleContextBuilder = new PolicyMuleContextBuilder(artifactName, artifactProperties, defaultEncoding);
} else {
muleContextBuilder = new DomainMuleContextBuilder(artifactName);
}
muleContextBuilder.setExecutionClassLoader(this.executionClassLoader);
ArtifactObjectSerializer objectSerializer = new ArtifactObjectSerializer(classLoaderRepository);
muleContextBuilder.setObjectSerializer(objectSerializer);
muleContextBuilder.setDeploymentProperties(properties);
if (parentArtifact != null) {
builders.add(new ConnectionManagerConfigurationBuilder(parentArtifact));
muleContextBuilder.setErrorTypeRepository(createCompositeErrorTypeRepository(parentArtifact.getRegistry().lookupByType(MuleContext.class).get().getErrorTypeRepository()));
} else {
builders.add(new ConnectionManagerConfigurationBuilder());
}
try {
muleContextFactory.createMuleContext(builders, muleContextBuilder);
return artifactContext.get();
} catch (InitialisationException e) {
throw new ConfigurationException(e);
}
});
} catch (MuleRuntimeException e) {
// We need this exception to be thrown as they are since the are possible causes of connectivity errors
if (e.getCause() instanceof InitialisationException) {
throw (InitialisationException) e.getCause();
}
if (e.getCause() instanceof ConfigurationException) {
throw (ConfigurationException) e.getCause();
}
throw e;
}
}
use of org.mule.runtime.api.lifecycle.InitialisationException 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);
}
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class ConfigOverrideValueResolverWrapper method initialise.
@Override
public void initialise() throws InitialisationException {
try {
muleContext.getInjector().inject(delegate);
initialiseIfNeeded(delegate, muleContext);
} catch (MuleException e) {
throw new InitialisationException(createStaticMessage("Failed to initialise the delegate ValueResolver for ConfigOverride wrapper"), e, this);
}
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class ApplicationModel method getConfigurationPropertiesProvidersFromComponents.
private List<ConfigurationPropertiesProvider> getConfigurationPropertiesProvidersFromComponents(ArtifactConfig artifactConfig, ConfigurationPropertiesResolver localResolver) {
Map<ComponentIdentifier, ConfigurationPropertiesProviderFactory> providerFactoriesMap = new HashMap<>();
ServiceLoader<ConfigurationPropertiesProviderFactory> providerFactories = java.util.ServiceLoader.load(ConfigurationPropertiesProviderFactory.class);
providerFactories.forEach(service -> {
ComponentIdentifier componentIdentifier = service.getSupportedComponentIdentifier();
if (providerFactoriesMap.containsKey(componentIdentifier)) {
throw new MuleRuntimeException(createStaticMessage("Multiple configuration providers for component: " + componentIdentifier));
}
providerFactoriesMap.put(componentIdentifier, service);
});
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = new ArrayList<>();
artifactConfig.getConfigFiles().stream().forEach(configFile -> configFile.getConfigLines().stream().forEach(configLine -> {
for (ConfigLine componentConfigLine : configLine.getChildren()) {
if (componentConfigLine.getNamespace() == null) {
continue;
}
ComponentIdentifier componentIdentifier = ComponentIdentifier.builder().namespace(componentConfigLine.getNamespace()).name(componentConfigLine.getIdentifier()).build();
if (!providerFactoriesMap.containsKey(componentIdentifier)) {
continue;
}
DefaultConfigurationParameters.Builder configurationParametersBuilder = DefaultConfigurationParameters.builder();
ConfigurationParameters configurationParameters = resolveConfigurationParameters(configurationParametersBuilder, componentConfigLine, localResolver);
ConfigurationPropertiesProvider provider = providerFactoriesMap.get(componentIdentifier).createProvider(configurationParameters, externalResourceProvider);
if (provider instanceof Component) {
Component providerComponent = (Component) provider;
TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(UNKNOWN).identifier(componentIdentifier).build();
DefaultComponentLocation.DefaultLocationPart locationPart = new DefaultComponentLocation.DefaultLocationPart(componentIdentifier.getName(), of(typedComponentIdentifier), of(configFile.getFilename()), of(configLine.getLineNumber()));
providerComponent.setAnnotations(ImmutableMap.<QName, Object>builder().put(AbstractComponent.LOCATION_KEY, new DefaultComponentLocation(of(componentIdentifier.getName()), singletonList(locationPart))).build());
}
configConfigurationPropertiesProviders.add(provider);
try {
initialiseIfNeeded(provider);
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
}
}));
return configConfigurationPropertiesProviders;
}
Aggregations