Search in sources :

Example 6 with Entity

use of org.opendaylight.mdsal.eos.binding.api.Entity in project genius by opendaylight.

the class EntityOwnershipUtils method runOnlyInOwnerNode.

/**
 * Runs a job task if the local node is the owner of an entity.
 *
 * @param entityType the entity type
 * @param entityName the entity name
 * @param coordinator the JobCoordinator on which to run the job
 * @param jobKey the job key
 * @param jobDesc description of the job for logging
 * @param job the job task
 */
public void runOnlyInOwnerNode(String entityType, String entityName, JobCoordinator coordinator, String jobKey, String jobDesc, Callable<List<ListenableFuture<Void>>> job) {
    final Entity entity = new Entity(entityType, entityName);
    coordinator.enqueueJob(entity.toString(), () -> {
        if (isEntityOwner(entity)) {
            LOG.debug("Scheduling job {} for {}", jobDesc, entity);
            coordinator.enqueueJob(jobKey, job, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
        } else {
            LOG.debug("runOnlyInOwnerNode: job {} was not run as I'm not the owner of {} ", jobDesc, entity);
        }
        return Collections.singletonList(Futures.immediateFuture(null));
    });
}
Also used : Entity(org.opendaylight.mdsal.eos.binding.api.Entity)

Example 7 with Entity

use of org.opendaylight.mdsal.eos.binding.api.Entity in project genius by opendaylight.

the class EntityOwnershipUtils method runOnlyInOwnerNode.

/**
 * Runs a job task if the local node is the owner of an entity.
 *
 * @param entityType the entity type
 * @param entityName the entity name
 * @param coordinator the JobCoordinator on which to run the job task
 * @param jobDesc description of the job for logging
 * @param job the job task
 */
public void runOnlyInOwnerNode(String entityType, String entityName, JobCoordinator coordinator, String jobDesc, Runnable job) {
    final Entity entity = new Entity(entityType, entityName);
    coordinator.enqueueJob(entity.toString(), () -> {
        if (isEntityOwner(entity)) {
            LOG.debug("Running job {} for {}", jobDesc, entity);
            job.run();
        } else {
            LOG.debug("runOnlyInOwnerNode: job {} was not run as I'm not the owner of {} ", jobDesc, entity);
        }
        return Collections.singletonList(Futures.immediateFuture(null));
    });
}
Also used : Entity(org.opendaylight.mdsal.eos.binding.api.Entity)

Example 8 with Entity

use of org.opendaylight.mdsal.eos.binding.api.Entity in project genius by opendaylight.

the class ItmProvider method registerEntityForOwnership.

private void registerEntityForOwnership() {
    try {
        Entity registryCandidate = new Entity(ITMConstants.ITM_CONFIG_ENTITY, ITMConstants.ITM_CONFIG_ENTITY);
        entityOwnershipService.registerCandidate(registryCandidate);
    } catch (CandidateAlreadyRegisteredException e) {
        LOG.error("failed to register entity {} for entity-ownership-service", e.getEntity());
    }
}
Also used : CandidateAlreadyRegisteredException(org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException) Entity(org.opendaylight.mdsal.eos.binding.api.Entity)

Aggregations

Entity (org.opendaylight.mdsal.eos.binding.api.Entity)8 CandidateAlreadyRegisteredException (org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException)3 Test (org.junit.Test)2 EntityOwnershipChange (org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange)2 EntityOwnershipState (org.opendaylight.mdsal.eos.common.api.EntityOwnershipState)1