Skip to content

Commit

Permalink
Merge pull request #3952 from arunans23/classloaderfix
Browse files Browse the repository at this point in the history
Improve connector dependency deployment
  • Loading branch information
arunans23 authored Feb 2, 2025
2 parents 1a655d2 + 69262f1 commit 0aaaebe
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static Artifact populateArtifact(OMElement artifactEle) {
artifact.setMainSequence(readAttribute(artifactEle, Artifact.MAIN_SEQUENCE));
artifact.setType(readAttribute(artifactEle, Artifact.TYPE));
artifact.setServerRole(readAttribute(artifactEle, Artifact.SERVER_ROLE));
artifact.setConnector(readAttribute(artifactEle, Artifact.CONNECTOR));

// read the dependencies
Iterator itr = artifactEle.getChildrenWithLocalName(Artifact.DEPENDENCY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,5 @@ public void setMainSequence(String mainSequence) {
this.mainSequence = mainSequence;
}

public ClassLoader getClassLoader() {
return classLoader;
}

public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Artifact {
public static final String ARTIFACT = "artifact";
public static final String DEPENDENCY = "dependency";
public static final String SERVER_ROLE = "serverRole";
public static final String CONNECTOR = "connector";

public static final String SUB_ARTIFACTS = "subArtifacts";
public static final String FILE = "file";
Expand All @@ -50,6 +51,7 @@ public class Artifact {
private String runtimeObjectName;
private String deploymentStatus;
private String mainSequence;
private String connector;

private List<Dependency> dependencies;
private List<Artifact> subArtifacts;
Expand Down Expand Up @@ -166,6 +168,14 @@ public void setMainSequence(String mainSequence) {
this.mainSequence = mainSequence;
}

public String getConnector() {
return connector;
}

public void setConnector(String connector) {
this.connector = connector;
}

public static class Dependency {
private String name;
private String version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DefaultAppDeployer implements AppDeploymentHandler {
public static final String DS_TYPE = "service/dataservice";
public static final String BUNDLE_TYPE = "bundle";
public static final String MEDIATOR_TYPE = "lib/synapse/mediator";
public static final String CONNECTOR_DEPENDENCY_TYPE = "lib/connector/dependency";

public static final String DS_DIR = "dataservices";

Expand Down Expand Up @@ -172,7 +173,9 @@ private void deployRecursively(List<Artifact.Dependency> deps, AxisConfiguration
artifact.setDeploymentStatus(org.wso2.micro.application.deployer.AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
throw e;
}
} else if (MEDIATOR_TYPE.equals(artifact.getType())) { // skip bundle installation for mediators
} else if (MEDIATOR_TYPE.equals(artifact.getType()) ||
CONNECTOR_DEPENDENCY_TYPE.equals(artifact.getType())) {
// skip bundle installation for mediators & connector dependencies
continue;
} else if ((artifact.getType().startsWith("lib/") || BUNDLE_TYPE.
equals(artifact.getType()))
Expand Down Expand Up @@ -236,7 +239,8 @@ private void undeployRecursively(List<Artifact.Dependency> deps,
artifact.setDeploymentStatus(org.wso2.micro.application.deployer.AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
log.error("Error while undeploying artifact : " + artifactPath, e);
}
} else if (MEDIATOR_TYPE.equals(artifact.getType())) {
} else if (MEDIATOR_TYPE.equals(artifact.getType()) ||
CONNECTOR_DEPENDENCY_TYPE.equals(artifact.getType())) {
continue;
} else if (artifact.getType() != null && (artifact.getType().startsWith("lib/") ||
BUNDLE_TYPE.equals(artifact.getType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.axis2.deployment.util.Utils;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -61,7 +60,6 @@
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.endpoints.Template;
import org.apache.synapse.inbound.InboundEndpoint;
import org.apache.synapse.libraries.LibClassLoader;
import org.apache.synapse.libraries.imports.SynapseImport;
import org.apache.synapse.libraries.model.Library;
import org.apache.synapse.libraries.util.LibDeployerUtils;
Expand Down Expand Up @@ -91,7 +89,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -132,12 +129,9 @@ public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisC
List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact()
.getDependencies();

if (carbonApp.getClassLoader() == null) {
carbonApp.setClassLoader(new LibClassLoader(new URL[0], Utils.getClassLoader
(LibDeployerUtils.class.getClassLoader(), carbonApp.getExtractedPath(), false)));
}
deployClassMediators(artifacts, axisConfig, carbonApp);
deploySynapseLibrary(artifacts, axisConfig, carbonApp);
deployClassMediators(artifacts, axisConfig);
deployConnectorDependencies(artifacts, axisConfig);
deploySynapseLibrary(artifacts, axisConfig);
Map<String, List<Artifact.Dependency>> artifactTypeMap = getOrderedArtifactsMap(artifacts);

//deploy artifacts
Expand Down Expand Up @@ -342,8 +336,8 @@ && handleMainFaultSeqUndeployment(artifact, axisConfig)) {
* @param axisConfig AxisConfiguration of the current tenant
* @throws DeploymentException if something goes wrong while deployment
*/
private void deployClassMediators(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig,
CarbonApplication carbonApplication) throws DeploymentException {
private void deployClassMediators(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig)
throws DeploymentException {
for (Artifact.Dependency dependency : artifacts) {

Artifact artifact = dependency.getArtifact();
Expand All @@ -361,9 +355,45 @@ private void deployClassMediators(List<Artifact.Dependency> artifacts, AxisConfi
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;

try {
DeploymentFileData deploymentFileData = new DeploymentFileData(new File(artifactPath), deployer);
deploymentFileData.setClassLoader(carbonApplication.getClassLoader());
deployer.deploy(deploymentFileData);
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
throw e;
}
}
}
}
}

/**
* Deploy the connector dependencies contains in the CApp
*
* @param artifacts List of Artifacts contains in the capp
* @param axisConfig AxisConfiguration of the current tenant
* @throws DeploymentException
*/
private void deployConnectorDependencies(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig)
throws DeploymentException {

for (Artifact.Dependency dependency : artifacts) {

Artifact artifact = dependency.getArtifact();
if (!validateArtifact(artifact)) {
continue;
}
if (SynapseAppDeployerConstants.CONNECTOR_DEPENDENCY_TYPE.equals(artifact.getType())) {
Deployer deployer = getSynapseLibraryDeployer(axisConfig);
if (deployer != null) {
artifact.setRuntimeObjectName(artifact.getName());
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;

try {
if (deployer instanceof LibraryArtifactDeployer) {
((LibraryArtifactDeployer) deployer).deployLibraryDependency(
new DeploymentFileData(new File(artifactPath), deployer), artifact.getConnector());
}
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
Expand All @@ -381,8 +411,8 @@ private void deployClassMediators(List<Artifact.Dependency> artifacts, AxisConfi
* @param axisConfig AxisConfiguration of the current tenant
* @throws DeploymentException if something goes wrong while deployment
*/
private void deploySynapseLibrary(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig,
CarbonApplication carbonApplication) throws DeploymentException {
private void deploySynapseLibrary(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig)
throws DeploymentException {
for (Artifact.Dependency dependency : artifacts) {

Artifact artifact = dependency.getArtifact();
Expand All @@ -406,9 +436,7 @@ private void deploySynapseLibrary(List<Artifact.Dependency> artifacts, AxisConfi
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} else {
try {
DeploymentFileData deploymentFileData = new DeploymentFileData(new File(artifactPath), deployer);
deploymentFileData.setClassLoader(carbonApplication.getClassLoader());
deployer.deploy(deploymentFileData);
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
try {
String artifactName = getArtifactName(artifactPath, axisConfig);
Expand Down Expand Up @@ -1133,9 +1161,7 @@ public void deployArtifactType(List<Artifact.Dependency> artifacts, CarbonApplic
} else {
try {
setCustomLogContent(deployer, carbonApp);
DeploymentFileData deploymentFileData = new DeploymentFileData(new File(artifactPath), deployer);
deploymentFileData.setClassLoader(carbonApp.getClassLoader());
deployer.deploy(deploymentFileData);
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SynapseAppDeployerConstants {
public static final String MESSAGE_STORE_TYPE = "synapse/message-store";
public static final String MESSAGE_PROCESSOR_TYPE="synapse/message-processors";
public static final String MEDIATOR_TYPE = "lib/synapse/mediator";
public static final String CONNECTOR_DEPENDENCY_TYPE = "lib/connector/dependency";
public static final String API_TYPE = "synapse/api";
public static final String TEMPLATE_TYPE = "synapse/template";
public static final String INBOUND_ENDPOINT_TYPE = "synapse/inbound-endpoint";
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@
<version.jaxb.api>2.4.0-b180830.0359</version.jaxb.api>
<com.sun.jaxb.version>2.3.0</com.sun.jaxb.version>
<com.sun.jaxb.impl.version>2.3.1</com.sun.jaxb.impl.version>
<synapse.version>4.0.0-wso2v198</synapse.version>
<synapse.version>4.0.0-wso2v200</synapse.version>
<imp.pkg.version.synapse>[4.0.0, 4.0.1)</imp.pkg.version.synapse>
<carbon.mediation.version>4.7.232</carbon.mediation.version>
<carbon.crypto.version>1.1.3</carbon.crypto.version>
Expand Down

0 comments on commit 0aaaebe

Please sign in to comment.