Search in sources :

Example 16 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class ControlPlaneRedirectManager method processRouterConfig.

/**
 * Sets up the router interfaces if router config is available.
 */
private void processRouterConfig() {
    ApplicationId routingAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
    Set<RoutersConfig.Router> routerConfigs = RoutingConfiguration.getRouterConfigurations(networkConfigService, routingAppId);
    for (RoutersConfig.Router router : routerConfigs) {
        DeviceId deviceId = router.controlPlaneConnectPoint().deviceId();
        routers.compute(deviceId, (d, r) -> {
            if (r == null) {
                return createRouter(RouterInfo.from(router));
            } else {
                r.changeConfiguration(RouterInfo.from(router), forceUnprovision);
                return r;
            }
        });
    }
    for (DeviceId deviceId : routers.keySet()) {
        if (!configExists(deviceId, routerConfigs)) {
            Router router = routers.remove(deviceId);
            router.cleanup();
        }
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Router(org.onosproject.routing.Router) ApplicationId(org.onosproject.core.ApplicationId) RoutersConfig(org.onosproject.routing.config.RoutersConfig)

Example 17 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class AddSpeakerCommand method doExecute.

@Override
protected void doExecute() {
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.addConfig(appId, BgpConfig.class);
    if (name != null) {
        BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
        if (speaker != null) {
            log.debug("Speaker already exists: {}", name);
            return;
        }
    }
    if (vlanId == null || vlanId.isEmpty()) {
        vlanIdObj = VlanId.NONE;
    } else {
        vlanIdObj = VlanId.vlanId(Short.valueOf(vlanId));
    }
    addSpeakerToConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(SPEAKER_ADD_SUCCESS);
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 18 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class BgpSpeakersListCommand method doExecute.

@Override
protected void doExecute() {
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null) {
        print("No speakers configured");
        return;
    }
    List<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Lists.newArrayList(config.bgpSpeakers());
    Collections.sort(bgpSpeakers, SPEAKERS_COMPARATOR);
    if (config.bgpSpeakers().isEmpty()) {
        print("No speakers configured");
    } else {
        bgpSpeakers.forEach(s -> {
            if (s.name().isPresent()) {
                print(NAME_FORMAT, s.name().get(), s.connectPoint().deviceId(), s.connectPoint().port(), s.vlan(), s.peers());
            } else {
                print(FORMAT, s.connectPoint().deviceId(), s.connectPoint().port(), s.vlan(), s.peers());
            }
        });
    }
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 19 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class RemoveSpeakerCommand method doExecute.

@Override
protected void doExecute() {
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }
    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
    if (speaker == null) {
        print(SPEAKER_NOT_FOUND, name);
        return;
    } else {
        if (!speaker.peers().isEmpty()) {
            // Removal not allowed when peer connections exist.
            print(PEERS_EXIST, name);
            return;
        }
    }
    removeSpeakerFromConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(SPEAKER_REMOVE_SUCCESS);
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 20 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class DistributedApplicationStore method loadFromDisk.

private Application loadFromDisk(String appName) {
    pendingApps.add(appName);
    for (int i = 0; i < MAX_LOAD_RETRIES; i++) {
        try {
            // Directly return if app already exists
            ApplicationId appId = getId(appName);
            if (appId != null) {
                Application application = getApplication(appId);
                if (application != null) {
                    pendingApps.remove(appName);
                    return application;
                }
            }
            ApplicationDescription appDesc = getApplicationDescription(appName);
            Optional<String> loop = appDesc.requiredApps().stream().filter(app -> pendingApps.contains(app)).findAny();
            if (loop.isPresent()) {
                log.error("Circular app dependency detected: {} -> {}", pendingApps, loop.get());
                pendingApps.remove(appName);
                return null;
            }
            boolean success = appDesc.requiredApps().stream().noneMatch(requiredApp -> loadFromDisk(requiredApp) == null);
            pendingApps.remove(appName);
            if (success) {
                return create(appDesc, false);
            } else {
                log.error("Unable to load dependencies for application {}", appName);
                return null;
            }
        } catch (Exception e) {
            log.warn("Unable to load application {} from disk: {}; retrying", appName, Throwables.getRootCause(e).getMessage());
            log.debug("Full error details:", e);
            // FIXME: This is a deliberate hack; fix in Falcon
            randomDelay(RETRY_DELAY_MS);
        }
    }
    pendingApps.remove(appName);
    log.error("Unable to load application {}", appName);
    return null;
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) ApplicationIdStore(org.onosproject.app.ApplicationIdStore) StorageService(org.onosproject.store.service.StorageService) ByteArrayInputStream(java.io.ByteArrayInputStream) ApplicationEvent(org.onosproject.app.ApplicationEvent) ApplicationId(org.onosproject.core.ApplicationId) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) Version(org.onosproject.core.Version) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ApplicationException(org.onosproject.app.ApplicationException) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Versioned(org.onosproject.store.service.Versioned) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) APP_ACTIVATED(org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED) APP_UNINSTALLED(org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RevisionType(org.onosproject.store.service.RevisionType) DEACTIVATED(org.onosproject.store.app.DistributedApplicationStore.InternalState.DEACTIVATED) ApplicationState(org.onosproject.app.ApplicationState) StorageException(org.onosproject.store.service.StorageException) APP_PERMISSIONS_CHANGED(org.onosproject.app.ApplicationEvent.Type.APP_PERMISSIONS_CHANGED) INSTALLED(org.onosproject.store.app.DistributedApplicationStore.InternalState.INSTALLED) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Multimap(com.google.common.collect.Multimap) Tools.randomDelay(org.onlab.util.Tools.randomDelay) Function(java.util.function.Function) ControllerNode(org.onosproject.cluster.ControllerNode) MapEventListener(org.onosproject.store.service.MapEventListener) Permission(org.onosproject.security.Permission) Component(org.osgi.service.component.annotations.Component) APP_DEACTIVATED(org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED) Lists(com.google.common.collect.Lists) APP_INSTALLED(org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED) ACTIVATED(org.onosproject.store.app.DistributedApplicationStore.InternalState.ACTIVATED) Multimaps.newSetMultimap(com.google.common.collect.Multimaps.newSetMultimap) VersionService(org.onosproject.core.VersionService) ApplicationDescription(org.onosproject.app.ApplicationDescription) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) Multimaps.synchronizedSetMultimap(com.google.common.collect.Multimaps.synchronizedSetMultimap) Application(org.onosproject.core.Application) DefaultApplication(org.onosproject.core.DefaultApplication) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) Topic(org.onosproject.store.service.Topic) MoreObjects(com.google.common.base.MoreObjects) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) ApplicationStoreDelegate(org.onosproject.app.ApplicationStoreDelegate) Maps(com.google.common.collect.Maps) Status(org.onosproject.store.service.DistributedPrimitive.Status) ApplicationArchive(org.onosproject.common.app.ApplicationArchive) ByteStreams.toByteArray(com.google.common.io.ByteStreams.toByteArray) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ApplicationStore(org.onosproject.app.ApplicationStore) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Preconditions(com.google.common.base.Preconditions) Reference(org.osgi.service.component.annotations.Reference) InputStream(java.io.InputStream) ApplicationId(org.onosproject.core.ApplicationId) Application(org.onosproject.core.Application) DefaultApplication(org.onosproject.core.DefaultApplication) ApplicationDescription(org.onosproject.app.ApplicationDescription) ApplicationException(org.onosproject.app.ApplicationException) StorageException(org.onosproject.store.service.StorageException) IOException(java.io.IOException)

Aggregations

ApplicationId (org.onosproject.core.ApplicationId)138 CoreService (org.onosproject.core.CoreService)36 Activate (org.osgi.service.component.annotations.Activate)36 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)25 Path (javax.ws.rs.Path)21 Produces (javax.ws.rs.Produces)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 GET (javax.ws.rs.GET)14 Test (org.junit.Test)13 ApplicationAdminService (org.onosproject.app.ApplicationAdminService)11 FlowRuleService (org.onosproject.net.flow.FlowRuleService)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Intent (org.onosproject.net.intent.Intent)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 InputStream (java.io.InputStream)9 DeviceId (org.onosproject.net.DeviceId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 IntentService (org.onosproject.net.intent.IntentService)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8