private int getNewPollFrequency(Dictionary<?, ?> properties, int pollFrequency) { int newPollFrequency; try { String s = get(properties, "pollFrequency"); newPollFrequency = isNullOrEmpty(s) ? pollFrequency : Integer.parseInt(s.trim()); } catch (NumberFormatException | ClassCastException e) { newPollFrequency = DEFAULT_POLL_FREQUENCY_SECONDS; } return newPollFrequency; }
/** * Returns a thread factory that produces threads named according to the * supplied name pattern and from the specified thread-group. The thread * group name is expected to be specified in slash-delimited format, e.g. * {@code onos/intent}. The thread names will be produced by converting * the thread group name into dash-delimited format and pre-pended to the * specified pattern. * * @param groupName group name in slash-delimited format to indicate hierarchy * @param pattern name pattern * @return thread factory */ public static ThreadFactory groupedThreads(String groupName, String pattern) { return groupedThreads(groupName, pattern, log); }
/** * Utility to convert a mapper and an input stream into a JSON tree, * and be tolerant of a null tree being returned. * * @param mapper JSON object mapper * @param stream IO stream containing the JSON * @return object node for the given * @throws IOException if JSON parsing fails */ public static ObjectNode readTreeFromStream(ObjectMapper mapper, InputStream stream) throws IOException { return nullIsIllegal((ObjectNode) mapper.readTree(stream), INPUT_JSON_CANNOT_BE_NULL); }
@Modified protected void modified(ComponentContext context) { String propertyValue = Tools.get(context.getProperties(), NUM_THREAD); int newNumThreads = isNullOrEmpty(propertyValue) ? numThreads : Integer.parseInt(propertyValue); if (newNumThreads != numThreads && newNumThreads > 0) { numThreads = newNumThreads; ExecutorService oldWorkerExecutor = executorService; executorService = newFixedThreadPool(numThreads, groupedThreads(GROUP_THREAD_NAME, WORKER_PATTERN, log)); if (oldWorkerExecutor != null) { oldWorkerExecutor.shutdown(); } log.info("Reconfigured number of worker threads to {}", numThreads); } }
/** * Extracts properties from the component configuration context. * * @param context the component context */ private void readComponentConfiguration(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); Boolean flag; flag = Tools.isPropertyEnabled(properties, GM_PURGE_ON_DISCONNECTION); if (flag == null) { log.info("PurgeOnDisconnection is not configured, " + "using current value of {}", purgeOnDisconnection); } else { purgeOnDisconnection = flag; log.info("Configured. PurgeOnDisconnection is {}", purgeOnDisconnection ? "enabled" : "disabled"); } String s = get(properties, GM_POLL_FREQUENCY); try { fallbackGroupPollFrequency = isNullOrEmpty(s) ? GM_POLL_FREQUENCY_DEFAULT : Integer.parseInt(s); } catch (NumberFormatException e) { fallbackGroupPollFrequency = GM_POLL_FREQUENCY_DEFAULT; } }
/** * Filter a given list of intents based on the existing content filter. * * @param intents Iterable of intents * @return further filtered list of intents */ private List<Intent> filterIntents(Iterable<Intent> intents) { return Tools.stream(intents) .filter(i -> contentFilter.filter(i)).collect(Collectors.toList()); }
@Override public Driver getDriver(String driverName) { checkPermission(DRIVER_READ); return nullIsNotFound(drivers.get(driverName), NO_DRIVER); }
String appId = nullIsIllegal(json.get(IntentCodec.APP_ID), IntentCodec.APP_ID + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); CoreService service = context.getService(CoreService.class); builder.appId(nullIsNotFound(service.getAppId(appId), IntentCodec.E_APP_ID_NOT_FOUND));
@Override public String localStatus(DeviceId deviceId) { LocalStatus ls = deviceLocalStatus.get(deviceId); if (ls == null) { return "No Record"; } String timeAgo = Tools.timeAgo(ls.dateTime.toEpochMilli()); return (ls.connected) ? "connected " + timeAgo : "disconnected " + timeAgo; }
/** * Next Objectives are stored as dummy groups for retrieval later * when Forwarding Objectives reference the next objective id. At that point * the dummy group is fetched from the distributed store and the enclosed * treatment is applied as a flow rule action. * * @param nextObj the next objective of type simple */ private void processSimpleNextObjective(NextObjective nextObj) { // Simple next objective has a single treatment (not a collection) log.debug("Received nextObj {}", nextObj.id()); // delay processing to emulate group creation delay(50); TrafficTreatment treatment = nextObj.next().iterator().next(); flowObjectiveStore.putNextGroup(nextObj.id(), new DummyGroup(treatment)); }
@Override protected List<String> choices() { MulticastRouteService service = AbstractShellCommand.get(MulticastRouteService.class); return Tools.stream(service.getRoutes()) .map(McastRoute::group) .map(IpAddress::toString) .collect(Collectors.toList()); }
@Override public Alarm getAlarm(AlarmId alarmId) { return nullIsNotFound(store.getAlarm(checkNotNull(alarmId, "Alarm Id cannot be null")), "Alarm is not found"); }
@Override protected void execute() { FpmInfoService fpmInfo = get(FpmInfoService.class); fpmInfo.peers().forEach((socketAddress, timestamp) -> { if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inet = (InetSocketAddress) socketAddress; print(FORMAT, inet.getHostString(), inet.getPort(), Tools.timeAgo(timestamp)); } else { print("Unknown data format"); } }); } }
private void executeMessage(SSHSession ssh, String xmlMsg) throws IOException, JNCException { String helloRequestXML = xmlMsg.trim(); log.debug("Sending Hello"); ssh.print(helloRequestXML); ssh.flush(); String xmlResponse = null; int i = CONNECTION_CHECK_INTERVAL; while (!ssh.ready() && i > 0) { delay(EVENTINTERVAL); i--; } if (ssh.ready()) { StringBuffer readOne = ssh.readOne(); if (readOne == null) { log.error("The Hello Contains No Capabilites"); throw new JNCException( JNCException.SESSION_ERROR, "server does not support NETCONF base capability: " + Capabilities.NETCONF_BASE_CAPABILITY); } else { xmlResponse = readOne.toString().trim(); log.debug("Reading Capabilities: " + ssh.getSSHConnection().getGanymedConnection() .getHostname()); } } }
@Modified protected void modified(ComponentContext ctx) { Dictionary<?, ?> properties = ctx.getProperties(); if (properties != null) { auditEnabled = Boolean.parseBoolean(get(properties, AUDIT_ENABLED)); auditLogger = get(properties, AUDIT_LOGGER); auditLog = LoggerFactory.getLogger(auditLogger); log.info("Reconfigured; auditEnabled={}; auditLogger={}", auditEnabled, auditLogger); } }
/** * Creates an executor that will be used for synchronization tasks. * <p> * Can be overridden to change the type of executor used. * </p> * * @return executor service */ protected ExecutorService createExecutor() { return newSingleThreadExecutor(groupedThreads("onos/" + appId, "sync", log)); }
@Override public Criterion decodeCriterion(ObjectNode json) { long metadata = nullIsIllegal(json.get(CriterionCodec.METADATA), CriterionCodec.METADATA + MISSING_MEMBER_MESSAGE).asLong(); return Criteria.matchMetadata(metadata); } }
@Override protected List<String> choices() { IntentService service = AbstractShellCommand.get(IntentService.class); return Tools.stream(service.getIntents()) .map(Intent::id) .map(IntentId::toString) .collect(Collectors.toList()); }
/** * Release a specified path. * * @param id path id * @return 200 OK, 404 if given identifier does not exist */ @Path("{path_id}") @DELETE public Response releasePath(@PathParam("path_id") String id) { log.debug("Deletes path by identifier {}.", id); Boolean isSuccess = nullIsNotFound(get(PceService.class).releasePath(TunnelId.valueOf(id)), PCE_PATH_NOT_FOUND); if (!isSuccess) { log.debug("Path identifier {} does not exist", id); } return Response.status(OK).entity(isSuccess.toString()).build(); } }
private void displayCandidates(Map<String, Leadership> leaderBoard) { print("--------------------------------------------------------------------------------------------"); print(FMT_C, "Topic", "Leader", "Term", "Elected", "Candidates"); print("--------------------------------------------------------------------------------------------"); leaderBoard.entrySet() .stream() .filter(es -> allTopics || pattern.matcher(es.getKey()).matches()) .sorted((a, b) -> leadershipComparator.compare(a.getValue(), b.getValue())) .forEach(es -> { Leadership l = es.getValue(); List<NodeId> candidateList = l.candidates(); if (candidateList == null || candidateList.isEmpty()) { return; } print(FMT_C, es.getKey(), String.valueOf(l.leaderNodeId()), l.leader().term(), Tools.timeAgo(l.leader().termStartTime()), // formatting hacks to get it into a table candidateList.get(0).toString()); candidateList.subList(1, candidateList.size()) .forEach(n -> print(FMT_C, " ", " ", " ", " ", n)); print(FMT_C, " ", " ", " ", " ", " "); }); print("--------------------------------------------------------------------------------------------"); }