Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhitam02 committed Mar 28, 2024
1 parent f686fbc commit ae9c60c
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: nf-hello CI
name: nf-polly CI
on:
push:
branches:
Expand All @@ -10,7 +10,7 @@ on:
- '*'
jobs:
build:
name: Build nf-hello
name: Build nf-polly
if: "!contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins {
id 'nf-hello'
id 'nf-polly'
}
2 changes: 0 additions & 2 deletions plugins/nf-hello/src/resources/META-INF/extensions.idx

This file was deleted.

10 changes: 10 additions & 0 deletions plugins/nf-hello/build.gradle → plugins/nf-polly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ ext{
}

dependencies {
implementation platform('software.amazon.awssdk:bom:2.21.1')
implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:kinesis'
implementation 'software.amazon.awssdk:sso'
implementation 'software.amazon.awssdk:ssooidc'
implementation platform('org.apache.logging.log4j:log4j-bom:2.20.0')
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl'
implementation 'org.apache.logging.log4j:log4j-1.2-api'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.0'

// This dependency is exported to consumers, that is to say found on their compile classpath.
compileOnly "io.nextflow:nextflow:$nextflowVersion"
compileOnly 'org.slf4j:slf4j-api:1.7.10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import groovy.transform.PackageScope
*
*/
@PackageScope
class HelloConfig {
class PollyConfig {

final private String prefix

HelloConfig(Map map){
PollyConfig(Map map){
def config = map ?: Collections.emptyMap()
prefix = config.prefix ?: 'Mr.'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package nextflow.hello

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.kinesis.KinesisClient;
import software.amazon.awssdk.services.kinesis.model.KinesisException;
import software.amazon.awssdk.services.kinesis.model.PutRecordRequest;
import software.amazon.awssdk.services.kinesis.model.PutRecordResponse;
import java.util.Map;
import java.util.*;

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
Expand All @@ -23,7 +34,9 @@ import nextflow.plugin.extension.PluginExtensionPoint
*/
@Slf4j
@CompileStatic
class HelloExtension extends PluginExtensionPoint {
class PollyExtension extends PluginExtensionPoint {
// static final Logger logger = LogManager.getLogger(KinesisWriteApp.class);
static final ObjectMapper objMapper = new ObjectMapper();

/*
* A session hold information about current execution of the script
Expand All @@ -42,7 +55,7 @@ class HelloExtension extends PluginExtensionPoint {
* prefix = 'Mrs'
* }
*/
private HelloConfig config
private PollyConfig config

/*
* nf-core initializes the plugin once loaded and session is ready
Expand All @@ -51,7 +64,7 @@ class HelloExtension extends PluginExtensionPoint {
@Override
protected void init(Session session) {
this.session = session
this.config = new HelloConfig(session.config.navigate('hello') as Map)
this.config = new PollyConfig(session.config.navigate('hello') as Map)
}

/*
Expand Down Expand Up @@ -107,8 +120,21 @@ class HelloExtension extends PluginExtensionPoint {
* Using @Function annotation we allow this function can be imported from the pipeline script
*/
@Function
String randomString(int length=9){
new Random().with {(1..length).collect {(('a'..'z')).join(null)[ nextInt((('a'..'z')).join(null).length())]}.join(null)}
void reportMetric(var key,var val){
String streamName ="pravaah-dev-user-defined-metrics-events-v1";
String partitionKey="1234";
var keyValuePairs = Map.of(key, val);
var data = objMapper.writeValueAsBytes(Map.of("metric", keyValuePairs));
// Instantiate the client
var client = KinesisClient.builder().build();
try {
// construct single PutRecord request
var putRequest = PutRecordRequest.builder().partitionKey(partitionKey).streamName(streamName).data(SdkBytes.fromByteArray(data)).build();
// execute single PutRecord request
PutRecordResponse response = client.putRecord(putRequest);
System.out.println("Produced Record " + response.sequenceNumber() + " to Shard " + response.shardId() + " (line 145)");
}catch (KinesisException e) {
System.out.println("Failed to produce " + ": " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import nextflow.trace.TraceObserverFactory
* @author Paolo Di Tommaso <[email protected]>
*/
@CompileStatic
class HelloFactory implements TraceObserverFactory {
class PollyFactory implements TraceObserverFactory {

@Override
Collection<TraceObserver> create(Session session) {
final result = new ArrayList()
result.add( new HelloObserver() )
result.add( new PollyObserver() )
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import nextflow.trace.TraceObserver
*/
@Slf4j
@CompileStatic
class HelloObserver implements TraceObserver {
class PollyObserver implements TraceObserver {

@Override
void onFlowCreate(Session session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import org.pf4j.PluginWrapper
* @author Paolo Di Tommaso <[email protected]>
*/
@CompileStatic
class HelloPlugin extends BasePlugin {
class PollyPlugin extends BasePlugin {

HelloPlugin(PluginWrapper wrapper) {
PollyPlugin(PluginWrapper wrapper) {
super(wrapper)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Plugin-Id: nf-hello
Plugin-Id: nf-polly
Plugin-Version: 0.5.0
Plugin-Class: nextflow.hello.HelloPlugin
Plugin-Class: nextflow.hello.PollyPlugin
Plugin-Provider: nextflow
Plugin-Requires: >=24.01.0-edge
2 changes: 2 additions & 0 deletions plugins/nf-polly/src/resources/META-INF/extensions.idx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nextflow.hello.PollyFactory
nextflow.hello.PollyExtension
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import java.nio.file.Path


/**
* Unit test for Hello DSL
* Unit test for Polly DSL
*
* @author : jorge <[email protected]>
*/
@Timeout(10)
class HelloDslTest extends Dsl2Spec{
class PollyDslTest extends Dsl2Spec{

@Shared String pluginsMode

Expand Down Expand Up @@ -66,11 +66,11 @@ class HelloDslTest extends Dsl2Spec{
def 'should perform a hi and create a channel' () {
when:
def SCRIPT = '''
include {reverse} from 'plugin/nf-hello'
include {reverse} from 'plugin/nf-polly'
channel.reverse('hi!')
'''
and:
def result = new MockScriptRunner([hello:[prefix:'>>']]).setScript(SCRIPT).execute()
def result = new MockScriptRunner([Polly:[prefix:'>>']]).setScript(SCRIPT).execute()
then:
result.val == 'hi!'.reverse()
result.val == Channel.STOP
Expand All @@ -79,7 +79,7 @@ class HelloDslTest extends Dsl2Spec{
def 'should store a goodbye' () {
when:
def SCRIPT = '''
include {goodbye} from 'plugin/nf-hello'
include {goodbye} from 'plugin/nf-polly'
channel
.of('folks')
.goodbye()
Expand All @@ -95,9 +95,9 @@ class HelloDslTest extends Dsl2Spec{
def 'can use an imported function' () {
when:
def SCRIPT = '''
include {randomString} from 'plugin/nf-hello'
include {reportMetric} from 'plugin/nf-polly'
channel
.of( randomString(20) )
.of( reportMetric("key","value") )
'''
and:
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import spock.lang.Specification
*
* @author Paolo Di Tommaso <[email protected]>
*/
class HelloFactoryTest extends Specification {
class PollyFactoryTest extends Specification {

def 'should return observer' () {
when:
def result = new HelloFactory().create(Mock(Session))
def result = new PollyFactory().create(Mock(Session))
then:
result.size()==1
result[0] instanceof HelloObserver
result[0] instanceof PollyObserver
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.util.zip.GZIPInputStream
*
* @author Paolo Di Tommaso <[email protected]>
*/
class TestHelper {
class PollyHelper {

static private fs = Jimfs.newFileSystem(Configuration.unix());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MockScriptRunner extends ScriptRunner {
}

MockScriptRunner setScript(String str) {
def script = TestHelper.createInMemTempFile('main.nf', str)
def script = PollyHelper.createInMemTempFile('main.nf', str)
setScript(script)
return this
}
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}

rootProject.name = 'nf-hello'
rootProject.name = 'nf-polly'
include('plugins')
include('plugins:nf-hello')
include('plugins:nf-polly')

0 comments on commit ae9c60c

Please sign in to comment.