Search in sources :

Example 11 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class DistributedApplicationStore method activate.

@Activate
public void activate() {
    messageHandlingExecutor = newSingleThreadExecutor(groupedThreads("onos/store/app", "message-handler", log));
    clusterCommunicator.addSubscriber(APP_BITS_REQUEST, bytes -> new String(bytes, Charsets.UTF_8), name -> {
        try {
            log.info("Sending bits for application {}", name);
            return toByteArray(getApplicationInputStream(name));
        } catch (ApplicationException e) {
            log.warn("Bits for application {} are not available on this node yet", name);
            return null;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }, Function.identity(), messageHandlingExecutor);
    apps = storageService.<ApplicationId, InternalApplicationHolder>consistentMapBuilder().withName("onos-apps").withRelaxedReadConsistency().withSerializer(Serializer.using(KryoNamespaces.API, InternalApplicationHolder.class, InternalState.class)).withVersion(versionService.version()).withRevisionType(RevisionType.PROPAGATE).withCompatibilityFunction(this::convertApplication).build();
    /* To update the version in application store if it does not matche with the local system.
           This will happen only when upgrading onos using issu or during rollback if upgrade does not work.
         */
    apps.asJavaMap().forEach((appId, holder) -> apps.asJavaMap().put(appId, convertApplication(holder, versionService.version())));
    appActivationTopic = storageService.<Application>topicBuilder().withName("onos-apps-activation-topic").withSerializer(Serializer.using(KryoNamespaces.API)).withVersion(versionService.version()).withRevisionType(RevisionType.PROPAGATE).withCompatibilityFunction(this::convertApplication).build();
    activationExecutor = newSingleThreadExecutor(groupedThreads("onos/store/app", "app-activation", log));
    appActivationTopic.subscribe(appActivator, activationExecutor);
    executor = newSingleThreadScheduledExecutor(groupedThreads("onos/app", "store", log));
    statusChangeListener = status -> {
        if (status == Status.ACTIVE) {
            executor.execute(this::bootstrapExistingApplications);
        }
    };
    apps.addListener(appsListener, activationExecutor);
    apps.addStatusChangeListener(statusChangeListener);
    coreAppId = getId(CoreService.CORE_APP_NAME);
    downloadMissingApplications();
    activateExistingApplications();
    log.info("Started");
}
Also used : ApplicationException(org.onosproject.app.ApplicationException) IOException(java.io.IOException) ApplicationId(org.onosproject.core.ApplicationId) StorageException(org.onosproject.store.service.StorageException) Activate(org.osgi.service.component.annotations.Activate)

Example 12 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class WorkFlowEngine method execEventTask.

/**
 * Executes event task.
 *
 * @param task event task
 * @return event task
 */
private EventTask execEventTask(EventTask task) {
    if (!eventMapStore.isEventMapPresent(task.context().name())) {
        log.trace("EventMap doesnt exist for taskcontext:{}", task.context().name());
        return task;
    }
    log.debug("execEventTask- task: {}, hash: {}", task, stringHash(task.context().distributor()));
    WorkflowContext context = (WorkflowContext) (task.context());
    Workflow workflow = workflowStore.get(context.workflowId());
    if (workflow == null) {
        log.error("Invalid workflow {}", context.workflowId());
        return task;
    }
    WorkflowContext latestContext = workplaceStore.getContext(context.name());
    if (latestContext == null) {
        log.error("Invalid workflow context {}", context.name());
        return task;
    }
    try {
        if (!Objects.equals(latestContext.current(), task.programCounter())) {
            log.error("Current worklet({}) is not mismatched with task work({}). Ignored.", latestContext.current(), task.programCounter());
            return task;
        }
        Worklet worklet = workflow.getWorkletInstance(task.programCounter());
        if (Worklet.Common.COMPLETED.equals(worklet) || Worklet.Common.INIT.equals(worklet)) {
            log.error("Current worklet is {}, Ignored", worklet);
            return task;
        }
        initWorkletExecution(latestContext);
        log.info("{} worklet.isCompleted:{}", latestContext.name(), worklet.tag());
        log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
        dataModelInjector.inject(worklet, latestContext);
        boolean completed = worklet.isCompleted(latestContext, task.event());
        dataModelInjector.inhale(worklet, latestContext);
        if (completed) {
            log.info("{} worklet.isCompleted(true):{}", latestContext.name(), worklet.tag());
            log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
            eventMapStore.unregisterEventMap(task.eventType(), latestContext.name());
            // completed case
            // increase program counter
            ProgramCounter pc = latestContext.current();
            latestContext.setCurrent(workflow.increased(pc));
            workplaceStore.commitContext(latestContext.name(), latestContext, true);
            return null;
        } else {
            log.info("{} worklet.isCompleted(false):{}", latestContext.name(), worklet.tag());
            log.trace("{} task:{}, context: {}", latestContext.name(), task, latestContext);
            workplaceStore.commitContext(latestContext.name(), latestContext, false);
        }
    } catch (WorkflowException e) {
        log.error("Exception: ", e);
        latestContext.setCause(e.getMessage());
        latestContext.setState(WorkflowState.EXCEPTION);
        workplaceStore.commitContext(latestContext.name(), latestContext, false);
    } catch (StorageException e) {
        log.error("Exception: ", e);
    // StorageException does not commit context.
    } catch (Exception e) {
        log.error("Exception: ", e);
        latestContext.setCause(e.getMessage());
        latestContext.setState(WorkflowState.EXCEPTION);
        workplaceStore.commitContext(latestContext.name(), latestContext, false);
    }
    return task;
}
Also used : WorkflowContext(org.onosproject.workflow.api.WorkflowContext) SystemWorkflowContext(org.onosproject.workflow.api.SystemWorkflowContext) WorkflowException(org.onosproject.workflow.api.WorkflowException) Workflow(org.onosproject.workflow.api.Workflow) Worklet(org.onosproject.workflow.api.Worklet) ProgramCounter(org.onosproject.workflow.api.ProgramCounter) StorageException(org.onosproject.store.service.StorageException) StorageException(org.onosproject.store.service.StorageException) WorkflowException(org.onosproject.workflow.api.WorkflowException)

Example 13 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class DistributedMeterStore method storeMeterFeatures.

@Override
public MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures) {
    // Store meter features, this is done once for each features of every device
    MeterStoreResult result = MeterStoreResult.success();
    MeterTableKey key = MeterTableKey.key(meterfeatures.deviceId(), meterfeatures.scope());
    try {
        metersFeatures.put(key, meterfeatures);
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
        result = MeterStoreResult.fail(TIMEOUT);
    }
    return result;
}
Also used : MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterTableKey(org.onosproject.net.meter.MeterTableKey) StorageException(org.onosproject.store.service.StorageException)

