Skip to content

Commit

Permalink
Updated the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhitam02 committed Apr 1, 2024
1 parent 0623110 commit 4d502df
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 35 deletions.
13 changes: 5 additions & 8 deletions plugins/nf-polly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ ext{
}

dependencies {
// 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'
compileOnly 'org.pf4j:pf4j:3.4.1'
// add here plugins depepencies
implementation platform('software.amazon.awssdk:bom:2.21.1')
implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:kinesis'
Expand All @@ -63,14 +68,6 @@ dependencies {
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'
// implementation 'software.amazon.awssdk.core.exception.SdkClientException'

// 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'
compileOnly 'org.pf4j:pf4j:3.4.1'
// add here plugins depepencies

// test configuration
testImplementation "org.apache.groovy:groovy:4.0.18"
testImplementation "org.apache.groovy:groovy-nio:4.0.18"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import nextflow.plugin.extension.PluginExtensionPoint
@Slf4j
@CompileStatic
class PollyExtension extends PluginExtensionPoint {
// static final Logger logger = LogManager.getLogger(KinesisWriteApp.class);
static final ObjectMapper objMapper = new ObjectMapper();

static final Logger logger = LoggerFactory.getLogger(PollyExtension.class);
// static final ObjectMapper objMapper = new ObjectMapper();
/*
* A session hold information about current execution of the script
*/
Expand Down Expand Up @@ -120,21 +120,23 @@ class PollyExtension extends PluginExtensionPoint {
* Using @Function annotation we allow this function can be imported from the pipeline script
*/
@Function
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());
}
void reportMetric(String key, String value) {
// logger.info("Starting PutRecord Producer");
String streamName = "pravaah-dev-user-defined-metrics-events-v1";
String partitionKey = "12345";
Map<String, String> keyValuePairs = Map.of(key, value);
try {
byte[] data = new ObjectMapper().writeValueAsBytes(Map.of("metricfromTest5", keyValuePairs));
KinesisClient client = KinesisClient.builder().build();
PutRecordRequest putRequest = PutRecordRequest.builder()
.partitionKey(partitionKey)
.streamName(streamName)
.data(SdkBytes.fromByteArray(data))
.build();
PutRecordResponse response = client.putRecord(putRequest);
System.out.println("Produced Record " + response.sequenceNumber() + " to Shard " + response.shardId() + " (line 145)");
} catch (Exception e) {
System.out.println("Failed to produce: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import org.pf4j.PluginDescriptorFinder
import spock.lang.Shared
import spock.lang.Timeout
import test.Dsl2Spec
import software.amazon.awssdk.core.exception.SdkClientException

import java.nio.file.Path


/**
* Unit test for Polly DSL
* Unit test for Hello DSL
*
* @author : jorge <[email protected]>
*/
Expand Down Expand Up @@ -71,7 +70,7 @@ class PollyDslTest extends Dsl2Spec{
channel.reverse('hi!')
'''
and:
def result = new MockScriptRunner([Polly:[prefix:'>>']]).setScript(SCRIPT).execute()
def result = new MockScriptRunner([hello:[prefix:'>>']]).setScript(SCRIPT).execute()
then:
result.val == 'hi!'.reverse()
result.val == Channel.STOP
Expand All @@ -94,17 +93,17 @@ class PollyDslTest extends Dsl2Spec{
}

def 'can use an imported function' () {
// when:
when:
def SCRIPT = '''
include {reportMetric} from 'plugin/nf-polly'
channel
.of( reportMetric("key","value") )
'''
// and:
// def result = new MockScriptRunner([:]).setScript(SCRIPT).execute()
// then:
// // result.val.size() == 20
// result.val == Channel.STOP
and:
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute()
then:
result.val.size() == 20
result.val == Channel.STOP
}

}

0 comments on commit 4d502df

Please sign in to comment.