use of org.mule.runtime.deployment.model.api.domain.Domain 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);
}
}
}
use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.
the class DomainBundleArchiveDeployer method deployDomain.
private void deployDomain(File domainFile) throws IOException {
String domainName = getBaseName(domainFile.getName());
Domain domain = findDomain(domainName);
if (domain != null) {
domainDeployer.undeployArtifact(domainName);
unzip(domainFile, domain.getLocation());
}
domainDeployer.deployPackagedArtifact(domainFile.toURI(), empty());
}
use of org.mule.runtime.deployment.model.api.domain.Domain 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);
}
}
}
use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.
the class DefaultDomainFactoryTestCase method createDefaultDomain.
@Test
public void createDefaultDomain() throws IOException {
final MuleApplicationClassLoader domainArtifactClassLoader = mock(MuleApplicationClassLoader.class);
when(domainArtifactClassLoader.getArtifactId()).thenReturn(DEFAULT_DOMAIN_NAME);
DomainClassLoaderBuilder domainClassLoaderBuilderMock = mock(DomainClassLoaderBuilder.class);
when(domainClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.setArtifactId(any())).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.addArtifactPluginDescriptors(new ArtifactPluginDescriptor[0])).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.build()).thenReturn(domainArtifactClassLoader);
when(domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(domainClassLoaderBuilderMock);
Domain domain = domainFactory.createArtifact(new File(DEFAULT_DOMAIN_NAME), empty());
assertThat(domain.getArtifactName(), is(DEFAULT_DOMAIN_NAME));
assertThat(domain.getDescriptor(), instanceOf(EmptyDomainDescriptor.class));
assertThat(domain.getArtifactClassLoader(), is(domainArtifactClassLoader));
}
use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.
the class DefaultApplicationFactoryTestCase method createDomain.
private Domain createDomain(String name) {
final Domain domain = mock(Domain.class);
final ArtifactClassLoader domainArtifactClassLoader = mock(ArtifactClassLoader.class);
when(domainArtifactClassLoader.getClassLoader()).thenReturn(mock(ClassLoader.class));
final ClassLoaderLookupPolicy domainLookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(domainArtifactClassLoader.getClassLoaderLookupPolicy()).thenReturn(domainLookupPolicy);
when(domainRepository.getDomain(DOMAIN_ARTIFACT_FILE_NAME)).thenReturn(domain);
when(domain.getArtifactClassLoader()).thenReturn(domainArtifactClassLoader);
when(domain.getDescriptor()).thenReturn(new DomainDescriptor(name));
return domain;
}
Aggregations