Search in sources :

Example 26 with K8sNode

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

the class K8sServiceHandler method setGroupBuckets.

private void setGroupBuckets(Service service, boolean install) {
    Map<ServicePort, Set<String>> spEpasMap = getSportEpAddressMap(service);
    Map<ServicePort, List<GroupBucket>> spGrpBkts = Maps.newConcurrentMap();
    Map<String, String> nodeIpGatewayIpMap = nodeIpGatewayIpMap(k8sNodeService, k8sNetworkService);
    for (K8sNode node : k8sNodeService.completeNodes()) {
        spEpasMap.forEach((sp, epas) -> {
            List<GroupBucket> bkts = Lists.newArrayList();
            for (String ip : epas) {
                GroupBucket bkt = buildBuckets(node.intgBridge(), nodeIpGatewayIpMap.getOrDefault(ip, ip), sp);
                if (bkt == null) {
                    continue;
                }
                if (install) {
                    bkts.add(bkt);
                } else {
                    bkts.remove(bkt);
                }
            }
            spGrpBkts.put(sp, bkts);
        });
        String serviceIp = service.getSpec().getClusterIP();
        spGrpBkts.forEach((sp, bkts) -> {
            String svcStr = servicePortStr(serviceIp, sp.getPort(), sp.getProtocol());
            int groupId = svcStr.hashCode();
            if (bkts.size() > 0) {
                k8sGroupRuleService.setBuckets(appId, node.intgBridge(), groupId, bkts);
            }
        });
        spEpasMap.forEach((sp, epas) -> epas.forEach(epa -> {
            String podIp = nodeIpGatewayIpMap.getOrDefault(epa, epa);
            int targetPort;
            if (sp.getTargetPort().getIntVal() == null) {
                Pod pod = podByIp(k8sPodService, podIp);
                targetPort = portNumberByName(pod, sp.getTargetPort().getStrVal());
            } else {
                targetPort = sp.getTargetPort().getIntVal();
            }
            if (targetPort != 0) {
                setUnshiftDomainRules(node.intgBridge(), POD_TABLE, PRIORITY_NAT_RULE, serviceIp, sp.getPort(), sp.getProtocol(), podIp, targetPort, install);
            }
        }));
    }
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) NODE_IP_PREFIX(org.onosproject.k8snetworking.api.Constants.NODE_IP_PREFIX) RulePopulatorUtil.niciraConnTrackTreatmentBuilder(org.onosproject.k8snetworking.util.RulePopulatorUtil.niciraConnTrackTreatmentBuilder) PRIORITY_CIDR_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_CIDR_RULE) NiciraConnTrackTreatmentBuilder(org.onosproject.k8snetworking.util.RulePopulatorUtil.NiciraConnTrackTreatmentBuilder) K8sEndpointsEvent(org.onosproject.k8snetworking.api.K8sEndpointsEvent) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) StorageService(org.onosproject.store.service.StorageService) ROUTING_TABLE(org.onosproject.k8snetworking.api.Constants.ROUTING_TABLE) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) RulePopulatorUtil.buildResubmitExtension(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildResubmitExtension) NAT_STATEFUL(org.onosproject.k8snetworking.api.Constants.NAT_STATEFUL) SELECT(org.onosproject.net.group.GroupDescription.Type.SELECT) K8sEndpointsListener(org.onosproject.k8snetworking.api.K8sEndpointsListener) PRIORITY_CT_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_CT_RULE) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) EndpointAddress(io.fabric8.kubernetes.api.model.EndpointAddress) PRIORITY_INTER_ROUTING_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_INTER_ROUTING_RULE) SERVICE_IP_NAT_MODE(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_IP_NAT_MODE) TUN_ENTRY_TABLE(org.onosproject.k8snetworking.api.Constants.TUN_ENTRY_TABLE) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) Tools(org.onlab.util.Tools) K8sServiceService(org.onosproject.k8snetworking.api.K8sServiceService) ACL_TABLE(org.onosproject.k8snetworking.api.Constants.ACL_TABLE) ComponentContext(org.osgi.service.component.ComponentContext) K8sNetworkingUtil.portNumberByName(org.onosproject.k8snetworking.util.K8sNetworkingUtil.portNumberByName) GROUPING_TABLE(org.onosproject.k8snetworking.api.Constants.GROUPING_TABLE) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) K8sNetworkEvent(org.onosproject.k8snetworking.api.K8sNetworkEvent) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Endpoints(io.fabric8.kubernetes.api.model.Endpoints) EndpointSubset(io.fabric8.kubernetes.api.model.EndpointSubset) Pod(io.fabric8.kubernetes.api.model.Pod) RulePopulatorUtil.computeCtMaskFlag(org.onosproject.k8snetworking.util.RulePopulatorUtil.computeCtMaskFlag) SERVICE_IP_NAT_MODE_DEFAULT(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_IP_NAT_MODE_DEFAULT) IPv4(org.onlab.packet.IPv4) GroupId(org.onosproject.core.GroupId) ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) B_CLASS(org.onosproject.k8snetworking.api.Constants.B_CLASS) MacAddress(org.onlab.packet.MacAddress) RulePopulatorUtil.buildLoadExtension(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildLoadExtension) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) LeadershipService(org.onosproject.cluster.LeadershipService) POD_TABLE(org.onosproject.k8snetworking.api.Constants.POD_TABLE) CT_NAT_DST_FLAG(org.onosproject.k8snetworking.util.RulePopulatorUtil.CT_NAT_DST_FLAG) SERVICE_FAKE_MAC_STR(org.onosproject.k8snetworking.api.Constants.SERVICE_FAKE_MAC_STR) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) NAMESPACE_TABLE(org.onosproject.k8snetworking.api.Constants.NAMESPACE_TABLE) K8sNetworkListener(org.onosproject.k8snetworking.api.K8sNetworkListener) NAT_STATELESS(org.onosproject.k8snetworking.api.Constants.NAT_STATELESS) Ethernet(org.onlab.packet.Ethernet) STAT_EGRESS_TABLE(org.onosproject.k8snetworking.api.Constants.STAT_EGRESS_TABLE) A_CLASS(org.onosproject.k8snetworking.api.Constants.A_CLASS) SERVICE_IP_CIDR_DEFAULT(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_IP_CIDR_DEFAULT) K8sNetworkingUtil.podByIp(org.onosproject.k8snetworking.util.K8sNetworkingUtil.podByIp) K8sPodService(org.onosproject.k8snetworking.api.K8sPodService) K8sServiceEvent(org.onosproject.k8snetworking.api.K8sServiceEvent) NodeId(org.onosproject.cluster.NodeId) SERVICE_CIDR(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_CIDR) DST(org.onosproject.k8snetworking.api.Constants.DST) RulePopulatorUtil.computeCtStateFlag(org.onosproject.k8snetworking.util.RulePopulatorUtil.computeCtStateFlag) K8sFlowRuleService(org.onosproject.k8snetworking.api.K8sFlowRuleService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ClusterService(org.onosproject.cluster.ClusterService) PRIORITY_NAT_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_NAT_RULE) IpPrefix(org.onlab.packet.IpPrefix) SRC(org.onosproject.k8snetworking.api.Constants.SRC) GroupBucket(org.onosproject.net.group.GroupBucket) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) K8sNetworkingUtil.getBclassIpPrefixFromCidr(org.onosproject.k8snetworking.util.K8sNetworkingUtil.getBclassIpPrefixFromCidr) K8sServiceListener(org.onosproject.k8snetworking.api.K8sServiceListener) Activate(org.osgi.service.component.annotations.Activate) Service(io.fabric8.kubernetes.api.model.Service) K8sNode(org.onosproject.k8snode.api.K8sNode) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) RulePopulatorUtil(org.onosproject.k8snetworking.util.RulePopulatorUtil) SHIFTED_IP_PREFIX(org.onosproject.k8snetworking.api.Constants.SHIFTED_IP_PREFIX) EndpointPort(io.fabric8.kubernetes.api.model.EndpointPort) NAT_TABLE(org.onosproject.k8snetworking.api.Constants.NAT_TABLE) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) K8sGroupRuleService(org.onosproject.k8snetworking.api.K8sGroupRuleService) Maps(com.google.common.collect.Maps) SERVICE_TABLE(org.onosproject.k8snetworking.api.Constants.SERVICE_TABLE) K8sNetworkingUtil.nodeIpGatewayIpMap(org.onosproject.k8snetworking.util.K8sNetworkingUtil.nodeIpGatewayIpMap) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) RulePopulatorUtil.buildGroupBucket(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildGroupBucket) K8sEndpointsService(org.onosproject.k8snetworking.api.K8sEndpointsService) SHIFTED_IP_CIDR(org.onosproject.k8snetworking.api.Constants.SHIFTED_IP_CIDR) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) Set(java.util.Set) Pod(io.fabric8.kubernetes.api.model.Pod) K8sNode(org.onosproject.k8snode.api.K8sNode) GroupBucket(org.onosproject.net.group.GroupBucket) RulePopulatorUtil.buildGroupBucket(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildGroupBucket) List(java.util.List)

