use of org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED in project onos by opennetworkinglab.
the class DistributedApplicationStore method fetchBits.
/**
* Fetches the bits from the cluster peers.
*/
private void fetchBits(Application app, boolean delegateInstallation) {
ControllerNode localNode = clusterService.getLocalNode();
CountDownLatch latch = new CountDownLatch(1);
// FIXME: send message with name & version to make sure we don't get served old bits
log.info("Downloading bits for application {} for version : {}", app.id().name(), app.version());
for (ControllerNode node : clusterService.getNodes()) {
if (latch.getCount() == 0) {
break;
}
if (node.equals(localNode)) {
continue;
}
clusterCommunicator.sendAndReceive(app.id().name(), APP_BITS_REQUEST, s -> s.getBytes(Charsets.UTF_8), Function.identity(), node.id()).whenCompleteAsync((bits, error) -> {
if (error == null && latch.getCount() > 0) {
saveApplication(new ByteArrayInputStream(bits));
log.info("Downloaded bits for application {} from node {}", app.id().name(), node.id());
latch.countDown();
if (delegateInstallation) {
if (log.isTraceEnabled()) {
log.trace("Delegate installation for {}", app.id());
}
notifyDelegate(new ApplicationEvent(APP_INSTALLED, app));
}
} else if (error != null) {
log.warn("Unable to fetch bits for application {} from node {}", app.id().name(), node.id());
}
}, messageHandlingExecutor);
}
try {
if (!latch.await(FETCH_TIMEOUT_MS, MILLISECONDS)) {
log.warn("Unable to fetch bits for application {}", app.id().name());
}
} catch (InterruptedException e) {
log.warn("Interrupted while fetching bits for application {}", app.id().name());
Thread.currentThread().interrupt();
}
}
Aggregations