Search in sources :

Example 1 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType in project netvirt by opendaylight.

the class L2GwValidateCli method compareNodes.

private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison, LogicalDatastoreType datastoreType) {
    if (node1 == null || node2 == null) {
        return false;
    }
    InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
    InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
    NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
    NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
    PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
    PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
    HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
    HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
    boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
    MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
    for (MergeCommand cmd : commands) {
        List<DataObject> data1 = null;
        List<DataObject> data2 = null;
        if (globalNodes) {
            data1 = cmd.getData(aug1);
            data2 = cmd.getData(aug2);
        } else {
            data1 = cmd.getData(node1);
            data2 = cmd.getData(node2);
        }
        data1 = data1 == null ? Collections.EMPTY_LIST : data1;
        data2 = data2 == null ? Collections.EMPTY_LIST : data2;
        if (parentChildComparison) {
            data2 = cmd.transform(nodeIid1, data2);
        }
        Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
        data1 = Lists.transform(data1, withoutUuidTransformer);
        data2 = Lists.transform(data2, withoutUuidTransformer);
        Map<Identifier<?>, DataObject> map1 = new HashMap<>();
        Map<Identifier<?>, DataObject> map2 = new HashMap<>();
        for (DataObject dataObject : data1) {
            map1.put(cmd.getKey(dataObject), dataObject);
        }
        for (DataObject dataObject : data2) {
            map2.put(cmd.getKey(dataObject), dataObject);
        }
        Set<DataObject> diff = Sets.newHashSet();
        for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
            DataObject obj1 = entry.getValue();
            DataObject obj2 = map2.get(entry.getKey());
            if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
                diff.add(obj1);
            }
        }
        if (!diff.isEmpty()) {
            if (parentChildComparison) {
                pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType + " parent node " + nodeId1 + " contain " + " more entries than child " + nodeId2 + " " + diff.size());
            } else {
                pw.println("Missing " + cmd.getDescription() + " op entries config " + nodeId1 + " contain " + " more entries than operational node " + diff.size());
            }
            if (diff.size() < 10) {
                for (Object obj : diff) {
                    pw.println(cmd.getKey((DataObject) obj));
                }
            }
        }
        diff = Sets.newHashSet();
        for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
            DataObject obj1 = entry.getValue();
            DataObject obj2 = map1.get(entry.getKey());
            if (globalNodes || parentChildComparison) {
                if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
                    diff.add(obj1);
                }
            }
        }
        if (!diff.isEmpty()) {
            if (parentChildComparison) {
                pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node " + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
            } else {
                pw.println("Extra " + cmd.getDescription() + " operational node " + nodeId2 + " contain " + " more entries than config node " + diff.size());
            }
            if (diff.size() < 10) {
                for (Object obj : diff) {
                    pw.println(cmd.getKey((DataObject) obj));
                }
            }
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 2 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType in project netvirt by opendaylight.

the class EvpnUtils method asyncReadAndExecute.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T extends DataObject> void asyncReadAndExecute(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> iid, final String jobKey, final Function<Optional<T>, Void> function) {
    jobCoordinator.enqueueJob(jobKey, () -> {
        SettableFuture<Optional<T>> settableFuture = SettableFuture.create();
        List futures = Collections.singletonList(settableFuture);
        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
            Futures.addCallback(tx.read(datastoreType, iid), new SettableFutureCallback<Optional<T>>(settableFuture) {

                @Override
                public void onSuccess(Optional<T> data) {
                    function.apply(data);
                    super.onSuccess(data);
                }
            }, MoreExecutors.directExecutor());
            return futures;
        }
    }, ElanConstants.JOB_MAX_RETRIES);
}
Also used : Optional(com.google.common.base.Optional) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) DcGatewayIpList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList) List(java.util.List) ArrayList(java.util.ArrayList) ExternalTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList)

Example 3 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType in project netvirt by opendaylight.

the class MergeCommandsAggregator method mergeUpdate.

