-
Notifications
You must be signed in to change notification settings - Fork 20
Executor skeleton #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
borditamas
wants to merge
10
commits into
development
Choose a base branch
from
executor-skeleton
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c32f99c
init executor skeleton
borditamas 8b2d8e7
executor skeleton impl
borditamas b4f6ff3
executor skeleton impl
borditamas 6abd90a
executor skeleton cert
borditamas bcb3e30
executor skeleton controller updates
borditamas d1f02c1
executor skeleton execution support impl
borditamas b09695f
executor skeleton execution add missing property
borditamas 60d0bb9
executor skeleton fix
borditamas 02d5523
check configuration
borditamas 959406d
Some fix and Merge branch 'development' into executor-skeleton
borditamas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
...-executor/src/main/java/eu/arrowhead/application/skeleton/executor/ExecutorConstants.java
This file contains hidden or 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,18 @@ | ||
| package eu.arrowhead.application.skeleton.executor; | ||
|
|
||
| public class ExecutorConstants { | ||
|
|
||
| //================================================================================================= | ||
| // members | ||
|
|
||
| public static final String THREAD_NUM_EXECUTION_WORKER = "thread.num.execution-worker"; | ||
| public static final String $THREAD_NUM_EXECUTION_WORKER_WD = "${" + THREAD_NUM_EXECUTION_WORKER + ":1}"; | ||
|
|
||
| //================================================================================================= | ||
| // assistant methods | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| private ExecutorConstants() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } |
This file contains hidden or 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
97 changes: 97 additions & 0 deletions
97
...or/src/main/java/eu/arrowhead/application/skeleton/executor/execution/ExecutionBoard.java
This file contains hidden or 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,97 @@ | ||
| package eu.arrowhead.application.skeleton.executor.execution; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| import eu.arrowhead.common.dto.shared.ChoreographerExecuteStepRequestDTO; | ||
|
|
||
| @Component | ||
| public class ExecutionBoard { | ||
|
|
||
| //================================================================================================= | ||
| // members | ||
|
|
||
| private final Map<String,Job> board = new ConcurrentHashMap<>(); | ||
| private final BlockingQueue<Job> queue = new LinkedBlockingQueue<>(); | ||
|
|
||
| private final Object lock = new Object(); | ||
|
|
||
| //================================================================================================= | ||
| // methods | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public Job newJob(final ChoreographerExecuteStepRequestDTO jobRequest) { | ||
| Assert.notNull(jobRequest, "jobRequest is null"); | ||
|
|
||
| synchronized (lock) { | ||
| final Job job = new Job(jobRequest, ExecutionSignal.DO); | ||
| board.put(getUinqueIdentifier(jobRequest), job); | ||
borditamas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| queue.add(job); | ||
| return job; | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public Optional<Job> peekJob(final long sessionId, final long sessionStepId) { | ||
| final Job job = board.get(getUinqueIdentifier(sessionId, sessionStepId)); | ||
borditamas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (job != null) { | ||
| return Optional.of(job); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public Job nextJob() throws InterruptedException { | ||
| return queue.take(); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public ExecutionSignal getJobExecutionSignal(final long sessionId, final long sessionStepId) { | ||
| synchronized (lock) { | ||
| final Job job = board.get(getUinqueIdentifier(sessionId, sessionStepId)); | ||
| if (job != null) { | ||
| return job.getExecutionSignal(); | ||
| } | ||
| return ExecutionSignal.UNKNOWN; | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public void abortJob(final long sessionId, final long sessionStepId) { | ||
| synchronized (lock) { | ||
| final Optional<Job> optional = peekJob(sessionId, sessionStepId); | ||
| if (optional.isPresent()) { | ||
| optional.get().setExecutionSignal(ExecutionSignal.ABORT); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public void removeJob(final long sessionId, final long sessionStepId) { | ||
| synchronized (lock) { | ||
| final Job job = board.remove(getUinqueIdentifier(sessionId, sessionStepId)); | ||
| if (job != null) { | ||
| queue.remove(job); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //================================================================================================= | ||
| // assistant methods | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| private String getUinqueIdentifier(final ChoreographerExecuteStepRequestDTO request) { | ||
| return getUinqueIdentifier(request.getSessionId(), request.getSessionStepId()); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| private String getUinqueIdentifier(final long sessionId, final long sessionStepId) { | ||
| return sessionId + "-" + sessionStepId; | ||
| } | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
.../src/main/java/eu/arrowhead/application/skeleton/executor/execution/ExecutionManager.java
This file contains hidden or 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,63 @@ | ||
| package eu.arrowhead.application.skeleton.executor.execution; | ||
|
|
||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.function.Function; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import eu.arrowhead.application.skeleton.executor.ExecutorConstants; | ||
|
|
||
| @Component | ||
| public class ExecutionManager extends Thread { | ||
|
|
||
| //================================================================================================= | ||
| // members | ||
|
|
||
| @Autowired | ||
| private ExecutionBoard board; | ||
|
|
||
| @Autowired | ||
| private Function<Job,Runnable> workerFactory; | ||
|
|
||
| private ThreadPoolExecutor threadPool; | ||
|
|
||
| @Value(ExecutorConstants.$THREAD_NUM_EXECUTION_WORKER_WD) | ||
| private int threadNum; | ||
|
|
||
| private boolean doWork = true; | ||
|
|
||
| //================================================================================================= | ||
| // methods | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| @Override | ||
| public void run() { | ||
|
|
||
| threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadNum); | ||
|
|
||
| while (doWork) { | ||
| try { | ||
| final Job job = board.nextJob(); | ||
| if (job.getExecutionSignal() == ExecutionSignal.ABORT) { | ||
| board.removeJob(job.getJobRequest().getSessionId(), job.getJobRequest().getSessionStepId()); | ||
|
|
||
| } else { | ||
| threadPool.execute(workerFactory.apply(job)); | ||
| } | ||
|
|
||
| } catch (final InterruptedException ex) { | ||
| interrupt(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| @Override | ||
| public void interrupt() { | ||
| doWork = false; | ||
| super.interrupt(); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...r/src/main/java/eu/arrowhead/application/skeleton/executor/execution/ExecutionSignal.java
This file contains hidden or 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,6 @@ | ||
| package eu.arrowhead.application.skeleton.executor.execution; | ||
|
|
||
| public enum ExecutionSignal { | ||
|
|
||
| DO, ABORT, UNKNOWN; | ||
| } |
28 changes: 28 additions & 0 deletions
28
...eton-executor/src/main/java/eu/arrowhead/application/skeleton/executor/execution/Job.java
This file contains hidden or 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,28 @@ | ||
| package eu.arrowhead.application.skeleton.executor.execution; | ||
|
|
||
| import eu.arrowhead.common.dto.shared.ChoreographerExecuteStepRequestDTO; | ||
|
|
||
| public class Job { | ||
|
|
||
| //================================================================================================= | ||
| // members | ||
|
|
||
| private final ChoreographerExecuteStepRequestDTO jobRequest; | ||
| private ExecutionSignal executionSignal; | ||
|
|
||
| //================================================================================================= | ||
| // methods | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public Job(final ChoreographerExecuteStepRequestDTO jobRequest, final ExecutionSignal executionSignal) { | ||
| this.jobRequest = jobRequest; | ||
| this.executionSignal = executionSignal; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public ExecutionSignal getExecutionSignal() { return executionSignal; } | ||
| public ChoreographerExecuteStepRequestDTO getJobRequest() { return jobRequest; } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public void setExecutionSignal(final ExecutionSignal executionSignal) { this.executionSignal = executionSignal; } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...rrowhead/application/skeleton/executor/execution/worker/ExecutionWorkerFactoryConfig.java
This file contains hidden or 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,39 @@ | ||
| package eu.arrowhead.application.skeleton.executor.execution.worker; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| import org.springframework.beans.factory.config.BeanDefinition; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Scope; | ||
|
|
||
| import eu.arrowhead.application.skeleton.executor.execution.Job; | ||
|
|
||
| @Configuration | ||
| public class ExecutionWorkerFactoryConfig { | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| @Bean | ||
| public Function<Job,Runnable> executionWorkerFactory() { | ||
| return job -> createExecutionWorker(job); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| @Bean | ||
| @Scope(BeanDefinition.SCOPE_PROTOTYPE) | ||
| public Runnable createExecutionWorker(final Job job) { | ||
| final String serviceDefinition = job.getJobRequest().getMainOrchestrationResult().getService().getServiceDefinition(); | ||
|
|
||
| switch (serviceDefinition) { | ||
| //TODO initiate here your execution workers | ||
| // case "your-main-service-A": | ||
| // return new YourMainServiceAExecutionWorker(job); | ||
|
|
||
| // case "your-main-service-B": | ||
| // return new YourMainServiceBExecutionWorker(job); | ||
|
|
||
| default: | ||
| return new UnkownServiceExecutionWorker(job); | ||
| } | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...rrowhead/application/skeleton/executor/execution/worker/UnkownServiceExecutionWorker.java
This file contains hidden or 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,33 @@ | ||
| package eu.arrowhead.application.skeleton.executor.execution.worker; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import eu.arrowhead.application.skeleton.executor.execution.Job; | ||
|
|
||
| public class UnkownServiceExecutionWorker implements Runnable { | ||
|
|
||
| //================================================================================================= | ||
| // members | ||
|
|
||
| private final Job job; | ||
|
|
||
| private final Logger logger = LogManager.getLogger(UnkownServiceExecutionWorker.class); | ||
|
|
||
| //================================================================================================= | ||
| // methods | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| public UnkownServiceExecutionWorker(Job job) { | ||
| this.job = job; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| @Override | ||
| public void run() { | ||
| logger.error("Unkown service execution request: sessionId={}, sessionStepId={}, service={}", | ||
| job.getJobRequest().getSessionId(), | ||
| job.getJobRequest().getSessionStepId(), | ||
| job.getJobRequest().getMainOrchestrationResult().getService().getServiceDefinition()); | ||
| } | ||
borditamas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.