Skip to content

Commit c1bcfea

Browse files
committed
Add getters for the parsed domain related yaml files' kubernetes artifacts
1 parent 2d7410a commit c1bcfea

10 files changed

+250
-12
lines changed

src/test/java/oracle/kubernetes/operator/create/CreateDomainInputsFileTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ public void createDomain_usesSpecifiedInputsFileAndSucceedsAndGeneratesExpectedY
7272
CreateDomainInputs inputs = readDefaultInputsFile().domainUid("test-domain-uid");
7373
assertThat(execCreateDomain(userProjects.getPath(), inputs), succeedsAndPrints("Completed"));
7474
DomainFiles domainFiles = new DomainFiles(userProjects.getPath(), inputs);
75+
assertThat(Files.isRegularFile(domainFiles.getCreateWeblogicDomainJobYamlPath()), is(true));
7576
assertThat(Files.isRegularFile(domainFiles.getDomainCustomResourceYamlPath()), is(true));
76-
// TBD - other per-domain generated yaml files once they're added to DomainFiles
77+
assertThat(Files.isRegularFile(domainFiles.getTraefikYamlPath()), is(true));
78+
assertThat(Files.isRegularFile(domainFiles.getTraefikSecurityYamlPath()), is(true));
79+
assertThat(Files.isRegularFile(domainFiles.getWeblogicDomainPersistentVolumeYamlPath()), is(true));
80+
assertThat(Files.isRegularFile(domainFiles.getWeblogicDomainPersistentVolumeClaimYamlPath()), is(true));
7781
}
7882
}

