Search in sources :

Example 1 with Scheme

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();
}
Also used : K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig) DefaultK8sApiConfig(org.onosproject.k8snode.api.DefaultK8sApiConfig) Scheme(org.onosproject.k8snode.api.K8sApiConfig.Scheme) Mode(org.onosproject.k8snode.api.K8sApiConfig.Mode) HostNodesInfo(org.onosproject.k8snode.api.HostNodesInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashSet(java.util.HashSet)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 HashSet (java.util.HashSet)1 IpAddress (org.onlab.packet.IpAddress)1 DefaultK8sApiConfig (org.onosproject.k8snode.api.DefaultK8sApiConfig)1 HostNodesInfo (org.onosproject.k8snode.api.HostNodesInfo)1 K8sApiConfig (org.onosproject.k8snode.api.K8sApiConfig)1 Mode (org.onosproject.k8snode.api.K8sApiConfig.Mode)1 Scheme (org.onosproject.k8snode.api.K8sApiConfig.Scheme)1