Search in sources :

Example 6 with K8sNode

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

the class K8sNodeManager method updateNode.

@Override
public void updateNode(K8sNode node) {
    checkNotNull(node, ERR_NULL_NODE);
    K8sNode intNode;
    K8sNode extNode;
    K8sNode localNode;
    K8sNode tunNode;
    K8sNode existingNode = nodeStore.node(node.hostname());
    checkNotNull(existingNode, ERR_NULL_NODE);
    DeviceId existIntgBridge = nodeStore.node(node.hostname()).intgBridge();
    if (node.intgBridge() == null) {
        intNode = node.updateIntgBridge(existIntgBridge);
        checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
    } else {
        intNode = node;
        checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
    }
    DeviceId existExtBridge = nodeStore.node(node.hostname()).extBridge();
    if (intNode.extBridge() == null) {
        extNode = intNode.updateExtBridge(existExtBridge);
        checkArgument(!hasExtBridge(extNode.extBridge(), extNode.hostname()), NOT_DUPLICATED_MSG, extNode.extBridge());
    } else {
        extNode = intNode;
        checkArgument(!hasExtBridge(extNode.extBridge(), extNode.hostname()), NOT_DUPLICATED_MSG, extNode.extBridge());
    }
    DeviceId existLocalBridge = nodeStore.node(node.hostname()).localBridge();
    if (extNode.localBridge() == null) {
        localNode = extNode.updateLocalBridge(existLocalBridge);
        checkArgument(!hasLocalBridge(localNode.localBridge(), localNode.hostname()), NOT_DUPLICATED_MSG, localNode.localBridge());
    } else {
        localNode = extNode;
        checkArgument(!hasLocalBridge(localNode.localBridge(), localNode.hostname()), NOT_DUPLICATED_MSG, localNode.localBridge());
    }
    if (node.mode() == NORMAL) {
        DeviceId existTunBridge = nodeStore.node(node.hostname()).tunBridge();
        if (localNode.tunBridge() == null) {
            tunNode = localNode.updateTunBridge(existTunBridge);
            checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
        } else {
            tunNode = localNode;
            checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
        }
        nodeStore.updateNode(tunNode);
    } else {
        nodeStore.updateNode(localNode);
    }
    log.info(String.format(MSG_NODE, extNode.hostname(), MSG_UPDATED));
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) DeviceId(org.onosproject.net.DeviceId)

Example 7 with K8sNode

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

the class K8sNodeManager method removeNode.

@Override
public K8sNode removeNode(String hostname) {
    checkArgument(!Strings.isNullOrEmpty(hostname), ERR_NULL_HOSTNAME);
    K8sNode node = nodeStore.removeNode(hostname);
    log.info(String.format(MSG_NODE, hostname, MSG_REMOVED));
    return node;
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode)

Example 8 with K8sNode

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

the class K8sNodeWebResource method stateOfNode.

/**
 * Obtains the state of the kubernetes node.
 *
 * @param hostname hostname of the kubernetes
 * @return the state of the kubernetes node in Json
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("state/{hostname}")
public Response stateOfNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    K8sNode k8sNode = nodeAdminService.node(hostname);
    String nodeState = k8sNode != null ? k8sNode.state().toString() : NOT_EXIST;
    return ok(mapper().createObjectNode().put(STATE, nodeState)).build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with K8sNode

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

the class K8sNodeWebResource method postOnBoardNode.

/**
 * Updates a kubernetes nodes' state as post-on-board.
 *
 * @param hostname kubernetes node name
 * @return 200 OK with the updated kubernetes node's config, 400 BAD_REQUEST
 * if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("update/postonboard/{hostname}")
public Response postOnBoardNode(@PathParam("hostname") String hostname) {
    K8sNode node = nodeAdminService.node(hostname);
    if (node != null && node.state() != POST_ON_BOARD) {
        K8sNode updated = node.updateState(POST_ON_BOARD);
        nodeAdminService.updateNode(updated);
    }
    return Response.ok().build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) 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 10 with K8sNode

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

the class K8sNodeWebResource method updateNodes.

/**
 * Updates a set of kubernetes nodes' config from the JSON input stream.
 *
 * @param input kubernetes nodes JSON input stream
 * @return 200 OK with the updated kubernetes node's config, 400 BAD_REQUEST
 * if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
 * @onos.rsModel K8sNode
 */
@PUT
@Path("node")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNodes(InputStream input) {
    log.trace(String.format(MESSAGE_NODE, UPDATE));
    Set<K8sNode> nodes = readNodeConfiguration(input);
    for (K8sNode node : nodes) {
        K8sNode existing = nodeAdminService.node(node.hostname());
        if (existing == null) {
            log.warn("There is no node configuration to update : {}", node.hostname());
            return Response.notModified().build();
        } else if (!existing.equals(node)) {
            nodeAdminService.updateNode(node);
        }
    }
    return Response.ok().build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) 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)

Aggregations

K8sNode (org.onosproject.k8snode.api.K8sNode)40 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 DefaultK8sNode (org.onosproject.k8snode.api.DefaultK8sNode)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 DeviceId (org.onosproject.net.DeviceId)6 Objects (java.util.Objects)5 Set (java.util.Set)5 ExecutorService (java.util.concurrent.ExecutorService)5 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)5 Consumes (javax.ws.rs.Consumes)5 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)5 ClusterService (org.onosproject.cluster.ClusterService)5 LeadershipService (org.onosproject.cluster.LeadershipService)5