Unverified Commit a2174b59 authored by TAO Xinxiu (Isabelle)'s avatar TAO Xinxiu (Isabelle) Committed by GitHub
Browse files

Use XSLT to update job descriptor schema version to latest (#3973)

parent 4e8a23b1
......@@ -55,6 +55,7 @@ dependencies {
runtime 'org.hsqldb:hsqldb:2.5.1'
runtime 'net.sf.saxon:Saxon-HE:10.5'
runtime "org.objectweb.proactive:programming-extension-pnp:${programmingVersion}"
runtime "org.objectweb.proactive:programming-extension-pnpssl:${programmingVersion}"
......
......@@ -59,8 +59,7 @@ import static org.ow2.proactive.scheduler.core.SchedulerFrontendState.YOU_DO_NOT
import static org.ow2.proactive.scheduler.core.SchedulerFrontendState.YOU_DO_NOT_HAVE_PERMISSION_TO_STOP_THE_SCHEDULER;
import static org.ow2.proactive.scheduler.core.SchedulerFrontendState.YOU_DO_NOT_HAVE_PERMISSION_TO_SUBMIT_A_JOB;
import java.io.IOException;
import java.io.Serializable;
import java.io.*;
import java.net.URI;
import java.nio.charset.Charset;
import java.security.KeyException;
......@@ -73,6 +72,9 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.security.auth.Subject;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -244,6 +246,13 @@ public class SchedulerFrontend implements InitActive, Scheduler, RunActive, EndA
private static final TaskId SIGNAL_TASK_ID = TaskIdImpl.makeTaskId(SIGNAL_TASK);
/**
* Attributes used for XSLT transformation of updating job descriptor schema version
*/
private static final String xslFilePath = "stylesheet/schemas.xsl";
private static final String saxonFactoryClassName = "net.sf.saxon.TransformerFactoryImpl";
/*
* ######################################################################### ##################
*/
......@@ -1913,7 +1922,38 @@ public class SchedulerFrontend implements InitActive, Scheduler, RunActive, EndA
frontendState.checkPermissions("getJobContent",
frontendState.getIdentifiedJob(jobId),
YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THIS_JOB);
return dbManager.loadInitalJobContent(jobId);
return updateJobSchemaVersionToLatest(dbManager.loadInitalJobContent(jobId));
}
/**
* Use XSLT to change the schema version of the job descriptor to the latest.
* Specifically, it's to change "xmlns" and "xsi:schemaLocation" to the "dev" version.
* This function is used to fix the potential problem of schema version mismatch between global variables and job descriptor.
* Since the schema change is backward compatible, updating the job to the latest version will fix the version mismatch problem.
*
* @param jobContent the String content of job descriptor (in xml)
* @return the updated String content of job descriptor (in xml) which is changed to the latest version
*/
private String updateJobSchemaVersionToLatest(String jobContent) {
try {
StreamSource xslSource = new StreamSource(this.getClass()
.getClassLoader()
.getResourceAsStream(xslFilePath));
StreamSource xmlInput = new StreamSource(new StringReader(jobContent));
StringWriter xmlOutput = new StringWriter();
Result result = new StreamResult(xmlOutput);
TransformerFactory factory = TransformerFactory.newInstance(saxonFactoryClassName, null);
Transformer transformer = factory.newTransformer(xslSource);
transformer.transform(xmlInput, result);
return xmlOutput.toString();
} catch (Exception e) {
logger.warn("Error during transforming the job descriptor schema to the latest version, it's kept unchanged.",
e);
return jobContent;
}
}
@Override
......
......@@ -141,6 +141,8 @@ public class SchedulerStarter {
public static final String REST_DISABLED_PROPERTY = "pa.scheduler.rest.disabled";
public static final String DEFAULT_XML_TRANSFORMER = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
private static final int DEFAULT_NODES_TIMEOUT = 120 * 1000;
private static final int DISCOVERY_DEFAULT_PORT = 64739;
......@@ -167,6 +169,7 @@ public class SchedulerStarter {
configureSecurityManager();
configureLogging();
configureDerby();
configureXMLTransformer();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
......@@ -745,6 +748,11 @@ public class SchedulerStarter {
setPropIfNotAlreadySet("derby.locks.deadlockTimeout", "1");
}
protected static void configureXMLTransformer() {
System.setProperty(CentralPAPropertyRepository.JAVAX_XML_TRANSFORM_TRANSFORMERFACTORY.getName(),
DEFAULT_XML_TRANSFORMER);
}
protected static boolean setPropIfNotAlreadySet(String name, Object value) {
boolean notSet = System.getProperty(name) == null;
if (notSet)
......
......@@ -73,6 +73,8 @@ public class JettyStarter {
public static final String HTTPS_CONNECTOR_NAME = "https";
public static final String DEFAULT_XML_TRANSFORMER = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
private static final Logger logger = Logger.getLogger(JettyStarter.class);
/**
......@@ -91,6 +93,8 @@ public class JettyStarter {
setSystemPropertyIfNotDefined("rm.url", rmUrl);
setSystemPropertyIfNotDefined("scheduler.url", schedulerUrl);
System.setProperty(CentralPAPropertyRepository.JAVAX_XML_TRANSFORM_TRANSFORMERFACTORY.getName(),
DEFAULT_XML_TRANSFORMER);
if (WebProperties.WEB_DEPLOY.getValueAsBoolean()) {
logger.info("Starting the web applications...");
......
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="urn:proactive:jobdescriptor:dev"
xmlns:dev="urn:proactive:jobdescriptor:dev"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="dev" >
<xsl:output standalone="no" method="xml" cdata-section-elements="dev:description dev:code dev:visualization"/>
<xsl:variable name ="nsdev">urn:proactive:jobdescriptor:dev</xsl:variable>
<xsl:template match="@* | comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template match="*" >
<xsl:element name="{local-name()}" namespace="{$nsdev}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="{name()}" namespace="{$nsdev}">
<xsl:copy-of select="namespace::*[name()]"/>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="xsi:schemaLocation">
<xsl:value-of select="'urn:proactive:jobdescriptor:dev http://www.activeeon.com/public_content/schemas/proactive/jobdescriptor/dev/schedulerjob.xsd'"/>
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment