當前位置: 首頁>>代碼示例>>Java>>正文


Java RouterService類代碼示例

本文整理匯總了Java中org.onosproject.vtnrsc.router.RouterService的典型用法代碼示例。如果您正苦於以下問題:Java RouterService類的具體用法?Java RouterService怎麽用?Java RouterService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RouterService類屬於org.onosproject.vtnrsc.router包,在下文中一共展示了RouterService類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@Override
protected void execute() {
    RouterService service = get(RouterService.class);
    try {
        List<String> routes = new ArrayList<String>();
        Router router = new DefaultRouter(
                                          RouterId.valueOf(id),
                                          routerName,
                                          adminStateUp,
                                          status == null ? Status.ACTIVE
                                                        : Status.valueOf(status),
                                          distributed,
                                          null,
                                          VirtualPortId.portId(gatewayPortId),
                                          TenantId.tenantId(tenantId),
                                          routes);
        Set<Router> routerSet = Sets.newHashSet(router);
        service.createRouters(routerSet);
    } catch (Exception e) {
        print(null, e.getMessage());
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:23,代碼來源:RouterCreateCommand.java

示例2: execute

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@Override
protected void execute() {
    RouterService service = get(RouterService.class);
    RouterId routerId = RouterId.valueOf(id);
    Router router = get(RouterService.class).getRouter(routerId);
    try {
        List<String> routes = new ArrayList<String>();
        Router routerObj = new DefaultRouter(
                                             RouterId.valueOf(id),
                                             routerName == null ? router.name() : routerName,
                                             adminStateUp,
                                             status == null ? Status.ACTIVE
                                                           : Status.valueOf(status),
                                             distributed,
                                             null,
                                             gatewayPortId == null ? router.gatewayPortid()
                                                                  : VirtualPortId.portId(gatewayPortId),
                                             tenantId == null ? router.tenantId()
                                                              : TenantId.tenantId(tenantId),
                                             routes);
        Set<Router> routerSet = Sets.newHashSet(routerObj);
        service.createRouters(routerSet);
    } catch (Exception e) {
        print(null, e.getMessage());
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:RouterUpdateCommand.java

示例3: getRouter

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@GET
@Path("{routerUUID}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getRouter(@PathParam("routerUUID") String id,
                          @QueryParam("fields") List<String> fields) {

    if (!get(RouterService.class).exists(RouterId.valueOf(id))) {
        return Response.status(NOT_FOUND)
                .entity("The Router does not exists").build();
    }
    Router sub = nullIsNotFound(get(RouterService.class)
            .getRouter(RouterId.valueOf(id)), NOT_EXIST);

    ObjectNode result = new ObjectMapper().createObjectNode();
    if (fields.size() > 0) {
        result.set("router",
                   new RouterCodec().extracFields(sub, this, fields));
    } else {
        result.set("router", new RouterCodec().encode(sub, this));
    }
    return ok(result.toString()).build();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:RouterWebResource.java

示例4: createRouter

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createRouter(final InputStream input) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        Collection<Router> routers = createOrUpdateByInputStream(subnode);

        Boolean result = nullIsNotFound((get(RouterService.class)
                .createRouters(routers)), CREATE_FAIL);
        if (!result) {
            return Response.status(CONFLICT).entity(CREATE_FAIL).build();
        }
        return Response.status(CREATED).entity(result.toString()).build();

    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:21,代碼來源:RouterWebResource.java

示例5: updateRouter

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@PUT
@Path("{routerUUID}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response updateRouter(@PathParam("routerUUID") String id,
                             final InputStream input) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        Collection<Router> routers = changeUpdateJsonToSub(subnode, id);
        Boolean result = nullIsNotFound(get(RouterService.class)
                .updateRouters(routers), UPDATE_FAIL);
        if (!result) {
            return Response.status(CONFLICT).entity(UPDATE_FAIL).build();
        }
        return ok(result.toString()).build();
    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:21,代碼來源:RouterWebResource.java

示例6: getRouter

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@GET
@Path("{routerUUID}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getRouter(@PathParam("routerUUID") String id,
                          @QueryParam("fields") List<String> fields) {

    if (!get(RouterService.class).exists(RouterId.valueOf(id))) {
        return Response.status(NOT_FOUND)
                .entity("The Router does not exists").build();
    }
    Router sub = nullIsNotFound(get(RouterService.class)
            .getRouter(RouterId.valueOf(id)), NOT_EXIST);

    ObjectNode result = new ObjectMapper().createObjectNode();
    if (!fields.isEmpty()) {
        result.set("router",
                   new RouterCodec().extracFields(sub, this, fields));
    } else {
        result.set("router", new RouterCodec().encode(sub, this));
    }
    return ok(result.toString()).build();
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:24,代碼來源:RouterWebResource.java

示例7: createRouter

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createRouter(final InputStream input) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        Collection<Router> routers = createOrUpdateByInputStream(subnode);

        Boolean result = nullIsNotFound((get(RouterService.class)
                .createRouters(routers)), CREATE_FAIL);
        if (!result) {
            return Response.status(CONFLICT).entity(CREATE_FAIL).build();
        }
        return Response.status(CREATED).entity(result.toString()).build();

    } catch (IllegalArgumentException | IOException e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:21,代碼來源:RouterWebResource.java

示例8: execute

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@Override
protected void execute() {
    RouterService service = get(RouterService.class);
    if (id == null && routerName == null) {
        print(null, "one of id, routerName should not be null");
    }
    try {
        Set<RouterId> routerSet = Sets.newHashSet();
        if (id != null) {
            routerSet.add(RouterId.valueOf(id));
            service.removeRouters(routerSet);
        } else {
            Iterable<Router> routers = service.getRouters();
            if (routers == null) {
                return;
            }
            for (Router router : routers) {
                if (router.name().equals(routerName)) {
                    routerSet.add(router.id());
                    service.removeRouters(routerSet);
                    return;
                }
            }
        }
    } catch (Exception e) {
        print(null, e.getMessage());
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:29,代碼來源:RouterRemoveCommand.java

示例9: listRouters

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response listRouters() {
    Collection<Router> routers = get(RouterService.class).getRouters();
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("routers", new RouterCodec().encode(routers, this));
    return ok(result.toString()).build();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:10,代碼來源:RouterWebResource.java

示例10: deleteSingleRouter

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@DELETE
@Path("{routerUUID}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteSingleRouter(@PathParam("routerUUID") String id)
        throws IOException {
    try {
        RouterId routerId = RouterId.valueOf(id);
        Set<RouterId> routerIds = Sets.newHashSet(routerId);
        get(RouterService.class).removeRouters(routerIds);
        return Response.noContent().entity(DELETE_SUCCESS).build();
    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:16,代碼來源:RouterWebResource.java

示例11: addRouterInterface

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@PUT
@Path("{routerUUID}/add_router_interface")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response addRouterInterface(@PathParam("routerUUID") String id,
                                   final InputStream input) {
    if (!get(RouterService.class).exists(RouterId.valueOf(id))) {
        return Response.status(NOT_FOUND).entity(NOT_EXIST).build();
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        if (!subnode.hasNonNull("id")) {
            throw new IllegalArgumentException("id should not be null");
        } else if (subnode.get("id").asText().isEmpty()) {
            throw new IllegalArgumentException("id should not be empty");
        }
        RouterId routerId = RouterId.valueOf(id);
        if (!subnode.hasNonNull("subnet_id")) {
            throw new IllegalArgumentException("subnet_id should not be null");
        } else if (subnode.get("subnet_id").asText().isEmpty()) {
            throw new IllegalArgumentException("subnet_id should not be empty");
        }
        SubnetId subnetId = SubnetId
                .subnetId(subnode.get("subnet_id").asText());
        if (!subnode.hasNonNull("tenant_id")) {
            throw new IllegalArgumentException("tenant_id should not be null");
        } else if (subnode.get("tenant_id").asText().isEmpty()) {
            throw new IllegalArgumentException("tenant_id should not be empty");
        }
        TenantId tenentId = TenantId
                .tenantId(subnode.get("tenant_id").asText());
        if (!subnode.hasNonNull("port_id")) {
            throw new IllegalArgumentException("port_id should not be null");
        } else if (subnode.get("port_id").asText().isEmpty()) {
            throw new IllegalArgumentException("port_id should not be empty");
        }
        VirtualPortId portId = VirtualPortId
                .portId(subnode.get("port_id").asText());
        RouterInterface routerInterface = RouterInterface
                .routerInterface(subnetId, portId, routerId, tenentId);
        get(RouterInterfaceService.class)
                .addRouterInterface(routerInterface);
        return ok(INTFACR_ADD_SUCCESS).build();
    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:49,代碼來源:RouterWebResource.java

示例12: removeRouterInterface

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
@PUT
@Path("{routerUUID}/remove_router_interface")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response removeRouterInterface(@PathParam("routerUUID") String id,
                                      final InputStream input) {
    if (!get(RouterService.class).exists(RouterId.valueOf(id))) {
        return Response.status(NOT_FOUND).entity(NOT_EXIST).build();
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        if (!subnode.hasNonNull("id")) {
            throw new IllegalArgumentException("id should not be null");
        } else if (subnode.get("id").asText().isEmpty()) {
            throw new IllegalArgumentException("id should not be empty");
        }
        RouterId routerId = RouterId.valueOf(id);
        if (!subnode.hasNonNull("subnet_id")) {
            throw new IllegalArgumentException("subnet_id should not be null");
        } else if (subnode.get("subnet_id").asText().isEmpty()) {
            throw new IllegalArgumentException("subnet_id should not be empty");
        }
        SubnetId subnetId = SubnetId
                .subnetId(subnode.get("subnet_id").asText());
        if (!subnode.hasNonNull("port_id")) {
            throw new IllegalArgumentException("port_id should not be null");
        } else if (subnode.get("port_id").asText().isEmpty()) {
            throw new IllegalArgumentException("port_id should not be empty");
        }
        VirtualPortId portId = VirtualPortId
                .portId(subnode.get("port_id").asText());
        if (!subnode.hasNonNull("tenant_id")) {
            throw new IllegalArgumentException("tenant_id should not be null");
        } else if (subnode.get("tenant_id").asText().isEmpty()) {
            throw new IllegalArgumentException("tenant_id should not be empty");
        }
        TenantId tenentId = TenantId
                .tenantId(subnode.get("tenant_id").asText());
        RouterInterface routerInterface = RouterInterface
                .routerInterface(subnetId, portId, routerId, tenentId);
        get(RouterInterfaceService.class)
                .removeRouterInterface(routerInterface);
        return ok(INTFACR_DEL_SUCCESS).build();
    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:49,代碼來源:RouterWebResource.java

示例13: changeUpdateJsonToSub

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
/**
 * Returns a collection of floatingIps from floatingIpNodes.
 *
 * @param subnode the router json node
 * @param routerId the router identify
 * @return routers a collection of router
 * @throws Exception when any argument is illegal
 */
public Collection<Router> changeUpdateJsonToSub(JsonNode subnode,
                                                String routerId)
                                                        throws Exception {
    checkNotNull(subnode, JSON_NOT_NULL);
    checkNotNull(routerId, "routerId should not be null");
    Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();
    JsonNode routerNode = subnode.get("router");
    RouterId id = RouterId.valueOf(routerId);
    Router sub = nullIsNotFound(get(RouterService.class).getRouter(id),
                                NOT_EXIST);
    TenantId tenantId = sub.tenantId();

    VirtualPortId gwPortId = null;
    if (routerNode.hasNonNull("gw_port_id")) {
        gwPortId = VirtualPortId
                .portId(routerNode.get("gw_port_id").asText());
    }
    Status status = sub.status();

    String routerName = routerNode.get("name").asText();

    checkArgument(routerNode.get("admin_state_up").isBoolean(),
                  "admin_state_up should be boolean");
    boolean adminStateUp = routerNode.get("admin_state_up").asBoolean();

    boolean distributed = sub.distributed();
    if (routerNode.hasNonNull("distributed")) {
        distributed = routerNode.get("distributed").asBoolean();
    }
    RouterGateway gateway = sub.externalGatewayInfo();
    if (routerNode.hasNonNull("external_gateway_info")) {
        gateway = jsonNodeToGateway(routerNode
                .get("external_gateway_info"));
    }
    List<String> routes = new ArrayList<String>();
    DefaultRouter routerObj = new DefaultRouter(id, routerName,
                                                adminStateUp, status,
                                                distributed, gateway,
                                                gwPortId, tenantId, routes);
    subMap.put(id, routerObj);
    return Collections.unmodifiableCollection(subMap.values());
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:51,代碼來源:RouterWebResource.java

示例14: changeUpdateJsonToSub

import org.onosproject.vtnrsc.router.RouterService; //導入依賴的package包/類
/**
 * Returns a collection of floatingIps from floatingIpNodes.
 *
 * @param subnode the router json node
 * @param routerId the router identify
 * @return routers a collection of router
 */
public Collection<Router> changeUpdateJsonToSub(JsonNode subnode,
                                                String routerId) {
    checkNotNull(subnode, JSON_NOT_NULL);
    checkNotNull(routerId, "routerId should not be null");
    Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();
    JsonNode routerNode = subnode.get("router");
    RouterId id = RouterId.valueOf(routerId);
    Router sub = nullIsNotFound(get(RouterService.class).getRouter(id),
                                NOT_EXIST);
    TenantId tenantId = sub.tenantId();

    VirtualPortId gwPortId = null;
    if (routerNode.hasNonNull("gw_port_id")) {
        gwPortId = VirtualPortId
                .portId(routerNode.get("gw_port_id").asText());
    }
    Status status = sub.status();

    String routerName = routerNode.get("name").asText();

    checkArgument(routerNode.get("admin_state_up").isBoolean(),
                  "admin_state_up should be boolean");
    boolean adminStateUp = routerNode.get("admin_state_up").asBoolean();

    boolean distributed = sub.distributed();
    if (routerNode.hasNonNull("distributed")) {
        distributed = routerNode.get("distributed").asBoolean();
    }
    RouterGateway gateway = sub.externalGatewayInfo();
    if (routerNode.hasNonNull("external_gateway_info")) {
        gateway = jsonNodeToGateway(routerNode
                .get("external_gateway_info"));
    }
    List<String> routes = new ArrayList<String>();
    DefaultRouter routerObj = new DefaultRouter(id, routerName,
                                                adminStateUp, status,
                                                distributed, gateway,
                                                gwPortId, tenantId, routes);
    subMap.put(id, routerObj);
    return Collections.unmodifiableCollection(subMap.values());
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:49,代碼來源:RouterWebResource.java


注:本文中的org.onosproject.vtnrsc.router.RouterService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。