From 54d9fcf300e28d5322790eae902f30e902887cc7 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 27 Apr 2015 12:55:27 +0000 Subject: [PATCH] Branched to release version 1.3 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-resources/1.3@114431 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 37 + .project | 36 + .settings/org.eclipse.core.resources.prefs | 7 + .settings/org.eclipse.jdt.core.prefs | 12 + .settings/org.eclipse.m2e.core.prefs | 5 + .settings/org.eclipse.wst.common.component | 6 + ....eclipse.wst.common.project.facet.core.xml | 5 + .settings/org.eclipse.wst.validation.prefs | 2 + distro/INSTALL | 1 + distro/LICENSE | 6 + distro/MAINTAINERS | 4 + distro/README | 41 + distro/changelog.xml | 22 + distro/descriptor.xml | 38 + distro/profile.xml | 26 + distro/svnpath.txt | 1 + pom.xml | 84 + .../common/resources/gcore/GCoreEndpoint.java | 1288 +++++++++ .../resources/gcore/GenericResource.java | 166 ++ .../common/resources/gcore/HostingNode.java | 2271 ++++++++++++++++ .../common/resources/gcore/Resource.java | 175 ++ .../common/resources/gcore/Resources.java | 222 ++ .../common/resources/gcore/ScopeGroup.java | 21 + .../resources/gcore/ServiceEndpoint.java | 710 +++++ .../resources/gcore/ServiceInstance.java | 377 +++ .../common/resources/gcore/Software.java | 2383 +++++++++++++++++ .../gcore/common/AnyMixedWrapper.java | 170 ++ .../resources/gcore/common/AnyWrapper.java | 89 + .../gcore/common/BooleanWrapper.java | 39 + .../resources/gcore/common/DateWrapper.java | 52 + .../resources/gcore/common/FileList.java | 47 + .../resources/gcore/common/GHNReference.java | 41 + .../resources/gcore/common/Identity.java | 68 + .../resources/gcore/common/Platform.java | 139 + .../gcore/common/ServiceReference.java | 41 + .../gcore/utils/DateFormatterAdapter.java | 31 + .../common/resources/gcore/utils/Group.java | 76 + .../resources/gcore/utils/ReadOnlyGroup.java | 87 + .../common/resources/gcore/utils/Utils.java | 65 + .../resources/gcore/utils/XPathHelper.java | 128 + .../schema/CommonTypeDefinitions.xsd | 79 + src/main/resources/schema/endpoint.xsd | 98 + src/main/resources/schema/gcoreendpoint.xsd | 197 ++ src/main/resources/schema/generic.xsd | 24 + src/main/resources/schema/node.xsd | 254 ++ src/main/resources/schema/service.xsd | 391 +++ .../resources/gcore/GCoreEndpointTest.java | 170 ++ .../resources/gcore/GenericResourceTests.java | 138 + .../resources/gcore/HostingNodeTest.java | 141 + .../resources/gcore/ServiceEndpointTest.java | 105 + .../resources/gcore/ServiceInstanceTest.java | 45 + .../common/resources/gcore/SoftwareTest.java | 178 ++ .../common/resources/gcore/TestUtils.java | 12 + src/test/resources/endpoint.xml | 42 + src/test/resources/gcoreendpoint.xml | 104 + src/test/resources/generic.xml | 21 + src/test/resources/instance.xml | 57 + src/test/resources/node.xml | 160 ++ src/test/resources/service.xml | 107 + src/test/resources/textgeneric.xml | 15 + 60 files changed, 11357 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 .settings/org.eclipse.wst.validation.prefs create mode 100644 distro/INSTALL create mode 100644 distro/LICENSE create mode 100644 distro/MAINTAINERS create mode 100644 distro/README create mode 100644 distro/changelog.xml create mode 100644 distro/descriptor.xml create mode 100644 distro/profile.xml create mode 100644 distro/svnpath.txt create mode 100644 pom.xml create mode 100644 src/main/java/org/gcube/common/resources/gcore/GCoreEndpoint.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/GenericResource.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/HostingNode.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/Resource.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/Resources.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/ScopeGroup.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/ServiceEndpoint.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/ServiceInstance.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/Software.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/AnyMixedWrapper.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/AnyWrapper.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/BooleanWrapper.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/DateWrapper.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/FileList.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/GHNReference.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/Identity.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/Platform.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/common/ServiceReference.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/utils/DateFormatterAdapter.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/utils/Group.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/utils/ReadOnlyGroup.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/utils/Utils.java create mode 100644 src/main/java/org/gcube/common/resources/gcore/utils/XPathHelper.java create mode 100644 src/main/resources/schema/CommonTypeDefinitions.xsd create mode 100644 src/main/resources/schema/endpoint.xsd create mode 100644 src/main/resources/schema/gcoreendpoint.xsd create mode 100644 src/main/resources/schema/generic.xsd create mode 100644 src/main/resources/schema/node.xsd create mode 100644 src/main/resources/schema/service.xsd create mode 100644 src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java create mode 100644 src/test/java/org/gcube/common/resources/gcore/GenericResourceTests.java create mode 100644 src/test/java/org/gcube/common/resources/gcore/HostingNodeTest.java create mode 100644 src/test/java/org/gcube/common/resources/gcore/ServiceEndpointTest.java create mode 100644 src/test/java/org/gcube/common/resources/gcore/ServiceInstanceTest.java create mode 100644 src/test/java/org/gcube/common/resources/gcore/SoftwareTest.java create mode 100644 src/test/java/org/gcube/common/resources/gcore/TestUtils.java create mode 100644 src/test/resources/endpoint.xml create mode 100644 src/test/resources/gcoreendpoint.xml create mode 100644 src/test/resources/generic.xml create mode 100644 src/test/resources/instance.xml create mode 100644 src/test/resources/node.xml create mode 100644 src/test/resources/service.xml create mode 100644 src/test/resources/textgeneric.xml diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..4201ad7 --- /dev/null +++ b/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..cc524ab --- /dev/null +++ b/.project @@ -0,0 +1,36 @@ + + + common-gcore-resources + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..a035832 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Mon Dec 03 17:40:30 CET 2012 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6249222 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f0662ac --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Mon Dec 03 17:40:29 CET 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..fce98ea --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,6 @@ + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..1b22d70 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/distro/INSTALL b/distro/INSTALL new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/distro/INSTALL @@ -0,0 +1 @@ + diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..630ba97 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,6 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..eeb18f6 --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1,4 @@ +* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy +* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR, Italy +* Luigi Fortunati (luigi.fortunati@isti.cnr.it), CNR, Italy +* Luca Frosini (luca.frosini@isti.cnr.it), CNR, Italy \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..65ef90f --- /dev/null +++ b/distro/README @@ -0,0 +1,41 @@ +The gCube System - ${name} +---------------------- + +This work has been partially supported by the following European projects: DILIGENT (FP6-2003-IST-2), D4Science (FP7-INFRA-2007-1.2.2), +D4Science-II (FP7-INFRA-2008-1.2.2), iMarine (FP7-INFRASTRUCTURES-2011-2), and EUBrazilOpenBio (FP7-ICT-2011-EU-Brazil). + +Authors +------- + +* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy +* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR, Italy +* Luigi Fortunati (luigi.fortunati@isti.cnr.it), CNR, Italy +* Luca Frosini (luca.frosini@isti.cnr.it), CNR, Italy + +Version and Release Date +------------------------ +${version} + +Description +----------- +${description} + +Download information +-------------------- + +Source code is available from SVN: +${scm.url} + +Binaries can be downloaded from: + + +Documentation +------------- +Documentation is available on-line from the Projects Documentation Wiki: +https://gcube.wiki.gcube-system.org/gcube/index.php/Common-gcore-resources + + +Licensing +--------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..ef814d4 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,22 @@ + + + First Release + + + readonly groups are iterables and can be converted in collections + hosting node's load work with doubles instead of integers + resources with no scopes (e.g. just created) now pass validation + hosting node's load work with doubles instead of integers + more robust serialisation to contain a JAXB bug + date serialisation now retro-compatible with legacy processor + GenericResource now takes mixed content in its body. #newBody(String) and #bodyAsString() as helpers to work with plain string bodies + Software now takes mixed content in its body. #newSpecificData(String) and #specificDataAsString() as helpers to work with plain string data + + + better string vs. DOM handling of Any content + Fixed visibility of Software inner class LevelWrapper to be public + + + Deprecated localAvailableStorage() methods and added replacements localAvailableSpace() + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..06c416f --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,38 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..91c49e4 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,26 @@ + + + + Service + + ${description} + Common + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..f416f9d --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..31331ea --- /dev/null +++ b/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + + org.gcube.tools + maven-parent + 1.0.0 + + org.gcube.resources + common-gcore-resources + 1.3.0-SNAPSHOT + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} + scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} + + + + distro + + + + + junit + junit + 4.10 + test + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/common/resources/gcore/GCoreEndpoint.java b/src/main/java/org/gcube/common/resources/gcore/GCoreEndpoint.java new file mode 100644 index 0000000..7aeb0b4 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/GCoreEndpoint.java @@ -0,0 +1,1288 @@ +package org.gcube.common.resources.gcore; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + +import org.gcube.common.resources.gcore.common.AnyWrapper; +import org.gcube.common.resources.gcore.common.DateWrapper; +import org.gcube.common.resources.gcore.common.GHNReference; +import org.gcube.common.resources.gcore.common.Identity; +import org.gcube.common.resources.gcore.common.Platform; +import org.gcube.common.resources.gcore.common.ServiceReference; +import org.gcube.common.resources.gcore.utils.Group; +import org.w3c.dom.Element; + +/** + * Describes endpoints of gCore services. + * + */ +@XmlRootElement(name = "Resource") +@XmlType(propOrder={"profile"}) +public class GCoreEndpoint extends Resource { + + public GCoreEndpoint() { + this.type(Type.GCOREENDPOINT); + } + + @XmlElementRef + private Profile profile = new Profile(); + + public Profile profile() { + return profile; + }; + + @XmlType (propOrder = { "description", "version", "ghn", "service", + "serviceName", "serviceClass", "security", "platform", + "deploymentData", "functions", "accessPoint", + "specificData", "accountings" }) + @XmlRootElement(name="Profile") + public static class Profile { + + @XmlElement(name = "Description") + private String description; + + @XmlElement(name = "Version") + private String version; + + @XmlElement(name = "GHN") + private GHNReference ghn; + + @XmlElement(name = "Service") + private ServiceReference service; + + @XmlElement(name = "ServiceName") + private String serviceName; + + @XmlElement(name = "ServiceClass") + private String serviceClass; + + @XmlElementRef + @XmlElementWrapper(name = "RunningInstanceSecurity") + private List security = new ArrayList(); + + @XmlElementRef + private Platform platform; + + @XmlElementRef + private DeploymentData deploymentData; + + @XmlElementWrapper(name = "RIEquivalenceFunctions") + @XmlElementRef + private List functions = new ArrayList(); + + @XmlElementRef + private AccessPoint accessPoint = new AccessPoint(); + + @XmlElementRef + private SpecificData specificData = new SpecificData(); + + @XmlElementWrapper(name = "Accounting") + @XmlElementRef + private List accountings = new ArrayList(); + + //before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (security!=null && security.isEmpty()) + security=null; + if (functions!=null && functions.isEmpty()) + functions=null; + if (accountings!=null && accountings.isEmpty()) + accountings=null; + if (accessPoint!=null && accessPoint.endpoints.isEmpty()) + accessPoint=null; + if (specificData!=null && specificData().getChildNodes().getLength()==0) + specificData=null; + } + + //after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (security==null) + security=new ArrayList(); + if (functions==null) + functions=new ArrayList(); + if (accountings==null) + accountings=new ArrayList(); + if (specificData==null) + specificData=new SpecificData(); + if (accessPoint==null) + accessPoint = new AccessPoint(); + } + + public String description() { + return description; + } + + public Profile description(String description) { + this.description = description; + return this; + } + + public String version() { + return version; + } + + public Profile version(String version) { + this.version = version; + return this; + } + + public String ghnId() { + return ghn==null?null:ghn.id; + } + + public Profile ghnId(String id) { + ghn=new GHNReference(); + ghn.id=id; + return this; + } + + public String serviceId() { + return service==null?null:service.id; + } + + public Profile serviceId(String id) { + service = new ServiceReference(); + service.id=id; + return this; + } + + public String serviceName() { + return serviceName; + } + + public Profile serviceName(String serviceName) { + this.serviceName = serviceName; + return this; + } + + public String serviceClass() { + return serviceClass; + } + + public Profile serviceClass(String serviceClass) { + this.serviceClass = serviceClass; + return this; + } + + public Group security() { + return new Group(security,Security.class); + } + + public Map securityMap(){ + Map map=new HashMap(); + for (Security s: security){ + if(s.name()!=null) + map.put(s.name(),s); + } + return map; + } + + public DeploymentData deploymentData() { + return deploymentData; + } + + public DeploymentData newDeploymentData() { + return deploymentData = new DeploymentData(); + } + + public Group functions() { + return new Group(functions,Function.class); + } + + public Map functionMap(){ + Map map=new HashMap(); + for (Function f: functions){ + if(f.name()!=null) + map.put(f.name(),f); + } + return map; + } + + public Platform platform() { + return platform; + } + + public boolean hasPlatform() { + return platform!=null; + } + + public Platform newPlatform() { + return platform = new Platform(); + } + + public Group endpoints() { + return new Group(accessPoint.endpoints,Endpoint.class); + } + + public Map endpointMap(){ + Map map=new HashMap(); + for (Endpoint e: accessPoint.endpoints){ + if(e.name()!=null) + map.put(e.name(),e); + } + return map; + } + + public Element specificData() { + return specificData.root(); + } + + public Group accountings() { + return new Group(accountings,ScopedAccounting.class); + } + + + public Map accountingsMap(){ + Map map=new HashMap(); + for (ScopedAccounting sa: accountings){ + if(sa.scope()!=null) + map.put(sa.scope(),sa); + } + return map; + } + + + @Override + public String toString() { + return "[description=" + description + ", version=" + version + + ", ghn=" + ghn + ", service=" + service + + ", serviceName=" + serviceName + ", serviceClass=" + + serviceClass + ", runningInstanceInterfaces=" + security + + ", platform=" + platform + ", deploymentData=" + + deploymentData + ", functions=" + functions + + ", endpoints=" + accessPoint.endpoints + ", specificData=" + + specificData() + ", accountings=" + accountings + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accessPoint == null) ? 0 : accessPoint.hashCode()); + result = prime * result + ((accountings == null) ? 0 : accountings.hashCode()); + result = prime * result + ((deploymentData == null) ? 0 : deploymentData.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((functions == null) ? 0 : functions.hashCode()); + result = prime * result + ((ghn == null) ? 0 : ghn.hashCode()); + result = prime * result + ((platform == null) ? 0 : platform.hashCode()); + result = prime * result + ((security == null) ? 0 : security.hashCode()); + result = prime * result + ((service == null) ? 0 : service.hashCode()); + result = prime * result + ((serviceClass == null) ? 0 : serviceClass.hashCode()); + result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); + result = prime * result + ((specificData == null) ? 0 : specificData.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Profile other = (Profile) obj; + if (accessPoint == null) { + if (other.accessPoint != null) + return false; + } else if (!accessPoint.equals(other.accessPoint)) + return false; + if (accountings == null) { + if (other.accountings != null) + return false; + } else if (!accountings.equals(other.accountings)) + return false; + if (deploymentData == null) { + if (other.deploymentData != null) + return false; + } else if (!deploymentData.equals(other.deploymentData)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (functions == null) { + if (other.functions != null) + return false; + } else if (!functions.equals(other.functions)) + return false; + if (ghn == null) { + if (other.ghn != null) + return false; + } else if (!ghn.equals(other.ghn)) + return false; + if (platform == null) { + if (other.platform != null) + return false; + } else if (!platform.equals(other.platform)) + return false; + if (security == null) { + if (other.security != null) + return false; + } else if (!security.equals(other.security)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + if (serviceClass == null) { + if (other.serviceClass != null) + return false; + } else if (!serviceClass.equals(other.serviceClass)) + return false; + if (serviceName == null) { + if (other.serviceName != null) + return false; + } else if (!serviceName.equals(other.serviceName)) + return false; + if (specificData == null) { + if (other.specificData != null) + return false; + } else if (!specificData.equals(other.specificData)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + + @XmlRootElement(name="SpecificData") + public static class SpecificData extends AnyWrapper{} + + + @XmlType(propOrder={"identity"}) + @XmlRootElement(name = "RunningInstanceInterface") + public static class Security { + + @XmlElementRef + private Identity identity; + + @XmlAttribute(name = "EntryName") + private String name; + + + public boolean hasIdentity() { + return identity!=null; + } + + public Identity newIdentity() { + return identity = new Identity(); + } + + public String name() { + return name; + } + + public Security name(String name) { + this.name = name; + return this; + } + + @Override + public String toString() { + return "Security [identity=" + identity + ", name=" + + name + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((identity == null) ? 0 : identity.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Security other = (Security) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (identity == null) { + if (other.identity != null) + return false; + } else if (!identity.equals(other.identity)) + return false; + return true; + } + + + + } + + @XmlType(propOrder={"name","path","activationTime","terminationTime","status","statusMsg","plugins"}) + @XmlRootElement(name = "DeploymentData") + public static class DeploymentData { + + @XmlElement(name = "InstanceName") + private String name; + + @XmlElement(name = "LocalPath") + private String path; + + @XmlElement(name = "ActivationTime") + private DateWrapper activationTime = new DateWrapper(); + + @XmlElement(name = "TerminationTime") + private DateWrapper terminationTime = new DateWrapper(); + + @XmlElement(name = "Status") + private String status; + + @XmlElement(name = "MessageState") + private String statusMsg; + + @XmlElementWrapper(name = "AvailablePlugins") + @XmlElement(name = "Plugin") + private List plugins = new ArrayList(); + + //before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (terminationTime!=null && terminationTime.value==null) + terminationTime=null; + if (plugins!=null && plugins.isEmpty()) + plugins=null; + } + + //after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (terminationTime==null) + terminationTime=new DateWrapper(); + if (plugins==null) + plugins=new ArrayList(); + } + + public String name() { + return name; + } + + public DeploymentData name(String name) { + this.name = name; + return this; + } + + public String path() { + return path; + } + + public DeploymentData path(String path) { + this.path = path; + return this; + } + + public Calendar activationTime() { + return activationTime.value; + } + + public DeploymentData activationTime(Calendar activationTime) { + this.activationTime.value=activationTime; + return this; + } + + public Calendar terminationTime() { + return terminationTime.value; + } + + public DeploymentData terminationTime(Calendar terminationTime) { + this.terminationTime.value=terminationTime; + return this; + } + + public String status() { + return status; + } + + public DeploymentData status(String status) { + this.status = status; + return this; + } + + public String statusMessage() { + return statusMsg; + } + + public DeploymentData statusMessage(String statusMsg) { + this.statusMsg = statusMsg; + return this; + } + + public Group plugins() { + return new Group(plugins,Plugin.class); + } + + + @Override + public String toString() { + return "[instanceName=" + name + ", localPath=" + path + + ", activationTime=" + activationTime + + ", terminationTime=" + terminationTime + ", status=" + + status + ", messageState=" + statusMsg + ", plugins=" + + plugins + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((activationTime == null) ? 0 : activationTime.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + ((plugins == null) ? 0 : plugins.hashCode()); + result = prime * result + ((statusMsg == null) ? 0 : statusMsg.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((terminationTime == null) ? 0 : terminationTime.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DeploymentData other = (DeploymentData) obj; + if (activationTime == null) { + if (other.activationTime != null) + return false; + } else if (!activationTime.equals(other.activationTime)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (path == null) { + if (other.path != null) + return false; + } else if (!path.equals(other.path)) + return false; + if (plugins == null) { + if (other.plugins != null) + return false; + } else if (!plugins.equals(other.plugins)) + return false; + if (statusMsg == null) { + if (other.statusMsg != null) + return false; + } else if (!statusMsg.equals(other.statusMsg)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + if (terminationTime == null) { + if (other.terminationTime != null) + return false; + } else if (!terminationTime.equals(other.terminationTime)) + return false; + return true; + } + + + + @XmlType(propOrder={"service","package_","version"}) + public static class Plugin { + + @XmlElement(name = "Service") + private Service service = new Service(); + + @XmlElement(name = "Package") + private String package_; + + @XmlElement(name = "Version") + private String version; + + public Service service() { + return service; + } + + public Plugin service(Service service) { + this.service = service; + return this; + } + + public Plugin service(String serviceClass,String serviceName,String version) { + this.service.clazz =serviceClass; + this.service.name=serviceName; + this.service.version=version; + return this; + } + + public String pluginPackage() { + return package_; + } + + public Plugin pluginPackage(String pluginPackage) { + this.package_=pluginPackage; + return this; + + } + + public String version() { + return version; + } + + public Plugin version(String version) { + this.version = version; + return this; + } + + @Override + public String toString() { + return "[service=" + service + ", package_=" + package_ + + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((package_ == null) ? 0 : package_.hashCode()); + result = prime * result + ((service == null) ? 0 : service.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Plugin other = (Plugin) obj; + if (package_ == null) { + if (other.package_ != null) + return false; + } else if (!package_.equals(other.package_)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + + + public static class Service { + + @XmlElement(name = "Class") + private String clazz; + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Version") + private String version; + + public String serviceClass() { + return clazz; + } + + public String serviceName() { + return name; + } + + public String version() { + return version; + } + + @Override + public String toString() { + return "[class=" + clazz + ", name=" + name + + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clazz == null) ? 0 : clazz.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Service other = (Service) obj; + if (clazz == null) { + if (other.clazz != null) + return false; + } else if (!clazz.equals(other.clazz)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + + } + } + + } + + @XmlType(propOrder={"name","parameters"}) + @XmlRootElement(name = "Function") + public static class Function { + + @XmlElement(name = "Name") + private String name; + + @XmlElementWrapper(name = "ActualParameters") + @XmlElement(name = "Param") + private List parameters = new ArrayList(); + + public String name() { + return name; + } + + public Function name(String name) { + this.name = name; + return this; + } + + public Group parameters() { + return new Group(parameters,Parameter.class); + } + + public Map parametersMap(){ + Map map=new HashMap(); + for (Parameter p: parameters){ + if(p.name()!=null) + map.put(p.name(),p); + } + return map; + } + + @Override + public String toString() { + return "[name=" + name + ", parameters=" + parameters + "]"; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Function other = (Function) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (parameters == null) { + if (other.parameters != null) + return false; + } else if (!parameters.equals(other.parameters)) + return false; + return true; + } + + + @XmlType(propOrder={"name","values"}) + public static class Parameter { + + @XmlElement(name = "Name") + String name; + + @XmlElement(name = "Value") + List values = new ArrayList(); + + public String name() { + return name; + } + + public List values() { + return values; + } + + public void nameAndValues(String name,String value, String ... values) { + this.name=name; + this.values.add(value); + this.values.addAll(Arrays.asList(values)); + } + + @Override + public String toString() { + return "[name=" + name + ", values=" + values + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((values == null) ? 0 : values.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Parameter other = (Parameter) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (values == null) { + if (other.values != null) + return false; + } else if (!values.equals(other.values)) + return false; + return true; + } + + + + } + } + + @XmlRootElement(name = "AccessPoint") + public static class AccessPoint { + + @XmlElementWrapper(name = "RunningInstanceInterfaces") + @XmlElement(name = "Endpoint") + private Set endpoints = new LinkedHashSet(); + + @Override + public String toString() { + return "[endpoints=" + endpoints + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((endpoints == null) ? 0 : endpoints.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccessPoint other = (AccessPoint) obj; + if (endpoints == null) { + if (other.endpoints != null) + return false; + } else if (!endpoints.equals(other.endpoints)) + return false; + return true; + } + + } + + public static class Endpoint { + + @XmlAttribute(name = "EntryName") + private String name; + + @XmlValue + private URI uri; + + public String name() { + return name; + } + + public Endpoint nameAndAddress(String name,URI uri) { + this.name = name; + this.uri=uri; + return this; + } + + public URI uri() { + return uri; + } + + @Override + public String toString() { + return "Endpoint [name=" + name + ", uri=" + uri + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Endpoint other = (Endpoint) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; + } + + + + } + + @XmlType(propOrder={"incomingCalls","averageIncomingCalls","averageInvocationTime","topCallerGHN"}) + @XmlRootElement(name = "ScopedAccounting") + public static class ScopedAccounting { + + @XmlAttribute + private String scope; + + @XmlElement(name = "TotalINCalls") + private long incomingCalls; + + @XmlElement(name = "AverageINCalls") + private List averageIncomingCalls = new ArrayList(); + + @XmlElement(name = "AverageInvocationTime") + private List averageInvocationTime = new ArrayList(); + + @XmlElement(name = "TopCallerGHN") + private TopCaller topCallerGHN; + + public String scope() { + return scope; + } + + public ScopedAccounting scope(String scope) { + this.scope = scope; + return this; + } + + public long incomingCalls() { + return incomingCalls; + } + + public ScopedAccounting incomingCalls(long incomingCalls) { + this.incomingCalls = incomingCalls; + return this; + } + + public Group averageInCalls() { + return new Group(averageIncomingCalls,AverageType.class); + } + + public Group averageInvocationTime() { + return new Group(averageInvocationTime,AverageType.class); + } + + public TopCaller topCaller() { + return topCallerGHN; + } + + public TopCaller newTopCaller() { + return topCallerGHN = new TopCaller(); + } + + + @Override + public String toString() { + return "ScopedAccounting [scope="+scope+", incomingCalls=" + incomingCalls + + ", averageincomingCalls=" + averageIncomingCalls + + ", averageInvocationTime=" + averageInvocationTime + + ", topCaller=" + topCallerGHN + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((averageIncomingCalls == null) ? 0 : averageIncomingCalls.hashCode()); + result = prime * result + ((averageInvocationTime == null) ? 0 : averageInvocationTime.hashCode()); + result = prime * result + (int) (incomingCalls ^ (incomingCalls >>> 32)); + result = prime * result + ((scope == null) ? 0 : scope.hashCode()); + result = prime * result + ((topCallerGHN == null) ? 0 : topCallerGHN.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ScopedAccounting other = (ScopedAccounting) obj; + if (averageIncomingCalls == null) { + if (other.averageIncomingCalls != null) + return false; + } else if (!averageIncomingCalls.equals(other.averageIncomingCalls)) + return false; + if (averageInvocationTime == null) { + if (other.averageInvocationTime != null) + return false; + } else if (!averageInvocationTime.equals(other.averageInvocationTime)) + return false; + if (incomingCalls != other.incomingCalls) + return false; + if (scope == null) { + if (other.scope != null) + return false; + } else if (!scope.equals(other.scope)) + return false; + if (topCallerGHN == null) { + if (other.topCallerGHN != null) + return false; + } else if (!topCallerGHN.equals(other.topCallerGHN)) + return false; + return true; + } + + + + public static class AverageType { + + @XmlAttribute(name = "interval") + private Long interval; + + @XmlAttribute(name = "average") + private Double average; + + public Long interval() { + return interval; + } + + public Double average() { + return average; + } + + public void intervalAndAverage(Long interval, Double average) { + this.interval=interval; + this.average=average; + } + + @Override + public String toString() { + return "[interval=" + interval + ", average=" + average + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((average == null) ? 0 : average.hashCode()); + result = prime * result + ((interval == null) ? 0 : interval.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AverageType other = (AverageType) obj; + if (average == null) { + if (other.average != null) + return false; + } else if (!average.equals(other.average)) + return false; + if (interval == null) { + if (other.interval != null) + return false; + } else if (!interval.equals(other.interval)) + return false; + return true; + } + + + + } + + public static class TopCaller { + + @XmlElement(name = "GHNName") + private String name; + + @XmlAttribute(name = "avgHourlyCalls") + private Double avgHourlyCalls; + + @XmlAttribute(name = "avgDailyCalls") + private Double avgDailyCalls; + + @XmlAttribute(name = "totalCalls") + private Long totalCalls; + + public String name() { + return name; + } + + public TopCaller name(String name) { + this.name = name; + return this; + } + + public TopCaller calls(Double hourlyAverage,Double dailyAverage,Long total) { + this.totalCalls=total; + this.avgDailyCalls = dailyAverage; + this.avgHourlyCalls = hourlyAverage; + return this; + } + + public Double avgHourlyCalls() { + return avgHourlyCalls; + } + + public Double avgDailyCalls() { + return avgDailyCalls; + } + + public Long totalCalls() { + return totalCalls; + } + + @Override + public String toString() { + return "[ghnName=" + name + ", avgHourlyCalls=" + + avgHourlyCalls + ", avgDailyCalls=" + + avgDailyCalls + ", totalCalls=" + totalCalls + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((avgDailyCalls == null) ? 0 : avgDailyCalls.hashCode()); + result = prime * result + ((avgHourlyCalls == null) ? 0 : avgHourlyCalls.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((totalCalls == null) ? 0 : totalCalls.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TopCaller other = (TopCaller) obj; + if (avgDailyCalls == null) { + if (other.avgDailyCalls != null) + return false; + } else if (!avgDailyCalls.equals(other.avgDailyCalls)) + return false; + if (avgHourlyCalls == null) { + if (other.avgHourlyCalls != null) + return false; + } else if (!avgHourlyCalls.equals(other.avgHourlyCalls)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (totalCalls == null) { + if (other.totalCalls != null) + return false; + } else if (!totalCalls.equals(other.totalCalls)) + return false; + return true; + } + + + } + + } + + } +} diff --git a/src/main/java/org/gcube/common/resources/gcore/GenericResource.java b/src/main/java/org/gcube/common/resources/gcore/GenericResource.java new file mode 100644 index 0000000..a56fe0f --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/GenericResource.java @@ -0,0 +1,166 @@ +package org.gcube.common.resources.gcore; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import org.gcube.common.resources.gcore.common.AnyMixedWrapper; +import org.w3c.dom.Element; + +/** + * A resource with custom semantics. + * + */ +@XmlRootElement(name="Resource") +@XmlType(propOrder={"profile"}) +public class GenericResource extends Resource { + + public GenericResource() { + this.type(Type.GENERIC); + } + + @XmlElementRef + private Profile profile; + + public Profile profile() { + return profile; + }; + + public Profile newProfile() { + return profile = new Profile(); + } + + @XmlRootElement(name="Profile") + @XmlType(propOrder={"secondaryType","name","description","body"}) + public static class Profile { + + @XmlElement(name="SecondaryType") + private String secondaryType; + + @XmlElement(name="Name") + private String name; + + @XmlElement(name="Description") + private String description; + + @XmlElementRef + private Body body; + + public String type() { + return secondaryType; + } + + public Profile type(String secondaryType) { + this.secondaryType = secondaryType; + return this; + } + + public String name() { + return name; + } + + public Profile name(String name) { + this.name = name; + return this; + } + + public String description() { + return description; + } + + public Profile description(String description) { + this.description = description; + return this; + } + + /** + * Returns the body as a DOM document. + * @return the body + */ + public Element body() { + return body==null?null:body.root(); + } + + /** + * Returns the body as a string. + * @return the body + */ + public String bodyAsString() { + return body==null?null:body.asString(); + } + + public Element newBody() { + body = new Body(); + return body(); + } + + public Profile newBody(String text) { + body = new Body(); + body.setString(text); + return this; + } + + @Override + public String toString() { + return "[secondaryType=" + secondaryType + ", name=" + name + ", description=" + description + + ", body=" + body + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((body == null) ? 0 : body.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((secondaryType == null) ? 0 : secondaryType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Profile other = (Profile) obj; + if (body == null) { + if (other.body != null) + return false; + } else if (!body.equals(other.body)) + return false; + + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (secondaryType == null) { + if (other.secondaryType != null) + return false; + } else if (!secondaryType.equals(other.secondaryType)) + return false; + return true; + } + + + + } + + @XmlRootElement(name="Body") + public static class Body extends AnyMixedWrapper{} + + @Override + public String toString() { + return super.toString()+profile; + } + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/HostingNode.java b/src/main/java/org/gcube/common/resources/gcore/HostingNode.java new file mode 100644 index 0000000..0fed422 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/HostingNode.java @@ -0,0 +1,2271 @@ +package org.gcube.common.resources.gcore; + +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import org.gcube.common.resources.gcore.common.BooleanWrapper; +import org.gcube.common.resources.gcore.common.Platform; +import org.gcube.common.resources.gcore.utils.DateFormatterAdapter; +import org.gcube.common.resources.gcore.utils.Group; +import org.gcube.common.resources.gcore.utils.Utils; + +/** + * Describes gHN installations. + * + * @author Fabio Simeoni + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + * + */ +@XmlRootElement(name = "Resource") +public class HostingNode extends Resource { + + private static final String CURRENT_VERSION = "1.3.0"; + + public HostingNode() { + this.type(Type.NODE); + this.version(CURRENT_VERSION); + } + + @XmlElementRef + private Profile profile; + + public Profile profile() { + return profile; + }; + + public Profile newProfile() { + return profile = new Profile(); + } + + @XmlType(propOrder = { "infrastructure", "ghn", "site", "packages" }) + @XmlRootElement(name = "Profile") + public static class Profile { + + @XmlElement(name = "Infrastructure") + private String infrastructure; + + @XmlElementRef + private NodeDescription ghn; + + @XmlElementRef + private Site site; + + @XmlElementWrapper(name = "DeployedPackages") + @XmlElementRef + private Set packages = new LinkedHashSet(); + + // before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (packages!=null && packages.isEmpty()) + packages = null; + } + + // after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (packages == null) + packages = new LinkedHashSet(); + } + + public String infrastructure() { + return infrastructure; + } + + public Profile infrastructure(String infrastructure) { + this.infrastructure = infrastructure; + return this; + } + + public NodeDescription description() { + return ghn; + } + + public NodeDescription newDescription() { + return ghn = new NodeDescription(); + } + + public Site site() { + return site; + } + + public Site newSite() { + return site = new Site(); + } + + public Group packages() { + return new Group(packages, DeployedPackage.class); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((ghn == null) ? 0 : ghn.hashCode()); + result = prime * result + ((infrastructure == null) ? 0 : infrastructure.hashCode()); + result = prime * result + ((packages == null) ? 0 : packages.hashCode()); + result = prime * result + ((site == null) ? 0 : site.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Profile other = (Profile) obj; + if (ghn == null) { + if (other.ghn != null) + return false; + } else if (!ghn.equals(other.ghn)) + return false; + if (infrastructure == null) { + if (other.infrastructure != null) + return false; + } else if (!infrastructure.equals(other.infrastructure)) + return false; + if (packages == null) { + if (other.packages != null) + return false; + } else if (!packages.equals(other.packages)) + return false; + if (site == null) { + if (other.site != null) + return false; + } else if (!site.equals(other.site)) + return false; + return true; + } + + @XmlType(propOrder = { "name", "activationTime", "status", "statusMessage", "ghnType", "platforms", + "securityEnabled", "securityData", "architecture", "operatingSystem", "processors", "networkAdapters", + "benchmark", "runtimeEnvironment", "storageDevices", "storagePartitions", "localFileSystems", + "remoteFileSystems", "devicePartitionMap", "partitionFilesystemMap", "uptime", "load", + "historicalLoad", "mainMemory", "localAvailableSpace", "lastUpdate" }) + @XmlRootElement(name = "GHNDescription") + public static class NodeDescription { + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "ActivationTime") + @XmlJavaTypeAdapter(DateFormatterAdapter.class) + private Calendar activationTime; + + @XmlElement(name = "Status") + private String status; + + @XmlElement(name = "StatusMessage") + private String statusMessage; + + @XmlElement(name = "Type") + private GHNType ghnType = GHNType.Dynamic; + + @XmlElementWrapper(name = "AvailablePlatforms") + @XmlElementRef + private Set platforms = new LinkedHashSet(); + + @XmlElement(name = "SecurityEnabled") + private BooleanWrapper securityEnabled = new BooleanWrapper(false); + + @XmlElementRef + private Security securityData; + + @XmlElementRef + private Architecture architecture; + + @XmlElementRef + private OperatingSystem operatingSystem; + + @XmlElementRef + private Set processors = new LinkedHashSet(); + + @XmlElementRef + private Set networkAdapters = new LinkedHashSet(); + + @XmlElementRef + private Benchmark benchmark; + + @XmlElementWrapper(name = "RunTimeEnv") + @XmlElementRef + private Set runtimeEnvironment = new LinkedHashSet(); + + @XmlElementRef + private Set storageDevices = new LinkedHashSet(); + + @XmlElementRef + private Set storagePartitions = new LinkedHashSet(); + + @XmlElementRef + private Set localFileSystems = new LinkedHashSet(); + + @XmlElementRef + private Set remoteFileSystems = new LinkedHashSet(); + + @XmlElementRef + private Set devicePartitionMap = new LinkedHashSet(); + + @XmlElementRef + private Set partitionFilesystemMap = new LinkedHashSet(); + + @XmlElement(name = "Uptime") + private String uptime; + + @XmlElementRef + private Load load; + + @XmlElementRef + private HistoricalLoad historicalLoad; + + @XmlElementRef + private MainMemory mainMemory; + + @XmlElement(name = "LocalAvailableSpace") + private Long localAvailableSpace; + + @XmlElement(name = "LastUpdate") + @XmlJavaTypeAdapter(DateFormatterAdapter.class) + private Calendar lastUpdate; + + // before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (platforms!=null && platforms.isEmpty()) + platforms = null; + if (runtimeEnvironment!=null && runtimeEnvironment.isEmpty()) + runtimeEnvironment = null; + } + + // after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (platforms == null) + platforms = new LinkedHashSet(); + if (runtimeEnvironment == null) + runtimeEnvironment = new LinkedHashSet(); + } + + public String name() { + return name; + } + + public NodeDescription name(String name) { + this.name = name; + return this; + } + + public Calendar activationTime() { + return activationTime; + } + + public NodeDescription activationTime(Calendar time) { + this.activationTime = time; + return this; + } + + public String status() { + return status; + } + + public NodeDescription status(String status) { + this.status = status; + return this; + } + + public String statusMessage() { + return statusMessage; + } + + public NodeDescription statusMessage(String message) { + this.statusMessage = message; + return this; + } + + public GHNType type() { + return ghnType; + } + + public NodeDescription type(GHNType type) { + this.ghnType = type; + return this; + } + + public Group platforms() { + return new Group(platforms, Platform.class); + } + + + public boolean isSecurityEnabled() { + return securityEnabled.value; + } + + public NodeDescription enableSecurity(boolean enabled) { + if (securityEnabled == null) { + securityEnabled = new BooleanWrapper(); + } + securityEnabled.value = enabled; + return this; + } + + public Security security() { + return securityData; + } + + public Security newSecurity() { + return securityData = new Security(); + } + + public Architecture architecture() { + return architecture; + } + + public Architecture newArchitecture() { + return architecture = new Architecture(); + } + + public OperatingSystem operatingSystem() { + return operatingSystem; + } + + public OperatingSystem newOperatingSystem() { + return operatingSystem = new OperatingSystem(); + } + + public Group processors() { + return new Group(processors, Processor.class); + } + + public Group networkAdapters() { + return new Group(networkAdapters, NetworkAdapter.class); + } + + public Benchmark benchmark() { + return benchmark; + } + + public Benchmark newBenchmark() { + return benchmark = new Benchmark(); + } + + public Group environmentVariables() { + return new Group(runtimeEnvironment, Variable.class); + } + + public Map variablesMap(){ + Map map=new HashMap(); + for (Variable v: runtimeEnvironment){ + if(v.key()!=null) + map.put(v.key(),v); + } + return map; + } + + public Group storageDevices() { + return new Group(storageDevices,StorageDevice.class); + } + + + public Group storagePartitions() { + return new Group(storagePartitions,StoragePartition.class); + } + + + public Group localFileSystems() { + return new Group(localFileSystems,LocalFileSystem.class); + } + + public Group remoteFileSystems() { + return new Group(remoteFileSystems,RemoteFileSystem.class); + } + + public Group devicePartitions() { + return new Group(devicePartitionMap,DevicePartition.class); + } + + public Group fileSystemPartitions() { + return new Group(partitionFilesystemMap,FileSystemPartition.class); + } + + public String uptime() { + return uptime; + } + + public NodeDescription uptime(String uptime) { + this.uptime = uptime; + return this; + } + + public Load load() { + return load; + } + + public Load newLoad() { + return load = new Load(); + } + + public HistoricalLoad historicalLoad() { + return historicalLoad; + } + + public HistoricalLoad newHistoricalLoad() { + return historicalLoad = new HistoricalLoad(); + } + + public MainMemory mainMemory() { + return mainMemory; + } + + public MainMemory newMainMemory() { + return this.mainMemory = new MainMemory(); + } + + public Long localAvailableSpace() { + return localAvailableSpace; + } + + public void localAvailableSpace(Long amount) { + this.localAvailableSpace=amount; + } + + /** + * @deprecated use {@link #localAvailableSpace()} instead + */ + @Deprecated + public Integer localAvailableStorage() { + return localAvailableSpace.intValue(); + } + + /** + * @deprecated use {@link #localAvailableSpace(Long amolocalAvailableSpaceunt)} instead + */ + @Deprecated + public NodeDescription localAvailableStorage(int amount) { + this.localAvailableSpace=(long) amount; + return this; + } + + public Calendar lastUpdate() { + return lastUpdate; + } + + public NodeDescription lastUpdate(Calendar time) { + this.lastUpdate = time; + return this; + } + + /** + * http://stackoverflow.com/questions/5806923/jaxb-element-of-type- enum + **/ + @XmlType(name = "GHNType") + @XmlEnum + public enum GHNType { + Dynamic, Static, SelfCleaning; + + public String value() { + return toString(); + } + + public static GHNType fromValue(String v) { + return valueOf(v); + } + } + + @XmlType(name = "SecurityData", propOrder = { "certificationAuthority", "credentialDistinguishedName", + "credentialsExpirationDate" }) + @XmlRootElement(name = "SecurityData") + public static class Security { + + @XmlElement(name = "CA") + private String certificationAuthority; + + @XmlElement(name = "CredentialsDistinguishedName") + private String credentialDistinguishedName; + + @XmlElement(name = "CredentialsExpireOn") + @XmlJavaTypeAdapter(DateFormatterAdapter.class) + private Calendar credentialsExpirationDate; + + public String authority() { + return certificationAuthority; + } + + public Security authority(String authority) { + this.certificationAuthority = authority; + return this; + } + + public String distinguishedName() { + return credentialDistinguishedName; + } + + public Security distinguishedName(String dn) { + this.credentialDistinguishedName = dn; + return this; + } + + public Calendar expirationDate() { + return credentialsExpirationDate; + } + + public Security expirationDate(Calendar date) { + this.credentialsExpirationDate = date; + return this; + } + + @Override + public String toString() { + return "SecurityData [certificationAuthority=" + certificationAuthority + + ", credentialDistinguishedName=" + credentialDistinguishedName + + ", credentialsExpirationDate=" + Utils.toString(credentialsExpirationDate) + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((certificationAuthority == null) ? 0 : certificationAuthority.hashCode()); + result = prime * result + + ((credentialDistinguishedName == null) ? 0 : credentialDistinguishedName.hashCode()); + result = prime * result + + ((credentialsExpirationDate == null) ? 0 : credentialsExpirationDate.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Security other = (Security) obj; + if (certificationAuthority == null) { + if (other.certificationAuthority != null) + return false; + } else if (!certificationAuthority.equals(other.certificationAuthority)) + return false; + if (credentialDistinguishedName == null) { + if (other.credentialDistinguishedName != null) + return false; + } else if (!credentialDistinguishedName.equals(other.credentialDistinguishedName)) + return false; + if (credentialsExpirationDate == null) { + if (other.credentialsExpirationDate != null) + return false; + } else if (!credentialsExpirationDate.equals(other.credentialsExpirationDate)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Architecture") + public static class Architecture { + + @XmlAttribute(name = "PlatformType") + private String platformType; + + @XmlAttribute(name = "SMPSize") + private int smpSize; + + @XmlAttribute(name = "SMTSize") + private int smtSize; + + public String platformType() { + return platformType; + } + + public Architecture platformType(String type) { + this.platformType = type; + return this; + } + + public int smpSize() { + return smpSize; + } + + public Architecture smpSize(int size) { + this.smpSize = size; + return this; + } + + public int smtSize() { + return smtSize; + } + + public Architecture smtSize(int size) { + this.smtSize = size; + return this; + } + + @Override + public String toString() { + return "Architecture [platformType=" + platformType + ", smpSize=" + smpSize + ", smtSize=" + + smtSize + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((platformType == null) ? 0 : platformType.hashCode()); + result = prime * result + smpSize; + result = prime * result + smtSize; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Architecture other = (Architecture) obj; + if (platformType == null) { + if (other.platformType != null) + return false; + } else if (!platformType.equals(other.platformType)) + return false; + if (smpSize != other.smpSize) + return false; + if (smtSize != other.smtSize) + return false; + return true; + } + + } + + @XmlRootElement(name = "OperatingSystem") + public static class OperatingSystem { + + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "Release") + private String release; + + @XmlAttribute(name = "Version") + private String version; + + public String name() { + return name; + } + + public OperatingSystem name(String name) { + this.name = name; + return this; + } + + public String release() { + return release; + } + + public OperatingSystem release(String release) { + this.release = release; + return this; + } + + public String version() { + return version; + } + + public OperatingSystem version(String version) { + this.version = version; + return this; + } + + @Override + public String toString() { + return "OperatingSystem [name=" + name + ", release=" + release + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((release == null) ? 0 : release.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OperatingSystem other = (OperatingSystem) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (release == null) { + if (other.release != null) + return false; + } else if (!release.equals(other.release)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Processor") + public static class Processor { + + @XmlAttribute(name = "Vendor") + private String vendor; + @XmlAttribute(name = "Model") + private String model; + @XmlAttribute(name = "ModelName") + private String modelName; + @XmlAttribute(name = "Family") + private String family; + @XmlAttribute(name = "ClockSpeedMhz") + private BigDecimal clockSpeedMhz; + @XmlAttribute(name = "Bogomips") + private BigDecimal bogomips; + @XmlAttribute(name = "CacheL1") + private int cacheL1; + @XmlAttribute(name = "CacheL1I") + private int cacheL1I; + @XmlAttribute(name = "CacheL1D") + private int cacheL1D; + @XmlAttribute(name = "CacheL2") + private int cacheL2; + + public String vendor() { + return vendor; + } + + public Processor vendor(String vendor) { + this.vendor = vendor; + return this; + } + + public String model() { + return model; + } + + public Processor model(String model) { + this.model = model; + return this; + } + + public String modelName() { + return modelName; + } + + public Processor modelName(String name) { + this.modelName = name; + return this; + } + + public String family() { + return family; + } + + public Processor family(String family) { + this.family = family; + return this; + } + + public BigDecimal clockSpeedMhz() { + return clockSpeedMhz; + } + + public Processor clockSpeedMhz(BigDecimal speed) { + this.clockSpeedMhz = speed; + return this; + } + + public BigDecimal bogomips() { + return bogomips; + } + + public Processor bogomips(BigDecimal bogomips) { + this.bogomips = bogomips; + return this; + } + + public int cacheL1() { + return cacheL1; + } + + public Processor cacheL1(int cache) { + this.cacheL1 = cache; + return this; + } + + public int cacheL1I() { + return cacheL1I; + } + + public Processor cacheL1I(int cache) { + this.cacheL1I = cache; + return this; + } + + public int cacheL1D() { + return cacheL1D; + } + + public Processor cacheL1D(int cache) { + this.cacheL1D = cache; + return this; + } + + public int cacheL2() { + return cacheL2; + } + + public Processor cacheL2(int cache) { + this.cacheL2 = cache; + return this; + } + + @Override + public String toString() { + return "Processor [vendor=" + vendor + ", model=" + model + ", modelName=" + modelName + + ", family=" + family + ", clockSpeedMhz=" + clockSpeedMhz + ", bogomips=" + bogomips + + ", cacheL1=" + cacheL1 + ", cacheL1I=" + cacheL1I + ", cacheL1D=" + cacheL1D + + ", cacheL2=" + cacheL2 + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((bogomips == null) ? 0 : bogomips.hashCode()); + result = prime * result + cacheL1; + result = prime * result + cacheL1D; + result = prime * result + cacheL1I; + result = prime * result + cacheL2; + result = prime * result + ((clockSpeedMhz == null) ? 0 : clockSpeedMhz.hashCode()); + result = prime * result + ((family == null) ? 0 : family.hashCode()); + result = prime * result + ((model == null) ? 0 : model.hashCode()); + result = prime * result + ((modelName == null) ? 0 : modelName.hashCode()); + result = prime * result + ((vendor == null) ? 0 : vendor.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Processor other = (Processor) obj; + if (bogomips == null) { + if (other.bogomips != null) + return false; + } else if (!bogomips.equals(other.bogomips)) + return false; + if (cacheL1 != other.cacheL1) + return false; + if (cacheL1D != other.cacheL1D) + return false; + if (cacheL1I != other.cacheL1I) + return false; + if (cacheL2 != other.cacheL2) + return false; + if (clockSpeedMhz == null) { + if (other.clockSpeedMhz != null) + return false; + } else if (!clockSpeedMhz.equals(other.clockSpeedMhz)) + return false; + if (family == null) { + if (other.family != null) + return false; + } else if (!family.equals(other.family)) + return false; + if (model == null) { + if (other.model != null) + return false; + } else if (!model.equals(other.model)) + return false; + if (modelName == null) { + if (other.modelName != null) + return false; + } else if (!modelName.equals(other.modelName)) + return false; + if (vendor == null) { + if (other.vendor != null) + return false; + } else if (!vendor.equals(other.vendor)) + return false; + return true; + } + + } + + @XmlRootElement(name = "NetworkAdapter") + public static class NetworkAdapter { + + @XmlAttribute(name = "InboundIP") + private String inboundIP; + @XmlAttribute(name = "OutboundIP") + private String outboundIP; + @XmlAttribute(name = "Name") + private String name; + @XmlAttribute(name = "IPAddress") + private String ipAddress; + @XmlAttribute(name = "MTU") + private int mtu; + + public String inboundIP() { + return inboundIP; + } + + public NetworkAdapter inboundIP(String ip) { + this.inboundIP = ip; + return this; + } + + public String outboundIP() { + return outboundIP; + } + + public NetworkAdapter outboundIP(String ip) { + this.outboundIP = ip; + return this; + } + + public String name() { + return name; + } + + public NetworkAdapter name(String name) { + this.name = name; + return this; + } + + public String ipAddress() { + return ipAddress; + } + + public NetworkAdapter ipAddress(String address) { + this.ipAddress = address; + return this; + } + + public int mtu() { + return mtu; + } + + public NetworkAdapter mtu(int mtu) { + this.mtu = mtu; + return this; + } + + @Override + public String toString() { + return "NetworkAdapter [inboundIP=" + inboundIP + ", outboundIP=" + outboundIP + ", name=" + name + + ", ipAddress=" + ipAddress + ", mtu=" + mtu + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((inboundIP == null) ? 0 : inboundIP.hashCode()); + result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode()); + result = prime * result + mtu; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((outboundIP == null) ? 0 : outboundIP.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NetworkAdapter other = (NetworkAdapter) obj; + if (inboundIP == null) { + if (other.inboundIP != null) + return false; + } else if (!inboundIP.equals(other.inboundIP)) + return false; + if (ipAddress == null) { + if (other.ipAddress != null) + return false; + } else if (!ipAddress.equals(other.ipAddress)) + return false; + if (mtu != other.mtu) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (outboundIP == null) { + if (other.outboundIP != null) + return false; + } else if (!outboundIP.equals(other.outboundIP)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Benchmark") + public static class Benchmark { + @XmlAttribute(name = "SI00") + private int si00; + @XmlAttribute(name = "SF00") + private int sf00; + + public int si00() { + return si00; + } + + public Benchmark si(int si) { + this.si00=si; + return this; + } + + public int sf00() { + return sf00; + } + + public Benchmark sf(int sf) { + this.sf00=sf; + return this; + } + + @Override + public String toString() { + return "Benchmark [si00=" + si00 + ", sf00=" + sf00 + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + sf00; + result = prime * result + si00; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Benchmark other = (Benchmark) obj; + if (sf00 != other.sf00) + return false; + if (si00 != other.si00) + return false; + return true; + } + + } + + @XmlType(propOrder = { "key", "value" }) + @XmlRootElement(name = "Variable") + public static class Variable { + + @XmlElement(name = "Key") + private String key; + + @XmlElement(name = "Value") + private String value; + + public String key() { + return key; + } + + public String value() { + return value; + } + + public void keyAndValue(String key, String value) { + this.key = key; + this.value = value; + } + + @Override + public String toString() { + return "Variable [key=" + key + ", value=" + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Variable other = (Variable) obj; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + } + + @XmlRootElement(name = "StorageDevice") + public static class StorageDevice { + + @XmlAttribute(name = "Name") + private String name; + @XmlAttribute(name = "Type") + private String type; + @XmlAttribute(name = "TransferRate") + private int transferRate; + @XmlAttribute(name = "Size") + private int size; + + public String name() { + return name; + } + + public StorageDevice name(String name) { + this.name=name; + return this; + } + + public String type() { + return type; + } + + public StorageDevice type(String type) { + this.type=type; + return this; + } + + public int transferRate() { + return transferRate; + } + + + public StorageDevice transferRate(int rate) { + this.transferRate=rate; + return this; + } + public int size() { + return size; + } + + public StorageDevice size(int size) { + this.size=size; + return this; + } + + @Override + public String toString() { + return "StorageDevice [name=" + name + ", type=" + type + ", transferRate=" + transferRate + + ", size=" + size + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + size; + result = prime * result + transferRate; + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StorageDevice other = (StorageDevice) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (size != other.size) + return false; + if (transferRate != other.transferRate) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } + + } + + @XmlRootElement(name = "StoragePartition") + public static class StoragePartition { + + @XmlAttribute(name = "Name") + private String name; + @XmlAttribute(name = "Size") + private String size; + @XmlAttribute(name = "ReadRate") + private int readRate; + @XmlAttribute(name = "WriteRate") + private int writeRate; + + public String name() { + return name; + } + + public StoragePartition name(String name) { + this.name=name; + return this; + } + + public String size() { + return size; + } + + public StoragePartition size(String size) { + this.size=size; + return this; + } + + public int readRate() { + return readRate; + } + + public StoragePartition readRate(int rate) { + this.readRate=rate; + return this; + } + + public int writeRate() { + return writeRate; + } + + public StoragePartition writeRate(int rate) { + this.writeRate=rate; + return this; + } + + @Override + public String toString() { + return "StoragePartition [name=" + name + ", size=" + size + ", readRate=" + readRate + + ", writeRate=" + writeRate + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + readRate; + result = prime * result + ((size == null) ? 0 : size.hashCode()); + result = prime * result + writeRate; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StoragePartition other = (StoragePartition) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (readRate != other.readRate) + return false; + if (size == null) { + if (other.size != null) + return false; + } else if (!size.equals(other.size)) + return false; + if (writeRate != other.writeRate) + return false; + return true; + } + + } + + @XmlRootElement(name = "LocalFileSystem") + public static class LocalFileSystem extends FileSystemType {} + + @XmlRootElement(name = "RemoteFileSystem") + public static class RemoteFileSystem extends FileSystemType {} + + @XmlType(name = "FileSystemType") + public static class FileSystemType { + + @XmlAttribute(name = "Name") + private String name; + @XmlAttribute(name = "Root") + private String root; + @XmlAttribute(name = "Size") + private int size; + @XmlAttribute(name = "ReadOnly") + private boolean readonly; + @XmlAttribute(name = "Type") + private String type; + + public String name() { + return name; + } + + public FileSystemType name(String name){ + this.name=name; + return this; + } + + public String root() { + return root; + } + + public FileSystemType root(String root){ + this.root=root; + return this; + } + + public int size() { + return size; + } + + public FileSystemType size(int size){ + this.size=size; + return this; + } + + public boolean isReadOnly() { + return readonly; + } + + public FileSystemType readOnly(boolean value){ + this.readonly=value; + return this; + } + + public String type() { + return type; + } + + public FileSystemType type(String type) { + this.type=type; + return this; + } + + @Override + public String toString() { + return "FileSystemType [name=" + name + ", root=" + root + ", size=" + size + ", readonly=" + + readonly + ", type=" + type + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + (readonly ? 1231 : 1237); + result = prime * result + ((root == null) ? 0 : root.hashCode()); + result = prime * result + size; + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FileSystemType other = (FileSystemType) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (readonly != other.readonly) + return false; + if (root == null) { + if (other.root != null) + return false; + } else if (!root.equals(other.root)) + return false; + if (size != other.size) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } + + } + + @XmlRootElement(name = "StorageDevice2StoragePartition") + public static class DevicePartition { + + @XmlAttribute(name = "StorageDeviceName") + private String storageDeviceName; + @XmlAttribute(name = "StoragePartitionName") + private String storagePartitionName; + + public String device() { + return storageDeviceName; + } + + public DevicePartition device(String name) { + this.storageDeviceName=name; + return this; + } + + public String name() { + return storagePartitionName; + } + + public DevicePartition name(String name) { + this.storagePartitionName=name; + return this; + } + + + @Override + public String toString() { + return "DevicePartitionMapping [storageDeviceName=" + storageDeviceName + ", storagePartitionName=" + + storagePartitionName + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((storageDeviceName == null) ? 0 : storageDeviceName.hashCode()); + result = prime * result + ((storagePartitionName == null) ? 0 : storagePartitionName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DevicePartition other = (DevicePartition) obj; + if (storageDeviceName == null) { + if (other.storageDeviceName != null) + return false; + } else if (!storageDeviceName.equals(other.storageDeviceName)) + return false; + if (storagePartitionName == null) { + if (other.storagePartitionName != null) + return false; + } else if (!storagePartitionName.equals(other.storagePartitionName)) + return false; + return true; + } + + } + + @XmlRootElement(name = "StoragePartition2FileSystem") + public static class FileSystemPartition { + + @XmlAttribute(name = "StoragePartitionName") + private String storagePartitionName; + @XmlAttribute(name = "FileSystemName") + private String fileSystemName; + + public String storagePartitionName() { + return storagePartitionName; + } + + public FileSystemPartition storageName(String name) { + this.storagePartitionName=name; + return this; + } + public String fsName() { + return fileSystemName; + } + + public FileSystemPartition fsName(String name) { + this.fileSystemName=name; + return this; + } + @Override + public String toString() { + return "PartitionFilesystemMapping [storagePartitionName=" + storagePartitionName + + ", fileSystemName=" + fileSystemName + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fileSystemName == null) ? 0 : fileSystemName.hashCode()); + result = prime * result + ((storagePartitionName == null) ? 0 : storagePartitionName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FileSystemPartition other = (FileSystemPartition) obj; + if (fileSystemName == null) { + if (other.fileSystemName != null) + return false; + } else if (!fileSystemName.equals(other.fileSystemName)) + return false; + if (storagePartitionName == null) { + if (other.storagePartitionName != null) + return false; + } else if (!storagePartitionName.equals(other.storagePartitionName)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Load") + public static class Load { + + @XmlAttribute(name = "Last1Min") + private Double last1Min; + @XmlAttribute(name = "Last5Min") + private Double last5Min; + @XmlAttribute(name = "Last15Min") + private Double last15Min; + + public Double lastMin() { + return last1Min; + } + + public Load lastMin(double load) { + this.last1Min=load; + return this; + } + + public Double last5Mins() { + return last5Min; + } + + public Load last5Mins(double load) { + this.last5Min=load; + return this; + } + + public Double last15Mins() { + return last15Min; + } + + public Load last15Mins(double load) { + this.last15Min=load; + return this; + } + + @Override + public String toString() { + return "[last1Min=" + last1Min + ", last5Min=" + last5Min + ", last15Min=" + last15Min + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((last15Min == null) ? 0 : last15Min.hashCode()); + result = prime * result + ((last1Min == null) ? 0 : last1Min.hashCode()); + result = prime * result + ((last5Min == null) ? 0 : last5Min.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Load other = (Load) obj; + if (last15Min == null) { + if (other.last15Min != null) + return false; + } else if (!last15Min.equals(other.last15Min)) + return false; + if (last1Min == null) { + if (other.last1Min != null) + return false; + } else if (!last1Min.equals(other.last1Min)) + return false; + if (last5Min == null) { + if (other.last5Min != null) + return false; + } else if (!last5Min.equals(other.last5Min)) + return false; + return true; + } + + } + + @XmlRootElement(name = "HistoricalLoad") + public static class HistoricalLoad { + + @XmlAttribute(name = "Last1H") + private Double last1H; + @XmlAttribute(name = "Last1Day") + private Double last1Day; + @XmlAttribute(name = "Last1Week") + private Double last1Week; + + public Double lastHour() { + return last1H; + } + + public HistoricalLoad lastHour(double load) { + this.last1H=load; + return this; + } + + public Double lastDay() { + return last1Day; + } + + public HistoricalLoad lastDay(double load) { + this.last1Day=load; + return this; + } + + public Double lastWeek() { + return last1Week; + } + + public HistoricalLoad lastWeek(double load) { + this.last1Week=load; + return this; + } + + @Override + public String toString() { + return "HistoricalLoad [last1H=" + last1H + ", last1Day=" + last1Day + ", last1Week=" + last1Week + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(last1Day); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(last1H); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(last1Week); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + HistoricalLoad other = (HistoricalLoad) obj; + if (Double.doubleToLongBits(last1Day) != Double.doubleToLongBits(other.last1Day)) + return false; + if (Double.doubleToLongBits(last1H) != Double.doubleToLongBits(other.last1H)) + return false; + if (Double.doubleToLongBits(last1Week) != Double.doubleToLongBits(other.last1Week)) + return false; + return true; + } + + } + + @XmlRootElement(name = "MainMemory") + public static class MainMemory { + + @XmlAttribute(name = "RAMSize") + private long ramSize; + @XmlAttribute(name = "VirtualSize") + private long virtualSize; + @XmlAttribute(name = "RAMAvailable") + private long ramAvailable; + @XmlAttribute(name = "VirtualAvailable") + private long virtualAvailable; + + public Long ramSize() { + return ramSize; + } + + public MainMemory ramSize(long size) { + this.ramSize = size; + return this; + } + + public long virtualSize() { + return virtualSize; + } + + public MainMemory virtualSize(long size) { + this.virtualSize = size; + return this; + } + + public Long ramAvailable() { + return ramAvailable; + } + + public MainMemory ramAvailable(long amount) { + this.ramAvailable = amount; + return this; + } + + public Long virtualAvailable() { + return virtualAvailable; + } + + public MainMemory virtualAvailable(long amount) { + this.virtualAvailable = amount; + return this; + } + + @Override + public String toString() { + return "MainMemory [ramSize=" + ramSize + ", virtualSize=" + virtualSize + ", ramAvailable=" + + ramAvailable + ", virtualAvailable=" + virtualAvailable + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (ramAvailable ^ (ramAvailable >>> 32)); + result = prime * result + (int) (ramSize ^ (ramSize >>> 32)); + result = prime * result + (int) (virtualAvailable ^ (virtualAvailable >>> 32)); + result = prime * result + (int) (virtualSize ^ (virtualSize >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MainMemory other = (MainMemory) obj; + if (ramAvailable != other.ramAvailable) + return false; + if (ramSize != other.ramSize) + return false; + if (virtualAvailable != other.virtualAvailable) + return false; + if (virtualSize != other.virtualSize) + return false; + return true; + } + + + + } + + @Override + public String toString() { + return "GHNDescriptor [name=" + name + ", activationTime=" + Utils.toString(activationTime) + + ", status=" + status + ", statusMessage=" + statusMessage + ", ghnType=" + ghnType + + ", platforms=" + platforms + ", securityEnabled=" + securityEnabled.value + ", securityData=" + + securityData + ", architecture=" + architecture + ", operatingSystem=" + operatingSystem + + ", processors=" + processors + ", networkAdapters=" + networkAdapters + ", benchmark=" + + benchmark + ", runtimeEnvironment=" + runtimeEnvironment + ", storageDevices=" + + storageDevices + ", storagePartitions=" + storagePartitions + ", localFileSystems=" + + localFileSystems + ", remoteFileSystems=" + remoteFileSystems + ", devicePartitionMap=" + + devicePartitionMap + ", partitionFilesystemMap=" + partitionFilesystemMap + ", uptime=" + + uptime + ", load=" + load + ", historicalLoad=" + historicalLoad + ", mainMemory=" + + mainMemory + ", localAvailableSpace=" + localAvailableSpace + ", lastUpdate=" + + Utils.toString(lastUpdate) + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((activationTime == null) ? 0 : activationTime.hashCode()); + result = prime * result + ((architecture == null) ? 0 : architecture.hashCode()); + result = prime * result + ((benchmark == null) ? 0 : benchmark.hashCode()); + result = prime * result + ((devicePartitionMap == null) ? 0 : devicePartitionMap.hashCode()); + result = prime * result + ((ghnType == null) ? 0 : ghnType.hashCode()); + result = prime * result + ((historicalLoad == null) ? 0 : historicalLoad.hashCode()); + result = prime * result + ((lastUpdate == null) ? 0 : lastUpdate.hashCode()); + result = prime * result + ((load == null) ? 0 : load.hashCode()); + result = prime * result + localAvailableSpace.hashCode(); + result = prime * result + ((localFileSystems == null) ? 0 : localFileSystems.hashCode()); + result = prime * result + ((mainMemory == null) ? 0 : mainMemory.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((networkAdapters == null) ? 0 : networkAdapters.hashCode()); + result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode()); + result = prime * result + ((partitionFilesystemMap == null) ? 0 : partitionFilesystemMap.hashCode()); + result = prime * result + ((platforms == null) ? 0 : platforms.hashCode()); + result = prime * result + ((processors == null) ? 0 : processors.hashCode()); + result = prime * result + ((remoteFileSystems == null) ? 0 : remoteFileSystems.hashCode()); + result = prime * result + ((runtimeEnvironment == null) ? 0 : runtimeEnvironment.hashCode()); + result = prime * result + ((securityData == null) ? 0 : securityData.hashCode()); + result = prime * result + ((securityEnabled == null) ? 0 : securityEnabled.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((statusMessage == null) ? 0 : statusMessage.hashCode()); + result = prime * result + ((storageDevices == null) ? 0 : storageDevices.hashCode()); + result = prime * result + ((storagePartitions == null) ? 0 : storagePartitions.hashCode()); + result = prime * result + ((uptime == null) ? 0 : uptime.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NodeDescription other = (NodeDescription) obj; + if (activationTime == null) { + if (other.activationTime != null) + return false; + } else if (!activationTime.equals(other.activationTime)) + return false; + if (architecture == null) { + if (other.architecture != null) + return false; + } else if (!architecture.equals(other.architecture)) + return false; + if (benchmark == null) { + if (other.benchmark != null) + return false; + } else if (!benchmark.equals(other.benchmark)) + return false; + if (devicePartitionMap == null) { + if (other.devicePartitionMap != null) + return false; + } else if (!devicePartitionMap.equals(other.devicePartitionMap)) + return false; + if (ghnType != other.ghnType) + return false; + if (historicalLoad == null) { + if (other.historicalLoad != null) + return false; + } else if (!historicalLoad.equals(other.historicalLoad)) + return false; + if (lastUpdate == null) { + if (other.lastUpdate != null) + return false; + } else if (!lastUpdate.equals(other.lastUpdate)) + return false; + if (load == null) { + if (other.load != null) + return false; + } else if (!load.equals(other.load)) + return false; + if (localAvailableSpace != other.localAvailableSpace) + return false; + if (localFileSystems == null) { + if (other.localFileSystems != null) + return false; + } else if (!localFileSystems.equals(other.localFileSystems)) + return false; + if (mainMemory == null) { + if (other.mainMemory != null) + return false; + } else if (!mainMemory.equals(other.mainMemory)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (networkAdapters == null) { + if (other.networkAdapters != null) + return false; + } else if (!networkAdapters.equals(other.networkAdapters)) + return false; + if (operatingSystem == null) { + if (other.operatingSystem != null) + return false; + } else if (!operatingSystem.equals(other.operatingSystem)) + return false; + if (partitionFilesystemMap == null) { + if (other.partitionFilesystemMap != null) + return false; + } else if (!partitionFilesystemMap.equals(other.partitionFilesystemMap)) + return false; + if (platforms == null) { + if (other.platforms != null) + return false; + } else if (!platforms.equals(other.platforms)) + return false; + if (processors == null) { + if (other.processors != null) + return false; + } else if (!processors.equals(other.processors)) + return false; + if (remoteFileSystems == null) { + if (other.remoteFileSystems != null) + return false; + } else if (!remoteFileSystems.equals(other.remoteFileSystems)) + return false; + if (runtimeEnvironment == null) { + if (other.runtimeEnvironment != null) + return false; + } else if (!runtimeEnvironment.equals(other.runtimeEnvironment)) + return false; + if (securityData == null) { + if (other.securityData != null) + return false; + } else if (!securityData.equals(other.securityData)) + return false; + if (securityEnabled == null) { + if (other.securityEnabled != null) + return false; + } else if (!securityEnabled.equals(other.securityEnabled)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + if (statusMessage == null) { + if (other.statusMessage != null) + return false; + } else if (!statusMessage.equals(other.statusMessage)) + return false; + if (storageDevices == null) { + if (other.storageDevices != null) + return false; + } else if (!storageDevices.equals(other.storageDevices)) + return false; + if (storagePartitions == null) { + if (other.storagePartitions != null) + return false; + } else if (!storagePartitions.equals(other.storagePartitions)) + return false; + if (uptime == null) { + if (other.uptime != null) + return false; + } else if (!uptime.equals(other.uptime)) + return false; + return true; + } + + } + + @XmlType(propOrder = { "location", "country", "latitude", "longitude", "domain" }) + @XmlRootElement(name = "Site") + public static class Site { + + @XmlElement(name = "Location") + private String location; + @XmlElement(name = "Country") + private String country; + @XmlElement(name = "Latitude") + private String latitude; + @XmlElement(name = "Longitude") + private String longitude; + @XmlElement(name = "Domain") + private String domain; + + public String location() { + return location; + } + + public Site location(String location) { + this.location = location; + return this; + } + + public String country() { + return country; + } + + public Site country(String country) { + this.country = country; + return this; + } + + public String latitude() { + return latitude; + } + + public Site latitude(String latitude) { + this.latitude = latitude; + return this; + } + + public String longitude() { + return longitude; + } + + public Site longitude(String longitude) { + this.longitude = longitude; + return this; + } + + public String domain() { + return domain; + } + + public Site domain(String domain) { + this.domain = domain; + return this; + } + + @Override + public String toString() { + return "Site [location=" + location + ", country=" + country + ", latitude=" + latitude + + ", longitude=" + longitude + ", domain=" + domain + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((country == null) ? 0 : country.hashCode()); + result = prime * result + ((domain == null) ? 0 : domain.hashCode()); + result = prime * result + ((latitude == null) ? 0 : latitude.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((longitude == null) ? 0 : longitude.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Site other = (Site) obj; + if (country == null) { + if (other.country != null) + return false; + } else if (!country.equals(other.country)) + return false; + if (domain == null) { + if (other.domain != null) + return false; + } else if (!domain.equals(other.domain)) + return false; + if (latitude == null) { + if (other.latitude != null) + return false; + } else if (!latitude.equals(other.latitude)) + return false; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + return false; + if (longitude == null) { + if (other.longitude != null) + return false; + } else if (!longitude.equals(other.longitude)) + return false; + return true; + } + + } + + @XmlType(propOrder = { "packageName", "packageVersion", "serviceName", "serviceClass", "serviceVersion" }) + @XmlRootElement(name = "Package") + public static class DeployedPackage { + + @XmlElement(name = "PackageName") + private String packageName; + + @XmlElement(name = "PackageVersion") + private String packageVersion; + + @XmlElement(name = "ServiceName") + private String serviceName; + @XmlElement(name = "ServiceClass") + private String serviceClass; + + //@XmlJavaTypeAdapter(value = VersionAdapter.class, type = Version.class) + @XmlElement(name = "ServiceVersion") + private String serviceVersion; + + public String name() { + return packageName; + } + + public DeployedPackage name(String name) { + this.packageName=name; + return this; + } + + public String packageVersion() { + return packageVersion; + } + + public DeployedPackage packageVersion(String version) { + this.packageVersion=version; + return this; + } + + public String serviceName() { + return serviceName; + } + + public DeployedPackage serviceName(String name) { + this.serviceName=name; + return this; + } + + public String serviceClass() { + return serviceClass; + } + + public DeployedPackage serviceClass(String serviceClass) { + this.serviceClass=serviceClass; + return this; + } + + public String serviceVersion() { + return serviceVersion; + } + + public DeployedPackage serviceVersion(String version) { + this.serviceVersion=version; + return this; + } + + @Override + public String toString() { + return "InstalledPackage [packageName=" + packageName + ", packageVersion=" + packageVersion() + + ", serviceName=" + serviceName + ", serviceClass=" + serviceClass + ", serviceVersion=" + + serviceVersion() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((packageName == null) ? 0 : packageName.hashCode()); + result = prime * result + ((packageVersion == null) ? 0 : packageVersion.hashCode()); + result = prime * result + ((serviceClass == null) ? 0 : serviceClass.hashCode()); + result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); + result = prime * result + ((serviceVersion == null) ? 0 : serviceVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DeployedPackage other = (DeployedPackage) obj; + if (packageName == null) { + if (other.packageName != null) + return false; + } else if (!packageName.equals(other.packageName)) + return false; + if (packageVersion == null) { + if (other.packageVersion != null) + return false; + } else if (!packageVersion.equals(other.packageVersion)) + return false; + if (serviceClass == null) { + if (other.serviceClass != null) + return false; + } else if (!serviceClass.equals(other.serviceClass)) + return false; + if (serviceName == null) { + if (other.serviceName != null) + return false; + } else if (!serviceName.equals(other.serviceName)) + return false; + if (serviceVersion == null) { + if (other.serviceVersion != null) + return false; + } else if (!serviceVersion.equals(other.serviceVersion)) + return false; + return true; + } + + } + + @Override + public String toString() { + return "Profile [infrastructure=" + infrastructure + ", ghn=" + ghn + ", site=" + site + ", packages=" + + packages + "]"; + } + + } +} diff --git a/src/main/java/org/gcube/common/resources/gcore/Resource.java b/src/main/java/org/gcube/common/resources/gcore/Resource.java new file mode 100644 index 0000000..5ecb1cd --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/Resource.java @@ -0,0 +1,175 @@ +package org.gcube.common.resources.gcore; + +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlType; + +/** + * Partial implementation for resource classes. + * + */ +@XmlType(propOrder={"id","type","scopes"}) +public abstract class Resource { + + //default resource type version + private static String CURRENT_VERSION = "0.4.x"; + + /** + * The type of the resource + */ + public static enum Type { + + GENERIC{public String toString() {return "GenericResource"; }}, + ENDPOINT{public String toString() {return "RuntimeResource"; }}, + GCOREENDPOINT{public String toString() {return "RunningInstance"; }}, + SOFTWARE{public String toString() {return "Service"; }}, + NODE{public String toString() {return "GHN"; }}; + + } + + //type string values -> enum values + private static Map types = new HashMap(); + + //populates type map + static { + for (Type t : Type.values()) + types.put(t.toString(),t); + } + + @XmlElement(name="ID") + private String id = UUID.randomUUID().toString(); + + @XmlElementWrapper(name = "Scopes") + @XmlElement(name = "Scope") + private Set scopes = new LinkedHashSet(); //order preserving + + @XmlElement(name="Type") + private String type; + + @XmlAttribute + private String version = CURRENT_VERSION; + + public ScopeGroup scopes() { + return new ScopeGroup(scopes,String.class); + } + + protected String addScope(String scope){ + scopes.add(scope); + return scope; + } + + protected String removeScope(String scope){ + scopes.remove(scope); + return scope; + } + + public Type type() { + return typeOf(type); + } + + protected void type(Type t) { + this.type=t.toString(); + } + + public String version() { + return version; + } + + protected void version(String version) { + this.version = version; + } + + public String id() { + return id; + } + + void setId(String id){ + this.id=id; + } + + abstract protected Object profile(); + + @Override + public String toString() { + return getClass().getSimpleName()+" [id=" + id + ", scopes=" + scopes + ", type=" + type + ", version=" + version + + ", profile=" + profile() + "]"; + } + + + //helper + private static Type typeOf(String type) { + return types.get(type); + } + + //before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (scopes!=null && scopes.isEmpty()) + scopes=null; + } + + //after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (scopes==null) + scopes=new LinkedHashSet(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((scopes == null) ? 0 : scopes.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + result = prime * result + ((profile() == null) ? 0 : profile().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Resource other = (Resource) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (scopes == null) { + if (other.scopes != null) + return false; + } else if (!scopes.equals(other.scopes)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + if (profile() == null) { + if (other.profile() != null) + return false; + } else if (!profile().equals(other.profile())){ + return false; + } + return true; + } + + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/Resources.java b/src/main/java/org/gcube/common/resources/gcore/Resources.java new file mode 100644 index 0000000..695263b --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/Resources.java @@ -0,0 +1,222 @@ +package org.gcube.common.resources.gcore; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.XMLConstants; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSResourceResolver; + +/** + * Utility methods over resources. + * + * @author Fabio Simeoni + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ +public class Resources { + + private static SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + + //known schema files embedded as classpath resources + private static Map, String> schemaResources = new HashMap, String>(); + + //cached schemas + private static Map,Schema> schemas = new HashMap, Schema>(); + + private static Map, JAXBContext> contexts = new HashMap, JAXBContext>(); + + + static { + + schemaFactory.setResourceResolver(new SchemaResolver()); + + //populates schema map + schemaResources.put(GenericResource.class, "schema/generic.xsd"); + schemaResources.put(ServiceEndpoint.class, "schema/endpoint.xsd"); + schemaResources.put(Software.class, "schema/service.xsd"); + schemaResources.put(GCoreEndpoint.class, "schema/gcoreendpoint.xsd"); + schemaResources.put(HostingNode.class, "schema/node.xsd"); + + //note: service instances have no schema so far + } + + // helper: resolves common type declarations in schemas + private static class SchemaResolver implements LSResourceResolver { + + private static LSInput input; + + static { + try { + input = ((DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS")) + .createLSInput(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, + String baseURI) { + + if (systemId.equals("CommonTypeDefinitions.xsd")) { + input.setByteStream(Resources.class.getResourceAsStream("/schema/CommonTypeDefinitions.xsd")); + } + return input; + } + }; + + /** + * Validates a resource against its own schema, if one exists. + * @param resource the resource + * @throws IllegalArgumentException if the resource has no associated scheme + * @throws Exception if the resource is not valid with respect to its own schema + */ + public static void validate(Resource resource) throws IllegalArgumentException, Exception { + + Schema schema = schema(resource.getClass()); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayInputStream in = new ByteArrayInputStream(marshal(resource,out).toByteArray()); + + schema.newValidator().validate(new StreamSource(in)); + + } + + //helper + private static synchronized Schema schema(Class resourceClass) throws Exception { + + String schemaResource = schemaResources.get(resourceClass); + + if (schemaResource==null) + throw new IllegalArgumentException("no known schema for:\n "+resourceClass); + + Schema schema = schemas.get(resourceClass); + if (schema==null) { + InputStream stream = Resources.class.getClassLoader().getResourceAsStream(schemaResource); + schema = schemaFactory.newSchema(new StreamSource(stream)); + schemas.put(resourceClass,schema); + } + return schema; + } + + /** + * Write the serialisation of a given resource to a given stream. + * @param resource the resource + * @param stream the stream in input + */ + public static T marshal(Object resource,T stream) { + + marshal(resource, new StreamResult(stream)); + return stream; + } + + /** + * Write the serialisation of a given resource to a given character stream. + * @param resource the resource + * @param stream the stream in input + */ + public static T marshal(Object resource,T stream) { + + marshal(resource,new StreamResult(stream)); + return stream; + } + + /** + * Write the serialisation of a given resource to a {@link Result}. + * @param resource the resource + * @param stream the result + * @return the result in input + */ + public static T marshal(Object resource,T result) { + + try { + JAXBContext context = context(resource.getClass()); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + + m.marshal(resource,result); + + return result; + } + catch(Exception e) { + throw new RuntimeException("serialisation error",e); + } + + } + + /** + * Prints the serialisation of a given resource to {@link System#out} + * @param resource the resource + */ + public static void print(Object resource) { + + marshal(resource,new OutputStreamWriter(System.out)); + } + + /** + * Creates a resource of given class from its serialisation in a given {@link Reader}. + * @param resourceClass the class of the resource + * @param reader the reader + * @return the resource + */ + public static T unmarshal(Class resourceClass, Reader reader) { + return unmarshal(resourceClass,new StreamSource(reader)); + } + + /** + * Creates a resource of given class from its serialisation in a given {@link InputStream}. + * @param resourceClass the class of the resource + * @param stream the stream + * @return the resource + */ + public static T unmarshal(Class resourceClass, InputStream stream) { + return unmarshal(resourceClass,new StreamSource(stream)); + } + + /** + * Creates a resource of given class from its serialisation in a given {@link Source}. + * @param resourceClass the class of the resource + * @param source the source + * @return the resource + */ + public static T unmarshal(Class resourceClass,Source source) { + try { + JAXBContext ctx = context(resourceClass); + Unmarshaller um = ctx.createUnmarshaller(); + return resourceClass.cast(um.unmarshal(source)); + } + catch(Exception e) { + throw new RuntimeException("deserialisation error",e); + } + } + + //helper + private static synchronized JAXBContext context(Class resourceClass) throws Exception { + + JAXBContext ctx = contexts.get(resourceClass); + if (ctx==null) { + ctx = JAXBContext.newInstance(resourceClass); + contexts.put(resourceClass,ctx); + } + return ctx; + + } +} diff --git a/src/main/java/org/gcube/common/resources/gcore/ScopeGroup.java b/src/main/java/org/gcube/common/resources/gcore/ScopeGroup.java new file mode 100644 index 0000000..6ec601a --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/ScopeGroup.java @@ -0,0 +1,21 @@ +package org.gcube.common.resources.gcore; + +import java.util.Collection; + +import org.gcube.common.resources.gcore.utils.ReadOnlyGroup; + +public class ScopeGroup extends ReadOnlyGroup { + + public ScopeGroup(Collection values, Class clazz) { + super(values, clazz); + } + + protected boolean add(T element) { + return base.add(element); + } + + protected boolean remove(T element) { + return base.remove(element); + } + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/ServiceEndpoint.java b/src/main/java/org/gcube/common/resources/gcore/ServiceEndpoint.java new file mode 100644 index 0000000..b23234a --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/ServiceEndpoint.java @@ -0,0 +1,710 @@ +package org.gcube.common.resources.gcore; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + +import org.gcube.common.resources.gcore.common.GHNReference; +import org.gcube.common.resources.gcore.common.Platform; +import org.gcube.common.resources.gcore.utils.Group; + +/** + * Describes endpoints of arbitrary services. + */ +@XmlRootElement(name = "Resource") +@XmlType(propOrder={"profile"}) +public class ServiceEndpoint extends Resource { + + public ServiceEndpoint() { + this.type(Type.ENDPOINT); + } + + @XmlElementRef + private Profile profile; + + public Profile profile() { + return profile; + }; + + public Profile newProfile() { + return profile = new Profile(); + }; + + @XmlRootElement(name="Profile") + @XmlType(propOrder={"category","name","version","description","platform","runtime","accessPoints"}) + public static class Profile { + + @XmlElement(name = "Category") + private String category; + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Version") + private String version; + + @XmlElement(name = "Description") + private String description; + + @XmlElementRef + private Platform platform; + + @XmlElementRef + private Runtime runtime; + + @XmlElementRef + private List accessPoints = new ArrayList(); + + public String name() { + return name; + } + + public Profile name(String name) { + this.name = name; + return this; + } + + public String description() { + return description; + } + + public Profile description(String description) { + this.description = description; + return this; + } + + public String version() { + return version; + } + + public Profile version(String version) { + this.version = version; + return this; + } + + public String category() { + return category; + } + + public Profile category(String category) { + this.category = category; + return this; + } + + public Runtime runtime() { + return runtime; + } + + public Runtime newRuntime() { + return runtime=new Runtime(); + } + + public Platform platform() { + return platform; + } + + public Platform newPlatform() { + return platform = new Platform(); + } + + public Group accessPoints() { + return new Group(accessPoints,AccessPoint.class); + } + + @Override + public String toString() { + return "[name=" + name + ", description=" + description + ", version=" + version + ", category=" + + category + ", runtime=" + runtime + ", platform=" + platform + ", accessPoints=" + accessPoints + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accessPoints == null) ? 0 : accessPoints.hashCode()); + result = prime * result + ((category == null) ? 0 : category.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((platform == null) ? 0 : platform.hashCode()); + result = prime * result + ((runtime == null) ? 0 : runtime.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Profile other = (Profile) obj; + if (accessPoints == null) { + if (other.accessPoints != null) + return false; + } else if (!accessPoints.equals(other.accessPoints)) + return false; + if (category == null) { + if (other.category != null) + return false; + } else if (!category.equals(other.category)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (platform == null) { + if (other.platform != null) + return false; + } else if (!platform.equals(other.platform)) + return false; + if (runtime == null) { + if (other.runtime != null) + return false; + } else if (!runtime.equals(other.runtime)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + + } + + @XmlRootElement(name = "RunTime") + @XmlType(propOrder={"hostedOn","ghn","status"}) + public static class Runtime { + + @XmlElement(name = "HostedOn") + private String hostedOn; + + @XmlElement(name = "GHN") + private GHNReference ghn = new GHNReference(); + + @XmlElement(name = "Status") + private String status; + + public String hostedOn() { + return hostedOn; + } + + public Runtime hostedOn(String hostedOn) { + this.hostedOn = hostedOn; + return this; + } + + public String status() { + return status; + } + + public Runtime status(String status) { + this.status = status; + return this; + } + + public String ghnId() { + return ghn.id; + } + + public Runtime ghnId(String id) { + this.ghn.id=id; + return this; + } + + //before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (ghn!=null && ghn.id==null) + ghn=null; + } + + //after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (ghn==null) + ghn = new GHNReference(); + } + + @Override + public String toString() { + return "[hostedOn=" + hostedOn + ", status=" + status + ", ghn=" + ghn + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((ghn == null) ? 0 : ghn.hashCode()); + result = prime * result + ((hostedOn == null) ? 0 : hostedOn.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Runtime other = (Runtime) obj; + if (ghn == null) { + if (other.ghn != null) + return false; + } else if (!ghn.equals(other.ghn)) + return false; + if (hostedOn == null) { + if (other.hostedOn != null) + return false; + } else if (!hostedOn.equals(other.hostedOn)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + + } + + @XmlRootElement(name = "AccessData") + @XmlType(propOrder={"username","password"}) + static class AccessData { + + @XmlElement(name = "Username") + private String username; + + @XmlElement(name = "Password") + private String password; + + public void set(String password,String username) { + this.password = password; + this.username=username; + } + + @Override + public String toString() { + return "[username=" + username + ", password=" + password + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccessData other = (AccessData) obj; + if (password == null) { + if (other.password != null) + return false; + } else if (!password.equals(other.password)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + + } + + @XmlRootElement(name = "Endpoint") + public static class Endpoint { + + @XmlAttribute(name = "EntryName") + private String name; + + + @XmlValue + private String address; + + + public String name() { + return name; + } + + public String address() { + return address; + } + + public void name(String name) { + this.name = name; + } + + public void address(String address) { + this.address = address; + } + + @Override + public String toString() { + return "[name=" + name + ", address=" + address + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((address == null) ? 0 : address.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Endpoint other = (Endpoint) obj; + if (address == null) { + if (other.address != null) + return false; + } else if (!address.equals(other.address)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Interface") + public static class Interface { + + @XmlElementRef + private Endpoint endpoint = new Endpoint(); + + public Endpoint endpoint() { + return endpoint; + } + + @Override + public String toString() { + return "[endpoints=" + endpoint + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Interface other = (Interface) obj; + if (endpoint == null) { + if (other.endpoint != null) + return false; + } else if (!endpoint.equals(other.endpoint)) + return false; + return true; + } + + + + } + + @XmlRootElement(name = "AccessPoint") + @XmlType(propOrder={"description","itfce","accessData","properties"}) + public static class AccessPoint { + + @XmlElement(name = "Description") + private String description; + + @XmlElementRef + private Interface itfce = new Interface(); + + @XmlElementRef + private AccessData accessData; + + @XmlElementWrapper(name = "Properties") + @XmlElementRef + private List properties = new ArrayList(); + + //before serialisation, we null the optional fields + void beforeMarshal(Marshaller marshaller) { + if (properties!=null && properties.isEmpty()) + properties=null; + } + + //after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (properties==null) + properties = new ArrayList(); + } + + public String description() { + return description; + } + + public AccessPoint description(String description) { + this.description = description; + return this; + } + + public String username() { + return accessData.username; + } + + public String password() { + return accessData.password; + } + + public AccessPoint credentials(String password,String username) { + accessData = new AccessData(); + accessData.password=password; + accessData.username=username; + return this; + } + + public String name() { + return itfce.endpoint().name(); + } + + public AccessPoint name(String address) { + itfce.endpoint().name(address); + return this; + } + + public String address() { + return itfce.endpoint().address(); + } + + public AccessPoint address(String address) { + itfce.endpoint().address(address); + return this; + } + + public Group properties() { + return new Group(properties,Property.class); + } + + public Map propertyMap(){ + Map map=new HashMap(); + for (Property p: properties){ + if(p.name()!=null) + map.put(p.name(),p); + } + return map; + } + + @Override + public String toString() { + return "AccessPoint [description=" + description + ", accessData=" + accessData + ", interface=" + itfce + + ", properties=" + properties + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accessData == null) ? 0 : accessData.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((itfce == null) ? 0 : itfce.hashCode()); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccessPoint other = (AccessPoint) obj; + if (accessData == null) { + if (other.accessData != null) + return false; + } else if (!accessData.equals(other.accessData)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (itfce == null) { + if (other.itfce != null) + return false; + } else if (!itfce.equals(other.itfce)) + return false; + if (properties == null) { + if (other.properties != null) + return false; + } else if (!properties.equals(other.properties)) + return false; + return true; + } + + + } + + + @XmlRootElement(name="Property") + @XmlType(propOrder={"name","value"}) + public static class Property { + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Value") + private PropertyValue value = new PropertyValue(); + + public String name() { + return name; + } + + public Property nameAndValue(String name,String value) { + this.name = name; + this.value.value=value; + return this; + } + + public boolean isEncrypted() { + return value.encrypted; + } + + public Property encrypted(boolean encrypted) { + this.value.encrypted = encrypted; + return this; + } + + public String value() { + return value.value; + } + + @Override + public String toString() { + return "Property [name=" + name + ", value=" + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Property other = (Property) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + + + } + + public static class PropertyValue { + + @XmlAttribute(name="encrypted") + private boolean encrypted; + + @XmlValue + private String value; + + + @Override + public String toString() { + return "[encrypted=" + encrypted + ", value=" + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (encrypted ? 1231 : 1237); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PropertyValue other = (PropertyValue) obj; + if (encrypted != other.encrypted) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + + + } +} diff --git a/src/main/java/org/gcube/common/resources/gcore/ServiceInstance.java b/src/main/java/org/gcube/common/resources/gcore/ServiceInstance.java new file mode 100644 index 0000000..52bd58e --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/ServiceInstance.java @@ -0,0 +1,377 @@ +package org.gcube.common.resources.gcore; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.ws.EndpointReference; +import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder; + +import org.gcube.common.resources.gcore.common.AnyWrapper; +import org.gcube.common.resources.gcore.utils.Group; +import org.gcube.common.resources.gcore.utils.Utils; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Describes instances of stateful services. + * + */ +@XmlRootElement(name="Document") +public class ServiceInstance { + + @XmlElement(name="ID") + private String id; + + @XmlElement(name="Source") + private URI endpoint; + + @XmlElement(name="SourceKey") + private String key; + + @XmlElementRef + private Reference keyElement; + + @XmlRootElement(name="CompleteSourceKey") + private static class Reference extends AnyWrapper {} + + @XmlElement(name="TerminationTime") + private long terminationTime; + + @XmlElement(name="LastUpdateMs") + private long lastUpdate; + + @XmlElement(name="PublicationMode") + private String publicationMode; + + @XmlElementRef + private Properties properties; + + public String id() { + return id; + } + + public ServiceInstance id(String id) { + this.id = id; + return this; + } + + public URI endpoint() { + return endpoint; + } + + public ServiceInstance endpoint(URI endpoint) { + this.endpoint = endpoint; + return this; + } + + public String key() { + return key; + } + + public ServiceInstance key(String key) { + this.key = key; + return this; + } + + + public EndpointReference reference() { + + return new W3CEndpointReferenceBuilder().address(endpoint.toString()).referenceParameter(keyElement.root()).build(); + } + + public long terminationTime() { + return terminationTime; + } + + public ServiceInstance terminationTime(long terminationTime) { + this.terminationTime = terminationTime; + return this; + } + + public long lastUpdate() { + return lastUpdate; + } + + public ServiceInstance lastUpdate(long lastUpdate) { + this.lastUpdate = lastUpdate; + return this; + } + + public String publicationMode() { + return publicationMode; + } + + public ServiceInstance publicationMode(String publicationMode) { + this.publicationMode = publicationMode; + return this; + } + + public Properties properties() { + return properties; + } + + public Properties newProperties() { + return properties=new Properties(); + } + + @Override + public String toString() { + return "ServiceInstance [id=" + id + ", endpoint=" + endpoint + ", key=" + key + ", reference=" + reference() + + ", terminationTime=" + terminationTime + ", lastUpdate=" + lastUpdate + ", publicationMode=" + + publicationMode + ", properties=" + properties + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + (int) (lastUpdate ^ (lastUpdate >>> 32)); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); + result = prime * result + ((publicationMode == null) ? 0 : publicationMode.hashCode()); + result = prime * result + ((keyElement == null) ? 0 : keyElement.hashCode()); + result = prime * result + (int) (terminationTime ^ (terminationTime >>> 32)); + return result; + } + + //NOTE: manually adapted, do not regenerate blindly + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceInstance other = (ServiceInstance) obj; + if (endpoint == null) { + if (other.endpoint != null) + return false; + } else if (!endpoint.equals(other.endpoint)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + if (lastUpdate != other.lastUpdate) + return false; + if (properties == null) { + if (other.properties != null) + return false; + } else if (!properties.equals(other.properties)) + return false; + if (publicationMode == null) { + if (other.publicationMode != null) + return false; + } else if (!publicationMode.equals(other.publicationMode)) + return false; + if (keyElement == null) { + if (other.keyElement != null) + return false; + } else if (!keyElement.equals(other.keyElement)) + return false; + if (terminationTime != other.terminationTime) + return false; + return true; + } + + @XmlRootElement(name="Data") + public static class Properties { + + public static final String PROVIDER_NS="http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider"; + + @XmlElement(name="GHN",namespace=PROVIDER_NS) + private String nodeId; + + @XmlElement(name="RI",namespace=PROVIDER_NS) + private String endpointId; + + @XmlElement(name="ServiceID",namespace=PROVIDER_NS) + private String serviceId; + + @XmlElement(name="ServiceClass",namespace=PROVIDER_NS) + private String serviceClass; + + @XmlElement(name="ServiceName",namespace=PROVIDER_NS) + private String serviceName; + + @XmlElement(name="Scope",namespace=PROVIDER_NS) + private List scopes = new ArrayList(); + + //this is the element we return to client for modifications + private Element root; + + @XmlAnyElement + private List customProperties; + + public String nodeId() { + return nodeId; + } + + public Properties nodeId(String nodeId) { + this.nodeId = nodeId; + return this; + } + + public String endpointId() { + return endpointId; + } + + public Properties endpointId(String endpointId) { + this.endpointId = endpointId; + return this; + } + + public String serviceId() { + return serviceId; + } + + public Properties serviceId(String serviceId) { + this.serviceId = serviceId; + return this; + } + + public String serviceClass() { + return serviceClass; + } + + public Properties serviceClass(String serviceClass) { + this.serviceClass = serviceClass; + return this; + } + + public String serviceName() { + return serviceName; + } + + public Properties serviceName(String serviceName) { + this.serviceName = serviceName; + return this; + } + + public Collection scopes() { + return new Group(scopes,String.class); + } + + public Element customProperties() { + return root; + } + + public Element newCustomProperties() { + return root = Utils.newDocument().getDocumentElement(); + } + + //after deserialisation, we link the elements to the root + void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if (customProperties!=null) { + newCustomProperties(); + for (Element e: customProperties) + root.appendChild(root.getOwnerDocument().adoptNode(e)); + } + customProperties=null; + } + + //before serialisation we copy the child elements of the root + void beforeMarshal(Marshaller marshaller) { + if (root!=null) { + customProperties = new ArrayList(); + NodeList list = root.getChildNodes(); + for (int i=0;i dependencies = new LinkedHashSet(); + + @XmlElementWrapper(name = "Packages") + @XmlElementRefs({ @XmlElementRef(type = ServicePackage.class), @XmlElementRef(type = PluginPackage.class), + @XmlElementRef(type = GenericPackage.class) }) + private Set> packages = new LinkedHashSet>(); + + @XmlElement(name = "SpecificData") + private SpecificData specificData; + + public String description() { + return description; + } + + public Profile description(String description) { + this.description = description; + return this; + } + + public String softwareClass() { + return clazz; + } + + public Profile softwareClass(String clazz) { + this.clazz = clazz; + return this; + } + + public String softwareName() { + return name; + } + + public Profile softwareName(String name) { + this.name = name; + return this; + } + + public Configuration configuration() { + return configuration; + } + + public boolean hasConfiguration() { + return configuration != null; + } + + public Configuration newConfiguration() { + return configuration = new Configuration(); + } + + @SuppressWarnings({"rawtypes","unchecked"}) + public Group> packages() { + return new Group>(packages,(Class)SoftwarePackage.class); //wrap if needed + } + + public Map> softwarePackageMap(){ + Map> map=new HashMap>(); + for (SoftwarePackage sp: packages){ + if(sp.name()!=null) + map.put(sp.name(),sp); + } + return map; + } + + + public Element specificData() { + return specificData==null?null:specificData.root(); + } + + public boolean hasSpecificData() { + return specificData != null; + } + + public Element newSpecificData() { + specificData = new SpecificData(); + return specificData.root(); + } + + public Group dependencies() { + return new Group(dependencies, Dependency.class); + } + + @Override + public String toString() { + return "Profile [description=" + description + ", clazz=" + clazz + ", name=" + name + ", configuration=" + + configuration + ", dependency=" + dependencies + ", packages=" + packages + ", specificData=" + + specificData + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clazz == null) ? 0 : clazz.hashCode()); + result = prime * result + ((configuration == null) ? 0 : configuration.hashCode()); + result = prime * result + ((dependencies == null) ? 0 : dependencies.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((packages == null) ? 0 : packages.hashCode()); + result = prime * result + ((specificData == null) ? 0 : specificData.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + void beforeMarshal(Marshaller marshaller) { + if (dependencies!=null && dependencies.isEmpty()) + dependencies = null; + if (packages!=null && packages.isEmpty()) + packages = null; + } + + // after serialisation, we reinitialise them + void afterMarshal(Marshaller marshaller) { + if (dependencies == null) + dependencies = new LinkedHashSet(); + if (packages == null) + packages = new LinkedHashSet>(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Profile other = (Profile) obj; + if (clazz == null) { + if (other.clazz != null) + return false; + } else if (!clazz.equals(other.clazz)) + return false; + if (configuration == null) { + if (other.configuration != null) + return false; + } else if (!configuration.equals(other.configuration)) + return false; + if (dependencies == null) { + if (other.dependencies != null) + return false; + } else if (!dependencies.equals(other.dependencies)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (packages == null) { + if (other.packages != null) + return false; + } else if (!packages.equals(other.packages)) + return false; + if (specificData == null) { + if (other.specificData != null) + return false; + } else if (!specificData.equals(other.specificData)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + @XmlRootElement(name = "SpecificData") + public static class SpecificData extends AnyMixedWrapper { + } + + @XmlRootElement(name = "Configuration") + @XmlType(propOrder = { "staticConfigurations" }) + public static class Configuration { + + @XmlElementRef + private StaticConfigurations staticConfigurations; + + public StaticConfigurations staticConfiguration() { + return staticConfigurations; + } + + public boolean hasStaticConfigurations() { + return staticConfigurations != null; + } + + public StaticConfigurations newStaticConfiguration() { + return staticConfigurations = new StaticConfigurations(); + } + + @Override + public String toString() { + return " [static=" + staticConfigurations + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((staticConfigurations == null) ? 0 : staticConfigurations.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Configuration other = (Configuration) obj; + if (staticConfigurations == null) { + if (other.staticConfigurations != null) + return false; + } else if (!staticConfigurations.equals(other.staticConfigurations)) + return false; + return true; + } + + @XmlRootElement(name = "Static") + @XmlType(propOrder = { "configurations", "template" }) + public static class StaticConfigurations { + + @XmlElementWrapper(name = "Configs") + @XmlElementRef + private List configurations = new ArrayList(); + + @XmlElementRef + private Template template; + + public Group configurations() { + return new Group(configurations, StaticConfiguration.class); + } + + public Template template() { + return template; + } + + public boolean hasTemplate() { + return template != null; + } + + public Template newTemplate() { + template = new Template(); + return template; + } + + @Override + public String toString() { + return "[configurations=" + configurations + ", template=" + template + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((configurations == null) ? 0 : configurations.hashCode()); + result = prime * result + ((template == null) ? 0 : template.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StaticConfigurations other = (StaticConfigurations) obj; + if (configurations == null) { + if (other.configurations != null) + return false; + } else if (!configurations.equals(other.configurations)) + return false; + if (template == null) { + if (other.template != null) + return false; + } else if (!template.equals(other.template)) + return false; + return true; + } + + @XmlRootElement(name = "Config") + @XmlType(propOrder = { "file", "description", "label" }) + public static class StaticConfiguration { + + @XmlElement(name = "File") + private String file; + + @XmlElement(name = "Description") + private String description; + + @XmlElement(name = "Label") + private String label; + + @XmlAttribute(name = "default") + private boolean default_; + + public boolean isDefault() { + return default_; + } + + public StaticConfiguration isDefault(boolean value) { + this.default_=value; + return this; + } + + public String file() { + return file; + } + + public StaticConfiguration file(String file) { + this.file = file; + return this; + } + + public String description() { + return description; + } + + public StaticConfiguration description(String description) { + this.description = description; + return this; + } + + public String label() { + return label; + } + + public StaticConfiguration label(String label) { + this.label = label; + return this; + } + + @Override + public String toString() { + return "Configuration [file=" + file + ", description=" + description + ", label=" + label + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (default_ ? 1231 : 1237); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((file == null) ? 0 : file.hashCode()); + result = prime * result + ((label == null) ? 0 : label.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StaticConfiguration other = (StaticConfiguration) obj; + if (default_ != other.default_) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (file == null) { + if (other.file != null) + return false; + } else if (!file.equals(other.file)) + return false; + if (label == null) { + if (other.label != null) + return false; + } else if (!label.equals(other.label)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Template") + public static class Template { + + @XmlElementWrapper(name = "Params") + @XmlElementRef + private List params = new ArrayList(); + + public Group params() { + return new Group(params, ConfigurationParameter.class); + } + + public Map paramsMap(){ + Map map=new HashMap(); + for (ConfigurationParameter cp: params){ + if(cp.name()!=null) + map.put(cp.name(),cp); + } + return map; + } + + @Override + public String toString() { + return "Template [params=" + params + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((params == null) ? 0 : params.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Template other = (Template) obj; + if (params == null) { + if (other.params != null) + return false; + } else if (!params.equals(other.params)) + return false; + return true; + } + + @XmlRootElement(name = "Param") + public static class ConfigurationParameter { + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Description") + private String description; + + @XmlElementWrapper(name = "AllowedValues") + @XmlElementRef + private List allowedValues = new ArrayList(); + + public String name() { + return name; + } + + public ConfigurationParameter name(String name) { + this.name = name; + return this; + } + + public String description() { + return description; + } + + public ConfigurationParameter description(String description) { + this.description = description; + return this; + } + + public Group allowedValues() { + return new Group(allowedValues, AllowedValue.class); + } + + @Override + public String toString() { + return "Parameter [name=" + name + ", description=" + description + ", allowedValues=" + + allowedValues + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((allowedValues == null) ? 0 : allowedValues.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConfigurationParameter other = (ConfigurationParameter) obj; + if (allowedValues == null) { + if (other.allowedValues != null) + return false; + } else if (!allowedValues.equals(other.allowedValues)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @XmlRootElement(name = "Value") + public static class AllowedValue { + + @XmlElement(name = "Description") + private String description; + + @XmlElement(name = "Literal") + private String literal; + + @XmlElement(name = "Label") + private String label; + + @XmlAttribute(name = "default") + private boolean isDefault; + + public String description() { + return description; + } + + public AllowedValue description(String desc) { + this.description = desc; + return this; + } + + public String literal() { + return literal; + } + + public AllowedValue literal(String lit) { + this.literal = lit; + return this; + } + + public String label() { + return label; + } + + public AllowedValue label(String label) { + this.label = label; + return this; + } + + public boolean isDefault() { + return isDefault; + } + + public AllowedValue isDefault(boolean def) { + this.isDefault = def; + return this; + } + + @Override + public String toString() { + return " [description=" + description + ", literal=" + literal + ", label=" + label + + ", isDefault=" + isDefault + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + (isDefault ? 1231 : 1237); + result = prime * result + ((label == null) ? 0 : label.hashCode()); + result = prime * result + ((literal == null) ? 0 : literal.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AllowedValue other = (AllowedValue) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (isDefault != other.isDefault) + return false; + if (label == null) { + if (other.label != null) + return false; + } else if (!label.equals(other.label)) + return false; + if (literal == null) { + if (other.literal != null) + return false; + } else if (!literal.equals(other.literal)) + return false; + return true; + } + + } + + } + } + + } + + } + + @XmlRootElement(name = "Dependency") + @XmlType(propOrder = { "clazz", "name", "version" }) + public static class Dependency { + + @XmlElement(name = "Class") + private String clazz; + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Version") + private String version; + + public String serviceClass() { + return clazz; + } + + public Dependency serviceClass(String serviceClass) { + this.clazz=serviceClass; + return this; + } + + public String serviceName() { + return name; + } + + public Dependency serviceName(String name) { + this.name = name; + return this; + } + + public String version() { + return version; + } + + public Dependency version(String version) { + this.version = version; + return this; + } + + @Override + public String toString() { + return "[clazz=" + clazz + ", name=" + name + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clazz == null) ? 0 : clazz.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Dependency other = (Dependency) obj; + if (clazz == null) { + if (other.clazz != null) + return false; + } else if (!clazz.equals(other.clazz)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + } + + @XmlRootElement(name = "Software") + @XmlType(propOrder = { "type", "entryPoints", "files", "uri" }) + public static class GenericPackage extends SoftwarePackage { + + @XmlElement(name = "EntryPoint") + private Set entryPoints = new LinkedHashSet(); + + @XmlElement(name = "URI") + private URI uri; + + @XmlElementWrapper(name = "Files") + @XmlElement(name = "File") + private Set files = new LinkedHashSet(); + + + @SuppressWarnings("unused") + private void beforeMarshal(Marshaller marshaller) { + super.beforeMarshal(marshaller); + if (files.isEmpty()) + files = null; + } + + // after serialisation, we reinitialise them + @SuppressWarnings("unused") + private void afterMarshal(Marshaller marshaller) { + super.afterMarshal(marshaller); + if (files == null) + files = new LinkedHashSet(); + } + + @XmlElement(name = "Type") + private Type type; + + @Override + protected GenericPackage _this() { + return this; + } + + public Collection entryPoints() { + return new Group(entryPoints,String.class); + } + + public Collection files() { + return new Group(files,String.class); + } + + public Type type() { + return type; + } + + public GenericPackage type(Type type) { + this.type = type; + return this; + } + + public URI uri() { + return uri; + } + + public GenericPackage uri(URI uri) { + this.uri = uri; + return this; + } + + @Override + public String toString() { + return "Software [entryPoint=" + entryPoints + ", uri=" + uri + ", files=" + files + ", type=" + type + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((entryPoints == null) ? 0 : entryPoints.hashCode()); + result = prime * result + ((files == null) ? 0 : files.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + GenericPackage other = (GenericPackage) obj; + if (entryPoints == null) { + if (other.entryPoints != null) + return false; + } else if (!entryPoints.equals(other.entryPoints)) + return false; + if (files == null) { + if (other.files != null) + return false; + } else if (!files.equals(other.files)) + return false; + if (type != other.type) + return false; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; + } + + @XmlType(name = "Type") + @XmlEnum + public enum Type { + + library, application, plugin, webapplication; + + public String value() { + return name(); + } + + public static Type fromValue(String v) { + return valueOf(v); + } + + } + + } + + @XmlRootElement(name = "Main") + @XmlType(propOrder = { "archive", "functions", "portTypes" }) + public static class ServicePackage extends SoftwarePackage { + + @XmlElement(name="GARArchive") + private String archive; + + @XmlElementWrapper(name = "ServiceEquivalenceFunctions") + @XmlElementRef + private Set functions = new LinkedHashSet(); + + @XmlElementRef + private Set portTypes = new LinkedHashSet(); + + protected ServicePackage _this() { + return this; + }; + + @SuppressWarnings("unused") + private void beforeMarshal(Marshaller marshaller) { + super.beforeMarshal(marshaller); + if (functions.isEmpty()) + functions=null; + } + + // after serialisation, we reinitialise them + @SuppressWarnings("unused") + private void afterMarshal(Marshaller marshaller) { + super.afterMarshal(marshaller); + if (functions == null) + functions = new LinkedHashSet(); + } + + public String archive() { + return archive; + } + + public ServicePackage archive(String archive) { + this.archive = archive; + return this; + } + + public Group functions() { + return new Group(functions, Function.class); + } + + public Group portTypes() { + return new Group(portTypes, PortType.class); + } + + public Map portTypeMap(){ + Map map=new HashMap(); + for (PortType p: portTypes){ + if(p.name()!=null) + map.put(p.name(),p); + } + return map; + } + + + @Override + public String toString() { + return "Main [garArchive=" + archive + ", function=" + functions + ", portTypes=" + portTypes + "]"; + } + + @XmlRootElement(name = "PortType") + public static class PortType { + + @XmlElement(name = "Name") + private String name; + + @XmlElementRef + private Security security; + + @XmlElementRef + private Wsdl wsdl; + + public String name() { + return name; + } + + public PortType name(String name) { + this.name = name; + return this; + } + + public Security security() { + return security; + } + + public Security newSecurity() { + security = new Security(); + return security; + } + + public Element wsdl() { + return wsdl==null?null:wsdl.root(); + } + + public Element newWsdl() { + return (this.wsdl=new Wsdl()).root(); + } + + + + @Override + public String toString() { + return " [name=" + name + ", security=" + security + ", wsdl=" + wsdl + "]"; + } + + @XmlRootElement(name = "Security") + public static class Security { + + @XmlElement(name = "Descriptor") + private SecurityDescriptor descriptor; + + @XmlElementWrapper(name = "Operations") + @XmlElement(name = "Operation") + private List operations; + + public Element descriptor() { + return descriptor==null?null:descriptor.root(); + } + + public Element newDescriptor() { + return (this.descriptor = new SecurityDescriptor()).root(); + } + + public Group operations() { + return new Group(operations, Operation.class); + } + + public Map portTypeMap(){ + Map map=new HashMap(); + for (Operation o: operations){ + if(o.name()!=null) + map.put(o.name(),o); + } + return map; + } + + @XmlRootElement(name = "Descriptor") + public static class SecurityDescriptor extends AnyWrapper{} + + @XmlRootElement(name = "Operation") + public static class Operation { + + @XmlElement(name = "id") + private String id; + + @XmlAttribute(name = "name") + private String name; + + @XmlElement(name = "description") + private String description; + + @XmlElementRef + private Roles roles; + + public String id() { + return id; + } + + public Operation id(String id) { + this.id = id; + return this; + } + + public String name() { + return name; + } + + public Operation name(String name) { + this.name = name; + return this; + } + + public String description() { + return description; + } + + public Operation description(String desc) { + this.description = desc; + return this; + } + + public Roles roles() { + return roles; + } + + public Roles newRoles() { + roles = new Roles(); + return roles; + } + + @Override + public String toString() { + return " [id=" + id + ", name=" + name + ", description=" + description + ", roles=" + + roles + "]"; + } + + @XmlRootElement(name = "Roles") + public static class Roles { + + @XmlElement(name = "Role") + private List roles = new ArrayList(); + + public Group role() { + return new Group(roles, Role.class); + } + + @Override + public String toString() { + return " [role=" + roles + "]"; + } + + @XmlRootElement(name = "Role") + public static class Role { + + @XmlAttribute(name = "value") + private String value; + + public String value() { + return value; + } + + public Role value(String value) { + this.value = value; + return this; + } + + @Override + public String toString() { + return " [value=" + value + "]"; + } + + } + + } + } + + } + + } + + @XmlRootElement(name = "Function") + @XmlType(propOrder = { "name", "formalParameters", "body" }) + public static class Function { + + @XmlElement(name = "Name") + private String name; + + @XmlElementWrapper(name = "FormalParameters") + @XmlElement(name = "Name") + private List formalParameters = new ArrayList(); + + @XmlElementRef + private Body body; + + public String name() { + return name; + } + + public Function name(String name) { + this.name = name; + return this; + } + + public List formalParameters() { + return formalParameters; + } + + public Group functions() { + return new Group(formalParameters, String.class); + } + + public Element body() { + return body==null?null:body.root(); + } + + public String bodyAsString() { + return body==null?null:body.asString(); + } + + public Element newBody() { + return (body = new Body()).root(); + } + + + public Function newBody(String text) { + body = new Body(); + body.setString(text); + return this; + } + + @Override + public String toString() { + return " [name=" + name + ", formalParametersName=" + formalParameters + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((body == null) ? 0 : body.hashCode()); + result = prime * result + ((formalParameters == null) ? 0 : formalParameters.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Function other = (Function) obj; + if (body == null) { + if (other.body != null) + return false; + } else if (!body.equals(other.body)) + return false; + if (formalParameters == null) { + if (other.formalParameters != null) + return false; + } else if (!formalParameters.equals(other.formalParameters)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @XmlRootElement(name="Body") + public static class Body extends AnyMixedWrapper{} + } + + } + + @XmlRootElement(name = "WSDL") + public static class Wsdl extends AnyWrapper {} + + @XmlRootElement(name = "Plugin") + @XmlType(propOrder = { "target","entryPoint","files"}) + public static class PluginPackage extends SoftwarePackage { + + @XmlElementRef + private TargetService target; + + + @XmlElementWrapper(name = "Files") + @XmlElement(name = "File") + private Set files = new LinkedHashSet(); + + @XmlElement(name = "EntryPoint") + private String entryPoint; + + @Override + protected PluginPackage _this() { + return this; + } + + @SuppressWarnings("unused") + private void beforeMarshal(Marshaller marshaller) { + super.beforeMarshal(marshaller); + if (files.isEmpty()) + files = null; + } + + // after serialisation, we reinitialise them + @SuppressWarnings("unused") + private void afterMarshal(Marshaller marshaller) { + super.afterMarshal(marshaller); + if (files == null) + files = new LinkedHashSet(); + } + + + public TargetService targetService() { + return target; + } + + public TargetService newTargetService() { + target = new TargetService(); + return target; + } + + public String entryPoint() { + return entryPoint; + } + + public PluginPackage entryPoint(String entry) { + this.entryPoint=entry; + return this; + } + + public Collection files() { + return new Group(files,String.class); + } + + @Override + public String toString() { + return "Plugin [service=" + target + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((target == null) ? 0 : target.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + PluginPackage other = (PluginPackage) obj; + if (target == null) { + if (other.target != null) + return false; + } else if (!target.equals(other.target)) + return false; + return true; + } + + @XmlRootElement(name = "TargetService") + public static class TargetService { + + @XmlElementRef + private Service service; + + @XmlElement(name = "Package") + private String package_; + + @XmlElement(name = "Version") + private String version; + + public Service service() { + return service; + } + + public Service newService() { + service = new Service(); + return service; + } + + public String servicePackage() { + return package_; + } + + public TargetService servicePackage(String pack) { + this.package_ = pack; + return this; + } + + public String version() { + return version; + } + + public TargetService version(String version) { + this.version = version; + return this; + } + + @Override + public String toString() { + return " [service=" + service + ", package_=" + package_ + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((package_ == null) ? 0 : package_.hashCode()); + result = prime * result + ((service == null) ? 0 : service.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TargetService other = (TargetService) obj; + if (package_ == null) { + if (other.package_ != null) + return false; + } else if (!package_.equals(other.package_)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + @XmlRootElement(name = "Service") + public static class Service { + + @XmlElement(name = "Class") + private String clazz; + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Version") + private String version; + + public String serviceClass() { + return clazz; + } + + public Service serviceClass(String clazz) { + this.clazz = clazz; + return this; + } + + public String serviceName() { + return name; + } + + public Service serviceName(String name) { + this.name = name; + return this; + } + + public String version() { + return version; + } + + public Service version(String version) { + this.version = version; + return this; + } + + @Override + public String toString() { + return " [class=" + clazz + ", name=" + name + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clazz == null) ? 0 : clazz.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Service other = (Service) obj; + if (clazz == null) { + if (other.clazz != null) + return false; + } else if (!clazz.equals(other.clazz)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + } + + } + + } + + @XmlType(propOrder = { "description", "name", "version", "coordinates", "targetPlatform", "multiversion", + "mandatory", "shareable", "ghnRequirements", "installScripts", "uninstallScripts", "rebootScripts" , "dependencies", "specificData" }) + public abstract static class SoftwarePackage> { + + @XmlElement(name = "Description") + private String description; + + @XmlElement(name = "Name") + private String name; + + @XmlElement(name = "Version") + private String version; + + @XmlElementRef + private MavenCoordinates coordinates; + + @XmlElementRef + private TargetPlatform targetPlatform; + + @XmlElement(name = "MultiVersion") + private BooleanWrapper multiversion = new BooleanWrapper(true); + + @XmlElement(name = "Mandatory") + private LevelWrapper mandatory; + + @XmlElement(name = "Shareable") + private LevelWrapper shareable; + + @XmlElementWrapper(name = "GHNRequirements") + @XmlElementRef + private Set ghnRequirements = new LinkedHashSet(); + + @XmlElementRef + private InstallScripts installScripts = new InstallScripts(); + + @XmlElementRef + private UninstallScripts uninstallScripts = new UninstallScripts(); + + @XmlElementRef + private RebootScripts rebootScripts = new RebootScripts(); + + @XmlElementWrapper(name = "Dependencies") + @XmlElementRef + private Set dependencies = new LinkedHashSet(); + + @XmlElement(name = "SpecificData") + private SpecificData specificData; + + + protected abstract T _this(); + + @SuppressWarnings("all") + private void beforeMarshal(Marshaller marshaller) { + if (ghnRequirements.isEmpty()) + ghnRequirements=null; + if (installScripts.files.isEmpty()) + installScripts=null; + if (uninstallScripts.files.isEmpty()) + uninstallScripts=null; + if (rebootScripts.files.isEmpty()) + rebootScripts=null; + if (dependencies.isEmpty()) + dependencies = null; + } + + // after serialisation, we reinitialise them + @SuppressWarnings("all") + private void afterMarshal(Marshaller marshaller) { + if (ghnRequirements == null) + ghnRequirements = new LinkedHashSet(); + if (installScripts == null) + installScripts = new InstallScripts(); + if (uninstallScripts == null) + uninstallScripts = new UninstallScripts(); + if (rebootScripts == null) + rebootScripts = new RebootScripts(); + if (dependencies == null) + dependencies = new LinkedHashSet(); + } + + + public String description() { + return description; + } + + public T description(String description) { + this.description = description; + return _this(); + } + + public String name() { + return name; + } + + public T name(String name) { + this.name = name; + return _this(); + } + + public String version() { + return version; + } + + public T version(String version) { + this.version = version; + return _this(); + } + + public MavenCoordinates coordinates() { + return coordinates; + } + + public boolean hasCoordinates() { + return coordinates != null; + } + + public MavenCoordinates newCoordinates() { + coordinates = new MavenCoordinates(); + return coordinates; + } + + public TargetPlatform targetPlatform() { + return targetPlatform; + } + + public boolean hasTargetPlatform() { + return targetPlatform != null; + } + + public TargetPlatform newTargetPlatform() { + targetPlatform = new TargetPlatform(); + return targetPlatform; + } + + public boolean isMultiVersion() { + return multiversion.value; + } + + public T multiVersion(boolean value) { + multiversion.value=value; + return _this(); + } + + public Level mandatory() { + return mandatory.level; + } + + public LevelWrapper newMandatory() { + mandatory = new LevelWrapper(Level.NONE); + return mandatory; + } + + public Level shareable() { + return shareable.level; + } + + public boolean hasShareable() { + return shareable != null; + } + + public LevelWrapper newShareable() { + shareable = new LevelWrapper(Level.VO); + return shareable; + } + + public Group ghnRequirements() { + return new Group(ghnRequirements, Requirement.class); + } + + + public Map ghnRequirementsMap(){ + Map map=new HashMap(); + for (Requirement r: ghnRequirements){ + if(r.key()!=null) + map.put(r.key(),r); + } + return map; + } + + + + public Collection installScripts() { + return new Group(installScripts.files,String.class); + } + + public Collection uninstallScripts() { + return new Group(uninstallScripts.files,String.class); + } + + public Collection rebootScripts() { + return new Group(rebootScripts.files,String.class); + } + + public boolean hasRebootScripts() { + return rebootScripts != null; + } + + @XmlRootElement(name = "InstallScripts") + public static class InstallScripts extends FileList { + } + + @XmlRootElement(name = "UninstallScripts") + public static class UninstallScripts extends FileList { + } + + @XmlRootElement(name = "RebootScripts") + public static class RebootScripts extends FileList { + } + + public Group dependencies() { + return new Group(dependencies, PackageDependency.class); + } + + public Element specificData() { + return specificData==null?null:specificData.root(); + } + + public String specificDataAsString() { + return specificData==null?null:specificData.asString(); + } + + public boolean hasSpecificData() { + return specificData != null; + } + + public Element newSpecificData() { + specificData = new SpecificData(); + return specificData.root(); + } + + public T newSpecificData(String text) { + specificData = new SpecificData(); + specificData.setString(text); + return _this(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((coordinates == null) ? 0 : coordinates.hashCode()); + result = prime * result + ((dependencies == null) ? 0 : dependencies.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((ghnRequirements == null) ? 0 : ghnRequirements.hashCode()); + result = prime * result + ((installScripts == null) ? 0 : installScripts.hashCode()); + result = prime * result + ((mandatory == null) ? 0 : mandatory.hashCode()); + result = prime * result + ((multiversion == null) ? 0 : multiversion.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((rebootScripts == null) ? 0 : rebootScripts.hashCode()); + result = prime * result + ((shareable == null) ? 0 : shareable.hashCode()); + result = prime * result + ((specificData == null) ? 0 : specificData.hashCode()); + result = prime * result + ((targetPlatform == null) ? 0 : targetPlatform.hashCode()); + result = prime * result + ((uninstallScripts == null) ? 0 : uninstallScripts.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SoftwarePackage other = (SoftwarePackage) obj; + if (coordinates == null) { + if (other.coordinates != null) + return false; + } else if (!coordinates.equals(other.coordinates)) + return false; + if (dependencies == null) { + if (other.dependencies != null) + return false; + } else if (!dependencies.equals(other.dependencies)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (ghnRequirements == null) { + if (other.ghnRequirements != null) + return false; + } else if (!ghnRequirements.equals(other.ghnRequirements)) + return false; + if (installScripts == null) { + if (other.installScripts != null) + return false; + } else if (!installScripts.equals(other.installScripts)) + return false; + if (mandatory == null) { + if (other.mandatory != null) + return false; + } else if (!mandatory.equals(other.mandatory)) + return false; + if (multiversion == null) { + if (other.multiversion != null) + return false; + } else if (!multiversion.equals(other.multiversion)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (rebootScripts == null) { + if (other.rebootScripts != null) + return false; + } else if (!rebootScripts.equals(other.rebootScripts)) + return false; + if (shareable == null) { + if (other.shareable != null) + return false; + } else if (!shareable.equals(other.shareable)) + return false; + if (specificData == null) { + if (other.specificData != null) + return false; + } else if (!specificData.equals(other.specificData)) + return false; + if (targetPlatform == null) { + if (other.targetPlatform != null) + return false; + } else if (!targetPlatform.equals(other.targetPlatform)) + return false; + if (uninstallScripts == null) { + if (other.uninstallScripts != null) + return false; + } else if (!uninstallScripts.equals(other.uninstallScripts)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + @Override + public String toString() { + return "[description=" + description + + ", name=" + name + ", version=" + version + + ", coordinates=" + coordinates + ", targetPlatform=" + + targetPlatform + ", multiversion=" + multiversion + + ", mandatory=" + mandatory + ", shareable=" + + shareable + ", ghnRequirements=" + ghnRequirements + + ", installScripts=" + installScripts + + ", uninstallScripts=" + uninstallScripts + + ", rebootScripts=" + rebootScripts + + ", dependencies=" + dependencies + "]" + ", specificData=" + + specificData + "]"; + } + + @XmlRootElement(name = "MavenCoordinates") + @XmlType(propOrder = { "groupId", "artifactId", "version", "classifier" }) + public static class MavenCoordinates { + + @XmlElement(name = "groupId") + private String groupId; + + @XmlElement(name = "artifactId") + private String artifactId; + + @XmlElement(name = "version") + private String version; + + @XmlElement(name = "classifier") + private String classifier; + + public String groupId() { + return groupId; + } + + public MavenCoordinates groupId(String gid) { + this.groupId = gid; + return this; + } + + public String artifactId() { + return artifactId; + } + + public MavenCoordinates artifactId(String aId) { + this.artifactId = aId; + return this; + } + + public String version() { + return version; + } + + public MavenCoordinates version(String version) { + this.version = version; + return this; + } + + public String classifier() { + return classifier; + } + + public MavenCoordinates classifier(String classifier) { + this.classifier = classifier; + return this; + } + + @Override + public String toString() { + return " [groupId=" + groupId + ", artifactId=" + artifactId + ", version=" + version + + ", classifier=" + classifier + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((artifactId == null) ? 0 : artifactId.hashCode()); + result = prime * result + ((classifier == null) ? 0 : classifier.hashCode()); + result = prime * result + ((groupId == null) ? 0 : groupId.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MavenCoordinates other = (MavenCoordinates) obj; + if (artifactId == null) { + if (other.artifactId != null) + return false; + } else if (!artifactId.equals(other.artifactId)) + return false; + if (classifier == null) { + if (other.classifier != null) + return false; + } else if (!classifier.equals(other.classifier)) + return false; + if (groupId == null) { + if (other.groupId != null) + return false; + } else if (!groupId.equals(other.groupId)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + } + + + @XmlRootElement(name = "Dependency") + @XmlType(propOrder = { "service", "package_", "version", "scope", "optional" }) + public static class PackageDependency { + + @XmlElement(name = "Package") + private String package_; + + @XmlElement(name = "Version") + private String version; + + @XmlElementRef + private DependencyService service; + + @XmlElement(name = "Scope") + private LevelWrapper scope; + + @XmlElement(name = "Optional") + private boolean optional; + + public boolean isOptional() { + return optional; + } + + public String dependencyPackage() { + return package_; + } + + public PackageDependency dependencyPackage(String dependencyPackage) { + this.package_=dependencyPackage; + return this; + } + + public String version() { + return version; + } + + public PackageDependency version(String version) { + this.version = version; + return this; + } + + public DependencyService service(){ + return service; + } + + public DependencyService newService(){ + service=new DependencyService(); + return service; + } + + public Level scope() { + return scope.level; + } + + public boolean hasScope() { + return scope != null; + } + + public LevelWrapper newScope() { + scope = new LevelWrapper(Level.VO); + return scope; + } + + + + + @Override + public String toString() { + return " [package_=" + package_ + ", version=" + + version + ", service=" + service + ", scope=" + + scope + ", optional=" + optional + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (optional ? 1231 : 1237); + result = prime * result + + ((package_ == null) ? 0 : package_.hashCode()); + result = prime * result + + ((scope == null) ? 0 : scope.hashCode()); + result = prime * result + + ((service == null) ? 0 : service.hashCode()); + result = prime * result + + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PackageDependency other = (PackageDependency) obj; + if (optional != other.optional) + return false; + if (package_ == null) { + if (other.package_ != null) + return false; + } else if (!package_.equals(other.package_)) + return false; + if (scope == null) { + if (other.scope != null) + return false; + } else if (!scope.equals(other.scope)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + + @XmlRootElement(name="Service") + public static class DependencyService{ + + @XmlElement(name = "Class") + private String clazz; + + @XmlElement(name = "Name") + private String name; + + // we bind it and serialise it, but this is otherwise fixed + @XmlElement(name = "Version") + private String version; + + + public String packageClass() { + return clazz; + } + + public DependencyService packageClass(String clazz) { + this.clazz = clazz; + return this; + } + + public String packageName() { + return name; + } + + public DependencyService packageName(String name) { + this.name = name; + return this; + } + + public String version() { + return version; + } + + public DependencyService version(String version) { + this.version = version; + return this; + } + + + @Override + public String toString() { + return " [clazz=" + clazz + ", name=" + name + + ", version=" + version + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((clazz == null) ? 0 : clazz.hashCode()); + result = prime * result + + ((name == null) ? 0 : name.hashCode()); + result = prime * result + + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DependencyService other = (DependencyService) obj; + if (clazz == null) { + if (other.clazz != null) + return false; + } else if (!clazz.equals(other.clazz)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + } + + + } + + + @XmlRootElement(name = "TargetPlatform") + public static class TargetPlatform extends Platform { + } + + public static class LevelWrapper { + + @XmlAttribute(name = "level") + private Level level; + + LevelWrapper() { + } + + LevelWrapper(Level level) { + this.level = level; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((level == null) ? 0 : level.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LevelWrapper other = (LevelWrapper) obj; + if (level != other.level) + return false; + return true; + } + + } + + @XmlType(name = "Scopes") + @XmlEnum + public enum Level { + + NONE, GHN, VRE, VO; + + public String value() { + return name(); + } + + public static Level fromValue(String v) { + return valueOf(v); + } + + } + + @XmlRootElement(name = "Requirement") + @XmlType(propOrder = { "category", "key", "requirement", "value", "operator" }) + public static class Requirement { + + @XmlAttribute(name = "category") + private String category; + + @XmlAttribute(name = "key") + private String key; + + @XmlAttribute(name = "requirement") + private String requirement; + + @XmlAttribute(name = "value") + private String value; + + @XmlAttribute(name = "operator") + private OpType operator; + + public String category() { + return category; + } + + public Requirement category(String cat) { + this.category = cat; + return this; + } + + public String key() { + return key; + } + + public Requirement key(String key) { + this.key = key; + return this; + } + + public String requirement() { + return requirement; + } + + public Requirement requirement(String requirement) { + this.requirement = requirement; + return this; + } + + public String value() { + return value; + } + + public Requirement value(String value) { + this.value = value; + return this; + } + + public OpType operator() { + return operator; + } + + public Requirement operator(OpType operator) { + this.operator = operator; + return this; + } + + @Override + public String toString() { + return "Requirement [category=" + category + ", key=" + key + ", requirement=" + requirement + + ", value=" + value + ", operator=" + operator + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((category == null) ? 0 : category.hashCode()); + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((operator == null) ? 0 : operator.hashCode()); + result = prime * result + ((requirement == null) ? 0 : requirement.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Requirement other = (Requirement) obj; + if (category == null) { + if (other.category != null) + return false; + } else if (!category.equals(other.category)) + return false; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + if (operator != other.operator) + return false; + if (requirement == null) { + if (other.requirement != null) + return false; + } else if (!requirement.equals(other.requirement)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + @XmlType(name = "OpType") + @XmlEnum + public enum OpType { + + eq, exist, ge, gt, le, lt, ne, contains; + + public String value() { + return name(); + } + + public static OpType fromValue(String v) { + return valueOf(v); + } + + } + + } + + } + + } +} diff --git a/src/main/java/org/gcube/common/resources/gcore/common/AnyMixedWrapper.java b/src/main/java/org/gcube/common/resources/gcore/common/AnyMixedWrapper.java new file mode 100644 index 0000000..064f889 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/common/AnyMixedWrapper.java @@ -0,0 +1,170 @@ +package org.gcube.common.resources.gcore.common; + +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.gcube.common.resources.gcore.utils.Utils; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class AnyMixedWrapper { + + //this is the element we return to client for modifications + private Element root = Utils.newDocument().getDocumentElement(); + + //these are the nodes we deserialise + @XmlAnyElement + @XmlMixed + private List nodes; + + public Element root() { + + Element response = root; + + NodeList list = root.getChildNodes(); + if (list.getLength()==1) { + Node child = list.item(0); + if (child instanceof Element) + response = (Element) child; + } + + return response; + } + + public String asString() { + + StringBuilder builder = new StringBuilder(); + + NodeList list = root.getChildNodes(); + + for (int i=0; i(); + NodeList list = root.getChildNodes(); + for (int i=0;i elements; + + public Element root() { + return root; + } + + //after deserialisation, we link the elements to the root + @SuppressWarnings("unused") + private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if (elements!=null) + for (Element e: elements) + root.appendChild(root.getOwnerDocument().adoptNode(e)); + elements=null; + } + + //before serialisation we copy the child elements of the root + @SuppressWarnings("unused") + private void beforeMarshal(Marshaller marshaller) { + elements = new ArrayList(); + NodeList list = root.getChildNodes(); + for (int i=0;i files=new LinkedHashSet(); + + + @Override + public String toString() { + return "[files=" + files + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((files == null) ? 0 : files.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FileList other = (FileList) obj; + if (files == null) { + if (other.files != null) + return false; + } else if (!files.equals(other.files)) + return false; + return true; + } + + + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/common/GHNReference.java b/src/main/java/org/gcube/common/resources/gcore/common/GHNReference.java new file mode 100644 index 0000000..93b9fb4 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/common/GHNReference.java @@ -0,0 +1,41 @@ +package org.gcube.common.resources.gcore.common; + +import javax.xml.bind.annotation.XmlAttribute; + +public class GHNReference { + + @XmlAttribute(name = "UniqueID") + public String id; + + @Override + public String toString() { + return "[id=" + id + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + GHNReference other = (GHNReference) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/common/Identity.java b/src/main/java/org/gcube/common/resources/gcore/common/Identity.java new file mode 100644 index 0000000..61b0858 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/common/Identity.java @@ -0,0 +1,68 @@ +package org.gcube.common.resources.gcore.common; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlType(propOrder={"subject", "caSubject"}) +@XmlRootElement(name = "RunningInstanceIdentity") +public class Identity { + + @XmlElement(name="subject") + public String subject; + + @XmlElement(name="CASubject") + public String caSubject; + + public void subjects(String subject, String caSubject) { + this.subject=subject; + this.caSubject=caSubject; + } + + public String subject() { + return this.subject; + } + + public String caSubject() { + return this.caSubject; + } + + @Override + public String toString() { + return "Identity [subject=" + subject + ", caSubject=" + caSubject + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((caSubject == null) ? 0 : caSubject.hashCode()); + result = prime * result + ((subject == null) ? 0 : subject.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Identity other = (Identity) obj; + if (caSubject == null) { + if (other.caSubject != null) + return false; + } else if (!caSubject.equals(other.caSubject)) + return false; + if (subject == null) { + if (other.subject != null) + return false; + } else if (!subject.equals(other.subject)) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/common/Platform.java b/src/main/java/org/gcube/common/resources/gcore/common/Platform.java new file mode 100644 index 0000000..4c384d3 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/common/Platform.java @@ -0,0 +1,139 @@ +package org.gcube.common.resources.gcore.common; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.XmlType; + +@XmlType(propOrder={"name","version","minorVersion","revisionVersion","buildVersion"}) +@XmlRootElement(name = "Platform") +public class Platform { + + @XmlTransient + public boolean isEmpty=true; + + @XmlElement(name="Name") + private String name; + + @XmlElement(name="Version") + private Short version; + + @XmlElement(name="MinorVersion") + private Short minorVersion; + + @XmlElement(name="RevisionVersion") + private Short revisionVersion; + + @XmlElement(name="BuildVersion") + private Short buildVersion; + + public String name() { + return name; + } + + public Platform name(String name) { + this.name = name; + this.isEmpty=false; + return this; + } + + public short version() { + return version; + } + + public Platform version(short version) { + this.version = version; + this.isEmpty=false; + return this; + } + + public Short minorVersion() { + return minorVersion; + } + + public Platform minorVersion(short minorVersion) { + this.minorVersion = minorVersion; + this.isEmpty=false; + return this; + } + + public Short revisionVersion() { + return revisionVersion; + } + + public Platform revisionVersion(short revisionVersion) { + this.revisionVersion = revisionVersion; + this.isEmpty=false; + return this; + } + + public Short buildVersion() { + return buildVersion; + } + + public Platform buildVersion(short buildVersion) { + this.buildVersion = buildVersion; + this.isEmpty=false; + return this; + } + + @Override + public String toString() { + return "[name=" + name + ", version=" + version + ", minorVersion=" + minorVersion + + ", revisionVersion=" + revisionVersion + ", buildVersion=" + buildVersion + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((buildVersion == null) ? 0 : buildVersion.hashCode()); + result = prime * result + (isEmpty ? 1231 : 1237); + result = prime * result + ((minorVersion == null) ? 0 : minorVersion.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((revisionVersion == null) ? 0 : revisionVersion.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Platform other = (Platform) obj; + if (buildVersion == null) { + if (other.buildVersion != null) + return false; + } else if (!buildVersion.equals(other.buildVersion)) + return false; + if (isEmpty != other.isEmpty) + return false; + if (minorVersion == null) { + if (other.minorVersion != null) + return false; + } else if (!minorVersion.equals(other.minorVersion)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (revisionVersion == null) { + if (other.revisionVersion != null) + return false; + } else if (!revisionVersion.equals(other.revisionVersion)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/common/ServiceReference.java b/src/main/java/org/gcube/common/resources/gcore/common/ServiceReference.java new file mode 100644 index 0000000..7083e4b --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/common/ServiceReference.java @@ -0,0 +1,41 @@ +package org.gcube.common.resources.gcore.common; + +import javax.xml.bind.annotation.XmlAttribute; + +public class ServiceReference { + + @XmlAttribute(name = "UniqueID") + public String id; + + @Override + public String toString() { + return "[id=" + id + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceReference other = (ServiceReference) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/common/resources/gcore/utils/DateFormatterAdapter.java b/src/main/java/org/gcube/common/resources/gcore/utils/DateFormatterAdapter.java new file mode 100644 index 0000000..37cd6cf --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/utils/DateFormatterAdapter.java @@ -0,0 +1,31 @@ +package org.gcube.common.resources.gcore.utils; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.datatype.DatatypeConstants; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +public class DateFormatterAdapter extends XmlAdapter { + + @Override + public String marshal(Calendar cal) throws Exception { + GregorianCalendar c = new GregorianCalendar(); + c.setTime(cal.getTime()); + XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + date2.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); + return date2.toXMLFormat(); + } + + @Override + public Calendar unmarshal(String date) throws Exception { + XMLGregorianCalendar gregorianDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(date); + Calendar cal = Calendar.getInstance(); + cal.setTime(gregorianDate.toGregorianCalendar().getTime()); + return cal; + + } + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/utils/Group.java b/src/main/java/org/gcube/common/resources/gcore/utils/Group.java new file mode 100644 index 0000000..0e74c28 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/utils/Group.java @@ -0,0 +1,76 @@ +package org.gcube.common.resources.gcore.utils; + +import java.util.Arrays; +import java.util.Collection; + +public class Group extends ReadOnlyGroup implements Collection { + + public Group(Collection values, Class clazz) { + super(values,clazz); + } + + /** + * Adds a new element to the collection and returns it. + * @return the new element + */ + public T add() { + try { + T t = clazz.newInstance(); + add(t); + return t; + } + catch(Exception e) { + throw new RuntimeException("invalid model class, cannot be instantiated reflectively",e); + } + } + + public S add(Class subclass) { + try { + S s = subclass.newInstance(); + add(s); + return s; + } + catch(Exception e) { + throw new RuntimeException("invalid model class, cannot be instantiated reflectively",e); + } + } + + + public boolean add(T element) { + return base.add(element); + }; + + public boolean remove(Object element) { + return base.remove(element); + } + + public void clear() { + base.clear(); + } + + public boolean removeAll(Collection c) { + return base.removeAll(c); + } + + public boolean removeAll(Object ... elements) { + return base.removeAll(Arrays.asList(elements)); + } + + public boolean retainAll(Collection c) { + return base.retainAll(c); + } + + public boolean retainAll(Object ... elements) { + return base.retainAll(Arrays.asList(elements)); + } + + public boolean addAll(@SuppressWarnings("unchecked") T ... elements) { + return base.addAll(Arrays.asList(elements)); + } + + public boolean addAll(Collection c) { + return base.addAll(c); + } + + +} diff --git a/src/main/java/org/gcube/common/resources/gcore/utils/ReadOnlyGroup.java b/src/main/java/org/gcube/common/resources/gcore/utils/ReadOnlyGroup.java new file mode 100644 index 0000000..99e2ed9 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/utils/ReadOnlyGroup.java @@ -0,0 +1,87 @@ +package org.gcube.common.resources.gcore.utils; + +import static java.util.Arrays.*; + +import java.util.Collection; +import java.util.Iterator; + +public class ReadOnlyGroup implements Iterable { + + protected final Collection base; + protected final Class clazz; + + public ReadOnlyGroup(Collection values, Class clazz) { + this.base=values; + this.clazz=clazz; + } + + public boolean contains(Object o) { + return base.contains(o); + } + + public boolean containsAll(Collection c) { + return base.containsAll(c); + } + + public boolean containsAll(Object ... elements) { + return base.containsAll(asList(elements)); + } + +// public boolean equals(Object o) { +// return base.equals(o); +// } +// +// public int hashCode() { +// return base.hashCode(); +// } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ReadOnlyGroup other = (ReadOnlyGroup) obj; + if (base == null) { + if (other.base != null) + return false; + } else if (!base.equals(other.base)) + return false; + return true; + } + + @Override + public int hashCode() { + return base.hashCode(); + } + + public boolean isEmpty() { + return base.isEmpty(); + } + + public Collection asCollection() { + return base; + } + + public int size() { + return base.size(); + } + + public Object[] toArray() { + return base.toArray(); + } + + public E[] toArray(E[] a) { + return base.toArray(a); + } + + + public Iterator iterator() { + return base.iterator(); + } + + +} + diff --git a/src/main/java/org/gcube/common/resources/gcore/utils/Utils.java b/src/main/java/org/gcube/common/resources/gcore/utils/Utils.java new file mode 100644 index 0000000..83b69c7 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/utils/Utils.java @@ -0,0 +1,65 @@ +package org.gcube.common.resources.gcore.utils; + +import java.io.StringReader; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/** + * Library-wide implementation utilities. + * + * + */ +public class Utils { + + static Document emptyDocument; + static SimpleDateFormat dateFormat = new SimpleDateFormat(); + + static DocumentBuilder builder; + + static { + DocumentBuilderFactory.newInstance(); + try { + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + emptyDocument=builder.newDocument(); + } + catch(Exception e) { + throw new RuntimeException(e); + } + } + + public static List parse(String text) throws Exception { + String wrapped = ""+text+""; + List nodes = new ArrayList(); + Document document = builder.parse(new InputSource(new StringReader(wrapped))); + NodeList children = document.getDocumentElement().getChildNodes(); + for (int i=0;i namespaces = new HashMap(); + + private NamespaceContext nsContext = new NamespaceContext() { + + public String getNamespaceURI(String prefix) { + return namespaces.get(prefix); + } + + public Iterator getPrefixes(String val) { + return null; + } + + public String getPrefix(String uri) { + return null; + } + }; + + /** Transformation engine. */ + private static Transformer transformer; + + static { + try { + transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); + } + catch(Exception e) { + throw new RuntimeException(e); + } + } + + private final Node root; + + /** + * Creates an instance with a {@link Node} . + * @param root the node + */ + public XPathHelper(Node root) { + this.root=root; + engine.setNamespaceContext(nsContext); + } + + /** + * Declares a namespace for XPath evaluation. + * @param prefix the namespace prefix + * @param uri the namespace URI + */ + public void addNamespace(String prefix,String uri) { + namespaces.put(prefix,uri); + } + + /** + * Evaluates an XPath expression and returns matching values as strings. + * @param xpath the expression + * @return the list matching values + */ + public List evaluate(String xpath) { + + List results = new ArrayList(); + + try { + + NodeList set = evaluateForNodes(xpath); + + for (int i=0;i + + + + + XML Schema for GCUBE Datatypes Version 1.2 Last modified: 29/02/2008 Contact: http://www.gcube-system.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/schema/endpoint.xsd b/src/main/resources/schema/endpoint.xsd new file mode 100644 index 0000000..a4c6686 --- /dev/null +++ b/src/main/resources/schema/endpoint.xsd @@ -0,0 +1,98 @@ + + + + + XML Schema for GCUBE + Runtime Resource Version 1.0 Last modified: + 29/07/2011 Contact: + http://www.gcube-system.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/schema/gcoreendpoint.xsd b/src/main/resources/schema/gcoreendpoint.xsd new file mode 100644 index 0000000..0fc9bd9 --- /dev/null +++ b/src/main/resources/schema/gcoreendpoint.xsd @@ -0,0 +1,197 @@ + + + + + XML Schema for GCUBE Running Instances Version 1.2 Last modified: 16/05/2011 Contact: http://www.gcube-system.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert here any other property you think is useful to describe a RI-specific feature + + + + + diff --git a/src/main/resources/schema/generic.xsd b/src/main/resources/schema/generic.xsd new file mode 100644 index 0000000..f828024 --- /dev/null +++ b/src/main/resources/schema/generic.xsd @@ -0,0 +1,24 @@ + + + + + XML Schema for GCUBE Generic Resource Version 1.4 Last modified: 29/05/2008 Contact: http://www.gcube-system.org + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/schema/node.xsd b/src/main/resources/schema/node.xsd new file mode 100644 index 0000000..9af8a5c --- /dev/null +++ b/src/main/resources/schema/node.xsd @@ -0,0 +1,254 @@ + + + + + XML Schema for gCube Nodes Version 0.5.0 Last modified:29/05/2009 Contact: http://www.gcube-system.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dynamic: the GHN supports dynamic deployment of new packages + Static: the GHN does not support dynamic deployment of new packages + SelfClening: the GHN supports dynamic deployment of new packages, but only for a short limited period + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/schema/service.xsd b/src/main/resources/schema/service.xsd new file mode 100644 index 0000000..38c44b9 --- /dev/null +++ b/src/main/resources/schema/service.xsd @@ -0,0 +1,391 @@ + + + + + XML Schema for gCube Services Version 1.2.0 Last modified:16/05/2011 Contact: http://www.gcube-system.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + These configurations have to refer to predefined configuration files distributed with the MAIN package. + At VRE creation time, the VRE designer will choose one. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - the "category" is represented by a tag name of a GHN profile + - the "requirement" is one of the attributes defined for the selected category in the GHN profile + - the "value" is the value of the selected attribute defined for the category in the GHN profile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java b/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java new file mode 100644 index 0000000..b0576c2 --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java @@ -0,0 +1,170 @@ +package org.gcube.common.resources.gcore; + +import static junit.framework.Assert.*; +import static org.gcube.common.resources.gcore.Resources.*; +import static org.gcube.common.resources.gcore.TestUtils.*; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URI; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.DeploymentData.Plugin; +import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Function.Parameter; +import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.ScopedAccounting; +import org.gcube.common.resources.gcore.utils.Group; +import org.gcube.common.resources.gcore.utils.XPathHelper; +import org.junit.Test; +import org.w3c.dom.Element; + +public class GCoreEndpointTest { + + @Test + public void bindGCoreEndpoint() throws Exception { + + GCoreEndpoint endpoint = unmarshal(GCoreEndpoint.class, "gcoreendpoint.xml"); + + print(endpoint); + + XPathHelper xpath = new XPathHelper(endpoint.profile().specificData()); + + assertFalse(xpath.evaluate("test").isEmpty()); + + validate(endpoint); + + GCoreEndpoint clone = unmarshal(GCoreEndpoint.class, "gcoreendpoint.xml"); + + assertEquals(endpoint,clone); + + } + + + private GCoreEndpoint minimalgCoreEndpoint() { + + GCoreEndpoint endpoint = new GCoreEndpoint(); + + endpoint.scopes().add("/some/scope"); + + endpoint.profile().version("345"). + ghnId("nodeid"). + serviceId("serviceid"). + serviceName("name"). + serviceClass("class"); + + endpoint.profile().newDeploymentData().activationTime(Calendar.getInstance()); + endpoint.profile().endpoints().add().nameAndAddress("name",URI.create("http://acme.org")); + + return endpoint; + } + + @Test + public void buildMinimalGcoreEndpoint() throws Exception { + + GCoreEndpoint endpoint = minimalgCoreEndpoint(); + + print(endpoint); + validate(endpoint); + + } + + @Test + public void marsharAndUnmarshalDatesTest() throws Exception{ + + GCoreEndpoint endpoint = minimalgCoreEndpoint(); + + print(endpoint); + validate(endpoint); + + StringWriter stringWriter = new StringWriter(); + marshal(endpoint, stringWriter); + + StringReader stringreader = new StringReader(stringWriter.toString()); + + GCoreEndpoint endpoint2 = unmarshal(GCoreEndpoint.class, stringreader); + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + + assertNotNull(endpoint2.profile().deploymentData().activationTime()); + + System.out.println(dateFormat.format(endpoint2.profile().deploymentData().activationTime().getTime())); + + validate(endpoint2); + + + } + + @Test + public void buildMaximalGCoreEndpoint() throws Exception { + + GCoreEndpoint endpoint = minimalgCoreEndpoint(); + + endpoint.profile().description("description"); + + ////// deployment + + endpoint.profile().newDeploymentData(). + name("name"). + path("path"). + status("status"). + statusMessage("msg"). + terminationTime(Calendar.getInstance()). + activationTime(Calendar.getInstance()); + + ////// plugins + + Group plugins = endpoint.profile().deploymentData().plugins(); + plugins.add().service("class","name","1").pluginPackage("package").version("2"); + plugins.add().service("class2","name2","1").pluginPackage("package2").version("2"); + + ////// endpoints + endpoint.profile().endpoints().add().nameAndAddress("name2",URI.create("http://acme2.org")); + + + assertFalse(endpoint.profile().hasPlatform()); + endpoint.profile().newPlatform().name("name").version((short)2); + + validate(endpoint); + + ////// security + + endpoint.profile().security().add().name("name"); //mandatory + + validate(endpoint); + + endpoint.profile().security().add().name("name2").newIdentity().subjects("subject", "caSubject"); //second with optionals + + + ////// functions + + endpoint.profile().functions().add().name("func0"); + endpoint.profile().functions().add().name("func1"). + parameters().add().nameAndValues("p1", "a","b","c"); + + Group params = endpoint.profile().functions().add().name("func2").parameters(); + params.add().nameAndValues("p2","1"); + params.add().nameAndValues("p3","2"); + + ////// specific data + + Element custom = endpoint.profile().specificData(); + custom.appendChild(custom.getOwnerDocument().createElement("empty")); + + ///// scoping + + ScopedAccounting acc = endpoint.profile().accountings().add(); + acc.scope("/some/scope").incomingCalls(100).newTopCaller().name("name").calls(10.5,100.6,20000l); + + acc.averageInCalls().add().intervalAndAverage(100L, 20.6); + acc.averageInvocationTime().add().intervalAndAverage(100L, 20.6); + + validate(endpoint); + + acc.averageInCalls().add().intervalAndAverage(110L, 21.6); + acc.averageInvocationTime().add().intervalAndAverage(110L, 21.6); + + print(endpoint); + + validate(endpoint); + } + +} diff --git a/src/test/java/org/gcube/common/resources/gcore/GenericResourceTests.java b/src/test/java/org/gcube/common/resources/gcore/GenericResourceTests.java new file mode 100644 index 0000000..bdb8e1b --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/GenericResourceTests.java @@ -0,0 +1,138 @@ +package org.gcube.common.resources.gcore; + +import static org.gcube.common.resources.gcore.Resources.*; +import static org.gcube.common.resources.gcore.TestUtils.*; +import static org.junit.Assert.*; +import java.util.List; +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.resources.gcore.utils.XPathHelper; +import org.junit.Assert; +import org.junit.Test; +import org.w3c.dom.Element; + +public class GenericResourceTests { + + @Test + public void bindGeneric() throws Exception { + + //unmarshal resource + GenericResource generic = unmarshal(GenericResource.class, "generic.xml"); + + //print it + print(generic); + + //resource-specific tests + assertEquals(Type.GENERIC,generic.type()); + + XPathHelper helper = new XPathHelper(generic.profile().body()); + + assertFalse(helper.evaluate("other").isEmpty()); + + //ensure schema conformance + validate(generic); + + //test for equality + GenericResource clone = unmarshal(GenericResource.class, "generic.xml"); + + assertEquals(generic,clone); + } + + @Test + public void bindTextGeneric() throws Exception { + + //unmarshal resource + GenericResource generic = unmarshal(GenericResource.class, "textgeneric.xml"); + + //print it + print(generic); + + assertEquals("text",generic.profile().bodyAsString()); + } + + //helper + private GenericResource minimalGeneric() { + + GenericResource generic = new GenericResource(); + + generic.scopes().add("/some/scope"); + + generic.newProfile().type("type").name("name").newBody(); + + return generic; + } + + @Test + public void buildMinimalGeneric() throws Exception { + + GenericResource generic = minimalGeneric(); + + print(generic); + + validate(generic); + } + + @Test + public void buildTextGeneric() throws Exception { + + GenericResource generic = minimalGeneric(); + + generic.profile().newBody("helloworld"); + + print(generic); + + validate(generic); + + generic.profile().newBody("mixedhellomixed"); + + print(generic); + + validate(generic); + + generic.profile().newBody("freetext"); + + print(generic); + + validate(generic); + } + + @Test + public void buildMaximalGeneric() throws Exception { + + GenericResource generic = minimalGeneric(); + + generic.scopes().add("/some/other/scope"); + + assertEquals(2,generic.scopes().size()); + + generic.profile().description("desc"); + + Element body = generic.profile().body(); + body.appendChild(body.getOwnerDocument().createElement("added")); + + print(generic); + + validate(generic); + } + + @Test + public void updateGeneric() throws Exception { + + GenericResource generic = unmarshal(GenericResource.class, "generic.xml"); + + generic.scopes().add("/some/other/scope"); + + generic.profile().description("descupdated").type("type"); + + Element body = generic.profile().body(); + body.appendChild(body.getOwnerDocument().createElement("added")); + + print(generic); + + List results = new XPathHelper(body).evaluate("added"); + + Assert.assertEquals(1,results.size()); + + validate(generic); + } +} diff --git a/src/test/java/org/gcube/common/resources/gcore/HostingNodeTest.java b/src/test/java/org/gcube/common/resources/gcore/HostingNodeTest.java new file mode 100644 index 0000000..afaa0f1 --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/HostingNodeTest.java @@ -0,0 +1,141 @@ +package org.gcube.common.resources.gcore; + +import static junit.framework.Assert.*; +import static org.gcube.common.resources.gcore.Resources.*; +import static org.gcube.common.resources.gcore.TestUtils.*; + +import java.math.BigDecimal; +import java.util.Calendar; + +import org.gcube.common.resources.gcore.HostingNode; +import org.junit.Test; + +/** + * + * @author Fabio Simeoni + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ +public class HostingNodeTest { + + @Test + public void bindNode() throws Exception { + + HostingNode node = unmarshal(HostingNode.class, "node.xml"); + + print(node); + + validate(node); + + HostingNode clone = unmarshal(HostingNode.class, "node.xml"); + + assertEquals(node,clone); + + } + + //helper + private HostingNode minimalNode() { + + HostingNode node = new HostingNode(); + + node.scopes().add("/some/scope"); + + node.newProfile().infrastructure("infrastructure"); + + node.profile().newDescription().name("name").uptime("uptime").lastUpdate(Calendar.getInstance()); + node.profile().description().newArchitecture().platformType("type").smpSize(30).smtSize(20); + node.profile().description().newOperatingSystem().name("name").version("version").release("release"); + node.profile().description().environmentVariables().add().keyAndValue("key", "value"); + node.profile().description().newMainMemory().ramAvailable(100).ramSize(200).virtualAvailable(300).virtualSize(350); + + node.profile().newSite().location("location").country("it"). + domain("domain").latitude("latitude").longitude("longitude"); + + return node; + } + + @Test + public void buildMininimalNode() throws Exception { + + HostingNode node = minimalNode(); + + + print(node); + + validate(node); + } + + @Test + public void buildMaximalNode() throws Exception { + + HostingNode node = minimalNode(); + + node.profile().description().activationTime(Calendar.getInstance()); + + node.profile().description().platforms().add().name("name").version((short)2); + + node.profile().description().newSecurity().authority("auth"). + distinguishedName("dn"). + expirationDate(Calendar.getInstance()); + + + node.profile().description().processors().add(). + family("family"). + model("model"). + vendor("vendor").modelName("name"). + cacheL1(10).cacheL1D(20).cacheL1I(30).cacheL2(40). + bogomips(BigDecimal.valueOf(40000)). + clockSpeedMhz(BigDecimal.valueOf(3000)); + + + node.profile().description().processors().add(). + family("family2"). + model("model2"). + vendor("vendor2").modelName("name2"). + cacheL1(10).cacheL1D(20).cacheL1I(30).cacheL2(40). + bogomips(BigDecimal.valueOf(40000)). + clockSpeedMhz(BigDecimal.valueOf(3000)); + + node.profile().description().networkAdapters().add(). + inboundIP("inbound"). + outboundIP("outbound"). + ipAddress("address").mtu(10).name("name"); + + node.profile().description().networkAdapters().add(). + inboundIP("inbound2"). + outboundIP("outbound2"). + ipAddress("address2").mtu(10).name("name2"); + + + node.profile().description().newBenchmark().sf(10).si(20); + + node.profile().description().storageDevices().add().name("name").size(10).transferRate(10).type("type"); + node.profile().description().storageDevices().add().name("name2").size(10).transferRate(10).type("type2"); + + node.profile().description().storagePartitions().add().name("name").readRate(10).writeRate(20).size("size"); + node.profile().description().storagePartitions().add().name("name2").readRate(10).writeRate(20).size("size2"); + + node.profile().description().localFileSystems().add().name("name").size(10).readOnly(true).root("root").type("type"); + node.profile().description().localFileSystems().add().name("name2").size(10).readOnly(true).root("root2").type("type2"); + + node.profile().description().remoteFileSystems().add().name("name").size(10).readOnly(true).root("root").type("type"); + node.profile().description().remoteFileSystems().add().name("name2").size(10).readOnly(true).root("root2").type("type2"); + + node.profile().description().devicePartitions().add().device("name").name("name"); + node.profile().description().devicePartitions().add().device("name2").name("name2"); + + node.profile().description().fileSystemPartitions().add().fsName("name").storageName("name"); + node.profile().description().fileSystemPartitions().add().fsName("name2").storageName("name2"); + + node.profile().description().newLoad().lastMin(4.5).last15Mins(20.6).last5Mins(5.6); + node.profile().description().newHistoricalLoad().lastDay(67).lastHour(15.3).lastWeek(150.6); + + node.profile().description().localAvailableSpace(new Long(100)); + + node.profile().packages().add().name("name").serviceVersion("1.0.0").packageVersion("version").serviceClass("class").serviceName("name"); + node.profile().packages().add().name("name").serviceVersion("2.0.1").packageVersion("version2").serviceClass("class2").serviceName("name2"); + + print(node); + + validate(node); + } +} diff --git a/src/test/java/org/gcube/common/resources/gcore/ServiceEndpointTest.java b/src/test/java/org/gcube/common/resources/gcore/ServiceEndpointTest.java new file mode 100644 index 0000000..229f027 --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/ServiceEndpointTest.java @@ -0,0 +1,105 @@ +package org.gcube.common.resources.gcore; + +import static junit.framework.Assert.*; +import static org.gcube.common.resources.gcore.Resources.*; +import static org.gcube.common.resources.gcore.TestUtils.*; + +import java.util.Iterator; +import java.util.Map; + +import org.gcube.common.resources.gcore.ServiceEndpoint; +import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; +import org.gcube.common.resources.gcore.ServiceEndpoint.Property; +import org.gcube.common.resources.gcore.utils.Group; +import org.junit.Test; + +public class ServiceEndpointTest { + + @Test + public void bindServiceEndpoint() throws Exception { + + ServiceEndpoint endpoint = unmarshal(ServiceEndpoint.class, "endpoint.xml"); + + print(endpoint); + + validate(endpoint); + +//test new map method + testPropertyWithMap(endpoint, "folder"); +//end test map + //test for equality + ServiceEndpoint clone = unmarshal(ServiceEndpoint.class, "endpoint.xml"); + + assertEquals(endpoint,clone); + } + + private void testPropertyWithMap(ServiceEndpoint endpoint, String propertyName) { + Group apCollection=endpoint.profile().accessPoints(); + Iterator i=apCollection.iterator(); + if(i.hasNext()){ + Map map=i.next().propertyMap(); + if(map !=null){ + Property p =map.get(propertyName); + System.out.println("\n\n Test property folder"); + System.out.println("property value founded: "+p.value()+" \n\n"); + } + } + } + + //helper + private ServiceEndpoint minimalEndpoint() { + + ServiceEndpoint endpoint = new ServiceEndpoint(); + + endpoint.scopes().add("/some/scope"); + + endpoint.newProfile().category("category").newPlatform().name("name").version((short)2); + + endpoint.profile().newRuntime().hostedOn("hosted").ghnId("id").status("status"); + + return endpoint; + } + + @Test + public void buildMinimalEndpoint() throws Exception { + + ServiceEndpoint endpoint = minimalEndpoint(); + + print(endpoint); + + validate(endpoint); + } + + @Test + public void buildMaximalEndpoint() throws Exception { + + ServiceEndpoint endpoint = minimalEndpoint(); + + endpoint.profile().description("description"). + name("name"). + version("version"); + + endpoint.profile().platform().buildVersion((short)1). + minorVersion((short)1). + revisionVersion((short)1); + + endpoint.profile().accessPoints().add().name("name").address("address"); + + validate(endpoint); + + endpoint.profile().accessPoints().add().name("name2").address("address2"). + description("description"). + credentials("pwd", "username"); + + Group props = endpoint.profile().accessPoints().add().name("name3"). + address("address3"). + properties(); + + props.add().nameAndValue("name","value"); + props.add().nameAndValue("name2","value2").encrypted(true); + + print(endpoint); + + validate(endpoint); + } +} diff --git a/src/test/java/org/gcube/common/resources/gcore/ServiceInstanceTest.java b/src/test/java/org/gcube/common/resources/gcore/ServiceInstanceTest.java new file mode 100644 index 0000000..3ea0a63 --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/ServiceInstanceTest.java @@ -0,0 +1,45 @@ +package org.gcube.common.resources.gcore; + +import static junit.framework.Assert.*; +import static org.gcube.common.resources.gcore.Resources.*; +import static org.gcube.common.resources.gcore.TestUtils.*; + +import org.gcube.common.resources.gcore.ServiceInstance; +import org.junit.Test; +import org.w3c.dom.Element; + +public class ServiceInstanceTest { + + @Test + public void bindServiceInstance() throws Exception { + + ServiceInstance instance = unmarshal(ServiceInstance.class, "instance.xml"); + + print(instance); + + ServiceInstance clone = unmarshal(ServiceInstance.class, "instance.xml"); + + assertEquals(instance,clone); + + } + + @Test + public void buildServiceInstance() throws Exception { + + ServiceInstance instance = new ServiceInstance(); + + instance.newProperties().serviceId("service"). + endpointId("endpoint"). + nodeId("node"). + serviceClass("class"). + serviceName("name"). + scopes().add("/some/scope"); + + Element custom = instance.properties().newCustomProperties(); + custom.appendChild(custom.getOwnerDocument().createElement("empty")); + + print(instance); + + } + +} diff --git a/src/test/java/org/gcube/common/resources/gcore/SoftwareTest.java b/src/test/java/org/gcube/common/resources/gcore/SoftwareTest.java new file mode 100644 index 0000000..e0eae1f --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/SoftwareTest.java @@ -0,0 +1,178 @@ +package org.gcube.common.resources.gcore; + +import static java.util.Arrays.*; +import static junit.framework.Assert.*; +import static org.gcube.common.resources.gcore.Resources.*; +import static org.gcube.common.resources.gcore.Software.Profile.GenericPackage.Type.*; +import static org.gcube.common.resources.gcore.Software.Profile.SoftwarePackage.Requirement.OpType.*; +import static org.gcube.common.resources.gcore.TestUtils.*; + +import java.net.URI; + +import org.gcube.common.resources.gcore.Software; +import org.gcube.common.resources.gcore.Software.Profile.GenericPackage; +import org.gcube.common.resources.gcore.Software.Profile.PluginPackage; +import org.gcube.common.resources.gcore.Software.Profile.ServicePackage; +import org.gcube.common.resources.gcore.Software.Profile.ServicePackage.Function; +import org.gcube.common.resources.gcore.Software.Profile.ServicePackage.PortType; +import org.gcube.common.resources.gcore.Software.Profile.SoftwarePackage.PackageDependency; +import org.junit.Test; +import org.w3c.dom.Element; + +public class SoftwareTest { + + @Test + public void bindSoftware() throws Exception { + + Software service = unmarshal(Software.class, "service.xml"); + + print(service); + + validate(service); + + Software clone = unmarshal(Software.class, "service.xml"); + + assertEquals(service,clone); + + validate(service); + + } + + + private Software minimalSoftware() { + + Software software = new Software(); + + software.scopes().add("/some/scope"); + + software.newProfile().softwareClass("class").softwareName("name"); + + ServicePackage service = software.profile().packages().add(ServicePackage.class); + + service.name("testName").version("testVersion").archive("archive").portTypes().add().name("name"); + + //not minimal but conveniently done here + PortType pt = service.portTypes().add(); + pt.name("name2").newSecurity().newDescriptor().appendChild(pt.security().descriptor().getOwnerDocument().createElement("descriptor")); + pt.newWsdl().appendChild(pt.wsdl().getOwnerDocument().createElement("wsdl")); + + //not minimal but conveniently done here + Function f = service.functions().add(); + Element body = f.name("name").newBody(); + body.appendChild(body.getOwnerDocument().createElement("body")); + f.formalParameters().addAll(asList("param1","param2")); + + return software; + + } + + @Test + public void buildMinimalSoftware() throws Exception { + + Software software = minimalSoftware(); + + print(software); + + validate(software); + } + + + @Test + public void buildMaximalSoftware() throws Exception { + + Software software = minimalSoftware(); + + software.profile().description("description"); + + software.profile().newConfiguration().newStaticConfiguration().configurations().add(). + description("desc").file("file").label("label").isDefault(true); + + software.profile().configuration().staticConfiguration().configurations().add(). + description("desc2").file("file2").label("label2").isDefault(false); + + validate(software); + + software.profile().configuration().staticConfiguration().newTemplate(). + params().add().name("name").description("descr"). + allowedValues().add(). + description("description"). + label("label"). + isDefault(true).literal("lit"); + + software.profile().configuration().staticConfiguration().template(). + params().add().name("name2").description("descr2"). + allowedValues().add(). + description("description2"). + label("label2"). + isDefault(false).literal("lit2"); + + + + software.profile().dependencies().add().serviceName("name").serviceClass("class").version("version"); + software.profile().dependencies().add().serviceName("name2").serviceClass("class2").version("version2"); + + GenericPackage generic = software.profile().packages().add(GenericPackage.class); + + generic.name("testName").type(application).version("testVersion").description("description").files().add("string"); + + validate(software); + + software.profile().packages().add(GenericPackage.class). + name("testName2").version("testVersion2").description("description2").uri(URI.create("http://acme.org")); + + generic.newCoordinates().artifactId("id").groupId("gid").version("version").classifier("classifier"); + generic.newTargetPlatform().name("name").version((short)1); + generic.multiVersion(false); + + generic.entryPoints().addAll(asList("entry1","entry2")); + + generic.ghnRequirements().add().category("cat").key("key").requirement("req").operator(exist).value("val"); + generic.ghnRequirements().add().category("cat2").key("key2").requirement("req2").operator(exist).value("val2"); + + generic.installScripts().addAll(asList("installone","installtwo")); + generic.uninstallScripts().addAll(asList("uninstallone","uninstalltwo")); + generic.rebootScripts().addAll(asList("rebootone","reboottwo")); + + PackageDependency pDependency= generic.dependencies().add(); + pDependency.newService().packageClass("pClass").packageName("pName").version("1.1.1"); + pDependency.dependencyPackage("pack1").version("1.1.1").newScope(); + + Element packageRoot=generic.newSpecificData(); + packageRoot.appendChild(packageRoot.getOwnerDocument().createElement("nothingData")); + + software.profile().packages().add(GenericPackage.class). + name("testName2").version("testVersion2"). + description("description2").uri(URI.create("http://acme.org")); + + Element root = software.profile().newSpecificData(); + root.appendChild(root.getOwnerDocument().createElement("nothing")); + + print(software); + + validate(software); + + + } + + @Test + public void buildPlugin() throws Exception { + + Software software = new Software(); + + software.scopes().add("/some/scope"); + + PluginPackage plugin = software.newProfile().softwareClass("class").softwareName("name"). + packages().add(PluginPackage.class); + + plugin.name("testName").version("version").newTargetService().servicePackage("package").version("version"). + newService().serviceClass("class").serviceName("name").version("version"); + + plugin.entryPoint("entry"); + plugin.files().addAll(asList("file1","file2")); + + print(software); + + validate(software); + } + +} diff --git a/src/test/java/org/gcube/common/resources/gcore/TestUtils.java b/src/test/java/org/gcube/common/resources/gcore/TestUtils.java new file mode 100644 index 0000000..9637908 --- /dev/null +++ b/src/test/java/org/gcube/common/resources/gcore/TestUtils.java @@ -0,0 +1,12 @@ +package org.gcube.common.resources.gcore; + +import org.gcube.common.resources.gcore.Resources; + +public class TestUtils { + + // helper: we use T instead of Resource as service instance does not extend it + public static T unmarshal(Class clazz, String sample) throws Exception { + + return Resources.unmarshal(clazz,TestUtils.class.getClassLoader().getResourceAsStream(sample)); + } +} diff --git a/src/test/resources/endpoint.xml b/src/test/resources/endpoint.xml new file mode 100644 index 0000000..6d39d75 --- /dev/null +++ b/src/test/resources/endpoint.xml @@ -0,0 +1,42 @@ + + 03489ee0-240a-11e2-b212-c52eb951fce1 + RuntimeResource + + /gcube/devsec + + + DataSource + HTTP GCUBE SVN + GCUBE SVN REPOSITORY + + apache + 2 + 0 + 0 + 0 + + + svn.research-infrastructures.eu/public/d4science/gcube/trunk + + + + + + URL + + http://svn.research-infrastructures.eu/public/d4science/gcube/trunk + + + + + 6vW1u92cpdgHzYAgIurn9w== + + + + folder + ./ + + + + + \ No newline at end of file diff --git a/src/test/resources/gcoreendpoint.xml b/src/test/resources/gcoreendpoint.xml new file mode 100644 index 0000000..f6fa1d9 --- /dev/null +++ b/src/test/resources/gcoreendpoint.xml @@ -0,0 +1,104 @@ + + + ID + RunningInstance + + Scope + /gcube/devsec + /gcube + + + Description + Version + + + ServiceName + ServiceClass + + + + subject + CASubject + + + + + Name + 0 + 0 + 0 + 0 + + + InstanceName + LocalPath + + + Status + MessageState + + + + Class + Name + Version + + Package + Version + + + + + + Name + + + Name + Value + + + + + + + http://tempuri.org + + + + this is a test + some other text + + + + 14 + + + + + + + + 146.48.87.217 + + + + 0 + + + + + + + + N/A + + + + + diff --git a/src/test/resources/generic.xml b/src/test/resources/generic.xml new file mode 100644 index 0000000..818d667 --- /dev/null +++ b/src/test/resources/generic.xml @@ -0,0 +1,21 @@ + + + b78909d3-4bef-4b3a-b3a1-7eb39fd86a27 + + /gcube + /gcube/devsec + + GenericResource + + DataSource + Sarda Sarda collection + Sarda Sarda collection + + + 2012-10-25T16:43:33.116+02:00 + true + + test + + + \ No newline at end of file diff --git a/src/test/resources/instance.xml b/src/test/resources/instance.xml new file mode 100644 index 0000000..ddfa48d --- /dev/null +++ b/src/test/resources/instance.xml @@ -0,0 +1,57 @@ + + node24.d.d4science.research-infrastructures.eu8080-wsrf-services-gcube-data-speciesproductsdiscovery-manager-manager + + http://node24.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/data/speciesproductsdiscovery/manager + + manager + + manager + + + + 1383840644689 + Thu Nov 07 17:10:44 CET 2013 + + 1352304644689 + Wed Nov 07 17:10:44 CET 2012 + push + + 3b1f7270-229e-11e2-97a7-e430d3499dac + 3b68d780-229e-11e2-97a8-e430d3499dac + DataAccess + /gcube/devNext + /gcube + /gcube/devsec + /gcube/devsec/devVRE + 9d6385e0-28f5-11e2-930e-f13bebb24295 + SpeciesProductsDiscovery + custom1 + custom2 + + \ No newline at end of file diff --git a/src/test/resources/node.xml b/src/test/resources/node.xml new file mode 100644 index 0000000..de591d9 --- /dev/null +++ b/src/test/resources/node.xml @@ -0,0 +1,160 @@ + + + ID + GHN + + Scope + + + Infrastructure + + Name + 2001-12-31T12:00:00 + Status + StatusMessage + Dynamic + + + Name + 0 + 0 + 0 + 0 + + + + + CA + CredentialsDistinguishedName + + 2001-12-31T12:00:00 + + + + + + + + + Key + Value + + + Key1 + Value1 + + + Key2 + Value2 + + + + + + + + + + + + + + + + + Uptime + + + + 0 + 2001-12-31T12:00:00 + + + Location + IT + Latitude + Longitude + Domain + + + + ResultSetService + 3.1.0 + ResultSetService + Search + 1.0.0 + + + ResultSetLibrary + [3.1.0,4.0.0) + ResultSetLibrary + Search + 1.0.0 + + + ResultSetService-stubs + [3.1.0,4.0.0) + ResultSetService + Search + 1.0.0 + + + ResultSetGarbageCollector + [3.1.0,4.0.0) + ResultSetGarbageCollector + Search + 1.0.0 + + + IS-Registry-stubs + 2.1.0 + IS-Registry + InformationSystem + 1.0.0 + + + GHNManager-stubs + 1.5.0 + GHNManager + VREManagement + 1.0.0 + + + GHNManager-service + 1.5.0 + GHNManager + VREManagement + 1.0.0 + + + Deployer-service + 2.3.0-SNAPSHOT + Deployer + VREManagement + 1.00.00 + + + + \ No newline at end of file diff --git a/src/test/resources/service.xml b/src/test/resources/service.xml new file mode 100644 index 0000000..7170a24 --- /dev/null +++ b/src/test/resources/service.xml @@ -0,0 +1,107 @@ + + + + 16a182f0-b609-11e1-959a-8f8c3e6664f5 + + Service + + + + /d4science.research-infrastructures.eu + + /d4science.research-infrastructures.eu/Ecosystem + + /d4science.research-infrastructures.eu/FARM + + /d4science.research-infrastructures.eu/gCubeApps + + /d4science.research-infrastructures.eu/gCubeApps/VesselActivitiesAnalyzer + + + /d4science.research-infrastructures.eu/EUBrazilOpenBio + + + + + + DataAccess + + tree-manager-service + + 1.0.0 + + + +
+ + tree-manager-service + + 2.0.0 + + + + org.gcube.data.access + + tree-manager-service + + 2.0.0 + + + + + + tree-manager-service-2.0.0.gar + + + + gcube/data/tm/binder + + + + + + gcube/data/tm/reader + + + + + + gcube/data/tm/writer + + + +
+ + + + tree-manager-stubs + + 2.0.0 + + + + org.gcube.data.access + + tree-manager-stubs + + 2.0.0 + + + + + + library + + + + tree-manager-stubs-2.0.0.jar + + + + + +
+ +
+ +
diff --git a/src/test/resources/textgeneric.xml b/src/test/resources/textgeneric.xml new file mode 100644 index 0000000..0a73ed5 --- /dev/null +++ b/src/test/resources/textgeneric.xml @@ -0,0 +1,15 @@ + + + b78909d3-4bef-4b3a-b3a1-7eb39fd86a27 + + /gcube + /gcube/devsec + + GenericResource + + DataSource + Sarda Sarda collection + Sarda Sarda collection + text + + \ No newline at end of file