Example 27 with K8sNode

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

the class K8sSwitchingArpHandler method processArpReply.

private void processArpReply(PacketContext context, Ethernet ethPacket) {
    ARP arpPacket = (ARP) ethPacket.getPayload();
    IpAddress srcIp = IpAddress.valueOf(INET, arpPacket.getSenderProtocolAddress());
    MacAddress srcMac = MacAddress.valueOf(arpPacket.getSenderHardwareAddress());
    IpAddress dstIp = IpAddress.valueOf(INET, arpPacket.getTargetProtocolAddress());
    if (dstIp.equals(IpAddress.valueOf(NODE_FAKE_IP_STR))) {
        // mutable MAP scenario is not considered for now
        if (!extHostMacStore.containsKey(srcIp)) {
            extHostMacStore.put(srcIp, srcMac);
        }
        K8sNode k8sNode = k8sNodeService.nodes().stream().filter(n -> n.nodeIp().equals(srcIp)).findAny().orElse(null);
        if (k8sNode == null) {
            return;
        } else {
            if (k8sNode.nodeInfo().nodeMac() != null) {
                return;
            }
        }
        // we update node MAC address which will be referred in node port scenario
        K8sNodeInfo nodeInfo = new K8sNodeInfo(k8sNode.nodeIp(), srcMac);
        K8sNode updatedNode = k8sNode.updateNodeInfo(nodeInfo);
        k8sNodeService.updateNode(updatedNode);
    }
}
Also used : K8sNodeInfo(org.onosproject.k8snode.api.K8sNodeInfo) K8sNode(org.onosproject.k8snode.api.K8sNode) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) ARP(org.onlab.packet.ARP)

