Skip to content

Commit

Permalink
Big refactor (#12)
Browse files Browse the repository at this point in the history
* refactor

- use java library
- remove non used code and config

Signed-off-by: Jorge Aguilera <jagedn@gmail.com>
  • Loading branch information
jagedn authored Feb 20, 2024
1 parent 70703f7 commit 710c207
Show file tree
Hide file tree
Showing 46 changed files with 633 additions and 2,946 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ out
_resources
oracle-nomad-cluster
sun-nomadlab

.project
.classpath
.settings
28 changes: 0 additions & 28 deletions .project

This file was deleted.

6 changes: 0 additions & 6 deletions plugins/.classpath

This file was deleted.

34 changes: 0 additions & 34 deletions plugins/.project

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/.settings/org.eclipse.buildship.core.prefs

This file was deleted.

10 changes: 10 additions & 0 deletions plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ subprojects {
* Creates plugin zip and json meta file in plugin `build/libs` directory
*/
task makeZip(type: Jar) {
group 'nextflow'

into('classes') { with jar }
into('lib') { from configurations.runtimeClasspath }
manifest.from file('src/resources/META-INF/MANIFEST.MF')
Expand Down Expand Up @@ -105,6 +107,8 @@ subprojects {
* Copy the plugin dependencies in the subproject `build/target/libs` directory
*/
task copyPluginLibs(type: Sync) {
group 'nextflow'

from configurations.runtimeClasspath
into 'build/target/libs'
}
Expand All @@ -113,6 +117,8 @@ subprojects {
* Copy the plugin in the project root build/plugins directory
*/
task copyPluginZip(type: Copy, dependsOn: project.tasks.findByName('makeZip')) {
group 'nextflow'

from makeZip
into "$rootProject.buildDir/plugins"
outputs.file("$rootProject.buildDir/plugins/${project.name}-${project.version}.zip")
Expand All @@ -130,6 +136,8 @@ subprojects {
project.parent.tasks.getByName("assemble").dependsOn << copyPluginZip

task uploadPlugin(type: io.nextflow.gradle.tasks.GithubUploader, dependsOn: makeZip) {
group 'nextflow'

assets = providers.provider {["$buildDir/libs/${project.name}-${project.version}.zip",
"$buildDir/libs/${project.name}-${project.version}-meta.json" ]}
release = providers.provider { project.version }
Expand All @@ -150,6 +158,8 @@ classes.dependsOn subprojects.copyPluginLibs
* Merge and publish the plugins index file
*/
task publishIndex( type: io.nextflow.gradle.tasks.GithubRepositoryPublisher ) {
group 'nextflow'

indexUrl = 'https://github.com/nextflow-io/plugins/main/plugins.json'
repos = allPlugins()
owner = github_organization
Expand Down
32 changes: 0 additions & 32 deletions plugins/nf-nomad/.classpath

This file was deleted.

34 changes: 0 additions & 34 deletions plugins/nf-nomad/.project

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/nf-nomad/.settings/org.eclipse.buildship.core.prefs

This file was deleted.

2 changes: 2 additions & 0 deletions plugins/nf-nomad/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ dependencies {
}

testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
testImplementation(testFixtures("io.nextflow:nextflow:$nextflowVersion"))
testImplementation(testFixtures("io.nextflow:nf-commons:$nextflowVersion"))
}

// use JUnit 5 platform
Expand Down
67 changes: 67 additions & 0 deletions plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2023, Stellenbosch University, South Africa
* Copyright 2022, Center for Medical Genetics, Ghent
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nextflow.nomad

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j

/**
* Nomad Config
*
* @author Jorge Aguilera <jagedn@gmail.com>
*/

@Slf4j
@CompileStatic
class NomadConfig {

final NomadClientOpts clientOpts
final NomadJobOpts jobOpts

NomadConfig(Map nomadConfigMap) {
clientOpts = new NomadClientOpts((nomadConfigMap.client ?: Collections.emptyMap()) as Map)
jobOpts = new NomadJobOpts((nomadConfigMap.jobs ?: Collections.emptyMap()) as Map)
}

class NomadClientOpts{
final String address
final String token

NomadClientOpts(Map nomadClientOpts){
address = (nomadClientOpts.address?.toString() ?: "http://127.0.0.1:4646")+"/v1"
token = nomadClientOpts.token ?: null
}
}

class NomadJobOpts{
final boolean deleteOnCompletion
final List<String> datacenters
final String region
final String namespace
final String dockerVolume

NomadJobOpts(Map nomadJobOpts){
deleteOnCompletion = nomadJobOpts.containsKey("deleteOnCompletion") ?
nomadJobOpts.deleteOnCompletion : false
datacenters = (nomadJobOpts.containsKey("datacenters") ?
nomadJobOpts.datacenters.toString().split(",") : List.of("dc1")) as List<String>
region = nomadJobOpts.region ?: null
namespace = nomadJobOpts.namespace ?: null
dockerVolume = nomadJobOpts.dockerVolume ?: null
}
}
}
94 changes: 0 additions & 94 deletions plugins/nf-nomad/src/main/nextflow/nomad/NomadHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

package nextflow.nomad

import nextflow.nomad.client.NomadResponseJson
import nextflow.nomad.model.NomadJobBuilder

import nextflow.processor.TaskRun
import nextflow.processor.TaskStatus

/**
* Nomad API Helper methods
*
Expand All @@ -39,92 +33,4 @@ class NomadHelper {
return str.take(60)
}

static String filterStatus (NomadResponseJson resp, String taskName) {
def statusMap = resp.json.Summary["${taskName}_taskgroup"]
def status = statusMap.find{it.value == 1}.key
return status
}

static TaskStatus mapJobToTaskStatus(NomadResponseJson resp, String taskName) {
def parsedStatus = filterStatus(resp, taskName)

def Map<String, TaskStatus> TASK_STATUS = [
'Queued' : TaskStatus.SUBMITTED,
'Starting' : TaskStatus.RUNNING,
'Running' : TaskStatus.RUNNING,
'Complete' : TaskStatus.COMPLETED,
'Failed' : TaskStatus.COMPLETED,
'Lost' : TaskStatus.COMPLETED,
'Unknown' : TaskStatus.COMPLETED,
]

return TASK_STATUS[parsedStatus]
}



}



//package nextflow.nomad.model
//
//import groovy.transform.CompileStatic
//import groovy.transform.EqualsAndHashCode
//import groovy.transform.ToString
//
//@CompileStatic
//@ToString(includeNames = true)
//@EqualsAndHashCode(includeFields = true)
//class NomadJobConstraints {
//
// private Map spec = [:]
//
// PodNodeSelector(selector) {
// if( selector instanceof CharSequence )
// createWithString(selector.toString())
//
// else if( selector instanceof Map )
// createWithMap(selector)
//
// else if( selector != null )
// throw new IllegalArgumentException("K8s invalid pod nodeSelector value: $selector [${selector.getClass().getName()}]")
// }
//
// private createWithMap(Map selection ) {
// if(selection) {
// for( Map.Entry entry : selection.entrySet() ) {
// spec.put(entry.key.toString(), entry.value?.toString())
// }
// }
// }
//
// /**
// * @param selector
// * A string representing a comma separated list of pairs
// * e.g. foo=1,bar=2
// *
// */
// private createWithString( String selector ) {
// if(!selector) return
// def entries = selector.tokenize(',')
// for( String item : entries ) {
// def pair = item.tokenize('=')
// spec.put( trim(pair[0]), trim(pair[1]) ?: 'true' )
// }
// }
//
// private String trim(String v) {
// v?.trim()
// }
//
// Map<String,String> toSpec() { spec }
//
// String toString() {
// "PodNodeSelector[ ${spec?.toString()} ]"
// }
//}
//
//
//class NomadJobMeta {
//}
Loading

0 comments on commit 710c207

Please sign in to comment.