import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
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.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.config.rev131024.meters.Meter;
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;
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");
} 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())) {
}
- private boolean doesGroupEntryExists(GroupKey key, String groupName, String containerName) {
+ /* private boolean doesGroupEntryExists(GroupKey key, String groupName, String containerName) {
if (!originalSwGroupView.containsKey(key)) {
return false;
}
}
}
}
- return false;
- }
+ return true;
+ }*/
/**
* Update Group entries to the southbound plugin/inventory and our internal
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();
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());
}
return groupOperationStatus;
}
- originalSwGroupView.put(groupKey, groupAddDataObject);
+ //originalSwGroupView.put(groupKey, groupAddDataObject);
if (groupAddDataObject.isInstall()) {
AddGroupInputBuilder groupData = new AddGroupInputBuilder();
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<Void> 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<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);
+ return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
}
}
if (!updateGroup(entry.getKey(), entry.getValue()).isSuccess()) {
transaction.updates.remove(entry.getKey());
- return Rpcs.getRpcResult(false, null, null);
+ return Rpcs.getRpcResult(false, null, Collections.<RpcError>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.<RpcError>emptySet());
+ }
+ }
}
return Rpcs.getRpcResult(true, null, null);
private final class GroupDataCommitHandler implements DataCommitHandler<InstanceIdentifier<?>, DataObject> {
- @SuppressWarnings("unchecked")
@Override
public DataCommitTransaction<InstanceIdentifier<?>, DataObject> requestCommit(
DataModification<InstanceIdentifier<?>, 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<InstanceIdentifier<?>, DataObject> {
+ private final class InternalTransaction implements DataCommitTransaction<InstanceIdentifier<?>, DataObject> {
private final DataModification<InstanceIdentifier<?>, DataObject> modification;
return modification;
}
- public internalTransaction(DataModification<InstanceIdentifier<?>, DataObject> modification) {
+ public InternalTransaction(DataModification<InstanceIdentifier<?>, DataObject> modification) {
this.modification = modification;
}
*
*/
void prepareUpdate() {
-
- Set<Entry<InstanceIdentifier<?>, DataObject>> puts = modification.getUpdatedConfigurationData().entrySet();
- for (Entry<InstanceIdentifier<?>, DataObject> entry : puts) {
+
+ Set<Entry<InstanceIdentifier<?>, DataObject>> groupAdded = modification.getCreatedConfigurationData().entrySet();
+ for (Entry<InstanceIdentifier<?>, DataObject> entry : groupAdded) {
+ if (entry.getValue() instanceof Group) {
+ Group group = (Group) entry.getValue();
+ additions.put(entry.getKey(), group);
+ }
+
+ }
+
+ Set<Entry<InstanceIdentifier<?>, DataObject>> groupUpdate = modification.getUpdatedConfigurationData().entrySet();
+ for (Entry<InstanceIdentifier<?>, 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
*
// 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.<RpcError>emptySet());
}
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAdded;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder;
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;
private MeterDataCommitHandler commitHandler;
private ConcurrentMap<MeterKey, Meter> originalSwMeterView;
+ @SuppressWarnings("unused")
private ConcurrentMap<MeterKey, Meter> installedSwMeterView;
-
+ @SuppressWarnings("unused")
private ConcurrentMap<Node, List<Meter>> nodeMeters;
+ @SuppressWarnings("unused")
private ConcurrentMap<MeterKey, Meter> inactiveMeters;
+ @SuppressWarnings("unused")
+ private IContainer container;
private IClusterContainerServices clusterMeterContainerService = null;
- private IContainer container;
+
public MeterConsumerImpl() {
InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(Meters.class).child(Meter.class)
meterBuilder.setMeterBandHeaders(meterAddDataObject.getMeterBandHeaders());
meterBuilder.setMeterId(meterAddDataObject.getMeterId());
meterBuilder.setNode(meterAddDataObject.getNode());
- originalSwMeterView.put(meterKey, meterAddDataObject);
+ // originalSwMeterView.put(meterKey, meterAddDataObject);
meterService.addMeter(meterBuilder.build());
}
- originalSwMeterView.put(meterKey, meterAddDataObject);
+ // originalSwMeterView.put(meterKey, meterAddDataObject);
} else {
return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
}
if (null != meterKey && validateMeter(meterUpdateDataObject, FRMUtil.operation.UPDATE).isSuccess()) {
- if (originalSwMeterView.containsKey(meterKey)) {
+ /* if (originalSwMeterView.containsKey(meterKey)) {
originalSwMeterView.remove(meterKey);
originalSwMeterView.put(meterKey, meterUpdateDataObject);
- }
+ }*/
if (meterUpdateDataObject.isInstall()) {
UpdateMeterInputBuilder updateMeterInputBuilder = new UpdateMeterInputBuilder();
updateMeterBuilder.fieldsFrom(meterUpdateDataObject);
updateMeterInputBuilder.setUpdatedMeter(updateMeterBuilder.build());
- if (installedSwMeterView.containsKey(meterKey)) {
+ /* if (installedSwMeterView.containsKey(meterKey)) {
installedSwMeterView.remove(meterKey);
installedSwMeterView.put(meterKey, meterUpdateDataObject);
- }
+ }*/
meterService.updateMeter(updateMeterInputBuilder.build());
}
*
* @param dataObject
*/
- private Status RemoveMeter(InstanceIdentifier<?> path, Meter meterUpdateDataObject) {
- MeterKey meterKey = meterUpdateDataObject.getKey();
-
- if (null != meterKey && validateMeter(meterUpdateDataObject, FRMUtil.operation.ADD).isSuccess()) {
- if (meterUpdateDataObject.isInstall()) {
- UpdateMeterInputBuilder updateMeterBuilder = new UpdateMeterInputBuilder();
-
- installedSwMeterView.put(meterKey, meterUpdateDataObject);
- meterService.updateMeter(updateMeterBuilder.build());
+ private Status removeMeter(InstanceIdentifier<?> path, Meter meterRemoveDataObject) {
+ MeterKey meterKey = meterRemoveDataObject.getKey();
+
+ if (null != meterKey && validateMeter(meterRemoveDataObject, FRMUtil.operation.DELETE).isSuccess()) {
+ if (meterRemoveDataObject.isInstall()) {
+ RemoveMeterInputBuilder meterBuilder = new RemoveMeterInputBuilder();
+ meterBuilder.setContainerName(meterRemoveDataObject.getContainerName());
+ meterBuilder.setNode(meterRemoveDataObject.getNode());
+ meterBuilder.setFlags(meterRemoveDataObject.getFlags());
+ meterBuilder.setMeterBandHeaders(meterRemoveDataObject.getMeterBandHeaders());
+ meterBuilder.setMeterId(meterRemoveDataObject.getMeterId());
+ meterBuilder.setNode(meterRemoveDataObject.getNode());
+ // originalSwMeterView.put(meterKey, meterAddDataObject);
+ meterService.removeMeter(meterBuilder.build());
}
- originalSwMeterView.put(meterKey, meterUpdateDataObject);
+ // originalSwMeterView.put(meterKey, meterAddDataObject);
} else {
return new Status(StatusCode.BADREQUEST, "Meter Key or attribute validation failed");
}
String containerName;
String meterName;
Status returnStatus = null;
- boolean returnResult;
if (null != meter) {
containerName = meter.getContainerName();
return returnStatus;
}
- returnResult = doesMeterEntryExists(meter.getKey(), meterName, containerName);
+ /* returnResult = doesMeterEntryExists(meter.getKey(), meterName, containerName);
if (FRMUtil.operation.ADD == operation && returnResult) {
logger.error("Record with same Meter Name exists");
logger.error("Group record does not exist");
returnStatus = new Status(StatusCode.BADREQUEST, "Meter record does not exist");
return returnStatus;
- }
+ }*/
for (int i = 0; i < meter.getMeterBandHeaders().getMeterBandHeader().size(); i++) {
if (!meter.getFlags().isMeterBurst()) {
return new Status(StatusCode.SUCCESS);
}
- private boolean doesMeterEntryExists(MeterKey key, String meterName, String containerName) {
+ /*private boolean doesMeterEntryExists(MeterKey key, String meterName, String containerName) {
if (!originalSwMeterView.containsKey(key)) {
return false;
}
}
}
return false;
- }
-
- private RpcResult<Void> commitToPlugin(internalTransaction transaction) {
- for (Entry<InstanceIdentifier<?>, Meter> entry : transaction.additions.entrySet()) {
-
- if (!addMeter(entry.getKey(), entry.getValue()).isSuccess()) {
- return Rpcs.getRpcResult(false, null, null);
- }
- }
- for (@SuppressWarnings("unused")
- Entry<InstanceIdentifier<?>, Meter> entry : transaction.updates.entrySet()) {
-
- if (!updateMeter(entry.getKey(), entry.getValue()).isSuccess()) {
- return Rpcs.getRpcResult(false, null, null);
- }
- }
-
- for (InstanceIdentifier<?> removal : transaction.removals) {
- /*
- * if (!removeMeter(entry.getKey(),entry.getValue()).isSuccess()) {
- * return Rpcs.getRpcResult(false, null, null); }
- */
- }
-
- return Rpcs.getRpcResult(true, null, null);
- }
+ }*/
- private final class internalTransaction implements DataCommitTransaction<InstanceIdentifier<?>, DataObject> {
+ private final class InternalTransaction implements DataCommitTransaction<InstanceIdentifier<?>, DataObject> {
private final DataModification<InstanceIdentifier<?>, DataObject> modification;
return modification;
}
- public internalTransaction(DataModification<InstanceIdentifier<?>, DataObject> modification) {
+ public InternalTransaction(DataModification<InstanceIdentifier<?>, DataObject> modification) {
this.modification = modification;
}
*
*/
void prepareUpdate() {
-
- Set<Entry<InstanceIdentifier<?>, DataObject>> puts = modification.getUpdatedConfigurationData().entrySet();
- for (Entry<InstanceIdentifier<?>, DataObject> entry : puts) {
+
+ Set<Entry<InstanceIdentifier<?>, DataObject>> addMeter = modification.getCreatedConfigurationData().entrySet();
+ for (Entry<InstanceIdentifier<?>, DataObject> entry : addMeter) {
if (entry.getValue() instanceof Meter) {
- Meter Meter = (Meter) entry.getValue();
- preparePutEntry(entry.getKey(), Meter);
+ Meter meter = (Meter) entry.getValue();
+ additions.put(entry.getKey(), meter);
}
}
+
+ Set<Entry<InstanceIdentifier<?>, DataObject>> updateMeter = modification.getUpdatedConfigurationData().entrySet();
+ for (Entry<InstanceIdentifier<?>, DataObject> entry : updateMeter) {
+ if (entry.getValue() instanceof Meter) {
+ Meter meter = (Meter) entry.getValue();
+ ///will be fixed once getUpdatedConfigurationData returns only updated data not created data with it.
+ if (!additions.containsKey(entry.getKey())) {
+ updates.put(entry.getKey(), meter);
+ }
+ }
+ }
removals = modification.getRemovedConfigurationData();
}
- private void preparePutEntry(InstanceIdentifier<?> key, Meter meter) {
-
- Meter original = originalSwMeterView.get(key);
- if (original != null) {
- // It is update for us
-
- updates.put(key, meter);
- } else {
- // It is addition for us
-
- additions.put(key, meter);
- }
- }
-
/**
* We are OK to go with execution of plan
*
// 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.<RpcError>emptySet());
+
+ }
+
+ }
+
+ private RpcResult<Void> commitToPlugin(InternalTransaction transaction) {
+ for (Entry<InstanceIdentifier<?>, Meter> entry : transaction.additions.entrySet()) {
+
+ if (!addMeter(entry.getKey(), entry.getValue()).isSuccess()) {
+ return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
+ }
+ }
+ for (Entry<InstanceIdentifier<?>, Meter> entry : transaction.updates.entrySet()) {
+
+ if (!updateMeter(entry.getKey(), entry.getValue()).isSuccess()) {
+ return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
+ }
+ }
+ for (InstanceIdentifier<?> meterId : transaction.removals) {
+ DataObject removeValue = transaction.getModification().getOriginalConfigurationData().get(meterId);
+
+ if(removeValue instanceof Meter) {
+ if(!removeMeter(meterId, (Meter)removeValue).isSuccess()) {
+ return Rpcs.getRpcResult(false, null, Collections.<RpcError>emptySet());
+ }
+ }
}
+ return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet());
}
private final class MeterDataCommitHandler implements DataCommitHandler<InstanceIdentifier<?>, DataObject> {
DataModification<InstanceIdentifier<?>, DataObject> modification) {
// We should verify transaction
System.out.println("Coming in MeterDataCommitHandler");
- internalTransaction transaction = new internalTransaction(modification);
+ InternalTransaction transaction = new InternalTransaction(modification);
transaction.prepareUpdate();
return transaction;
}