public void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, LogicalDatastoreType datastoreType, ReadWriteTransaction tx) {
    if (mod == null) {
        return;
    }
    Collection<DataObjectModification> modifications = mod.getModifiedChildren();
    modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
        MergeCommand mergeCommand = commands.get(modification.getDataType());
        boolean create = modification.getDataAfter() != null;
        DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
        InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
        DataObject transformedItem = mergeCommand.transform(dstPath, data);
        Optional<DataObject> existingDataOptional = null;
        try {
            existingDataOptional = tx.read(datastoreType, transformedId).checkedGet();
        } catch (ReadFailedException ex) {
            LOG.error("Failed to read data {} from {}", transformedId, datastoreType);
            return;
        }
        String destination = datastoreType == CONFIGURATION ? "child" : "parent";
        if (create) {
            if (isDataUpdated(existingDataOptional, transformedItem)) {
                LOG.debug("Copy to {} {} {}", destination, datastoreType, transformedId);
                tx.put(datastoreType, transformedId, transformedItem, true);
            } else {
                LOG.debug("Data not updated skip copy to {}", transformedId);
            }
        } else {
            if (existingDataOptional.isPresent()) {
                LOG.debug("Delete from {} {} {}", destination, datastoreType, transformedId);
                tx.delete(datastoreType, transformedId);
            } else {
                LOG.debug("Delete skipped for {}", transformedId);
            }
        }
    });
}
Also used : Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) CONFIGURATION(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION) HashMap(java.util.HashMap) SuperTypeUtil(org.opendaylight.genius.utils.SuperTypeUtil) LocalUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalUcastCmd) RemoteUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteUcastCmd) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Map(java.util.Map) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) Builder(org.opendaylight.yangtools.concepts.Builder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)

Example 4 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType in project netvirt by opendaylight.

the class ElanL2GatewayUtils method readRemoteMcastMac.

/**
 * Gets the remote mcast mac.
 *
 * @param nodeId
 *            the node id
 * @param logicalSwitchName
 *            the logical switch name
 * @param datastoreType
 *            the datastore type
 * @return the remote mcast mac
 */
public RemoteMcastMacs readRemoteMcastMac(NodeId nodeId, String logicalSwitchName, LogicalDatastoreType datastoreType) {
    InstanceIdentifier<LogicalSwitches> logicalSwitch = HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
    RemoteMcastMacsKey remoteMcastMacsKey = new RemoteMcastMacsKey(new HwvtepLogicalSwitchRef(logicalSwitch), new MacAddress(ElanConstants.UNKNOWN_DMAC));
    return HwvtepUtils.getRemoteMcastMac(broker, datastoreType, nodeId, remoteMcastMacsKey);
}
Also used : LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) RemoteMcastMacsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey) HwvtepLogicalSwitchRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef) HwvtepNodeName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)

Example 5 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType in project controller by opendaylight.

the class ClusterAdminRpcService method removeShardReplica.

@Override
public Future<RpcResult<Void>> removeShardReplica(RemoveShardReplicaInput input) {
    final String shardName = input.getShardName();
    if (Strings.isNullOrEmpty(shardName)) {
        return newFailedRpcResultFuture("A valid shard name must be specified");
    }
    DataStoreType dataStoreType = input.getDataStoreType();
    if (dataStoreType == null) {
        return newFailedRpcResultFuture("A valid DataStoreType must be specified");
    }
    final String memberName = input.getMemberName();
    if (Strings.isNullOrEmpty(memberName)) {
        return newFailedRpcResultFuture("A valid member name must be specified");
    }
    LOG.info("Removing replica for shard {} memberName {}, datastoreType {}", shardName, memberName, dataStoreType);
    final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
    ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new RemoveShardReplica(shardName, MemberName.forName(memberName)));
    Futures.addCallback(future, new FutureCallback<Success>() {

        @Override
        public void onSuccess(Success success) {
            LOG.info("Successfully removed replica for shard {}", shardName);
            returnFuture.set(newSuccessfulResult());
        }

        @Override
        public void onFailure(Throwable failure) {
            onMessageFailure(String.format("Failed to remove replica for shard %s", shardName), returnFuture, failure);
        }
    }, MoreExecutors.directExecutor());
    return returnFuture;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) Success(akka.actor.Status.Success) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 DataStoreType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)8 Success (akka.actor.Status.Success)5 Optional (com.google.common.base.Optional)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Objects (java.util.Objects)2 GetShardRole (org.opendaylight.controller.cluster.datastore.messages.GetShardRole)2 GetShardRoleReply (org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply)2 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)2 MergeCommand (org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)2 HwvtepPhysicalLocatorAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation)2 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 ActorRef (akka.actor.ActorRef)1 Lists (com.google.common.collect.Lists)1