This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from jvfullam/issue#33
- Loading branch information
Showing
6 changed files
with
345 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...ibm.jbatch.tck/src/main/java/com/ibm/jbatch/tck/artifacts/reusable/DoNothingBatchlet.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,32 @@ | ||
/* | ||
* Copyright 2016 International Business Machines Corp. | ||
* | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. 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 com.ibm.jbatch.tck.artifacts.reusable; | ||
|
||
import javax.batch.api.AbstractBatchlet; | ||
import javax.batch.runtime.context.JobContext; | ||
import javax.batch.runtime.context.StepContext; | ||
import javax.inject.Inject; | ||
|
||
@javax.inject.Named("doNothingBatchlet") | ||
public class DoNothingBatchlet extends AbstractBatchlet { | ||
|
||
@Override | ||
public String process() { | ||
return "The DoNothingBatchlet COMPLETED Without Incident"; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...com/ibm/jbatch/tck/artifacts/specialized/DeciderReceivesCorrectStepExecutionsDecider.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,68 @@ | ||
/* | ||
* Copyright 2016 International Business Machines Corp. | ||
* | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. 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 com.ibm.jbatch.tck.artifacts.specialized; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
|
||
import javax.batch.api.BatchProperty; | ||
import javax.batch.api.Decider; | ||
import javax.batch.runtime.StepExecution; | ||
import javax.batch.runtime.context.JobContext; | ||
import javax.inject.Inject; | ||
|
||
@javax.inject.Named("deciderReceivesCorrectStepExecutionsDecider") | ||
public class DeciderReceivesCorrectStepExecutionsDecider implements Decider { | ||
|
||
@Inject | ||
JobContext jobCtx; | ||
|
||
@Inject @BatchProperty(name="expected.number.of.step.executions") | ||
String numOfStepExecs; | ||
|
||
@Override | ||
public String decide(StepExecution[] stepExecutions) throws Exception { | ||
if (stepExecutions.length != Integer.parseInt(numOfStepExecs)) { | ||
throw new Exception("Expecting stepExecutions array of size " +numOfStepExecs+ ", found one of size = " + stepExecutions.length); | ||
} | ||
|
||
/*we sort the stepExecutions to guarantee that the decider exit status, made up of the concatenated | ||
step executions, will have the same order of step executions on subsequent job executions*/ | ||
sortStepExecutionsByStepName(stepExecutions); | ||
|
||
/* | ||
* exitStatus will be in the format: | ||
* "split1flow1step1:1235;split1flow1step2:1236;split1flow2step1:1237;" | ||
* split the exitStatus at each ";" for each stepExecution | ||
* split a stepExecution at ":" to get the stepName and stepExecutionId | ||
*/ | ||
String exitStatus = ""; | ||
for (StepExecution stepExecution: stepExecutions) { | ||
exitStatus += stepExecution.getStepName() + ":" + stepExecution.getStepExecutionId() + ";"; | ||
} | ||
return exitStatus; //Decider return value should be set as the Job Exit Status | ||
} | ||
|
||
private void sortStepExecutionsByStepName(StepExecution[] stepExecutions) { | ||
Arrays.sort(stepExecutions, new Comparator<StepExecution>() { | ||
@Override | ||
public int compare(StepExecution se1, StepExecution se2) { | ||
return se1.getStepName().compareTo(se2.getStepName()); | ||
} | ||
}); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...main/resources/META-INF/batch-jobs/decider_receives_correct_step_execution_after_step.xml
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Copyright 2016 International Business Machines Corp. See the NOTICE file distributed with this work | ||
for additional information regarding copyright ownership. 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. --> | ||
<job id="decider_receives_correct_step_execution_after_step" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0"> | ||
<step id="step1" next="decider1" allow-start-if-complete="#{jobParameters['allow.start.if.complete']}"> | ||
<batchlet ref="doNothingBatchlet"/> | ||
</step> | ||
<decision id="decider1" ref="deciderReceivesCorrectStepExecutionsDecider"> | ||
<properties> | ||
<property name="expected.number.of.step.executions" value="1"/> | ||
</properties> | ||
<stop on="#{jobParameters['decider.stop.on']}"/> | ||
<next on="*" to="step2"/> | ||
</decision> | ||
<step id="step2"> | ||
<batchlet ref="doNothingBatchlet"/> | ||
<end on="*"/> | ||
</step> | ||
</job> |
33 changes: 33 additions & 0 deletions
33
...in/resources/META-INF/batch-jobs/decider_receives_correct_step_executions_after_split.xml
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Copyright 2016 International Business Machines Corp. See the NOTICE file distributed with this work | ||
for additional information regarding copyright ownership. 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. --> | ||
<job id="decider_receives_correct_step_executions_after_split" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0"> | ||
<split id="split1" next="decider1"> | ||
<flow id="split1flow1"> | ||
<step id="split1flow1step1" allow-start-if-complete="#{jobParameters['split1flow1step1.allow.start.if.complete']}"> | ||
<batchlet ref="doNothingBatchlet"/> | ||
</step> | ||
</flow> | ||
<flow id="split1flow2"> | ||
<step id="split1flow2step1" allow-start-if-complete="#{jobParameters['split1flow2step1.allow.start.if.complete']}"> | ||
<batchlet ref="doNothingBatchlet"/> | ||
</step> | ||
</flow> | ||
</split> | ||
<decision id="decider1" ref="deciderReceivesCorrectStepExecutionsDecider"> | ||
<properties> | ||
<property name="expected.number.of.step.executions" value="2"/> | ||
</properties> | ||
<stop on="#{jobParameters['decider.stop.on']}"/> | ||
<next on="*" to="step2"/> | ||
</decision> | ||
<step id="step2"> | ||
<batchlet ref="doNothingBatchlet"/> | ||
<end on="*"/> | ||
</step> | ||
</job> |
Oops, something went wrong.