use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class IntentsWebResource method getIntentFlowsById.
/**
* Gets all related flow entries created by a particular intent.
* Returns all flow entries of the specified intent.
*
* @param appId application identifier
* @param key intent key
* @return 200 OK with intent data
* @onos.rsModel Relatedflows
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("relatedflows/{appId}/{key}")
public Response getIntentFlowsById(@PathParam("appId") String appId, @PathParam("key") String key) {
ApplicationId applicationId = get(CoreService.class).getAppId(appId);
nullIsNotFound(applicationId, APP_ID_NOT_FOUND);
IntentService intentService = get(IntentService.class);
FlowRuleService flowService = get(FlowRuleService.class);
Intent intent = intentService.getIntent(Key.of(key, applicationId));
if (intent == null) {
long numericalKey = Long.decode(key);
intent = intentService.getIntent(Key.of(numericalKey, applicationId));
}
nullIsNotFound(intent, INTENT_NOT_FOUND);
ObjectNode root = mapper().createObjectNode();
root.put(APP_ID, appId);
root.put(ID, key);
IntentFilter intentFilter = new IntentFilter(intentService, flowService);
List<Intent> installables = intentService.getInstallableIntents(intent.key());
root.put(INTENT_TYPE, intent.getClass().getSimpleName());
ArrayNode pathsNode = root.putArray(INTENT_PATHS);
for (List<FlowEntry> flowEntries : intentFilter.readIntentFlows(installables)) {
ArrayNode flowNode = pathsNode.addArray();
for (FlowEntry entry : flowEntries) {
flowNode.add(codec(FlowEntry.class).encode(entry, this));
}
}
return ok(root).build();
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class IntentKeyCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
IntentService service = AbstractShellCommand.get(IntentService.class);
Iterator<Intent> it = service.getIntents().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next().key().toString());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method createIntent.
/**
* Submits a new optical intent.
* Creates and submits optical intents from the JSON request.
*
* @param stream input JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel CreateIntent
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createIntent(InputStream stream) {
try {
IntentService service = get(IntentService.class);
ObjectNode root = readTreeFromStream(mapper(), stream);
Intent intent = decode(root);
service.submit(intent);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("intents").path(intent.appId().name()).path(Long.toString(intent.id().fingerprint()));
return Response.created(locationBuilder.build()).build();
} catch (IOException ioe) {
throw new IllegalArgumentException(ioe);
}
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class IntentSynchronizerTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
setUpConnectPoints();
intentService = EasyMock.createMock(IntentService.class);
intentSynchronizer = new TestIntentSynchronizer();
intentSynchronizer.coreService = new TestCoreService();
intentSynchronizer.clusterService = new TestClusterService();
intentSynchronizer.leadershipService = new LeadershipServiceAdapter();
intentSynchronizer.intentService = intentService;
intentSynchronizer.activate();
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class StartMonitorCommand method doExecute.
@Override
protected void doExecute() {
imrService = get(IntentMonitorAndRerouteService.class);
intentService = get(IntentService.class);
if (appId != null && appName != null) {
if (key != null) {
/*
Intent key might be a StringKey or a LongKey, but in any case is
provided via CLI as a string. To solve only ambiguity we check if
"--longkey" CLI parameter has been set.
*/
if (treatAsLongKey) {
try {
Key intentKeyLong = Key.of(Integer.decode(key), new DefaultApplicationId(appId, appName));
for (Intent intent : intentService.getIntents()) {
if (intent.key().equals(intentKeyLong)) {
imrService.startMonitorIntent(intentKeyLong);
print("Started monitoring of intent with LongKey %s", intentKeyLong);
return;
}
}
imrService.startMonitorIntent(intentKeyLong);
print("Started monitoring of intent with LongKey %s, even if not yet submitted", intentKeyLong);
} catch (NumberFormatException nfe) {
print("\"%s\" is not a valid LongKey", key);
}
} else {
Key intentKeyString = Key.of(key, new DefaultApplicationId(appId, appName));
for (Intent intent : intentService.getIntents()) {
if (intent.key().equals(intentKeyString)) {
imrService.startMonitorIntent(intentKeyString);
print("Started monitoring of intent with StringKey %s", intentKeyString);
return;
}
}
imrService.startMonitorIntent(intentKeyString);
print("Started monitoring of intent with StringKey %s, even if not yet submitted", intentKeyString);
}
} else {
intentService.getIntents().forEach(i -> {
if (i.appId().equals(new DefaultApplicationId(appId, appName))) {
imrService.startMonitorIntent(i.key());
print("Started monitoring of intent with Key %s", i.key());
}
});
}
}
}
Aggregations