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.UpdateGroupOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
+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.group.Buckets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
private IContainer container;
public GroupConsumerImpl() {
- InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder().node(Groups.class)
- .node(Group.class).toInstance();
+
+ InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder().node(Groups.class).node(Group.class).toInstance();
groupService = FRMConsumerImpl.getProviderSession().getRpcService(SalGroupService.class);
clusterGroupContainerService = FRMConsumerImpl.getClusterContainerService();
clusterGroupContainerService.createCache("frm.nodeGroups",
EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
- // TODO for cluster mode
- /*
- * clusterGroupContainerService.createCache(WORK_STATUS_CACHE,
- * EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL,
- * IClusterServices.cacheMode.ASYNC));
- *
- * clusterGroupContainerService.createCache(WORK_ORDER_CACHE,
- * EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL,
- * IClusterServices.cacheMode.ASYNC));
- */
-
- } catch (CacheConfigException cce) {
+
+//TODO for cluster mode
+ /* clusterGroupContainerService.createCache(WORK_STATUS_CACHE,
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.ASYNC));
+
+ clusterGroupContainerService.createCache(WORK_ORDER_CACHE,
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.ASYNC));*/
+
+ } catch (CacheConfigException cce) {
logger.error("Group CacheConfigException");
return false;
-
+
} catch (CacheExistException cce) {
- logger.error(" Group CacheExistException");
+ logger.error(" Group CacheExistException");
}
-
+
return true;
}
-
+
private void nonClusterGroupObjectCreate() {
originalSwGroupView = new ConcurrentHashMap<GroupKey, Group>();
installedSwGroupView = new ConcurrentHashMap<GroupKey, Group>();
- nodeGroups = new ConcurrentHashMap<Node, List<Group>>();
+ nodeGroups = new ConcurrentHashMap<Node, List<Group>>();
inactiveGroups = new ConcurrentHashMap<GroupKey, Group>();
}
-
+
@SuppressWarnings({ "unchecked" })
private boolean retrieveGroupCaches() {
ConcurrentMap<?, ?> map;
logger.warn("Group: un-initialized clusterGroupContainerService, can't retrieve cache");
nonClusterGroupObjectCreate();
return false;
- }
+ }
map = clusterGroupContainerService.getCache("frm.originalSwGroupView");
if (map != null) {
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() >= GroupType.GroupAll.getIntValue() &&
+ group.getGroupType().getIntValue() <= GroupType.GroupFf.getIntValue())) {
logger.error("Invalid Group type %d" + group.getGroupType().getIntValue());
- return new Status(StatusCode.BADREQUEST, "Invalid Group type");
+ return new Status(StatusCode.BADREQUEST, "Invalid Group type");
}
groupBuckets = group.getBuckets();
* @param dataObject
*/
private Status updateGroup(InstanceIdentifier<?> path, Group groupUpdateDataObject) {
- GroupKey groupKey = groupUpdateDataObject.getKey();
+ GroupKey groupKey = groupUpdateDataObject.getKey();
+ UpdatedGroupBuilder updateGroupBuilder = null;
+
Status groupOperationStatus = validateGroup(groupUpdateDataObject, FRMUtil.operation.UPDATE);
-
+
if (!groupOperationStatus.isSuccess()) {
logger.error("Group data object validation failed %s" + groupUpdateDataObject.getGroupName());
return groupOperationStatus;
}
-
- originalSwGroupView.remove(groupKey);
- originalSwGroupView.put(groupKey, groupUpdateDataObject);
-
+
+ if (originalSwGroupView.containsKey(groupKey)) {
+ originalSwGroupView.remove(groupKey);
+ originalSwGroupView.put(groupKey, groupUpdateDataObject);
+ }
+
if (groupUpdateDataObject.isInstall()) {
UpdateGroupInputBuilder groupData = new UpdateGroupInputBuilder();
- // TODO how to get original group and modified group.
-
+ updateGroupBuilder = new UpdatedGroupBuilder();
+ updateGroupBuilder.fieldsFrom(groupUpdateDataObject);
+ groupData.setUpdatedGroup(updateGroupBuilder.build());
+ //TODO how to get original group and modified group.
+
if (installedSwGroupView.containsKey(groupKey)) {
installedSwGroupView.remove(groupKey);
+ installedSwGroupView.put(groupKey, groupUpdateDataObject);
}
-
- installedSwGroupView.put(groupKey, groupUpdateDataObject);
+
groupService.updateGroup(groupData.build());
}
-
+
return groupOperationStatus;
}
-
+
/**
* Adds Group to the southbound plugin and our internal database
*
return groupOperationStatus;
}
-
- private RpcResult<Void> commitToPlugin(internalTransaction transaction) {
- for (Entry<InstanceIdentifier<?>, Group> entry : transaction.additions.entrySet()) {
-
- if (!addGroup(entry.getKey(), entry.getValue()).isSuccess()) {
+
+ private RpcResult<Void> commitToPlugin(internalTransaction transaction) {
+ for(Entry<InstanceIdentifier<?>, Group> entry :transaction.additions.entrySet()) {
+
+ if (!addGroup(entry.getKey(),entry.getValue()).isSuccess()) {
+ transaction.additions.remove(entry.getKey());
return Rpcs.getRpcResult(false, null, null);
}
}
- for (@SuppressWarnings("unused")
- Entry<InstanceIdentifier<?>, Group> entry : transaction.additions.entrySet()) {
-
- if (!updateGroup(entry.getKey(), entry.getValue()).isSuccess()) {
+
+ for(Entry<InstanceIdentifier<?>, Group> entry :transaction.updates.entrySet()) {
+
+ if (!updateGroup(entry.getKey(),entry.getValue()).isSuccess()) {
+ transaction.updates.remove(entry.getKey());
return Rpcs.getRpcResult(false, null, null);
}
}
-
- for (InstanceIdentifier<?> removal : transaction.removals) {
- // removeFlow(removal);
+
+ for(InstanceIdentifier<?> removal : transaction.removals) {
+ // removeFlow(removal);
}
return Rpcs.getRpcResult(true, null, null);