|
4 | 4 | const Joi = require('joi'); |
5 | 5 | const dataSchema = require('screwdriver-data-schema'); |
6 | 6 | const executorSchema = dataSchema.plugins.executor; |
| 7 | +const ANNOTATIONS = [ |
| 8 | + 'screwdriver.cd/cpu', |
| 9 | + 'screwdriver.cd/ram', |
| 10 | + 'screwdriver.cd/disk', |
| 11 | + 'screwdriver.cd/timeout', |
| 12 | + 'screwdriver.cd/executor', |
| 13 | + 'screwdriver.cd/buildPeriodically', |
| 14 | + 'screwdriver.cd/repoManifest' |
| 15 | +]; |
| 16 | +const annotationRe = /screwdriver.cd\/(\w+)/; |
7 | 17 |
|
8 | 18 | /** |
9 | 19 | * Validate the config using the schema |
@@ -121,6 +131,26 @@ class Executor { |
121 | 131 | stats() { |
122 | 132 | return {}; |
123 | 133 | } |
| 134 | + |
| 135 | + /** |
| 136 | + * Parsed annotations object |
| 137 | + * @method parseAnnotations |
| 138 | + * @return {Object} object Object contains parsed annotations |
| 139 | + */ |
| 140 | + parseAnnotations(annotations) { |
| 141 | + const parsedAnnotations = {}; |
| 142 | + |
| 143 | + Object.keys(annotations).forEach((key) => { |
| 144 | + const parsedKey = key.replace(/^beta./, ''); |
| 145 | + |
| 146 | + if (ANNOTATIONS.includes(parsedKey)) { |
| 147 | + // First group will be the part after slash, e.g. cpu, ram, disk |
| 148 | + parsedAnnotations[parsedKey.match(annotationRe)[1]] = annotations[key]; |
| 149 | + } |
| 150 | + }); |
| 151 | + |
| 152 | + return parsedAnnotations; |
| 153 | + } |
124 | 154 | } |
125 | 155 |
|
126 | 156 | module.exports = Executor; |
0 commit comments