Example 28 with K8sNode

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

the class K8sSwitchingHandler method setForwardingRulesForTunnel.

/**
 * Configures the flow rules which are used for L2 packet switching.
 * Note that these rules will be inserted in switching table (table 80).
 *
 * @param port      kubernetes port object
 * @param install   install flag, add the rule if true, remove it otherwise
 */
private void setForwardingRulesForTunnel(K8sPort port, boolean install) {
    // switching rules for the instPorts in the same node
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(port.ipAddress().toIpPrefix()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthDst(port.macAddress()).setOutput(port.portNumber()).build();
    k8sFlowRuleService.setRule(appId, port.deviceId(), selector, treatment, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
    // switching rules for the node in the remote node
    K8sNode localNode = k8sNodeService.node(port.deviceId());
    if (localNode == null) {
        final String error = String.format("Cannot find kubernetes node for %s", port.deviceId());
        throw new IllegalStateException(error);
    }
    k8sNodeService.completeNodes().stream().filter(remoteNode -> !remoteNode.intgBridge().equals(localNode.intgBridge())).forEach(remoteNode -> {
        TrafficTreatment treatmentToTunnel = DefaultTrafficTreatment.builder().setOutput(remoteNode.intgToTunPortNum()).build();
        k8sFlowRuleService.setRule(appId, remoteNode.intgBridge(), selector, treatmentToTunnel, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
        PortNumber portNum = tunnelPortNumByNetId(port.networkId(), k8sNetworkService, remoteNode);
        TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, remoteNode.tunBridge(), localNode.dataIp().getIp4Address()), remoteNode.tunBridge()).setTunnelId(getVni(port)).setOutput(portNum).build();
        k8sFlowRuleService.setRule(appId, remoteNode.tunBridge(), selector, treatmentToRemote, PRIORITY_DEFAULT_RULE, TUN_ENTRY_TABLE, install);
    });
}
Also used : VXLAN(org.onosproject.k8snetworking.api.K8sNetwork.Type.VXLAN) ARP_TABLE(org.onosproject.k8snetworking.api.Constants.ARP_TABLE) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) K8sNetworkListener(org.onosproject.k8snetworking.api.K8sNetworkListener) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) K8sNetworkingUtil.tunnelPortNumByNetId(org.onosproject.k8snetworking.util.K8sNetworkingUtil.tunnelPortNumByNetId) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) K8sFlowRuleService(org.onosproject.k8snetworking.api.K8sFlowRuleService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) GRE(org.onosproject.k8snetworking.api.K8sNetwork.Type.GRE) Objects(java.util.Objects) GENEVE(org.onosproject.k8snetworking.api.K8sNetwork.Type.GENEVE) ARP_BROADCAST_MODE(org.onosproject.k8snetworking.api.Constants.ARP_BROADCAST_MODE) TUN_ENTRY_TABLE(org.onosproject.k8snetworking.api.Constants.TUN_ENTRY_TABLE) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) PRIORITY_DEFAULT_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_DEFAULT_RULE) PRIORITY_TUNNEL_TAG_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_TUNNEL_TAG_RULE) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) FORWARDING_TABLE(org.onosproject.k8snetworking.api.Constants.FORWARDING_TABLE) K8sNetworkEvent(org.onosproject.k8snetworking.api.K8sNetworkEvent) K8sPort(org.onosproject.k8snetworking.api.K8sPort) JUMP_TABLE(org.onosproject.k8snetworking.api.Constants.JUMP_TABLE) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) VTAG_TABLE(org.onosproject.k8snetworking.api.Constants.VTAG_TABLE) K8sNetworkingUtil.getPropertyValue(org.onosproject.k8snetworking.util.K8sNetworkingUtil.getPropertyValue) K8sNode(org.onosproject.k8snode.api.K8sNode) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) K8sNetworkingUtil.tunnelPortNumByNetType(org.onosproject.k8snetworking.util.K8sNetworkingUtil.tunnelPortNumByNetType) RulePopulatorUtil.buildExtension(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildExtension) PRIORITY_SWITCHING_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ConfigProperty(org.onosproject.cfg.ConfigProperty) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) K8sNode(org.onosproject.k8snode.api.K8sNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 29 with K8sNode

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

the class K8sNodeCheckCommand method doExecute.

@Override
protected void doExecute() {
    K8sNodeService nodeService = get(K8sNodeService.class);
    DeviceService deviceService = get(DeviceService.class);
    K8sNode node = nodeService.node(hostname);
    if (node == null) {
        print("Cannot find %s from registered nodes", hostname);
        return;
    }
    print("[Integration Bridge Status]");
    Device intgBridge = deviceService.getDevice(node.intgBridge());
    if (intgBridge != null) {
        print("%s %s=%s available=%s %s", deviceService.isAvailable(intgBridge.id()) ? MSG_OK : MSG_ERROR, node.intgBridgeName(), intgBridge.id(), deviceService.isAvailable(intgBridge.id()), intgBridge.annotations());
        printPortState(deviceService, node.intgBridge(), node.intgBridgePortName());
        printPortState(deviceService, node.intgBridge(), node.intgToExtPatchPortName());
        printPortState(deviceService, node.intgBridge(), node.intgToLocalPatchPortName());
    } else {
        print("%s %s=%s is not available", MSG_ERROR, node.intgBridgeName(), node.intgBridge());
    }
    print("");
    print("[External Bridge Status]");
    Device extBridge = deviceService.getDevice(node.extBridge());
    if (extBridge != null) {
        print("%s %s=%s available=%s %s", deviceService.isAvailable(extBridge.id()) ? MSG_OK : MSG_ERROR, node.extBridgeName(), extBridge.id(), deviceService.isAvailable(extBridge.id()), extBridge.annotations());
        printPortState(deviceService, node.extBridge(), node.extToIntgPatchPortName());
    } else {
        print("%s %s=%s is not available", MSG_ERROR, node.extBridgeName(), node.extBridge());
    }
    print("");
    print("[Local Bridge Status]");
    Device localBridge = deviceService.getDevice(node.localBridge());
    if (localBridge != null) {
        print("%s %s=%s available=%s %s", deviceService.isAvailable(localBridge.id()) ? MSG_OK : MSG_ERROR, node.localBridgeName(), localBridge.id(), deviceService.isAvailable(localBridge.id()), localBridge.annotations());
        printPortState(deviceService, node.localBridge(), node.localToIntgPatchPortName());
    }
    print("");
    print("[Tunnel Bridge Status]");
    Device tunBridge = deviceService.getDevice(node.tunBridge());
    if (tunBridge != null) {
        print("%s %s=%s available=%s %s", deviceService.isAvailable(tunBridge.id()) ? MSG_OK : MSG_ERROR, node.tunBridgeName(), tunBridge.id(), deviceService.isAvailable(tunBridge.id()), tunBridge.annotations());
        printPortState(deviceService, node.tunBridge(), node.tunToIntgPatchPortName());
        if (node.dataIp() != null) {
            printPortState(deviceService, node.tunBridge(), node.vxlanPortName());
            printPortState(deviceService, node.tunBridge(), node.grePortName());
            printPortState(deviceService, node.tunBridge(), node.genevePortName());
        }
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) Device(org.onosproject.net.Device) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) DeviceService(org.onosproject.net.device.DeviceService)

Example 30 with K8sNode

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

the class K8sNodeWebResource method createNodes.

/**
 * Creates a set of kubernetes nodes' config from the JSON input stream.
 *
 * @param input kubernetes nodes JSON input stream
 * @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is malformed
 * @onos.rsModel K8sNode
 */
@POST
@Path("node")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNodes(InputStream input) {
    log.trace(String.format(MESSAGE_NODE, CREATE));
    readNodeConfiguration(input).forEach(node -> {
        K8sNode existing = nodeAdminService.node(node.hostname());
        if (existing == null) {
            nodeAdminService.createNode(node);
        }
    });
    UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(NODES).path(NODE_ID);
    return created(locationBuilder.build()).build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

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