-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Executor ID to provide more unique executor identifier
with initial implementation for AWS ECS
- Loading branch information
Showing
5 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
libs/micronaut-worker/src/main/java/com/agorapulse/worker/executor/ExecutorId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.agorapulse.worker.executor; | ||
|
||
/** | ||
* Unique identifier of the executor. | ||
* @param id unique identifier of the executor | ||
*/ | ||
public record ExecutorId(String id) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...cronaut-worker/src/main/java/com/agorapulse/worker/executor/ecs/EcsExecutorIdFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.agorapulse.worker.executor.ecs; | ||
|
||
import com.agorapulse.worker.executor.ExecutorId; | ||
import io.micronaut.context.annotation.Bean; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.context.annotation.Value; | ||
import jakarta.inject.Singleton; | ||
|
||
@Factory | ||
@Requires(property = "ecs.agent.uri") | ||
public class EcsExecutorIdFactory { | ||
|
||
@Bean | ||
@Singleton | ||
public ExecutorId ecsExecutorId(@Value("${ecs.agent.uri}") String ecsAgentUri) { | ||
return new ExecutorId(extractId(ecsAgentUri)); | ||
} | ||
|
||
private static String extractId(String ecsAgentUri) { | ||
return ecsAgentUri.substring(ecsAgentUri.lastIndexOf('/') + 1, ecsAgentUri.lastIndexOf("-")); | ||
} | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...worker/src/test/groovy/com/agorapulse/worker/executor/ecs/EcsExecutorIdFactorySpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.agorapulse.worker.executor.ecs | ||
|
||
import com.agorapulse.worker.executor.ExecutorId | ||
import spock.lang.Specification | ||
|
||
class EcsExecutorIdFactorySpec extends Specification { | ||
|
||
void 'extract id'() { | ||
given: | ||
String id = 'http://169.254.170.2/api/c613006db31d4ac192bbb07b1577c40e-1280352332' | ||
expect: | ||
new EcsExecutorIdFactory().ecsExecutorId(id) == new ExecutorId('c613006db31d4ac192bbb07b1577c40e') | ||
} | ||
|
||
} |