src/test/java/oracle/kubernetes/operator/create/DomainFiles.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public class DomainFiles {
1111
public static final String CREATE_SCRIPT = "src/test/scripts/unit-test-create-weblogic-domain.sh";
1212
private static final String DOMAIN_CUSTOM_RESOURCE_YAML = "domain-custom-resource.yaml";
1313

14+
private static final String CREATE_WEBLOGIC_DOMAIN_JOB_YAML = "create-weblogic-domain-job.yaml";
15+
private static final String TRAEFIK_YAML = "traefik.yaml";
16+
private static final String TRAEFIK_SECURITY_YAML = "traefik-security.yaml";
17+
private static final String WEBLOGIC_DOMAIN_PERSISTENT_VOLUME_YAML = "weblogic-domain-persistent-volume.yaml";
18+
private static final String WEBLOGIC_DOMAIN_PERSISTENT_VOLUME_CLAIM_YAML = "weblogic-domain-persistent-volume-claim.yaml";
19+
1420
private Path userProjectsPath;
1521
private CreateDomainInputs inputs;
1622

@@ -21,20 +27,31 @@ public DomainFiles(Path userProjectsPath, CreateDomainInputs inputs) {
2127

2228
public Path userProjectsPath() { return userProjectsPath; }
2329

30+
public Path getCreateWeblogicDomainJobYamlPath() {
31+
return getWeblogicDomainPath().resolve(CREATE_WEBLOGIC_DOMAIN_JOB_YAML);
32+
}
33+
2434
public Path getDomainCustomResourceYamlPath() {
2535
return getWeblogicDomainPath().resolve(DOMAIN_CUSTOM_RESOURCE_YAML);
2636
}
2737

38+
public Path getTraefikYamlPath() {
39+
return getWeblogicDomainPath().resolve(TRAEFIK_YAML);
40+
}
41+
42+
public Path getTraefikSecurityYamlPath() {
43+
return getWeblogicDomainPath().resolve(TRAEFIK_SECURITY_YAML);
44+
}
45+
46+
public Path getWeblogicDomainPersistentVolumeYamlPath() {
47+
return getWeblogicDomainPath().resolve(WEBLOGIC_DOMAIN_PERSISTENT_VOLUME_YAML);
48+
}
49+
50+
public Path getWeblogicDomainPersistentVolumeClaimYamlPath() {
51+
return getWeblogicDomainPath().resolve(WEBLOGIC_DOMAIN_PERSISTENT_VOLUME_CLAIM_YAML);
52+
}
53+
2854
public Path getWeblogicDomainPath() {
2955
return userProjectsPath().resolve("weblogic-domains").resolve(inputs.getDomainUid());
3056
}
31-
32-
/*
33-
TBD
34-
create-weblogic-domain-domain-job.yaml
35-
traefik-security.yaml
36-
traefik.yaml
37-
weblogic-domain-persistent-volume-claim.yaml
38-
weblogic-domain-persistent-volume.yaml
39-
*/
4057
}

src/test/java/oracle/kubernetes/operator/create/GeneratedDomainYamlFiles.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ public class GeneratedDomainYamlFiles {
1515

1616
private UserProjects userProjects;
1717
private DomainFiles domainFiles;
18+
private ParsedCreateWeblogicDomainJobYaml createDomainJobYaml;
1819
private ParsedDomainCustomResourceYaml domainCustomResourceYaml;
19-
// TBD - other generated yaml files
20+
private ParsedTraefikYaml traefikYaml;
21+
private ParsedTraefikSecurityYaml traefikSecurityYaml;
22+
private ParsedWeblogicDomainPersistentVolumeYaml weblogicDomainPersistentVolumeYaml;
23+
private ParsedWeblogicDomainPersistentVolumeClaimYaml weblogicDomainPersistentVolumeClaimYaml;
2024

2125
public static GeneratedDomainYamlFiles generateDomainYamlFiles(CreateDomainInputs inputs) throws Exception {
2226
return new GeneratedDomainYamlFiles(inputs);
@@ -28,9 +32,18 @@ private GeneratedDomainYamlFiles(CreateDomainInputs inputs) throws Exception {
2832
try {
2933
domainFiles = new DomainFiles(userProjects.getPath(), inputs);
3034
assertThat(execCreateDomain(userProjects.getPath(), inputs), succeedsAndPrints("Completed"));
35+
createDomainJobYaml =
36+
new ParsedCreateWeblogicDomainJobYaml(domainFiles.getCreateWeblogicDomainJobYamlPath(), inputs);
3137
domainCustomResourceYaml =
3238
new ParsedDomainCustomResourceYaml(domainFiles.getDomainCustomResourceYamlPath(), inputs);
33-
// TBD - other generated yaml files
39+
traefikYaml =
40+
new ParsedTraefikYaml(domainFiles.getTraefikYamlPath(), inputs);
41+
traefikSecurityYaml =
42+
new ParsedTraefikSecurityYaml(domainFiles.getTraefikSecurityYamlPath(), inputs);
43+
weblogicDomainPersistentVolumeYaml =
44+
new ParsedWeblogicDomainPersistentVolumeYaml(domainFiles.getWeblogicDomainPersistentVolumeYamlPath(), inputs);
45+
weblogicDomainPersistentVolumeClaimYaml =
46+
new ParsedWeblogicDomainPersistentVolumeClaimYaml(domainFiles.getWeblogicDomainPersistentVolumeClaimYamlPath(), inputs);
3447
ok = true;
3548
} finally {
3649
if (!ok) {

src/test/java/oracle/kubernetes/operator/create/KubernetesArtifactUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public class KubernetesArtifactUtils {
4545
public static final String KIND_CLUSTER_ROLE = "ClusterRole";
4646
public static final String KIND_CLUSTER_ROLE_BINDING = "ClusterRoleBinding";
4747
public static final String KIND_DOMAIN = "Domain";
48+
public static final String KIND_JOB = "Job";
4849
public static final String KIND_DEPLOYMENT = "Deployment";
4950
public static final String KIND_NAMESPACE = "Namespace";
51+
public static final String KIND_PERSISTENT_VOLUME = "PersistentVolume";
52+
public static final String KIND_PERSISTENT_VOLUME_CLAIM = "PersistentVolumeClaim";
5053
public static final String KIND_ROLE_BINDING = "RoleBinding";
5154
public static final String KIND_SECRET = "Secret";
5255
public static final String KIND_SERVICE = "Service";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
package oracle.kubernetes.operator.create;
3+
4+
import java.nio.file.Path;
5+
6+
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
7+
8+
/**
9+
* Parses a generated create-weblogic-domain-job.yaml file into a set of typed k8s java objects
10+
*/
11+
public class ParsedCreateWeblogicDomainJobYaml {
12+
13+
private CreateDomainInputs inputs;
14+
private ParsedKubernetesYaml parsedYaml;
15+
16+
public ParsedCreateWeblogicDomainJobYaml(Path yamlPath, CreateDomainInputs inputs) throws Exception {
17+
this.inputs = inputs;
18+
parsedYaml = new ParsedKubernetesYaml(yamlPath);
19+
}
20+
}
21+
22+
/*
23+
ConfigMap - domain-domainuid-scripts
24+
kind: Job - domain-domainuid-job
25+
*/

src/test/java/oracle/kubernetes/operator/create/ParsedKubernetesYaml.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
import io.kubernetes.client.models.V1beta1ClusterRoleBinding;
1515
import io.kubernetes.client.models.V1beta1RoleBinding;
1616
import io.kubernetes.client.models.V1ConfigMap;
17+
import io.kubernetes.client.models.V1Job;
1718
import io.kubernetes.client.models.V1ObjectMeta;
1819
import io.kubernetes.client.models.V1Namespace;
20+
import io.kubernetes.client.models.V1PersistentVolume;
21+
import io.kubernetes.client.models.V1PersistentVolumeClaim;
1922
import io.kubernetes.client.models.V1Secret;
2023
import io.kubernetes.client.models.V1Service;
2124
import io.kubernetes.client.models.V1ServiceAccount;
@@ -43,7 +46,10 @@ public ParsedKubernetesYaml(InputStream is) {
4346
kindToHandler.put(KIND_CLUSTER_ROLE_BINDING, new ClusterRoleBindingHandler());
4447
kindToHandler.put(KIND_DEPLOYMENT, new DeploymentHandler());
4548
kindToHandler.put(KIND_DOMAIN, new DomainHandler());
49+
kindToHandler.put(KIND_JOB, new JobHandler());
4650
kindToHandler.put(KIND_NAMESPACE, new NamespaceHandler());
51+
kindToHandler.put(KIND_PERSISTENT_VOLUME, new PersistentVolumeHandler());
52+
kindToHandler.put(KIND_PERSISTENT_VOLUME_CLAIM, new PersistentVolumeClaimHandler());
4753
kindToHandler.put(KIND_ROLE_BINDING, new RoleBindingHandler());
4854
kindToHandler.put(KIND_SECRET, new SecretHandler());
4955
kindToHandler.put(KIND_SERVICE, new ServiceHandler());
@@ -89,10 +95,22 @@ public TypeHandler<Domain> getDomains() {
8995
return (TypeHandler<Domain>)getHandler(KIND_DOMAIN);
9096
}
9197

98+
public TypeHandler<V1Job> getJobs() {
99+
return (TypeHandler<V1Job>)getHandler(KIND_JOB);
100+
}
101+
92102
public TypeHandler<V1Namespace> getNamespaces() {
93103
return (TypeHandler<V1Namespace>)getHandler(KIND_NAMESPACE);
94104
}
95105

106+
public TypeHandler<V1PersistentVolume> getPersistentVolumes() {
107+
return (TypeHandler<V1PersistentVolume>)getHandler(KIND_PERSISTENT_VOLUME);
108+
}
109+
110+
public TypeHandler<V1PersistentVolumeClaim> getPersistentVolumeClaims() {
111+
return (TypeHandler<V1PersistentVolumeClaim>)getHandler(KIND_PERSISTENT_VOLUME_CLAIM);
112+
}
113+
96114
public TypeHandler<V1beta1RoleBinding> getRoleBindings() {
97115
return (TypeHandler<V1beta1RoleBinding>)getHandler(KIND_ROLE_BINDING);
98116
}
@@ -199,11 +217,26 @@ private static class DomainHandler extends TypeHandler<Domain> {
199217
@Override protected V1ObjectMeta getMetadata(Domain instance) { return instance.getMetadata(); }
200218
}
201219

220+
private static class JobHandler extends TypeHandler<V1Job> {
221+
private JobHandler() { super(V1Job.class); }
222+
@Override protected V1ObjectMeta getMetadata(V1Job instance) { return instance.getMetadata(); }
223+
}
224+
202225
private static class NamespaceHandler extends TypeHandler<V1Namespace> {
203226
private NamespaceHandler() { super(V1Namespace.class); }
204227
@Override protected V1ObjectMeta getMetadata(V1Namespace instance) { return instance.getMetadata(); }
205228
}
206229

230+
private static class PersistentVolumeHandler extends TypeHandler<V1PersistentVolume> {
231+
private PersistentVolumeHandler() { super(V1PersistentVolume.class); }
232+
@Override protected V1ObjectMeta getMetadata(V1PersistentVolume instance) { return instance.getMetadata(); }
233+
}
234+
235+
private static class PersistentVolumeClaimHandler extends TypeHandler<V1PersistentVolumeClaim> {
236+
private PersistentVolumeClaimHandler() { super(V1PersistentVolumeClaim.class); }
237+
@Override protected V1ObjectMeta getMetadata(V1PersistentVolumeClaim instance) { return instance.getMetadata(); }
238+
}
239+
207240
private static class RoleBindingHandler extends TypeHandler<V1beta1RoleBinding> {
208241
private RoleBindingHandler() { super(V1beta1RoleBinding.class); }
209242
@Override protected V1ObjectMeta getMetadata(V1beta1RoleBinding instance) { return instance.getMetadata(); }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
package oracle.kubernetes.operator.create;
3+
4+
import java.nio.file.Path;
5+
6+
import io.kubernetes.client.models.V1beta1ClusterRole;
7+
import io.kubernetes.client.models.V1beta1ClusterRoleBinding;
8+
9+
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
10+
import oracle.kubernetes.weblogic.domain.v1.Domain;
11+
12+
/**
13+
* Parses a generated traefik-security.yaml file into a set of typed k8s java objects
14+
*/
15+
public class ParsedTraefikSecurityYaml {
16+
17+
private CreateDomainInputs inputs;
18+
private ParsedKubernetesYaml parsedYaml;
19+
20+
public ParsedTraefikSecurityYaml(Path yamlPath, CreateDomainInputs inputs) throws Exception {
21+
this.inputs = inputs;
22+
parsedYaml = new ParsedKubernetesYaml(yamlPath);
23+
}
24+
25+
public V1beta1ClusterRole getTraefikClusterRole() {
26+
return parsedYaml.getClusterRoles().find(getClusterScope() + "-traefik");
27+
}
28+
29+
public V1beta1ClusterRoleBinding getTraefikDashboardClusterRoleBinding() {
30+
return parsedYaml.getClusterRoleBindings().find(getClusterScope() + "-traefik-dashboard");
31+
}
32+
33+
private String getClusterScope() {
34+
return inputs.getDomainUid() + "-" + inputs.getClusterName().toLowerCase();
35+
}
36+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
package oracle.kubernetes.operator.create;
3+
4+
import java.nio.file.Path;
5+
6+
import io.kubernetes.client.models.ExtensionsV1beta1Deployment;
7+
import io.kubernetes.client.models.V1ConfigMap;
8+
import io.kubernetes.client.models.V1Service;
9+
import io.kubernetes.client.models.V1ServiceAccount;
10+
11+
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
12+
13+
/**
14+
* Parses a generated traefik.yaml file into a set of typed k8s java objects
15+
*/
16+
public class ParsedTraefikYaml {
17+
18+
private CreateDomainInputs inputs;
19+
private ParsedKubernetesYaml parsedYaml;
20+
21+
public ParsedTraefikYaml(Path yamlPath, CreateDomainInputs inputs) throws Exception {
22+
this.inputs = inputs;
23+
parsedYaml = new ParsedKubernetesYaml(yamlPath);
24+
}
25+
26+
public V1ServiceAccount getTraefikServiceAccount() {
27+
return parsedYaml.getServiceAccounts().find(getTraefikScope());
28+
}
29+
30+
public ExtensionsV1beta1Deployment getTraefikDeployment() {
31+
return parsedYaml.getDeployments().find(getTraefikScope());
32+
}
33+
34+
public V1ConfigMap getTraefikConfig() {
35+
return parsedYaml.getConfigMaps().find(getTraefikScope());
36+
}
37+
38+
public V1Service getTraefikService() {
39+
return parsedYaml.getServices().find(getTraefikScope());
40+
}
41+
42+
public V1Service getTraefikDashboardService() {
43+
return parsedYaml.getServices().find(getClusterScope() + "-traefik-dashboard");
44+
}
45+
46+
private String getTraefikScope() {
47+
return getClusterScope() + "-traefik";
48+
}
49+
50+
private String getClusterScope() {
51+
return inputs.getDomainUid() + "-" + inputs.getClusterName().toLowerCase();
52+
}
53+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
package oracle.kubernetes.operator.create;
3+
4+
import java.nio.file.Path;
5+
6+
import io.kubernetes.client.models.V1PersistentVolumeClaim;
7+
8+
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
9+
import oracle.kubernetes.weblogic.domain.v1.Domain;
10+
11+
/**
12+
* Parses a generated weblogic-domain-persistent-volume-claim.yaml file into a set of typed k8s java objects
13+
*/
14+
public class ParsedWeblogicDomainPersistentVolumeClaimYaml {
15+
16+
private CreateDomainInputs inputs;
17+
private ParsedKubernetesYaml parsedYaml;
18+
19+
public ParsedWeblogicDomainPersistentVolumeClaimYaml(Path yamlPath, CreateDomainInputs inputs) throws Exception {
20+
this.inputs = inputs;
21+
parsedYaml = new ParsedKubernetesYaml(yamlPath);
22+
}
23+
24+
public V1PersistentVolumeClaim getPersistentVolumeClaim() {
25+
return parsedYaml.getPersistentVolumeClaims().find(inputs.getPersistenceVolumeClaimName());
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
package oracle.kubernetes.operator.create;
3+
4+
import java.nio.file.Path;
5+
6+
import io.kubernetes.client.models.V1PersistentVolume;
7+
8+
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
9+
import oracle.kubernetes.weblogic.domain.v1.Domain;
10+
11+
/**
12+
* Parses a generated weblogic-domain-persistent-volume.yaml file into a set of typed k8s java objects
13+
*/
14+
public class ParsedWeblogicDomainPersistentVolumeYaml {
15+
16+
private CreateDomainInputs inputs;
17+
private ParsedKubernetesYaml parsedYaml;
18+
19+
public ParsedWeblogicDomainPersistentVolumeYaml(Path yamlPath, CreateDomainInputs inputs) throws Exception {
20+
this.inputs = inputs;
21+
parsedYaml = new ParsedKubernetesYaml(yamlPath);
22+
}
23+
24+
public V1PersistentVolume getPersistentVolume() {
25+
return parsedYaml.getPersistentVolumes().find(inputs.getPersistenceVolumeName());
26+
}
27+
}

0 commit comments

Comments
 (0)