diff --git a/.directory b/.directory deleted file mode 100644 index 3c6b184f..00000000 --- a/.directory +++ /dev/null @@ -1,6 +0,0 @@ -[Dolphin] -Timestamp=2019,6,10,10,31,52 -Version=4 - -[Settings] -HiddenFilesShown=true diff --git a/.gitignore b/.gitignore index aa118746..c76157f7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ Terradue.OpenSearch.Client.sln.DotSettings.user TestResult\.xml *auth.txt* .*.swp +.directory diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..421e0356 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM debian:buster-slim + +# MAINTAINER Emmanuel Mathot + +ENV MONO_VERSION 6.8.0.123 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends gnupg dirmngr \ + && rm -rf /var/lib/apt/lists/* \ + && export GNUPGHOME="$(mktemp -d)" \ + && gpg --batch --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ + && gpg --batch --export --armor 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF > /etc/apt/trusted.gpg.d/mono.gpg.asc \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && apt-key list | grep Xamarin \ + && apt-get purge -y --auto-remove gnupg dirmngr + +RUN echo "deb http://download.mono-project.com/repo/debian stable-buster/snapshots/$MONO_VERSION main" > /etc/apt/sources.list.d/mono-official-stable.list \ + && apt-get update \ + && apt-get install -y mono-complete \ + && rm -rf /var/lib/apt/lists/* /tmp/* + +ARG OPENSEARCH_CLIENT_TGZ +COPY $OPENSEARCH_CLIENT_TGZ /tmp/$OPENSEARCH_CLIENT_TGZ +RUN cd / && tar xvzf /tmp/$OPENSEARCH_CLIENT_TGZ \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index b5037c34..07bf2e75 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,62 +4,63 @@ pipeline { string(name: 'TEST_AUTH', defaultValue: '', description: 'Add <name>=<username>:<password> triples separated by spaces. If not specified, tests requring authentication are skipped.', ) choice(name: 'DOTNET_CONFIG', choices: "Debug\nRelease", description: 'Debug will produce symbols in the assmbly to be able to debug it at runtime. This is the recommended option for feature, hotfix testing or release candidate.
For publishing a release from master branch, please choose Release.', ) } - agent { node { label 'centos7-mono4' } } + agent any stages { - stage('Init') { + stage('Build') { + agent { + docker { + image 'mono:6.8' + } + } + environment { + HOME = '$WORKSPACE' + } steps { - sh 'sudo yum -y install rpm-build redhat-rpm-config rpmdevtools yum-utils' - sh 'mkdir -p $WORKSPACE/build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}' - sh 'cp opensearch-client.spec $WORKSPACE/build/SPECS/opensearch-client.spec' - sh 'spectool -g -R --directory $WORKSPACE/build/SOURCES $WORKSPACE/build/SPECS/opensearch-client.spec' + echo "Build .NET application" + sh "msbuild /t:build /p:Configuration=DEBUG /Restore:true" + stash includes: 'Terradue.OpenSearch.Client/bin/**', name: 'opensearch-client-build' + } + } + stage('Package') { + agent { + docker { + image 'alectolytic/rpmbuilder:centos-7' + } + } + steps { + unstash name: 'opensearch-client-build' script { def sdf = sh(returnStdout: true, script: 'date -u +%Y%m%dT%H%M%S').trim() if (env.BRANCH_NAME == 'master') env.release = env.BUILD_NUMBER else env.release = "SNAPSHOT" + sdf + def descriptor = readDescriptor() + env.version = descriptor.version } - } - } - stage('Build') { - steps { - echo "Build .NET application" - sh "msbuild /t:build /p:Configuration=DEBUG /Restore:true" - sh 'cp -r Terradue.OpenSearch.Client/bin $WORKSPACE/build/SOURCES/' + sh 'mkdir -p $WORKSPACE/build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}' + sh 'mkdir -p $WORKSPACE/build/SOURCES/usr/lib/opensearch-client' + sh 'cp -r Terradue.OpenSearch.Client/bin/Debug/net4.5/* $WORKSPACE/build/SOURCES/usr/lib/opensearch-client/' + sh 'mkdir -p $WORKSPACE/build/SOURCES/usr/bin' + sh 'cp src/main/scripts/opensearch-client $WORKSPACE/build/SOURCES/usr/bin' sh 'cp src/main/scripts/opensearch-client $WORKSPACE/build/SOURCES/' - sh 'cp -r packages $WORKSPACE/build/SOURCES/' -// temporary commnented -// sh 'ls -l $WORKSPACE/build/SOURCES/packages/terradue.metadata.earthobservation/*/content/Resources/ne_110m_land' - } - } - stage('Package') { - steps { - echo "Build package dependencies" - sh "sudo yum-builddep -y $WORKSPACE/build/SPECS/opensearch-client.spec" + sh 'cp opensearch-client.spec $WORKSPACE/build/SPECS/opensearch-client.spec' + sh 'spectool -g -R --directory $WORKSPACE/build/SOURCES $WORKSPACE/build/SPECS/opensearch-client.spec' echo "Build package" - sh "sudo rpmbuild --define \"_topdir $WORKSPACE/build\" -ba --define '_branch ${env.BRANCH_NAME}' --define '_release ${env.release}' $WORKSPACE/build/SPECS/opensearch-client.spec" + sh "rpmbuild --define \"_topdir $WORKSPACE/build\" -ba --define '_branch ${env.BRANCH_NAME}' --define '_version ${env.version}' --define '_release ${env.release}' $WORKSPACE/build/SPECS/opensearch-client.spec" sh "rpm -qpl $WORKSPACE/build/RPMS/*/*.rpm" - } - } - stage('Test') { - when { - expression { - return params.RUN_TESTS - } - } - steps { - sh 'echo "${params.TEST_AUTH}" > Terradue.OpenSearch.Client.Test/auth.txt' - sh 'mono packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe *.Test/bin/*/net45/*.Test.dll' - } - post { - success { - nunit(testResultsPattern: 'TestResult.xml') - } + sh 'rm -f $WORKSPACE/build/SOURCES/opensearch-client' + sh "tar -cvzf opensearch-client-${env.version}-${env.release}.tar.gz -C $WORKSPACE/build/SOURCES/ ." + archiveArtifacts artifacts: 'build/RPMS/**/*.rpm,opensearch-client-*.tar.gz', fingerprint: true + stash includes: 'opensearch-client-*.tar.gz', name: 'opensearch-client-tgz' + stash includes: 'build/RPMS/**/*.rpm', name: 'opensearch-client-rpm' } } stage('Publish') { + agent { node { label 'artifactory' } } steps { echo 'Deploying' + unstash name: 'opensearch-client-rpm' script { // Obtain an Artifactory server instance, defined in Jenkins --> Manage: def server = Artifactory.server "repository.terradue.com" @@ -75,5 +76,33 @@ pipeline { } } } + stage('Build & Publish Docker') { + steps { + unstash name: 'opensearch-client-tgz' + script { + def opensearchclienttgz = findFiles(glob: "opensearch-client-*.tar.gz") + def descriptor = readDescriptor() + def testsuite = docker.build(descriptor.docker_image_name, "--build-arg OPENSEARCH_CLIENT_TGZ=${opensearchclienttgz[0].name} .") + def mType=getTypeOfVersion(env.BRANCH_NAME) + docker.withRegistry('https://registry.hub.docker.com', 'dockerhub-emmanuelmathot') { + testsuite.push("${mType}${descriptor.version}") + testsuite.push("${mType}latest") + } + } + } + } } } + +def getTypeOfVersion(branchName) { + + def matcher = (env.BRANCH_NAME =~ /master/) + if (matcher.matches()) + return "" + + return "dev" +} + +def readDescriptor (){ + return readYaml(file: 'build.yml') +} diff --git a/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj b/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj index 3458fc2c..28471971 100644 --- a/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj +++ b/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj @@ -11,7 +11,7 @@ DotNetOpenSearchClient Generic OpenSearch Client LICENSE - 1.9.6 + 1.9.7 Emmanuel Mathot Terradue https://github.com/Terradue/DotNetOpenSearchClient diff --git a/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs b/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs index 62eb0940..dab1fb68 100644 --- a/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs +++ b/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs @@ -364,7 +364,7 @@ public void Initialize() { // check if url contains terradue domain var terradueDomainPattern = new Regex(@"^.*\.terradue\.com.*"); - var hasTerradueDomain = BaseUrls.Any(url => terradueDomainPattern.IsMatch(url)); + var hasTerradueDomain = (BaseUrls == null ? false : BaseUrls.Any(url => terradueDomainPattern.IsMatch(url))); // if url contains terradue.com and no credentials has been specified, check for _T2Credentials in HDFS if ( hasTerradueDomain && NetCreds.IsEmpty() ) { diff --git a/Terradue.OpenSearch.Model.Base/Terradue.OpenSearch.Model.Base.csproj.TMP b/Terradue.OpenSearch.Model.Base/Terradue.OpenSearch.Model.Base.csproj.TMP deleted file mode 100644 index 8e577717..00000000 --- a/Terradue.OpenSearch.Model.Base/Terradue.OpenSearch.Model.Base.csproj.TMP +++ /dev/null @@ -1,47 +0,0 @@ - - - Debug - AnyCPU - Library - Terradue.OpenSearch.Model.Base - Terradue.OpenSearch.Model.Base - net4.5 - win;linux-x64 - $(SolutionDir)\packages - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/CycleNumberMetadataExtractor.cs b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/CycleNumberMetadataExtractor.cs new file mode 100644 index 00000000..880448ce --- /dev/null +++ b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/CycleNumberMetadataExtractor.cs @@ -0,0 +1,57 @@ +using System; +using System.Xml; +using Terradue.OpenSearch.Result; +using Terradue.ServiceModel.Ogc; + +namespace Terradue.OpenSearch.Model.EarthObservation { + + class CycleNumberMetadataExtractor : IMetadataExtractor { + #region IMetadataExtractor implementation + + public string GetMetadata(IOpenSearchResultItem item, string specifier) { + + ServiceModel.Ogc.Om20.OM_ObservationType eo = null; + var extensions = item.ElementExtensions; + + foreach (var ext in extensions) { + if (ext.OuterName == "EarthObservation") { + XmlReader reader = ext.GetReader(); + + eo = (ServiceModel.Ogc.Om20.OM_ObservationType)OgcHelpers.DeserializeEarthObservation(reader); + } + } + + if (eo != null) { + if (eo is ServiceModel.Ogc.Eop21.EarthObservationType) { + try { + return eo.procedure.Eop21EarthObservationEquipment.acquisitionParameters.AltAcquisition.cycleNumber; + } catch (Exception) { + return null; + } + } + + if (eo is ServiceModel.Ogc.Eop20.EarthObservationType) { + try { + return eo.procedure.Eop20EarthObservationEquipment.acquisitionParameters.AltAcquisition.cycleNumber; + } catch (Exception) { + return null; + } + } + } + + return null; + } + + + public string Description { + get { + return "A number representing the cycle number, if available"; + } + } + + #endregion + } + + +} + diff --git a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/EarthObservationDataModelExtension.cs b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/EarthObservationDataModelExtension.cs index 84b833db..62d051a5 100644 --- a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/EarthObservationDataModelExtension.cs +++ b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/EarthObservationDataModelExtension.cs @@ -44,6 +44,14 @@ protected override void InitializeExtractors() { metadataExtractors.Add("cc", new CloudCoverMetadataExtractor()); metadataExtractors.Add("sensorResolution", new SensorResolutionMetadataExtractor()); metadataExtractors.Add("vs", new VendorSpecificMetadataExtractor()); + metadataExtractors.Add("instrument", new InstrumentShortNameMetadataExtractor()); + metadataExtractors.Add("instrumentShortName", new InstrumentShortNameMetadataExtractor()); + metadataExtractors.Add("instrumentType", new InstrumentTypeMetadataExtractor()); + metadataExtractors.Add("instrumentDescription", new InstrumentDescriptionMetadataExtractor()); + metadataExtractors.Add("sensor", new SensorTypeMetadataExtractor()); + metadataExtractors.Add("sensorType", new SensorTypeMetadataExtractor()); + metadataExtractors.Add("cycle", new CycleNumberMetadataExtractor()); + metadataExtractors.Add("cycleNumber", new CycleNumberMetadataExtractor()); } public override string Name { diff --git a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentDescriptionMetadataExtractor.cs b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentDescriptionMetadataExtractor.cs new file mode 100644 index 00000000..2c2c6f37 --- /dev/null +++ b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentDescriptionMetadataExtractor.cs @@ -0,0 +1,56 @@ +using System; +using System.Xml; +using Terradue.OpenSearch.Result; +using Terradue.ServiceModel.Ogc; + +namespace Terradue.OpenSearch.Model.EarthObservation { + + class InstrumentDescriptionMetadataExtractor : IMetadataExtractor { + #region IMetadataExtractor implementation + + public string GetMetadata(IOpenSearchResultItem item, string specifier) { + + ServiceModel.Ogc.Om20.OM_ObservationType eo = null; + var extensions = item.ElementExtensions; + + foreach (var ext in extensions) { + if (ext.OuterName == "EarthObservation") { + XmlReader reader = ext.GetReader(); + + eo = (ServiceModel.Ogc.Om20.OM_ObservationType)OgcHelpers.DeserializeEarthObservation(reader); + } + } + + if (eo != null) { + if (eo is ServiceModel.Ogc.Eop21.EarthObservationType) { + try { + return eo.procedure.Eop21EarthObservationEquipment.instrument.Instrument.description; + } catch (Exception) { + return null; + } + } + + if (eo is ServiceModel.Ogc.Eop20.EarthObservationType) { + try { + return eo.procedure.Eop20EarthObservationEquipment.instrument[0].Instrument.description; + } catch (Exception) { + return null; + } + } + } + + return null; + } + + + public string Description { + get { + return "A number representing the instrument description, if available"; + } + } + + #endregion + } + + +} diff --git a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentShortNameMetadataExtractor.cs b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentShortNameMetadataExtractor.cs new file mode 100644 index 00000000..b3cd3796 --- /dev/null +++ b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentShortNameMetadataExtractor.cs @@ -0,0 +1,23 @@ +using Terradue.OpenSearch.Result; + +namespace Terradue.OpenSearch.Model.EarthObservation { + + class InstrumentShortNameMetadataExtractor : IMetadataExtractor { + #region IMetadataExtractor implementation + + public string GetMetadata(IOpenSearchResultItem item, string specifier) { + + return Terradue.Metadata.EarthObservation.OpenSearch.Extensions.EarthObservationOpenSearchResultExtensions.FindInstrumentShortName(item); + } + + public string Description { + get { + return "A string identifying the instrument."; + } + } + + #endregion + } + + +} diff --git a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentTypeMetadataExtractor.cs b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentTypeMetadataExtractor.cs new file mode 100644 index 00000000..d24bd687 --- /dev/null +++ b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/InstrumentTypeMetadataExtractor.cs @@ -0,0 +1,59 @@ +using System; +using System.Xml; +using Terradue.OpenSearch.Model.GeoTime; +using Terradue.OpenSearch.Result; +using Terradue.ServiceModel; +using Terradue.ServiceModel.Ogc; +using Terradue.ServiceModel.Syndication; + +namespace Terradue.OpenSearch.Model.EarthObservation { + + class InstrumentTypeMetadataExtractor : IMetadataExtractor { + #region IMetadataExtractor implementation + + public string GetMetadata(IOpenSearchResultItem item, string specifier) { + + ServiceModel.Ogc.Om20.OM_ObservationType eo = null; + var extensions = item.ElementExtensions; + + foreach (var ext in extensions) { + if (ext.OuterName == "EarthObservation") { + XmlReader reader = ext.GetReader(); + + eo = (ServiceModel.Ogc.Om20.OM_ObservationType)OgcHelpers.DeserializeEarthObservation(reader); + } + } + + if (eo != null) { + if (eo is ServiceModel.Ogc.Eop21.EarthObservationType) { + try { + return eo.procedure.Eop21EarthObservationEquipment.instrument.Instrument.instrumentType; + } catch (Exception) { + return null; + } + } + + if (eo is ServiceModel.Ogc.Eop20.EarthObservationType) { + try { + return eo.procedure.Eop20EarthObservationEquipment.instrument[0].Instrument.instrumentType; + } catch (Exception) { + return null; + } + } + } + + return null; + } + + + public string Description { + get { + return "A number representing the instrument type"; + } + } + + #endregion + } + + +} diff --git a/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/SensorTypeMetadataExtractor.cs b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/SensorTypeMetadataExtractor.cs new file mode 100644 index 00000000..52e16888 --- /dev/null +++ b/Terradue.OpenSearch.Model.Base/Terradue/OpenSearch/Model/EarthObservation/SensorTypeMetadataExtractor.cs @@ -0,0 +1,63 @@ +using System; +using System.Xml; +using Terradue.OpenSearch.Model.GeoTime; +using Terradue.OpenSearch.Result; +using Terradue.ServiceModel; +using Terradue.ServiceModel.Ogc; +using Terradue.ServiceModel.Syndication; + +namespace Terradue.OpenSearch.Model.EarthObservation { + + class SensorTypeMetadataExtractor : IMetadataExtractor { + #region IMetadataExtractor implementation + + public string GetMetadata(IOpenSearchResultItem item, string specifier) { + + //ServiceModel.Ogc.Om20.OM_ObservationType aa = item.ElementExtensions.GetEarthObservationProfile(); + + //OgcHelpers.DeserializeEarthObservation() + ServiceModel.Ogc.Om20.OM_ObservationType eo = null; + var extensions = item.ElementExtensions; + + foreach (var ext in extensions) { + if (ext.OuterName == "EarthObservation") { + XmlReader reader = ext.GetReader(); + + eo = (ServiceModel.Ogc.Om20.OM_ObservationType)OgcHelpers.DeserializeEarthObservation(reader); + } + } + + if (eo != null) { + if (eo is ServiceModel.Ogc.Eop21.EarthObservationType) { + try { + return eo.procedure.Eop21EarthObservationEquipment.sensor.Sensor.sensorType; + } catch (Exception) { + return null; + } + } + + if (eo is ServiceModel.Ogc.Eop20.EarthObservationType) { + try { + return eo.procedure.Eop20EarthObservationEquipment.sensor.Sensor.sensorType; + } catch (Exception) { + return null; + } + } + } + + return null; + } + + + public string Description { + get { + return "A string representing the sensor type"; + } + } + + #endregion + } + + +} + diff --git a/build.yml b/build.yml new file mode 100644 index 00000000..90ef7240 --- /dev/null +++ b/build.yml @@ -0,0 +1,2 @@ +docker_image_name: terradue/opensearch-client +version: 1.9.7 \ No newline at end of file diff --git a/opensearch-client.spec b/opensearch-client.spec index b2a90430..d3a3c1ff 100644 --- a/opensearch-client.spec +++ b/opensearch-client.spec @@ -1,52 +1,47 @@ + +%define debug_package %{nil} +%define __jar_repack %{nil} + Name: opensearch-client Url: https://github.com/Terradue/DotNetOpenSearchClient License: AGPLv3 Group: Productivity/Networking/Web/Servers -Version: 1.9.6 +Version: %{_version} Release: %{_release} Summary: Terradue Opensearch Client BuildArch: noarch Source: /usr/bin/opensearch-client Requires: mono AutoReqProv: no -BuildRequires: libtool - %description Generic OpenSearch Client giving the ability to retrieve element values from generic opensearch queries. -%define debug_package %{nil} - %prep %build %install -mkdir -p %{buildroot}/usr/lib/opensearch-client -cp -r %{_sourcedir}/bin/Debug/net4.5/* %{buildroot}/usr/lib/opensearch-client -mkdir -p %{buildroot}/usr/bin/ -cp %{_sourcedir}/opensearch-client %{buildroot}/usr/bin/ -mkdir -p %{buildroot}/usr/local/lib/ +cp -r %{_sourcedir}/* %{buildroot} +rm -f %{buildroot}/opensearch-client + # temporary commnented #cp -r %{_sourcedir}/packages/terradue.metadata.earthobservation/*/content/Resources/ne_110m_land %{buildroot}/usr/local/lib/ - - %post %postun %clean -rm -rf %{buildroot} +# rm -rf %{buildroot} %files /usr/lib/opensearch-client/* /usr/bin/opensearch-client -#/usr/local/lib/* %changelog