Search in sources :

Example 11 with K8sApiConfig

use of org.onosproject.k8snode.api.K8sApiConfig in project onos by opennetworkinglab.

the class K8sNodeWebResource method updateApiConfigs.

/**
 * Updates a set of kubernetes API config from the JSON input stream.
 *
 * @param input kubernetes API configs JSON input stream
 * @return 200 OK with the updated kubernetes API config, 400 BAD_REQUEST
 * if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
 * @onos.rsModel K8sApiConfig
 */
@PUT
@Path("api")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateApiConfigs(InputStream input) {
    log.trace(String.format(MESSAGE_NODE, UPDATE));
    Set<K8sApiConfig> configs = readApiConfigConfiguration(input);
    for (K8sApiConfig config : configs) {
        K8sApiConfig existing = configAdminService.apiConfig(endpoint(config));
        if (existing == null) {
            log.warn("There is no API configuration to update : {}", endpoint(config));
            return Response.notModified().build();
        } else if (!existing.equals(config)) {
            configAdminService.updateApiConfig(config);
        }
    }
    return Response.ok().build();
}
Also used : K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

Example 12 with K8sApiConfig

use of org.onosproject.k8snode.api.K8sApiConfig in project onos by opennetworkinglab.

the class K8sApiConfigCodecTest method testK8sApiConfigDecode.

/**
 * Tests the kubernetes API config decoding.
 *
 * @throws IOException IO exception
 */
@Test
public void testK8sApiConfigDecode() throws IOException {
    K8sApiConfig config = getK8sApiConfig("K8sApiConfig.json");
    assertEquals("kubernetes", config.clusterName());
    assertEquals(1, config.segmentId());
    assertEquals("192.168.200.0/24", config.extNetworkCidr().toString());
    assertEquals("NORMAL", config.mode().name());
    assertEquals("HTTPS", config.scheme().name());
    assertEquals("10.134.34.223", config.ipAddress().toString());
    assertEquals(6443, config.port());
    assertEquals("token", config.token());
    assertEquals("caCertData", config.caCertData());
    assertEquals("clientCertData", config.clientCertData());
    assertEquals("clientKeyData", config.clientKeyData());
    assertTrue(config.dvr());
    Set<HostNodesInfo> infos = config.infos();
    assertEquals(1, infos.size());
}
Also used : K8sApiConfigJsonMatcher.matchesK8sApiConfig(org.onosproject.k8snode.codec.K8sApiConfigJsonMatcher.matchesK8sApiConfig) K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig) DefaultK8sApiConfig(org.onosproject.k8snode.api.DefaultK8sApiConfig) DefaultHostNodesInfo(org.onosproject.k8snode.api.DefaultHostNodesInfo) HostNodesInfo(org.onosproject.k8snode.api.HostNodesInfo) Test(org.junit.Test)

Example 13 with K8sApiConfig

use of org.onosproject.k8snode.api.K8sApiConfig in project onos by opennetworkinglab.

the class K8sApiConfigCodecTest method testK8sApiConfigEncode.

/**
 * Tests the kubernetes API config encoding.
 */
@Test
public void testK8sApiConfigEncode() {
    HostNodesInfo info = new DefaultHostNodesInfo.Builder().hostIp(IpAddress.valueOf("192.168.10.10")).nodes(ImmutableSet.of("master", "worker")).build();
    K8sApiConfig config = DefaultK8sApiConfig.builder().clusterName("kubernetes").segmentId(1).extNetworkCidr(IpPrefix.valueOf("192.168.200.0/24")).mode(K8sApiConfig.Mode.NORMAL).scheme(K8sApiConfig.Scheme.HTTPS).ipAddress(IpAddress.valueOf("10.10.10.23")).port(6443).state(CONNECTED).token("token").caCertData("caCertData").clientCertData("clientCertData").clientKeyData("clientKeyData").infos(ImmutableSet.of(info)).dvr(true).build();
    ObjectNode configJson = k8sApiConfigCodec.encode(config, context);
    assertThat(configJson, matchesK8sApiConfig(config));
}
Also used : K8sApiConfigJsonMatcher.matchesK8sApiConfig(org.onosproject.k8snode.codec.K8sApiConfigJsonMatcher.matchesK8sApiConfig) K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig) DefaultK8sApiConfig(org.onosproject.k8snode.api.DefaultK8sApiConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultHostNodesInfo(org.onosproject.k8snode.api.DefaultHostNodesInfo) HostNodesInfo(org.onosproject.k8snode.api.HostNodesInfo) DefaultHostNodesInfo(org.onosproject.k8snode.api.DefaultHostNodesInfo) Test(org.junit.Test)

Example 14 with K8sApiConfig

use of org.onosproject.k8snode.api.K8sApiConfig in project onos by opennetworkinglab.

the class K8sApiConfigManager method removeApiConfig.

@Override
public K8sApiConfig removeApiConfig(String endpoint) {
    checkArgument(!Strings.isNullOrEmpty(endpoint), ERR_NULL_ENDPOINT);
    K8sApiConfig config = configStore.removeApiConfig(endpoint);
    log.info(String.format(MSG_CONFIG, endpoint, MSG_REMOVED));
    return config;
}
Also used : K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig)

Aggregations

K8sApiConfig (org.onosproject.k8snode.api.K8sApiConfig)14 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 DefaultK8sApiConfig (org.onosproject.k8snode.api.DefaultK8sApiConfig)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)3 Consumes (javax.ws.rs.Consumes)3 HostNodesInfo (org.onosproject.k8snode.api.HostNodesInfo)3 K8sApiConfigJsonMatcher.matchesK8sApiConfig (org.onosproject.k8snode.codec.K8sApiConfigJsonMatcher.matchesK8sApiConfig)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 DefaultHostNodesInfo (org.onosproject.k8snode.api.DefaultHostNodesInfo)2 K8sApiConfigService (org.onosproject.k8snode.api.K8sApiConfigService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 INDENT_OUTPUT (com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1