Search in sources :

Example 6 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class OpenstackManagementWebResource method syncStates.

/**
 * Synchronizes the network states with openstack.
 *
 * @return 200 OK with sync result, 404 not found
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sync/states")
public Response syncStates() {
    Map<String, String> headerMap = new HashMap();
    headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
    Optional<OpenstackNode> node = osNodeAdminService.nodes(CONTROLLER).stream().findFirst();
    if (!node.isPresent()) {
        log.error(AUTH_INFO_NOT_FOUND);
        throw new ItemNotFoundException(AUTH_INFO_NOT_FOUND);
    }
    OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
    if (osClient == null) {
        log.error(AUTH_INFO_NOT_CORRECT);
        throw new ItemNotFoundException(AUTH_INFO_NOT_CORRECT);
    }
    try {
        osClient.headers(headerMap).networking().securitygroup().list().forEach(osSg -> {
            if (osSgAdminService.securityGroup(osSg.getId()) != null) {
                osSgAdminService.updateSecurityGroup(osSg);
            } else {
                osSgAdminService.createSecurityGroup(osSg);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve security group due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().network().list().forEach(osNet -> {
            if (osNetAdminService.network(osNet.getId()) != null) {
                osNetAdminService.updateNetwork(osNet);
            } else {
                osNetAdminService.createNetwork(osNet);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve network due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().subnet().list().forEach(osSubnet -> {
            if (osNetAdminService.subnet(osSubnet.getId()) != null) {
                osNetAdminService.updateSubnet(osSubnet);
            } else {
                osNetAdminService.createSubnet(osSubnet);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve subnet due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().port().list().forEach(osPort -> {
            if (osNetAdminService.port(osPort.getId()) != null) {
                osNetAdminService.updatePort(osPort);
            } else {
                osNetAdminService.createPort(osPort);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve port due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().router().list().forEach(osRouter -> {
            if (osRouterAdminService.router(osRouter.getId()) != null) {
                osRouterAdminService.updateRouter(osRouter);
            } else {
                osRouterAdminService.createRouter(osRouter);
            }
            osNetAdminService.ports().stream().filter(osPort -> Objects.equals(osPort.getDeviceId(), osRouter.getId()) && Objects.equals(osPort.getDeviceOwner(), DEVICE_OWNER_IFACE)).forEach(osPort -> addRouterIface(osPort, osRouterAdminService));
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve router due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().floatingip().list().forEach(osFloating -> {
            if (osRouterAdminService.floatingIp(osFloating.getId()) != null) {
                osRouterAdminService.updateFloatingIp(osFloating);
            } else {
                osRouterAdminService.createFloatingIp(osFloating);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve floating IP due to {}", e.getMessage());
        return Response.serverError().build();
    }
    return ok(mapper().createObjectNode()).build();
}
Also used : AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) OpenstackRoutingArpHandler(org.onosproject.openstacknetworking.impl.OpenstackRoutingArpHandler) OSClient(org.openstack4j.api.OSClient) OpenstackNetworkingUtil(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil) CoreService(org.onosproject.core.CoreService) OpenstackRouterAdminService(org.onosproject.openstacknetworking.api.OpenstackRouterAdminService) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackHaService(org.onosproject.openstacknetworking.api.OpenstackHaService) COMPLETE(org.onosproject.openstacknode.api.NodeState.COMPLETE) OpenstackNetworkingUtil.checkArpMode(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.checkArpMode) OpenstackSecurityGroupAdminService(org.onosproject.openstacknetworking.api.OpenstackSecurityGroupAdminService) MediaType(javax.ws.rs.core.MediaType) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Consumes(javax.ws.rs.Consumes) OpenstackNetworkingUtil.addRouterIface(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.addRouterIface) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) Response.status(javax.ws.rs.core.Response.status) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) ItemNotFoundException(org.onlab.util.ItemNotFoundException) OpenstackNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) List(java.util.List) NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) Response(javax.ws.rs.core.Response) StreamSupport.stream(java.util.stream.StreamSupport.stream) Optional(java.util.Optional) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) PathParam(javax.ws.rs.PathParam) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) GET(javax.ws.rs.GET) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OpenstackSwitchingArpHandler(org.onosproject.openstacknetworking.impl.OpenstackSwitchingArpHandler) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) OpenstackNetworkingUtil.checkActivationFlag(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.checkActivationFlag) Logger(org.slf4j.Logger) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) OpenstackSecurityGroupHandler(org.onosproject.openstacknetworking.impl.OpenstackSecurityGroupHandler) PUT(javax.ws.rs.PUT) OpenstackRoutingSnatHandler(org.onosproject.openstacknetworking.impl.OpenstackRoutingSnatHandler) Comparator(java.util.Comparator) NodeState(org.onosproject.openstacknode.api.NodeState) HashMap(java.util.HashMap) OSClient(org.openstack4j.api.OSClient) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) ItemNotFoundException(org.onlab.util.ItemNotFoundException) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class OpenstackManagementWebResource method purgeRulesBase.

private boolean purgeRulesBase() {
    ApplicationId appId = coreService.getAppId(Constants.OPENSTACK_NETWORKING_APP_ID);
    if (appId == null) {
        throw new ItemNotFoundException("application not found");
    }
    flowRuleService.removeFlowRulesById(appId);
    boolean result = true;
    long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
    // we make sure all flow rules are removed from the store
    while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
        long waitMs = timeoutExpiredMs - System.currentTimeMillis();
        try {
            sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during rule purging...");
        }
        if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
            break;
        } else {
            flowRuleService.removeFlowRulesById(appId);
            log.info("Failed to purging flow rules, retrying rule purging...");
        }
        if (waitMs <= 0) {
            result = false;
            break;
        }
    }
    if (result) {
        log.info("Successfully purged flow rules!");
    } else {
        log.warn("Failed to purge flow rules.");
    }
    return result;
}
Also used : ApplicationId(org.onosproject.core.ApplicationId) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 8 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class FlowsWebResource method deleteFlowByDeviceIdAndFlowId.

/**
 * Removes flow rule. Removes the specified flow rule.
 *
 * @param deviceId device identifier
 * @param flowId   flow rule identifier
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{deviceId}/{flowId}")
public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, @PathParam("flowId") long flowId) {
    FlowRuleService service = get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId));
    if (!flowEntries.iterator().hasNext()) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }
    StreamSupport.stream(flowEntries.spliterator(), false).filter(entry -> entry.id().value() == flowId).forEach(service::removeFlowRules);
    return Response.noContent().build();
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) ListMultimap(com.google.common.collect.ListMultimap) GET(javax.ws.rs.GET) DeviceService(org.onosproject.net.device.DeviceService) Path(javax.ws.rs.Path) FlowEntry(org.onosproject.net.flow.FlowEntry) ApplicationService(org.onosproject.app.ApplicationService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) FlowRuleService(org.onosproject.net.flow.FlowRuleService) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) StreamSupport(java.util.stream.StreamSupport) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Tools.nullIsNotFound(org.onlab.util.Tools.nullIsNotFound) Device(org.onosproject.net.Device) IndexTableId(org.onosproject.net.flow.IndexTableId) IOException(java.io.IOException) ItemNotFoundException(org.onlab.util.ItemNotFoundException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Response(javax.ws.rs.core.Response) FlowRule(org.onosproject.net.flow.FlowRule) UriInfo(javax.ws.rs.core.UriInfo) DeviceId(org.onosproject.net.DeviceId) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) InputStream(java.io.InputStream) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 9 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class FlowsWebResource method getFlowByDeviceId.

/**
 * Gets flow entries of a device. Returns array of all flow rules for the
 * specified device.
 *
 * @param deviceId device identifier
 * @return 200 OK with a collection of flows of given device
 * @onos.rsModel FlowEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
// TODO: we need to add "/device" suffix to the path to differentiate with appId
@Path("{deviceId}")
public Response getFlowByDeviceId(@PathParam("deviceId") String deviceId) {
    FlowRuleService service = get(FlowRuleService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode flowsNode = root.putArray(FLOWS);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId));
    if (flowEntries == null || !flowEntries.iterator().hasNext()) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }
    for (FlowEntry entry : flowEntries) {
        flowsNode.add(codec(FlowEntry.class).encode(entry, this));
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class NetconfSessionMinaImpl method getClientCapabilites.

/**
 * Get the list of the netconf client capabilities from device driver property.
 *
 * @param deviceId the deviceID for which to recover the capabilities from the driver.
 * @return the String list of clientCapability property, or null if it is not configured
 */
