| 1 |
/* |
| 2 |
Copyright 2016 Google Inc. All rights reserved. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
import java.util.Arrays; |
| 18 |
import java.util.HashSet; |
| 19 |
import java.util.Set; |
| 20 |
|
| 21 |
public class BaseTemplate extends JsonnetObject { |
| 22 |
public Set<String> nonHiddenFields() { |
| 23 |
Set<String> r = super.nonHiddenFields(); |
| 24 |
r.addAll(Arrays.asList("apiVersion", "kind", "spec")); |
| 25 |
return r; |
| 26 |
} |
| 27 |
|
| 28 |
// Mandatory param |
| 29 |
public Object accessToken() { |
| 30 |
throw new RuntimeException("accessToken must be defined"); |
| 31 |
} |
| 32 |
|
| 33 |
// Optional params |
| 34 |
public Object image() { return "gcr.io/cooltool-1009/pipeline_image:latest"; } |
| 35 |
public Object[] extraEnv() { return new Object[]{}; } |
| 36 |
|
| 37 |
public Object apiVersion() { return "v1"; } |
| 38 |
public Object kind() { return "ReplicationController"; } |
| 39 |
|
| 40 |
public class BaseTemplateSpec extends JsonnetObject { |
| 41 |
public Set<String> nonHiddenFields() { |
| 42 |
Set<String> r = super.nonHiddenFields(); |
| 43 |
r.addAll(Arrays.asList("replicas", "spec")); |
| 44 |
return r; |
| 45 |
} |
| 46 |
|
| 47 |
public Object replicas() { return 1.0; } |
| 48 |
|
| 49 |
public class BaseTemplateSpecSpec extends JsonnetObject { |
| 50 |
public Set<String> nonHiddenFields() { |
| 51 |
Set<String> r = super.nonHiddenFields(); |
| 52 |
r.addAll(Arrays.asList("containers")); |
| 53 |
return r; |
| 54 |
} |
| 55 |
|
| 56 |
public class Container0 extends JsonnetObject { |
| 57 |
public Set<String> nonHiddenFields() { |
| 58 |
Set<String> r = super.nonHiddenFields(); |
| 59 |
r.addAll(Arrays.asList("env", "image", "name")); |
| 60 |
return r; |
| 61 |
} |
| 62 |
|
| 63 |
class Env0 extends JsonnetObject { |
| 64 |
public Set<String> nonHiddenFields() { |
| 65 |
Set<String> r = super.nonHiddenFields(); |
| 66 |
r.addAll(Arrays.asList("name", "value")); |
| 67 |
return r; |
| 68 |
} |
| 69 |
public Object name() { return "ACCESSTOKEN"; } |
| 70 |
public Object value() { return BaseTemplate.this.accessToken(); } |
| 71 |
} |
| 72 |
|
| 73 |
public Object[] env() { |
| 74 |
// Concatenating arrays (first + second) is hard in Java. |
| 75 |
Object[] first = new Object[]{ new Env0() }; |
| 76 |
Object[] second = BaseTemplate.this.extraEnv(); |
| 77 |
Object[] result = Arrays.copyOf(first, first.length + second.length); |
| 78 |
System.arraycopy(second, 0, result, first.length, second.length); |
| 79 |
return result; |
| 80 |
} |
| 81 |
public Object image() { return BaseTemplate.this.image(); } |
| 82 |
public Object name() { return "twitter-to-redis"; } |
| 83 |
} |
| 84 |
|
| 85 |
public Object containers() { return new Object[] { new Container0() }; } |
| 86 |
} |
| 87 |
public Object spec() { return new BaseTemplateSpecSpec(); } |
| 88 |
|
| 89 |
} |
| 90 |
public Object spec() { return new BaseTemplateSpec(); } |
| 91 |
} |
| 92 |
|