X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fforwardingrules-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwardingrulesmanager%2Fconsumer%2Fimpl%2FGroupConsumerImpl.java;h=381faa41b082ea069df75ca8b5a82736d94fd642;hp=851e7d9b2685420b5093d8771770a64a3fe52250;hb=8b7df31b57271de1f2fc05c65d60f1c549a7701e;hpb=a87db38d47967eae159c5be17ab334bb6a4edffc diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java index 851e7d9b26..381faa41b0 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java @@ -2,6 +2,7 @@ package org.opendaylight.controller.forwardingrulesmanager.consumer.impl; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -33,17 +34,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.Add import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAdded; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes.GroupType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,8 +71,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager { public GroupConsumerImpl() { - InstanceIdentifier path = InstanceIdentifier.builder(Groups.class).child(Group.class) - .toInstance(); + InstanceIdentifier path = InstanceIdentifier.builder(Groups.class).toInstance(); groupService = FRMConsumerImpl.getProviderSession().getRpcService(SalGroupService.class); clusterGroupContainerService = FRMConsumerImpl.getClusterContainerService(); @@ -225,7 +227,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager { return new Status(StatusCode.BADREQUEST, "Group Name is invalid"); } - returnResult = doesGroupEntryExists(group.getKey(), groupName, containerName); + /* returnResult = doesGroupEntryExists(group.getKey(), groupName, containerName); if (FRMUtil.operation.ADD == operation && returnResult) { logger.error("Record with same Group Name exists"); @@ -233,10 +235,10 @@ public class GroupConsumerImpl implements IForwardingRulesManager { } else if (!returnResult) { logger.error("Group record does not exist"); return new Status(StatusCode.BADREQUEST, "Group record does not exist"); - } + }*/ - if (!(group.getGroupType().getIntValue() >= GroupType.GroupAll.getIntValue() && group.getGroupType() - .getIntValue() <= GroupType.GroupFf.getIntValue())) { + if (!(group.getGroupType().getIntValue() >= GroupTypes.GroupAll.getIntValue() && group.getGroupType() + .getIntValue() <= GroupTypes.GroupFf.getIntValue())) { logger.error("Invalid Group type %d" + group.getGroupType().getIntValue()); return new Status(StatusCode.BADREQUEST, "Invalid Group type"); } @@ -259,7 +261,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager { } - private boolean doesGroupEntryExists(GroupKey key, String groupName, String containerName) { + /* private boolean doesGroupEntryExists(GroupKey key, String groupName, String containerName) { if (!originalSwGroupView.containsKey(key)) { return false; } @@ -271,8 +273,8 @@ public class GroupConsumerImpl implements IForwardingRulesManager { } } } - return false; - } + return true; + }*/ /** * Update Group entries to the southbound plugin/inventory and our internal @@ -292,11 +294,11 @@ public class GroupConsumerImpl implements IForwardingRulesManager { return groupOperationStatus; } - if (originalSwGroupView.containsKey(groupKey)) { + /*if (originalSwGroupView.containsKey(groupKey)) { originalSwGroupView.remove(groupKey); originalSwGroupView.put(groupKey, groupUpdateDataObject); } - +*/ if (groupUpdateDataObject.isInstall()) { UpdateGroupInputBuilder groupData = new UpdateGroupInputBuilder(); updateGroupBuilder = new UpdatedGroupBuilder(); @@ -304,10 +306,10 @@ public class GroupConsumerImpl implements IForwardingRulesManager { groupData.setUpdatedGroup(updateGroupBuilder.build()); // TODO how to get original group and modified group. - if (installedSwGroupView.containsKey(groupKey)) { + /* if (installedSwGroupView.containsKey(groupKey)) { installedSwGroupView.remove(groupKey); installedSwGroupView.put(groupKey, groupUpdateDataObject); - } + }*/ groupService.updateGroup(groupData.build()); } @@ -330,7 +332,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager { return groupOperationStatus; } - originalSwGroupView.put(groupKey, groupAddDataObject); + //originalSwGroupView.put(groupKey, groupAddDataObject); if (groupAddDataObject.isInstall()) { AddGroupInputBuilder groupData = new AddGroupInputBuilder(); @@ -339,19 +341,49 @@ public class GroupConsumerImpl implements IForwardingRulesManager { groupData.setGroupId(groupAddDataObject.getGroupId()); groupData.setGroupType(groupAddDataObject.getGroupType()); groupData.setNode(groupAddDataObject.getNode()); - installedSwGroupView.put(groupKey, groupAddDataObject); + // installedSwGroupView.put(groupKey, groupAddDataObject); groupService.addGroup(groupData.build()); } return groupOperationStatus; } - private RpcResult commitToPlugin(internalTransaction transaction) { + /** + * Remove Group to the southbound plugin and our internal database + * + * @param path + * @param dataObject + */ + private Status removeGroup(InstanceIdentifier path, Group groupRemoveDataObject) { + GroupKey groupKey = groupRemoveDataObject.getKey(); + Status groupOperationStatus = validateGroup(groupRemoveDataObject, FRMUtil.operation.ADD); + + if (!groupOperationStatus.isSuccess()) { + logger.error("Group data object validation failed %s" + groupRemoveDataObject.getGroupName()); + return groupOperationStatus; + } + //originalSwGroupView.put(groupKey, groupAddDataObject); + + if (groupRemoveDataObject.isInstall()) { + RemoveGroupInputBuilder groupData = new RemoveGroupInputBuilder(); + groupData.setBuckets(groupRemoveDataObject.getBuckets()); + groupData.setContainerName(groupRemoveDataObject.getContainerName()); + groupData.setGroupId(groupRemoveDataObject.getGroupId()); + groupData.setGroupType(groupRemoveDataObject.getGroupType()); + groupData.setNode(groupRemoveDataObject.getNode()); + // installedSwGroupView.put(groupKey, groupAddDataObject); + groupService.removeGroup(groupData.build()); + } + + return groupOperationStatus; + } + + private RpcResult commitToPlugin(InternalTransaction transaction) { for (Entry, Group> entry : transaction.additions.entrySet()) { if (!addGroup(entry.getKey(), entry.getValue()).isSuccess()) { transaction.additions.remove(entry.getKey()); - return Rpcs.getRpcResult(false, null, null); + return Rpcs.getRpcResult(false, null, Collections.emptySet()); } } @@ -359,12 +391,18 @@ public class GroupConsumerImpl implements IForwardingRulesManager { if (!updateGroup(entry.getKey(), entry.getValue()).isSuccess()) { transaction.updates.remove(entry.getKey()); - return Rpcs.getRpcResult(false, null, null); + return Rpcs.getRpcResult(false, null, Collections.emptySet()); } } - for (InstanceIdentifier removal : transaction.removals) { - // removeFlow(removal); + for (InstanceIdentifier groupId : transaction.removals) { + DataObject removeValue = transaction.getModification().getOriginalConfigurationData().get(groupId); + + if(removeValue instanceof Group) { + if(!removeGroup(groupId, (Group)removeValue).isSuccess()) { + return Rpcs.getRpcResult(false, null, Collections.emptySet()); + } + } } return Rpcs.getRpcResult(true, null, null); @@ -372,19 +410,18 @@ public class GroupConsumerImpl implements IForwardingRulesManager { private final class GroupDataCommitHandler implements DataCommitHandler, DataObject> { - @SuppressWarnings("unchecked") @Override public DataCommitTransaction, DataObject> requestCommit( DataModification, DataObject> modification) { // We should verify transaction System.out.println("Coming in GroupDatacommitHandler"); - internalTransaction transaction = new internalTransaction(modification); + InternalTransaction transaction = new InternalTransaction(modification); transaction.prepareUpdate(); return transaction; } } - private final class internalTransaction implements DataCommitTransaction, DataObject> { + private final class InternalTransaction implements DataCommitTransaction, DataObject> { private final DataModification, DataObject> modification; @@ -393,7 +430,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager { return modification; } - public internalTransaction(DataModification, DataObject> modification) { + public InternalTransaction(DataModification, DataObject> modification) { this.modification = modification; } @@ -407,33 +444,31 @@ public class GroupConsumerImpl implements IForwardingRulesManager { * */ void prepareUpdate() { - - Set, DataObject>> puts = modification.getUpdatedConfigurationData().entrySet(); - for (Entry, DataObject> entry : puts) { + + Set, DataObject>> groupAdded = modification.getCreatedConfigurationData().entrySet(); + for (Entry, DataObject> entry : groupAdded) { + if (entry.getValue() instanceof Group) { + Group group = (Group) entry.getValue(); + additions.put(entry.getKey(), group); + } + + } + + Set, DataObject>> groupUpdate = modification.getUpdatedConfigurationData().entrySet(); + for (Entry, DataObject> entry : groupUpdate) { if (entry.getValue() instanceof Group) { Group group = (Group) entry.getValue(); - preparePutEntry(entry.getKey(), group); + ///will be fixed once getUpdatedConfigurationData returns only updated data not created data with it. + if (additions.containsKey(entry.getKey())) { + updates.put(entry.getKey(), group); + } } } removals = modification.getRemovedConfigurationData(); } - - private void preparePutEntry(InstanceIdentifier key, Group group) { - - Group original = originalSwGroupView.get(key); - if (original != null) { - // It is update for us - - updates.put(key, group); - } else { - // It is addition for us - - additions.put(key, group); - } - } - + /** * We are OK to go with execution of plan * @@ -457,7 +492,7 @@ public class GroupConsumerImpl implements IForwardingRulesManager { // NOOP - we did not modified any internal state during // requestCommit phase // return Rpcs.getRpcResult(true, null, Collections.emptySet()); - return Rpcs.getRpcResult(true, null, null); + return Rpcs.getRpcResult(true, null, Collections.emptySet()); }