http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-usagerecord/src/main/java/org/ogf/usage/JobUsageRecord.java ---------------------------------------------------------------------- diff --git a/taverna-server-usagerecord/src/main/java/org/ogf/usage/JobUsageRecord.java b/taverna-server-usagerecord/src/main/java/org/ogf/usage/JobUsageRecord.java new file mode 100644 index 0000000..d12d3d8 --- /dev/null +++ b/taverna-server-usagerecord/src/main/java/org/ogf/usage/JobUsageRecord.java @@ -0,0 +1,304 @@ +/* + * Copyright (C) 2011 The University of Manchester + * + * See the file "LICENSE" for license terms. + */ +package org.ogf.usage; + +import static java.util.UUID.randomUUID; + +import java.io.StringReader; +import java.io.StringWriter; +import java.math.BigInteger; +import java.util.Date; +import java.util.GregorianCalendar; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.transform.dom.DOMSource; + +import org.ogf.usage.v1_0.Charge; +import org.ogf.usage.v1_0.ConsumableResourceType; +import org.ogf.usage.v1_0.CpuDuration; +import org.ogf.usage.v1_0.Disk; +import org.ogf.usage.v1_0.EndTime; +import org.ogf.usage.v1_0.Host; +import org.ogf.usage.v1_0.JobName; +import org.ogf.usage.v1_0.MachineName; +import org.ogf.usage.v1_0.Memory; +import org.ogf.usage.v1_0.Network; +import org.ogf.usage.v1_0.NodeCount; +import org.ogf.usage.v1_0.Processors; +import org.ogf.usage.v1_0.ProjectName; +import org.ogf.usage.v1_0.Queue; +import org.ogf.usage.v1_0.RecordIdentity; +import org.ogf.usage.v1_0.ResourceType; +import org.ogf.usage.v1_0.ServiceLevel; +import org.ogf.usage.v1_0.StartTime; +import org.ogf.usage.v1_0.Status; +import org.ogf.usage.v1_0.SubmitHost; +import org.ogf.usage.v1_0.Swap; +import org.ogf.usage.v1_0.TimeDuration; +import org.ogf.usage.v1_0.TimeInstant; +import org.ogf.usage.v1_0.UserIdentity; +import org.ogf.usage.v1_0.WallDuration; +import org.w3c.dom.Element; + +@XmlRootElement(name = "UsageRecord", namespace = "http://schema.ogf.org/urf/2003/09/urf") +public class JobUsageRecord extends org.ogf.usage.v1_0.UsageRecordType { + /** + * Create a new usage record with a random UUID as its identity. + * + * @throws DatatypeConfigurationException + * If the factory for XML-relevant datatypes fails to build; not + * expected. + */ + public JobUsageRecord() throws DatatypeConfigurationException { + datatypeFactory = DatatypeFactory.newInstance(); + RecordIdentity recid = new RecordIdentity(); + recid.setRecordId(randomUUID().toString()); + recid.setCreateTime(datatypeFactory + .newXMLGregorianCalendar(new GregorianCalendar())); + setRecordIdentity(recid); + } + + /** + * Create a new usage record with a random UUID as its identity. + * + * @param name + * The name of the job to which this record pertains. + * @throws DatatypeConfigurationException + * If the factory for XML-relevant datatypes fails to build; not + * expected. + */ + public JobUsageRecord(String name) throws DatatypeConfigurationException { + this(); + setJobName(name); + } + + @XmlTransient + private DatatypeFactory datatypeFactory; + + public Status setStatus(String status) { + Status s = new Status(); + s.setValue(status); + setStatus(s); + return s; + } + + public WallDuration addWallDuration(long millis) { + WallDuration wall = new WallDuration(); + wall.setValue(datatypeFactory.newDuration(millis)); + getWallDurationOrCpuDurationOrNodeCount().add(wall); + return wall; + } + + public CpuDuration addCpuDuration(long millis) { + CpuDuration cpu = new CpuDuration(); + cpu.setValue(datatypeFactory.newDuration(millis)); + getWallDurationOrCpuDurationOrNodeCount().add(cpu); + return cpu; + } + + public NodeCount addNodeCount(int nodes) { + NodeCount nc = new NodeCount(); + nc.setValue(BigInteger.valueOf(nodes)); + getWallDurationOrCpuDurationOrNodeCount().add(nc); + return nc; + } + + public Processors addProcessors(int processors) { + Processors pc = new Processors(); + pc.setValue(BigInteger.valueOf(processors)); + getWallDurationOrCpuDurationOrNodeCount().add(pc); + return pc; + } + + public SubmitHost addSubmitHost(String host) { + SubmitHost sh = new SubmitHost(); + sh.setValue(host); + getWallDurationOrCpuDurationOrNodeCount().add(sh); + return sh; + } + + public Host addHost(String host) { + Host h = new Host(); + h.setValue(host); + getWallDurationOrCpuDurationOrNodeCount().add(h); + return h; + } + + public MachineName addMachine(String host) { + MachineName machine = new MachineName(); + machine.setValue(host); + getWallDurationOrCpuDurationOrNodeCount().add(machine); + return machine; + } + + public ProjectName addProject(String project) { + ProjectName p = new ProjectName(); + p.setValue(project); + getWallDurationOrCpuDurationOrNodeCount().add(p); + return p; + } + + public void addStartAndEnd(Date start, Date end) { + GregorianCalendar gc; + + gc = new GregorianCalendar(); + gc.setTime(start); + StartTime st = new StartTime(); + st.setValue(datatypeFactory.newXMLGregorianCalendar(gc)); + getWallDurationOrCpuDurationOrNodeCount().add(st); + + gc = new GregorianCalendar(); + gc.setTime(end); + EndTime et = new EndTime(); + et.setValue(datatypeFactory.newXMLGregorianCalendar(gc)); + getWallDurationOrCpuDurationOrNodeCount().add(et); + } + + public Queue addQueue(String queue) { + Queue q = new Queue(); + q.setValue(queue); + getWallDurationOrCpuDurationOrNodeCount().add(q); + return q; + } + + public void addResource(ConsumableResourceType consumable) { + getWallDurationOrCpuDurationOrNodeCount().add(consumable); + } + + public ResourceType addResource(ResourceType resource) { + getWallDurationOrCpuDurationOrNodeCount().add(resource); + return resource; + } + + public ResourceType addResource(String description, String value) { + ResourceType resource = new ResourceType(); + resource.setDescription(description); + resource.setValue(value); + getWallDurationOrCpuDurationOrNodeCount().add(resource); + return resource; + } + + public ServiceLevel addServiceLevel(String service) { + ServiceLevel sl = new ServiceLevel(); + sl.setValue(service); + getDiskOrMemoryOrSwap().add(sl); + return sl; + } + + public Memory addMemory(long memory) { + Memory mem = new Memory(); + mem.setValue(BigInteger.valueOf(memory)); + getDiskOrMemoryOrSwap().add(mem); + return mem; + } + + public TimeInstant addTimestamp(Date timestamp, String type) { + TimeInstant instant = new TimeInstant(); + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(timestamp); + instant.setValue(datatypeFactory.newXMLGregorianCalendar(gc)); + instant.setType(type); + getDiskOrMemoryOrSwap().add(instant); + return instant; + } + + public TimeDuration addDuration(long millis, String type) { + TimeDuration duration = new TimeDuration(); + duration.setValue(datatypeFactory.newDuration(millis)); + duration.setType(type); + getDiskOrMemoryOrSwap().add(duration); + return duration; + } + + public Network addNetwork(long value) { + Network net = new Network(); + net.setValue(BigInteger.valueOf(value)); + getDiskOrMemoryOrSwap().add(net); + return net; + } + + public Disk addDisk(long value) { + Disk disk = new Disk(); + disk.setValue(BigInteger.valueOf(value)); + getDiskOrMemoryOrSwap().add(disk); + return disk; + } + + public Swap addSwap(long value) { + Swap net = new Swap(); + net.setValue(BigInteger.valueOf(value)); + getDiskOrMemoryOrSwap().add(net); + return net; + } + + public UserIdentity addUser(String localUID, String globalName) { + UserIdentity user = new UserIdentity(); + user.setLocalUserId(localUID); + user.setGlobalUserName(globalName); + getUserIdentity().add(user); + return user; + } + + public JobName setJobName(String name) { + JobName jn = new JobName(); + jn.setValue(name); + this.setJobName(jn); + return jn; + } + + public Charge addCharge(float value) { + Charge c = new Charge(); + c.setValue(value); + this.setCharge(c); + return c; + } + + @SuppressWarnings("unchecked") + public <T> T getOfType(Class<T> clazz) { + for (Object o : getWallDurationOrCpuDurationOrNodeCount()) + if (clazz.isInstance(o)) + return (T) o; + for (Object o : getDiskOrMemoryOrSwap()) + if (clazz.isInstance(o)) + return (T) o; + return null; + } + + public String marshal() throws JAXBException { + StringWriter writer = new StringWriter(); + JAXBContext.newInstance(getClass()).createMarshaller() + .marshal(this, writer); + return writer.toString(); + } + + private static JAXBContext context; + static { + try { + context = JAXBContext.newInstance(JobUsageRecord.class); + } catch (JAXBException e) { + throw new RuntimeException("failed to handle JAXB annotated class", + e); + } + } + + public static JobUsageRecord unmarshal(String s) throws JAXBException { + return (JobUsageRecord) context.createUnmarshaller().unmarshal( + new StringReader(s)); + } + + public static JobUsageRecord unmarshal(Element elem) throws JAXBException { + return context.createUnmarshaller() + .unmarshal(new DOMSource(elem), JobUsageRecord.class) + .getValue(); + } + + // TODO: Add signing support +}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-usagerecord/src/main/xsd/ur.xsd ---------------------------------------------------------------------- diff --git a/taverna-server-usagerecord/src/main/xsd/ur.xsd b/taverna-server-usagerecord/src/main/xsd/ur.xsd new file mode 100644 index 0000000..16344a7 --- /dev/null +++ b/taverna-server-usagerecord/src/main/xsd/ur.xsd @@ -0,0 +1,425 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsd:schema attributeFormDefault="qualified" jaxb:version="2.1" + elementFormDefault="qualified" targetNamespace="http://schema.ogf.org/urf/2003/09/urf" + xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:urf="http://schema.ogf.org/urf/2003/09/urf" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" + xsi:schemaLocation="http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"> + <xsd:annotation> + <!-- Copyright (c) 2003-2008 Open Grid Forum --> + <xsd:documentation xml:lang="en">Usage Record Working Group XML Schema definition</xsd:documentation> + <xsd:appinfo> + <jaxb:schemaBindings> + <jaxb:package name="org.ogf.usage.v1_0" /> + </jaxb:schemaBindings> + </xsd:appinfo> + </xsd:annotation> + <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" + schemaLocation="xmlds.xsd" /> <!-- http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd --> + <xsd:complexType name="UsageRecordType"> + <xsd:sequence> + <xsd:element ref="urf:RecordIdentity" /> + <xsd:element minOccurs="0" ref="urf:JobIdentity" /> + <xsd:element maxOccurs="unbounded" minOccurs="0" ref="urf:UserIdentity" /> + <xsd:element minOccurs="0" ref="urf:JobName" /> + <xsd:element minOccurs="0" ref="urf:Charge" /> + <xsd:element ref="urf:Status" /> + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:annotation> + <xsd:documentation> + The elements grouped together in this choice may be represented + within a usage record multiple times. Each of these appearances + must be differentiated by the metric and/or type associated with + the element. + </xsd:documentation> + </xsd:annotation> + <xsd:element ref="urf:Disk" /> + <xsd:element ref="urf:Memory" /> + <xsd:element ref="urf:Swap" /> + <xsd:element ref="urf:Network" /> + <xsd:element ref="urf:TimeDuration" /> + <xsd:element ref="urf:TimeInstant" /> + <xsd:element ref="urf:ServiceLevel" /> + </xsd:choice> + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element minOccurs="0" ref="urf:WallDuration" /> + <xsd:sequence minOccurs="0"> + <xsd:element maxOccurs="2" minOccurs="0" ref="urf:CpuDuration" /> + </xsd:sequence> + <xsd:element minOccurs="0" ref="urf:NodeCount" /> + <xsd:element minOccurs="0" ref="urf:Processors" /> + <xsd:element minOccurs="0" ref="urf:EndTime" /> + <xsd:element minOccurs="0" ref="urf:StartTime" /> + <xsd:element minOccurs="0" ref="urf:MachineName" /> + <xsd:element minOccurs="0" ref="urf:SubmitHost" /> + <xsd:element minOccurs="0" ref="urf:Queue" /> + <xsd:sequence minOccurs="0"> + <xsd:element maxOccurs="unbounded" minOccurs="0" ref="urf:ProjectName" /> + </xsd:sequence> + <xsd:sequence minOccurs="0"> + <xsd:element maxOccurs="unbounded" minOccurs="0" ref="urf:Host" /> + </xsd:sequence> + <xsd:sequence minOccurs="0"> + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element ref="urf:PhaseResource" /> + <xsd:element ref="urf:VolumeResource" /> + <xsd:element ref="urf:Resource" /> + <xsd:element ref="urf:ConsumableResource" /> + </xsd:choice> + </xsd:sequence> + </xsd:choice> + </xsd:sequence> + </xsd:complexType> + <xsd:element abstract="true" name="Usage" type="urf:UsageRecordType" /> + <xsd:element name="UsageRecord" substitutionGroup="urf:Usage" + type="urf:UsageRecordType" /> + <xsd:element name="JobUsageRecord" substitutionGroup="urf:Usage"> + <xsd:complexType> + <xsd:complexContent> + <xsd:extension base="urf:UsageRecordType" /> + </xsd:complexContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="UsageRecords"> + <xsd:complexType> + <xsd:sequence> + <xsd:element maxOccurs="unbounded" minOccurs="0" ref="urf:Usage" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <!-- Common properties that may be measured with several different metrics + within the same usage record --> + <xsd:element name="Network"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:positiveInteger"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attributeGroup ref="urf:intervallicVolume" /> + <xsd:attribute default="total" ref="urf:metric" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Disk"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:positiveInteger"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attributeGroup ref="urf:intervallicVolume" /> + <xsd:attribute default="total" ref="urf:metric" use="optional" /> + <xsd:attribute ref="urf:type" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Memory"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:positiveInteger"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attributeGroup ref="urf:intervallicVolume" /> + <xsd:attribute default="total" ref="urf:metric" use="optional" /> + <xsd:attribute ref="urf:type" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Swap"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:positiveInteger"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attributeGroup ref="urf:intervallicVolume" /> + <xsd:attribute default="total" ref="urf:metric" use="optional" /> + <xsd:attribute ref="urf:type" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="NodeCount"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:positiveInteger"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attribute default="total" ref="urf:metric" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Processors"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:positiveInteger"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attribute ref="urf:metric" use="optional" /> + <xsd:attribute name="consumptionRate" type="xsd:float" + use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="TimeDuration"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:duration"> + <xsd:attribute ref="urf:type" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="TimeInstant"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:dateTime"> + <xsd:attribute ref="urf:type" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="ServiceLevel"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:token"> + <xsd:attribute ref="urf:type" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <!-- This element should appear at most twice within a usage record, with + differing values for usageType for each appearance --> + <xsd:element name="CpuDuration"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:duration"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attribute name="usageType"> + <xsd:simpleType> + <xsd:restriction base="xsd:token"> + <xsd:enumeration value="user" /> + <xsd:enumeration value="system" /> + </xsd:restriction> + </xsd:simpleType> + </xsd:attribute> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <!-- These common properties should appear at most once within a usage record, + rather that at most once per metric per usage record --> + <xsd:element name="WallDuration"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:duration"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="EndTime"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:dateTime"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="StartTime"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:dateTime"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="MachineName"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="urf:domainNameType"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="SubmitHost"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="urf:domainNameType"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Host"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="urf:domainNameType"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attribute default="false" name="primary" type="xsd:boolean" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Queue"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:string"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="JobName"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:string"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="ProjectName"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:string"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Status"> + <xsd:annotation> + <xsd:documentation> + Minimum required set = {Aborted, Completed, Failed, + Held, Queued, Started, Suspended} + </xsd:documentation> + </xsd:annotation> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:token"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="Charge"> + <xsd:complexType> + <xsd:simpleContent> + <xsd:extension base="xsd:float"> + <xsd:attribute ref="urf:description" use="optional" /> + <xsd:attribute ref="urf:unit" use="optional" /> + <xsd:attribute name="formula" type="xsd:string" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + </xsd:element> + <!-- identity elements --> + <xsd:element name="JobIdentity"> + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="0" name="GlobalJobId" type="xsd:string" /> + <xsd:element minOccurs="0" name="LocalJobId" type="xsd:string" /> + <xsd:sequence> + <xsd:element maxOccurs="unbounded" minOccurs="0" + name="ProcessId" type="xsd:string" /> + </xsd:sequence> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <xsd:element name="UserIdentity"> + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="0" name="LocalUserId" type="xsd:string" /> + <xsd:element minOccurs="0" name="GlobalUserName" type="xsd:string" /> + <xsd:element minOccurs="0" ref="ds:KeyInfo" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <xsd:element name="RecordIdentity"> + <xsd:complexType> + <xsd:sequence minOccurs="0"> + <xsd:element ref="ds:KeyInfo" /> + </xsd:sequence> + <xsd:attribute name="recordId" type="xsd:token" use="required" /> + <xsd:attribute name="createTime" type="xsd:dateTime" use="optional" /> + </xsd:complexType> + </xsd:element> + <!-- Extensibility Framework --> + <xsd:element name="Resource" type="urf:ResourceType" /> + <xsd:element name="ConsumableResource" type="urf:ConsumableResourceType" /> + <xsd:element name="PhaseResource"> + <xsd:complexType> + <xsd:complexContent> + <xsd:extension base="urf:ConsumableResourceType"> + <xsd:attribute ref="urf:phaseUnit" use="optional" /> + </xsd:extension> + </xsd:complexContent> + </xsd:complexType> + </xsd:element> + <xsd:element name="VolumeResource"> + <xsd:complexType> + <xsd:complexContent> + <xsd:extension base="urf:ConsumableResourceType"> + <xsd:attribute ref="urf:storageUnit" use="optional" /> + </xsd:extension> + </xsd:complexContent> + </xsd:complexType> + </xsd:element> + <!-- Create a generic consumable resource. Carries the units attribute --> + <xsd:complexType name="ConsumableResourceType"> + <xsd:simpleContent> + <xsd:extension base="xsd:float"> + <xsd:attribute name="units" type="xsd:string" use="optional" /> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + <!-- Create a generic resource type --> + <xsd:complexType name="ResourceType"> + <xsd:simpleContent> + <xsd:extension base="xsd:string"> + <xsd:attribute ref="urf:description" use="optional" /> + </xsd:extension> + </xsd:simpleContent> + </xsd:complexType> + <!-- Global Attribute Definitions --> + <xsd:attribute name="description" type="xsd:string" /> + <!-- Units of measure attribute definitions --> + <xsd:attribute name="unit" type="xsd:token" /> + <xsd:attribute name="storageUnit"> + <xsd:simpleType> + <xsd:restriction base="xsd:token"> + <xsd:enumeration value="b" /> + <xsd:enumeration value="B" /> + <xsd:enumeration value="KB" /> + <xsd:enumeration value="MB" /> + <xsd:enumeration value="GB" /> + <xsd:enumeration value="PB" /> + <xsd:enumeration value="EB" /> + <xsd:enumeration value="Kb" /> + <xsd:enumeration value="Mb" /> + <xsd:enumeration value="Gb" /> + <xsd:enumeration value="Pb" /> + <xsd:enumeration value="Eb" /> + </xsd:restriction> + </xsd:simpleType> + </xsd:attribute> + <xsd:attribute name="phaseUnit" type="xsd:duration" /> + <xsd:attributeGroup name="intervallicVolume"> + <xsd:attribute ref="urf:storageUnit" use="optional" /> + <xsd:attribute ref="urf:phaseUnit" use="optional" /> + </xsd:attributeGroup> + <!-- End units attributes --> + <xsd:attribute name="metric" type="xsd:token" /> + <xsd:attribute name="type" type="xsd:token" /> + <!-- Simple type definitions used to constrain values of attributes --> + <xsd:simpleType name="domainNameType"> + <xsd:restriction base="xsd:string"> + <xsd:pattern + value="([a-zA-Z0-9][a-zA-Z0-9'\-']*[a-zA-Z0-9]\.)*([a-zA-Z0-9][a-zA-Z0-9'\-']*[a-zA-Z0-9])?" /> + <xsd:maxLength value="255" /> + </xsd:restriction> + </xsd:simpleType> +</xsd:schema> + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-usagerecord/src/main/xsd/xmlds.xsd ---------------------------------------------------------------------- diff --git a/taverna-server-usagerecord/src/main/xsd/xmlds.xsd b/taverna-server-usagerecord/src/main/xsd/xmlds.xsd new file mode 100644 index 0000000..c3421c4 --- /dev/null +++ b/taverna-server-usagerecord/src/main/xsd/xmlds.xsd @@ -0,0 +1,318 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE schema + PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd" + [ + <!ATTLIST schema + xmlns:ds CDATA #FIXED "http://www.w3.org/2000/09/xmldsig#"> + <!ENTITY dsig 'http://www.w3.org/2000/09/xmldsig#'> + <!ENTITY % p ''> + <!ENTITY % s ''> + ]> + +<!-- Schema for XML Signatures + http://www.w3.org/2000/09/xmldsig# + $Revision: 1.1 $ on $Date: 2002/02/08 20:32:26 $ by $Author: reagle $ + + Copyright 2001 The Internet Society and W3C (Massachusetts Institute + of Technology, Institut National de Recherche en Informatique et en + Automatique, Keio University). All Rights Reserved. + http://www.w3.org/Consortium/Legal/ + + This document is governed by the W3C Software License [1] as described + in the FAQ [2]. + + [1] http://www.w3.org/Consortium/Legal/copyright-software-19980720 + [2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD +--> + + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:ds="http://www.w3.org/2000/09/xmldsig#" + targetNamespace="http://www.w3.org/2000/09/xmldsig#" + version="0.1" elementFormDefault="qualified"> + +<!-- Basic Types Defined for Signatures --> + +<simpleType name="CryptoBinary"> + <restriction base="base64Binary"> + </restriction> +</simpleType> + +<!-- Start Signature --> + +<element name="Signature" type="ds:SignatureType"/> +<complexType name="SignatureType"> + <sequence> + <element ref="ds:SignedInfo"/> + <element ref="ds:SignatureValue"/> + <element ref="ds:KeyInfo" minOccurs="0"/> + <element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="Id" type="ID" use="optional"/> +</complexType> + + <element name="SignatureValue" type="ds:SignatureValueType"/> + <complexType name="SignatureValueType"> + <simpleContent> + <extension base="base64Binary"> + <attribute name="Id" type="ID" use="optional"/> + </extension> + </simpleContent> + </complexType> + +<!-- Start SignedInfo --> + +<element name="SignedInfo" type="ds:SignedInfoType"/> +<complexType name="SignedInfoType"> + <sequence> + <element ref="ds:CanonicalizationMethod"/> + <element ref="ds:SignatureMethod"/> + <element ref="ds:Reference" maxOccurs="unbounded"/> + </sequence> + <attribute name="Id" type="ID" use="optional"/> +</complexType> + + <element name="CanonicalizationMethod" type="ds:CanonicalizationMethodType"/> + <complexType name="CanonicalizationMethodType" mixed="true"> + <sequence> + <any namespace="##any" minOccurs="0" maxOccurs="unbounded"/> + <!-- (0,unbounded) elements from (1,1) namespace --> + </sequence> + <attribute name="Algorithm" type="anyURI" use="required"/> + </complexType> + + <element name="SignatureMethod" type="ds:SignatureMethodType"/> + <complexType name="SignatureMethodType" mixed="true"> + <sequence> + <element name="HMACOutputLength" minOccurs="0" type="ds:HMACOutputLengthType"/> + <any namespace="##other" minOccurs="0" maxOccurs="unbounded"/> + <!-- (0,unbounded) elements from (1,1) external namespace --> + </sequence> + <attribute name="Algorithm" type="anyURI" use="required"/> + </complexType> + +<!-- Start Reference --> + +<element name="Reference" type="ds:ReferenceType"/> +<complexType name="ReferenceType"> + <sequence> + <element ref="ds:Transforms" minOccurs="0"/> + <element ref="ds:DigestMethod"/> + <element ref="ds:DigestValue"/> + </sequence> + <attribute name="Id" type="ID" use="optional"/> + <attribute name="URI" type="anyURI" use="optional"/> + <attribute name="Type" type="anyURI" use="optional"/> +</complexType> + + <element name="Transforms" type="ds:TransformsType"/> + <complexType name="TransformsType"> + <sequence> + <element ref="ds:Transform" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="Transform" type="ds:TransformType"/> + <complexType name="TransformType" mixed="true"> + <choice minOccurs="0" maxOccurs="unbounded"> + <any namespace="##other" processContents="lax"/> + <!-- (1,1) elements from (0,unbounded) namespaces --> + <element name="XPath" type="string"/> + </choice> + <attribute name="Algorithm" type="anyURI" use="required"/> + </complexType> + +<!-- End Reference --> + +<element name="DigestMethod" type="ds:DigestMethodType"/> +<complexType name="DigestMethodType" mixed="true"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="Algorithm" type="anyURI" use="required"/> +</complexType> + +<element name="DigestValue" type="ds:DigestValueType"/> +<simpleType name="DigestValueType"> + <restriction base="base64Binary"/> +</simpleType> + +<!-- End SignedInfo --> + +<!-- Start KeyInfo --> + +<element name="KeyInfo" type="ds:KeyInfoType"/> +<complexType name="KeyInfoType" mixed="true"> + <choice maxOccurs="unbounded"> + <element ref="ds:KeyName"/> + <element ref="ds:KeyValue"/> + <element ref="ds:RetrievalMethod"/> + <element ref="ds:X509Data"/> + <element ref="ds:PGPData"/> + <element ref="ds:SPKIData"/> + <element ref="ds:MgmtData"/> + <any processContents="lax" namespace="##other"/> + <!-- (1,1) elements from (0,unbounded) namespaces --> + </choice> + <attribute name="Id" type="ID" use="optional"/> +</complexType> + + <element name="KeyName" type="string"/> + <element name="MgmtData" type="string"/> + + <element name="KeyValue" type="ds:KeyValueType"/> + <complexType name="KeyValueType" mixed="true"> + <choice> + <element ref="ds:DSAKeyValue"/> + <element ref="ds:RSAKeyValue"/> + <any namespace="##other" processContents="lax"/> + </choice> + </complexType> + + <element name="RetrievalMethod" type="ds:RetrievalMethodType"/> + <complexType name="RetrievalMethodType"> + <sequence> + <element ref="ds:Transforms" minOccurs="0"/> + </sequence> + <attribute name="URI" type="anyURI"/> + <attribute name="Type" type="anyURI" use="optional"/> + </complexType> + +<!-- Start X509Data --> + +<element name="X509Data" type="ds:X509DataType"/> +<complexType name="X509DataType"> + <sequence maxOccurs="unbounded"> + <choice> + <element name="X509IssuerSerial" type="ds:X509IssuerSerialType"/> + <element name="X509SKI" type="base64Binary"/> + <element name="X509SubjectName" type="string"/> + <element name="X509Certificate" type="base64Binary"/> + <element name="X509CRL" type="base64Binary"/> + <any namespace="##other" processContents="lax"/> + </choice> + </sequence> +</complexType> + +<complexType name="X509IssuerSerialType"> + <sequence> + <element name="X509IssuerName" type="string"/> + <element name="X509SerialNumber" type="integer"/> + </sequence> +</complexType> + +<!-- End X509Data --> + +<!-- Begin PGPData --> + +<element name="PGPData" type="ds:PGPDataType"/> +<complexType name="PGPDataType"> + <choice> + <sequence> + <element name="PGPKeyID" type="base64Binary"/> + <element name="PGPKeyPacket" type="base64Binary" minOccurs="0"/> + <any namespace="##other" processContents="lax" minOccurs="0" + maxOccurs="unbounded"/> + </sequence> + <sequence> + <element name="PGPKeyPacket" type="base64Binary"/> + <any namespace="##other" processContents="lax" minOccurs="0" + maxOccurs="unbounded"/> + </sequence> + </choice> +</complexType> + +<!-- End PGPData --> + +<!-- Begin SPKIData --> + +<element name="SPKIData" type="ds:SPKIDataType"/> +<complexType name="SPKIDataType"> + <sequence maxOccurs="unbounded"> + <element name="SPKISexp" type="base64Binary"/> + <any namespace="##other" processContents="lax" minOccurs="0"/> + </sequence> +</complexType> + +<!-- End SPKIData --> + +<!-- End KeyInfo --> + +<!-- Start Object (Manifest, SignatureProperty) --> + +<element name="Object" type="ds:ObjectType"/> +<complexType name="ObjectType" mixed="true"> + <sequence minOccurs="0" maxOccurs="unbounded"> + <any namespace="##any" processContents="lax"/> + </sequence> + <attribute name="Id" type="ID" use="optional"/> + <attribute name="MimeType" type="string" use="optional"/> <!-- add a grep facet --> + <attribute name="Encoding" type="anyURI" use="optional"/> +</complexType> + +<element name="Manifest" type="ds:ManifestType"/> +<complexType name="ManifestType"> + <sequence> + <element ref="ds:Reference" maxOccurs="unbounded"/> + </sequence> + <attribute name="Id" type="ID" use="optional"/> +</complexType> + +<element name="SignatureProperties" type="ds:SignaturePropertiesType"/> +<complexType name="SignaturePropertiesType"> + <sequence> + <element ref="ds:SignatureProperty" maxOccurs="unbounded"/> + </sequence> + <attribute name="Id" type="ID" use="optional"/> +</complexType> + + <element name="SignatureProperty" type="ds:SignaturePropertyType"/> + <complexType name="SignaturePropertyType" mixed="true"> + <choice maxOccurs="unbounded"> + <any namespace="##other" processContents="lax"/> + <!-- (1,1) elements from (1,unbounded) namespaces --> + </choice> + <attribute name="Target" type="anyURI" use="required"/> + <attribute name="Id" type="ID" use="optional"/> + </complexType> + +<!-- End Object (Manifest, SignatureProperty) --> + +<!-- Start Algorithm Parameters --> + +<simpleType name="HMACOutputLengthType"> + <restriction base="integer"/> +</simpleType> + +<!-- Start KeyValue Element-types --> + +<element name="DSAKeyValue" type="ds:DSAKeyValueType"/> +<complexType name="DSAKeyValueType"> + <sequence> + <sequence minOccurs="0"> + <element name="P" type="ds:CryptoBinary"/> + <element name="Q" type="ds:CryptoBinary"/> + </sequence> + <element name="G" type="ds:CryptoBinary" minOccurs="0"/> + <element name="Y" type="ds:CryptoBinary"/> + <element name="J" type="ds:CryptoBinary" minOccurs="0"/> + <sequence minOccurs="0"> + <element name="Seed" type="ds:CryptoBinary"/> + <element name="PgenCounter" type="ds:CryptoBinary"/> + </sequence> + </sequence> +</complexType> + +<element name="RSAKeyValue" type="ds:RSAKeyValueType"/> +<complexType name="RSAKeyValueType"> + <sequence> + <element name="Modulus" type="ds:CryptoBinary"/> + <element name="Exponent" type="ds:CryptoBinary"/> + </sequence> +</complexType> + +<!-- End KeyValue Element-types --> + +<!-- End Signature --> + +</schema> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-usagerecord/src/test/java/TestUR.java ---------------------------------------------------------------------- diff --git a/taverna-server-usagerecord/src/test/java/TestUR.java b/taverna-server-usagerecord/src/test/java/TestUR.java new file mode 100644 index 0000000..42e9000 --- /dev/null +++ b/taverna-server-usagerecord/src/test/java/TestUR.java @@ -0,0 +1,120 @@ +import static java.lang.Runtime.getRuntime; + +import java.io.IOException; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.JAXBIntrospector; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.ogf.usage.JobUsageRecord; +import org.ogf.usage.v1_0.Charge; +import org.ogf.usage.v1_0.CpuDuration; +import org.ogf.usage.v1_0.Disk; +import org.ogf.usage.v1_0.EndTime; +import org.ogf.usage.v1_0.Host; +import org.ogf.usage.v1_0.JobIdentity; +import org.ogf.usage.v1_0.JobName; +import org.ogf.usage.v1_0.MachineName; +import org.ogf.usage.v1_0.Memory; +import org.ogf.usage.v1_0.Network; +import org.ogf.usage.v1_0.NodeCount; +import org.ogf.usage.v1_0.PhaseResource; +import org.ogf.usage.v1_0.Processors; +import org.ogf.usage.v1_0.ProjectName; +import org.ogf.usage.v1_0.Queue; +import org.ogf.usage.v1_0.RecordIdentity; +import org.ogf.usage.v1_0.ServiceLevel; +import org.ogf.usage.v1_0.StartTime; +import org.ogf.usage.v1_0.Status; +import org.ogf.usage.v1_0.SubmitHost; +import org.ogf.usage.v1_0.Swap; +import org.ogf.usage.v1_0.TimeDuration; +import org.ogf.usage.v1_0.TimeInstant; +import org.ogf.usage.v1_0.UserIdentity; +import org.ogf.usage.v1_0.VolumeResource; +import org.ogf.usage.v1_0.WallDuration; + +public class TestUR { + SchemaOutputResolver sink; + StringWriter writer; + + String result() { + return writer.toString(); + } + + @Before + public void setUp() throws Exception { + writer = new StringWriter(); + sink = new SchemaOutputResolver() { + @Override + public Result createOutput(String namespaceUri, + String suggestedFileName) throws IOException { + StreamResult sr = new StreamResult(writer); + sr.setSystemId("/dev/null"); + return sr; + } + }; + Assert.assertNull(null);// Shut up, Eclipse! + Assert.assertEquals("", result()); + } + + @Test + public void testSchema() throws JAXBException, IOException { + JAXBContext.newInstance(JobUsageRecord.class).generateSchema(sink); + Assert.assertNotSame("", result()); + } + + @Test + public void testSchemaCompleteness() throws JAXBException, DatatypeConfigurationException { + JAXBIntrospector info = JAXBContext.newInstance(JobUsageRecord.class).createJAXBIntrospector(); + Assert.assertTrue(info.isElement(new Charge())); + Assert.assertTrue(info.isElement(new CpuDuration())); + Assert.assertTrue(info.isElement(new Disk())); + Assert.assertTrue(info.isElement(new EndTime())); + Assert.assertTrue(info.isElement(new Host())); + Assert.assertTrue(info.isElement(new JobIdentity())); + Assert.assertTrue(info.isElement(new JobName())); + Assert.assertTrue(info.isElement(new JobUsageRecord())); + Assert.assertTrue(info.isElement(new MachineName())); + Assert.assertTrue(info.isElement(new Memory())); + Assert.assertTrue(info.isElement(new Network())); + Assert.assertTrue(info.isElement(new NodeCount())); + Assert.assertTrue(info.isElement(new PhaseResource())); + Assert.assertTrue(info.isElement(new Processors())); + Assert.assertTrue(info.isElement(new ProjectName())); + Assert.assertTrue(info.isElement(new Queue())); + Assert.assertTrue(info.isElement(new RecordIdentity())); + Assert.assertTrue(info.isElement(new ServiceLevel())); + Assert.assertTrue(info.isElement(new StartTime())); + Assert.assertTrue(info.isElement(new Status())); + Assert.assertTrue(info.isElement(new SubmitHost())); + Assert.assertTrue(info.isElement(new Swap())); + Assert.assertTrue(info.isElement(new TimeDuration())); + Assert.assertTrue(info.isElement(new TimeInstant())); + Assert.assertTrue(info.isElement(new UserIdentity())); + Assert.assertTrue(info.isElement(new VolumeResource())); + Assert.assertTrue(info.isElement(new WallDuration())); + } + + @Test + public void testGenerate() throws DatatypeConfigurationException, + JAXBException { + JobUsageRecord ur = new JobUsageRecord(); + ur.setStatus("Completed"); + ur.addWallDuration(1000 * 65); + ur.addHost("localhost"); + ur.addMemory(getRuntime().totalMemory() - getRuntime().freeMemory()).setType("vm"); + + String record = ur.marshal(); + Assert.assertNotSame("", record); + //System.out.println(record); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-webapp/.gitignore ---------------------------------------------------------------------- diff --git a/taverna-server-webapp/.gitignore b/taverna-server-webapp/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/taverna-server-webapp/.gitignore @@ -0,0 +1 @@ +/target http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-webapp/pom.xml ---------------------------------------------------------------------- diff --git a/taverna-server-webapp/pom.xml b/taverna-server-webapp/pom.xml new file mode 100644 index 0000000..f4cf0ef --- /dev/null +++ b/taverna-server-webapp/pom.xml @@ -0,0 +1,889 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.taverna.server</groupId> + <artifactId>taverna-server</artifactId> + <version>3.1.0-incubating-SNAPSHOT</version> + </parent> + <artifactId>taverna-server-webapp</artifactId> + <packaging>war</packaging> + <name>Apache Taverna Server Web Application Core</name> + <description>This is the implementation of the web-app that provides the Taverna Server with its SOAP and REST faces. It relies on the worker process to handle the actual launching of workflow runs.</description> + + <properties> + <version.cxf>2.7.7</version.cxf> + <version.spring>3.2.5.RELEASE</version.spring> + <version.spring-security>3.1.4.RELEASE</version.spring-security> + <version.asm>3.3.1</version.asm> + <version.smack>3.2.1</version.smack> + <version.jdoapi>3.0.1</version.jdoapi> + <forker.module>taverna-server-unix-forker</forker.module> + <util.dir>${project.build.directory}/${project.build.finalName}/WEB-INF/classes/util</util.dir> + <cmdline.dir>${util.dir}/taverna-commandline-${edition.commandline}-${version.commandline}</cmdline.dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxws</artifactId> + <version>${version.cxf}</version> + <exclusions> + <exclusion> + <artifactId>jaxb-impl</artifactId> + <groupId>com.sun.xml.bind</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>${version.cxf}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-transports-http</artifactId> + <version>${version.cxf}</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-core</artifactId> + <version>${version.spring-security}</version> + </dependency> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-web</artifactId> + <version>${version.spring-security}</version> + </dependency> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-config</artifactId> + <version>${version.spring-security}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${version.spring}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId><!--$NO-MVN-MAN-VER$--> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-port-description</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-runinterface</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-usagerecord</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-worker</artifactId> + <version>${project.parent.version}</version> + <classifier>jar-with-dependencies</classifier> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>${forker.module}</artifactId> + <version>${project.parent.version}</version> + <classifier>jar-with-dependencies</classifier> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-rmidaemon</artifactId> + <version>${project.parent.version}</version> + <classifier>jar-with-dependencies</classifier> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + <!-- + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.4.0.GA</version> + <scope>compile</scope> + </dependency> + --> + <!-- + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <version>4.0.2.GA</version> + <scope>compile</scope> + </dependency> + --> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.10.1.1</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + </dependency> + <dependency> + <groupId>javax.jdo</groupId> + <artifactId>jdo-api</artifactId> + <version>3.0.1</version> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-api-jdo</artifactId> + <version>[3.2.0, 3.2.99)</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-core</artifactId> + <version>3.2.10</version> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-rdbms</artifactId> + <version>[3.2.0, 3.2.99)</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.jdo</groupId> + <artifactId>jdo2-core</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>joda-time</groupId> + <artifactId>joda-time</artifactId> + </dependency> + <dependency> + <groupId>net.sf.mime-util</groupId> + <artifactId>mime-util</artifactId> + </dependency> + <dependency> + <groupId>org.twitter4j</groupId> + <artifactId>twitter4j-core</artifactId> + <version>[3.0,)</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + <version>3.0</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>1.7.4</version> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack</artifactId> + <version>${version.smack}</version> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smackx</artifactId> + <version>${version.smack}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>jsr250-api</artifactId> + <version>1.0</version> + </dependency> + <dependency> + <groupId>org.apache.abdera</groupId> + <artifactId>abdera-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.abdera</groupId> + <artifactId>abdera-parser</artifactId> + <version>1.1.3</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <artifactId>xercesImpl</artifactId> + <groupId>xerces</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk15on</artifactId> + <version>1.49</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context-support</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>1.7.4</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + <version>1.4.4</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <groupId>javax.activation</groupId> + <artifactId>activation</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + <version>1.7</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-extension-providers</artifactId> + <version>${version.cxf}</version> + </dependency> + <dependency> + <groupId>org.codehaus.jettison</groupId> + <artifactId>jettison</artifactId> + <version>1.3.4</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.taverna.language</groupId> + <artifactId>taverna-scufl2-api</artifactId> + <version>${taverna.language.version}</version> + </dependency> + <dependency> + <groupId>org.apache.taverna.language</groupId> + <artifactId>taverna-scufl2-t2flow</artifactId> + <version>${taverna.language.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.taverna.language</groupId> + <artifactId>taverna-scufl2-wfbundle</artifactId> + <version>${taverna.language.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-compress</artifactId> + <version>1.4.1</version> + </dependency> + </dependencies> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-runinterface</artifactId> + <version>${project.parent.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>${version.asm}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.2.7</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-tx</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + <version>${version.spring}</version> + </dependency> + <dependency> + <groupId>org.apache.abdera</groupId> + <artifactId>abdera-core</artifactId> + <version>1.1.3</version> + </dependency> + <dependency> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + <version>4.0.6</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-javamail_1.4_spec</artifactId> + <version>1.7.1</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>woodstox-core-asl</artifactId> + <version>4.2.0</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + <version>1.1.4</version> + </dependency> + </dependencies> + </dependencyManagement> + + <build> + <finalName>TavernaServer.${project.parent.version}</finalName> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>tomcat-maven-plugin</artifactId> + <version>1.1</version> + <configuration> + <server>deployhost</server> + <path>/taverna-server</path> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <encoding>US-ASCII</encoding> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + <plugin> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-maven-plugin</artifactId> + <version>3.3.0-release</version> + <configuration> + <jdkLogConfiguration>${project.basedir}/src/build/resources/datanucleus-log.properties</jdkLogConfiguration> + <log4jConfiguration>${project.basedir}/src/build/resources/datanucleus_log4j.properties</log4jConfiguration> + <verbose>true</verbose> + </configuration> + <dependencies> + <!-- Sucks that I have to say these explicitly --> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-core</artifactId> + <version>3.2.10</version> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-enhancer</artifactId> + <version>3.1.1</version> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-api-jdo</artifactId> + <version>3.2.5</version> + </dependency> + <dependency> + <groupId>javax.jdo</groupId> + <artifactId>jdo-api</artifactId> + <version>${version.jdoapi}</version> + </dependency> + </dependencies> + </plugin> + <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <versionRange>[2.0,)</versionRange> + <goals> + <goal>copy-dependencies</goal> + <goal>unpack</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore /> + </action> + </pluginExecution> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-maven-plugin</artifactId> + <versionRange>3.3.0-release</versionRange> + <goals> + <goal>enhance</goal> + </goals> + </pluginExecutionFilter> + <action> + <execute /> + </action> + </pluginExecution> + <pluginExecution> + <pluginExecutionFilter> + <groupId>pl.project13.maven</groupId> + <artifactId>git-commit-id-plugin</artifactId> + <versionRange>[2.1.4,)</versionRange> + <goals> + <goal>revision</goal> + </goals> + </pluginExecutionFilter> + <action> + <execute /> + </action> + </pluginExecution> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-maven-plugin</artifactId> + <versionRange>3.3.0-release</versionRange> + <goals> + <goal>schema-create</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore /> + </action> + </pluginExecution> + <pluginExecution> + <pluginExecutionFilter> + <groupId>net.alchim31.maven</groupId> + <artifactId>yuicompressor-maven-plugin</artifactId> + <versionRange>[1.0.0,)</versionRange> + <goals> + <goal>compress</goal> + </goals> + </pluginExecutionFilter> + <action> + <execute/> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + <defaultGoal>package</defaultGoal> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-executable-library-jars</id> + <phase>prepare-package</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-worker</artifactId> + <version>${project.parent.version}</version> + <classifier>jar-with-dependencies</classifier> + <overWrite>false</overWrite> + <destFileName>server.worker.jar</destFileName> + </artifactItem> + <artifactItem> + <groupId>${project.parent.groupId}</groupId> + <artifactId>${forker.module}</artifactId> + <version>${project.parent.version}</version> + <classifier>jar-with-dependencies</classifier> + <overWrite>false</overWrite> + <destFileName>secure.fork.jar</destFileName> + </artifactItem> + <artifactItem> + <groupId>${project.parent.groupId}</groupId> + <artifactId>taverna-server-rmidaemon</artifactId> + <version>${project.parent.version}</version> + <classifier>jar-with-dependencies</classifier> + <overWrite>false</overWrite> + <destFileName>rmi.daemon.jar</destFileName> + </artifactItem> + </artifactItems> + <outputDirectory>${util.dir}</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>true</overWriteSnapshots> + <excludeTransitive>true</excludeTransitive> + </configuration> + </execution> + <execution> + <id>unpack-taverna-commandline</id> + <phase>prepare-package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.apache.taverna.commandline</groupId> + <artifactId>taverna-commandline</artifactId> + <version>${taverna.commandline.version}</version> + <classifier>bin</classifier> + <type>zip</type> + <classifier>bin</classifier> + <outputDirectory>${util.dir}</outputDirectory> + </artifactItem> + </artifactItems> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>true</overWriteSnapshots> + <excludeTransitive>true</excludeTransitive> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-maven-plugin</artifactId> + <configuration> + <fork>false</fork> + <metadataIncludes> + org/taverna/server/master/*.class, + org/taverna/server/master/identity/*.class, + org/taverna/server/master/localworker/*.class, + org/taverna/server/master/notification/atom/*.class, + org/taverna/server/master/usage/*.class, + org/taverna/server/master/worker/*.class + </metadataIncludes> + </configuration> + <executions> + <execution> + <id>enhance</id> + <phase>process-classes</phase> + <goals> + <goal>enhance</goal> + </goals> + </execution> + <!-- + <execution> + <id>gen-db-schema</id> + <phase>process-classes</phase> + <goals> + <goal>schema-create</goal> + </goals> + <configuration> + <completeDdl>true</completeDdl> + <ddlFile>${util.dir}/schema.sql</ddlFile> + </configuration> + </execution> + --> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <encoding>US-ASCII</encoding> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + <plugin> + <groupId>pl.project13.maven</groupId> + <artifactId>git-commit-id-plugin</artifactId> + <version>2.1.4</version> + <executions> + <execution> + <id>buildinfo</id> + <phase>generate-resources</phase> + <goals> + <goal>revision</goal> + </goals> + </execution> + </executions> + <configuration> + <dotGitDirectory>${project.basedir}/../.git</dotGitDirectory> + <prefix>git</prefix> + <verbose>true</verbose> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <version>2.4</version> + <configuration> + <webXml>src/main/webapp/WEB-INF/web-sec.xml</webXml> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-eclipse-plugin</artifactId> + <configuration> + <additionalProjectnatures> + <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> + </additionalProjectnatures> + <additionalConfig> + <file> + <name>.springBeans</name> + <content><![CDATA[<?xml version="1.0" encoding="UTF-8"?> +<beansProjectDescription> + <version>1</version> + <pluginVersion>3.3.0.201307091516-RELEASE</pluginVersion> + <configSuffixes> + <configSuffix>xml</configSuffix> + </configSuffixes> + <enableImports>true</enableImports> + <configs> + <config>src/main/webapp/WEB-INF/partsecure.xml</config> + <config>src/main/webapp/WEB-INF/beans.xml</config> + <config>src/main/webapp/WEB-INF/insecure.xml</config> + <config>src/main/webapp/WEB-INF/providers.xml</config> + <config>src/main/webapp/WEB-INF/secure.xml</config> + <config>src/main/webapp/WEB-INF/webappBeans.xml</config> + </configs> + <configSets> + <configSet> + <name>Secure Configuration</name> + <allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding> + <incomplete>false</incomplete> + <configs> + <config>src/main/webapp/WEB-INF/beans.xml</config> + <config>src/main/webapp/WEB-INF/providers.xml</config> + <config>src/main/webapp/WEB-INF/secure.xml</config> + <config>src/main/webapp/WEB-INF/webappBeans.xml</config> + </configs> + <profiles> + </profiles> + </configSet> + <configSet> + <name>Insecure Configuration</name> + <allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding> + <incomplete>false</incomplete> + <configs> + <config>src/main/webapp/WEB-INF/beans.xml</config> + <config>src/main/webapp/WEB-INF/insecure.xml</config> + <config>src/main/webapp/WEB-INF/providers.xml</config> + <config>src/main/webapp/WEB-INF/webappBeans.xml</config> + </configs> + <profiles> + </profiles> + </configSet> + <configSet> + <name>Semi-Secure Configuration</name> + <allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding> + <incomplete>false</incomplete> + <configs> + <config>src/main/webapp/WEB-INF/beans.xml</config> + <config>src/main/webapp/WEB-INF/providers.xml</config> + <config>src/main/webapp/WEB-INF/webappBeans.xml</config> + <config>src/main/webapp/WEB-INF/partsecure.xml</config> + </configs> + <profiles> + </profiles> + </configSet> + </configSets> +</beansProjectDescription>]]></content> + </file> + </additionalConfig> + </configuration> + </plugin> + <plugin> + <groupId>net.alchim31.maven</groupId> + <artifactId>yuicompressor-maven-plugin</artifactId> + <version>1.4.0</version> + <executions> + <execution> + <goals> + <goal>compress</goal> + </goals> + </execution> + </executions> + <configuration> + <excludes> + <exclude>**/*.min.js</exclude> + </excludes> + <nosuffix>true</nosuffix> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>override-executeworkflow-scripts</id> + <phase>prepare-package</phase> + <goals> + <goal>copy-resources</goal> + </goals> + <configuration> + <outputDirectory>${cmdline.dir}</outputDirectory> + <resources> + <resource> + <directory>src/main/replacementscripts</directory> + <filtering>false</filtering> + </resource> + </resources> + <overwrite>true</overwrite> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.2.1</version> + <executions> + <execution> + <id>improve-registry-coverage</id> + <phase>prepare-package</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <executable>/bin/sh</executable> + <workingDirectory>${cmdline.dir}</workingDirectory> + <environmentVariables> + <RAVEN_APPHOME>${cmdline.dir}</RAVEN_APPHOME> + </environmentVariables> + <arguments> + <argument>./executeworkflow.sh</argument> + <argument>-help</argument> + </arguments> + <outputFile>/dev/null</outputFile> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + <resource> + <directory>src/main/webapp</directory> + <filtering>false</filtering> + </resource> + </resources> + </build> + + <profiles> + <profile> + <id>unix</id> + <properties> + <forker.module>taverna-server-unix-forker</forker.module> + </properties> + </profile> + <profile> + <id>win</id> + <properties> + <!-- This doesn't exist yet. --> + <forker.module>taverna-server-win-forker</forker.module> + </properties> + </profile> + <profile> + <id>nosec</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <webXml>src/main/webapp/WEB-INF/web-nosec.xml</webXml> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>partsec</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <webXml>src/main/webapp/WEB-INF/web-partsec.xml</webXml> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-webapp/src/build/resources/datanucleus_log4j.properties ---------------------------------------------------------------------- diff --git a/taverna-server-webapp/src/build/resources/datanucleus_log4j.properties b/taverna-server-webapp/src/build/resources/datanucleus_log4j.properties new file mode 100644 index 0000000..6707f55 --- /dev/null +++ b/taverna-server-webapp/src/build/resources/datanucleus_log4j.properties @@ -0,0 +1,4 @@ +log4j.rootLogger=info, R +log4j.appender.R=org.apache.log4j.ConsoleAppender +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d{yyyyMMdd'T'HHmmss.SSS} %-5p %c{1} %C{1} - %m%n \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/2c71f9a9/taverna-server-webapp/src/main/java/org/taverna/server/master/ContentsDescriptorBuilder.java ---------------------------------------------------------------------- diff --git a/taverna-server-webapp/src/main/java/org/taverna/server/master/ContentsDescriptorBuilder.java b/taverna-server-webapp/src/main/java/org/taverna/server/master/ContentsDescriptorBuilder.java new file mode 100644 index 0000000..f5259bd --- /dev/null +++ b/taverna-server-webapp/src/main/java/org/taverna/server/master/ContentsDescriptorBuilder.java @@ -0,0 +1,292 @@ +/* + * Copyright (C) 2010-2011 The University of Manchester + * + * See the file "LICENSE" for license terms. + */ +package org.taverna.server.master; + +import static eu.medsea.util.MimeUtil.getMimeType; +import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE; +import static javax.ws.rs.core.UriBuilder.fromUri; +import static org.apache.commons.logging.LogFactory.getLog; +import static org.taverna.server.master.common.Uri.secure; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.apache.commons.logging.Log; +import org.springframework.beans.factory.annotation.Required; +import org.taverna.server.master.exceptions.FilesystemAccessException; +import org.taverna.server.master.exceptions.NoDirectoryEntryException; +import org.taverna.server.master.interfaces.Directory; +import org.taverna.server.master.interfaces.DirectoryEntry; +import org.taverna.server.master.interfaces.File; +import org.taverna.server.master.interfaces.TavernaRun; +import org.taverna.server.master.interfaces.UriBuilderFactory; +import org.taverna.server.master.utils.FilenameUtils; +import org.taverna.server.port_description.AbsentValue; +import org.taverna.server.port_description.AbstractPortDescription; +import org.taverna.server.port_description.AbstractValue; +import org.taverna.server.port_description.ErrorValue; +import org.taverna.server.port_description.InputDescription; +import org.taverna.server.port_description.InputDescription.InputPort; +import org.taverna.server.port_description.LeafValue; +import org.taverna.server.port_description.ListValue; +import org.taverna.server.port_description.OutputDescription; +import org.taverna.server.port_description.OutputDescription.OutputPort; + +import uk.org.taverna.scufl2.api.container.WorkflowBundle; +import uk.org.taverna.scufl2.api.core.Workflow; +import uk.org.taverna.scufl2.api.port.InputWorkflowPort; +import uk.org.taverna.scufl2.api.port.OutputWorkflowPort; + +/** + * A class that is used to build descriptions of the contents of a workflow + * run's filesystem. + * + * @author Donal Fellows + */ +public class ContentsDescriptorBuilder { + private Log log = getLog("Taverna.Server.Webapp"); + private FilenameUtils fileUtils; + private UriBuilderFactory uriBuilderFactory; + + @Required + public void setUriBuilderFactory(UriBuilderFactory uriBuilderFactory) { + this.uriBuilderFactory = uriBuilderFactory; + } + + @Required + public void setFileUtils(FilenameUtils fileUtils) { + this.fileUtils = fileUtils; + } + + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + + private Workflow fillInFromWorkflow(TavernaRun run, UriBuilder ub, + AbstractPortDescription portDesc) throws IOException { + WorkflowBundle bundle = run.getWorkflow().getScufl2Workflow(); + bundle.getMainWorkflow().getInputPorts(); + portDesc.fillInBaseData(bundle.getMainWorkflow() + .getWorkflowIdentifier().toString(), run.getId(), ub.build()); + return bundle.getMainWorkflow(); + } + + /** + * Computes the depth of value in a descriptor. + * + * @param value + * The value description to characterise. + * @return Its depth (i.e., the depth of the port outputting the value) or + * <tt>null</tt> if that is impossible to determine. + */ + private Integer computeDepth(AbstractValue value) { + if (value instanceof ListValue) { + int mv = 1; + for (AbstractValue v : ((ListValue) value).contents) { + Integer d = computeDepth(v); + if (d != null && mv <= d) + mv = d + 1; + } + return mv; + } else if (value instanceof LeafValue || value instanceof ErrorValue) + return 0; + else + return null; + } + + /** + * Build a description of a leaf value. + * + * @param file + * The file representing the value. + * @return A value descriptor. + * @throws FilesystemAccessException + * If anything goes wrong. + */ + private LeafValue constructLeafValue(File file) + throws FilesystemAccessException { + LeafValue v = new LeafValue(); + v.fileName = file.getFullName(); + v.byteLength = file.getSize(); + try { + byte[] head = file.getContents(0, 1024); + v.contentType = getMimeType(new ByteArrayInputStream(head)); + } catch (Exception e) { + v.contentType = APPLICATION_OCTET_STREAM_TYPE.toString(); + } + return v; + } + + /** + * Build a description of an error value. + * + * @param file + * The file representing the error. + * @return A value descriptor. + * @throws FilesystemAccessException + * If anything goes wrong. + */ + private ErrorValue constructErrorValue(File file) + throws FilesystemAccessException { + ErrorValue v = new ErrorValue(); + v.fileName = file.getFullName(); + v.byteLength = file.getSize(); + return v; + } + + /** + * Build a description of a list value. + * + * @param dir + * The directory representing the list. + * @param ub + * The factory for URIs. + * @return A value descriptor. + * @throws FilesystemAccessException + * If anything goes wrong. + */ + private ListValue constructListValue(Directory dir, UriBuilder ub) + throws FilesystemAccessException { + ListValue v = new ListValue(); + v.length = 0; + Set<DirectoryEntry> contents = new HashSet<>(dir.getContents()); + Iterator<DirectoryEntry> it = contents.iterator(); + while (it.hasNext()) + if (!it.next().getName().matches("^[0-9]+([.].*)?$")) + it.remove(); + for (int i = 1; !contents.isEmpty(); i++) { + String exact = Integer.toString(i); + AbstractValue subval = constructValue(contents, ub, exact); + v.contents.add(subval); + if (!(subval instanceof AbsentValue)) { + v.length = i; + String pfx = i + "."; + for (DirectoryEntry de : contents) + if (de.getName().equals(exact) + || de.getName().startsWith(pfx)) { + contents.remove(de); + break; + } + } + } + return v; + } + + /** + * Build a value description. + * + * @param parentContents + * The contents of the parent directory. + * @param ub + * The factory for URIs. + * @param name + * The name of the value's file/directory representative. + * @return A value descriptor. + * @throws FilesystemAccessException + * If anything goes wrong. + */ + private AbstractValue constructValue( + Collection<DirectoryEntry> parentContents, UriBuilder ub, + String name) throws FilesystemAccessException { + String error = name + ".error"; + String prefix = name + "."; + for (DirectoryEntry entry : parentContents) { + AbstractValue av; + if (entry.getName().equals(error) && entry instanceof File) { + av = constructErrorValue((File) entry); + } else if (!entry.getName().equals(name) + && !entry.getName().startsWith(prefix)) + continue; + else if (entry instanceof File) + av = constructLeafValue((File) entry); + else + av = constructListValue((Directory) entry, ub); + String fullPath = entry.getFullName().replaceFirst("^/", ""); + av.href = ub.clone().path(fullPath).build(); + return av; + } + return new AbsentValue(); + } + + /** + * Construct a description of the outputs of a workflow run. + * + * @param run + * The workflow run whose outputs are to be described. + * @param ui + * The origin for URIs. + * @return The description, which can be serialized to XML. + * @throws FilesystemAccessException + * If something goes wrong reading the directories. + * @throws NoDirectoryEntryException + * If something goes wrong reading the directories. + */ + public OutputDescription makeOutputDescriptor(TavernaRun run, UriInfo ui) + throws FilesystemAccessException, NoDirectoryEntryException { + OutputDescription descriptor = new OutputDescription(); + try { + UriBuilder ub = getRunUriBuilder(run, ui); + Workflow dataflow = fillInFromWorkflow(run, ub, descriptor); + Collection<DirectoryEntry> outs = null; + ub = ub.path("wd/{path}"); + for (OutputWorkflowPort output : dataflow.getOutputPorts()) { + OutputPort p = descriptor.addPort(output.getName()); + if (run.getOutputBaclavaFile() == null) { + if (outs == null) + outs = fileUtils.getDirectory(run, "out").getContents(); + p.output = constructValue(outs, ub, p.name); + p.depth = computeDepth(p.output); + } + } + } catch (IOException e) { + log.info("failure in conversion to .scufl2", e); + } + return descriptor; + } + + private UriBuilder getRunUriBuilder(TavernaRun run, UriInfo ui) { + if (ui == null) + return secure(uriBuilderFactory.getRunUriBuilder(run)); + else + return secure(fromUri(ui.getAbsolutePath().toString() + .replaceAll("/(out|in)put/?$", ""))); + } + + /** + * Constructs input descriptions. + * + * @param run + * The run to build for. + * @param ui + * The mechanism for building URIs. + * @return The description of the <i>expected</i> inputs of the run. + */ + public InputDescription makeInputDescriptor(TavernaRun run, UriInfo ui) { + InputDescription desc = new InputDescription(); + try { + UriBuilder ub = getRunUriBuilder(run, ui); + Workflow workflow = fillInFromWorkflow(run, ub, desc); + ub = ub.path("input/{name}"); + for (InputWorkflowPort port : workflow.getInputPorts()) { + InputPort in = desc.addPort(port.getName()); + in.href = ub.build(in.name); + try { + in.depth = port.getDepth(); + } catch (NumberFormatException ex) { + in.depth = null; + } + } + } catch (IOException e) { + log.info("failure in conversion to .scufl2", e); + } + return desc; + } +}