public Set<String> getClientCapabilites(DeviceId deviceId) {
    Set<String> capabilities = new LinkedHashSet<>();
    DriverService driverService = directory.get(DriverService.class);
    try {
        Driver driver = driverService.getDriver(deviceId);
        if (driver == null) {
            return capabilities;
        }
        String clientCapabilities = driver.getProperty(NETCONF_CLIENT_CAPABILITY);
        if (clientCapabilities == null) {
            return capabilities;
        }
        String[] textStr = clientCapabilities.split("\\|");
        capabilities.addAll(Arrays.asList(textStr));
        return capabilities;
    } catch (ItemNotFoundException e) {
        log.warn("Driver for device {} currently not available", deviceId);
        return capabilities;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Driver(org.onosproject.net.driver.Driver) DriverService(org.onosproject.net.driver.DriverService) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Aggregations

ItemNotFoundException (org.onlab.util.ItemNotFoundException)25 DriverHandler (org.onosproject.net.driver.DriverHandler)9 Path (javax.ws.rs.Path)8 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 FlowRuleService (org.onosproject.net.flow.FlowRuleService)5 ApplicationId (org.onosproject.core.ApplicationId)4 Driver (org.onosproject.net.driver.Driver)4 List (java.util.List)3 Consumes (javax.ws.rs.Consumes)3 DeviceId (org.onosproject.net.DeviceId)3 FlowEntry (org.onosproject.net.flow.FlowEntry)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 PathParam (javax.ws.rs.PathParam)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2