import static org.opendaylight.ovsdb.lib.operations.Operations.op;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import com.google.common.collect.Lists;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import com.google.common.base.Optional;
-public class McastMacsLocalRemoveCommand extends AbstractTransactCommand {
+public class McastMacsLocalRemoveCommand extends AbstractTransactCommand<LocalMcastMacs, HwvtepGlobalAugmentation> {
private static final Logger LOG = LoggerFactory.getLogger(McastMacsLocalRemoveCommand.class);
public McastMacsLocalRemoveCommand(HwvtepOperationalState state,
}
}
- private Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> extractRemoved(
- Collection<DataTreeModification<Node>> changes, Class<LocalMcastMacs> class1) {
- Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> result
- = new HashMap<InstanceIdentifier<Node>, List<LocalMcastMacs>>();
- if (changes != null && !changes.isEmpty()) {
- for (DataTreeModification<Node> change : changes) {
- final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
- final DataObjectModification<Node> mod = change.getRootNode();
- //If the node which localMcastMacs belong to is removed, all localMcastMacs should be removed too.
- Node removed = TransactUtils.getRemoved(mod);
- if (removed != null) {
- List<LocalMcastMacs> macListRemoved = null;
- if (removed.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
- macListRemoved = removed.getAugmentation(HwvtepGlobalAugmentation.class).getLocalMcastMacs();
- }
- if (macListRemoved != null) {
- result.put(key, macListRemoved);
- }
- }
- //If the node which localMcastMacs belong to is updated, and localMcastMacs may
- //be created or updated or deleted, we need to get deleted ones.
- Node updated = TransactUtils.getUpdated(mod);
- Node before = mod.getDataBefore();
- if (updated != null && before != null) {
- List<LocalMcastMacs> macListUpdated = null;
- List<LocalMcastMacs> macListBefore = null;
- HwvtepGlobalAugmentation hgUpdated = updated.getAugmentation(HwvtepGlobalAugmentation.class);
- if (hgUpdated != null) {
- macListUpdated = hgUpdated.getLocalMcastMacs();
- }
- HwvtepGlobalAugmentation hgBefore = before.getAugmentation(HwvtepGlobalAugmentation.class);
- if (hgBefore != null) {
- macListBefore = hgBefore.getLocalMcastMacs();
- }
- if (macListBefore != null) {
- List<LocalMcastMacs> macListRemoved = new ArrayList<LocalMcastMacs>();
- if (macListUpdated != null) {
- macListBefore.removeAll(macListUpdated);
- }
- //then exclude updated localMcastMacs
- if (macListUpdated != null) {
- for (LocalMcastMacs macBefore : macListBefore) {
- int i = 0;
- for (; i < macListUpdated.size(); i++) {
- if (macBefore.getKey().equals(macListUpdated.get(i).getKey())) {
- break;
- }
- }
- if (i == macListUpdated.size()) {
- macListRemoved.add(macBefore);
- }
- }
- } else {
- macListRemoved.addAll(macListBefore);
- }
- if (!macListRemoved.isEmpty()) {
- result.put(key, macListRemoved);
- }
- }
- }
- }
+ @Override
+ protected List<LocalMcastMacs> getData(HwvtepGlobalAugmentation augmentation) {
+ return augmentation.getLocalMcastMacs();
+ }
+
+ @Override
+ protected boolean cascadeDelete() {
+ return true;
+ }
+
+ @Override
+ protected UnMetDependencyGetter getDependencyGetter() {
+ return MAC_DEPENDENCY_GETTER;
+ }
+
+ static UnMetDependencyGetter MAC_DEPENDENCY_GETTER = new MacDependencyGetter();
+
+ public static class MacDependencyGetter extends UnMetDependencyGetter<LocalMcastMacs> {
+ public List<InstanceIdentifier<?>> getLogicalSwitchDependencies(LocalMcastMacs data) {
+ return Lists.newArrayList(data.getLogicalSwitchRef().getValue());
+ }
+
+ @Override
+ public List<InstanceIdentifier<?>> getTerminationPointDependencies(LocalMcastMacs data) {
+ return Collections.EMPTY_LIST;
}
- return result;
}
}