Example 14 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class DistributedMeterStore method addOrUpdateMeter.

@Override
public CompletableFuture<MeterStoreResult> addOrUpdateMeter(Meter meter) {
    checkArgument(validIndex(meter), "Meter index is not valid");
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
    MeterData data = new MeterData(meter, null);
    futures.put(key, future);
    try {
        meters.compute(key, (k, v) -> data);
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
        futures.remove(key);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) StorageException(org.onosproject.store.service.StorageException)

Example 15 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class DistributedMeterStore method deleteMeter.

@Override
public CompletableFuture<MeterStoreResult> deleteMeter(Meter meter) {
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
    futures.put(key, future);
    // that it has been removed from the dataplane.
    try {
        Versioned<MeterData> versionedData = meters.computeIfPresent(key, (k, v) -> {
            DefaultMeter m = (DefaultMeter) v.meter();
            MeterState meterState = m.state();
            if (meterState == MeterState.PENDING_REMOVE) {
                return v;
            }
            m.setState(meter.state());
            return new MeterData(m, v.reason().isPresent() ? v.reason().get() : null);
        });
        // If it does not exist in the system, completes immediately
        if (versionedData == null) {
            futures.remove(key);
            future.complete(MeterStoreResult.success());
        }
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
        futures.remove(key);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterState(org.onosproject.net.meter.MeterState) StorageException(org.onosproject.store.service.StorageException)

Aggregations

StorageException (org.onosproject.store.service.StorageException)18 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)10 CompletableFuture (java.util.concurrent.CompletableFuture)8 MeterKey (org.onosproject.net.meter.MeterKey)7 MeterFeatures (org.onosproject.net.meter.MeterFeatures)6 DefaultMeter (org.onosproject.net.meter.DefaultMeter)4 MeterFeaturesKey (org.onosproject.net.meter.MeterFeaturesKey)4 MeterTableKey (org.onosproject.net.meter.MeterTableKey)4 Activate (org.osgi.service.component.annotations.Activate)4 Collections2 (com.google.common.collect.Collections2)3 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 DeviceId (org.onosproject.net.DeviceId)3 Meter (org.onosproject.net.meter.Meter)3 MeterEvent (org.onosproject.net.meter.MeterEvent)3 MeterFailReason (org.onosproject.net.meter.MeterFailReason)3 TIMEOUT (org.onosproject.net.meter.MeterFailReason.TIMEOUT)3 MeterOperation (org.onosproject.net.meter.MeterOperation)3