use of org.onosproject.k8snode.api.K8sApiConfig.Scheme in project onos by opennetworkinglab.
the class K8sApiConfigCodec method decode.
@Override
public K8sApiConfig decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode clusterNameJson = json.get(CLUSTER_NAME);
String clusterNameStr = "";
if (clusterNameJson == null) {
clusterNameStr = DEFAULT_CLUSTER_NAME;
} else {
clusterNameStr = clusterNameJson.asText();
}
JsonNode segmentIdJson = json.get(SEGMENT_ID);
int segmentId = DEFAULT_SEGMENT_ID;
if (segmentIdJson != null) {
segmentId = segmentIdJson.asInt();
}
JsonNode modeJson = json.get(MODE);
String modeStr = "";
if (modeJson == null) {
modeStr = DEFAULT_CONFIG_MODE;
} else {
modeStr = modeJson.asText();
}
Mode mode = Mode.valueOf(modeStr);
Scheme scheme = Scheme.valueOf(nullIsIllegal(json.get(SCHEME).asText(), SCHEME + MISSING_MESSAGE));
IpAddress ipAddress = IpAddress.valueOf(nullIsIllegal(json.get(IP_ADDRESS).asText(), IP_ADDRESS + MISSING_MESSAGE));
int port = json.get(PORT).asInt();
K8sApiConfig.Builder builder = DefaultK8sApiConfig.builder().clusterName(clusterNameStr).segmentId(segmentId).mode(mode).scheme(scheme).ipAddress(ipAddress).port(port).state(DISCONNECTED);
JsonNode dvrJson = json.get(DVR);
if (dvrJson != null) {
builder.dvr(dvrJson.asBoolean());
}
JsonNode tokenJson = json.get(TOKEN);
JsonNode caCertDataJson = json.get(CA_CERT_DATA);
JsonNode clientCertDataJson = json.get(CLIENT_CERT_DATA);
JsonNode clientKeyDataJson = json.get(CLIENT_KEY_DATA);
String token = "";
String caCertData = "";
String clientCertData = "";
String clientKeyData = "";
if (scheme == HTTPS) {
caCertData = nullIsIllegal(caCertDataJson.asText(), CA_CERT_DATA + MISSING_MESSAGE);
clientCertData = nullIsIllegal(clientCertDataJson.asText(), CLIENT_CERT_DATA + MISSING_MESSAGE);
clientKeyData = nullIsIllegal(clientKeyDataJson.asText(), CLIENT_KEY_DATA + MISSING_MESSAGE);
if (tokenJson != null) {
token = tokenJson.asText();
}
} else {
if (tokenJson != null) {
token = tokenJson.asText();
}
if (caCertDataJson != null) {
caCertData = caCertDataJson.asText();
}
if (clientCertDataJson != null) {
clientCertData = clientCertDataJson.asText();
}
if (clientKeyDataJson != null) {
clientKeyData = clientKeyDataJson.asText();
}
}
if (StringUtils.isNotEmpty(token)) {
builder.token(token);
}
if (StringUtils.isNotEmpty(caCertData)) {
builder.caCertData(caCertData);
}
if (StringUtils.isNotEmpty(clientCertData)) {
builder.clientCertData(clientCertData);
}
if (StringUtils.isNotEmpty(clientKeyData)) {
builder.clientKeyData(clientKeyData);
}
JsonNode extNetworkCidrJson = json.get(EXT_NETWORK_CIDR);
if (extNetworkCidrJson != null) {
builder.extNetworkCidr(IpPrefix.valueOf(extNetworkCidrJson.asText()));
}
Set<HostNodesInfo> infos = new HashSet<>();
ArrayNode infosJson = (ArrayNode) json.get(HOST_NODES_INFO);
if (infosJson != null) {
for (JsonNode infoJson : infosJson) {
HostNodesInfo info = context.codec(HostNodesInfo.class).decode((ObjectNode) infoJson, context);
infos.add(info);
}
builder.infos(infos);
}
return builder.build();
}
Aggregations