use of org.onosproject.net.intent.IntentState in project onos by opennetworkinglab.
the class IntentsListCommand method detailsFormat.
/**
* Returns detailed information text about a specific intent.
*
* @param intent to print
* @param state of intent
* @return detailed information or "" if {@code state} was null
*/
private StringBuilder detailsFormat(Intent intent, IntentState state) {
StringBuilder builder = new StringBuilder();
if (state == null) {
return builder;
}
if (!intent.resources().isEmpty()) {
builder.append('\n').append(format(RESOURCES, intent.resources()));
}
if (intent instanceof ConnectivityIntent) {
ConnectivityIntent ci = (ConnectivityIntent) intent;
if (!ci.selector().criteria().isEmpty()) {
builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
}
if (!ci.treatment().allInstructions().isEmpty()) {
builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
}
if (ci.constraints() != null && !ci.constraints().isEmpty()) {
builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
}
}
if (intent instanceof HostToHostIntent) {
HostToHostIntent pi = (HostToHostIntent) intent;
builder.append('\n').append(format(SRC + HOST, pi.one()));
builder.append('\n').append(format(DST + HOST, pi.two()));
} else if (intent instanceof PointToPointIntent) {
PointToPointIntent pi = (PointToPointIntent) intent;
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
} else if (intent instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
} else if (intent instanceof SinglePointToMultiPointIntent) {
SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
} else if (intent instanceof PathIntent) {
PathIntent pi = (PathIntent) intent;
builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
} else if (intent instanceof LinkCollectionIntent) {
LinkCollectionIntent li = (LinkCollectionIntent) intent;
builder.append('\n').append(format("links=%s", li.links()));
builder.append('\n').append(format(CP, li.egressPoints()));
} else if (intent instanceof OpticalCircuitIntent) {
OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
} else if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
builder.append('\n').append(format("ochSignal=%s", ci.ochSignal()));
} else if (intent instanceof OpticalOduIntent) {
OpticalOduIntent ci = (OpticalOduIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
}
List<Intent> installable = service.getInstallableIntents(intent.key()).stream().filter(i -> contentFilter.filter(i)).collect(Collectors.toList());
if (showInstallable && installable != null && !installable.isEmpty()) {
builder.append('\n').append(format(INSTALLABLE, installable));
}
return builder;
}
use of org.onosproject.net.intent.IntentState in project onos by opennetworkinglab.
the class IntentCodec method encode.
@Override
public ObjectNode encode(Intent intent, CodecContext context) {
checkNotNull(intent, "Intent cannot be null");
final ObjectNode result = context.mapper().createObjectNode().put(TYPE, intent.getClass().getSimpleName()).put(ID, intent.id().toString()).put(KEY, intent.key().toString()).put(APP_ID, UrlEscapers.urlPathSegmentEscaper().escape(intent.appId().name()));
if (intent.resourceGroup() != null) {
result.put(RESOURCE_GROUP, intent.resourceGroup().toString());
}
final ArrayNode jsonResources = result.putArray(RESOURCES);
intent.resources().forEach(resource -> {
if (resource instanceof Link) {
jsonResources.add(context.codec(Link.class).encode((Link) resource, context));
} else {
jsonResources.add(resource.toString());
}
});
IntentService service = context.getService(IntentService.class);
IntentState state = service.getIntentState(intent.key());
if (state != null) {
result.put(STATE, state.toString());
}
return result;
}
use of org.onosproject.net.intent.IntentState in project onos by opennetworkinglab.
the class IntentsWebResource method deleteIntentById.
/**
* Withdraws intent.
* Withdraws the specified intent from the system.
*
* @param appId application identifier
* @param key intent key
* @return 204 NO CONTENT
*/
@DELETE
@Path("{appId}/{key}")
public Response deleteIntentById(@PathParam("appId") String appId, @PathParam("key") String key) {
final ApplicationId app = get(CoreService.class).getAppId(appId);
nullIsNotFound(app, APP_ID_NOT_FOUND);
Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
IntentService service = get(IntentService.class);
if (intent == null) {
intent = service.getIntent(Key.of(Long.decode(key), app));
}
if (intent == null) {
// in this case.
return Response.noContent().build();
}
Key k = intent.key();
// set up latch and listener to track uninstall progress
CountDownLatch latch = new CountDownLatch(1);
IntentListener listener = new DeleteListener(k, latch);
service.addListener(listener);
try {
// request the withdraw
service.withdraw(intent);
try {
latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.info("REST Delete operation timed out waiting for intent {}", k);
Thread.currentThread().interrupt();
}
// double check the state
IntentState state = service.getIntentState(k);
if (state == WITHDRAWN || state == FAILED) {
service.purge(intent);
}
} finally {
// clean up the listener
service.removeListener(listener);
}
return Response.noContent().build();
}
use of org.onosproject.net.intent.IntentState in project onos by opennetworkinglab.
the class ServiceApplicationComponent method processTapiEvent.
/**
* Process TAPI Event from NBI.
*
* @param config TAPI Connectivity config for the event
*/
public void processTapiEvent(TapiConnectivityConfig config) {
checkNotNull(config, "Config can't be null");
Key key = Key.of(config.uuid(), appId);
// Setup the Intent
if (config.isSetup()) {
log.debug("TAPI config: {} to setup intent", config);
Intent intent = createOpticalIntent(config.leftCp(), config.rightCp(), key, appId);
intentService.submit(intent);
} else {
// Release the intent
Intent intent = intentService.getIntent(key);
if (intent == null) {
log.error("Intent for uuid {} does not exist", config.uuid());
return;
}
log.debug("TAPI config: {} to purge intent {}", config, intent);
CountDownLatch latch = new CountDownLatch(1);
IntentListener listener = new DeleteListener(key, latch);
intentService.addListener(listener);
try {
/*
* RCAS: Note, withdraw is asynchronous. We cannot call purge
* directly, because at this point it remains in the "INSTALLED"
* state.
*/
intentService.withdraw(intent);
/*
* org.onosproject.onos-core-net - 2.1.0.SNAPSHOT |
* Purge for intent 0x0 is rejected because intent state is INSTALLED
* intentService.purge(intent);
*/
try {
latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// double check the state
IntentState state = intentService.getIntentState(key);
if (state == WITHDRAWN || state == FAILED) {
intentService.purge(intent);
}
} finally {
intentService.removeListener(listener);
}
}
}
use of org.onosproject.net.intent.IntentState in project onos by opennetworkinglab.
the class IntentSynchronizer method synchronizeIntents.
private void synchronizeIntents() {
Map<Key, Intent> serviceIntents = new HashMap<>();
intentService.getIntents().forEach(i -> {
if (i.appId().equals(appId)) {
serviceIntents.put(i.key(), i);
}
});
List<Intent> intentsToAdd = new LinkedList<>();
List<Intent> intentsToRemove = new LinkedList<>();
for (Intent localIntent : intents.values()) {
Intent serviceIntent = serviceIntents.remove(localIntent.key());
if (serviceIntent == null) {
intentsToAdd.add(localIntent);
} else {
IntentState state = intentService.getIntentState(serviceIntent.key());
if (!IntentUtils.intentsAreEqual(serviceIntent, localIntent) || state == null || state == IntentState.WITHDRAW_REQ || state == IntentState.WITHDRAWING || state == IntentState.WITHDRAWN) {
intentsToAdd.add(localIntent);
}
}
}
for (Intent serviceIntent : serviceIntents.values()) {
IntentState state = intentService.getIntentState(serviceIntent.key());
if (state != null && state != IntentState.WITHDRAW_REQ && state != IntentState.WITHDRAWING && state != IntentState.WITHDRAWN) {
intentsToRemove.add(serviceIntent);
}
}
log.debug("Intent Synchronizer: submitting {}, withdrawing {}", intentsToAdd.size(), intentsToRemove.size());
// Withdraw Intents
for (Intent intent : intentsToRemove) {
intentService.withdraw(intent);
log.trace("Intent Synchronizer: withdrawing intent: {}", intent);
}
if (!isElectedLeader) {
log.debug("Intent Synchronizer: cannot withdraw intents: " + "not elected leader anymore");
isActivatedLeader = false;
return;
}
// Add Intents
for (Intent intent : intentsToAdd) {
intentService.submit(intent);
log.trace("Intent Synchronizer: submitting intent: {}", intent);
}
if (!isElectedLeader) {
log.debug("Intent Synchronizer: cannot submit intents: " + "not elected leader anymore");
isActivatedLeader = false;
return;
}
if (isElectedLeader) {
// Allow push of Intents
isActivatedLeader = true;
} else {
isActivatedLeader = false;
}
log.debug("Intent synchronization completed");
}
Aggregations