Search in sources :

Example 6 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project controller by opendaylight.

the class GetEntitiesReply method extractName.

/**
 * if the entity is general entity then shorthand the name to only the last path argument, otherwise return
 * full YIID path encoded as string.
 *
 * @param entity Entity to extract the name from
 * @param iidCodec codec to encode entity name back to InstanceIdentifier if needed
 * @return Extracted name
 */
private static EntityName extractName(final DOMEntity entity, final BindingInstanceIdentifierCodec iidCodec) {
    final var id = entity.getIdentifier();
    if (id.isEmpty() || !id.getPathArguments().get(0).getNodeType().equals(Entity.QNAME)) {
        return new EntityName(iidCodec.toBinding(id));
    }
    final PathArgument last = id.getLastPathArgument();
    verify(last instanceof NodeIdentifierWithPredicates, "Unexpected last argument %s", last);
    final Object value = Iterables.getOnlyElement(((NodeIdentifierWithPredicates) last).values());
    verify(value instanceof String, "Unexpected predicate value %s", value);
    return new EntityName((String) value);
}
Also used : EntityName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 7 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project openflowplugin by opendaylight.

the class ContextChainHolderImpl method ownershipChanged.

@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public void ownershipChanged(EntityOwnershipChange entityOwnershipChange) {
    if (entityOwnershipChange.getState().hasOwner()) {
        return;
    }
    // Findbugs flags a false violation for "Unchecked/unconfirmed cast" from GenericEntity to Entity hence the
    // suppression above. The suppression is temporary until EntityOwnershipChange is modified to eliminate the
    // violation.
    final String entityName = entityOwnershipChange.getEntity().getIdentifier().firstKeyOf(Entity.class).getName();
    if (Objects.nonNull(entityName)) {
        LOG.debug("Entity {} has no owner", entityName);
        try {
            // TODO:Remove notifications
            final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil.createNodeInstanceIdentifier(new NodeId(entityName));
            deviceManager.sendNodeRemovedNotification(nodeInstanceIdentifier);
            LOG.info("Try to remove device {} from operational DS", entityName);
            deviceManager.removeDeviceFromOperationalDS(nodeInstanceIdentifier).get(REMOVE_DEVICE_FROM_DS_TIMEOUT, TimeUnit.MILLISECONDS);
            LOG.info("Removing device from operational DS {} was successful", entityName);
        } catch (TimeoutException | ExecutionException | NullPointerException | InterruptedException e) {
            LOG.warn("Not able to remove device {} from operational DS. ", entityName, e);
        }
    }
}
Also used : Entity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) TimeoutException(java.util.concurrent.TimeoutException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project genius by opendaylight.

the class SrmRpcUtils method callSrmOp.

public static RecoverOutput callSrmOp(DataBroker broker, RecoverInput input) {
    RecoverOutputBuilder outputBuilder = new RecoverOutputBuilder();
    if (input.getEntityName() == null) {
        outputBuilder.setResponse(RpcFailEntityName.class).setMessage("EntityName is null");
        return outputBuilder.build();
    }
    if (input.getEntityType() == null) {
        outputBuilder.setResponse(RpcFailEntityType.class).setMessage(String.format("EntityType for %s can't be null", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    }
    String entityId;
    if (EntityTypeInstance.class.equals(input.getEntityType()) && input.getEntityId() == null) {
        outputBuilder.setResponse(RpcFailEntityId.class).setMessage(String.format("EntityId can't be null for %s", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    } else {
        entityId = input.getEntityId();
    }
    Class<? extends EntityNameBase> serviceName = NAME_TO_SERVICE_MAP.get(input.getEntityName());
    if (serviceName == null) {
        outputBuilder.setResponse(RpcFailEntityName.class).setMessage(String.format("EntityName %s has no matching service", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    }
    Class<? extends EntityTypeBase> entityType = NAME_TO_TYPE_MAP.get(input.getEntityName());
    if (entityType == null || !input.getEntityType().equals(entityType)) {
        outputBuilder.setResponse(RpcFailEntityType.class).setMessage(String.format("EntityName %s doesn't match with EntityType %s", input.getEntityName().getSimpleName(), entityType));
        return outputBuilder.build();
    }
    OperationsBuilder opsBuilder = new OperationsBuilder().setEntityName(input.getEntityName()).setEntityType(entityType).setTriggerOperation(ServiceOpRecover.class);
    if (entityId != null) {
        opsBuilder.setEntityId(entityId);
    }
    Operations operation = opsBuilder.build();
    InstanceIdentifier<Operations> opsIid = getInstanceIdentifier(operation, serviceName);
    WriteTransaction tx = broker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, opsIid, operation, CREATE_MISSING_PARENT);
    try {
        tx.submit().get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error writing RecoveryOp to datastore. path:{}, data:{}", opsIid, operation);
        outputBuilder.setResponse(RpcFailUnknown.class).setMessage(e.getMessage());
        return outputBuilder.build();
    }
    outputBuilder.setResponse(RpcSuccess.class).setMessage("Recovery operation successfully triggered");
    return outputBuilder.build();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RpcFailEntityId(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityId) RpcFailEntityType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityType) RpcSuccess(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcSuccess) RecoverOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RecoverOutputBuilder) OperationsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder) RpcFailEntityName(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityName) EntityTypeInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityTypeInstance) ExecutionException(java.util.concurrent.ExecutionException) Operations(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)3 EntityName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName)3 Test (org.junit.Test)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)2 DOMEntityOwnershipCandidateRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration)2 Operations (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations)2 OperationsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder)2 EntityType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType)2 GetEntitiesInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInputBuilder)2 GetEntitiesOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput)2 GetEntityInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInputBuilder)2 GetEntityOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput)2 GetEntityOwnerInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInputBuilder)2 GetEntityOwnerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput)2 NodeName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName)2 EntitiesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesKey)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1