blob: b1ce6f5eb4f6077c76494c1c17ab6df975bc4a96 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.schema.document.SDDocumentType;
import com.yahoo.schema.document.TemporarySDDocumentType;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
/**
* @author arnej
*/
public class TemporarySDTypeResolver {
private final DeployLogger deployLogger;
private final Collection<Schema> toProcess;
private final List<SDDocumentType> docTypes = new LinkedList<>();
public TemporarySDTypeResolver(Collection<Schema> schemas, DeployLogger deployLogger) {
this.deployLogger = deployLogger;
this.toProcess = schemas;
}
private SDDocumentType findDocType(String name) {
assert(name != null);
for (var doc : docTypes) {
if (doc.getName().equals(name)) {
return doc;
}
}
deployLogger.logApplicationPackage(Level.WARNING, "No document type in application matching name: "+name);
return null;
}
public void process() {
docTypes.add(SDDocumentType.VESPA_DOCUMENT);
for (Schema schema : toProcess) {
if (schema.hasDocument()) {
docTypes.add(schema.getDocument());
}
}
// first, fix inheritance
for (SDDocumentType doc : docTypes) {
for (SDDocumentType inherited : doc.getInheritedTypes()) {
if (inherited instanceof TemporarySDDocumentType) {
var actual = findDocType(inherited.getName());
if (actual != null) {
doc.inherit(actual);
} else {
deployLogger.logApplicationPackage(Level.WARNING, "Unresolved inherit '"+inherited.getName() +"' for document "+doc.getName());
}
}
}
}
// next, check owned types (structs only?)
for (SDDocumentType doc : docTypes) {
for (SDDocumentType owned : doc.getTypes()) {
if (owned instanceof TemporarySDDocumentType) {
deployLogger.logApplicationPackage(Level.WARNING, "Schema '"+doc.getName()+"' owned type '"+owned.getName()+"' is temporary, should not happen");
continue;
}
for (SDDocumentType inherited : owned.getInheritedTypes()) {
if (inherited instanceof TemporarySDDocumentType) {
var actual = doc.getType(inherited.getName());
if (actual != null) {
owned.inherit(actual);
} else {
deployLogger.logApplicationPackage(Level.WARNING, "Unresolved inherit '"+inherited.getName() +"' for type '"+owned.getName()+"' in document "+doc.getName());
}
}
}
}
}
}
}
|